Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Bug_933_Regression / MessengerClient.cpp
blobef5cd9894f604985468a5a2c06fe482b8ee80857
1 #include "MessengerC.h"
2 #include "tao/CodecFactory/CodecFactory.h"
3 #include "ace/Get_Opt.h"
5 const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior");
7 int
8 parse_args (int argc, ACE_TCHAR *argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
11 int c;
13 while ((c = get_opts ()) != -1)
14 switch (c)
16 case 'k':
17 ior = get_opts.opt_arg ();
18 break;
20 case '?':
21 default:
22 ACE_ERROR_RETURN ((LM_ERROR,
23 "usage: %s "
24 "-k <ior> "
25 "\n",
26 argv [0]),
27 -1);
29 // Indicates successful parsing of the command line
30 return 0;
33 int
34 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
36 try {
37 // Initialize orb
38 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
40 if (parse_args (argc, argv) != 0)
41 return 1;
43 // Destringify ior
44 CORBA::Object_var obj = orb->string_to_object(ior);
46 // Narrow
47 Messenger_var messenger = Messenger::_narrow( obj.in());
48 if(CORBA::is_nil( messenger.in())) {
49 ACE_ERROR_RETURN ((LM_ERROR,
50 " (%P|%t) Panic: nil reference\n"),
51 1);
54 // Obtain a reference to the CodecFactory.
55 CORBA::Object_var obj2 =
56 orb->resolve_initial_references ("CodecFactory");
58 IOP::CodecFactory_var codec_factory =
59 IOP::CodecFactory::_narrow (obj2.in ());
61 // Set up a structure that contains information necessary to
62 // create a GIOP 1.2 CDR encapsulation Codec.
63 IOP::Encoding encoding;
64 encoding.format = IOP::ENCODING_CDR_ENCAPS;
65 encoding.major_version = 1;
66 encoding.minor_version = 2;
68 // Obtain the CDR encapsulation Codec.
69 IOP::Codec_var codec =
70 codec_factory->create_codec (encoding);
72 CORBA::String_var user_name = CORBA::string_dup ("Ru");
74 CORBA::Any user_name_as_any;
75 user_name_as_any <<= user_name.in ();
77 CORBA::OctetSeq_var client_user_name = codec->encode (user_name_as_any);
79 messenger->send_message (client_user_name.in ());
81 messenger->shutdown ();
83 orb->destroy ();
85 catch( const CORBA::SystemException &ex) {
86 ex._tao_print_exception ("Caught CORBA exception: ");
87 return 1;
89 catch( ...) {
90 return 1;
93 return 0;