1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
// $Id$
// ===========================================================
//
//
// = LIBRARY
// TAO/tests/Simple/chat
//
// = FILENAME
// Server_i.cpp
//
// = DESCRIPTION
// Implementation of the Chat Server_i class.
//
// = AUTHOR
// Pradeep Gore <pradeep@cs.wustl.edu>
//
// ===========================================================
#include "Server_i.h"
#include "ace/Get_Opt.h"
Server_i::Server_i ()
: ior_file_name_ ("chat.ior")
{
// No Op.
}
Server_i::~Server_i (void)
{
// NO Op.
}
int
Server_i::parse_args (int argc, char *argv[])
{
ACE_Get_Opt get_opts (argc, argv, "o:");
int c;
while ((c = get_opts ()) != -1)
switch (c)
{
case 'o': // get the file name to write to
this->ior_file_name_ = get_opts.optarg;
break;
case '?': // display help for use of the server.
default:
ACE_ERROR_RETURN ((LM_ERROR,
"usage: %s"
" [-o] <ior_output_file>"
"\n",
argv [0]),
-1);
}
return 0;
}
int
Server_i::init (int argc,
char *argv[],
CORBA::Environment &ACE_TRY_ENV)
{
// Parse the command line options.
if (this-> parse_args(argc, argv) == -1)
return -1;
if (this->orb_manager_.init (argc,
argv,
ACE_TRY_ENV) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"orb manager init failed\n"),
-1);
ACE_CHECK_RETURN (-1);
CORBA::ORB_var orb = this->orb_manager_.orb ();
// Activate the servant.
CORBA::String_var str =
this->orb_manager_.activate (&this->broadcaster_i_,
ACE_TRY_ENV);
ACE_CHECK_RETURN (-1);
// Write the IOR to a file.
this->write_IOR (str.in ());
return 0;
}
int
Server_i::run (CORBA::Environment &ACE_TRY_ENV)
{
ACE_DEBUG ((LM_DEBUG,
"Running chat server...\n"));
// Run the main event loop for the ORB.
int ret = this->orb_manager_.run (ACE_TRY_ENV);
ACE_CHECK_RETURN (-1);
if (ret == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"Server_i::run"),
-1);
return 0;
}
int
Server_i::write_IOR(const char* ior)
{
FILE* ior_output_file_ =
ACE_OS::fopen (this->ior_file_name_, "w");
if (ior_output_file_)
{
ACE_OS::fprintf (ior_output_file_,
"%s",
ior);
ACE_OS::fclose (ior_output_file_);
}
return 0;
}
|