2 #include "ace/OS_NS_unistd.h"
4 const ACE_TCHAR
* ior_output_file
= 0;
6 void eat_args (int & argc
, ACE_TCHAR
*argv
[], int argp
, int how_many
)
8 for (int marg
= argp
; marg
+ how_many
< argc
; ++marg
)
10 argv
[marg
] = argv
[marg
+ how_many
];
15 bool parse_args (int & argc
, ACE_TCHAR
*argv
[])
20 const ACE_TCHAR
* arg
= argv
[argp
];
21 if(arg
[0] == '-' && arg
[1] == 'o' && argp
+ 1 < argc
)
23 if (ior_output_file
!= 0)
26 "Sink (%P|%t) duplicate -o options\n"));
29 // capture output file name
30 // then remove it from arguemnt list
31 ior_output_file
= argv
[argp
+ 1];
32 eat_args(argc
, argv
, argp
, 2);
37 // just ignore unknown arguments
40 if (ior_output_file
== 0)
43 "Sink (%P|%t) missing required -o option\n"));
51 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
54 "Sink (%P|%t) started\n"));
59 CORBA::ORB_init (argc
,
62 if (!parse_args (argc
, argv
))
66 CORBA::Object_var poa_object
=
67 orb
->resolve_initial_references ("RootPOA");
69 PortableServer::POA_var root_poa
=
70 PortableServer::POA::_narrow (poa_object
.in ());
72 PortableServer::POAManager_var poa_manager
=
73 root_poa
->the_POAManager ();
75 Sink_i
sink (orb
.in());
76 if (sink
.parse_args (argc
, argv
) )
78 PortableServer::ObjectId_var id
=
79 root_poa
->activate_object (&sink
);
81 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
83 ThreeTier_var server
=
84 ThreeTier::_narrow (object
.in ());
86 CORBA::String_var ior
=
87 orb
->object_to_string (server
.in ());
89 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
91 ACE_ERROR_RETURN ((LM_ERROR
,
92 "Cannot open output file for writing IOR: %s",
95 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
96 ACE_OS::fclose (output_file
);
98 poa_manager
->activate ();
102 catch (const CORBA::UserException
& userex
)
104 userex
._tao_print_exception ("SINK: User Exception in main");
107 catch (const CORBA::SystemException
& sysex
)
109 sysex
._tao_print_exception ("SINK: System Exception in main");
113 ACE_DEBUG ((LM_DEBUG
,
114 "Sink (%P|%t) exits\n"));