1 #include "MessengerC.h"
2 #include "Smart_Messenger_Proxy.h"
4 #include "ace/Get_Opt.h"
6 const ACE_TCHAR
*ior
= ACE_TEXT ("file://Messenger.ior");
9 parse_args (int argc
, ACE_TCHAR
*argv
[])
11 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
14 while ((c
= get_opts ()) != -1)
18 ior
= get_opts
.opt_arg ();
23 ACE_ERROR_RETURN ((LM_ERROR
,
30 // Indicates successful parsing of the command line
34 int ACE_TMAIN(int argc
, ACE_TCHAR
* argv
[])
38 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
40 if (parse_args (argc
, argv
) != 0)
43 // Create a smart proxy factory. It will register itself with the
44 // smart proxy factory adapter so it can be used to create
45 // Messenger proxies. It must be created on the heap, but is
46 // otherwise unused here.
47 new Smart_Messenger_Proxy_Factory(orb
.in());
49 // Convert the contents of the Messenger.ior file to an object reference.
50 CORBA::Object_var obj
= orb
->string_to_object(ior
);
51 if (CORBA::is_nil(obj
.in())) {
52 std::cerr
<< "Nil Messenger reference" << std::endl
;
56 // Narrow the object reference to a Messenger object reference.
57 Messenger_var messenger
= Messenger::_narrow(obj
.in());
58 if (CORBA::is_nil(messenger
.in())) {
59 std::cerr
<< "Not a Messenger object reference" << std::endl
;
63 // Create a message and send it to the Messenger.
64 CORBA::String_var message
= CORBA::string_dup("Hello!");
65 messenger
->send_message ("TAO User", "TAO Test", message
.inout());
66 std::cout
<< "Message was sent" << std::endl
;
71 catch(const CORBA::Exception
& ex
) {
72 std::cerr
<< "Caught a CORBA exception: " << ex
<< std::endl
;
76 std::cerr
<< "Caught an unknown exception type" << std::endl
;