Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / NestedUpcall / Triangle_Test / server_B.cpp
blob43f07d30a43d6cca8e36e9c03627863781f8e216
2 //=============================================================================
3 /**
4 * @file server_B.cpp
6 * This class implements a simple server for the
7 * Nested Upcalls - Triangle test.
9 * @author Michael Kircher
11 //=============================================================================
14 #include "server_B.h"
15 #include "tao/debug.h"
16 #include "ace/OS_NS_stdio.h"
18 Object_B_Server::Object_B_Server (void)
19 : ior_output_file_ (0)
23 int
24 Object_B_Server::parse_args (void)
26 ACE_Get_Opt get_opts (argc_, argv_, ACE_TEXT("do:"));
27 int c;
29 while ((c = get_opts ()) != -1)
30 switch (c)
32 case 'd': // debug flag.
33 TAO_debug_level++;
34 break;
35 case 'o': // output the IOR to a file.
36 this->ior_output_file_ = 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 Object_B_Server::init (int argc,
59 ACE_TCHAR** argv)
61 // Call the init of TAO_ORB_Manager to create a child POA
62 // under the root POA.
63 this->orb_manager_.init_child_poa (argc,
64 argv,
65 "child_poa");
67 this->argc_ = argc;
68 this->argv_ = argv;
70 this->parse_args ();
71 // ~~ check for the return value here
73 CORBA::String_var str =
74 this->orb_manager_.activate_under_child_poa ("object_B",
75 &this->object_B_i_);
77 if (this->ior_output_file_)
79 ACE_OS::fprintf (this->ior_output_file_,
80 "%s",
81 str.in ());
82 ACE_OS::fclose (this->ior_output_file_);
85 return 0;
89 int
90 Object_B_Server::run (void)
92 int result = this->orb_manager_.run ();
94 if (result == -1)
95 ACE_ERROR_RETURN ((LM_ERROR,
96 "Object_B_Server::run"),
97 -1);
99 return 0;
102 Object_B_Server::~Object_B_Server (void)
107 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
109 Object_B_Server object_B_Server;
111 ACE_DEBUG ((LM_DEBUG,
112 "\n \t NestedUpCalls.Triangle_Test: Object B Server \n\n"));
116 int retval = object_B_Server.init (argc, argv);
118 if (retval == -1)
119 return 1;
120 else
122 object_B_Server.run ();
125 catch (const CORBA::SystemException& sysex)
127 sysex._tao_print_exception ("System Exception");
128 return -1;
130 catch (const CORBA::UserException& userex)
132 userex._tao_print_exception ("User Exception");
133 return -1;
135 return 0;