summaryrefslogtreecommitdiff
path: root/modules/CIAO/DAnCE/tests/RedirectionServiceTest/clt_main.cpp
blob: 84ecb82f476f18035f18869d4ed35f518db4abd1 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// $Id$
#include "ace/String_Base.h"
#include <orbsvcs/orbsvcs/CosNamingC.h>
#include "DAnCE/Logger/Log_Macros.h"
#include "RegistrationPath.h"
#include "DummyC.h"
#include "ace/SString.h"

using namespace Test;

CORBA::ORB_var orb;
CORBA::Object_var naming_obj;

void inspect ()
  {
    CORBA::Object_var obj = orb->resolve_initial_references("NameService");
    CosNaming::NamingContext_var naming = CosNaming::NamingContext::_narrow(obj.in());
    CosNaming::BindingList_var bl;
    CosNaming::BindingIterator_var bi;
    //naming->list(10L, bl.out(), bi.out());
    CosNaming::Name name(1);
    name.length(2);
    name[0].id = CORBA::string_dup("Host1");//CORBA::string_dup("CcmDance1Test");
    name[1].id = CORBA::string_dup ("CcmDance2_1@Host1");
    name[1].kind = CORBA::string_dup ("DeploymentPlan");
    //name[2].id = CORBA::string_dup("ASSEMBLYANDDEPLOYMENT");
    obj = naming->resolve(name);
    DANCE_DEBUG((LM_DEBUG, "[%M] create_external_connections - After resolve\n"));
    CosNaming::NamingContext_var CcmDance1Test = CosNaming::NamingContext::_narrow(obj.in());
    CcmDance1Test->list(10L, bl.out(), bi.out());
    bool exit = false;
    while (!exit)
    {
        DANCE_DEBUG((LM_DEBUG, "[%M] create_external_connections - naming size is %u\n", bl->length()));
        for ( size_t i = 0; i< bl->length(); i++ )
        {
            for ( size_t j = 0; j < (*bl)[i].binding_name.length(); j++ )
            {
                DANCE_DEBUG((LM_DEBUG,  "create_external_connections - Binding name %s, binding kind %s, binding type %i\n"
                                      , (*bl)[i].binding_name[j].id.in()
                                      , (*bl)[i].binding_name[j].kind.in()
                                      , (*bl)[i].binding_type));
            }
        }
        if(!bi->next_n(10L, bl.out()))
        {
            exit = true;
        }
    }

  }
bool test (const ACE_CString& url)
{
  bool res = false;
  try
    {
      DANCE_DEBUG((LM_DEBUG, "[%M] URL : %s\n", url.c_str()));

      CORBA::Object_var obj = orb->string_to_object (url.c_str());
      if (CORBA::is_nil (obj))
        {
          DANCE_ERROR((LM_ERROR, "[%M] Failed to convert url to object. The test failed.\n"));
          return 1;
        }
      DANCE_DEBUG((LM_DEBUG, "[%M] URL -> object : ok.\n"));

      Dummy_var dummy_obj = Dummy::_narrow (obj);
      if (CORBA::is_nil (dummy_obj))
        {
          DANCE_ERROR((LM_ERROR, "[%M] Failed to narrow the object to custom type. The test failed.\n"));
          return 1;
        }
      DANCE_DEBUG((LM_DEBUG, "[%M] object -> dummy : ok.\n"));

      DANCE_DEBUG((LM_DEBUG, "[%M] Dummy object returned : %s.\n", dummy_obj->sayHello()));
      DANCE_DEBUG((LM_DEBUG, "[%M] The test succeeded.\n"));
      res = true;
    }
  catch (CORBA::Exception & e)
    {
      DANCE_ERROR((LM_ERROR, "[%M] A CORBA exception \"%s\" (%s) was thrown. The test failed."
                   , e._name(), e._info().c_str()));
    }
  catch (...)
    {
      DANCE_ERROR((LM_ERROR, "[%M] An exception was thrown. The test failed.\n"));
    }

  return res;
}


int ACE_TMAIN (int argc, ACE_TCHAR * argv[])
{
  orb = CORBA::ORB_init (argc, argv);

  //naming_obj = orb->resolve_initial_references("NameService");
  //glasgow.headquarters.eclipsesp.com:12345
  ACE_CString url = "corbaname::glasgow:12345#" + node_name + "/" + app_name + ".DeploymentPlan" + "/" + inst_name + "/" + port_name + ".Port";
  test (url);
  url = "corbaname::glasgow:12345#" + node_name + "/" + app_name + ".DeploymentPlan" + "/" + inst_name + ".Component";
  test (url);
  //node_name + "/" +                                               %14%01%0f%00NUP%00%00%00%17%01%00%00%00%01%00%00%00RootPOA%00MyNode%00
  url = "corbaloc:iiop:1.2@glasgow.headquarters.eclipsesp.com:12345/%14%01%0f%00NUP%00%00%00%17%01%00%00%00%01%00%00%00RootPOA%00MyNode%00" + app_name + "/" + inst_name + "/" + port_name;
  test (url);
  url = "corbaloc:iiop:1.2@glasgow.headquarters.eclipsesp.com:12345/%14%01%0f%00NUP%00%00%00%17%01%00%00%00%01%00%00%00RootPOA%00MyNode%00" + app_name + "/" + inst_name;
  test (url);

  return 0;
}