Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Bug_2356_Regression / client.cpp
blob5d9afb6e56bd7354093fcb638271d736b2fd4217
2 //=============================================================================
3 /**
4 * @file client.cpp
6 * A very simple client which uses the AMI callback model.
8 * @author Johnny Willemsen <jwillemsen@remedy.nl>
9 */
10 //=============================================================================
13 #include "ace/Get_Opt.h"
14 #include "ace/Task.h"
16 #include "ami_testS.h"
17 #include "tao/Codeset/Codeset.h"
19 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
20 int niterations = 5;
21 int shutdown_flag = 1;
22 int debug = 0;
23 int result = 0;
25 int
26 parse_args (int argc, ACE_TCHAR *argv[])
28 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("dk:"));
29 int c;
31 while ((c = get_opts ()) != -1)
32 switch (c)
34 case 'd':
35 debug = 1;
36 break;
37 case 'k':
38 ior = get_opts.opt_arg ();
39 break;
40 case '?':
41 default:
42 ACE_ERROR_RETURN ((LM_ERROR,
43 "usage: %s "
44 "-k <ior> "
45 "\n",
46 argv [0]),
47 -1);
49 // Indicates successful parsing of the command line
50 return 0;
53 class Handler : public POA_A::AMI_AMI_TestHandler
55 public:
56 /// Constructor.
57 Handler () = default;
59 /// Destructor.
60 ~Handler () = default;
62 void foo ()
66 void foo_excep (::Messaging::ExceptionHolder * excep_holder)
68 ACE_DEBUG ((LM_DEBUG,
69 "Callback method <foo_excep> called:\n"
70 "Testing proper exception handling ...\n"));
71 try
73 excep_holder->raise_exception ();
75 catch (const A::DidTheRightThing& ex)
77 ACE_DEBUG ((LM_DEBUG,
78 "... exception received successfully: <%d>\n",
79 ex.id));
80 #if defined(ACE_HAS_WCHAR) || defined(ACE_HAS_XPG4_MULTIBYTE_CHAR)
81 ACE_HEX_DUMP((LM_DEBUG,
82 reinterpret_cast<char const *>(ex.whatDidTheRightThing.in()),
83 ACE_OS::strlen(ex.whatDidTheRightThing.in()) * sizeof(CORBA::WChar)
84 ));
86 CORBA::WChar const* wstring = L"Hello world";
87 #else
88 CORBA::WChar const empty[] = { 0 };
89 CORBA::WChar const* wstring = empty;
90 #endif
91 if (ACE_OS::strcmp (wstring, ex.whatDidTheRightThing.in()) != 0)
93 ex._tao_print_exception ("ERROR");
94 ACE_ERROR ((LM_ERROR,
95 "... caught the exception but got wrong wstring -> ERROR\n"));
96 result = 1;
99 catch (const CORBA::Exception& ex)
101 ex._tao_print_exception ("ERROR");
102 ACE_ERROR ((LM_ERROR,
103 "... caught the wrong exception -> ERROR\n"));
104 result = 1;
110 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
114 CORBA::ORB_var orb =
115 CORBA::ORB_init (argc, argv);
117 CORBA::Object_var object_var =
118 orb->resolve_initial_references ("RootPOA");
120 PortableServer::POA_var poa_var =
121 PortableServer::POA::_narrow (object_var.in ());
123 PortableServer::POAManager_var poa_manager_var =
124 poa_var->the_POAManager ();
126 poa_manager_var->activate ();
128 if (parse_args (argc, argv) != 0)
129 return 1;
131 // We reuse the object_var smart pointer!
132 object_var = orb->string_to_object (ior);
134 A::AMI_Test_var ami_test_var =
135 A::AMI_Test::_narrow (object_var.in ());
137 if (CORBA::is_nil (ami_test_var.in ()))
139 ACE_ERROR_RETURN ((LM_ERROR,
140 "Object reference <%s> is nil.\n",
141 ior),
145 // Instantiate the ReplyHandler and register that with the POA.
146 Handler handler;
147 PortableServer::ObjectId_var id =
148 poa_var->activate_object (&handler);
150 CORBA::Object_var object = poa_var->id_to_reference (id.in ());
152 A::AMI_AMI_TestHandler_var the_handler_var =
153 A::AMI_AMI_TestHandler::_narrow (object.in ());
155 // Trigger the DidTheRightThing exception on the server side
156 // by sending 0 to it.
157 ACE_DEBUG ((LM_DEBUG,
158 "Sending asynch message\n"));
160 ami_test_var->sendc_foo (the_handler_var.in (), 0);
162 if (debug)
164 ACE_DEBUG ((LM_DEBUG,
165 "Issuing a synchronous method to collect the AMI replies\n"));
168 ami_test_var->foo (1);
170 if (shutdown_flag)
172 ami_test_var->shutdown ();
175 poa_var->destroy (1, // ethernalize objects
176 0); // wait for completion
178 orb->destroy ();
180 catch (const CORBA::Exception& ex)
182 ex._tao_print_exception ("Caught exception:");
183 return 1;
186 return result;