Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / performance-tests / CSD_Strategy / TestInf / AppHelper.h
blob816486a8d6cf47cf85367d1dcdec68dc54d8ffca
1 #ifndef APPHELPER_H
2 #define APPHELPER_H
4 #include "CSD_PT_TestInf_Export.h"
5 #include "TestInf/TestAppExceptionC.h"
6 #include "tao/PortableServer/PortableServer.h"
7 #include "tao/ORB.h"
8 #include "ace/Log_Msg.h"
10 template <typename T>
11 struct RefHelper
13 typedef typename T::_ptr_type T_ptr;
14 typedef typename T::_var_type T_var;
16 static T_ptr string_to_ref(CORBA::ORB_ptr orb,
17 const ACE_TCHAR* ior)
19 CORBA::Object_var obj = orb->string_to_object(ior);
21 if (CORBA::is_nil(obj.in()))
23 ACE_ERROR((LM_ERROR,
24 "(%P|%t) Failed to convert IOR string to obj ref.\n"));
25 throw TestAppException();
28 T_var t_obj = T::_narrow(obj.in());
30 if (CORBA::is_nil(t_obj.in()))
32 ACE_ERROR((LM_ERROR,
33 "(%P|%t) Failed to narrow obj ref to T interface.\n"));
34 throw TestAppException();
37 return t_obj._retn();
40 static T_ptr resolve_initial_ref(CORBA::ORB_ptr orb,
41 const char* name)
43 CORBA::Object_var obj
44 = orb->resolve_initial_references(name);
46 if (CORBA::is_nil(obj.in()))
48 ACE_ERROR((LM_ERROR,
49 "(%P|%t) Failed to resolve initial ref for '%s'.\n",
50 name));
51 throw TestAppException();
54 T_var t_obj = T::_narrow(obj.in());
57 if (CORBA::is_nil(t_obj.in()))
59 ACE_ERROR((LM_ERROR,
60 "(%P|%t) Failed to narrow resolved initial ref '%s'.\n",
61 name));
62 throw TestAppException();
65 return t_obj._retn();
69 struct CSD_PT_TestInf_Export AppHelper
71 static void ref_to_file(CORBA::ORB_ptr orb,
72 CORBA::Object_ptr obj,
73 const ACE_TCHAR* filename);
75 static PortableServer::POA_ptr create_poa
76 (const char* name,
77 PortableServer::POA_ptr root_poa,
78 PortableServer::POAManager_ptr mgr,
79 CORBA::PolicyList& policies);
81 static CORBA::Object_ptr activate_servant(PortableServer::POA_ptr poa,
82 PortableServer::Servant servant);
84 // This helper method is used because there is a chance that the
85 // initial CORBA request made to the target ORB will fail during
86 // connection establishment with a TRANSIENT CORBA SystemException.
87 // This occurs for some platforms (ie, windows) when several clients
88 // make their initial CORBA request to the same ORB at the same time,
89 // causing the ORB to attempt to handle several connection establishments
90 // at one time. Apparently, under certain conditions, it will throw the
91 // TRANSIENT exception to tell the client application to "try again later".
92 // The analogy is making a phone call. Sometimes you get a busy tone.
93 // This means "try again later".
94 // This helper function will retry until the connection establishment
95 // works - or until it decides that enough is enough.
96 static bool validate_connection (CORBA::Object_ptr obj);
99 #endif