Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / DevGuideExamples / PortableInterceptors / SimpleCodec / Messenger_i.cpp
blob6abb61497073d9e36839bc07e1c7d8ea70d667b6
1 #include "Messenger_i.h"
2 #include "ace/OS_NS_string.h"
3 #include "tao/CodecFactory/CodecFactory.h"
4 #include <iostream>
6 // Implementation skeleton constructor
7 Messenger_i::Messenger_i ()
11 // Implementation skeleton destructor
12 Messenger_i::~Messenger_i ()
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) {
58 std::cout << "UID: " << uid << std::endl;
59 } else {
60 std::cerr << "Could not extract UID from any." << std::endl;
64 catch(...)
66 std::cerr << "exception received" << std::endl;
67 ACE_OS::exit(1);