Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / DevGuideExamples / NotifyService / SupplierSideNC / MessengerClient.cpp
blob56bb0b9cae4655d91edd5df6a59ac6c62fbdc5df
1 #include "orbsvcs/CosNamingC.h"
2 #include "MessengerC.h"
3 #include <iostream>
4 int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
6 try
8 // Initialize orb
9 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
11 CORBA::Object_var rootObj =
12 orb->resolve_initial_references("NameService");
14 CosNaming::NamingContext_var rootContext =
15 CosNaming::NamingContext::_narrow(rootObj.in());
17 CosNaming::Name name;
18 name.length (1);
19 name[0].id = CORBA::string_dup ("MessengerService");
21 CORBA::Object_var messengerObj = rootContext->resolve(name);
23 if (CORBA::is_nil(messengerObj.in())) {
24 std::cerr << "Nil Messenger reference" << std::endl;
25 return 1;
28 // Narrow
29 Messenger_var messenger = Messenger::_narrow(messengerObj.in());
30 if (CORBA::is_nil(messenger.in ())) {
31 std::cerr << "Argument is not a Messenger reference" << std::endl;
32 return 1;
35 CORBA::String_var message =
36 CORBA::string_dup("Where can I get TAO?");
37 messenger->send_message ("person@company.com",
38 "OCI's Distribution of TAO",
39 message.inout());
41 message = CORBA::string_dup("I need TAO now.");
42 messenger->send_message ("person@company.com",
43 "OCI's Distribution of TAO",
44 message.inout());
47 catch(const CORBA::Exception& ex) {
48 std::cerr << "Caught a CORBA exception: " << ex << std::endl;
49 return 1;
52 std::cout << "MessengerClient: success" << std::endl;
53 return 0;