Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / DevGuideExamples / AMH / MessengerClient.cpp
blobefa1bce79880e2c37e7e4f96f069e9bd8810036f
1 #include "amh_pch.h"
3 #include "ace/Get_Opt.h"
4 #include "MessengerC.h"
5 #include <iostream>
7 ACE_TString ior = ACE_TEXT ("file://test.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.optarg;
20 break;
22 case '?':
23 default:
24 std::cerr << "usage: " << argv[0] << " -k <ior>" << std::endl;
25 return -1;
26 break;
28 return 0;
31 int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
33 try {
34 // Initialize the ORB.
35 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
37 if (parse_args(argc, argv) != 0) {
38 return 1;
41 // Read and destringify the Messenger object's IOR.
42 CORBA::Object_var obj = orb->string_to_object(ior.c_str());
43 if( CORBA::is_nil( obj.in() ) ) {
44 std::cerr << "Could not get Messenger IOR." << std::endl;
45 return 1;
48 // Narrow the IOR to a Messenger object reference.
49 DevGuide::Messenger_var messenger =
50 DevGuide::Messenger::_narrow( obj.in() );
51 if( CORBA::is_nil( messenger.in() ) ) {
52 std::cerr << "IOR was not a Messenger object reference." << std::endl;
53 return 1;
56 // Send a message the the Messenger object.
57 CORBA::String_var msg = CORBA::string_dup( "Hello!" );
58 messenger->send_message( "TAO User", "TAO Test", msg.inout() );
60 // Print the Messenger's reply.
61 std::cout << "Reply: " << msg.in() << std::endl;
63 orb->destroy();
65 return 0;
67 catch(const CORBA::Exception& ex) {
68 std::cerr << "CORBA exception: " << ex << std::endl;
71 return 1;