1 #include "Messenger_i.h"
2 #include "ace/Get_Opt.h"
3 #include <orbsvcs/SecurityLevel2C.h>
5 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("server.ior");
8 parse_args (int argc
, ACE_TCHAR
*argv
[])
10 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
13 while ((c
= get_opts ()) != -1)
17 ior_output_file
= get_opts
.opt_arg ();
22 ACE_ERROR_RETURN ((LM_ERROR
,
29 // Indicates successful parsing of the command line
34 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
39 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
41 if (parse_args (argc
, argv
) != 0)
44 //Get reference to Root POA
45 CORBA::Object_var POA_obj
= orb
->resolve_initial_references( "RootPOA");
46 PortableServer::POA_var poa
= PortableServer::POA::_narrow( POA_obj
.in());
48 // Activate POA Manager
49 PortableServer::POAManager_var mgr
= poa
->the_POAManager();
53 Messenger_i
messenger_servant (orb
);
54 Messenger_var messenger_factory
= messenger_servant
._this ();
56 // In order to allow collocated invocations we need to allow unsecured
57 // collocated invocations to the object else our security manager will
58 // block the collocated invocation unless you explicitly allow it
59 CORBA::Object_var sec_man
=
60 orb
->resolve_initial_references ("SecurityLevel2:SecurityManager");
61 SecurityLevel2::SecurityManager_var sec2manager
=
62 SecurityLevel2::SecurityManager::_narrow (sec_man
.in ());
63 SecurityLevel2::AccessDecision_var ad_tmp
=
64 sec2manager
->access_decision ();
65 TAO::SL2::AccessDecision_var ad
=
66 TAO::SL2::AccessDecision::_narrow (ad_tmp
.in ());
67 // Allow unsecured collocated invocations
68 ad
->default_collocated_decision (true);
70 CORBA::String_var ior
=
71 orb
->object_to_string (messenger_factory
.in ());
73 // If the ior_output_file exists, output the ior to it
74 if (ior_output_file
!= 0)
76 FILE *output_file
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_output_file
), "w");
78 ACE_ERROR_RETURN ((LM_ERROR
,
79 "Cannot open output file for writing IOR: %s",
80 ACE_TEXT_ALWAYS_CHAR(ior_output_file
)),
82 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
83 ACE_OS::fclose (output_file
);
89 poa
->destroy (true, true);
93 catch (const CORBA::Exception
&)
95 ACE_ERROR((LM_ERROR
, "Caught a CORBA exception: "));