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"
23 // The following test throws an exception that the operation
24 // <secure_universal_time> has not been currently implemented in the
28 Client_i::test_for_secure_universal_time ()
31 "[CLIENT] Process/Thread Id : (%P/%t) Testing secure_time()\n"));
35 CosTime::UTO_var UTO_server
=
36 this->clerk_
->secure_universal_time ();
38 catch (const CORBA::SystemException
& sysex
)
40 sysex
._tao_print_exception ("System Exception");
42 "[CLIENT] Process/Thread Id : (%P/%t) test_for_secure_universal_time() successful !!\n"));
46 // The following test retrieves the current universal time as a UTO
47 // from the clerk_ and prints out the various attributes of the UTO.
50 Client_i::test_for_universal_time ()
53 "[CLIENT] Process/Thread Id : (%P/%t) Testing universal_time()\n"));
56 CosTime::UTO_var UTO_server
=
57 this->clerk_
->universal_time ();
60 "\nTime = %Q\nInaccuracy = %Q\nTimeDiff = %d\nstruct.time = %Q"
61 "\nstruct.inacclo = %d\nstruct.inacchi = %d\nstruct.Tdf = %d\n",
63 UTO_server
->inaccuracy (),
65 (UTO_server
->utc_time ()).time
,
66 (UTO_server
->utc_time ()).inacclo
,
67 (UTO_server
->utc_time ()).inacchi
,
68 (UTO_server
->utc_time ()).tdf
));
70 catch (const CORBA::Exception
& ex
)
72 ex
._tao_print_exception ("Error:");
74 "[CLIENT] Process/Thread Id : (%P/%t) test_for_universal_time()\n"));
79 Client_i::test_for_new_universal_time ()
81 TimeBase::TimeT time
= 999999999;
82 TimeBase::InaccuracyT inaccuracy
= 9999;
83 TimeBase::TdfT tdf
= 99;
86 "[CLIENT] Process/Thread Id : (%P/%t) Testing new_universal_time()\n"));
90 CosTime::UTO_var UTO_server
= this->clerk_
->new_universal_time (time
,
94 ACE_ASSERT (UTO_server
->time () == 999999999);
95 ACE_ASSERT (UTO_server
->inaccuracy () == 9999);
96 ACE_ASSERT (UTO_server
->tdf () == 99);
97 ACE_ASSERT ((UTO_server
->utc_time ()).time
== 999999999);
98 ACE_ASSERT ((UTO_server
->utc_time ()).inacchi
== 0);
99 ACE_ASSERT ((UTO_server
->utc_time ()).inacclo
== 9999);
100 ACE_ASSERT ((UTO_server
->utc_time ()).tdf
== 99);
102 catch (const CORBA::Exception
& ex
)
104 ACE_DEBUG ((LM_DEBUG
,
105 "[CLIENT] Process/Thread Id : (%P/%t) Test new_universal_time () fails.\n"));
106 ex
._tao_print_exception ("Exception :\n");
111 Client_i::test_for_uto_from_utc ()
113 TimeBase::UtcT utc_struct
;
115 utc_struct
.time
= 999999999;
116 utc_struct
.inacclo
= 50;
117 utc_struct
.inacchi
= 50;
120 ACE_DEBUG ((LM_DEBUG
,
121 "[CLIENT] Process/Thread Id : (%P/%t) Testing uto_from_utc ()\n"));
125 CosTime::UTO_var UTO_server
= this->clerk_
->uto_from_utc (utc_struct
);
127 TimeBase::InaccuracyT inaccuracy
= utc_struct
.inacchi
;
129 inaccuracy
|= utc_struct
.inacclo
;
131 ACE_ASSERT (UTO_server
->time () == 999999999);
132 ACE_ASSERT (UTO_server
->inaccuracy () == inaccuracy
);
133 ACE_ASSERT (UTO_server
->tdf () == 99);
134 ACE_ASSERT ((UTO_server
->utc_time ()).time
== 999999999);
135 ACE_ASSERT ((UTO_server
->utc_time ()).inacclo
== 50);
136 ACE_ASSERT ((UTO_server
->utc_time ()).inacchi
== 50);
137 ACE_ASSERT ((UTO_server
->utc_time ()).tdf
== 99);
139 catch (const CORBA::Exception
& ex
)
141 ACE_DEBUG ((LM_DEBUG
,
142 "[CLIENT] Process/Thread Id : (%P/%t) Test uto_from_utc () fails.\n"));
143 ex
._tao_print_exception ("Exception :\n");
148 Client_i::test_for_new_interval ()
150 TimeBase::TimeT lower
= 666666666;
151 TimeBase::TimeT upper
= 999999999;
153 ACE_DEBUG ((LM_DEBUG
,
154 "[CLIENT] Process/Thread Id : (%P/%t) Testing new_interval ()\n"));
158 CosTime::TIO_var TIO_server
= this->clerk_
->new_interval (lower
,
161 ACE_ASSERT ((TIO_server
->time_interval ()).lower_bound
== 666666666);
162 ACE_ASSERT ((TIO_server
->time_interval ()).upper_bound
== 999999999);
164 catch (const CORBA::Exception
& ex
)
166 ACE_DEBUG ((LM_DEBUG
,
167 "[CLIENT] Process/Thread Id : (%P/%t) Test new_interval () fails.\n"));
168 ex
._tao_print_exception ("Exception :\n");
174 // Reads the Time Service Server ior from a file
177 Client_i::read_ior (ACE_TCHAR
*filename
)
179 // Open the file for reading.
180 ACE_HANDLE f_handle
= ACE_OS::open (filename
, 0);
182 if (f_handle
== ACE_INVALID_HANDLE
)
183 ACE_ERROR_RETURN ((LM_ERROR
,
184 "[CLIENT] Process/Thread Id : (%P/%t) Unable to open %s for writing: %p\n",
188 ACE_Read_Buffer
ior_buffer (f_handle
);
189 char *data
= ior_buffer
.read ();
192 ACE_ERROR_RETURN ((LM_ERROR
,
193 "[CLIENT] Process/Thread Id : (%P/%t) Unable to read ior: %p\n"),
196 this->ior_
= ACE_OS::strdup (data
);
197 ior_buffer
.alloc ()->free (data
);
199 ACE_OS::close (f_handle
);
204 // Parses the command line arguments and returns an error status.
207 Client_i::parse_args ()
209 ACE_Get_Opt
get_opts (argc_
, argv_
, ACE_TEXT("dn:f:xk:"));
213 while ((c
= get_opts ()) != -1)
214 // ACE_DEBUG((LM_DEBUG,"bal =1%c",c
218 case 'd': // debug flag
221 case 'n': // loop count
222 this->loop_count_
= (u_int
) ACE_OS::atoi (get_opts
.opt_arg ());
224 case 'k': // ior provide on command line
225 this->ior_
= ACE_OS::strdup (ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ()));
227 case 'f': // read the IOR from the file.
228 result
= this->read_ior (get_opts
.opt_arg ());
230 ACE_ERROR_RETURN ((LM_ERROR
,
231 "[CLIENT] Process/Thread Id : (%P/%t) Unable to read ior from %s : %p\n",
232 get_opts
.opt_arg ()),
240 ACE_ERROR_RETURN ((LM_ERROR
,
252 // Indicates successful parsing of command line.
256 // Execute client example code.
261 // Retrieves the current universal time.
262 test_for_universal_time ();
264 // Asserts the validity of the new_universal_time.
265 test_for_new_universal_time ();
267 // Asserts the validity of the UTO created from a given UTC.
268 test_for_uto_from_utc ();
270 // Asserts the validity of the TIO created using the given
272 test_for_new_interval ();
274 // Throws an exception because the method has not been
275 // implemented currently.
276 test_for_secure_universal_time ();
281 Client_i::~Client_i ()
283 ACE_OS::free (this->ior_
);
287 Client_i::obtain_initial_references ()
291 // Initialize the naming services.
292 if (my_name_client_
.init (orb_
.in ()) != 0)
293 ACE_ERROR_RETURN ((LM_ERROR
,
294 "[CLIENT] Process/Thread Id : (%P/%t) Unable to initialize "
295 "the TAO_Naming_Client.\n"),
298 ACE_DEBUG ((LM_DEBUG
,
301 char host_name
[MAXHOSTNAMELEN
];
302 char name
[MAXHOSTNAMELEN
];
304 ACE_OS::hostname (host_name
, MAXHOSTNAMELEN
);
306 CosNaming::Name clerk_name
;
307 clerk_name
.length (2);
308 clerk_name
[0].id
= CORBA::string_dup ("ClerkContext");
309 ACE_OS::strcpy (name
, "Clerk:");
310 ACE_OS::strcat (name
, host_name
);
311 clerk_name
[1].id
= CORBA::string_dup (name
);
313 ACE_DEBUG ((LM_DEBUG
,
317 CORBA::Object_var temp_object
=
318 my_name_client_
->resolve (clerk_name
);
320 clerk_
= CosTime::TimeService::_narrow (temp_object
.in ());
322 if (CORBA::is_nil (clerk_
.in ()))
323 ACE_ERROR_RETURN ((LM_ERROR
,
324 "[CLIENT] Process/Thread Id : (%P/%t) Unable to Resolve "
325 "Clerk Reference\n"),
328 catch (const CORBA::Exception
& ex
)
330 ex
._tao_print_exception (
331 "Client :: obtain_initial_references\n");
338 // This method uses the IOR if specified on the command line or in a
339 // file, else it uses the Naming Service
342 Client_i::init (int argc
, ACE_TCHAR
**argv
)
350 this->orb_
= CORBA::ORB_init (this->argc_
, this->argv_
);
352 // Parse command line and verify parameters.
353 if (this->parse_args () == -1)
358 // An ior is specified for the client through a commandline
361 CORBA::Object_var server_object
=
362 this->orb_
->string_to_object (this->ior_
);
364 if (CORBA::is_nil (server_object
.in ()))
365 ACE_ERROR_RETURN ((LM_ERROR
,
366 "invalid ior <%C>\n",
370 CosTime::TimeService::_narrow (server_object
.in ());
372 ACE_DEBUG ((LM_DEBUG
,
373 "[CLIENT] Process/Thread Id : (%P/%t) Using the IOR provided\n"));
376 { // No IOR specified. Use the Naming Service
378 "[CLIENT] Process/Thread Id : (%P/%t) Using the Naming Service\n"));
380 if (this->obtain_initial_references () == -1)
384 catch (const CORBA::Exception
& ex
)
386 ex
._tao_print_exception ("Client_i::init\n");