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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
// **********************************************************************
//
// Copyright (c) 2003-present ZeroC, Inc. All rights reserved.
//
// **********************************************************************
#include <Ice/Ice.h>
#include <TestHelper.h>
#include <TestI.h>
#include <Configuration.h>
#include <PluginI.h>
#include <Ice/Locator.h>
#include <Ice/Router.h>
#ifdef _MSC_VER
# pragma comment(lib, ICE_LIBNAME("testtransport"))
#endif
using namespace std;
extern "C"
{
Ice::Plugin* createTestTransport(const Ice::CommunicatorPtr&, const std::string&, const Ice::StringSeq&);
};
class LocatorI : public Ice::Locator
{
public:
#ifdef ICE_CPP11_MAPPING
virtual void
findAdapterByIdAsync(string,
function<void(const shared_ptr<Ice::ObjectPrx>&)> response,
function<void(exception_ptr)>,
const Ice::Current& current) const
{
_controller->checkCallPause(current);
Ice::CommunicatorPtr communicator = current.adapter->getCommunicator();
response(current.adapter->createDirectProxy(Ice::stringToIdentity("dummy")));
}
virtual void
findObjectByIdAsync(Ice::Identity id,
function<void(const shared_ptr<Ice::ObjectPrx>&)> response,
function<void(exception_ptr)>,
const Ice::Current& current) const
{
_controller->checkCallPause(current);
Ice::CommunicatorPtr communicator = current.adapter->getCommunicator();
response(current.adapter->createDirectProxy(id));
}
#else
virtual void
findAdapterById_async(const Ice::AMD_Locator_findAdapterByIdPtr& response, const string&,
const Ice::Current& current) const
{
_controller->checkCallPause(current);
Ice::CommunicatorPtr communicator = current.adapter->getCommunicator();
response->ice_response(current.adapter->createDirectProxy(Ice::stringToIdentity("dummy")));
}
virtual void
findObjectById_async(const Ice::AMD_Locator_findObjectByIdPtr& response, const Ice::Identity& id,
const Ice::Current& current) const
{
_controller->checkCallPause(current);
Ice::CommunicatorPtr communicator = current.adapter->getCommunicator();
response->ice_response(current.adapter->createDirectProxy(id));
}
#endif
virtual Ice::LocatorRegistryPrxPtr
getRegistry(const Ice::Current&) const
{
return ICE_NULLPTR;
}
LocatorI(const BackgroundControllerIPtr& controller) : _controller(controller)
{
}
private:
BackgroundControllerIPtr _controller;
};
class RouterI : public Ice::Router
{
public:
virtual Ice::ObjectPrxPtr
getClientProxy(IceUtil::Optional<bool>& hasRoutingTable, const Ice::Current& current) const
{
hasRoutingTable = true;
_controller->checkCallPause(current);
return ICE_NULLPTR;
}
virtual Ice::ObjectPrxPtr
getServerProxy(const Ice::Current& current) const
{
_controller->checkCallPause(current);
return ICE_NULLPTR;
}
virtual Ice::ObjectProxySeq
addProxies(ICE_IN(Ice::ObjectProxySeq), const Ice::Current&)
{
return Ice::ObjectProxySeq();
}
RouterI(const BackgroundControllerIPtr& controller)
{
_controller = controller;
}
private:
BackgroundControllerIPtr _controller;
};
class Server : public Test::TestHelper
{
public:
void run(int, char**);
};
void
Server::run(int argc, char** argv)
{
#ifdef ICE_STATIC_LIBS
Ice::registerPluginFactory("Test", createTestTransport, false);
#endif
Ice::PropertiesPtr properties = createTestProperties(argc, argv);
//
// This test kills connections, so we don't want warnings.
//
properties->setProperty("Ice.Warn.Connections", "0");
properties->setProperty("Ice.MessageSizeMax", "50000");
//
// This test relies on filling the TCP send/recv buffer, so
// we rely on a fixed value for these buffers.
//
properties->setProperty("Ice.TCP.RcvSize", "50000");
//
// Setup the test transport plug-in.
//
properties->setProperty("Ice.Plugin.Test", "TestTransport:createTestTransport");
string defaultProtocol = properties->getPropertyWithDefault("Ice.Default.Protocol", "tcp");
properties->setProperty("Ice.Default.Protocol", "test-" + defaultProtocol);
Ice::CommunicatorHolder communicator = initialize(argc, argv, properties);
communicator->getProperties()->setProperty("TestAdapter.Endpoints", getTestEndpoint(0));
communicator->getProperties()->setProperty("ControllerAdapter.Endpoints", getTestEndpoint(1, "tcp"));
communicator->getProperties()->setProperty("ControllerAdapter.ThreadPool.Size", "1");
Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter");
Ice::ObjectAdapterPtr adapter2 = communicator->createObjectAdapter("ControllerAdapter");
#ifdef ICE_CPP11_MAPPING
shared_ptr<PluginI> plugin = dynamic_pointer_cast<PluginI>(communicator->getPluginManager()->getPlugin("Test"));
#else
PluginI* plugin = dynamic_cast<PluginI*>(communicator->getPluginManager()->getPlugin("Test").get());
#endif
assert(plugin);
ConfigurationPtr configuration = plugin->getConfiguration();
BackgroundControllerIPtr backgroundController = ICE_MAKE_SHARED(BackgroundControllerI, adapter, configuration);
adapter->add(ICE_MAKE_SHARED(BackgroundI, backgroundController), Ice::stringToIdentity("background"));
adapter->add(ICE_MAKE_SHARED(LocatorI, backgroundController), Ice::stringToIdentity("locator"));
adapter->add(ICE_MAKE_SHARED(RouterI, backgroundController), Ice::stringToIdentity("router"));
adapter->activate();
adapter2->add(backgroundController, Ice::stringToIdentity("backgroundController"));
adapter2->activate();
communicator->waitForShutdown();
}
DEFINE_TEST(Server)
|