blob: 946f04972aba392b2bf9a8501946aaf747e78355 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#include "AMIS.h"
#include "tao/IORTable/IORTable.h"
class AdderServant :
public POA_AMI_test::adder {
public:
AdderServant () {}
virtual ~AdderServant () {}
virtual
CORBA::Long add (
CORBA::Long a,
CORBA::Long b
)
{
return a + b;
}
};
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) {
try {
CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
// Get reference to Root POA
CORBA::Object_var obj
= orb->resolve_initial_references ("RootPOA");
PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (obj.in ());
// Activate POA manager
PortableServer::POAManager_var mgr
= rootPOA->the_POAManager ();
mgr->activate();
// Create Persistent Lifespan Policy and User Id Policy
PortableServer::LifespanPolicy_var lifespan =
rootPOA->create_lifespan_policy(PortableServer::PERSISTENT);
PortableServer::IdAssignmentPolicy_var idassignment =
rootPOA->create_id_assignment_policy(PortableServer::USER_ID);
// Stuff them into a policy list
CORBA::PolicyList policies(2);
policies.length(2);
policies[0] = PortableServer::IdAssignmentPolicy::_duplicate(idassignment.in());
policies[1] = PortableServer::LifespanPolicy::_duplicate(lifespan.in());
// Create the Child POA
PortableServer::POA_var persistentPOA =
rootPOA->create_POA("persistentPOA", mgr.in(), policies);
// Policies are no longer needed
idassignment->destroy();
lifespan->destroy();
AdderServant servant;
// Create an id
PortableServer::ObjectId_var oid =
PortableServer::string_to_ObjectId("Adder");
// Activate the object (with id)
persistentPOA->activate_object_with_id(oid.in(), & servant);
CORBA::Object_var ref = persistentPOA->id_to_reference(oid.in());
CORBA::String_var iors = orb->object_to_string(ref.in());
CORBA::Object_var tobj = orb->resolve_initial_references("IORTable");
IORTable::Table_var table = IORTable::Table::_narrow(tobj.in());
table->bind("Adder", iors.in ());
orb->run();
} catch (...) {
ACE_ERROR ((LM_ERROR, "ERROR: Caught exception in server"));
return 1;
}
return 0;
}
|