Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_3387_Regression / MessengerClient.cpp
blob7cf1bdd9bc1a9487043b80dd8ff05ae83f96ab30
1 #include "MessengerC.h"
2 #include "orbsvcs/CosNamingC.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "ace/Get_Opt.h"
5 #include <iostream>
7 const ACE_TCHAR *ior_file = 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_file = 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
36 ACE_TMAIN(int argc, ACE_TCHAR * argv[])
38 try
40 // Initialize orb
41 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
43 if (parse_args (argc, argv) != 0)
44 return 1;
47 CORBA::Object_var obj = orb->string_to_object(ACE_TEXT_ALWAYS_CHAR(ior_file));
48 if (CORBA::is_nil(obj.in())) {
49 std::cerr << "Nil Messenger reference" << std::endl;
50 return 1;
53 // Narrow
54 Messenger_var messenger = Messenger::_narrow( obj.in() );
55 if (CORBA::is_nil(messenger.in())) {
56 std::cerr << "Argument is not a Messenger reference" << std::endl;
57 return 1;
60 CORBA::String_var message = CORBA::string_dup(
61 "Where can I get TAO?");
62 for (int i=0; i<120; i++) {
63 ACE_OS::sleep(1);
64 messenger->send_message ("person@company.com",
65 "OCI's Distribution of TAO",
66 message.inout());
69 catch(const CORBA::Exception& ex)
71 std::cerr << "Caught exception: " << ex << std::endl;
72 return 1;
75 ACE_OS::sleep(5);
76 return 0;