summaryrefslogtreecommitdiff
path: root/TAO/tests/Bug_1869_Regression/server.cpp
blob: 6b741d07984c33b7fb1581dea047f20a677587b5 (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
82
83
84
85
86
87
// $Id$

#include "AMIS.h"
#include "tao/IORTable/IORTable.h"

class  AdderServant :
  public POA_AMI_test::adder {

public:
  AdderServant (void) {}

  virtual ~AdderServant (void) {}

  virtual
  CORBA::Long add (
      CORBA::Long a,
      CORBA::Long b
    )
    ACE_THROW_SPEC ((
      CORBA::SystemException
    )) {
      return a + b;
    }
};


int main (int argc, char* 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;
}