#include <HxServer.h>
Inheritance diagram for HxServer::

Public Methods | |
| HxServer (int argc, char *argv[]) | |
| Construct a server. More... | |
| HxServer (int port) | |
| Construct a simple (inprocess) server. More... | |
| virtual | ~HxServer () |
| Destructor. More... | |
| virtual void | run () |
| virtual void | message (const char *msg) |
| void | shutdown (bool wait_for_completion=false) |
| void | bindToNameServer (const char *name, const char *nsAddress) |
| CORBA::Object_ptr | getInitialObject (const char *name) |
| void | addInitialObject (const char *name, PortableServer::Servant servant) |
| char * | object_to_string (CORBA::Object_ptr obj) |
| CORBA::Object_ptr | string_to_object (const char *ref) |
| PortableServer::POA_ptr | getDataPOA () |
| PortableServer::POA_ptr | getRootPOA () |
| PortableServer::POA_ptr | getCurrentPOA () |
| PortableServer::Servant | getCurrentServant () |
| PortableServer::ObjectId * | getCurrentObjectId () |
| virtual CORBA::Object_ptr | registerServant (PortableServer::Servant srv) |
| virtual void | unregisterServant (const PortableServer::ObjectId &oid) |
| virtual PortableServer::Servant | getServant (CORBA::Object_ptr obj) |
| virtual HxCorba::RgbBuffer_ptr | createRgbBuffer () |
| virtual void | setRgbBufferArray (HxCorba::RgbBuffer_ptr buf, int *array) |
Static Public Methods | |
| HxServer * | instance () |
| Get the one and only Horus server. More... | |
Protected Methods | |
| void | init (int argc, char *argv[]) |
Protected Attributes | |
| CORBA::ORB_ptr | _orb |
| PortableServer::POA_var | _rootPOA |
| PortableServer::POA_var | _dataPOA |
| PortableServer::POA_var | _initialPOA |
| OB::BootManager_var | _bootMgr |
| PortableServer::Current_var | _poaCurrent |
| std::list< HxNSBinding *> | _nsBindings |
|
||||||||||||
|
Construct a server.
00033 : _silent(0)
00034 {
00035 _inst = this;
00036 init(argc, argv);
00037 }
|
|
|
Construct a simple (inprocess) server.
00039 : _silent(1)
00040 {
00041 if(port != -1) {
00042 char strport[20];
00043 sprintf(strport, "%d", port);
00044
00045 OB::Properties_var properties = OB::Properties::getDefaultProperties();
00046 properties -> setProperty("ooc.orb.oa.port", strport);
00047 }
00048
00049 char* args[1];
00050 char* progname = "ServerDLL";
00051 args[0] = progname;
00052
00053 _inst = this;
00054 init(1, args);
00055 }
|
|
|
Destructor.
00058 {
00059 _inst = NULL;
00060
00061 std::list<HxNSBinding*>::iterator it = _nsBindings.begin();
00062 while(it != _nsBindings.end())
00063 delete (*it++);
00064 // Destructor of binding unbinds server
00065 }
|
|
|
Get the one and only Horus server.
00069 {
00070 return _inst;
00071 }
|
|
|
|
|
|
00075 {
00076 if(!_silent) cout << msg << endl;
00077 }
|
|
|
00181 {
00182 // It doesn't work if the server is not in the "running" state
00183 // (if the server is showing a prompt, it is not "running")
00184
00185 cout << "Shutting down ORB" << endl;
00186 _orb->shutdown(wait_for_completion);
00187
00188 if(wait_for_completion) delete this;
00189 }
|
|
||||||||||||
|
00193 {
00194 HxNSBinding* b = HxNSBinding::bindServer(name, nsAddress);
00195 if(b != NULL)
00196 _nsBindings.push_back(b);
00197 }
|
|
|
00215 {
00216 PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId(name);
00217
00218 try {
00219 return _initialPOA->id_to_reference(oid);
00220 }catch(PortableServer::POA::ObjectNotActive&) {}
00221
00222 return CORBA::Object::_nil();
00223 }
|
|
||||||||||||
|
00201 {
00202 ostrstream ostr;
00203 ostr << "... " << name << ends;
00204 message(ostr.str());
00205 ostr.freeze(0);
00206
00207 PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId(name);
00208 _initialPOA->activate_object_with_id(oid, servant);
00209 CORBA::Object_var obj = _initialPOA->servant_to_reference(servant);
00210 _bootMgr->add_binding(oid, obj);
00211 }
|
|
|
00259 {
00260 return _orb->object_to_string(obj);
00261 }
|
|
|
00265 {
00266 return _orb->string_to_object(ref);
00267 }
|
|
|
00227 {
00228 return PortableServer::POA::_duplicate(_dataPOA);
00229 }
|
|
|
00233 {
00234 return PortableServer::POA::_duplicate(_rootPOA);
00235 }
|
|
|
00253 {
00254 return _poaCurrent->get_POA();
00255 }
|
|
|
00239 {
00240 PortableServer::POA_var poa = _poaCurrent->get_POA();
00241 PortableServer::ObjectId_var oid = _poaCurrent->get_object_id();
00242 return poa->id_to_servant(oid);
00243 }
|
|
|
00247 {
00248 return _poaCurrent->get_object_id();
00249 }
|
|
|
Reimplemented from HxServerBase.
00272 {
00273 PortableServer::ObjectId_var oid = _dataPOA->activate_object(srv);
00274
00275 char* repositoryId = srv->_primary_interface(oid, _dataPOA);
00276 HxDataObjectManager* mgr = HxDataObjectManager::get(repositoryId);
00277 CORBA::Object_var obj = _dataPOA->servant_to_reference(srv);
00278
00279 mgr->objectCreated(oid);
00280
00281 return obj._retn();
00282 }
|
|
|
Reimplemented from HxServerBase.
00286 {
00287 PortableServer::Servant srv = _dataPOA->id_to_servant(oid);
00288
00289 _dataPOA->deactivate_object(oid);
00290
00291 char* repositoryId = srv->_primary_interface(oid, _dataPOA);
00292 HxDataObjectManager* mgr = HxDataObjectManager::get(repositoryId);
00293 mgr->objectDeleted(oid);
00294
00295 srv->_remove_ref();
00296 }
|
|
|
Reimplemented from HxServerBase.
00300 {
00301 PortableServer::Servant result;
00302
00303 try
00304 {
00305 result = _dataPOA->reference_to_servant(obj);
00306 }
00307 catch(PortableServer::POA::WrongAdapter&)
00308 {
00309 result = NULL;
00310 }
00311 catch(PortableServer::POA::ObjectNotActive&)
00312 {
00313 result = NULL;
00314 }
00315
00316 return result;
00317 }
|
|
|
00321 {
00322 HxRgbBufferServant* servant = new HxRgbBufferServant();
00323 CORBA::Object_var obj = registerServant(servant);
00324 HxCorba::RgbBuffer_var res = HxCorba::RgbBuffer::_narrow(obj);
00325 return res._retn();
00326 }
|
|
||||||||||||
|
00330 {
00331 PortableServer::Servant servant = HxServer::instance()->getServant(buf);
00332 if(servant != NULL) {
00333 HxRgbBufferServant* pixbuff = dynamic_cast<HxRgbBufferServant*>(servant);
00334 pixbuff->setBuffer(array);
00335 servant->_remove_ref();
00336 }
00337 }
|
|
||||||||||||
|
00081 {
00082 message("Initializing ORB");
00083
00084 const char* dataPOAname = "dataPOA";
00085 HxDataObjectManager::init(dataPOAname);
00086
00087 #if (OB_INTEGER_VERSION >= 4000500L)
00088 OB::Properties_var dflt = OB::Properties::getDefaultProperties();
00089 OB::Properties_var props = new OB::Properties(dflt);
00090 //props -> setProperty("ooc.orb.oa.port", "8010");
00091 //props -> setProperty("ooc.iiop.acceptor.data.port", "2000");
00092
00093 props -> setProperty("ooc.orb.oa.conc_model", "threaded");
00094 _orb = OBCORBA::ORB_init(argc, argv, props);
00095 #else
00096 _orb = CORBA::ORB_init(argc, argv);
00097 #endif
00098
00099 //RootPOA
00100 CORBA::Object_var poaObj = _orb->resolve_initial_references("RootPOA");
00101 _rootPOA = PortableServer::POA::_narrow(poaObj);
00102 PortableServer::POAManager_var poa_manager = _rootPOA->the_POAManager();
00103
00104 //Display the host and port (ORBacus specific)
00105 OBPortableServer::POAManager_var obManager =
00106 OBPortableServer::POAManager::_narrow(poa_manager);
00107 OCI::AcceptorSeq_var acceptors = obManager->get_acceptors();
00108 for(int i=0; i<acceptors->length(); i++) {
00109 OCI::AcceptorInfo_var info = acceptors[i]->get_info();
00110 OCI::IIOP::AcceptorInfo_var iiopInfo =
00111 OCI::IIOP::AcceptorInfo::_narrow(info);
00112 if(!CORBA::is_nil(iiopInfo)) {
00113 ostrstream ostr;
00114 ostr << "Starting server at port " << iiopInfo->port() << ends;
00115 message(ostr.str());
00116 ostr.freeze(0);
00117 }
00118 }
00119
00120
00121 //POACurrent
00122 CORBA::Object_var currObj = _orb->resolve_initial_references("POACurrent");
00123 _poaCurrent = PortableServer::Current::_narrow(currObj);
00124
00125 //Initial POA
00126 message("Creating POA for initial objects:");
00127 CORBA::PolicyList policies;
00128 policies.length(2);
00129 policies[0] = _rootPOA->create_id_assignment_policy(PortableServer::USER_ID);
00130 policies[1] = _rootPOA->create_lifespan_policy(PortableServer::PERSISTENT);
00131 _initialPOA = _rootPOA->create_POA("InitialPOA", poa_manager, policies);
00132
00133 //BootManager (ORBacus specific)
00134 CORBA::Object_var bootObj = _orb->resolve_initial_references("BootManager");
00135 _bootMgr = OB::BootManager::_narrow(bootObj);
00136
00137 addInitialObject("Constructor", new HxConstructorServant());
00138 addInitialObject("GlobalOps", new HxGlobalOpsServant(this));
00139 addInitialObject("Registry", new HxRegistryServant());
00140 addInitialObject("Test", new HxTestServant());
00141 addInitialObject("Configure", new HxConfigureServant());
00142
00143 /*CORBA::Object_var poaMgrObj = _orb->resolve_initial_references("POAManagerFactory");
00144 OBPortableServer::POAManagerFactory_var factory =
00145 OBPortableServer::POAManagerFactory::_narrow(poaMgrObj);
00146 PortableServer::POAManager_var dataPOAManager =
00147 factory -> create_poa_manager("data");*/
00148
00149 //Data POA
00150 message("Creating POA for data");
00151 policies.length(0);
00152 _dataPOA = _rootPOA->create_POA(dataPOAname, poa_manager, policies);
00153 //_dataPOA = _rootPOA->create_POA(dataPOAname, dataPOAManager, policies);
00154 //dataPOAManager->activate();
00155
00156 //Activate POAManager
00157 poa_manager->activate();
00158
00159 //Set HxEnvironment
00160 HxEnvCorba *env = new HxEnvCorba();
00161
00162 //In case of collocated... (ORBacus specific)
00163 #if (OB_INTEGER_VERSION < 4000500L)
00164 OBCORBA::ORB_var oborb = OBCORBA::ORB::_narrow(_orb);
00165 oborb -> run_init();
00166 #endif
00167 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.2.12 written by Dimitri van Heesch,
© 1997-2001