[DEV/DEBUG] corect the interface of connection/deiconection

This commit is contained in:
Edouard DUPIN 2016-12-08 21:38:28 +01:00
parent 0619e613eb
commit fe4ba85a05
21 changed files with 36 additions and 185 deletions

View File

@ -206,6 +206,7 @@ int main(int _argc, const char *_argv[]) {
APPL_INFO("Appl in waiting ... " << iii << "/3");
iii++;
}
APPL_INFO("Request disconnect");
client1.disconnect();
APPL_INFO("==================================");
APPL_INFO("== ZEUS test client stop");

View File

@ -33,7 +33,7 @@ def configure(target, my_module):
])
my_module.add_src_file([
'appl/debug.cpp',
'appl/main.cpp'
'appl/main-test-client.cpp'
])
return True

View File

@ -29,7 +29,7 @@ def configure(target, my_module):
my_module.add_depend(['zeus'])
my_module.add_src_file([
'appl/debug.cpp',
'appl/main.cpp'
'appl/main-test-service.cpp'
])
return True

View File

@ -136,6 +136,9 @@ bool appl::GateWay::serviceExist(const std::string& _service) {
if (it == nullptr) {
continue;
}
if (it->isConnected() == false) {
continue;
}
for (auto &srvIt : it->getServiceList()) {
if (srvIt == _service) {
return true;
@ -150,6 +153,9 @@ uint16_t appl::GateWay::serviceClientIdGet(const std::string& _service) {
if (it == nullptr) {
continue;
}
if (it->isConnected() == false) {
continue;
}
for (auto &srvIt : it->getServiceList()) {
if (srvIt == _service) {
return it->getId();
@ -167,6 +173,9 @@ std::vector<std::string> appl::GateWay::getAllServiceName() {
if (it == nullptr) {
continue;
}
if (it->isConnected() == false) {
continue;
}
for (auto &srvIt : it->getServiceList()) {
out.push_back(srvIt);
}
@ -182,6 +191,9 @@ bool appl::GateWay::send(ememory::SharedPtr<zeus::Message> _data) {
if (*it == nullptr) {
continue;
}
if ((*it)->isConnected() == false) {
continue;
}
if ((*it)->getId() == id) {
(*it)->send(_data);
return true;
@ -192,7 +204,7 @@ bool appl::GateWay::send(ememory::SharedPtr<zeus::Message> _data) {
}
void appl::GateWay::cleanIO() {
APPL_INFO("Check if something need to be clean ...");
APPL_VERBOSE("Check if something need to be clean ...");
std::vector<uint16_t> tmpIDToRemove;
// Clean all IOs...
{

View File

@ -28,13 +28,18 @@ appl::clientSpecificInterface::~clientSpecificInterface() {
APPL_INFO("-- DELETE Client --");
APPL_INFO("-------------------");
}
/*
void appl::clientSpecificInterface::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) {
//m_interfaceWeb->answerError(_transactionId, m_routeurUID, ZEUS_ID_SERVICE_ROOT, protocolError, _errorHelp);
//m_interfaceWeb->sendCtrl(m_routeurUID, ZEUS_ID_SERVICE_ROOT, "DISCONNECT");
m_state = appl::clientState::disconnect;
zeus::WebServer* appl::clientSpecificInterface::getInterface() {
return m_interfaceWeb;
}
*/
bool appl::clientSpecificInterface::isConnected() {
if (m_interfaceWeb == nullptr) {
return false;
}
return m_interfaceWeb->isActive();
};
bool appl::clientSpecificInterface::start(appl::GateWay* _gateway, zeus::WebServer* _interfaceWeb, uint16_t _id) {
appl::IOInterface::start(_gateway, _id);
m_interfaceWeb = _interfaceWeb;

View File

@ -21,9 +21,8 @@ namespace appl {
bool start(appl::GateWay* _gateway, zeus::WebServer* _interfaceWeb, uint16_t _id);
void send(ememory::SharedPtr<zeus::Message> _data);
//void answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp);
zeus::WebServer* getInterface() {
return m_interfaceWeb;
}
zeus::WebServer* getInterface();
bool isConnected();
};
class RouterInterface {
@ -41,7 +40,6 @@ namespace appl {
bool isAlive();
void send(const ememory::SharedPtr<zeus::Message>& _data);
void clean();
bool isConnected() { return m_interfaceWeb.isActive(); };
};
}

View File

@ -1,126 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <appl/debug.hpp>
#include <appl/ServiceInterface.hpp>
#include <appl/GateWay.hpp>
#include <etk/stdTools.hpp>
// todo : cHANGE THIS ...
static const std::string protocolError = "PROTOCOL-ERROR";
bool appl::ServiceInterface::requestURI(const std::string& _uri) {
APPL_WARNING("request connect on SERVICE: '" << _uri << "'");
if(m_gatewayInterface == nullptr) {
APPL_ERROR("Can not access to the main GateWay interface (nullptr)");
return false;
}
std::string tmpURI = _uri;
if (tmpURI.size() == 0) {
APPL_ERROR("Empty URI ... not supported ...");
return false;
}
if (tmpURI[0] == '/') {
tmpURI = std::string(tmpURI.begin() + 1, tmpURI.end());
}
std::vector<std::string> listValue = etk::split(tmpURI, '?');
if (listValue.size() == 0) {
APPL_ERROR("can not parse URI ...");
return false;
}
tmpURI = listValue[0];
if (etk::start_with(tmpURI, "service:") == false ) {
APPL_ERROR("Missing 'service:' at the start of the URI ...");
return false;
}
m_name = &tmpURI[8];
APPL_INFO("Connect service name : '" << m_name << "'");
return true;
}
appl::ServiceInterface::ServiceInterface(enet::Tcp _connection, appl::GateWay* _gatewayInterface) :
m_gatewayInterface(_gatewayInterface),
m_interfaceClient(std::move(_connection), true) {
APPL_INFO("-----------------");
APPL_INFO("-- NEW Service --");
APPL_INFO("-----------------");
}
appl::ServiceInterface::~ServiceInterface() {
APPL_INFO("--------------------");
APPL_INFO("-- DELETE Service --");
APPL_INFO("--------------------");
}
bool appl::ServiceInterface::isAlive() {
return m_interfaceClient.isActive();
}
void appl::ServiceInterface::start() {
m_interfaceClient.connect(this, &appl::ServiceInterface::onServiceData);
m_interfaceClient.connectUri(this, &appl::ServiceInterface::requestURI);
m_interfaceClient.connect();
m_interfaceClient.setInterfaceName("srv-?");
}
void appl::ServiceInterface::stop() {
m_interfaceClient.disconnect();
}
void appl::ServiceInterface::SendData(uint64_t _userSessionId, ememory::SharedPtr<zeus::Message> _data) {
_data->setClientId(_userSessionId);
m_interfaceClient.writeBinary(_data);
}
void appl::ServiceInterface::onServiceData(ememory::SharedPtr<zeus::Message> _value) {
if (_value == nullptr) {
return;
}
uint32_t transactionId = _value->getTransactionId();
//data.add("from-service", ejson::String(m_name));
if (_value->getType() == zeus::Message::type::event) {
/*
if (data.valueExist("event") == true) {
// No need to have a user ID ...
if (data["event"].toString().get() == "IS-ALIVE") {
APPL_VERBOSE("Service Alive ...");
if (std::chrono::steady_clock::now() - m_interfaceClient.getLastTimeSend() >= std::chrono::seconds(20)) {
ejson::Object tmpp;
tmpp.add("event", ejson::String("IS-ALIVE"));
m_interfaceClient.writeJson(tmpp);
}
} else {
APPL_INFO("Unknow service event: '" << data["event"].toString().get() << "'");
}
return;
}
*/
return;
}
if (_value->getType() == zeus::Message::type::call) {
ememory::SharedPtr<zeus::message::Call> callObj = ememory::staticPointerCast<zeus::message::Call>(_value);
std::string callFunction = callObj->getCall();
if (callFunction == "getUserName") {
m_interfaceClient.answerValue(transactionId, _value->getClientId(), _value->getServiceId(), *m_gatewayInterface->propertyUserName);
return;
}
answerProtocolError(transactionId, "unknow function");
}
if (_value->getClientId() == 0) {
APPL_ERROR("Service interface ==> wrong service answer ==> missing 'client-id'");
return;
}
m_gatewayInterface->answer(_value->getClientId(), _value);
}
void appl::ServiceInterface::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) {
m_interfaceClient.answerError(_transactionId, 0, 0, protocolError, _errorHelp);
m_interfaceClient.disconnect(true);
}

View File

@ -1,39 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <zeus/WebServer.hpp>
#include <ememory/memory.hpp>
#error remove ...
namespace appl {
class GateWay;
class RouterInterface;
class userSpecificInterface;
class ServiceInterface {
friend class appl::RouterInterface;
friend class appl::userSpecificInterface;
private:
appl::GateWay* m_gatewayInterface;
zeus::WebServer m_interfaceClient;
std::string m_name;
public:
ServiceInterface(enet::Tcp _connection, appl::GateWay* _gatewayInterface);
virtual ~ServiceInterface();
void start();
void stop();
void onServiceData(ememory::SharedPtr<zeus::Message> _value);
bool requestURI(const std::string& _uri);
public:
void SendData(uint64_t _userSessionId, ememory::SharedPtr<zeus::Message> _data);
const std::string& getName() {
return m_name;
}
bool isAlive();
protected:
void answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp);
};
}

View File

@ -51,7 +51,7 @@ int main(int _argc, const char *_argv[]) {
APPL_INFO("==================================");
basicGateway.start();
while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
basicGateway.cleanIO();
}
basicGateway.stop();

View File

@ -34,7 +34,7 @@ def configure(target, my_module):
#'appl/ServiceInterface.cpp',
'appl/DirectInterface.cpp',
'appl/GateWay.cpp',
'appl/main.cpp'
'appl/main-gateway.cpp'
])
return True

View File

@ -33,7 +33,7 @@ def configure(target, my_module):
])
my_module.add_src_file([
'appl/debug.cpp',
'appl/main.cpp'
'appl/main-launcher.cpp'
])
return True

View File

@ -32,7 +32,7 @@ def configure(target, my_module):
'appl/ClientInterface.cpp',
'appl/GateWayInterface.cpp',
'appl/Router.cpp',
'appl/main.cpp'
'appl/main-router.cpp'
])
return True

View File

@ -35,7 +35,7 @@ def configure(target, my_module):
])
my_module.add_src_file([
'appl/debug.cpp',
'appl/main.cpp'
'appl/main-service-picture.cpp'
])
my_module.add_flag('c++', "-DSERVICE_NAME=\"\\\"picture\\\"\"")
return True

View File

@ -36,7 +36,7 @@ def configure(target, my_module):
])
my_module.add_src_file([
'appl/debug.cpp',
'appl/main.cpp'
'appl/main-service-user.cpp'
])
my_module.add_flag('c++', "-DSERVICE_NAME=\"\\\"user\\\"\"")

View File

@ -35,7 +35,7 @@ def configure(target, my_module):
])
my_module.add_src_file([
'appl/debug.cpp',
'appl/main.cpp'
'appl/main-service-video.cpp'
])
my_module.add_flag('c++', "-DSERVICE_NAME=\"\\\"video\\\"\"")
return True