Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Smart_Proxies / client.cpp
blobf6bdb2903938a234bc3fcc7b367238936ef87aed
2 //=============================================================================
3 /**
4 * @file client.cpp
6 * This is the client program that tests TAO's Smart Proxy extension.
8 * @author Kirthika Parameswaran <kirthika@cs.wustl.edu>
9 */
10 //=============================================================================
13 #include "ace/Get_Opt.h"
14 #include "testC.h"
15 #include "Smart_Proxy_Impl.h"
16 #include "ace/OS_NS_string.h"
17 #include "ace/OS_NS_unistd.h"
19 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
21 int
22 parse_args (int argc, ACE_TCHAR *argv[])
24 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("i:"));
25 int c;
27 while ((c = get_opts ()) != -1)
28 switch (c)
30 case 'i':
31 ior = get_opts.opt_arg ();
32 break;
33 case '?':
34 default:
35 ACE_ERROR_RETURN ((LM_ERROR,
36 "usage: %s "
37 "-i "
38 "\n",
39 argv [0]),
40 -1);
42 return 0;
45 int
46 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
48 int status = 0;
49 try
51 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
53 if (parse_args (argc, argv) != 0)
54 return 1;
56 CORBA::Object_var object =
57 orb->string_to_object (ior);
59 // To use the smart proxy it is necessary to allocate the
60 // user-defined smart factory on the heap as the smart proxy
61 // generated classes take care of destroying the object. This
62 // way it a win situation for the application developer who
63 // doesnt have to make sure to destroy it and also for the smart
64 // proxy designer who now can manage the lifetime of the object
65 // much surely.
66 Smart_Test_Factory *test_factory = 0;
67 ACE_NEW_RETURN (test_factory,
68 Smart_Test_Factory,
69 -1);
71 ACE_UNUSED_ARG (test_factory);
73 Test_var server =
74 Test::_narrow (object.in ());
76 if (CORBA::is_nil (server.in ()))
77 ACE_ERROR_RETURN ((LM_ERROR,
78 "Object reference <%s> is nil.\n",
79 ior),
80 1);
82 try
84 CORBA::String_var sm_ior = orb->object_to_string (server.in ());
85 if (Smart_Test_Proxy::fake_ior () != sm_ior.in ())
87 status = 1;
88 ACE_ERROR ((LM_ERROR,
89 "ERROR: The Smart Proxy IOR is:\n%C\n"
90 "but should have been: %C\n",
91 sm_ior.in (),
92 Smart_Test_Proxy::fake_ior ().c_str ()));
95 catch (const CORBA::MARSHAL& ex)
97 status = 1;
98 ex._tao_print_exception ("Unexpected MARSHAL exception:");
101 server->method (0);
103 server->shutdown ();
105 // The following sleep is a hack to make sure the above oneway
106 // request gets sent before we exit. Otherwise, at least on
107 // Windows XP, the server may not even get the request.
108 ACE_Time_Value tv (0, 100000);
109 ACE_OS::sleep(tv);
111 orb->destroy ();
113 catch (const CORBA::Exception& ex)
115 ex._tao_print_exception ("Client-side exception:");
116 status = 1;
119 return status;