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
38 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
42 PortableInterceptor::ORBInitializer_var orb_initializer
=
43 new ClientInitializer
;
45 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
48 CORBA::ORB_var orb
= CORBA::ORB_init( argc
, argv
);
50 if (parse_args (argc
, argv
) != 0)
54 CORBA::Object_var obj
= orb
->string_to_object( ior
);
55 if( CORBA::is_nil( obj
.in() ) ) {
56 std::cerr
<< "Nil Messenger reference" << std::endl
;
61 Messenger_var messenger
= Messenger::_narrow( obj
.in() );
62 if( CORBA::is_nil( messenger
.in() ) ) {
63 std::cerr
<< "Argument is not a Messenger reference" << std::endl
;
67 // Obtain a reference to the CodecFactory.
68 CORBA::Object_var obj2
=
69 orb
->resolve_initial_references ("CodecFactory");
71 IOP::CodecFactory_var codec_factory
;
73 if(CORBA::is_nil(obj2
.in()))
75 std::cerr
<< "Error: codec_factory" << std::endl
;
80 codec_factory
= IOP::CodecFactory::_narrow (obj2
.in ());
81 std::cout
<< "got codec factory" << std::endl
;
84 // Set up a structure that contains information necessary to
85 // create a GIOP 1.2 CDR encapsulation Codec.
86 IOP::Encoding encoding
;
87 encoding
.format
= IOP::ENCODING_CDR_ENCAPS
;
88 encoding
.major_version
= 1;
89 encoding
.minor_version
= 2;
91 // Obtain the CDR encapsulation Codec.
92 IOP::Codec_var codec
=
93 codec_factory
->create_codec (encoding
);
95 CORBA::Long uid
= 64321;
97 CORBA::Any uid_as_any
;
100 CORBA::OctetSeq client_uid
= *codec
->encode (uid_as_any
);
101 messenger
->send_message( client_uid
);
104 catch(const CORBA::Exception
& ex
)
106 std::cerr
<< "Exception in MessengerClient: " << ex
<< std::endl
;
110 std::cout
<< "message was sent" << std::endl
;