Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_3387_Regression / MessengerServer.cpp
blob5095a179afd785eb98727e7b175383ed62699cec
1 #include "orbsvcs/CosNamingC.h"
2 #include "Messenger_i.h"
3 #include "ace/Get_Opt.h"
4 #include <iostream>
5 #include <fstream>
7 const ACE_TCHAR *ior_file = ACE_TEXT ("Messenger.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'o':
19 ior_file = get_opts.opt_arg ();
20 break;
22 case '?':
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "usage: %s "
26 "-o <ior> "
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
36 int
37 ACE_TMAIN(int argc, ACE_TCHAR * argv[])
39 try
41 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
43 if (parse_args (argc, argv) != 0)
44 return 1;
46 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
47 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
48 PortableServer::POAManager_var mgr = poa->the_POAManager();
49 mgr->activate();
51 Messenger_i messenger_servant (orb.in ());
52 PortableServer::ObjectId_var oid = poa->activate_object (&messenger_servant);
53 CORBA::Object_var messenger_obj = poa->id_to_reference (oid.in ());
54 CORBA::String_var str = orb->object_to_string (messenger_obj.in());
56 std::ofstream iorFile (ACE_TEXT_ALWAYS_CHAR(ior_file));
57 iorFile << str.in () << std::endl;
58 iorFile.close ();
59 std::cout << "IOR written to file Messenger.ior " << std::endl;
61 orb->run ();
62 orb->destroy ();
65 catch(const CORBA::Exception& ex)
67 std::cerr << "Caught exception: " << ex << std::endl;
68 return 1;
71 return 0;