Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Smart_Proxies / Policy / server.cpp
blobd08190d433236c6292caccaff048c2830e83de46
2 //=============================================================================
3 /**
4 * @file server.cpp
6 * This is the server program that tests TAO's Smart Proxy extension.
8 * @author Kirthika Parameswaran <kirthika@cs.wustl.edu>
9 */
10 //=============================================================================
13 #include "testS.h"
14 #include "ace/Get_Opt.h"
15 #include "ace/OS_NS_string.h"
17 // The servant
19 class Test_i : public POA_Test
21 public:
22 Test_i (CORBA::ORB_ptr orb);
24 CORBA::Short method (CORBA::Short boo);
26 //FUZZ: disable check_for_lack_ACE_OS
27 ///FUZZ: enable check_for_lack_ACE_OS
28 void shutdown (void);
30 private:
31 CORBA::ORB_var orb_;
35 Test_i::Test_i (CORBA::ORB_ptr orb)
36 : orb_ (CORBA::ORB::_duplicate (orb))
40 CORBA::Short
41 Test_i :: method (CORBA::Short boo)
43 ACE_DEBUG ((LM_DEBUG,
44 ACE_TEXT ("Test_i::method () invoked\n")));
45 if (boo == 5)
46 throw Test::Oops ("Invalid boo\n");
48 return 0;
51 void
52 Test_i::shutdown (void)
54 this->orb_->shutdown (0);
57 static const ACE_TCHAR *ior_output_file = 0;
59 int
60 parse_args (int argc, ACE_TCHAR *argv[])
62 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
63 int c;
65 while ((c = get_opts ()) != -1)
66 switch (c)
68 case 'o':
69 ior_output_file = get_opts.opt_arg ();
70 break;
71 case '?':
72 default:
73 ACE_ERROR_RETURN ((LM_ERROR,
74 "usage: %s "
75 "-o <iorfile>"
76 "\n",
77 argv [0]),
78 -1);
80 // Indicates successful parsing of the command line
81 return 0;
84 int
85 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
87 try
89 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
91 if (parse_args (argc, argv) != 0)
92 return 1;
94 Test_i servant (orb.in ());
95 // Obtain RootPOA.
96 CORBA::Object_var object =
97 orb->resolve_initial_references ("RootPOA");
99 PortableServer::POA_var root_poa =
100 PortableServer::POA::_narrow (object.in ());
102 // Get the POAManager of the RootPOA.
103 PortableServer::POAManager_var poa_manager =
104 root_poa->the_POAManager ();
106 PortableServer::ObjectId_var id =
107 root_poa->activate_object (&servant);
109 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
111 Test_var Test_object =
112 Test::_narrow (object_act.in ());
114 CORBA::String_var ior =
115 orb->object_to_string (Test_object.in ());
117 // If the ior_output_file exists, output the ior to it
118 if (ior_output_file != 0)
120 FILE *output_file =
121 ACE_OS::fopen (ior_output_file, "w");
123 if (output_file == 0)
124 ACE_ERROR_RETURN ((LM_ERROR,
125 "Cannot open output file for writing IOR: %s",
126 ior_output_file),
129 ACE_OS::fprintf (output_file,
130 "%s",
131 ior.in ());
132 ACE_OS::fclose (output_file);
135 poa_manager->activate ();
137 orb->run ();
139 ACE_DEBUG ((LM_DEBUG,
140 "event loop finished\n"));
142 root_poa->destroy (true, true);
144 orb->destroy ();
146 catch (const CORBA::Exception& ex)
148 ex._tao_print_exception ("Exception in setting up server");
149 ACE_ASSERT (0);
151 return 0;