Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / DII_AMI_Forward / client.cpp
bloba63a9402ebdbf4b83bb87a6e1e4099b24a369d01
1 // -*- C++ -*-
4 #include "tao/DynamicInterface/Request.h" /* This must come first for
5 G++ 3.4 or better */
6 #include "tao/debug.h"
7 #include "ace/Get_Opt.h"
8 #include "ace/Task.h"
9 #include "ace/Log_Msg.h"
10 #include "DII_ReplyHandler.h"
11 #include "tao/AnyTypeCode/Any.h"
12 #include "tao/PortableServer/POAC.h"
13 #include "tao/PortableServer/POAManagerC.h"
15 const ACE_TCHAR *ior = ACE_TEXT("file://server.ior");
17 int do_shutdown = 0;
19 int
20 parse_args (int argc, ACE_TCHAR *argv[])
22 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("xk:"));
23 int c;
25 while ((c = get_opts ()) != -1)
26 switch (c)
28 case 'x':
29 do_shutdown = 1;
30 break;
32 case 'k':
33 ior = get_opts.optarg;
34 break;
36 case '?':
37 default:
38 ACE_ERROR_RETURN ((LM_ERROR,
39 "usage: %s "
40 "-x "
41 "-k <ior> "
42 "\n",
43 argv [0]),
44 -1);
47 // Indicates successful parsing of the command line
48 return 0;
51 void
52 do_primary_test (CORBA::Object_var &server,
53 Messaging::ReplyHandler_var &callback)
55 try
57 CORBA::Request_var req = server->_request("do_forward");
59 if (CORBA::is_nil (server.in ()))
61 ACE_ERROR ((LM_ERROR,
62 "Object reference <%s> is nil.\n",
63 ior));
64 return;
67 ACE_DEBUG((LM_DEBUG,"Client sending test string\n"));
68 CORBA::String_var test_string = CORBA::string_dup ("123 look at me");
69 req->add_in_arg ("text") <<=
70 CORBA::Any::from_string(test_string.in(),30);
71 req->sendc(callback.in());
73 catch (const CORBA::Exception &ex)
75 ACE_ERROR ((LM_ERROR,
76 "Client caught exception: %C\n",ex._name()));
80 int do_shutdown_test (CORBA::Object_var &server)
82 ACE_DEBUG ((LM_DEBUG,
83 "[client] invoking shutdown on the server \n"));
84 try
86 CORBA::Request_var req = server->_request("shutdown");
87 req->invoke();
89 catch (const CORBA::Exception& ex)
91 ex._tao_print_exception ("Client: exception caught during shutdown - ");
92 return 1;
94 return 0;
98 int
99 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
101 int result = 0;
105 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
107 if (parse_args (argc, argv) != 0)
108 return 1;
110 ACE_DEBUG ((LM_DEBUG,"Client using ior source %s\n", ior));
111 CORBA::Object_var server = orb->string_to_object (ior);
113 CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
114 PortableServer::POA_var root =
115 PortableServer::POA::_narrow (obj.in());
117 PortableServer::POAManager_var pm = root->the_POAManager();
118 pm->activate();
119 bool got_reply = false;
120 Messaging::ReplyHandler_var callback = new DII_ReplyHandler(got_reply);
122 do_primary_test (server,callback);
124 for (int i = 0; i < 100 && !got_reply; i++)
126 ACE_Time_Value t(0,10000);
127 orb->perform_work(t);
130 if (do_shutdown)
131 result = do_shutdown_test (server);
133 ACE_DEBUG ((LM_DEBUG,"Shutting down and destrying ORB.\n"));
134 orb->destroy();
135 ACE_DEBUG ((LM_DEBUG,"ORB destroyed\n"));
137 catch (const ::CORBA::Exception &ex)
139 ex._tao_print_exception("ERROR : unexpected CORBA exception caugth :");
140 ++result;
142 return result;