1 #include "MessengerC.h"
2 #include "ClientInitializer.h"
3 #include "tao/ORBInitializer_Registry.h"
4 // Ensure that the PI library is linked in when building statically
7 #include "ace/Get_Opt.h"
9 const ACE_TCHAR
*ior
= ACE_TEXT ("file://Messenger.ior");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
17 while ((c
= get_opts ()) != -1)
21 ior
= get_opts
.opt_arg ();
26 ACE_ERROR_RETURN ((LM_ERROR
,
33 // Indicates successful parsing of the command line
39 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
43 PortableInterceptor::ORBInitializer_var orb_initializer
=
44 new ClientInitializer
;
46 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
49 CORBA::ORB_var orb
= CORBA::ORB_init( argc
, argv
);
51 if (parse_args (argc
, argv
) != 0)
55 CORBA::Object_var obj
= orb
->string_to_object( ior
);
56 if( CORBA::is_nil( obj
.in() ) ) {
57 std::cerr
<< "Nil Messenger reference" << std::endl
;
62 Messenger_var messenger
= Messenger::_narrow( obj
.in() );
63 if( CORBA::is_nil( messenger
.in() ) ) {
64 std::cerr
<< "Argument is not a Messenger reference" << std::endl
;
68 // Obtain a reference to the CodecFactory.
69 CORBA::Object_var obj2
=
70 orb
->resolve_initial_references ("CodecFactory");
72 IOP::CodecFactory_var codec_factory
;
74 if(CORBA::is_nil(obj2
.in()))
76 std::cerr
<< "Error: codec_factory" << std::endl
;
81 codec_factory
= IOP::CodecFactory::_narrow (obj2
.in ());
82 std::cout
<< "got codec factory" << std::endl
;
85 // Set up a structure that contains information necessary to
86 // create a GIOP 1.2 CDR encapsulation Codec.
87 IOP::Encoding encoding
;
88 encoding
.format
= IOP::ENCODING_CDR_ENCAPS
;
89 encoding
.major_version
= 1;
90 encoding
.minor_version
= 2;
92 // Obtain the CDR encapsulation Codec.
93 IOP::Codec_var codec
=
94 codec_factory
->create_codec (encoding
);
96 CORBA::Long uid
= 64321;
98 CORBA::Any uid_as_any
;
101 CORBA::OctetSeq client_uid
= *codec
->encode (uid_as_any
);
102 messenger
->send_message( client_uid
);
105 catch(const CORBA::Exception
& ex
)
107 std::cerr
<< "Exception in MessengerClient: " << ex
<< std::endl
;
111 std::cout
<< "Message was sent" << std::endl
;