#include <CorbaService.h>
Public Methods | |
| CorbaService (const std::string &nsHost, vpr::Uint16 nsPort=2809, const std::string &iiopVersion=std::string("1.0"), const std::string &subContextId=std::string("")) | |
| Creates a new instance of this class and initializes the URI that will be used to contact the CORBA Naming Service. More... | |
| ~CorbaService () | |
| This will destroy the Portable Object Adapter associated with this CORBA Service, and it will shut down the ORB. More... | |
| vpr::ReturnStatus | init (int &argc, char *argv[]) |
| void | shutdown (bool waitForCompletion=true) |
| Shuts down the ORB and the POA (if they were successfully initialized). More... | |
| bool | isValid () const |
| Checks the validity of this service object to ensure that initialization completed successfully. More... | |
| const std::string & | getNameServiceURI () const |
| const CosNaming::NamingContext_var | getLocalContext () |
| std::list< tweek::SubjectManager_var > | getSubjectManagerList () |
| Retrieves a reference to all the valid CORBA objects that implement the tweek::SubjectManager interface. More... | |
| void | setSubjectManager (tweek::SubjectManager_var mgr) |
| Sets the Subject Manager reference that will be used with this CORBA service object. More... | |
| tweek::SubjectManager_var | getSubjectManager () const |
| Returns a reference to the CORBA object known as the Subject Manager. More... | |
| PortableServer::ObjectId_var | registerObject (PortableServer::ServantBase *servant, const std::string &name) |
| Registers the given servant with the local Portable Object Adaptor. More... | |
| void | unregisterObject (PortableServer::ObjectId_var id) |
| Removes the identified Servant object from the collection of activated CORBA objects. More... | |
| void | run () |
| Runs the ORB thread. More... | |
Definition at line 58 of file CorbaService.h.
|
||||||||||||||||||||
|
Creates a new instance of this class and initializes the URI that will be used to contact the CORBA Naming Service.
Definition at line 57 of file CorbaService.cpp. References tweek::getVersionString, and tweekDBG_CORBA.
00060 : mOrbFunctor(NULL), mOrbThread(NULL), mNsHost(nsHost), mNsPort(nsPort),
00061 mNameServiceURI("corbaloc:iiop:"), mSubContextId(subContextId)
00062 {
00063 // Why isn't this conversion easier to do with std::string?
00064 char nsPort_str[6];
00065 std::sprintf(nsPort_str, "%hu", nsPort);
00066
00067 mNameServiceURI += iiopVersion;
00068 mNameServiceURI += std::string("@");
00069 mNameServiceURI += nsHost;
00070 mNameServiceURI += std::string(":");
00071 mNameServiceURI += nsPort_str;
00072 mNameServiceURI += std::string("/NameService");
00073
00074 vprDEBUG(tweekDBG_CORBA, vprDBG_VERB_LVL)
00075 << "Naming Service URI: " << mNameServiceURI << std::endl
00076 << vprDEBUG_FLUSH;
00077
00078 std::string tweek_ver = getVersionString();
00079
00080 // Print out the Tweek version information.
00081 vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00082 << std::string(tweek_ver.length() + 14, '=') << std::endl
00083 << vprDEBUG_FLUSH;
00084 vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00085 << clrOutNORM(clrGREEN, "Tweek Client: ")
00086 << clrOutNORM(clrGREEN, tweek_ver) << clrRESET << std::endl
00087 << vprDEBUG_FLUSH;
00088 vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00089 << std::string(tweek_ver.length() + 14, '=') << std::endl
00090 << vprDEBUG_FLUSH;
00091 }
|
|
|
This will destroy the Portable Object Adapter associated with this CORBA Service, and it will shut down the ORB. These steps may be performed manually shutdown().
Definition at line 88 of file CorbaService.h. References shutdown.
00089 {
00090 shutdown();
00091
00092 if ( mOrbThread != NULL )
00093 {
00094 delete mOrbThread;
00095 mOrbThread = NULL;
00096 delete mOrbFunctor;
00097 mOrbFunctor = NULL;
00098 }
00099 }
|
|
||||||||||||
|
Definition at line 93 of file CorbaService.cpp. References tweek::bindLocalNamingContext, tweek::getRootNamingContextByURI, and tweekDBG_CORBA.
00094 {
00095 vpr::ReturnStatus status;
00096
00097 try
00098 {
00099 // Initialize the ORB.
00100 vprDEBUG(tweekDBG_CORBA, vprDBG_STATE_LVL)
00101 << "Initializing client ORB (using init string '"
00102 << TWEEK_ORB_VER_STRING << "')\n" << vprDEBUG_FLUSH;
00103 mORB = CORBA::ORB_init(argc, argv, TWEEK_ORB_VER_STRING);
00104
00105 initRootPOA();
00106
00107 try
00108 {
00109 mRootContext = tweek::getRootNamingContextByURI(mORB, mNameServiceURI);
00110
00111 if ( ! CORBA::is_nil(mRootContext) )
00112 {
00113 vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00114 << "Got root context, now binding local context\n"
00115 << vprDEBUG_FLUSH;
00116 mLocalContext =
00117 tweek::bindLocalNamingContext(mRootContext,
00118 std::string("tweek"));
00119 }
00120 }
00121 catch (CORBA::ORB::InvalidName& ex)
00122 {
00123 boost::ignore_unused_variable_warning(ex);
00124
00125 // This should not happen!
00126 vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
00127 << "NameService name invalid in CorbaService::init!\n"
00128 << vprDEBUG_FLUSH;
00129 }
00130
00131 vprDEBUG(tweekDBG_CORBA, vprDBG_STATE_LVL) << "Starting ORB thread\n"
00132 << vprDEBUG_FLUSH;
00133
00134 mOrbFunctor = new vpr::ThreadRunFunctor<CorbaService>(this);
00135 mOrbThread = new vpr::Thread(mOrbFunctor);
00136 }
00137 catch (CORBA::SystemException& sysEx)
00138 {
00139 status.setCode(vpr::ReturnStatus::Fail);
00140 vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00141 << "Caught CORBA::SystemException during initialization\n"
00142 << vprDEBUG_FLUSH;
00143 vprDEBUG_NEXT(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00144 << "Mindor code: " << sysEx.minor() << ", completed: "
00145 << vprDEBUG_FLUSH;
00146
00147 switch ( sysEx.completed() )
00148 {
00149 case CORBA::COMPLETED_YES:
00150 vprDEBUG_CONT(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00151 << "YES" << std::endl << vprDEBUG_FLUSH;
00152 break;
00153 case CORBA::COMPLETED_NO:
00154 vprDEBUG_CONT(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00155 << "NO" << std::endl << vprDEBUG_FLUSH;
00156 break;
00157 case CORBA::COMPLETED_MAYBE:
00158 vprDEBUG_CONT(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00159 << "MAYBE" << std::endl << vprDEBUG_FLUSH;
00160 break;
00161 }
00162 }
00163 catch (CORBA::Exception&)
00164 {
00165 status.setCode(vpr::ReturnStatus::Fail);
00166 vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00167 << "Caught CORBA::Exception during initialization.\n"
00168 << vprDEBUG_FLUSH;
00169 }
00170 catch (omniORB::fatalException& fe)
00171 {
00172 boost::ignore_unused_variable_warning(fe);
00173
00174 status.setCode(vpr::ReturnStatus::Fail);
00175 vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00176 << "Caught omniORB::fatalException:\n" << vprDEBUG_FLUSH;
00177 vprDEBUG_NEXT(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00178 << " file: " << fe.file() << std::endl << vprDEBUG_FLUSH;
00179 vprDEBUG_NEXT(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00180 << " line: " << fe.line() << std::endl << vprDEBUG_FLUSH;
00181 vprDEBUG_NEXT(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00182 << " mesg: " << fe.errmsg() << std::endl << vprDEBUG_FLUSH;
00183 }
00184 catch(...)
00185 {
00186 vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00187 << "Caught unknown exception during initialization." << std::endl
00188 << vprDEBUG_FLUSH;
00189 }
00190
00191 return status;
00192 }
|
|
|
Shuts down the ORB and the POA (if they were successfully initialized).
Definition at line 194 of file CorbaService.cpp. Referenced by ~CorbaService.
00195 {
00196 if ( ! CORBA::is_nil(mRootPOA) )
00197 {
00198 // We want to etherialize objects (destroy registered servants). This
00199 // will destroy all descendant POAs, so we do not have to worry about
00200 // them at all.
00201 mRootPOA->destroy(true, waitForCompletion);
00202 }
00203
00204 if ( ! CORBA::is_nil(mORB) )
00205 {
00206 mORB->shutdown(waitForCompletion);
00207 }
00208 }
|
|
|
Checks the validity of this service object to ensure that initialization completed successfully.
Definition at line 122 of file CorbaService.h.
00123 {
00124 return ! (CORBA::is_nil(mORB) || CORBA::is_nil(mRootPOA));
00125 }
|
|
|
Definition at line 127 of file CorbaService.h.
00128 {
00129 return mNameServiceURI;
00130 }
|
|
|
Definition at line 132 of file CorbaService.h.
00133 {
00134 return mLocalContext;
00135 }
|
|
|
Retrieves a reference to all the valid CORBA objects that implement the tweek::SubjectManager interface. When the references are added to the list, it is guaranteed to have only valid tweek::SubjectManager references. However, due to the nature of CORBA references, they may become invalid at any time thereafter.
Definition at line 210 of file CorbaService.cpp.
00211 {
00212 std::list<tweek::SubjectManager_var> mgr_list;
00213
00214 const CORBA::ULong data_size(100);
00215
00216 CosNaming::BindingList_var binding_list;
00217 CosNaming::BindingIterator_var binding_iter;
00218
00219 mLocalContext->list(data_size, binding_list, binding_iter);
00220
00221 addSubjectManagers(binding_list, mgr_list);
00222
00223 if ( ! CORBA::is_nil(binding_iter) )
00224 {
00225 while ( binding_iter->next_n(data_size, binding_list) )
00226 {
00227 addSubjectManagers(binding_list, mgr_list);
00228 }
00229
00230 binding_iter->destroy();
00231 }
00232
00233 return mgr_list;
00234 }
|
|
|
Sets the Subject Manager reference that will be used with this CORBA service object.
Definition at line 155 of file CorbaService.h.
00156 {
00157 this->mSubjectManager = mgr;
00158 }
|
|
|
Returns a reference to the CORBA object known as the Subject Manager. Using this reference, the caller can request references to subjects registered with the manager.
Definition at line 168 of file CorbaService.h.
00169 {
00170 return mSubjectManager;
00171 }
|
|
||||||||||||
|
Registers the given servant with the local Portable Object Adaptor. This is necessary for tweek::Observer implementations to be referenced by their corresponding subject.
Definition at line 236 of file CorbaService.cpp.
00238 {
00239 // XXX: Why is name unused? It doesn't seem like it should even be a
00240 // parameter.
00241 boost::ignore_unused_variable_warning(name);
00242
00243 PortableServer::ObjectId_var obj_id;
00244
00245 try
00246 {
00247 obj_id = mRootPOA->activate_object(servant);
00248 }
00249 catch (PortableServer::POA::ServantAlreadyActive& activeEx)
00250 {
00251 boost::ignore_unused_variable_warning(activeEx);
00252 }
00253 catch (PortableServer::POA::WrongPolicy& policyEx)
00254 {
00255 boost::ignore_unused_variable_warning(policyEx);
00256 }
00257
00258 return obj_id;
00259 }
|
|
|
Removes the identified Servant object from the collection of activated CORBA objects. In CORBA terms, the servant is deactivated within the POA and cannot be referenced after this occurs.
Definition at line 261 of file CorbaService.cpp. References tweekDBG_CORBA.
00262 {
00263 // XXX: Is there a way to verify that the id is valid first?
00264 // if ( ! PortableServer::is_nil(id) )
00265 // {
00266 try
00267 {
00268 mRootPOA->deactivate_object(id);
00269 }
00270 catch (PortableServer::POA::ObjectNotActive& activeEx)
00271 {
00272 boost::ignore_unused_variable_warning(activeEx);
00273 vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00274 << "CorbaService::unregisterObject: Tried to deactivate an inactive object\n"
00275 << vprDEBUG_FLUSH;
00276 }
00277 catch (PortableServer::POA::WrongPolicy& policyEx)
00278 {
00279 boost::ignore_unused_variable_warning(policyEx);
00280 vprDEBUG(tweekDBG_CORBA, vprDBG_CRITICAL_LVL)
00281 << "CorbaService::unregisterObject: Wrong POA policy\n"
00282 << vprDEBUG_FLUSH;
00283 }
00284 // }
00285 // else
00286 // {
00287 // vprDEBUG(tweekDBG_CORBA, vprDBG_WARNING_LVL)
00288 // << clrOutNORM(clrYELLOW, "WARNING:")
00289 // << " Tried to unregister null ID in CorbaService::unregisterObject()!"
00290 // << std::endl << vprDEBUG_FLUSH;
00291 // }
00292 }
|
|
|
Runs the ORB thread. This should not be invoked by user code. It is for use with the internally managed ORB thread. Definition at line 433 of file CorbaService.cpp. References tweekDBG_CORBA.
00434 {
00435 vprDEBUG(tweekDBG_CORBA, vprDBG_STATE_LVL) << "Server is running!\n"
00436 << vprDEBUG_FLUSH;
00437
00438 // PortableServer::POAManager_var pman = mChildPOA->the_POAManager();
00439 PortableServer::POAManager_var pman = mRootPOA->the_POAManager();
00440
00441 pman->activate();
00442 mORB->run();
00443 // mORB->destroy();
00444
00445 vprDEBUG(tweekDBG_CORBA, vprDBG_STATE_LVL) << "Server has shut down\n"
00446 << vprDEBUG_FLUSH;
00447 }
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002