Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / DevGuideExamples / PortableInterceptors / Auth / MessengerClient.cpp
blob1529aa4bef01196789ec51a1d8115a91bc00db16
1 #include "MessengerC.h"
2 #include "ClientInitializer.h"
3 #include "tao/ORBInitializer_Registry.h"
4 // Ensure that the PI library is linked in when building statically
5 #include "tao/PI/PI.h"
6 #include <iostream>
7 #include "ace/Get_Opt.h"
9 const ACE_TCHAR *ior = ACE_TEXT ("file://Messenger.ior");
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'k':
21 ior = get_opts.opt_arg ();
22 break;
24 case '?':
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "usage: %s "
28 "-k <ior> "
29 "\n",
30 argv [0]),
31 -1);
33 // Indicates successful parsing of the command line
34 return 0;
37 int
38 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
40 try
42 PortableInterceptor::ORBInitializer_var orb_initializer =
43 new ClientInitializer;
45 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
47 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "Client ORB");
49 if (parse_args (argc, argv) != 0)
50 return 1;
52 CORBA::Object_var obj = orb->string_to_object( ior );
54 if ( CORBA::is_nil(obj.in() ) ) {
55 std::cerr << "Nil Messenger reference" << std::endl;
56 return 1;
59 Messenger_var messenger = Messenger::_narrow( obj.in() );
61 if( CORBA::is_nil( messenger.in() ) ) {
62 std::cerr << "Not a Messenger reference" << std::endl;
63 return 1;
66 CORBA::String_var message = CORBA::string_dup( "Hello!" );
67 messenger->send_message( "TAO User", "TAO Test", message.inout() );
69 catch(const CORBA::Exception& ex)
71 std::cerr << "Caught CORBA exception: " << ex << std::endl;
72 return 1;
75 return 0;