summaryrefslogtreecommitdiff
path: root/cpp/src/IcePack/AdminI.cpp
blob: fd6ff00c17cb99e589c775f96b31a1d1d6e11918 (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
// **********************************************************************
//
// Copyright (c) 2001
// MutableRealms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************

#include <Ice/Ice.h>
#include <IcePack/AdminI.h>
#include <IcePack/ServerManager.h>
#include <IcePack/AdapterManager.h>

using namespace std;
using namespace Ice;
using namespace IcePack;

IcePack::AdminI::AdminI(const CommunicatorPtr& communicator, const ServerManagerPrx& serverManager,
			const AdapterManagerPrx& adapterManager) :
    _communicator(communicator),
    _serverManager(serverManager),
    _adapterManager(adapterManager)
{
}

void
IcePack::AdminI::addServer(const ServerDescription& desc, const Current&)
{
    _serverManager->create(desc);
}

ServerDescription
IcePack::AdminI::getServerDescription(const string& name, const Current&)
{
    ServerPrx server = _serverManager->findByName(name);
    if(server)
    {
	try
	{
	    return server->getServerDescription();
	}
	catch(const ObjectNotExistException&)
	{
	}
    }
    throw ServerNotExistException();
}

ServerState
IcePack::AdminI::getServerState(const string& name, const Current&)
{
    ServerPrx server = _serverManager->findByName(name);
    if(server)
    {
	try
	{
	    return server->getState();
	}
	catch(const ObjectNotExistException&)
	{
	}
    }
    throw ServerNotExistException();
}

bool
IcePack::AdminI::startServer(const string& name, const Current&)
{
    ServerPrx server = _serverManager->findByName(name);
    if(server)
    {
	try
	{
	    return server->start();
	}
	catch(const ObjectNotExistException&)
	{
	}
    }
    throw ServerNotExistException();
}

void
IcePack::AdminI::removeServer(const string& name, const Current&)
{
    _serverManager->remove(name);
}

ServerNames
IcePack::AdminI::getAllServerNames(const Current&)
{
    return _serverManager->getAll();
}

void 
IcePack::AdminI::addAdapterWithEndpoints(const string& name, const string& endpoints, const Current&)
{
    AdapterDescription desc;
    desc.name = name;

    //
    // Create the adapter.
    //
    AdapterPrx adapter = _adapterManager->create(desc);

    //
    // Set the adapter direct proxy.
    //
    ObjectPrx object = _communicator->stringToProxy("dummy:" + endpoints);
    adapter->setDirectProxy(object);
}

void 
IcePack::AdminI::removeAdapter(const string& name, const Current&)
{
    _adapterManager->remove(name);
}

string 
IcePack::AdminI::getAdapterEndpoints(const string& name, const Current&)
{
    AdapterPrx adapter = _adapterManager->findByName(name);
    if(adapter)
    {
	try
	{
	    return _communicator->proxyToString(adapter->getDirectProxy(false));
	}
	catch(const ObjectNotExistException&)
	{
	}
    }
    throw AdapterNotExistException();
}

AdapterNames
IcePack::AdminI::getAllAdapterNames(const Current&)
{
    return _adapterManager->getAll();
}

void
IcePack::AdminI::shutdown(const Current&)
{
    _communicator->shutdown();
}