Merge pull request #1815 from sonndinh/get_signal_info
[ACE_TAO.git] / TAO / tests / Bug_1495_Regression / Client_Task.cpp
blob93bda38044a646bb11d586e775747d469b43ccf3
1 /**
2 * @file Client_Task.cpp
3 * @author Will Otte <wotte@dre.vanderbilt.edu
5 * Implements the Client_Task class defined in Client_Task.h.
6 */
8 #include "Client_Task.h"
9 #include "testC.h"
10 #include "Client_ORBInitializer.h"
11 #include "tid_to_int.h"
12 #include "ace/OS_NS_unistd.h"
13 #include "ace/OS_NS_sys_stat.h"
15 Client_Task::Client_Task (const ACE_TCHAR *input,
16 CORBA::ORB_ptr corb,
17 ACE_Thread_Manager *thr_mgr)
18 : ACE_Task_Base (thr_mgr),
19 input_ (input),
20 corb_ (CORBA::ORB::_duplicate (corb))
24 int
25 Client_Task::svc (void)
27 try
29 // The test was designed so that we have to wait here.
30 ACE_stat st;
31 int timeout = 10;
32 while (--timeout)
34 if (ACE_OS::stat (this->input_, &st) == 0 &&
35 st.st_size != 0)
37 break;
40 ACE_OS::sleep (1);
43 ACE_TString infile = ACE_TString (ACE_TEXT("file://")) + this->input_;
45 CORBA::Object_var object =
46 this->corb_->string_to_object (infile.c_str ());
48 Bug1495_Regression::Bug1495_var server =
49 Bug1495_Regression::Bug1495::_narrow (object.in ());
51 if (CORBA::is_nil (server.in ()))
53 ACE_ERROR ((LM_ERROR,
54 "Object reference <%s> is nil\n",
55 input_));
57 return 1;
60 // Try multiple calls to see if we keep being forwarded
61 for (int i = 0; i < 5; ++i)
63 using Bug1495_Regression::ThreadId;
65 // call the thread_id function on the test object
66 ThreadId remote_thread_id;
68 server->get_thread_id (remote_thread_id);
70 ACE_DEBUG ((LM_INFO,
71 ACE_TEXT ("Remote thread ID was ")
72 ACE_INT64_FORMAT_SPECIFIER
73 ACE_TEXT ("\n"),
74 remote_thread_id));
76 ThreadId const mythread_id =
77 ACE_thread_t_to_integer<ThreadId> (ACE_Thread::self ());
79 if (mythread_id != remote_thread_id)
81 ACE_ERROR ((LM_ERROR,
82 ACE_TEXT ("ERROR: Failed Bug_1495_Regression test. ")
83 ACE_TEXT ("Expected thread id was ")
84 ACE_INT64_FORMAT_SPECIFIER
85 ACE_TEXT (", received ")
86 ACE_INT64_FORMAT_SPECIFIER
87 ACE_TEXT (".\n"),
88 mythread_id,
89 remote_thread_id));
91 else
93 ACE_DEBUG ((LM_INFO,
94 ACE_TEXT ("Passed Bug_1495_Regression test.\n")
95 ACE_TEXT ("Local thread id was ")
96 ACE_INT64_FORMAT_SPECIFIER
97 ACE_TEXT (", received ")
98 ACE_INT64_FORMAT_SPECIFIER
99 ACE_TEXT (".\n"),
100 mythread_id,
101 remote_thread_id));
105 catch (const CORBA::Exception& ex)
107 ex._tao_print_exception ("Caught exception in client task:");
108 return 1;
111 return 0;