The code.ill.fr has been recreated and upgraded with the latest version this weekend, If you encounter any problem please inform the Helpdesk.

Commit 895e4d18 authored by legoc's avatar legoc
Browse files

(split) Defined the Com class for Communication operations manager

parent 186976ca
......@@ -101,6 +101,25 @@ class This : private Services, private EventListener {
typedef std::function<void ()> StopFunctionType;
public:
/**
* Class defining the Communication Operations Manager (COM).
*/
class Com {
friend class This;
public:
void storeKeyValue(const std::string& key, const std::string& value) const;
std::string getKeyValue(const std::string& key) const;
void removeKey(const std::string& key) const;
private:
Com(Server * server, int applicationId);
Server * m_server;
int m_applicationId;
};
This();
~This();
......@@ -117,6 +136,7 @@ public:
static int getTimeout();
static const std::string& getEndpoint();
static Server& getServer();
static const Com& getCom();
/**
* throws StarterServerException.
......@@ -146,10 +166,6 @@ public:
*/
static std::unique_ptr<Instance> connectToStarter();
static void storeKeyValue(const std::string& key, const std::string& value);
static std::string getKeyValue(const std::string& key);
static void removeKey(const std::string& key);
private:
void initApplication(int argc, char *argv[]);
......@@ -177,6 +193,7 @@ private:
std::unique_ptr<Server> m_server;
std::unique_ptr<Server> m_starterServer;
std::unique_ptr<Com> m_com;
std::unique_ptr<WaitingImplSet> m_waitingSet;
std::unique_ptr<HandlerImpl> m_stopHandler;
......@@ -195,6 +212,20 @@ class Instance : private EventListener {
public:
typedef std::function<void (State)> StateHandlerType;
class Com {
friend class Instance;
public:
std::string getKeyValue(const std::string& key) const;
private:
Com(Server * server);
Server * m_server;
int m_applicationId;
};
~Instance();
const std::string& getName() const;
......@@ -202,6 +233,8 @@ public:
const std::string& getUrl() const;
const std::string& getEndpoint() const;
std::string getNameId() const;
const Com& getCom() const;
bool hasResult() const;
bool exists() const;
const std::string& getErrorMessage() const;
......@@ -246,8 +279,6 @@ public:
std::shared_ptr<OutputStreamSocket> getOutputStreamSocket();
std::string getKeyValue(const std::string& key);
private:
Instance(Server * server);
......@@ -262,6 +293,8 @@ private:
std::shared_ptr<OutputStreamSocket> m_outputStreamSocket;
int m_id;
std::string m_errorMessage;
Com m_com;
int m_pastStates;
State m_initialState;
State m_lastState;
......
......@@ -53,6 +53,22 @@ namespace application {
This This::m_instance;
const std::string This::RUNNING_STATE = "RUNNING";
This::Com::Com(Server * server, int applicationId) :
m_server(server),
m_applicationId(applicationId) {
}
void This::Com::storeKeyValue(const std::string& key, const std::string& value) const {
m_server->storeKeyValue(m_applicationId, key, value);
}
std::string This::Com::getKeyValue(const std::string& key) const {
return m_server->getKeyValue(m_applicationId, key);
}
void This::Com::removeKey(const std::string& key) const {
m_server->removeKey(m_applicationId, key);
}
State This::parseState(const std::string& value) {
if (value == "UNKNOWN") {
......@@ -207,6 +223,10 @@ void This::initApplication(int argc, char *argv[]) {
// Init listener.
setName(m_name);
m_server->registerEventListener(this);
// Init com.
m_com = unique_ptr<Com>(new Com(m_server.get(), m_id));
}
This::~This() {
......@@ -246,6 +266,10 @@ Server& This::getServer() {
return *m_instance.m_server;
}
const This::Com& This::getCom() {
return *m_instance.m_com;
}
Server& This::getStarterServer() {
if (m_instance.m_starterServer.get() == nullptr) {
......@@ -405,18 +429,6 @@ std::unique_ptr<Instance> This::connectToStarter() {
return unique_ptr<Instance>(nullptr);
}
void This::storeKeyValue(const std::string& key, const std::string& value) {
m_instance.m_server->storeKeyValue(m_instance.m_id, key, value);
}
std::string This::getKeyValue(const std::string& key) {
return m_instance.m_server->getKeyValue(m_instance.m_id, key);
}
void This::removeKey(const std::string& key) {
m_instance.m_server->removeKey(m_instance.m_id, key);
}
void This::stoppingFunction(StopFunctionType stop) {
application::State state = waitForStop();
......@@ -434,9 +446,20 @@ void This::handleStopImpl(StopFunctionType function) {
///////////////////////////////////////////////////////////////////////////////
// Instance
Instance::Com::Com(Server * server) :
m_server(server),
m_applicationId(-1) {
}
std::string Instance::Com::getKeyValue(const std::string& key) const {
// TODO catch exceptions and rethrow an exception: TerminatedException?
return m_server->getKeyValue(m_applicationId, key);
}
Instance::Instance(Server * server) :
m_server(server),
m_id(-1),
m_com(server),
m_pastStates(0),
m_initialState(UNKNOWN),
m_lastState(UNKNOWN),
......@@ -455,6 +478,7 @@ Instance::~Instance() {
void Instance::setId(int id) {
m_id = id;
m_com.m_applicationId = id;
}
const std::string& Instance::getName() const {
......@@ -502,6 +526,10 @@ std::string Instance::getNameId() const {
return os.str();
}
const Instance::Com& Instance::getCom() const {
return m_com;
}
bool Instance::hasResult() const {
return m_hasResult;
}
......@@ -706,11 +734,6 @@ std::shared_ptr<OutputStreamSocket> Instance::getOutputStreamSocket() {
return m_outputStreamSocket;
}
std::string Instance::getKeyValue(const std::string& key) {
// TODO catch exceptions and rethrow an exception: TerminatedException?
return m_server->getKeyValue(m_id, key);
}
///////////////////////////////////////////////////////////////////////////
// InstanceArray
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment