Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / DevGuideExamples / GettingStarted / MessengerClient.cpp
bloba355424de26475ba55cec5f45d9bc504e97adcbf
1 #include "started_pch.h"
3 #include "MessengerC.h"
4 #include <iostream>
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR *ior = ACE_TEXT ("file://Messenger.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'k':
19 ior = get_opts.opt_arg ();
20 break;
22 case '?':
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "usage: %s "
26 "-k <ior> "
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
35 int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
37 try {
38 // Initialize the ORB.
39 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
41 if (parse_args (argc, argv) != 0)
42 return 1;
44 // Read and destringify the Messenger object's IOR.
45 CORBA::Object_var obj = orb->string_to_object( ior );
46 if( CORBA::is_nil( obj.in() ) ) {
47 std::cerr << "Could not get Messenger IOR." << std::endl;
48 return 1;
51 // Narrow the IOR to a Messenger object reference.
52 Messenger_var messenger = Messenger::_narrow( obj.in() );
53 if( CORBA::is_nil( messenger.in() ) ) {
54 std::cerr << "IOR was not a Messenger object reference." << std::endl;
55 return 1;
58 // Send a message the the Messenger object.
59 CORBA::String_var msg = CORBA::string_dup( "Hello!" );
60 messenger->send_message( "TAO User", "TAO Test", msg.inout() );
62 // Print the Messenger's reply.
63 std::cout << "Reply: " << msg.in() << std::endl;
65 orb->destroy();
67 return 0;
69 catch(const CORBA::Exception& ex) {
70 std::cerr << "CORBA exception: " << ex << std::endl;
73 return 1;