5 #include "ace/Get_Opt.h"
6 #include "ace/Read_Buffer.h"
7 #include "ace/OS_NS_unistd.h"
8 #include "ace/OS_NS_string.h"
9 #include "ace/OS_NS_fcntl.h"
10 #include "ace/os_include/os_netdb.h"
16 Client_i::Client_i (void)
24 // The following test throws an exception that the operation
25 // <secure_universal_time> has not been currently implemented in the
29 Client_i::test_for_secure_universal_time (void)
32 "[CLIENT] Process/Thread Id : (%P/%t) Testing secure_time()\n"));
36 CosTime::UTO_var UTO_server
=
37 this->clerk_
->secure_universal_time ();
40 catch (const CORBA::SystemException
& sysex
)
42 sysex
._tao_print_exception ("System Exception");
44 "[CLIENT] Process/Thread Id : (%P/%t) test_for_secure_universal_time() successful !!\n"));
48 // The following test retrieves the current universal time as a UTO
49 // from the clerk_ and prints out the various attributes of the UTO.
52 Client_i::test_for_universal_time (void)
55 "[CLIENT] Process/Thread Id : (%P/%t) Testing universal_time()\n"));
58 CosTime::UTO_var UTO_server
=
59 this->clerk_
->universal_time ();
62 "\nTime = %Q\nInaccuracy = %Q\nTimeDiff = %d\nstruct.time = %Q"
63 "\nstruct.inacclo = %d\nstruct.inacchi = %d\nstruct.Tdf = %d\n",
65 UTO_server
->inaccuracy (),
67 (UTO_server
->utc_time ()).time
,
68 (UTO_server
->utc_time ()).inacclo
,
69 (UTO_server
->utc_time ()).inacchi
,
70 (UTO_server
->utc_time ()).tdf
));
72 catch (const CORBA::Exception
& ex
)
74 ex
._tao_print_exception ("Error:");
76 "[CLIENT] Process/Thread Id : (%P/%t) test_for_universal_time()\n"));
81 Client_i::test_for_new_universal_time (void)
83 TimeBase::TimeT time
= 999999999;
84 TimeBase::InaccuracyT inaccuracy
= 9999;
85 TimeBase::TdfT tdf
= 99;
88 "[CLIENT] Process/Thread Id : (%P/%t) Testing new_universal_time()\n"));
92 CosTime::UTO_var UTO_server
= this->clerk_
->new_universal_time (time
,
96 ACE_ASSERT (UTO_server
->time () == 999999999);
97 ACE_ASSERT (UTO_server
->inaccuracy () == 9999);
98 ACE_ASSERT (UTO_server
->tdf () == 99);
99 ACE_ASSERT ((UTO_server
->utc_time ()).time
== 999999999);
100 ACE_ASSERT ((UTO_server
->utc_time ()).inacchi
== 0);
101 ACE_ASSERT ((UTO_server
->utc_time ()).inacclo
== 9999);
102 ACE_ASSERT ((UTO_server
->utc_time ()).tdf
== 99);
105 catch (const CORBA::Exception
& ex
)
107 ACE_DEBUG ((LM_DEBUG
,
108 "[CLIENT] Process/Thread Id : (%P/%t) Test new_universal_time () fails.\n"));
109 ex
._tao_print_exception ("Exception :\n");
114 Client_i::test_for_uto_from_utc (void)
116 TimeBase::UtcT utc_struct
;
118 utc_struct
.time
= 999999999;
119 utc_struct
.inacclo
= 50;
120 utc_struct
.inacchi
= 50;
123 ACE_DEBUG ((LM_DEBUG
,
124 "[CLIENT] Process/Thread Id : (%P/%t) Testing uto_from_utc ()\n"));
128 CosTime::UTO_var UTO_server
= this->clerk_
->uto_from_utc (utc_struct
);
130 TimeBase::InaccuracyT inaccuracy
= utc_struct
.inacchi
;
132 inaccuracy
|= utc_struct
.inacclo
;
134 ACE_ASSERT (UTO_server
->time () == 999999999);
135 ACE_ASSERT (UTO_server
->inaccuracy () == inaccuracy
);
136 ACE_ASSERT (UTO_server
->tdf () == 99);
137 ACE_ASSERT ((UTO_server
->utc_time ()).time
== 999999999);
138 ACE_ASSERT ((UTO_server
->utc_time ()).inacclo
== 50);
139 ACE_ASSERT ((UTO_server
->utc_time ()).inacchi
== 50);
140 ACE_ASSERT ((UTO_server
->utc_time ()).tdf
== 99);
143 catch (const CORBA::Exception
& ex
)
145 ACE_DEBUG ((LM_DEBUG
,
146 "[CLIENT] Process/Thread Id : (%P/%t) Test uto_from_utc () fails.\n"));
147 ex
._tao_print_exception ("Exception :\n");
152 Client_i::test_for_new_interval (void)
154 TimeBase::TimeT lower
= 666666666;
155 TimeBase::TimeT upper
= 999999999;
157 ACE_DEBUG ((LM_DEBUG
,
158 "[CLIENT] Process/Thread Id : (%P/%t) Testing new_interval ()\n"));
162 CosTime::TIO_var TIO_server
= this->clerk_
->new_interval (lower
,
165 ACE_ASSERT ((TIO_server
->time_interval ()).lower_bound
== 666666666);
166 ACE_ASSERT ((TIO_server
->time_interval ()).upper_bound
== 999999999);
169 catch (const CORBA::Exception
& ex
)
171 ACE_DEBUG ((LM_DEBUG
,
172 "[CLIENT] Process/Thread Id : (%P/%t) Test new_interval () fails.\n"));
173 ex
._tao_print_exception ("Exception :\n");
179 // Reads the Time Service Server ior from a file
182 Client_i::read_ior (ACE_TCHAR
*filename
)
184 // Open the file for reading.
185 ACE_HANDLE f_handle
= ACE_OS::open (filename
, 0);
187 if (f_handle
== ACE_INVALID_HANDLE
)
188 ACE_ERROR_RETURN ((LM_ERROR
,
189 "[CLIENT] Process/Thread Id : (%P/%t) Unable to open %s for writing: %p\n",
193 ACE_Read_Buffer
ior_buffer (f_handle
);
194 char *data
= ior_buffer
.read ();
197 ACE_ERROR_RETURN ((LM_ERROR
,
198 "[CLIENT] Process/Thread Id : (%P/%t) Unable to read ior: %p\n"),
201 this->ior_
= ACE_OS::strdup (data
);
202 ior_buffer
.alloc ()->free (data
);
204 ACE_OS::close (f_handle
);
209 // Parses the command line arguments and returns an error status.
212 Client_i::parse_args (void)
214 ACE_Get_Opt
get_opts (argc_
, argv_
, ACE_TEXT("dn:f:xk:"));
218 while ((c
= get_opts ()) != -1)
219 // ACE_DEBUG((LM_DEBUG,"bal =1%c",c
223 case 'd': // debug flag
226 case 'n': // loop count
227 this->loop_count_
= (u_int
) ACE_OS::atoi (get_opts
.opt_arg ());
229 case 'k': // ior provide on command line
230 this->ior_
= ACE_OS::strdup (ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ()));
232 case 'f': // read the IOR from the file.
233 result
= this->read_ior (get_opts
.opt_arg ());
235 ACE_ERROR_RETURN ((LM_ERROR
,
236 "[CLIENT] Process/Thread Id : (%P/%t) Unable to read ior from %s : %p\n",
237 get_opts
.opt_arg ()),
245 ACE_ERROR_RETURN ((LM_ERROR
,
257 // Indicates successful parsing of command line.
261 // Execute client example code.
266 // Retrieves the current universal time.
267 test_for_universal_time ();
269 // Asserts the validity of the new_universal_time.
270 test_for_new_universal_time ();
272 // Asserts the validity of the UTO created from a given UTC.
273 test_for_uto_from_utc ();
275 // Asserts the validity of the TIO created using the given
277 test_for_new_interval ();
279 // Throws an exception because the method has not been
280 // implemented currently.
281 test_for_secure_universal_time ();
286 Client_i::~Client_i (void)
288 ACE_OS::free (this->ior_
);
292 Client_i::obtain_initial_references (void)
297 // Initialize the naming services.
298 if (my_name_client_
.init (orb_
.in ()) != 0)
299 ACE_ERROR_RETURN ((LM_ERROR
,
300 "[CLIENT] Process/Thread Id : (%P/%t) Unable to initialize "
301 "the TAO_Naming_Client.\n"),
304 ACE_DEBUG ((LM_DEBUG
,
307 char host_name
[MAXHOSTNAMELEN
];
308 char name
[MAXHOSTNAMELEN
];
310 ACE_OS::hostname (host_name
, MAXHOSTNAMELEN
);
312 CosNaming::Name clerk_name
;
313 clerk_name
.length (2);
314 clerk_name
[0].id
= CORBA::string_dup ("ClerkContext");
315 ACE_OS::strcpy (name
, "Clerk:");
316 ACE_OS::strcat (name
, host_name
);
317 clerk_name
[1].id
= CORBA::string_dup (name
);
319 ACE_DEBUG ((LM_DEBUG
,
323 CORBA::Object_var temp_object
=
324 my_name_client_
->resolve (clerk_name
);
326 clerk_
= CosTime::TimeService::_narrow (temp_object
.in ());
328 if (CORBA::is_nil (clerk_
.in ()))
329 ACE_ERROR_RETURN ((LM_ERROR
,
330 "[CLIENT] Process/Thread Id : (%P/%t) Unable to Resolve "
331 "Clerk Reference\n"),
334 catch (const CORBA::Exception
& ex
)
336 ex
._tao_print_exception (
337 "Client :: obtain_initial_references\n");
344 // This method uses the IOR if specified on the command line or in a
345 // file, else it uses the Naming Service
348 Client_i::init (int argc
, ACE_TCHAR
**argv
)
356 this->orb_
= CORBA::ORB_init (this->argc_
, this->argv_
);
358 // Parse command line and verify parameters.
359 if (this->parse_args () == -1)
364 // An ior is specified for the client through a commandline
367 CORBA::Object_var server_object
=
368 this->orb_
->string_to_object (this->ior_
);
370 if (CORBA::is_nil (server_object
.in ()))
371 ACE_ERROR_RETURN ((LM_ERROR
,
372 "invalid ior <%C>\n",
376 CosTime::TimeService::_narrow (server_object
.in ());
378 ACE_DEBUG ((LM_DEBUG
,
379 "[CLIENT] Process/Thread Id : (%P/%t) Using the IOR provided\n"));
382 { // No IOR specified. Use the Naming Service
384 "[CLIENT] Process/Thread Id : (%P/%t) Using the Naming Service\n"));
386 if (this->obtain_initial_references () == -1)
391 catch (const CORBA::Exception
& ex
)
393 ex
._tao_print_exception ("Client_i::init\n");