Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Smart_Proxies / Policy / client.cpp
blobb28fe0a4b24e97cdc2fa42a4a5a967cb38897ff8
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 "ace/OS_NS_string.h"
15 #include "testC.h"
16 #include "Smart_Proxy_Impl.h"
18 const ACE_TCHAR *ior1 = ACE_TEXT("file://test1.ior");
19 const ACE_TCHAR *ior2 = ACE_TEXT("file://test2.ior");
20 int one_shot_factory = 1;
22 int
23 parse_args (int argc, ACE_TCHAR *argv[])
25 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("i:j:f:"));
26 int c;
28 while ((c = get_opts ()) != -1)
29 switch (c)
31 case 'i':
32 ior1 = get_opts.opt_arg ();
33 break;
34 case 'j':
35 ior2 = get_opts.opt_arg ();
36 break;
37 case 'f':
38 one_shot_factory = ACE_OS::atoi (get_opts.opt_arg ());
39 break;
40 case '?':
41 default:
42 ACE_ERROR_RETURN ((LM_ERROR,
43 "usage: %s "
44 "-i -j -f"
45 "\n",
46 argv [0]),
47 -1);
49 return 0;
52 int
53 run_test (CORBA::ORB_ptr orb_ptr,
54 int target)
56 CORBA::ORB_var orb = CORBA::ORB::_duplicate (orb_ptr);
57 CORBA::Object_var object;
58 try
60 if (target == 1)
62 object =
63 orb->string_to_object (ior1);
65 else
67 object =
68 orb->string_to_object (ior2);
71 Test_var server =
72 Test::_narrow (object.in ());
74 if (CORBA::is_nil (server.in ()))
75 ACE_ERROR_RETURN ((LM_ERROR,
76 "Object reference is nil\n"),
77 1);
79 server->method (0);
81 server->shutdown ();
83 catch (const CORBA::Exception& ex)
85 ex._tao_print_exception ("Client-side exception:");
87 return 0;
90 int
91 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
93 try
95 CORBA::ORB_var orb =
96 CORBA::ORB_init (argc,
97 argv);
99 if (parse_args (argc, argv) != 0)
100 return 1;
102 // To use the smart proxy it is necessary to allocate the
103 // user-defined smart factory on the heap as the smart proxy
104 // generated classes take care of destroying the object. This
105 // way it a win situation for the application developer who
106 // doesnt have to make sure to destroy it and also for the smart
107 // proxy designer who now can manage the lifetime of the object
108 // much surely.
109 // By default this factory is permanent (i.e. registered for
110 // this interface) but if there is a need for flexibility per
111 // object instance then <one_shot_factory> needs to be set to 0.
112 Smart_Test_Factory *test_factory = 0;
113 ACE_NEW_RETURN (test_factory,
114 Smart_Test_Factory (one_shot_factory),
115 -1);
117 ACE_UNUSED_ARG (test_factory);
119 run_test (orb.in (), 1);
120 run_test (orb.in (), 2);
122 orb->destroy ();
124 catch (const CORBA::Exception& ex)
126 ex._tao_print_exception ("Client-side exception:");
127 return 1;
130 return 0;