Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / examples / Load_Balancing_persistent / Load_Balancing_Service.cpp
blobf758ba108736c34040bcfc6ee6f40ccd256f7cd7
1 //=============================================================================
2 /**
3 * @file Load_Balancing_Service.cpp
5 * @author Marina Spivak <marina@cs.wustl.edu>
6 */
7 //=============================================================================
10 #include "Load_Balancing_Service.h"
11 #include "Load_Balancer_i.h"
12 #include "tao/debug.h"
13 #include "ace/Get_Opt.h"
14 #include "ace/OS_NS_stdio.h"
16 Load_Balancing_Service::Load_Balancing_Service ()
17 : ior_output_file_ (0)
21 int
22 Load_Balancing_Service::parse_args (int argc, ACE_TCHAR *argv[])
24 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("do:"));
25 int c;
27 while ((c = get_opts ()) != -1)
28 switch (c)
30 case 'd': // debug flag.
31 TAO_debug_level++;
32 break;
33 case 'o': // outputs object ior to the specified file.
34 this->ior_output_file_ =
35 ACE_OS::fopen (get_opts.opt_arg (), "w");
37 if (this->ior_output_file_ == 0)
38 ACE_ERROR_RETURN ((LM_ERROR,
39 "Unable to open %s for writing: %p\n",
40 get_opts.opt_arg ()), -1);
41 break;
42 case '?':
43 default:
44 ACE_ERROR_RETURN ((LM_ERROR,
45 "usage: %s"
46 " [-d]"
47 " [-o] <ior_output_file>"
48 "\n",
49 argv [0]),
50 -1);
53 // Indicates successful parsing of command line.
54 return 0;
57 int
58 Load_Balancing_Service::init (int argc, ACE_TCHAR* argv[])
60 int result;
61 CORBA::String_var ior;
63 try
65 result = this->orb_manager_.init (argc, argv);
66 if (result == -1)
67 return result;
69 // Check the non-ORB arguments.
70 result = this->parse_args (argc, argv);
71 if (result < 0)
72 return result;
75 CORBA::PolicyList policies (2);
76 policies.length (2);
78 // Lifespan policy
79 policies[0] =
80 this->orb_manager_.root_poa()->create_lifespan_policy (PortableServer::PERSISTENT);
82 policies[1] =
83 this->orb_manager_.root_poa()->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION);
85 PortableServer::POA_var persistent_POA =
86 this->orb_manager_.root_poa()->create_POA ("persistent",
87 this->orb_manager_.poa_manager (),
88 policies);
91 // Destroy policy objects
92 for (CORBA::ULong i = 0;
93 i < policies.length ();
94 ++i)
96 policies[i]->destroy ();
99 // Create, ref. count, and activate the servant.
100 Object_Group_Factory_i * factory_servant;
101 ACE_NEW_RETURN (factory_servant,
102 Object_Group_Factory_i (this->orb_manager_.orb (),
103 persistent_POA.in ()),
104 -1);
106 // Activate the POA manager
107 //PortableServer::ServantBase_var s = factory_servant;
108 this->orb_manager_.activate_poa_manager ();
110 CORBA::Object_var objref = factory_servant->_this ();
112 ior = this->orb_manager_.orb ()->object_to_string (objref.in ());
114 if (ior.in () == 0)
115 return -1;
116 else if (TAO_debug_level > 0)
117 ACE_DEBUG ((LM_DEBUG,
118 "Object Group Factory ior: %s\n",
119 ior.in ()));
121 catch (const CORBA::Exception& ex)
123 ex._tao_print_exception ("Load_Balancing_Service::init");
124 return -1;
127 if (this->ior_output_file_ != 0)
129 ACE_OS::fprintf (this->ior_output_file_,
130 "%s",
131 ior.in ());
132 ACE_OS::fclose (this->ior_output_file_);
134 return 0;
139 Load_Balancing_Service::run ()
141 int result;
143 result = this->orb_manager_.run ();
145 return result;
148 Load_Balancing_Service::~Load_Balancing_Service ()
153 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
155 int result = 0;
156 Load_Balancing_Service factory;
158 if (factory.init (argc, argv) == -1)
159 return 1;
163 result = factory.run ();
165 catch (const CORBA::Exception& ex)
167 ex._tao_print_exception ("Load_Balancing_Service");
168 return 1;
171 if (result == -1)
172 return 1;
173 else
174 return 0;