Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / InterOp-Naming / Server_i.cpp
blobd1dca7f3a99c9bf2f935f7c69ac994a245504344
1 #include "Server_i.h"
2 #include "tao/debug.h"
3 #include "tao/IORTable/IORTable.h"
4 #include "ace/OS_NS_stdio.h"
6 // Constructor.
7 Server_i::Server_i ()
8 : ior_output_file_ (0),
9 ins_ (0)
13 // Destructor.
14 Server_i::~Server_i ()
18 // Parse the command-line arguments and set options.
19 int
20 Server_i::parse_args ()
22 ACE_Get_Opt get_opts (this->argc_, this->argv_, ACE_TEXT("do:ni:"));
23 int c = 0;
25 while ((c = get_opts ()) != -1)
26 switch (c)
28 case 'd': // debug flag.
29 TAO_debug_level++;
30 break;
31 case 'o': // output the IOR to a file.
32 this->ior_output_file_ = ACE_OS::fopen (get_opts.opt_arg (), "w");
33 if (this->ior_output_file_ == 0)
34 ACE_ERROR_RETURN ((LM_ERROR,
35 "Unable to open %s for writing: %p\n",
36 get_opts.opt_arg ()), -1);
37 break;
39 case 'i': // For Testing the InterOperable Naming Service.
40 this->ins_ = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(get_opts.opt_arg ()));
41 break;
43 case '?': // display help for use of the server.
44 default:
45 ACE_ERROR_RETURN ((LM_ERROR,
46 "usage: %s"
47 " [-d]"
48 " [-o] <ior_output_file>"
49 " [-n] "
50 "\n",
51 argv_ [0]),
52 -1);
55 // Indicates successful parsing of command line.
56 return 0;
59 // Add the ObjectID:IOR mapping to the IOR table of
60 // the ORB.
62 int
63 Server_i::add_IOR_to_table (CORBA::String_var ior)
65 try
67 if (TAO_debug_level > 0)
68 ACE_DEBUG ((LM_DEBUG,
69 "Adding (KEY:IOR) %C:%C\n",
70 this->ins_,
71 ior.in ()));
73 CORBA::Object_var table_object =
74 this->orb_manager_.orb ()->resolve_initial_references (
75 "IORTable");
77 IORTable::Table_var adapter =
78 IORTable::Table::_narrow (table_object.in ());
80 adapter->bind (this->ins_, ior.in ());
82 catch (const CORBA::SystemException& ex)
84 ex._tao_print_exception ("Exception caugh in add_IOR_to_table");
87 return 0;
90 // Initialize the server.
91 int
92 Server_i::init (int argc,
93 ACE_TCHAR *argv[])
95 // Call the init of <TAO_ORB_Manager> to initialize the ORB and
96 // create a child POA under the root POA.
97 int result = this->orb_manager_.init_child_poa (argc,
98 argv,
99 "child_poa");
101 if (result == -1)
102 ACE_ERROR_RETURN ((LM_ERROR,
103 "%p\n",
104 "init_child_poa"),
105 -1);
107 this->argc_ = argc;
108 this->argv_ = argv;
110 int retval = this->parse_args ();
112 if (retval != 0)
113 return retval;
115 CORBA::ORB_var orb = this->orb_manager_.orb ();
117 // Stash our ORB pointer for later reference.
118 this->servant_.orb (orb.in ());
122 CORBA::String_var str =
123 this->orb_manager_.activate_under_child_poa ("INS_servant",
124 &this->servant_);
126 ACE_DEBUG ((LM_DEBUG,
127 "The IOR is: <%C>\n",
128 str.in ()));
130 if (this->ins_)
131 if (this->add_IOR_to_table (str) != 0)
132 ACE_ERROR_RETURN ((LM_ERROR,
133 "test_for_ins (): failed\n"),
134 -1);
136 if (this->ior_output_file_)
138 ACE_OS::fprintf (this->ior_output_file_,
139 "%s",
140 str.in ());
141 ACE_OS::fclose (this->ior_output_file_);
145 catch (const CORBA::Exception& ex)
147 ex._tao_print_exception (
148 "\tException in activation of POA");
149 return -1;
152 return 0;
156 Server_i::run ()
158 // Run the main event loop for the ORB.
159 int result = this->orb_manager_.run ();
161 if (result == -1)
162 ACE_ERROR_RETURN ((LM_ERROR,
163 "Server_i::run"),
164 -1);
166 return 0;