Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / DevGuideExamples / PortableInterceptors / PICurrent / MessengerClient.cpp
blob43a3b3159955ad7cc8e6375ae87412ffedb0c5cf
1 #include "MessengerC.h"
2 #include "ClientInitializer.h"
4 #include "tao/ORBInitializer_Registry.h"
5 // Ensure that the PI library is linked in when building statically
6 #include "tao/PI/PI.h"
7 #include <iostream>
8 #include "ace/Get_Opt.h"
10 const ACE_TCHAR *ior = ACE_TEXT ("file://Messenger.ior");
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'k':
22 ior = get_opts.opt_arg ();
23 break;
25 case '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s "
29 "-k <ior> "
30 "\n",
31 argv [0]),
32 -1);
34 // Indicates successful parsing of the command line
35 return 0;
39 int
40 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
42 try
44 ClientInitializer* temp_initializer = new ClientInitializer;
46 PortableInterceptor::ORBInitializer_var orb_initializer =
47 temp_initializer;
49 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
51 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "Client ORB");
53 if (parse_args (argc, argv) != 0)
54 return 1;
55 // Now that the ORB is initialized (and subsequently the
56 // PICurrent), we can set the slot data on the PICurrent for our
57 // interceptor initializer.
58 temp_initializer->set_slot_data ();
60 CORBA::Object_var obj = orb->string_to_object( ior );
61 if ( CORBA::is_nil(obj.in() ) ) {
62 std::cerr << "Nil Messenger reference" << std::endl;
63 return 1;
65 // Narrow
66 Messenger_var messenger = Messenger::_narrow( obj.in() );
67 if( CORBA::is_nil( messenger.in() ) ) {
68 std::cerr << "Not a Messenger reference" << std::endl;
69 return 1;
72 CORBA::String_var message = CORBA::string_dup( "Hello!" );
73 messenger->send_message( "TAO User", "TAO Test", message.inout() );
76 catch(const CORBA::Exception& ex)
78 std::cerr << "client Caught CORBA exception: " << ex << std::endl;
79 return 1;
82 return 0;