[DEV] connect and unconnect better interface
This commit is contained in:
parent
2978045244
commit
181930f01d
@ -6,120 +6,146 @@
|
|||||||
#include <jus/AbstractFunction.h>
|
#include <jus/AbstractFunction.h>
|
||||||
#include <jus/debug.h>
|
#include <jus/debug.h>
|
||||||
|
|
||||||
template<> bool convertJsonTo<bool>(const ejson::Value& _value) {
|
template<> bool jus::convertJsonTo<bool>(const ejson::Value& _value) {
|
||||||
return _value.toBoolean().get();
|
return _value.toBoolean().get();
|
||||||
}
|
}
|
||||||
template<> float convertJsonTo<float>(const ejson::Value& _value) {
|
template<> float jus::convertJsonTo<float>(const ejson::Value& _value) {
|
||||||
return _value.toNumber().get();
|
return _value.toNumber().get();
|
||||||
}
|
}
|
||||||
template<> double convertJsonTo<double>(const ejson::Value& _value) {
|
template<> double jus::convertJsonTo<double>(const ejson::Value& _value) {
|
||||||
return _value.toNumber().get();
|
return _value.toNumber().get();
|
||||||
}
|
}
|
||||||
template<> int64_t convertJsonTo<int64_t>(const ejson::Value& _value) {
|
template<> int64_t jus::convertJsonTo<int64_t>(const ejson::Value& _value) {
|
||||||
return int64_t(_value.toNumber().get());
|
return int64_t(_value.toNumber().get());
|
||||||
}
|
}
|
||||||
template<> int32_t convertJsonTo<int32_t>(const ejson::Value& _value) {
|
template<> int32_t jus::convertJsonTo<int32_t>(const ejson::Value& _value) {
|
||||||
//_value.display();
|
//_value.display();
|
||||||
return int32_t(_value.toNumber().get());
|
return int32_t(_value.toNumber().get());
|
||||||
}
|
}
|
||||||
template<> int16_t convertJsonTo<int16_t>(const ejson::Value& _value) {
|
template<> int16_t jus::convertJsonTo<int16_t>(const ejson::Value& _value) {
|
||||||
return int16_t(_value.toNumber().get());
|
return int16_t(_value.toNumber().get());
|
||||||
}
|
}
|
||||||
template<> int8_t convertJsonTo<int8_t>(const ejson::Value& _value) {
|
template<> int8_t jus::convertJsonTo<int8_t>(const ejson::Value& _value) {
|
||||||
return int8_t(_value.toNumber().get());
|
return int8_t(_value.toNumber().get());
|
||||||
}
|
}
|
||||||
template<> uint64_t convertJsonTo<uint64_t>(const ejson::Value& _value) {
|
template<> uint64_t jus::convertJsonTo<uint64_t>(const ejson::Value& _value) {
|
||||||
return uint64_t(_value.toNumber().get());
|
return uint64_t(_value.toNumber().get());
|
||||||
}
|
}
|
||||||
template<> uint32_t convertJsonTo<uint32_t>(const ejson::Value& _value) {
|
template<> uint32_t jus::convertJsonTo<uint32_t>(const ejson::Value& _value) {
|
||||||
return uint32_t(_value.toNumber().get());
|
return uint32_t(_value.toNumber().get());
|
||||||
}
|
}
|
||||||
template<> uint16_t convertJsonTo<uint16_t>(const ejson::Value& _value) {
|
template<> uint16_t jus::convertJsonTo<uint16_t>(const ejson::Value& _value) {
|
||||||
return uint16_t(_value.toNumber().get());
|
return uint16_t(_value.toNumber().get());
|
||||||
}
|
}
|
||||||
template<> uint8_t convertJsonTo<uint8_t>(const ejson::Value& _value) {
|
template<> uint8_t jus::convertJsonTo<uint8_t>(const ejson::Value& _value) {
|
||||||
return uint8_t(_value.toNumber().get());
|
return uint8_t(_value.toNumber().get());
|
||||||
}
|
}
|
||||||
template<> std::string convertJsonTo<std::string>(const ejson::Value& _value) {
|
template<> std::string jus::convertJsonTo<std::string>(const ejson::Value& _value) {
|
||||||
//_value.display();
|
//_value.display();
|
||||||
return _value.toString().get();
|
return _value.toString().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> ejson::Value convertToJson<bool>(const bool& _value) {
|
template<> ejson::Value jus::convertToJson<bool>(const bool& _value) {
|
||||||
return ejson::Boolean(_value);
|
return ejson::Boolean(_value);
|
||||||
}
|
}
|
||||||
template<> ejson::Value convertToJson<float>(const float& _value) {
|
template<> ejson::Value jus::convertToJson<float>(const float& _value) {
|
||||||
return ejson::Number(_value);
|
return ejson::Number(_value);
|
||||||
}
|
}
|
||||||
template<> ejson::Value convertToJson<double>(const double& _value) {
|
template<> ejson::Value jus::convertToJson<double>(const double& _value) {
|
||||||
return ejson::Number(_value);
|
return ejson::Number(_value);
|
||||||
}
|
}
|
||||||
template<> ejson::Value convertToJson<int64_t>(const int64_t& _value) {
|
template<> ejson::Value jus::convertToJson<int64_t>(const int64_t& _value) {
|
||||||
return ejson::Number(_value);
|
return ejson::Number(_value);
|
||||||
}
|
}
|
||||||
template<> ejson::Value convertToJson<int32_t>(const int32_t& _value) {
|
template<> ejson::Value jus::convertToJson<int32_t>(const int32_t& _value) {
|
||||||
return ejson::Number(_value);
|
return ejson::Number(_value);
|
||||||
}
|
}
|
||||||
template<> ejson::Value convertToJson<int16_t>(const int16_t& _value) {
|
template<> ejson::Value jus::convertToJson<int16_t>(const int16_t& _value) {
|
||||||
return ejson::Number(_value);
|
return ejson::Number(_value);
|
||||||
}
|
}
|
||||||
template<> ejson::Value convertToJson<int8_t>(const int8_t& _value) {
|
template<> ejson::Value jus::convertToJson<int8_t>(const int8_t& _value) {
|
||||||
return ejson::Number(_value);
|
return ejson::Number(_value);
|
||||||
}
|
}
|
||||||
template<> ejson::Value convertToJson<uint64_t>(const uint64_t& _value) {
|
template<> ejson::Value jus::convertToJson<uint64_t>(const uint64_t& _value) {
|
||||||
return ejson::Number(_value);
|
return ejson::Number(_value);
|
||||||
}
|
}
|
||||||
template<> ejson::Value convertToJson<uint32_t>(const uint32_t& _value) {
|
template<> ejson::Value jus::convertToJson<uint32_t>(const uint32_t& _value) {
|
||||||
return ejson::Number(_value);
|
return ejson::Number(_value);
|
||||||
}
|
}
|
||||||
template<> ejson::Value convertToJson<uint16_t>(const uint16_t& _value) {
|
template<> ejson::Value jus::convertToJson<uint16_t>(const uint16_t& _value) {
|
||||||
return ejson::Number(_value);
|
return ejson::Number(_value);
|
||||||
}
|
}
|
||||||
template<> ejson::Value convertToJson<uint8_t>(const uint8_t& _value) {
|
template<> ejson::Value jus::convertToJson<uint8_t>(const uint8_t& _value) {
|
||||||
return ejson::Number(_value);
|
return ejson::Number(_value);
|
||||||
}
|
}
|
||||||
template<> ejson::Value convertToJson<std::string>(const std::string& _value) {
|
template<> ejson::Value jus::convertToJson<std::string>(const std::string& _value) {
|
||||||
return ejson::String(_value);
|
return ejson::String(_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> bool convertStringTo<bool>(const std::string& _value) {
|
template<> bool jus::convertStringTo<bool>(const std::string& _value) {
|
||||||
return etk::string_to_bool(_value);
|
return etk::string_to_bool(_value);
|
||||||
}
|
}
|
||||||
template<> float convertStringTo<float>(const std::string& _value) {
|
template<> float jus::convertStringTo<float>(const std::string& _value) {
|
||||||
return etk::string_to_float(_value);
|
return etk::string_to_float(_value);
|
||||||
}
|
}
|
||||||
template<> double convertStringTo<double>(const std::string& _value) {
|
template<> double jus::convertStringTo<double>(const std::string& _value) {
|
||||||
return etk::string_to_double(_value);
|
return etk::string_to_double(_value);
|
||||||
}
|
}
|
||||||
template<> int64_t convertStringTo<int64_t>(const std::string& _value) {
|
template<> int64_t jus::convertStringTo<int64_t>(const std::string& _value) {
|
||||||
return etk::string_to_int64_t(_value);
|
return etk::string_to_int64_t(_value);
|
||||||
}
|
}
|
||||||
template<> int32_t convertStringTo<int32_t>(const std::string& _value) {
|
template<> int32_t jus::convertStringTo<int32_t>(const std::string& _value) {
|
||||||
return etk::string_to_int32_t(_value);
|
return etk::string_to_int32_t(_value);
|
||||||
}
|
}
|
||||||
template<> int16_t convertStringTo<int16_t>(const std::string& _value) {
|
template<> int16_t jus::convertStringTo<int16_t>(const std::string& _value) {
|
||||||
return etk::string_to_int16_t(_value);
|
return etk::string_to_int16_t(_value);
|
||||||
}
|
}
|
||||||
template<> int8_t convertStringTo<int8_t>(const std::string& _value) {
|
template<> int8_t jus::convertStringTo<int8_t>(const std::string& _value) {
|
||||||
return etk::string_to_int8_t(_value);
|
return etk::string_to_int8_t(_value);
|
||||||
}
|
}
|
||||||
template<> uint64_t convertStringTo<uint64_t>(const std::string& _value) {
|
template<> uint64_t jus::convertStringTo<uint64_t>(const std::string& _value) {
|
||||||
return etk::string_to_uint64_t(_value);
|
return etk::string_to_uint64_t(_value);
|
||||||
}
|
}
|
||||||
template<> uint32_t convertStringTo<uint32_t>(const std::string& _value) {
|
template<> uint32_t jus::convertStringTo<uint32_t>(const std::string& _value) {
|
||||||
return etk::string_to_uint32_t(_value);
|
return etk::string_to_uint32_t(_value);
|
||||||
}
|
}
|
||||||
template<> uint16_t convertStringTo<uint16_t>(const std::string& _value) {
|
template<> uint16_t jus::convertStringTo<uint16_t>(const std::string& _value) {
|
||||||
return etk::string_to_uint16_t(_value);
|
return etk::string_to_uint16_t(_value);
|
||||||
}
|
}
|
||||||
template<> uint8_t convertStringTo<uint8_t>(const std::string& _value) {
|
template<> uint8_t jus::convertStringTo<uint8_t>(const std::string& _value) {
|
||||||
return etk::string_to_uint8_t(_value);
|
return etk::string_to_uint8_t(_value);
|
||||||
}
|
}
|
||||||
template<> std::string convertStringTo<std::string>(const std::string& _value) {
|
template<> std::string jus::convertStringTo<std::string>(const std::string& _value) {
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AbstractFunction::checkCompatibility(const ParamType& _type, const ejson::Value& _params) {
|
const std::string& jus::AbstractFunction::getName() const {
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& jus::AbstractFunction::getDescription() const {
|
||||||
|
return m_description;
|
||||||
|
}
|
||||||
|
|
||||||
|
void jus::AbstractFunction::setDescription(const std::string& _desc) {
|
||||||
|
m_description = _desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void jus::AbstractFunction::setParam(int32_t _idParam, const std::string& _name, const std::string& _desc) {
|
||||||
|
JUS_TODO("not implemented set param ... '" << _name << "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
void jus::AbstractFunction::addParam(const std::string& _name, const std::string& _desc) {
|
||||||
|
m_paramsDescription.push_back(std::make_pair(_name, _desc));
|
||||||
|
}
|
||||||
|
|
||||||
|
jus::AbstractFunction::AbstractFunction(const std::string& _name,
|
||||||
|
const std::string& _desc):
|
||||||
|
m_name(_name),
|
||||||
|
m_description(_desc) {
|
||||||
|
|
||||||
|
}
|
||||||
|
bool jus::AbstractFunction::checkCompatibility(const ParamType& _type, const ejson::Value& _params) {
|
||||||
if (createType<bool>() == _type) {
|
if (createType<bool>() == _type) {
|
||||||
return _params.isBoolean();
|
return _params.isBoolean();
|
||||||
}
|
}
|
||||||
@ -140,6 +166,6 @@ bool AbstractFunction::checkCompatibility(const ParamType& _type, const ejson::V
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool AbstractFunction::checkCompatibility(const ParamType& _type, const std::string& _params) {
|
bool jus::AbstractFunction::checkCompatibility(const ParamType& _type, const std::string& _params) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -10,29 +10,27 @@
|
|||||||
#include <ejson/ejson.h>
|
#include <ejson/ejson.h>
|
||||||
#include <jus/debug.h>
|
#include <jus/debug.h>
|
||||||
#include <jus/ParamType.h>
|
#include <jus/ParamType.h>
|
||||||
|
namespace jus {
|
||||||
class AbstractFunction {
|
class AbstractFunction {
|
||||||
protected:
|
protected:
|
||||||
const std::string m_name;
|
std::string m_name;
|
||||||
public:
|
public:
|
||||||
const std::string& getName() const {
|
const std::string& getName() const;
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
protected:
|
protected:
|
||||||
const std::string m_description;
|
std::string m_description;
|
||||||
public:
|
public:
|
||||||
const std::string& getDescription() const {
|
const std::string& getDescription() const;
|
||||||
return m_description;
|
void setDescription(const std::string& _desc);
|
||||||
}
|
|
||||||
protected:
|
protected:
|
||||||
AbstractFunction(const std::string& _name,
|
std::vector<std::pair<std::string, std::string>> m_paramsDescription;
|
||||||
const std::string& _desc):
|
public:
|
||||||
m_name(_name),
|
void setParam(int32_t _idParam, const std::string& _name, const std::string& _desc);
|
||||||
m_description(_desc) {
|
void addParam(const std::string& _name, const std::string& _desc);
|
||||||
|
protected:
|
||||||
}
|
AbstractFunction(const std::string& _name, const std::string& _desc="");
|
||||||
public:
|
public:
|
||||||
virtual ~AbstractFunction() {};
|
virtual ~AbstractFunction() {};
|
||||||
|
public:
|
||||||
bool checkCompatibility(const ParamType& _type, const ejson::Value& _params);
|
bool checkCompatibility(const ParamType& _type, const ejson::Value& _params);
|
||||||
bool checkCompatibility(const ParamType& _type, const std::string& _params);
|
bool checkCompatibility(const ParamType& _type, const std::string& _params);
|
||||||
public:
|
public:
|
||||||
@ -49,8 +47,5 @@ JUS_TYPE convertJsonTo(const ejson::Value& _value);
|
|||||||
|
|
||||||
template<class JUS_TYPE>
|
template<class JUS_TYPE>
|
||||||
ejson::Value convertToJson(const JUS_TYPE& _value);
|
ejson::Value convertToJson(const JUS_TYPE& _value);
|
||||||
/*
|
}
|
||||||
template <class, class...>
|
|
||||||
class TypeList;
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include <ejson/ejson.h>
|
#include <ejson/ejson.h>
|
||||||
#include <jus/debug.h>
|
#include <jus/debug.h>
|
||||||
#include <jus/AbstractFunction.h>
|
#include <jus/AbstractFunction.h>
|
||||||
|
namespace jus {
|
||||||
template <class JUS_CLASS_TYPE, class JUS_RETURN, class... JUS_TYPES>
|
template <class JUS_CLASS_TYPE, class JUS_RETURN, class... JUS_TYPES>
|
||||||
ejson::Value executeClassCallJson(JUS_CLASS_TYPE* _pointer, JUS_RETURN (JUS_CLASS_TYPE::*_func)(JUS_TYPES...), const ejson::Array& _params) {
|
ejson::Value executeClassCallJson(JUS_CLASS_TYPE* _pointer, JUS_RETURN (JUS_CLASS_TYPE::*_func)(JUS_TYPES...), const ejson::Array& _params) {
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
@ -77,7 +77,7 @@ std::string executeClassCallString(JUS_CLASS_TYPE* _pointer, void (JUS_CLASS_TYP
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class JUS_RETURN, class JUS_CLASS_TYPE, class... JUS_TYPES>
|
template <class JUS_RETURN, class JUS_CLASS_TYPE, class... JUS_TYPES>
|
||||||
class AbstractFunctionTypeClass: public AbstractFunction {
|
class AbstractFunctionTypeClass: public jus::AbstractFunction {
|
||||||
protected:
|
protected:
|
||||||
static const ParamType m_returnType;
|
static const ParamType m_returnType;
|
||||||
static const ParamType m_paramType[sizeof...(JUS_TYPES)];
|
static const ParamType m_paramType[sizeof...(JUS_TYPES)];
|
||||||
@ -128,7 +128,7 @@ class AbstractFunctionTypeClass: public AbstractFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// execute cmd:
|
// execute cmd:
|
||||||
ejson::Value retVal = executeClassCallJson(tmpClass, m_function, _params);
|
ejson::Value retVal = jus::executeClassCallJson(tmpClass, m_function, _params);
|
||||||
out.add("return", retVal);
|
out.add("return", retVal);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ class AbstractFunctionTypeClass: public AbstractFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// execute cmd:
|
// execute cmd:
|
||||||
out = executeClassCallString(tmpClass, m_function, _params);
|
out = jus::executeClassCallString(tmpClass, m_function, _params);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -172,4 +172,5 @@ template <typename JUS_RETURN, class JUS_CLASS_TYPE, typename... JUS_TYPES>
|
|||||||
AbstractFunction* createAbstractFunctionClass(const std::string& _name, const std::string& _desc, JUS_RETURN (JUS_CLASS_TYPE::*_fffp)(JUS_TYPES...)) {
|
AbstractFunction* createAbstractFunctionClass(const std::string& _name, const std::string& _desc, JUS_RETURN (JUS_CLASS_TYPE::*_fffp)(JUS_TYPES...)) {
|
||||||
return new AbstractFunctionTypeClass<JUS_RETURN, JUS_CLASS_TYPE, JUS_TYPES...>(_name, _desc, _fffp);
|
return new AbstractFunctionTypeClass<JUS_RETURN, JUS_CLASS_TYPE, JUS_TYPES...>(_name, _desc, _fffp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include <ejson/ejson.h>
|
#include <ejson/ejson.h>
|
||||||
#include <jus/debug.h>
|
#include <jus/debug.h>
|
||||||
#include <jus/AbstractFunction.h>
|
#include <jus/AbstractFunction.h>
|
||||||
|
namespace jus {
|
||||||
template <class JUS_RETURN, class... JUS_TYPES>
|
template <class JUS_RETURN, class... JUS_TYPES>
|
||||||
ejson::Value executeCallJson(JUS_RETURN (*_func)(JUS_TYPES...), const ejson::Array& _params) {
|
ejson::Value executeCallJson(JUS_RETURN (*_func)(JUS_TYPES...), const ejson::Array& _params) {
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
@ -77,7 +77,7 @@ std::string executeCallString(void (*_func)(JUS_TYPES...), const std::vector<std
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class JUS_RETURN, class... JUS_TYPES>
|
template <class JUS_RETURN, class... JUS_TYPES>
|
||||||
class AbstractFunctionTypeDirect: public AbstractFunction {
|
class AbstractFunctionTypeDirect: public jus::AbstractFunction {
|
||||||
protected:
|
protected:
|
||||||
static const ParamType m_returnType;
|
static const ParamType m_returnType;
|
||||||
static const ParamType m_paramType[sizeof...(JUS_TYPES)];
|
static const ParamType m_paramType[sizeof...(JUS_TYPES)];
|
||||||
@ -127,7 +127,7 @@ class AbstractFunctionTypeDirect: public AbstractFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// execute cmd:
|
// execute cmd:
|
||||||
ejson::Value retVal = executeCallJson(m_function, _params);
|
ejson::Value retVal = jus::executeCallJson(m_function, _params);
|
||||||
out.add("return", retVal);
|
out.add("return", retVal);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ class AbstractFunctionTypeDirect: public AbstractFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// execute cmd:
|
// execute cmd:
|
||||||
out = executeCallString(m_function, _params);
|
out = jus::executeCallString(m_function, _params);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -170,4 +170,4 @@ template <typename JUS_RETURN, typename... JUS_TYPES>
|
|||||||
AbstractFunction* createAbstractFunctionDirect(const std::string& _name, const std::string& _desc, JUS_RETURN (*_fffp)(JUS_TYPES...)) {
|
AbstractFunction* createAbstractFunctionDirect(const std::string& _name, const std::string& _desc, JUS_RETURN (*_fffp)(JUS_TYPES...)) {
|
||||||
return new AbstractFunctionTypeDirect<JUS_RETURN, JUS_TYPES...>(_name, _desc, _fffp);
|
return new AbstractFunctionTypeDirect<JUS_RETURN, JUS_TYPES...>(_name, _desc, _fffp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -45,6 +45,9 @@ void jus::Client::unlink(const std::string& _serviceName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string jus::Client::asyncRead() {
|
std::string jus::Client::asyncRead() {
|
||||||
|
if (m_interfaceClient.isActive() == false) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
int32_t iii = 5000;
|
int32_t iii = 5000;
|
||||||
while (iii>0) {
|
while (iii>0) {
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
@ -102,9 +105,11 @@ ejson::Object jus::Client::createBaseCall(const std::string& _functionName, cons
|
|||||||
|
|
||||||
ejson::Object jus::Client::callJson(const ejson::Object& _obj) {
|
ejson::Object jus::Client::callJson(const ejson::Object& _obj) {
|
||||||
JUS_VERBOSE("Call JSON [START] ");
|
JUS_VERBOSE("Call JSON [START] ");
|
||||||
std::string tmpVal = _obj.generate();
|
if (m_interfaceClient.isActive() == false) {
|
||||||
JUS_DEBUG("Call JSON '" << tmpVal << "'");
|
return ejson::Object();
|
||||||
m_interfaceClient.write(_obj.generate());
|
}
|
||||||
|
JUS_DEBUG("Call JSON '" << _obj.generateHumanString() << "'");
|
||||||
|
m_interfaceClient.write(_obj.generateMachineString());
|
||||||
std::string ret = asyncRead();
|
std::string ret = asyncRead();
|
||||||
JUS_VERBOSE("Call JSON [STOP]");
|
JUS_VERBOSE("Call JSON [STOP]");
|
||||||
return ejson::Object(ret);
|
return ejson::Object(ret);
|
||||||
|
@ -130,6 +130,37 @@ void jus::GateWay::answer(uint64_t _userSessionId, ejson::Object _data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void jus::GateWay::cleanIO() {
|
||||||
|
|
||||||
|
auto it = m_serviceList.begin();
|
||||||
|
while (it != m_serviceList.end()) {
|
||||||
|
if (*it != nullptr) {
|
||||||
|
if ((*it)->isAlive() == false) {
|
||||||
|
it = m_serviceList.erase(it);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
it = m_serviceList.erase(it);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it2 = m_clientList.begin();
|
||||||
|
while (it2 != m_clientList.end()) {
|
||||||
|
if (*it2 != nullptr) {
|
||||||
|
if ((*it2)->isAlive() == false) {
|
||||||
|
it2 = m_clientList.erase(it2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
it2 = m_clientList.erase(it2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
++it2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void jus::GateWay::onClientConnect(const bool& _value) {
|
void jus::GateWay::onClientConnect(const bool& _value) {
|
||||||
JUS_TODO("Client connection: " << _value);
|
JUS_TODO("Client connection: " << _value);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ namespace jus {
|
|||||||
void answer(uint64_t _userSessionId, ejson::Object _data);
|
void answer(uint64_t _userSessionId, ejson::Object _data);
|
||||||
void newService(enet::Tcp _connection);
|
void newService(enet::Tcp _connection);
|
||||||
void newClient(enet::Tcp _connection);
|
void newClient(enet::Tcp _connection);
|
||||||
|
void cleanIO();
|
||||||
private:
|
private:
|
||||||
void onPropertyChangeClientIp();
|
void onPropertyChangeClientIp();
|
||||||
void onPropertyChangeClientPort();
|
void onPropertyChangeClientPort();
|
||||||
|
@ -12,14 +12,18 @@
|
|||||||
|
|
||||||
jus::GateWayClient::GateWayClient(enet::Tcp _connection, jus::GateWay* _gatewayInterface) :
|
jus::GateWayClient::GateWayClient(enet::Tcp _connection, jus::GateWay* _gatewayInterface) :
|
||||||
m_gatewayInterface(_gatewayInterface),
|
m_gatewayInterface(_gatewayInterface),
|
||||||
m_interfaceClient(std::move(_connection)),
|
m_interfaceClient(std::move(_connection)) {
|
||||||
m_returnValueOk(false) {
|
JUS_INFO("----------------");
|
||||||
|
JUS_INFO("-- NEW Client --");
|
||||||
|
JUS_INFO("----------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
jus::GateWayClient::~GateWayClient() {
|
jus::GateWayClient::~GateWayClient() {
|
||||||
JUS_TODO("Call All unlink ...");
|
JUS_TODO("Call All unlink ...");
|
||||||
|
stop();
|
||||||
|
JUS_INFO("-------------------");
|
||||||
|
JUS_INFO("-- DELETE Client --");
|
||||||
|
JUS_INFO("-------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
void jus::GateWayClient::start(size_t _uid) {
|
void jus::GateWayClient::start(size_t _uid) {
|
||||||
@ -30,9 +34,20 @@ void jus::GateWayClient::start(size_t _uid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void jus::GateWayClient::stop() {
|
void jus::GateWayClient::stop() {
|
||||||
|
for (auto &it : m_listConnectedService) {
|
||||||
|
if (it == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
it->SendData(m_uid, ejson::Object(), "delete");
|
||||||
|
}
|
||||||
|
m_listConnectedService.clear();
|
||||||
m_interfaceClient.disconnect();
|
m_interfaceClient.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool jus::GateWayClient::isAlive() {
|
||||||
|
return m_interfaceClient.isActive();
|
||||||
|
}
|
||||||
|
|
||||||
void jus::GateWayClient::onClientData(const std::string& _value) {
|
void jus::GateWayClient::onClientData(const std::string& _value) {
|
||||||
JUS_DEBUG("On data: " << _value);
|
JUS_DEBUG("On data: " << _value);
|
||||||
ejson::Object data(_value);
|
ejson::Object data(_value);
|
||||||
@ -93,21 +108,11 @@ void jus::GateWayClient::onClientData(const std::string& _value) {
|
|||||||
ejson::Object linkService;
|
ejson::Object linkService;
|
||||||
linkService.add("user", ejson::String(m_userConnectionName));
|
linkService.add("user", ejson::String(m_userConnectionName));
|
||||||
srv->SendData(m_uid, linkService, "new");
|
srv->SendData(m_uid, linkService, "new");
|
||||||
while (m_returnValueOk == false) {
|
|
||||||
JUS_DEBUG("wait Return Value (LINK)");
|
|
||||||
usleep(20000);
|
|
||||||
}
|
|
||||||
JUS_DEBUG("new answer: " << m_returnMessage.generate());
|
|
||||||
if (m_returnMessage["return"].toString().get() == "OK") {
|
|
||||||
m_listConnectedService.push_back(srv);
|
m_listConnectedService.push_back(srv);
|
||||||
answer.add("return", ejson::Boolean(true));
|
answer.add("return", ejson::Boolean(true));
|
||||||
} else {
|
} else {
|
||||||
answer.add("return", ejson::Boolean(false));
|
answer.add("return", ejson::Boolean(false));
|
||||||
}
|
}
|
||||||
m_returnValueOk = false;
|
|
||||||
} else {
|
|
||||||
answer.add("return", ejson::Boolean(false));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// TODO : Service already connected;
|
// TODO : Service already connected;
|
||||||
answer.add("return", ejson::Boolean(false));
|
answer.add("return", ejson::Boolean(false));
|
||||||
@ -129,30 +134,18 @@ void jus::GateWayClient::onClientData(const std::string& _value) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (it == m_listConnectedService.end()) {
|
if (it == m_listConnectedService.end()) {
|
||||||
// TODO : Service already unlink;
|
|
||||||
answer.add("return", ejson::Boolean(false));
|
answer.add("return", ejson::Boolean(false));
|
||||||
} else {
|
} else {
|
||||||
(*it)->SendData(m_uid, ejson::Object(), "delete");
|
(*it)->SendData(m_uid, ejson::Object(), "delete");
|
||||||
while (m_returnValueOk == false) {
|
|
||||||
JUS_DEBUG("wait Return Value (UNLINK)");
|
|
||||||
usleep(20000);
|
|
||||||
}
|
|
||||||
JUS_DEBUG("new answer: " << m_returnMessage.generate());
|
|
||||||
if (m_returnMessage["return"].toString().get() == "OK") {
|
|
||||||
m_listConnectedService.erase(it);
|
m_listConnectedService.erase(it);
|
||||||
answer.add("return", ejson::Boolean(true));
|
answer.add("return", ejson::Boolean(true));
|
||||||
} else {
|
|
||||||
answer.add("return", ejson::Boolean(false));
|
|
||||||
}
|
|
||||||
m_returnValueOk = false;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
JUS_ERROR("Function does not exist ... '" << call << "'");
|
JUS_ERROR("Function does not exist ... '" << call << "'");
|
||||||
answer.add("error", ejson::String("CALL-UNEXISTING"));
|
answer.add("error", ejson::String("CALL-UNEXISTING"));
|
||||||
}
|
}
|
||||||
std::string valueReturn = answer.generate();
|
JUS_DEBUG("answer: " << answer.generateHumanString());
|
||||||
JUS_DEBUG("answer: " << valueReturn);
|
m_interfaceClient.write(answer.generateMachineString());
|
||||||
m_interfaceClient.write(valueReturn);
|
|
||||||
} else if (service == "Authentification") {
|
} else if (service == "Authentification") {
|
||||||
std::string call = data["call"].toString().get();
|
std::string call = data["call"].toString().get();
|
||||||
|
|
||||||
@ -176,26 +169,17 @@ void jus::GateWayClient::onClientData(const std::string& _value) {
|
|||||||
answer.add("id", data["id"]);
|
answer.add("id", data["id"]);
|
||||||
JUS_ERROR("Service not linked ... " << service);
|
JUS_ERROR("Service not linked ... " << service);
|
||||||
answer.add("error", ejson::String("SERVICE-NOT-LINK"));
|
answer.add("error", ejson::String("SERVICE-NOT-LINK"));
|
||||||
std::string valueReturn = answer.generate();
|
JUS_DEBUG("answer: " << answer.generateHumanString());
|
||||||
JUS_DEBUG("answer: " << valueReturn);
|
m_interfaceClient.write(answer.generateMachineString());
|
||||||
m_interfaceClient.write(valueReturn);
|
|
||||||
} else {
|
} else {
|
||||||
JUS_ERROR("Add in link the name of the user in parameter ...");
|
JUS_ERROR("Add in link the name of the user in parameter ...");
|
||||||
data.remove("service");
|
data.remove("service");
|
||||||
(*it)->SendData(m_uid, data);
|
(*it)->SendData(m_uid, data);
|
||||||
while (m_returnValueOk == false) {
|
|
||||||
JUS_DEBUG("wait Return Value");
|
|
||||||
usleep(20000);
|
|
||||||
}
|
|
||||||
std::string valueReturn = m_returnMessage.generate();
|
|
||||||
JUS_DEBUG("answer: " << valueReturn);
|
|
||||||
m_interfaceClient.write(valueReturn);
|
|
||||||
m_returnValueOk = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void jus::GateWayClient::returnMessage(ejson::Object _data) {
|
void jus::GateWayClient::returnMessage(ejson::Object _data) {
|
||||||
m_returnMessage = _data;
|
JUS_DEBUG("answer: " << _data.generateHumanString());
|
||||||
m_returnValueOk = true;
|
m_interfaceClient.write(_data.generateMachineString());
|
||||||
}
|
}
|
@ -19,8 +19,6 @@ namespace jus {
|
|||||||
public:
|
public:
|
||||||
esignal::Signal<bool> signalIsConnected;
|
esignal::Signal<bool> signalIsConnected;
|
||||||
esignal::Connection m_dataCallback;
|
esignal::Connection m_dataCallback;
|
||||||
bool m_returnValueOk;
|
|
||||||
ejson::Object m_returnMessage;
|
|
||||||
std::vector<ememory::SharedPtr<jus::GateWayService>> m_listConnectedService;
|
std::vector<ememory::SharedPtr<jus::GateWayService>> m_listConnectedService;
|
||||||
size_t m_uid;
|
size_t m_uid;
|
||||||
std::string m_userConnectionName;
|
std::string m_userConnectionName;
|
||||||
@ -34,6 +32,7 @@ namespace jus {
|
|||||||
size_t getId() const {
|
size_t getId() const {
|
||||||
return m_uid;
|
return m_uid;
|
||||||
}
|
}
|
||||||
|
bool isAlive();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,11 +12,20 @@
|
|||||||
jus::GateWayService::GateWayService(enet::Tcp _connection, jus::GateWay* _gatewayInterface) :
|
jus::GateWayService::GateWayService(enet::Tcp _connection, jus::GateWay* _gatewayInterface) :
|
||||||
m_gatewayInterface(_gatewayInterface),
|
m_gatewayInterface(_gatewayInterface),
|
||||||
m_interfaceClient(std::move(_connection)) {
|
m_interfaceClient(std::move(_connection)) {
|
||||||
|
JUS_INFO("-----------------");
|
||||||
|
JUS_INFO("-- NEW Service --");
|
||||||
|
JUS_INFO("-----------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
jus::GateWayService::~GateWayService() {
|
jus::GateWayService::~GateWayService() {
|
||||||
|
|
||||||
|
JUS_INFO("--------------------");
|
||||||
|
JUS_INFO("-- DELETE Service --");
|
||||||
|
JUS_INFO("--------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool jus::GateWayService::isAlive() {
|
||||||
|
return m_interfaceClient.isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void jus::GateWayService::start() {
|
void jus::GateWayService::start() {
|
||||||
@ -32,14 +41,21 @@ void jus::GateWayService::stop() {
|
|||||||
void jus::GateWayService::SendData(size_t _userSessionId, ejson::Object _data, const std::string& _action) {
|
void jus::GateWayService::SendData(size_t _userSessionId, ejson::Object _data, const std::string& _action) {
|
||||||
_data.add("client-id", ejson::String(etk::to_string(_userSessionId)));
|
_data.add("client-id", ejson::String(etk::to_string(_userSessionId)));
|
||||||
_data.add("action", ejson::String(_action));
|
_data.add("action", ejson::String(_action));
|
||||||
std::string value = _data.generate();
|
JUS_DEBUG("Send Service: " << _data.generateHumanString());
|
||||||
JUS_DEBUG("Send Service: " << value);
|
m_interfaceClient.write(_data.generateMachineString());
|
||||||
m_interfaceClient.write(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void jus::GateWayService::onServiceData(const std::string& _value) {
|
void jus::GateWayService::onServiceData(const std::string& _value) {
|
||||||
JUS_DEBUG("On service data: " << _value);
|
JUS_DEBUG("On service data: " << _value);
|
||||||
ejson::Object data(_value);
|
ejson::Object data(_value);
|
||||||
|
if (data.valueExist("event") == true) {
|
||||||
|
if (data["event"].toString().get() == "IS-ALIVE") {
|
||||||
|
JUS_INFO("Service Alive ...");
|
||||||
|
} else {
|
||||||
|
JUS_INFO("Unknow service event: '" << data["event"].toString().get() << "'");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (data.valueExist("connect-service") == true) {
|
if (data.valueExist("connect-service") == true) {
|
||||||
if (m_name != "") {
|
if (m_name != "") {
|
||||||
JUS_WARNING("Service interface ==> try change the servie name after init: '" << data["connect-service"].toString().get());
|
JUS_WARNING("Service interface ==> try change the servie name after init: '" << data["connect-service"].toString().get());
|
||||||
|
@ -31,6 +31,7 @@ namespace jus {
|
|||||||
const std::string& getName() {
|
const std::string& getName() {
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
bool isAlive();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ bool jus::ParamType::operator == (const ParamType& _obj) const {
|
|||||||
|
|
||||||
|
|
||||||
#define generate_basic_type(_type, _name) \
|
#define generate_basic_type(_type, _name) \
|
||||||
template<> ParamType createType<_type>() {\
|
template<> jus::ParamType jus::createType<_type>() {\
|
||||||
return ParamType(_name); \
|
return jus::ParamType(_name); \
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_basic_type(void, "void");
|
generate_basic_type(void, "void");
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* @license APACHE v2.0 (see license file)
|
* @license APACHE v2.0 (see license file)
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
namespace jus {
|
||||||
class ParamType {
|
class ParamType {
|
||||||
protected:
|
protected:
|
||||||
const char* m_typeName;
|
const char* m_typeName;
|
||||||
@ -17,5 +17,5 @@ class ParamType {
|
|||||||
|
|
||||||
template<class JUS_TYPE>
|
template<class JUS_TYPE>
|
||||||
ParamType createType();
|
ParamType createType();
|
||||||
|
}
|
||||||
|
|
||||||
|
86
jus/RemoteProcessCall.cpp
Normal file
86
jus/RemoteProcessCall.cpp
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#include <jus/RemoteProcessCall.h>
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<jus::AbstractFunction*> m_listFunction;
|
||||||
|
|
||||||
|
|
||||||
|
void jus::RemoteProcessCall::setDescription(const std::string& _desc) {
|
||||||
|
m_description = _desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& jus::RemoteProcessCall::getDescription() const {
|
||||||
|
return m_description;
|
||||||
|
}
|
||||||
|
|
||||||
|
void jus::RemoteProcessCall::setVersion(const std::string& _desc) {
|
||||||
|
m_version = _desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& jus::RemoteProcessCall::getVersion() const {
|
||||||
|
return m_version;
|
||||||
|
}
|
||||||
|
|
||||||
|
void jus::RemoteProcessCall::addAuthor(const std::string& _name, const std::string& _email) {
|
||||||
|
m_authors.push_back(std::make_pair(_name, _email));
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<std::pair<std::string,std::string>>& jus::RemoteProcessCall::getAuthors() const {
|
||||||
|
return m_authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
void jus::RemoteProcessCall::setLastFuncDesc(const std::string& _desc) {
|
||||||
|
if (m_listFunction.size() == 0) {
|
||||||
|
JUS_ERROR("Can not set description to a function with no function advertise before ...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m_listFunction[m_listFunction.size()-1] == nullptr) {
|
||||||
|
JUS_ERROR("Last element is nullptr ... ==> what are you doing??");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_listFunction[m_listFunction.size()-1]->setDescription(_desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void jus::RemoteProcessCall::setFuncDesc(const std::string& _funcName, const std::string& _desc) {
|
||||||
|
for (auto &it : m_listFunction) {
|
||||||
|
if (it == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (it->getName() != _funcName) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
it->setDescription(_desc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JUS_ERROR("function '" << _funcName << "' des not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
void jus::RemoteProcessCall::addLastFuncParam(const std::string& _name, const std::string& _desc) {
|
||||||
|
if (m_listFunction.size() == 0) {
|
||||||
|
JUS_ERROR("Can not set description to a function with no function advertise before ...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m_listFunction[m_listFunction.size()-1] == nullptr) {
|
||||||
|
JUS_ERROR("Last element is nullptr ... ==> what are you doing??");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_listFunction[m_listFunction.size()-1]->addParam(_name, _desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void jus::RemoteProcessCall::setFuncParam(const std::string& _funcName, int32_t _idParam, const std::string& _name, const std::string& _desc) {
|
||||||
|
for (auto &it : m_listFunction) {
|
||||||
|
if (it == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (it->getName() != _funcName) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
it->setParam(_idParam, _name, _desc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JUS_ERROR("function '" << _funcName << "' des not exist");
|
||||||
|
}
|
59
jus/RemoteProcessCall.h
Normal file
59
jus/RemoteProcessCall.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <jus/TcpString.h>
|
||||||
|
#include <eproperty/Value.h>
|
||||||
|
#include <ejson/ejson.h>
|
||||||
|
#include <jus/AbstractFunctionTypeDirect.h>
|
||||||
|
#include <jus/AbstractFunctionTypeClass.h>
|
||||||
|
#include <jus/debug.h>
|
||||||
|
|
||||||
|
namespace jus {
|
||||||
|
class RemoteProcessCall {
|
||||||
|
protected:
|
||||||
|
std::vector<jus::AbstractFunction*> m_listFunction;
|
||||||
|
protected:
|
||||||
|
std::string m_description;
|
||||||
|
public:
|
||||||
|
void setDescription(const std::string& _desc);
|
||||||
|
const std::string& getDescription() const;
|
||||||
|
protected:
|
||||||
|
std::string m_version;
|
||||||
|
public:
|
||||||
|
void setVersion(const std::string& _desc);
|
||||||
|
const std::string& getVersion() const;
|
||||||
|
protected:
|
||||||
|
std::vector<std::pair<std::string,std::string>> m_authors;
|
||||||
|
public:
|
||||||
|
void addAuthor(const std::string& _name, const std::string& _email);
|
||||||
|
const std::vector<std::pair<std::string,std::string>>& getAuthors() const;
|
||||||
|
public:
|
||||||
|
void setLastFuncDesc(const std::string& _desc);
|
||||||
|
void setFuncDesc(const std::string& _funcName, const std::string& _desc);
|
||||||
|
void addLastFuncParam(const std::string& _name, const std::string& _desc);
|
||||||
|
void setFuncParam(const std::string& _funcName, int32_t _idParam, const std::string& _name, const std::string& _desc);
|
||||||
|
public:
|
||||||
|
template<class JUS_RETURN_VALUE,
|
||||||
|
class... JUS_FUNC_ARGS_TYPE>
|
||||||
|
void advertise(const std::string& _name,
|
||||||
|
JUS_RETURN_VALUE (*_func)(JUS_FUNC_ARGS_TYPE... _args),
|
||||||
|
const std::string& _desc = "") {
|
||||||
|
for (auto &it : m_listFunction) {
|
||||||
|
if (it == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (it->getName() == _name) {
|
||||||
|
JUS_ERROR("Advertise function already bind .. ==> can not be done...: '" << _name << "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AbstractFunction* tmp = createAbstractFunctionDirect(_name, _desc, _func);
|
||||||
|
m_listFunction.push_back(tmp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -27,10 +27,12 @@ jus::Service::~Service() {
|
|||||||
void jus::Service::onClientData(const std::string& _value) {
|
void jus::Service::onClientData(const std::string& _value) {
|
||||||
ejson::Object request(_value);
|
ejson::Object request(_value);
|
||||||
JUS_INFO("Request: " << _value);
|
JUS_INFO("Request: " << _value);
|
||||||
ejson::Object answer = callJson(request);
|
ejson::Value answer = callJson(request);
|
||||||
std::string answerString = answer.generate();
|
// check if an answer is needed
|
||||||
JUS_INFO("Answer: " << answerString);
|
if (answer.isNull() == false) {
|
||||||
m_interfaceClient.write(answerString);
|
JUS_INFO("Answer: " << answer.generateHumanString());
|
||||||
|
m_interfaceClient.write(answer.generateMachineString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void jus::Service::onPropertyChangeIp() {
|
void jus::Service::onPropertyChangeIp() {
|
||||||
@ -58,33 +60,44 @@ void jus::Service::disconnect(){
|
|||||||
JUS_DEBUG("disconnect [STOP]");
|
JUS_DEBUG("disconnect [STOP]");
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Object jus::Service::callJson(const ejson::Object& _obj) {
|
|
||||||
|
void jus::Service::pingIsAlive() {
|
||||||
|
m_interfaceClient.write("{\"event\":\"IS-ALIVE\"}");
|
||||||
|
}
|
||||||
|
|
||||||
|
ejson::Value jus::Service::callJson(const ejson::Object& _obj) {
|
||||||
std::string action = _obj["action"].toString().get();
|
std::string action = _obj["action"].toString().get();
|
||||||
if (action == "new") {
|
if (action == "new") {
|
||||||
uint64_t clientId = etk::string_to_uint64_t(_obj["client-id"].toString().get());
|
uint64_t clientId = etk::string_to_uint64_t(_obj["client-id"].toString().get());
|
||||||
std::string userName = _obj["user"].toString().get();
|
std::string userName = _obj["user"].toString().get();
|
||||||
clientConnect(clientId, userName);
|
clientConnect(clientId, userName);
|
||||||
|
/*
|
||||||
ejson::Object tmpp;
|
ejson::Object tmpp;
|
||||||
tmpp.add("client-id", ejson::String(etk::to_string(clientId)));
|
tmpp.add("client-id", ejson::String(etk::to_string(clientId)));
|
||||||
tmpp.add("return", ejson::String("OK"));
|
tmpp.add("return", ejson::String("OK"));
|
||||||
return tmpp;
|
return tmpp
|
||||||
} else if (action == "delete") {
|
*/
|
||||||
|
return ejson::Null();
|
||||||
|
}
|
||||||
|
if (action == "delete") {
|
||||||
uint64_t clientId = etk::string_to_uint64_t(_obj["client-id"].toString().get());
|
uint64_t clientId = etk::string_to_uint64_t(_obj["client-id"].toString().get());
|
||||||
clientDisconnect(clientId);
|
clientDisconnect(clientId);
|
||||||
|
/*
|
||||||
ejson::Object tmpp;
|
ejson::Object tmpp;
|
||||||
tmpp.add("client-id", ejson::String(etk::to_string(clientId)));
|
tmpp.add("client-id", ejson::String(etk::to_string(clientId)));
|
||||||
tmpp.add("return", ejson::String("OK"));
|
tmpp.add("return", ejson::String("OK"));
|
||||||
return tmpp;
|
return tmpp;
|
||||||
} else if ( action == "call"
|
*/
|
||||||
|
return ejson::Null();
|
||||||
|
}
|
||||||
|
if ( action == "call"
|
||||||
|| action == "") {
|
|| action == "") {
|
||||||
uint64_t clientId = etk::string_to_uint64_t(_obj["client-id"].toString().get());
|
uint64_t clientId = etk::string_to_uint64_t(_obj["client-id"].toString().get());
|
||||||
ejson::Object tmpp = callJson2(clientId, _obj);
|
ejson::Object tmpp = callJson2(clientId, _obj);
|
||||||
tmpp.add("client-id", ejson::String(etk::to_string(clientId)));
|
tmpp.add("client-id", ejson::String(etk::to_string(clientId)));
|
||||||
return tmpp;
|
return tmpp;
|
||||||
} else {
|
}
|
||||||
ejson::Object tmpp;
|
ejson::Object tmpp;
|
||||||
tmpp.add("error", ejson::String("NOT-IMPLEMENTED-ACTION"));
|
tmpp.add("error", ejson::String("NOT-IMPLEMENTED-ACTION"));
|
||||||
return tmpp;
|
return tmpp;
|
||||||
}
|
}
|
||||||
return ejson::Object();
|
|
||||||
}
|
|
||||||
|
@ -11,9 +11,10 @@
|
|||||||
#include <jus/AbstractFunctionTypeDirect.h>
|
#include <jus/AbstractFunctionTypeDirect.h>
|
||||||
#include <jus/AbstractFunctionTypeClass.h>
|
#include <jus/AbstractFunctionTypeClass.h>
|
||||||
#include <jus/debug.h>
|
#include <jus/debug.h>
|
||||||
|
#include <jus/RemoteProcessCall.h>
|
||||||
|
|
||||||
namespace jus {
|
namespace jus {
|
||||||
class Service : public eproperty::Interface {
|
class Service : public eproperty::Interface, public jus::RemoteProcessCall {
|
||||||
public:
|
public:
|
||||||
eproperty::Value<std::string> propertyIp;
|
eproperty::Value<std::string> propertyIp;
|
||||||
eproperty::Value<uint16_t> propertyPort;
|
eproperty::Value<uint16_t> propertyPort;
|
||||||
@ -25,25 +26,16 @@ namespace jus {
|
|||||||
public:
|
public:
|
||||||
Service();
|
Service();
|
||||||
virtual ~Service();
|
virtual ~Service();
|
||||||
// Genenric function call:
|
|
||||||
ejson::Object callJson(const ejson::Object& _obj);
|
|
||||||
virtual ejson::Object callJson2(size_t _clientId, const ejson::Object& _obj) = 0;
|
|
||||||
void connect(const std::string& _serviceName);
|
void connect(const std::string& _serviceName);
|
||||||
void disconnect();
|
void disconnect();
|
||||||
private:
|
private:
|
||||||
void onClientData(const std::string& _value);
|
void onClientData(const std::string& _value);
|
||||||
std::string asyncRead();
|
std::string asyncRead();
|
||||||
|
public:
|
||||||
|
void pingIsAlive();
|
||||||
private:
|
private:
|
||||||
void onPropertyChangeIp();
|
void onPropertyChangeIp();
|
||||||
void onPropertyChangePort();
|
void onPropertyChangePort();
|
||||||
public:
|
|
||||||
template<class JUS_RETURN_VALUE,
|
|
||||||
class... JUS_FUNC_ARGS_TYPE>
|
|
||||||
void advertise(const std::string& _name,
|
|
||||||
JUS_RETURN_VALUE (*_func)(JUS_FUNC_ARGS_TYPE... _args),
|
|
||||||
const std::string& _desc) {
|
|
||||||
AbstractFunction* tmp = createAbstractFunctionDirect(_name, _desc, _func);
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* @brief A extern client connect on specific user
|
* @brief A extern client connect on specific user
|
||||||
* @param[in] _clientSessionID Source session Id on the client
|
* @param[in] _clientSessionID Source session Id on the client
|
||||||
@ -52,6 +44,9 @@ namespace jus {
|
|||||||
*/
|
*/
|
||||||
virtual void clientConnect(size_t _clientSessionID, const std::string& _userName) = 0;
|
virtual void clientConnect(size_t _clientSessionID, const std::string& _userName) = 0;
|
||||||
virtual void clientDisconnect(size_t _clientSessionID) = 0;
|
virtual void clientDisconnect(size_t _clientSessionID) = 0;
|
||||||
|
// Genenric function call:
|
||||||
|
ejson::Value callJson(const ejson::Object& _obj);
|
||||||
|
virtual ejson::Object callJson2(size_t _clientId, const ejson::Object& _obj) = 0;
|
||||||
};
|
};
|
||||||
template<class JUS_TYPE_SERVICE, class JUS_USER_ACCESS>
|
template<class JUS_TYPE_SERVICE, class JUS_USER_ACCESS>
|
||||||
class ServiceType : public jus::Service {
|
class ServiceType : public jus::Service {
|
||||||
@ -59,15 +54,23 @@ namespace jus {
|
|||||||
JUS_USER_ACCESS& m_getUserInterface;
|
JUS_USER_ACCESS& m_getUserInterface;
|
||||||
// no need of shared_ptr or unique_ptr (if service die all is lost and is client die, the gateway notify us...)
|
// no need of shared_ptr or unique_ptr (if service die all is lost and is client die, the gateway notify us...)
|
||||||
std::map<size_t, JUS_TYPE_SERVICE*> m_interface;
|
std::map<size_t, JUS_TYPE_SERVICE*> m_interface;
|
||||||
std::vector<AbstractFunction*> m_listFunction;
|
|
||||||
public:
|
public:
|
||||||
template<class JUS_RETURN_VALUE,
|
template<class JUS_RETURN_VALUE,
|
||||||
class JUS_CLASS_TYPE,
|
class JUS_CLASS_TYPE,
|
||||||
class... JUS_FUNC_ARGS_TYPE>
|
class... JUS_FUNC_ARGS_TYPE>
|
||||||
void advertise(const std::string& _name,
|
void advertise(const std::string& _name,
|
||||||
JUS_RETURN_VALUE (JUS_CLASS_TYPE::*_func)(JUS_FUNC_ARGS_TYPE... _args),
|
JUS_RETURN_VALUE (JUS_CLASS_TYPE::*_func)(JUS_FUNC_ARGS_TYPE... _args),
|
||||||
const std::string& _desc) {
|
const std::string& _desc = "") {
|
||||||
// TODO: check if fucntion does not exist ...
|
for (auto &it : m_listFunction) {
|
||||||
|
if (it == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (it->getName() == _name) {
|
||||||
|
JUS_ERROR("Advertise function already bind .. ==> can not be done...: '" << _name << "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
AbstractFunction* tmp = createAbstractFunctionClass(_name, _desc, _func);
|
AbstractFunction* tmp = createAbstractFunctionClass(_name, _desc, _func);
|
||||||
m_listFunction.push_back(tmp);
|
m_listFunction.push_back(tmp);
|
||||||
}
|
}
|
||||||
|
@ -48,9 +48,14 @@ void jus::TcpString::threadCallback() {
|
|||||||
signalData.emit(data);
|
signalData.emit(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_threadRunning = false;
|
||||||
JUS_DEBUG("End of thread");
|
JUS_DEBUG("End of thread");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool jus::TcpString::isActive() const {
|
||||||
|
return m_threadRunning;
|
||||||
|
}
|
||||||
|
|
||||||
void jus::TcpString::connect(bool _async){
|
void jus::TcpString::connect(bool _async){
|
||||||
JUS_DEBUG("connect [START]");
|
JUS_DEBUG("connect [START]");
|
||||||
m_threadRunning = true;
|
m_threadRunning = true;
|
||||||
@ -75,13 +80,13 @@ void jus::TcpString::connect(bool _async){
|
|||||||
|
|
||||||
void jus::TcpString::disconnect(){
|
void jus::TcpString::disconnect(){
|
||||||
JUS_DEBUG("disconnect [START]");
|
JUS_DEBUG("disconnect [START]");
|
||||||
|
if (m_thread != nullptr) {
|
||||||
|
m_threadRunning = false;
|
||||||
|
}
|
||||||
if (m_connection.getConnectionStatus() == enet::Tcp::status::link) {
|
if (m_connection.getConnectionStatus() == enet::Tcp::status::link) {
|
||||||
uint32_t size = 0xFFFFFFFF;
|
uint32_t size = 0xFFFFFFFF;
|
||||||
m_connection.write(&size, 4);
|
m_connection.write(&size, 4);
|
||||||
}
|
}
|
||||||
if (m_thread != nullptr) {
|
|
||||||
m_threadRunning = false;
|
|
||||||
}
|
|
||||||
if (m_connection.getConnectionStatus() != enet::Tcp::status::unlink) {
|
if (m_connection.getConnectionStatus() != enet::Tcp::status::unlink) {
|
||||||
m_connection.unlink();
|
m_connection.unlink();
|
||||||
}
|
}
|
||||||
@ -94,6 +99,9 @@ void jus::TcpString::disconnect(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t jus::TcpString::write(const std::string& _data) {
|
int32_t jus::TcpString::write(const std::string& _data) {
|
||||||
|
if (m_threadRunning == false) {
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
if (_data.size() == 0) {
|
if (_data.size() == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -103,6 +111,11 @@ int32_t jus::TcpString::write(const std::string& _data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string jus::TcpString::read() {
|
std::string jus::TcpString::read() {
|
||||||
|
JUS_VERBOSE("Read [START]");
|
||||||
|
if (m_threadRunning == false) {
|
||||||
|
JUS_DEBUG("Read [END] Disconected");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
// TODO : Do it better with a correct way to check data size ...
|
// TODO : Do it better with a correct way to check data size ...
|
||||||
JUS_VERBOSE("Read [START]");
|
JUS_VERBOSE("Read [START]");
|
||||||
std::string out;
|
std::string out;
|
||||||
|
@ -26,6 +26,7 @@ namespace jus {
|
|||||||
void setInterface(enet::Tcp _connection);
|
void setInterface(enet::Tcp _connection);
|
||||||
void connect(bool _async = false);
|
void connect(bool _async = false);
|
||||||
void disconnect();
|
void disconnect();
|
||||||
|
bool isActive() const;
|
||||||
void setInterfaceName(const std::string& _name);
|
void setInterfaceName(const std::string& _name);
|
||||||
int32_t write(const std::string& _data);
|
int32_t write(const std::string& _data);
|
||||||
std::string asyncRead();
|
std::string asyncRead();
|
||||||
|
@ -40,6 +40,7 @@ def create(target, module_name):
|
|||||||
'jus/GateWay.cpp',
|
'jus/GateWay.cpp',
|
||||||
'jus/GateWayService.cpp',
|
'jus/GateWayService.cpp',
|
||||||
'jus/GateWayClient.cpp',
|
'jus/GateWayClient.cpp',
|
||||||
|
'jus/RemoteProcessCall.cpp',
|
||||||
'jus/Service.cpp',
|
'jus/Service.cpp',
|
||||||
'jus/ServiceRemote.cpp',
|
'jus/ServiceRemote.cpp',
|
||||||
'jus/TcpString.cpp',
|
'jus/TcpString.cpp',
|
||||||
@ -54,6 +55,7 @@ def create(target, module_name):
|
|||||||
'jus/GateWay.h',
|
'jus/GateWay.h',
|
||||||
'jus/GateWayService.h',
|
'jus/GateWayService.h',
|
||||||
'jus/GateWayClient.h',
|
'jus/GateWayClient.h',
|
||||||
|
'jus/RemoteProcessCall.h',
|
||||||
'jus/Service.h',
|
'jus/Service.h',
|
||||||
'jus/ServiceRemote.h',
|
'jus/ServiceRemote.h',
|
||||||
'jus/TcpString.h',
|
'jus/TcpString.h',
|
||||||
|
@ -69,7 +69,13 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
etk::init(_argc, _argv);
|
etk::init(_argc, _argv);
|
||||||
appl::UserManager userMng;
|
appl::UserManager userMng;
|
||||||
jus::ServiceType<appl::Calculator, appl::UserManager> serviceInterface(userMng);
|
jus::ServiceType<appl::Calculator, appl::UserManager> serviceInterface(userMng);
|
||||||
serviceInterface.advertise("mul", &appl::Calculator::mul, "simple multiplication to test double IO");
|
serviceInterface.setDescription("Calculator interface");
|
||||||
|
serviceInterface.setVersion("0.1.1");
|
||||||
|
serviceInterface.addAuthor("Heero Yui", "yui.heero@gmail.com");
|
||||||
|
serviceInterface.advertise("mul", &appl::Calculator::mul);
|
||||||
|
serviceInterface.setLastFuncDesc("simple multiplication to test double IO");
|
||||||
|
serviceInterface.addLastFuncParam("val1", "First Parameter To multiply");
|
||||||
|
serviceInterface.addLastFuncParam("val2", "Second Parameter To multiply");
|
||||||
for (int32_t iii=0; iii<_argc ; ++iii) {
|
for (int32_t iii=0; iii<_argc ; ++iii) {
|
||||||
std::string data = _argv[iii];
|
std::string data = _argv[iii];
|
||||||
if (etk::start_with(data, "--ip=") == true) {
|
if (etk::start_with(data, "--ip=") == true) {
|
||||||
@ -91,7 +97,8 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
serviceInterface.connect("serviceTest1");
|
serviceInterface.connect("serviceTest1");
|
||||||
int32_t iii=0;
|
int32_t iii=0;
|
||||||
while (true) {
|
while (true) {
|
||||||
usleep(500000);
|
usleep(1000000);
|
||||||
|
serviceInterface.pingIsAlive();
|
||||||
APPL_INFO("service in waiting ... " << iii << "/inf");
|
APPL_INFO("service in waiting ... " << iii << "/inf");
|
||||||
iii++;
|
iii++;
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,10 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
APPL_INFO("==================================");
|
APPL_INFO("==================================");
|
||||||
basicGateway.start();
|
basicGateway.start();
|
||||||
while (true) {
|
while (true) {
|
||||||
usleep(200000);
|
usleep(100000);
|
||||||
|
basicGateway.cleanIO();
|
||||||
}
|
}
|
||||||
|
basicGateway.stop();
|
||||||
APPL_INFO("==================================");
|
APPL_INFO("==================================");
|
||||||
APPL_INFO("== JUS gateway stop ==");
|
APPL_INFO("== JUS gateway stop ==");
|
||||||
APPL_INFO("==================================");
|
APPL_INFO("==================================");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user