summaryrefslogtreecommitdiff
path: root/modules/CIAO/DAnCE/tests/RedirectionServiceTest/srv_main.cpp
blob: fa44d6b8b2f76710a5af162e8fa4a92ce50aa6f3 (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
// $Id$
#include "ace/OS_NS_stdio.h"
#include "ace/Get_Opt.h"
#include <orbsvcs/orbsvcs/Naming/Naming_Loader.h>
#include "DAnCE/Logger/Log_Macros.h"
#include "RedirectionService/RedirectionService.h"

#include "DummyC.h"
#include "DummyImpl.h"
#include "RegistrationPath.h"

using namespace Test;

int ACE_TMAIN (int argc, ACE_TCHAR * argv[])
{
//    try
  {
    int argcm = argc + 2;
    ACE_TCHAR ** argvm = new ACE_TCHAR* [argcm+1];
    for (int i = 0; i < argc; ++i)
      {
        argvm[i] = argv[i];
      }
    ACE_TCHAR buf1[32];
    ACE_OS::sprintf (buf1, ACE_TEXT("-ORBListenEndpoints"));
    argvm[argcm-2] = buf1;
    ACE_TCHAR buf2[32];
    ACE_OS::sprintf (buf2, ACE_TEXT("iiop://:12345"));
    argvm[argcm-1] = buf2;
    argvm[argcm] = 0;

    CORBA::ORB_var orb = CORBA::ORB_init (argcm, argvm);

    CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
    PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj.in ());

    PortableServer::POAManager_var poa_manager = root_poa->the_POAManager();
    poa_manager->activate();

    DummyImpl servant;

    PortableServer::ObjectId_var id = root_poa->activate_object (&servant);

    Dummy_var dummy_obj = Dummy::_narrow (root_poa->id_to_reference (id));

    TAO_Naming_Loader loader;

    CORBA::Object_var obj_tmp = loader.create_object (orb.in(), argcm, argvm);
    CORBA::Object_var naming_obj =
      orb->resolve_initial_references ("NameService");
    CosNaming::NamingContext_var naming =
      CosNaming::NamingContext::_narrow (naming_obj.in());

    DAnCE::RedirectionService redirection (orb.in(),
                                           root_poa.in(),
                                           naming.in(),
                                           CosNaming::NamingContext::_nil(),
                                           true,
                                           true);

    redirection.registration_start (node_name, app_name);
    redirection.registration (node_name, app_name, inst_name, port_name, dummy_obj.in());
    DANCE_DEBUG((LM_DEBUG, "[%M] Registration for port have finished.\n\n"));
    redirection.registration (node_name, app_name, inst_name, dummy_obj.in());
    DANCE_DEBUG((LM_DEBUG, "[%M] Registration for component have finished.\n\n"));
    redirection.registration_finish (node_name, app_name);
    orb->run();
  }
//    catch (...)
//    {
//        DANCE_ERROR((LM_ERROR, "[%M] An error has occured."));
//    }
  return 0;
}