Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / DevGuideExamples / PortableInterceptors / IOR / Messenger_i.cpp
blob07e184ac27c105246377e24feadc6639e64723be
1 #include "tao/CodecFactory/CodecFactory.h"
2 #include "ace/OS_NS_string.h"
3 #include <iostream>
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)
18 try
20 int argc = 0;
21 char **argv = 0;
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;
34 ACE_OS::exit(1);
36 else
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));
56 CORBA::Long uid;
57 if (uid_as_any >>= uid)
59 std::cout << "UID: " << uid << std::endl;
61 else
63 std::cerr << "Could not extract UID from any." << std::endl;
68 catch(...)
70 std::cerr << "exception received" << std::endl;
71 ACE_OS::exit(1);