1 #include "tao/PortableServer/POAC.h"
2 #include "tao/ORB_Constants.h"
3 #include "ace/OS_NS_strings.h"
4 #include "ace/OS_NS_stdio.h"
6 const ACE_TCHAR
*ior_file
= ACE_TEXT("test.ior");
7 const ACE_TCHAR
*iorstr
= ACE_TEXT("");
9 CORBA::Short endpoint_port
= 12345;
11 bool as_server
= true;
14 parse_args (int argc
, ACE_TCHAR
*argv
[])
16 for (int c
= 1; c
< argc
; c
++) {
17 if (ACE_OS::strcasecmp(argv
[c
], ACE_TEXT("-o")) == 0)
21 else if (ACE_OS::strcasecmp(argv
[c
], ACE_TEXT("-k")) == 0)
26 else if (ACE_OS::strcasecmp(argv
[c
], ACE_TEXT("-p")) == 0)
28 endpoint_port
= ACE_OS::atoi (argv
[++c
]);
30 else if (ACE_OS::strstr(argv
[c
], ACE_TEXT("-ORB")) == argv
[c
])
36 ACE_ERROR_RETURN ((LM_ERROR
,
45 // Indicates successful parsing of the command line
50 gen_objref (int argc
, ACE_TCHAR
*argv
[])
53 CORBA::Object_var obj
;
54 PortableServer::POA_var root_poa
;
56 ACE_TCHAR
**largv
= new ACE_TCHAR
*[argc
+4];
59 for (i
= 0; i
< argc
; i
++)
63 extra
[0] = CORBA::wstring_dup (ACE_TEXT ("-ORBEndpoint"));
64 extra
[1] =CORBA::wstring_alloc (100);
66 extra
[0] = CORBA::string_dup ("-ORBEndpoint");
67 extra
[1] = CORBA::string_alloc (100);
69 ACE_OS::sprintf (extra
[1],
70 ACE_TEXT ("iiop://localhost:%d"),
74 extra
[2] = CORBA::wstring_dup (ACE_TEXT ("-ORBEndpoint"));
75 extra
[3] = CORBA::wstring_alloc (100);
77 extra
[2] = CORBA::string_dup ("-ORBEndpoint");
78 extra
[3] = CORBA::string_alloc (100);
80 ACE_OS::sprintf (extra
[3],
81 ACE_TEXT ("iiop://localhost:%d"),
84 for (i
= 0; i
< 4; i
++)
85 largv
[argc
++] = extra
[i
];
90 CORBA::ORB_init (argc
, largv
);
93 orb
->resolve_initial_references("RootPOA");
96 PortableServer::POA::_narrow (obj
.in ());
98 if (CORBA::is_nil (root_poa
.in ()))
99 ACE_ERROR_RETURN ((LM_ERROR
,
100 " (%P|%t) Panic: nil RootPOA\n"),
103 catch (const CORBA::Exception
&ex
)
105 ex
._tao_print_exception("initialization error ");
109 for (i
= 0; i
< 4; i
++)
110 #ifdef ACE_USES_WCHAR
111 CORBA::wstring_free (extra
[i
]);
113 CORBA::string_free (extra
[i
]);
118 CORBA::Object_var o
= root_poa
->create_reference ("IDL:JustATest:1.0");
120 CORBA::String_var ior
=
121 orb
->object_to_string (o
.in ());
123 FILE *output_file
= ACE_OS::fopen (ior_file
, "w");
124 if (output_file
== 0)
125 ACE_ERROR_RETURN ((LM_ERROR
,
126 "Cannot open output file for writing IOR: %s",
129 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
130 ACE_OS::fclose (output_file
);
135 parse_objref (int argc
, ACE_TCHAR
*argv
[])
138 CORBA::Object_var obj
;
143 CORBA::ORB_init (argc
, argv
);
145 obj
= orb
->string_to_object (iorstr
);
149 catch (const CORBA::Exception
&ex
)
151 ex
._tao_print_exception("initialization error ");
159 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
161 if (parse_args (argc
, argv
) != 0)
164 return gen_objref(argc
, argv
);
165 return parse_objref(argc
, argv
);