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
|
// $Id$
#include "ServantList_T.h"
#include "AppHelper.h"
#include "TestAppExceptionC.h"
template <typename T>
ServantList<T>::ServantList()
{
}
template <typename T>
ServantList<T>::~ServantList()
{
}
template <typename T>
void
ServantList<T>::create_and_activate(unsigned num_servants,
CORBA::ORB_ptr orb,
PortableServer::POA_ptr poa,
const char* ior_fname_prefix
ACE_ENV_ARG_DECL)
{
for (unsigned i = 0; i < num_servants; i++)
{
char buf[32];
ACE_OS::sprintf(buf, "%02d", i + 1);
ACE_CString filename = ACE_CString(ior_fname_prefix) + "_" + buf + ".ior";
ServantRecord record;
record.servant_ = new T();
record.safe_servant_ = record.servant_;
CORBA::Object_var obj
= AppHelper::activate_servant(poa,
record.safe_servant_.in()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
AppHelper::ref_to_file(orb, obj.in(), filename.c_str() ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
record.obj_ = T_stub::_narrow(obj.in() ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
if (CORBA::is_nil(record.obj_.in()))
{
ACE_THROW (TestAppException());
}
this->servant_records_.push_back(record);
}
}
template <typename T>
void
ServantList<T>::create_and_activate(unsigned num_servants,
PortableServer::POA_ptr poa
ACE_ENV_ARG_DECL)
{
for (unsigned i = 0; i < num_servants; i++)
{
ServantRecord record;
record.servant_ = new T();
record.safe_servant_ = record.servant_;
CORBA::Object_var obj
= AppHelper::activate_servant(poa,
record.safe_servant_.in()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
record.obj_ = T_stub::_narrow(obj.in() ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
if (CORBA::is_nil(record.obj_.in()))
{
ACE_THROW (TestAppException());
}
this->servant_records_.push_back(record);
}
}
// Code for reference - doesn't work right now
#if 0
template <typename T>
void
ServantList<T>::deactivate(PortableServer::POA_ptr poa)
{
ServantRecord record;
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
PortableServer::ObjectId_var id =
poa->servant_to_id(record.safe_servant_.in() ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
poa->deactivate_object(id.in() ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"ServantList_T::deactivate_servant ()");
}
ACE_CATCHALL
{
ACE_ERROR((LM_ERROR, "(%P|%t)ServantList_T::deactivate_servant "
"Caught unknown exception \n"));
}
ACE_ENDTRY;
ACE_CHECK;
}
#endif
template <typename T>
typename ServantList<T>::T_stub_ptr
ServantList<T>::objref(unsigned index)
{
return T_stub::_duplicate(this->servant_records_[index].obj_.in());
}
template <typename T>
T*
ServantList<T>::servant(unsigned index)
{
return this->servant_records_[index].servant_;
}
|