Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / CSD_Strategy_Tests / TP_Common / AppHelper.h
blobbf55c5cbdda6122163240ba7207ae1b472e4357e
1 #ifndef APPHELPER_H
2 #define APPHELPER_H
4 #include "CSD_TP_Test_Export.h"
5 #include "TestAppExceptionC.h"
6 #include "tao/PortableServer/PortableServer.h"
7 #include "tao/ORB.h"
8 #include "ace/Log_Msg.h"
11 template <typename T>
12 struct RefHelper
14 typedef typename T::_ptr_type T_ptr;
15 typedef typename T::_var_type T_var;
17 static T_ptr string_to_ref(CORBA::ORB_ptr orb,
18 const ACE_TCHAR* ior)
20 CORBA::Object_var obj = orb->string_to_object(ior);
22 if (CORBA::is_nil(obj.in()))
24 ACE_ERROR((LM_ERROR,
25 "(%P|%t) Failed to convert IOR string to obj ref.\n"));
26 throw TestAppException();
29 T_var t_obj = T::_narrow(obj.in());
31 if (CORBA::is_nil(t_obj.in()))
33 ACE_ERROR((LM_ERROR,
34 "(%P|%t) Failed to narrow obj ref to T interface.\n"));
35 throw TestAppException();
38 return t_obj._retn();
41 static T_ptr resolve_initial_ref(CORBA::ORB_ptr orb,
42 const char* name)
44 CORBA::Object_var obj
45 = orb->resolve_initial_references(name);
47 if (CORBA::is_nil(obj.in()))
49 ACE_ERROR((LM_ERROR,
50 "(%P|%t) Failed to resolve initial ref for '%s'.\n",
51 name));
52 throw TestAppException();
55 T_var t_obj = T::_narrow(obj.in());
58 if (CORBA::is_nil(t_obj.in()))
60 ACE_ERROR((LM_ERROR,
61 "(%P|%t) Failed to narrow resolved initial ref '%s'.\n",
62 name));
63 throw TestAppException();
66 return t_obj._retn();
70 struct CSD_TP_Test_Export AppHelper
72 static void ref_to_file(CORBA::ORB_ptr orb,
73 CORBA::Object_ptr obj,
74 const ACE_TCHAR* filename);
76 static PortableServer::POA_ptr create_poa
77 (const char* name,
78 PortableServer::POA_ptr root_poa,
79 PortableServer::POAManager_ptr mgr,
80 CORBA::PolicyList& policies);
82 static CORBA::Object_ptr activate_servant(PortableServer::POA_ptr poa,
83 PortableServer::Servant servant);
85 // This helper method is used because there is a chance that the
86 // initial CORBA request made to the target ORB will fail during
87 // connection establishment with a TRANSIENT CORBA SystemException.
88 // This occurs for some platforms (ie, windows) when several clients
89 // make their initial CORBA request to the same ORB at the same time,
90 // causing the ORB to attempt to handle several connection establishments
91 // at one time. Apparently, under certain conditions, it will throw the
92 // TRANSIENT exception to tell the client application to "try again later".
93 // The analogy is making a phone call. Sometimes you get a busy tone.
94 // This means "try again later".
95 // This helper function will retry until the connection establishment
96 // works - or until it decides that enough is enough.
97 static bool validate_connection (CORBA::Object_ptr obj);
100 #endif