Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / DevGuideExamples / Security / PolicyControllingApp / MessengerServer.cpp
blob6c0826db3e289c26d56f31ab6f246aac99d11466
1 /* -*- C++ -*- */
3 #include "Messenger_i.h"
4 #include <iostream>
5 #include <fstream>
6 #include "ace/Get_Opt.h"
8 const ACE_TCHAR *ior_output_file = ACE_TEXT ("Messenger.ior");
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'o':
20 ior_output_file = get_opts.opt_arg ();
21 break;
23 case '?':
24 default:
27 // Indicates successful parsing of the command line
28 return 0;
30 int
31 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
33 try {
34 // Initialize orb
35 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
37 if (parse_args (argc, argv) != 0)
38 return 1;
40 //Get reference to Root POA
41 CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
42 PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() );
44 // Activate POA Manager
45 PortableServer::POAManager_var mgr = poa->the_POAManager();
46 mgr->activate();
48 // Create an object
49 PortableServer::Servant_var<Messenger_i> messenger_servant = new Messenger_i;
51 // Register the servant with the RootPOA, obtain its object
52 // reference, stringify it, and write it to a file.
53 PortableServer::ObjectId_var oid =
54 poa->activate_object( messenger_servant.in() );
55 CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() );
56 CORBA::String_var str = orb->object_to_string( messenger_obj.in() );
57 std::ofstream iorFile( ACE_TEXT_ALWAYS_CHAR(ior_output_file) );
58 iorFile << str.in() << std::endl;
59 iorFile.close();
60 std::cout << "IOR written to file " << ior_output_file << std::endl;
62 // Accept requests
63 orb->run();
64 orb->destroy();
67 catch(const CORBA::Exception& ex) {
68 ex._tao_print_exception("Server Error: main block");
69 return 1;
72 return 0;