summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Notify/PluggableTopology/main.cpp
blob: ea040206afcc21622eba11ddfa35dbb97c56ae18 (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
/**
 *  $Id$
 */

#include "orbsvcs/CosNotifyChannelAdminC.h"
//#include <orbsvcs/CosNotifyCommS.h>
//#include <orbsvcs/CosNotificationS.h>
#include "tao/TimeBaseC.h"

#include "ace/ARGV.h"
#include "ace/OS_NS_stdio.h"

using namespace CORBA;
namespace CNCA = CosNotifyChannelAdmin;
namespace CN = CosNotification;
namespace CNC = CosNotifyComm;

const char* NOTIFY_IOR = "corbaloc::localhost:9050/NotifyEventChannelFactory";

ORB_var orb;
CNCA::EventChannelFactory_var ecf;

namespace {
  void init_qos_props(CN::QoSProperties& qos, bool topology_persist) {
    qos.length(13);
    ULong i = 0;
    qos[i].name = "EventReliability";
    qos[i++].value <<= CN::BestEffort;
    if (topology_persist) {
      qos[i].name = "ConnectionReliability";
      qos[i++].value <<= CN::Persistent;
    }
    else
    {
      qos[i].name = "ConnectionReliability";
      qos[i++].value <<= CN::BestEffort;
    }
    qos[i].name = "Priority";
    qos[i++].value <<= (Short) 1234;
    qos[i].name = "Timeout";
    qos[i++].value <<= (TimeBase::TimeT) 55555; // 5.5555 ms
    qos[i].name = "MaximumBatchSize";
    qos[i++].value <<= (Long) 200;
    qos[i].name = "PacingInterval";
    qos[i++].value <<= (TimeBase::TimeT) 42000; // 4.2ms
    qos[i].name = "StopTimeSupported";
    qos[i++].value <<= Any::from_boolean(0);
    qos.length(i);
  }
  void init_admin_props(CN::AdminProperties& admin) {
    admin.length(13);
    ULong i = 0;
    admin[i].name = "MaxQueueLength";
    admin[i++].value <<= (Long) 200;
    admin[i].name = "MaxConsumers";
    admin[i++].value <<= (Long) 2;
    admin[i].name = "MaxSuppliers";
    admin[i++].value <<= (Long) 1;
    admin[i].name = "RejectNewEvents";
    admin[i++].value <<= Any::from_boolean(1);
  }
  void setUp()
  {
    ACE_ARGV av;
    int ac = 0;
    orb = ORB_init(ac, av.argv());
    ACE_ASSERT(! is_nil(orb.in()));
    Object_var obj = orb->string_to_object(NOTIFY_IOR);
    ACE_ASSERT(! is_nil(obj.in()));
    ecf = CNCA::EventChannelFactory::_narrow(obj.in());
    ACE_ASSERT(! is_nil(ecf.in()));
  }

  void tearDown()
  {
    ecf = CNCA::EventChannelFactory::_nil();
    orb->destroy();
    orb = ORB::_nil();
  }
}


int main(int, char**)
{
  try
  {
    setUp();

    CN::QoSProperties qos;
    CN::AdminProperties admin;
    init_qos_props(qos, true);
    init_admin_props(admin);

    CNCA::ChannelID ecid;
    CNCA::EventChannel_var ec = ecf->create_channel(qos, admin, ecid);

    ACE_OS::printf("Created channel id=\"%ld\"\n", static_cast<long>(ecid));

    tearDown();

    return 0;
  }
  catch (Exception& e)
  {
    ACE_OS::fputs(e._name (), stderr);
    ACE_OS::fputs("\n", stderr);
  }
  return 1;
}