3 const ACE_TCHAR
* ior_output_file
= 0;
5 const ACE_TCHAR
* ior_input_file
= 0;
9 void eat_args (int & argc
, ACE_TCHAR
*argv
[], int argp
, int how_many
)
11 for (int marg
= argp
; marg
+ how_many
< argc
; ++marg
)
13 argv
[marg
] = argv
[marg
+ how_many
];
18 bool parse_args (int & argc
, ACE_TCHAR
*argv
[])
23 const ACE_TCHAR
* arg
= argv
[argp
];
24 if(arg
[0] == '-' && arg
[1] == 'o' && argp
+ 1 < argc
)
26 if (ior_output_file
!= 0)
29 "Middle (%P|%t) duplicate -o options\n"));
32 // capture output file name
33 // then remove it from arguemnt list
34 ior_output_file
= argv
[argp
+ 1];
35 eat_args(argc
, argv
, argp
, 2);
37 else if(arg
[0] == '-' && arg
[1] == 'f' && argp
+ 1 < argc
)
39 if (ior_input_file
!= 0)
42 "Middle (%P|%t) duplicate -f options\n"));
45 // capture input file name
46 // then remove it from arguemnt list
47 ior_input_file
= argv
[argp
+ 1];
48 eat_args(argc
, argv
, argp
, 2);
53 // just ignore unknown arguments
56 if (ior_output_file
== 0)
59 "Middle (%P|%t) missing required -o option\n"));
66 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
69 "Middle (%P|%t) started\n"));
74 CORBA::ORB_init (argc
,
77 if ( ! parse_args (argc
, argv
))
82 ///////////////////////////////
83 // Prepare to be a CORBA server
84 CORBA::Object_var poa_object
=
85 orb
->resolve_initial_references ("RootPOA");
87 PortableServer::POA_var root_poa
=
88 PortableServer::POA::_narrow (poa_object
.in ());
90 PortableServer::POAManager_var poa_manager
=
91 root_poa
->the_POAManager ();
93 ///////////////////////////////
94 // Prepare to be a CORBA client
95 FILE *input_file
= ACE_OS::fopen (ior_input_file
, "r");
98 ACE_ERROR_RETURN ((LM_ERROR
,
99 "Cannot open input IOR file: %s",
103 ACE_OS::fread (input_ior
, 1, sizeof(input_ior
), input_file
);
104 ACE_OS::fclose (input_file
);
106 // Convert the IOR to an object reference.
107 CORBA::Object_var object
=
108 orb
->string_to_object (input_ior
);
110 // narrow the object reference to a ThreeTier reference
111 ThreeTier_var target
= ThreeTier::_narrow (object
.in ());
113 if (CORBA::is_nil (target
.in ()))
115 ACE_ERROR_RETURN ((LM_ERROR
,
116 "IOR does not refer to a ThreeTier implementation"),
120 // We should have a good connection now
121 // temporary: check it out
125 Middle_i
middle (orb
.in(), target
.in ());
126 if (middle
.parse_args (argc
, argv
) )
128 /////////////////////////////////
129 // Activate server side mechanism
130 PortableServer::ObjectId_var id
=
131 root_poa
->activate_object (&middle
);
133 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
135 ThreeTier_var server
=
136 ThreeTier::_narrow (object
.in ());
138 CORBA::String_var ior
=
139 orb
->object_to_string (server
.in ());
141 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
142 if (output_file
== 0)
143 ACE_ERROR_RETURN ((LM_ERROR
,
144 "Cannot open output file for writing IOR: %s",
147 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
148 ACE_OS::fclose (output_file
);
150 poa_manager
->activate ();
154 catch (const CORBA::UserException
& userex
)
156 userex
._tao_print_exception ("Middle: User Exception in main");
159 catch (const CORBA::SystemException
& sysex
)
161 sysex
._tao_print_exception ("Middle: System Exception in main");
165 ACE_DEBUG ((LM_DEBUG
,
166 "Middle (%P|%t) exits\n"));