1 #include "tao/CodecFactory/CodecFactory.h"
2 #include "ace/OS_NS_string.h"
4 #include "Messenger_i.h"
6 // Implementation skeleton constructor
7 Messenger_i::Messenger_i (void)
11 // Implementation skeleton destructor
12 Messenger_i::~Messenger_i (void)
16 void Messenger_i::send_message (const CORBA::OctetSeq
& user_name
)
23 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
25 // Obtain a reference to the CodecFactory.
26 CORBA::Object_var obj
=
27 orb
->resolve_initial_references ("CodecFactory");
29 IOP::CodecFactory_var codec_factory
;
31 if(CORBA::is_nil(obj
.in()))
33 std::cerr
<< "Error: codec_factory" << std::endl
;
38 codec_factory
= IOP::CodecFactory::_narrow (obj
.in ());
39 std::cout
<< "Server got codec factory" << std::endl
;
42 // Set up a structure that contains information necessary to
43 // create a GIOP 1.2 CDR encapsulation Codec.
44 IOP::Encoding encoding
;
45 encoding
.format
= IOP::ENCODING_CDR_ENCAPS
;
46 encoding
.major_version
= 1;
47 encoding
.minor_version
= 2;
49 // Obtain the CDR encapsulation Codec.
50 IOP::Codec_var codec
=
51 codec_factory
->create_codec (encoding
);
53 CORBA::Any uid_as_any
;
54 uid_as_any
= *(codec
->decode(user_name
));
57 if (uid_as_any
>>= uid
)
59 std::cout
<< "UID: " << uid
<< std::endl
;
63 std::cerr
<< "Could not extract UID from any." << std::endl
;
70 std::cerr
<< "exception received" << std::endl
;