1
// server.cpp,v 1.3 2003/11/27 23:42:40 bala Exp
3
#include "ace/Get_Opt.h"
4
#include "ace/OS_NS_stdio.h"
5
#include "ace/OS_NS_unistd.h"
8
ACE_RCSID(Send_File, server, "server.cpp,v 1.3 2003/11/27 23:42:40 bala Exp")
10
const char *ior_output_file = 0;
13
parse_args (int argc, char *argv[])
15
ACE_Get_Opt get_opts (argc, argv, "o:");
18
while ((c = get_opts ()) != -1)
22
ior_output_file = get_opts.opt_arg ();
26
ACE_ERROR_RETURN ((LM_ERROR,
27
"SERVER (%P): usage: %s "
28
"-o <iorfile> -w <wait-time>"
33
// Indicates sucessful parsing of the command line
38
main (int argc, char *argv[])
40
ACE_DECLARE_NEW_CORBA_ENV;
45
CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER);
48
CORBA::Object_var poa_object =
49
orb->resolve_initial_references ("RootPOA" ACE_ENV_ARG_PARAMETER);
52
if (CORBA::is_nil (poa_object.in ()))
53
ACE_ERROR_RETURN ((LM_ERROR,
54
"SERVER (%P): Unable to initialize the POA.\n"),
57
PortableServer::POA_var root_poa =
58
PortableServer::POA::_narrow (poa_object.in () ACE_ENV_ARG_PARAMETER);
61
PortableServer::POAManager_var poa_manager =
62
root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
65
if (parse_args (argc, argv) != 0)
68
Simple_Server_i server_impl (orb.in ());
70
CORBA::PolicyList policies (2);
74
root_poa->create_id_assignment_policy (PortableServer::USER_ID
75
ACE_ENV_ARG_PARAMETER);
79
root_poa->create_lifespan_policy (PortableServer::PERSISTENT
80
ACE_ENV_ARG_PARAMETER);
83
PortableServer::POA_var persistent_poa =
84
root_poa->create_POA ("PersistentPOA",
87
ACE_ENV_ARG_PARAMETER);
90
PortableServer::ObjectId_var oid =
91
PortableServer::string_to_ObjectId ("object1");
94
persistent_poa->activate_object_with_id (oid.in (),
96
ACE_ENV_ARG_PARAMETER);
100
CORBA::Object_var server =
101
persistent_poa->create_reference_with_id (oid.in (),
102
"IDL:Simple_Server:1.0"
103
ACE_ENV_ARG_PARAMETER);
106
CORBA::String_var ior =
107
orb->object_to_string (server.in () ACE_ENV_ARG_PARAMETER);
110
// If the ior_output_file exists, output the ior to it
111
if (ior_output_file != 0)
113
FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
114
if (output_file == 0)
115
ACE_ERROR_RETURN ((LM_ERROR,
116
"SERVER (%P): Cannot open output file "
117
"for writing IOR: %s",
120
ACE_OS::fprintf (output_file, "%s", ior.in ());
121
ACE_OS::fclose (output_file);
123
ACE_DEBUG ((LM_DEBUG,
124
"SERVER (%P): Activated as file://%s\n",
129
ACE_DEBUG ((LM_DEBUG,
130
"SERVER (%P): Activated as <%s>\n",
135
poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
138
orb->run (ACE_ENV_SINGLE_ARG_PARAMETER);
141
ACE_DEBUG ((LM_DEBUG, "SERVER (%P): Event loop finished.\n"));
143
persistent_poa->destroy (1, 1 ACE_ENV_ARG_PARAMETER);
146
root_poa->destroy (1, 1 ACE_ENV_ARG_PARAMETER);
153
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
154
"SERVER (%P): Caught exception:");