Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / examples / Simple / chat / Server_i.cpp
blob6628b345992d5a0b57f65927c71ba4a9d7651cff
2 //=============================================================================
3 /**
4 * @file Server_i.cpp
6 * Implementation of the Chat Server_i class.
8 * @author Pradeep Gore <pradeep@cs.wustl.edu>
9 */
10 //=============================================================================
13 #include "Server_i.h"
14 #include "ace/Get_Opt.h"
15 #include "ace/OS_NS_stdio.h"
17 Server_i::Server_i ()
18 : ior_file_name_ (ACE_TEXT ("chat.ior"))
20 Broadcaster_i *tmp = 0;
21 ACE_NEW_THROW_EX (tmp,
22 Broadcaster_i (),
23 CORBA::NO_MEMORY ());
24 this->broadcaster_i_ = tmp;
27 Server_i::~Server_i ()
29 // NO Op.
32 int
33 Server_i::parse_args (int argc, ACE_TCHAR *argv[])
35 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("o:"));
36 int c;
38 while ((c = get_opts ()) != -1)
39 switch (c)
41 case 'o': // get the file name to write to
42 this->ior_file_name_ = get_opts.opt_arg ();
43 break;
45 case '?': // display help for use of the server.
46 default:
47 ACE_ERROR_RETURN ((LM_ERROR,
48 ACE_TEXT ("usage: %s")
49 ACE_TEXT (" [-o] <ior_output_file>")
50 ACE_TEXT ("\n"),
51 argv [0]),
52 -1);
55 return 0;
58 int
59 Server_i::init (int argc,
60 ACE_TCHAR *argv[])
62 // Parse the command line options.
63 if (this->parse_args(argc, argv) == -1)
64 return -1;
66 if (this->orb_manager_.init (argc,
67 argv) == -1)
68 ACE_ERROR_RETURN ((LM_ERROR,
69 ACE_TEXT ("%p\n"),
70 ACE_TEXT ("orb manager init failed")),
71 -1);
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 ());
81 return 0;
84 int
85 Server_i::run ()
87 ACE_DEBUG ((LM_DEBUG,
88 ACE_TEXT ("Running chat server...\n")));
90 // Run the main event loop for the ORB.
91 int ret = this->orb_manager_.run ();
92 if (ret == -1)
93 ACE_ERROR_RETURN ((LM_ERROR,
94 ACE_TEXT ("Server_i::run")),
95 -1);
96 return 0;
99 int
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_,
108 ACE_TEXT ("%s"),
109 ior);
110 ACE_OS::fclose (ior_output_file_);
113 return 0;