2 //=============================================================================
6 * Implementation of the Chat Server_i class.
8 * @author Pradeep Gore <pradeep@cs.wustl.edu>
10 //=============================================================================
14 #include "ace/Get_Opt.h"
15 #include "ace/OS_NS_stdio.h"
18 : ior_file_name_ (ACE_TEXT ("chat.ior"))
20 Broadcaster_i
*tmp
= 0;
21 ACE_NEW_THROW_EX (tmp
,
24 this->broadcaster_i_
= tmp
;
27 Server_i::~Server_i ()
33 Server_i::parse_args (int argc
, ACE_TCHAR
*argv
[])
35 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("o:"));
38 while ((c
= get_opts ()) != -1)
41 case 'o': // get the file name to write to
42 this->ior_file_name_
= get_opts
.opt_arg ();
45 case '?': // display help for use of the server.
47 ACE_ERROR_RETURN ((LM_ERROR
,
48 ACE_TEXT ("usage: %s")
49 ACE_TEXT (" [-o] <ior_output_file>")
59 Server_i::init (int argc
,
62 // Parse the command line options.
63 if (this->parse_args(argc
, argv
) == -1)
66 if (this->orb_manager_
.init (argc
,
68 ACE_ERROR_RETURN ((LM_ERROR
,
70 ACE_TEXT ("orb manager init failed")),
73 CORBA::ORB_var orb
= this->orb_manager_
.orb ();
75 // Activate the servant.
76 CORBA::String_var str
=
77 this->orb_manager_
.activate (this->broadcaster_i_
.in ());
79 // Write the IOR to a file.
80 this->write_IOR (str
.in ());
88 ACE_TEXT ("Running chat server...\n")));
90 // Run the main event loop for the ORB.
91 int ret
= this->orb_manager_
.run ();
93 ACE_ERROR_RETURN ((LM_ERROR
,
94 ACE_TEXT ("Server_i::run")),
100 Server_i::write_IOR (const char* ior
)
102 FILE* ior_output_file_
=
103 ACE_OS::fopen (this->ior_file_name_
, "w");
105 if (ior_output_file_
)
107 ACE_OS::fprintf (ior_output_file_
,
110 ACE_OS::fclose (ior_output_file_
);