3 #include "tao/IORTable/IORTable.h"
4 #include "tao/PortableServer/Root_POA.h"
6 #include "ace/Dynamic_Service.h"
10 using namespace PortableServer
;
12 DynServer::DynServer()
17 DynServer::~DynServer() {
22 ACE_DEBUG((LM_DEBUG
, "dynserver: get() %d\n", ++n_
));
27 POA_ptr
createPersistPOA(const char* name
, POA_ptr root_poa
, POAManager_ptr poaman
)
29 PolicyList
policies (2);
31 policies
[0] = root_poa
->create_id_assignment_policy(USER_ID
);
32 policies
[1] = root_poa
->create_lifespan_policy(PERSISTENT
);
33 POA_var poa
= root_poa
->create_POA(name
, poaman
, policies
);
34 policies
[0]->destroy();
35 policies
[1]->destroy();
40 class DynServer_ORB_Runner
: public ACE_Task_Base
44 DynServer_ORB_Runner(ORB_ptr orb
)
45 : orb_(ORB::_duplicate(orb
))
49 if (! is_nil(orb_
.in())) {
62 DynServer_Loader::DynServer_Loader()
67 DynServer_Loader::init (int argc
, ACE_TCHAR
* argv
[])
70 orb_
= ORB_init(argc
, argv
, "DynServer");
72 Object_var obj
= orb_
->resolve_initial_references("RootPOA");
73 root_poa_
= POA::_narrow(obj
.in());
74 POAManager_var poaman
= root_poa_
->the_POAManager();
75 obj
= this->orb_
->resolve_initial_references ("IORTable");
76 IORTable::Table_var ior_table
= IORTable::Table::_narrow (obj
.in());
77 ACE_ASSERT(! is_nil(ior_table
.in()));
79 ACE_DEBUG((LM_DEBUG
, "dynserver: creating poas. (Registers with ImR)\n"));
81 POA_var poa1
= createPersistPOA("DynObject1", root_poa_
.in(), poaman
.in());
82 POA_var poa2
= createPersistPOA("DynObject2", root_poa_
.in(), poaman
.in());
84 ACE_DEBUG((LM_DEBUG
, "dynserver: activating objects.\n"));
86 DynServer
* svt1
= new DynServer
;
87 ServantBase_var
scoped_svt1(svt1
);
88 DynServer
* svt2
= new DynServer
;
89 ServantBase_var
scoped_svt2(svt2
);
91 ObjectId_var id
= string_to_ObjectId("myobject");
93 poa1
->activate_object_with_id(id
.in(), svt1
);
94 poa2
->activate_object_with_id(id
.in(), svt2
);
96 TAO_Root_POA
* tmp_poa
= dynamic_cast<TAO_Root_POA
*>(poa1
.in());
97 obj
= tmp_poa
->id_to_reference_i (id
.in(), false);
98 String_var ior
= orb_
->object_to_string(obj
.in());
99 ior_table
->bind ("DynObject1", ior
.in());
101 tmp_poa
= dynamic_cast<TAO_Root_POA
*>(poa2
.in());
102 obj
= tmp_poa
->id_to_reference_i (id
.in(), false);
103 ior
= orb_
->object_to_string(obj
.in());
104 ior_table
->bind ("DynObject2", ior
.in());
108 runner_
.reset(new DynServer_ORB_Runner(orb_
.in()));
111 ACE_DEBUG((LM_DEBUG
, "dynserver: running.\n"));
112 } catch (Exception
& e
) {
113 e
._tao_print_exception ("DynServer::init()");
119 DynServer_Loader::fini ()
121 ACE_ASSERT(runner_
.get() != 0);
123 ACE_DEBUG((LM_DEBUG
, "dynserver: shutting down.\n"));
128 root_poa_
->destroy(1, 1);
131 ACE_DEBUG((LM_DEBUG
, "dynserver: shut down successfully.\n"));
134 } catch (Exception
& e
) {
135 e
._tao_print_exception ("DynServer::fini()");
141 DynServer_Loader::create_object (ORB_ptr
,
145 throw NO_IMPLEMENT();
148 ACE_FACTORY_DEFINE (DynServer
, DynServer_Loader
)