Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / DevGuideExamples / Multithreading / GracefulShutdown / MessengerClient.cpp
blobd86f8e03fc6584434ec76b896fa2eec517f6ee79
1 #include "MessengerC.h"
2 #include "ace/Get_Opt.h"
3 #include <iostream>
5 int call_shutdown = 0;
6 const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior");
8 int parse_args (int argc, ACE_TCHAR* argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:x"));
11 int c;
13 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'k':
18 ior = get_opts.opt_arg ();
19 break;
20 case 'x':
21 call_shutdown = 1;
22 break;
23 case '?':
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "usage: %s\n"
27 "-k <ior> "
28 "-x - call shutdown on server\n",
29 argv[0]),
30 -1);
33 return 0;
36 int ACE_TMAIN( int argc, ACE_TCHAR* argv[] )
38 try {
39 // Initialize the ORB.
40 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
42 // Parse arguments.
43 if (parse_args (argc, argv) != 0)
44 return 1;
46 // Read and destringify the Messenger object's IOR.
47 CORBA::Object_var obj = orb->string_to_object(ior);
48 if( CORBA::is_nil( obj.in() ) ) {
49 std::cerr << "Could not get Messenger IOR." << std::endl;
50 return 1;
53 // Narrow the IOR to a Messenger object reference.
54 Messenger_var messenger = Messenger::_narrow( obj.in() );
55 if( CORBA::is_nil( messenger.in() ) ) {
56 std::cerr << "IOR was not a Messenger object reference." << std::endl;
57 return 1;
60 // Send a message the the Messenger object.
61 CORBA::String_var message = CORBA::string_dup( "Hello!" );
62 messenger->send_message( "TAO User", "TAO Test", message.inout() );
64 // Print the Messenger's reply.
65 std::cout << "Reply: " << message.in() << std::endl;
67 // Shutdown server?
68 if (call_shutdown == 1)
70 messenger->shutdown();
71 orb->perform_work();
74 orb->destroy();
76 catch(const CORBA::Exception& ex) {
77 std::cerr << "CORBA exception: " << ex << std::endl;
78 return 1;
81 return 0;