3 // A ThreeTier client that calls tick and/or tock
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] == 'f' && argp
+ 1 < argc
)
26 if (ior_input_file
!= 0)
29 "Sink (%P|%t) duplicate -f options\n"));
32 // capture input file name
33 // then remove it from arguemnt list
34 ior_input_file
= argv
[argp
+ 1];
35 eat_args (argc
, argv
, argp
, 2);
40 // just ignore unknown arguments
43 if (ior_input_file
== 0)
46 "Sink (%P|%t) missing required -f option\n"));
55 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
59 "Source (%P|%t) started\n"));
62 // Initialize the ORB.
64 CORBA::ORB_init (argc
, argv
);
66 // Initialize options based on command-line arguments.
67 if (!parse_args (argc
, argv
))
72 FILE *input_file
= ACE_OS::fopen (ior_input_file
, "r");
75 ACE_ERROR_RETURN ((LM_ERROR
,
76 "Cannot open input IOR file: %s",
80 ACE_OS::fread (input_ior
, 1, sizeof(input_ior
), input_file
);
81 ACE_OS::fclose (input_file
);
83 // Convert the IOR to an object reference.
84 CORBA::Object_var object
=
85 orb
->string_to_object (input_ior
);
87 // narrow the object reference to a ThreeTier reference
88 ThreeTier_var server
= ThreeTier::_narrow (object
.in ());
90 if (CORBA::is_nil (server
.in ()))
92 ACE_ERROR_RETURN ((LM_ERROR
,
93 "IOR does not refer to a ThreeTier implementation"),
97 Source_i
source (server
.in ());
98 result
= source
.run();
100 catch (const CORBA::Exception
& ex
)
102 ex
._tao_print_exception ("Exception caught:");
106 ACE_DEBUG ((LM_DEBUG
,
107 "Source (%P|%t) exits\n"));