1 // file : RolyPoly/server.cpp
2 // author : Boris Kolpackov <boris@dre.vanderbilt.edu>
3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_stdio.h"
6 #include "RolyPoly_i.h"
7 #include "CrashPoint.h"
8 #include "ORB_Initializer.h"
9 #include "tao/ORBInitializer_Registry.h"
11 const ACE_TCHAR
*ior_file
= 0;
14 parse_args (int argc
, ACE_TCHAR
*argv
[])
16 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:c:"));
19 while ((c
= get_opts ()) != -1)
23 ior_file
= get_opts
.opt_arg ();
26 crash_point
= ACE_OS::atoi (get_opts
.opt_arg ());
29 ACE_ERROR_RETURN ((LM_ERROR
,
41 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
45 if (::parse_args (argc
, argv
) != 0) return -1;
47 ORB_Initializer
*temp_initializer
= 0;
48 ACE_NEW_RETURN (temp_initializer
,
50 -1); // No exceptions yet!
52 PortableInterceptor::ORBInitializer_var orb_initializer
=
55 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
58 CORBA::ORB_init (argc
, argv
, "Server ORB");
60 CORBA::Object_var poa_object
=
61 orb
->resolve_initial_references ("RootPOA");
63 if (CORBA::is_nil (poa_object
.in ()))
64 ACE_ERROR_RETURN ((LM_ERROR
,
65 " (%P|%t) Unable to initialize the POA.\n"),
68 PortableServer::POA_var root_poa
=
69 PortableServer::POA::_narrow (poa_object
.in ());
71 PortableServer::POAManager_var poa_manager
=
72 root_poa
->the_POAManager ();
74 RolyPoly_i
* roly_poly_impl
;
76 ACE_NEW_RETURN (roly_poly_impl
,
77 RolyPoly_i (orb
.in ()),
80 PortableServer::ServantBase_var
owner_transfer (roly_poly_impl
);
83 roly_poly_impl
->_this ();
85 CORBA::PolicyList policies
; // Empty policy list.
87 CORBA::String_var ior
=
88 orb
->object_to_string (t
.in ());
90 poa_manager
->activate ();
92 FILE *output_file
= ACE_OS::fopen (ior_file
, "w");
95 ACE_ERROR_RETURN ((LM_ERROR
,
96 "Cannot open output file <%s> for writing "
102 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
103 ACE_OS::fclose (output_file
);
105 ACE_DEBUG ((LM_DEBUG
, "Server is ready\n"));
107 // Run the ORB event loop.
110 root_poa
->destroy (true, true);
114 ACE_DEBUG ((LM_DEBUG
, "Event loop finished.\n"));
116 catch (const CORBA::Exception
& ex
)
118 ex
._tao_print_exception ("Caught exception:");