3 //=============================================================================
7 * A simple server to demonstrate the use of codeset translation
9 * @author Phil Mesnier <mesnier_p@ociweb.com>
11 //=============================================================================
13 // IDL generated header
16 // FUZZ: disable check_for_streams_include
17 #include "ace/streams.h"
19 #include "ace/OS_NS_stdio.h"
20 #include "ace/Get_Opt.h"
22 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("test.ior");
25 parse_args (int argc
, ACE_TCHAR
*argv
[])
27 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
30 while ((c
= get_opts ()) != -1)
34 ior_output_file
= get_opts
.opt_arg ();
39 ACE_ERROR_RETURN ((LM_ERROR
,
46 // Indicates successful parsing of the command line
50 // ------------------------------------------------------------
51 // Servant for associated CORBA object
52 // ------------------------------------------------------------
53 class SimpleImpl
: public POA_simple
56 SimpleImpl (CORBA::ORB_ptr orb
)
57 : orb_ (CORBA::ORB::_duplicate (orb
))
60 // implementation of corba interface
61 char * op1 (const char * name
,
62 const CORBA::Any
& inany
,
63 CORBA::Any_out outany
)
66 "Server: bare string: %C\n", name
));
70 "Server: inserted string: %C\n\n", any_str
));
72 CORBA::Any
*out_ptr
= 0;
73 ACE_NEW_RETURN (out_ptr
,
76 (*out_ptr
) <<= any_str
;
79 return CORBA::string_dup (name
);
82 ACE_CDR::WChar
* op2 (const ACE_CDR::WChar
*s1
)
84 return CORBA::wstring_dup (s1
);
87 //FUZZ: disable check_for_lack_ACE_OS
90 this->orb_
->shutdown (0);
92 //FUZZ: enable check_for_lack_ACE_OS
95 /// Use an ORB reference to shutdown
100 // ------------------------------------------------------------
102 // ------------------------------------------------------------
103 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
108 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
111 CORBA::Object_var poa_object
=
112 orb
->resolve_initial_references ("RootPOA");
115 if (CORBA::is_nil (poa_object
.in ()))
117 ACE_DEBUG ((LM_DEBUG
,
118 "Couldn't initialize POA\n"));
123 PortableServer::POA_var root_poa
=
124 PortableServer::POA::_narrow (poa_object
.in ());
126 // Get the POA manager
127 PortableServer::POAManager_var poa_manager
=
128 root_poa
->the_POAManager ();
130 if (parse_args (argc
, argv
) != 0)
133 // Create a C++ implementation of CORBA object
134 SimpleImpl
* my_impl
= 0;
135 ACE_NEW_RETURN (my_impl
,
136 SimpleImpl (orb
.in ()),
138 PortableServer::ServantBase_var
safe (my_impl
);
140 // Create CORBA object for servant and REGISTER with POA
141 PortableServer::ObjectId_var id
=
142 root_poa
->activate_object (my_impl
);
144 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
146 simple_var server
= simple::_narrow (object_act
.in ());
148 // Get the IOR for our object
149 CORBA::String_var ior
= orb
->object_to_string (server
.in ());
151 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
152 if (output_file
== 0)
153 ACE_ERROR_RETURN ((LM_ERROR
,
154 "Cannot open output file for writing IOR: server.ior"),
156 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
157 ACE_OS::fclose (output_file
);
159 // Activate POA manager
160 poa_manager
->activate ();
165 root_poa
->destroy (1, 1);
169 catch (const CORBA::Exception
& ex
)
171 ex
._tao_print_exception ("Exception caught in server:");