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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
//=============================================================================
/**
* @file objref.cpp
*
* tests object references
*
* @author Aniruddha Gokhale
*/
//=============================================================================
#include "helper.h"
#include "objref.h"
// ************************************************************************
// Test_ObjRef
// ************************************************************************
Test_ObjRef::Test_ObjRef (void)
: opname_ (CORBA::string_dup ("test_objref"))
{
}
Test_ObjRef::~Test_ObjRef (void)
{
CORBA::string_free (this->opname_);
this->opname_ = 0;
}
const char *
Test_ObjRef::opname () const
{
return this->opname_;
}
void
Test_ObjRef::dii_req_invoke (CORBA::Request *req)
{
req->add_in_arg ("s1") <<= this->in_.in ();
req->add_inout_arg ("s2") <<= this->inout_.in ();
req->add_out_arg ("s3") <<= this->out_.in ();
req->set_return_type (_tc_Coffee);
req->invoke ();
Coffee_ptr tmp;
req->return_value () >>= tmp;
this->ret_ = Coffee::_duplicate (tmp);
CORBA::NamedValue_ptr o2 =
req->arguments ()->item (1);
*o2->value () >>= tmp;
this->inout_ = Coffee::_duplicate (tmp);
CORBA::NamedValue_ptr o3 =
req->arguments ()->item (2);
*o3->value () >>= tmp;
this->out_ = Coffee::_duplicate (tmp);
}
static const char *Coffee_Flavor [] = {
"Italian Roast",
"Irish Creme",
"Costa Rican",
"Colombian Supremo",
"Macademia Nut",
"Swiss Chocolate Mocha"
};
int
Test_ObjRef::init_parameters (Param_Test_ptr objref)
{
Coffee::Desc desc;
Generator *gen = GENERATOR::instance (); // value generator
char msg_str[256] = "";
try
{
ACE_OS::strcpy (msg_str, "make_cofee");
// first get a Coffee object
this->in_ = objref->make_coffee ();
// Get some index into Coffee_Flavor [].
CORBA::ULong index = (CORBA::ULong) (gen->gen_long () % 6);
desc.name = Coffee_Flavor [index];
// set the attribute of the object
ACE_OS::strcpy (msg_str, "set coffee attribute");
this->in_->description (desc); // set the attribute for the in object
this->inout_ = Coffee::_nil ();
this->out_ = Coffee::_nil ();
this->ret_ = Coffee::_nil ();
return 0;
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception (msg_str);
}
return -1;
}
int
Test_ObjRef::reset_parameters (void)
{
// Environemnt variable
Coffee::Desc desc;
Generator *gen = GENERATOR::instance (); // value generator
// Get some index into Coffee_Flavor [].
CORBA::ULong index = (CORBA::ULong) (gen->gen_long () % 6);
desc.name = Coffee_Flavor [index];
try
{
// set the attribute of the object
this->in_->description (desc); // set the attribute for the in object
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("set coffee attribute");
return -1;
}
this->inout_ = Coffee::_nil ();
this->out_ = Coffee::_nil ();
this->ret_ = Coffee::_nil ();
return 0;
}
int
Test_ObjRef::run_sii_test (Param_Test_ptr objref)
{
try
{
this->ret_ =
objref->test_objref (this->in_.in (),
this->inout_.inout (),
this->out_.out ());
return 0;
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Test_ObjRef::run_sii_test\n");
}
return -1;
}
CORBA::Boolean
Test_ObjRef::check_validity (void)
{
// Environemnt variable
try
{
if (CORBA::is_nil (this->in_.in ())
|| CORBA::is_nil (this->inout_.in ())
|| CORBA::is_nil (this->out_.in ())
|| CORBA::is_nil (this->ret_.in ()))
{
ACE_ERROR ((LM_ERROR, "Nil object references returned\n"));
return 0;
}
Coffee::Desc_var in_desc =
this->in_->description ();
const char *in = in_desc->name.in ();
Coffee::Desc_var inout_desc =
this->inout_->description ();
const char *inout = inout_desc->name.in ();
Coffee::Desc_var out_desc =
this->out_->description ();
const char *out = out_desc->name.in ();
Coffee::Desc_var ret_desc = this->out_->description ();
const char* ret = ret_desc->name.in ();
// now compare them
if (!ACE_OS::strcmp (in, inout) &&
!ACE_OS::strcmp (in, out) &&
!ACE_OS::strcmp (in, ret))
return 1; // success
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Retrieving description");
return 0;
}
return 1;
}
CORBA::Boolean
Test_ObjRef::check_validity (CORBA::Request_ptr)
{
return this->check_validity ();
}
void
Test_ObjRef::print_values (void)
{
// Env. variable
Coffee::Desc_var in_desc;
Coffee::Desc_var inout_desc;
Coffee::Desc_var out_desc;
Coffee::Desc_var ret_desc;
const char *in = 0;
const char *out = 0;
const char *inout = 0;
const char *ret = 0;
try
{
if (!CORBA::is_nil (this->in_.in ()))
{
in_desc =
this->in_->description ();
in = in_desc->name.in ();
}
if (!CORBA::is_nil (this->inout_.in ()))
{
inout_desc =
this->inout_->description ();
inout = inout_desc->name.in ();
}
if (!CORBA::is_nil (this->out_.in ()))
{
out_desc =
this->out_->description ();
out = out_desc->name.in ();
}
if (!CORBA::is_nil (this->ret_.in ()))
{
ret_desc =
this->ret_->description ();
ret = ret_desc->name.in ();
}
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Retrieving Description");
return;
}
ACE_DEBUG ((LM_DEBUG,
"\n=*=*=*=*=*=*"
"in = %C, "
"inout = %C, "
"out = %C, "
"ret = %C*=*=*=*=*=\n",
in?in:"ERROR(null string)",
inout?inout:"ERROR(null string)",
out?out:"ERROR(null string)",
ret?ret:"ERROR(null string)"
));
}
|