summaryrefslogtreecommitdiff
path: root/TAO/tests/Bug_2936_Regression/PersistentPOA.cpp
blob: 97e8ee72f659c3ee6190628d5226f7ccce5ca46e (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

#include "ace/Arg_Shifter.h"
#include "tao/PortableServer/POAManager.h"
#include "tao/PortableServer/PortableServer.h"

#include "PersistentPOA.h"
#include "DllORB.h"

const ACE_TCHAR *POAname_ = 0;
const ACE_TCHAR *ORBname_ = 0;

PersistentPoa::PersistentPoa ()
{
}


PersistentPoa::~PersistentPoa ()
  throw ()
{
}


int PersistentPoa::init (int argc, ACE_TCHAR *argv[])
{
  int result = 0;

  ACE_Arg_Shifter as(argc, argv);
  POAname_ = as.get_current();
  as.ignore_arg();

  ORBname_ = as.get_current();
  as.ignore_arg();

  while(as.is_anything_left())
  {
    as.ignore_arg();
  }

  try
  {
    DllORB * p_orb = ACE_Dynamic_Service<DllORB>::instance (ORBname_);

    mv_orb = p_orb->orb();

    CORBA::Object_var v_poa = mv_orb->resolve_initial_references("RootPOA");

    mv_rootPOA = PortableServer::POA::_narrow(v_poa.in ());

    if(CORBA::is_nil(mv_rootPOA.in()))
    {
      ACE_DEBUG((
        LM_DEBUG,
        ACE_TEXT ("(%P|%t) init - nil root POA\n")
      ));
      return -1;
    }

    // Policies for the new POA
    CORBA::PolicyList policies(3);
    policies.length (3);

    // Threading policy
    policies[0] = mv_rootPOA->create_thread_policy(PortableServer::ORB_CTRL_MODEL);

    // Lifespan policy
    policies[1] = mv_rootPOA->create_lifespan_policy(PortableServer::PERSISTENT);

    // ID assignment policy
    policies[2] = mv_rootPOA->create_id_assignment_policy(PortableServer::USER_ID);

    mv_thisPOA = mv_rootPOA->create_POA(
      ACE_TEXT_ALWAYS_CHAR(POAname_),
      PortableServer::POAManager::_nil(),
      policies);
    if (CORBA::is_nil(mv_thisPOA.in()))
    {
      ACE_DEBUG((
        LM_DEBUG,
        ACE_TEXT ("(%P|%t) init - POA creation failed\n")
      ));
      return -1;
    }
    else
    {
      ACE_DEBUG((
        LM_DEBUG,
        ACE_TEXT ("(%P|%t) init - POA created\n")
      ));
    }

    mv_poaManager = mv_thisPOA->the_POAManager();

    mv_poaManager->activate();
    ACE_DEBUG((
      LM_DEBUG,
      ACE_TEXT ("(%P|%t) init - activated POA manager\n")
    ));
  }
  catch(...)
  {
    ACE_DEBUG((
      LM_DEBUG,
      ACE_TEXT ("(%P|%t) init - exception\n")
    ));
    result = -1;
    return result;
  }

  ACE_DEBUG((
    LM_DEBUG,
    ACE_TEXT ("(%P|%t) init - POA activated\n")
  ));

  return result;
}


int PersistentPoa::fini ()
{
  int result = 0;

  try
  {
    mv_poaManager->deactivate(1, 1);
    mv_thisPOA->destroy(1, 1);
    mv_thisPOA = PortableServer::POA::_nil();
  }
  catch(...)
  {
    ACE_DEBUG((
      LM_DEBUG,
      ACE_TEXT ("(%P|%t) init - exception\n")
    ));
    result = -1;
    return result;
  }
  ACE_DEBUG((
    LM_DEBUG,
    ACE_TEXT ("(%P|%t) fini - POA deactivated\n")
  ));

  return result;
}

ACE_FACTORY_DEFINE (bug2936, PersistentPoa)