summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/CommunicatorI.cpp
blob: 02ff7d95913bb0a25e623e22c02f2ce05c38a83e (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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// **********************************************************************
//
// Copyright (c) 2001
// MutableRealms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************

#include <Ice/CommunicatorI.h>
#include <Ice/PropertiesI.h>
#include <Ice/Instance.h>
#include <Ice/ProxyFactory.h>
#include <Ice/ThreadPool.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/ValueFactoryManager.h>
#include <Ice/ObjectAdapterFactory.h>
#include <Ice/Logger.h>
#include <Ice/Initialize.h>
#include <Ice/LocalException.h>

using namespace std;
using namespace Ice;
using namespace IceInternal;

void
Ice::CommunicatorI::destroy()
{
    JTCSyncT<JTCRecursiveMutex> sync(*this);
    shutdown();
    _instance->destroy();
    _instance = 0;
}

void
Ice::CommunicatorI::shutdown()
{
    JTCSyncT<JTCRecursiveMutex> sync(*this);
    if (!_instance)
    {
	throw CommunicatorDestroyedException(__FILE__, __LINE__);
    }
    _instance->objectAdapterFactory()->shutdown();
}

void
Ice::CommunicatorI::waitForShutdown()
{
    ThreadPoolPtr threadPool;

    {
	JTCSyncT<JTCRecursiveMutex> sync(*this);
	if (!_instance)
	{
	    throw CommunicatorDestroyedException(__FILE__, __LINE__);
	}
	threadPool = _instance->threadPool();
    }

    threadPool->waitUntilServerFinished();
}

ObjectPrx
Ice::CommunicatorI::stringToProxy(const string& s)
{
    JTCSyncT<JTCRecursiveMutex> sync(*this);
    if (!_instance)
    {
	throw CommunicatorDestroyedException(__FILE__, __LINE__);
    }
    return _instance->proxyFactory()->stringToProxy(s);
}

ObjectAdapterPtr
Ice::CommunicatorI::createObjectAdapter(const string& name)
{
    JTCSyncT<JTCRecursiveMutex> sync(*this);
    if (!_instance)
    {
	throw CommunicatorDestroyedException(__FILE__, __LINE__);
    }
    string endpts = _instance->properties()->getProperty("Ice.Adapter." + name + ".Endpoints");
    return createObjectAdapterWithEndpoints(name, endpts);
}

ObjectAdapterPtr
Ice::CommunicatorI::createObjectAdapterWithEndpoints(const string& name, const string& endpts)
{
    JTCSyncT<JTCRecursiveMutex> sync(*this);
    if (!_instance)
    {
	throw CommunicatorDestroyedException(__FILE__, __LINE__);
    }
    return _instance->objectAdapterFactory() -> createObjectAdapter(name, endpts);
}

void
Ice::CommunicatorI::installValueFactory(const ValueFactoryPtr& factory, const string& id)
{
    JTCSyncT<JTCRecursiveMutex> sync(*this);
    if (!_instance)
    {
	throw CommunicatorDestroyedException(__FILE__, __LINE__);
    }
    _instance->valueFactoryManager()->install(factory, id);
}

PropertiesPtr
Ice::CommunicatorI::getProperties()
{
    JTCSyncT<JTCRecursiveMutex> sync(*this);
    if (!_instance)
    {
	throw CommunicatorDestroyedException(__FILE__, __LINE__);
    }
    return _instance->properties();
}

LoggerPtr
Ice::CommunicatorI::getLogger()
{
    JTCSyncT<JTCRecursiveMutex> sync(*this);
    if (!_instance)
    {
	throw CommunicatorDestroyedException(__FILE__, __LINE__);
    }
    return _instance->logger();
}

void
Ice::CommunicatorI::setLogger(const LoggerPtr& logger)
{
    JTCSyncT<JTCRecursiveMutex> sync(*this);
    if (!_instance)
    {
	throw CommunicatorDestroyedException(__FILE__, __LINE__);
    }
    _instance->logger(logger);
}

PicklerPtr
Ice::CommunicatorI::getPickler()
{
    JTCSyncT<JTCRecursiveMutex> sync(*this);
    if (!_instance)
    {
	throw CommunicatorDestroyedException(__FILE__, __LINE__);
    }
    return _instance->pickler();
}

Ice::CommunicatorI::CommunicatorI(const PropertiesPtr& properties) :
    _instance(new ::IceInternal::Instance(this, properties))
{
}

Ice::CommunicatorI::~CommunicatorI()
{
    if (_instance)
    {
	_instance->logger()->warning("communicator object has not been destroyed");
    }
}

CommunicatorPtr
Ice::initialize(int&, char*[], Int version)
{
#ifndef ICE_IGNORE_VERSION
    if (version != ICE_INT_VERSION)
    {
	throw VersionMismatchException(__FILE__, __LINE__);
    }
#endif

    return new CommunicatorI(getDefaultProperties());
}

CommunicatorPtr
Ice::initializeWithProperties(int&, char*[], const PropertiesPtr& properties, Int version)
{
#ifndef ICE_IGNORE_VERSION
    if (version != ICE_INT_VERSION)
    {
	throw VersionMismatchException(__FILE__, __LINE__);
    }
#endif

    return new CommunicatorI(properties);
}

PropertiesPtr
Ice::getDefaultProperties()
{
    PropertiesPtr properties;
    const char* file = getenv("ICE_CONFIG");
    if (file && *file != '\0')
    {
	properties = new PropertiesI(file);
    }
    else
    {
	properties = new PropertiesI;
    }
    return properties;
}

PropertiesPtr
Ice::createProperties()
{
    return new PropertiesI;
}

PropertiesPtr
Ice::loadProperties(const std::string& file)
{
    return new PropertiesI(file);
}