summaryrefslogtreecommitdiff
path: root/TAO/tests/CSD_Strategy_Tests/TP_Common/AppHelper.cpp
blob: 2cddb374de7fdc54cb71d4d890c4a6aaa8110297 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// $Id$
#include "AppHelper.h"

void
AppHelper::ref_to_file(CORBA::ORB_ptr    orb,
                       CORBA::Object_ptr obj,
                       const char*       filename)
{
  CORBA::String_var ior = orb->object_to_string(obj);

  FILE* ior_file = ACE_OS::fopen(filename, (const ACE_TCHAR *)("w"));

  if (ior_file == 0)
    {
      ACE_ERROR((LM_ERROR,
                 "(%P|%t) Cannot open output file [%s] to write IOR.\n",
                 filename));
      throw TestAppException();
    }

  ACE_OS::fprintf(ior_file, "%s", ior.in());
  ACE_OS::fclose(ior_file);
}


PortableServer::POA_ptr
AppHelper::create_poa(const char*                    name,
                      PortableServer::POA_ptr        root_poa,
                      PortableServer::POAManager_ptr mgr,
                      CORBA::PolicyList&             policies)
{
  PortableServer::POA_var child_poa = root_poa->create_POA(name,
                                                           mgr,
                                                           policies);

  if (CORBA::is_nil(child_poa.in()))
    {
      ACE_ERROR((LM_ERROR,
                 "(%P|%t) Failed to create child POA: %s.\n", name));
      throw TestAppException();
    }

  return child_poa._retn();
}


CORBA::Object_ptr
AppHelper::activate_servant(PortableServer::POA_ptr poa,
                            PortableServer::Servant servant)
{
  // Activate the servant using the Child POA.
  PortableServer::ObjectId_var oid
    = poa->activate_object(servant);

  CORBA::Object_var obj
    = poa->servant_to_reference(servant);

  if (CORBA::is_nil(obj.in()))
    {
      ACE_ERROR((LM_ERROR,
                 "(%P|%t) Failed to convert servant_to_ref.\n"));
      throw TestAppException();
    }

  return obj._retn();
}


bool
AppHelper::validate_connection (CORBA::Object_ptr obj)
{
  for (CORBA::ULong j = 0; j != 100; ++j)
    {
      try
        {
#if (TAO_HAS_CORBA_MESSAGING == 1)
          CORBA::PolicyList_var unused;
          obj->_validate_connection (unused);
#else
          obj->_is_a ("Not_An_IDL_Type");
#endif /* TAO_HAS_MESSAGING == 1 */
          return true;
        }
      catch (const CORBA::Exception&)
        {
        }
    }

  return false;
}