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
|
// -*- C++ -*-
/*
* $Id$
*/
#include "tao/DynamicInterface/Request.h" /* This must come first for
G++ 3.4 or better */
#include "tao/debug.h"
#include "ace/Get_Opt.h"
#include "ace/Task.h"
#include "ace/Log_Msg.h"
#include "DII_ReplyHandler.h"
#include "tao/AnyTypeCode/Any.h"
#include "tao/PortableServer/POAC.h"
#include "tao/PortableServer/POAManagerC.h"
const ACE_TCHAR *ior = ACE_TEXT("file://server.ior");
int do_shutdown = 0;
int
parse_args (int argc, ACE_TCHAR *argv[])
{
ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("xk:"));
int c;
while ((c = get_opts ()) != -1)
switch (c)
{
case 'x':
do_shutdown = 1;
break;
case 'k':
ior = get_opts.optarg;
break;
case '?':
default:
ACE_ERROR_RETURN ((LM_ERROR,
"usage: %s "
"-x "
"-k <ior> "
"\n",
argv [0]),
-1);
}
// Indicates sucessful parsing of the command line
return 0;
}
void
do_primary_test (CORBA::Object_var &server,
Messaging::ReplyHandler_var &callback)
{
try
{
CORBA::Request_var req = server->_request("do_forward");
if (CORBA::is_nil (server.in ()))
{
ACE_ERROR ((LM_ERROR,
"Object reference <%C> is nil.\n",
ior));
return;
}
ACE_DEBUG((LM_DEBUG,"Client sending test string\n"));
CORBA::String_var test_string = CORBA::string_dup ("123 look at me");
req->add_in_arg ("text") <<=
CORBA::Any::from_string(test_string.in(),30);
req->sendc(callback.in());
}
catch (CORBA::Exception &ex)
{
ACE_ERROR ((LM_ERROR,
"Client caught exception: %s\n",ex._name()));
}
}
int do_shutdown_test (CORBA::Object_var &server)
{
ACE_DEBUG ((LM_DEBUG,
"[client] invoking shutdown on the server \n "));
try
{
CORBA::Request_var req = server->_request("shutdown");
req->invoke();
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Client: exception caught during shutdown - ");
return 1;
}
return 0;
}
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
if (parse_args (argc, argv) != 0)
return 1;
int result = 0;
ACE_DEBUG ((LM_DEBUG,"Client using ior source %s\n", ior));
CORBA::Object_var server = orb->string_to_object (ior);
CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
PortableServer::POA_var root =
PortableServer::POA::_narrow (obj.in());
PortableServer::POAManager_var pm = root->the_POAManager();
pm->activate();
bool got_reply = false;
Messaging::ReplyHandler_var callback = new DII_ReplyHandler(got_reply);
do_primary_test (server,callback);
for (int i = 0; i < 100 && !got_reply; i++)
{
ACE_Time_Value t(0,10000);
orb->perform_work(t);
}
if (do_shutdown)
result = do_shutdown_test (server);
ACE_DEBUG ((LM_DEBUG,"Shutting down and destrying ORB.\n"));
orb->destroy();
ACE_DEBUG ((LM_DEBUG,"ORB destroyed\n"));
return result;
}
|