[DEV] remove json interface (start)
This commit is contained in:
parent
ef853b106e
commit
5023d6842b
@ -6,277 +6,7 @@
|
||||
#include <jus/AbstractFunction.h>
|
||||
#include <jus/debug.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
#include <ejson/base64.h>
|
||||
namespace jus {
|
||||
template<> bool convertJsonTo<bool>(const ejson::Value& _value) {
|
||||
return _value.toBoolean().get();
|
||||
}
|
||||
template<> std::vector<bool> convertJsonTo<std::vector<bool>>(const ejson::Value& _value) {
|
||||
std::vector<bool> out;
|
||||
for (const auto it : _value.toArray()) {
|
||||
out.push_back(convertJsonTo<bool>(it));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
template<> float convertJsonTo<float>(const ejson::Value& _value) {
|
||||
return _value.toNumber().get();
|
||||
}
|
||||
template<> double convertJsonTo<double>(const ejson::Value& _value) {
|
||||
return _value.toNumber().get();
|
||||
}
|
||||
template<> int64_t convertJsonTo<int64_t>(const ejson::Value& _value) {
|
||||
return int64_t(_value.toNumber().get());
|
||||
}
|
||||
template<> int32_t convertJsonTo<int32_t>(const ejson::Value& _value) {
|
||||
return int32_t(_value.toNumber().get());
|
||||
}
|
||||
template<> int16_t convertJsonTo<int16_t>(const ejson::Value& _value) {
|
||||
return int16_t(_value.toNumber().get());
|
||||
}
|
||||
template<> int8_t convertJsonTo<int8_t>(const ejson::Value& _value) {
|
||||
return int8_t(_value.toNumber().get());
|
||||
}
|
||||
template<> uint64_t convertJsonTo<uint64_t>(const ejson::Value& _value) {
|
||||
return uint64_t(_value.toNumber().get());
|
||||
}
|
||||
template<> uint32_t convertJsonTo<uint32_t>(const ejson::Value& _value) {
|
||||
return uint32_t(_value.toNumber().get());
|
||||
}
|
||||
template<> uint16_t convertJsonTo<uint16_t>(const ejson::Value& _value) {
|
||||
return uint16_t(_value.toNumber().get());
|
||||
}
|
||||
template<> uint8_t convertJsonTo<uint8_t>(const ejson::Value& _value) {
|
||||
return uint8_t(_value.toNumber().get());
|
||||
}
|
||||
template<> std::string convertJsonTo<std::string>(const ejson::Value& _value) {
|
||||
return _value.toString().get();
|
||||
}
|
||||
template<> std::vector<std::string> convertJsonTo<std::vector<std::string>>(const ejson::Value& _value) {
|
||||
std::vector<std::string> out;
|
||||
for (const auto it : _value.toArray()) {
|
||||
out.push_back(convertJsonTo<std::string>(it));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
template<> jus::File convertJsonTo<jus::File>(const ejson::Value& _value) {
|
||||
ejson::Object obj = _value.toObject();
|
||||
jus::File out;
|
||||
out.setMineType(obj["mine-type"].toString().get());
|
||||
out.preSetDataSize(obj["size"].toNumber().getU64());
|
||||
//out.add("type", ejson::String("file"));
|
||||
|
||||
uint64_t offset = 0;
|
||||
for (auto it : obj["data"].toArray()) {
|
||||
ejson::String valData = it.toString();
|
||||
if (valData.get().size() != 0) {
|
||||
std::vector<uint8_t> tmpData = ejson::base64::decode(valData.get());
|
||||
out.setData(offset, tmpData);
|
||||
offset += tmpData.size();
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------
|
||||
|
||||
template<> ejson::Value convertToJson<bool>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const bool& _value) {
|
||||
return ejson::Boolean(_value);
|
||||
}
|
||||
template<> ejson::Value convertToJson<std::vector<bool>>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const std::vector<bool>& _value) {
|
||||
ejson::Array out;
|
||||
for (const auto &it : _value) {
|
||||
out.add(ejson::Boolean(it));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
template<> ejson::Value convertToJson<float>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const float& _value) {
|
||||
return ejson::Number(_value);
|
||||
}
|
||||
template<> ejson::Value convertToJson<double>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const double& _value) {
|
||||
return ejson::Number(_value);
|
||||
}
|
||||
template<> ejson::Value convertToJson<int64_t>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const int64_t& _value) {
|
||||
return ejson::Number(_value);
|
||||
}
|
||||
template<> ejson::Value convertToJson<int32_t>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const int32_t& _value) {
|
||||
return ejson::Number(_value);
|
||||
}
|
||||
template<> ejson::Value convertToJson<int16_t>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const int16_t& _value) {
|
||||
return ejson::Number(_value);
|
||||
}
|
||||
template<> ejson::Value convertToJson<int8_t>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const int8_t& _value) {
|
||||
return ejson::Number(_value);
|
||||
}
|
||||
template<> ejson::Value convertToJson<uint64_t>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const uint64_t& _value) {
|
||||
return ejson::Number(_value);
|
||||
}
|
||||
template<> ejson::Value convertToJson<uint32_t>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const uint32_t& _value) {
|
||||
return ejson::Number(_value);
|
||||
}
|
||||
template<> ejson::Value convertToJson<uint16_t>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const uint16_t& _value) {
|
||||
return ejson::Number(_value);
|
||||
}
|
||||
template<> ejson::Value convertToJson<uint8_t>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const uint8_t& _value) {
|
||||
return ejson::Number(_value);
|
||||
}
|
||||
template<> ejson::Value convertToJson<std::string>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const std::string& _value) {
|
||||
return ejson::String(_value);
|
||||
}
|
||||
template<> ejson::Value convertToJson<char*>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, char* const & _value) {
|
||||
if (_value == nullptr) {
|
||||
return ejson::String();
|
||||
}
|
||||
return ejson::String(_value);
|
||||
}
|
||||
template<> ejson::Value convertToJson<std::vector<std::string>>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const std::vector<std::string>& _value) {
|
||||
ejson::Array out;
|
||||
for (auto &it : _value) {
|
||||
out.add(ejson::String(it));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
template<> ejson::Value convertToJson<jus::FileServer>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const jus::FileServer& _value) {
|
||||
ejson::Array out;
|
||||
/*
|
||||
for (auto &it : _value) {
|
||||
out.add(ejson::String(it));
|
||||
}
|
||||
*/
|
||||
return out;
|
||||
}
|
||||
|
||||
static const int32_t BASE_SIZE_TRANSFER = 4096;
|
||||
class SenderJusFile {
|
||||
private:
|
||||
jus::File m_data;
|
||||
uint64_t m_size;
|
||||
uint64_t m_offset;
|
||||
int32_t m_paramID;
|
||||
public:
|
||||
SenderJusFile(jus::File _data, int32_t _paramID) :
|
||||
m_data(_data),
|
||||
m_size(m_data.getData().size()),
|
||||
m_offset(0),
|
||||
m_paramID(_paramID) {
|
||||
|
||||
}
|
||||
~SenderJusFile() {
|
||||
|
||||
}
|
||||
bool operator() (TcpString* _interface, const uint32_t& _serviceId, uint64_t _transactionId, uint64_t _part) {
|
||||
ejson::Object answer;
|
||||
if (_serviceId != 0) {
|
||||
answer.add("service", ejson::Number(_serviceId));
|
||||
}
|
||||
answer.add("id", ejson::Number(_transactionId));
|
||||
answer.add("part", ejson::Number(_part));
|
||||
if (m_paramID >= 0) {
|
||||
answer.add("param-id", ejson::Number(m_paramID));
|
||||
}
|
||||
int32_t tmpSize = BASE_SIZE_TRANSFER;
|
||||
if (m_size < BASE_SIZE_TRANSFER) {
|
||||
tmpSize = m_size;
|
||||
}
|
||||
uint8_t tmpData[BASE_SIZE_TRANSFER];
|
||||
answer.add("data", ejson::String(ejson::base64::encode(&m_data.getData()[m_offset], tmpSize)));
|
||||
m_offset += tmpSize;
|
||||
m_size -= tmpSize;
|
||||
_interface->writeJson(answer);
|
||||
if (m_size <= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
template<> ejson::Value convertToJson<jus::File>(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const jus::File& _value) {
|
||||
ejson::Object out;
|
||||
out.add("type", ejson::String("file"));
|
||||
out.add("mine-type", ejson::String(_value.getMineType()));
|
||||
out.add("size", ejson::Number(_value.getData().size()));
|
||||
if (_value.getData().size() != 0) {
|
||||
_asyncAction.push_back(SenderJusFile(_value, _paramId));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------
|
||||
|
||||
template<> bool convertStringTo<bool>(const std::string& _value) {
|
||||
return etk::string_to_bool(_value);
|
||||
}
|
||||
template<> float convertStringTo<float>(const std::string& _value) {
|
||||
return etk::string_to_float(_value);
|
||||
}
|
||||
template<> double convertStringTo<double>(const std::string& _value) {
|
||||
return etk::string_to_double(_value);
|
||||
}
|
||||
template<> int64_t convertStringTo<int64_t>(const std::string& _value) {
|
||||
return etk::string_to_int64_t(_value);
|
||||
}
|
||||
template<> int32_t convertStringTo<int32_t>(const std::string& _value) {
|
||||
return etk::string_to_int32_t(_value);
|
||||
}
|
||||
template<> int16_t convertStringTo<int16_t>(const std::string& _value) {
|
||||
return etk::string_to_int16_t(_value);
|
||||
}
|
||||
template<> int8_t convertStringTo<int8_t>(const std::string& _value) {
|
||||
return etk::string_to_int8_t(_value);
|
||||
}
|
||||
template<> uint64_t convertStringTo<uint64_t>(const std::string& _value) {
|
||||
return etk::string_to_uint64_t(_value);
|
||||
}
|
||||
template<> uint32_t convertStringTo<uint32_t>(const std::string& _value) {
|
||||
return etk::string_to_uint32_t(_value);
|
||||
}
|
||||
template<> uint16_t convertStringTo<uint16_t>(const std::string& _value) {
|
||||
return etk::string_to_uint16_t(_value);
|
||||
}
|
||||
template<> uint8_t convertStringTo<uint8_t>(const std::string& _value) {
|
||||
return etk::string_to_uint8_t(_value);
|
||||
}
|
||||
template<> std::string convertStringTo<std::string>(const std::string& _value) {
|
||||
return _value;
|
||||
}
|
||||
template<> std::vector<std::string> convertStringTo<std::vector<std::string>>(const std::string& _value) {
|
||||
std::vector<std::string> out;
|
||||
JUS_TODO("Convert string to vs");
|
||||
return out;
|
||||
}
|
||||
template<> jus::FileServer convertStringTo<jus::FileServer>(const std::string& _value) {
|
||||
return jus::FileServer();
|
||||
}
|
||||
template<> jus::File convertStringTo<jus::File>(const std::string& _value) {
|
||||
return jus::File();
|
||||
}
|
||||
|
||||
}
|
||||
// ============================================================
|
||||
// == JSON
|
||||
// ============================================================
|
||||
|
||||
ejson::Object jus::createCallJson(uint64_t _transactionId, const std::string& _functionName, ejson::Array _params) {
|
||||
ejson::Object callElem = createBaseCall(_transactionId, _functionName);
|
||||
callElem.add("param", _params);
|
||||
return callElem;
|
||||
}
|
||||
|
||||
ejson::Object jus::createBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId) {
|
||||
ejson::Object obj;
|
||||
if (_serviceId != 0) {
|
||||
obj.add("service", ejson::Number(_serviceId));
|
||||
}
|
||||
obj.add("call", ejson::String(_functionName));
|
||||
obj.add("id", ejson::Number(_transactionId));
|
||||
return obj;
|
||||
}
|
||||
void jus::createParam(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, ejson::Object& _obj) {
|
||||
// Finish recursive parse ...
|
||||
}
|
||||
|
||||
|
||||
// ============================================================
|
||||
// == Binary
|
||||
// ============================================================
|
||||
jus::Buffer jus::createBinaryCall(uint64_t _transactionId, const std::string& _functionName, const jus::Buffer& _params) {
|
||||
jus::Buffer callElem = createBinaryBaseCall(_transactionId, _functionName);
|
||||
//callElem.add("param", _params);
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
#pragma once
|
||||
#include <eproperty/Value.h>
|
||||
#include <ejson/ejson.h>
|
||||
#include <jus/debug.h>
|
||||
#include <jus/ParamType.h>
|
||||
#include <jus/File.h>
|
||||
@ -67,67 +66,6 @@ namespace jus {
|
||||
virtual void execute(const ememory::SharedPtr<jus::TcpString>& _interfaceClient, uint64_t _transactionId, uint64_t _clientId, jus::Buffer& _params, void* _class=nullptr) = 0;
|
||||
};
|
||||
|
||||
|
||||
template<class JUS_TYPE>
|
||||
JUS_TYPE convertStringTo(const std::string& _value);
|
||||
|
||||
template<class JUS_TYPE>
|
||||
JUS_TYPE convertJsonTo(const ejson::Value& _value);
|
||||
|
||||
template<class JUS_TYPE>
|
||||
ejson::Value convertToJson(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const JUS_TYPE& _value);
|
||||
//ejson::Value convertToJson(std::vector<ActionAsyncClient>& _asyncAction, int32_t _paramId, const char* _value);
|
||||
|
||||
|
||||
// ============================================================
|
||||
// == JSON
|
||||
// ============================================================
|
||||
ejson::Object createBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId=0);
|
||||
|
||||
void createParam(std::vector<ActionAsyncClient>& _asyncAction,
|
||||
int32_t _paramId,
|
||||
ejson::Object& _obj);
|
||||
|
||||
template<class JUS_TYPE, class... _ARGS>
|
||||
void createParam(std::vector<ActionAsyncClient>& _asyncAction,
|
||||
int32_t _paramId,
|
||||
ejson::Object& _obj,
|
||||
const JUS_TYPE& _param,
|
||||
_ARGS&&... _args) {
|
||||
if (_obj.valueExist("param") == false) {
|
||||
_obj.add("param", ejson::Array());
|
||||
}
|
||||
ejson::Array array = _obj["param"].toArray();
|
||||
array.add(convertToJson<JUS_TYPE>(_asyncAction, _paramId, _param));
|
||||
_paramId++;
|
||||
createParam(_asyncAction, _paramId, _obj, std::forward<_ARGS>(_args)...);
|
||||
}
|
||||
// convert const char in std::string ...
|
||||
template<class... _ARGS>
|
||||
void createParam(std::vector<ActionAsyncClient>& _asyncAction,
|
||||
int32_t _paramId,
|
||||
ejson::Object& _obj,
|
||||
const char* _param,
|
||||
_ARGS&&... _args) {
|
||||
createParam(_asyncAction, _paramId, _obj, std::string(_param), std::forward<_ARGS>(_args)...);
|
||||
}
|
||||
template<class... _ARGS>
|
||||
ejson::Object createCall(std::vector<ActionAsyncClient>& _asyncAction, uint64_t _transactionId, const std::string& _functionName, _ARGS&&... _args) {
|
||||
ejson::Object callElem = createBaseCall(_transactionId, _functionName);
|
||||
createParam(_asyncAction, 0, callElem, std::forward<_ARGS>(_args)...);
|
||||
return callElem;
|
||||
}
|
||||
template<class... _ARGS>
|
||||
ejson::Object createCallService(std::vector<ActionAsyncClient>& _asyncAction, uint64_t _transactionId, const uint32_t& _serviceId, const std::string& _functionName, _ARGS&&... _args) {
|
||||
ejson::Object callElem = createBaseCall(_transactionId, _functionName, _serviceId);
|
||||
createParam(_asyncAction, 0, callElem, std::forward<_ARGS>(_args)...);
|
||||
return callElem;
|
||||
}
|
||||
ejson::Object createCallJson(uint64_t _transactionId, const std::string& _functionName, ejson::Array _params);
|
||||
|
||||
// ============================================================
|
||||
// == Binary
|
||||
// ============================================================
|
||||
jus::Buffer createBinaryBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId=0);
|
||||
void createBinaryParam(std::vector<ActionAsyncClient>& _asyncAction,
|
||||
int32_t _paramId,
|
||||
|
@ -7,12 +7,10 @@
|
||||
|
||||
#include <jus/TcpString.h>
|
||||
#include <eproperty/Value.h>
|
||||
#include <ejson/ejson.h>
|
||||
#include <jus/debug.h>
|
||||
#include <jus/AbstractFunction.h>
|
||||
#include <jus/mineType.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
#include <ejson/base64.h>
|
||||
|
||||
|
||||
namespace jus {
|
||||
@ -81,7 +79,6 @@ namespace jus {
|
||||
m_size = m_node.fileSize();
|
||||
jus::File tmpFile(jus::getMineType(extention), std::vector<uint8_t>(), m_size);
|
||||
answer.addAnswer(tmpFile);
|
||||
// TODO : Manage JSON ...
|
||||
_interface->writeBinary(answer);
|
||||
m_partId++;
|
||||
return false;
|
||||
@ -93,13 +90,11 @@ namespace jus {
|
||||
uint8_t tmpData[1024];
|
||||
m_node.fileRead(tmpData, 1, tmpSize);
|
||||
answer.addData(tmpData, tmpSize);
|
||||
//answer.add("data", ejson::String(ejson::base64::encode(tmpData, tmpSize)));
|
||||
m_size -= tmpSize;
|
||||
if (m_size <= 0) {
|
||||
answer.setPartFinish(true);
|
||||
m_node.fileClose();
|
||||
}
|
||||
//JUS_INFO("Answer: " << answer.generateHumanString());
|
||||
_interface->writeBinary(answer);;
|
||||
m_partId++;
|
||||
if (m_size <= 0) {
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include <jus/TcpString.h>
|
||||
#include <eproperty/Value.h>
|
||||
#include <ejson/ejson.h>
|
||||
#include <jus/debug.h>
|
||||
#include <jus/AbstractFunction.h>
|
||||
namespace jus {
|
||||
@ -21,13 +20,12 @@ namespace jus {
|
||||
// clang generate a basic warning:
|
||||
// warning: multiple unsequenced modifications to 'idParam' [-Wunsequenced]
|
||||
int32_t idParam = 0;
|
||||
JUS_RETURN ret = jus::convertToJson(_func(_obj.getParameter<JUS_TYPES>(idParam++)...));
|
||||
JUS_RETURN ret = _func(_obj.getParameter<JUS_TYPES>(idParam++)...);
|
||||
#elif defined(__GNUC__) || defined(__GNUG__) || defined(_MSC_VER)
|
||||
int32_t idParam = int32_t(sizeof...(JUS_TYPES))-1;
|
||||
JUS_RETURN ret = jus::convertToJson(_func(_obj.getParameter<JUS_TYPES>(idParam--)...));
|
||||
JUS_RETURN ret = _func(_obj.getParameter<JUS_TYPES>(idParam--)...);
|
||||
#else
|
||||
#error Must be implemented ...
|
||||
JUS_RETURN ret = ejson::Null();
|
||||
#endif
|
||||
_interfaceClient->addAsync([=](TcpString* _interface) {
|
||||
_interface->answerValue(_transactionId, ret, _clientId);
|
||||
@ -41,7 +39,6 @@ namespace jus {
|
||||
uint64_t _clientId,
|
||||
void (*_func)(JUS_TYPES...),
|
||||
jus::Buffer& _obj) {
|
||||
ejson::Object out;
|
||||
#if defined(__clang__)
|
||||
// clang generate a basic warning:
|
||||
// warning: multiple unsequenced modifications to 'idParam' [-Wunsequenced]
|
||||
|
@ -1,106 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#include <etk/types.h>
|
||||
#include <jus/Buffer.h>
|
||||
#include <jus/debug.h>
|
||||
#include <jus/ParamType.h>
|
||||
|
||||
|
||||
|
||||
|
||||
namespace jus {
|
||||
// ----------------------------------------------------------------------------------------------------
|
||||
|
||||
template<> ejson::Value convertBinaryToJson<bool>(const uint8_t* _data, uint32_t _size) {
|
||||
const bool* value = reinterpret_cast<const bool*>(_data);
|
||||
return ejson::Boolean(*value);
|
||||
}
|
||||
template<> ejson::Value convertBinaryToJson<std::vector<bool>>(const uint8_t* _data, uint32_t _size) {
|
||||
const bool* value = reinterpret_cast<const bool*>(_data);
|
||||
ejson::Array out;
|
||||
for (size_t iii=0; iii<_size; ++iii) {
|
||||
out.add(ejson::Boolean(value[iii]));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
template<> ejson::Value convertBinaryToJson<float>(const uint8_t* _data, uint32_t _size) {
|
||||
const float* value = reinterpret_cast<const float*>(_data);
|
||||
return ejson::Number(*value);
|
||||
}
|
||||
template<> ejson::Value convertBinaryToJson<double>(const uint8_t* _data, uint32_t _size) {
|
||||
const double* value = reinterpret_cast<const double*>(_data);
|
||||
return ejson::Number(*value);
|
||||
}
|
||||
template<> ejson::Value convertBinaryToJson<int64_t>(const uint8_t* _data, uint32_t _size) {
|
||||
const int64_t* value = reinterpret_cast<const int64_t*>(_data);
|
||||
return ejson::Number(*value);
|
||||
}
|
||||
template<> ejson::Value convertBinaryToJson<int32_t>(const uint8_t* _data, uint32_t _size) {
|
||||
const int32_t* value = reinterpret_cast<const int32_t*>(_data);
|
||||
return ejson::Number(*value);
|
||||
}
|
||||
template<> ejson::Value convertBinaryToJson<int16_t>(const uint8_t* _data, uint32_t _size) {
|
||||
const int16_t* value = reinterpret_cast<const int16_t*>(_data);
|
||||
return ejson::Number(*value);
|
||||
}
|
||||
template<> ejson::Value convertBinaryToJson<int8_t>(const uint8_t* _data, uint32_t _size) {
|
||||
const int8_t* value = reinterpret_cast<const int8_t*>(_data);
|
||||
return ejson::Number(*value);
|
||||
}
|
||||
template<> ejson::Value convertBinaryToJson<uint64_t>(const uint8_t* _data, uint32_t _size) {
|
||||
const uint64_t* value = reinterpret_cast<const uint64_t*>(_data);
|
||||
return ejson::Number(*value);
|
||||
}
|
||||
template<> ejson::Value convertBinaryToJson<uint32_t>(const uint8_t* _data, uint32_t _size) {
|
||||
const uint32_t* value = reinterpret_cast<const uint32_t*>(_data);
|
||||
return ejson::Number(*value);
|
||||
}
|
||||
template<> ejson::Value convertBinaryToJson<uint16_t>(const uint8_t* _data, uint32_t _size) {
|
||||
const uint16_t* value = reinterpret_cast<const uint16_t*>(_data);
|
||||
return ejson::Number(*value);
|
||||
}
|
||||
template<> ejson::Value convertBinaryToJson<uint8_t>(const uint8_t* _data, uint32_t _size) {
|
||||
const uint8_t* value = reinterpret_cast<const uint8_t*>(_data);
|
||||
return ejson::Number(*value);
|
||||
}
|
||||
template<> ejson::Value convertBinaryToJson<std::string>(const uint8_t* _data, uint32_t _size) {
|
||||
std::string val;
|
||||
val.resize(_size, '\0');
|
||||
memcpy(&val[0], _data, _size);
|
||||
return ejson::String(val);
|
||||
}
|
||||
template<> ejson::Value convertBinaryToJson<std::vector<std::string>>(const uint8_t* _data, uint32_t _size) {
|
||||
/*
|
||||
Little hard ... TODO : ...
|
||||
const bool* value = reinterpret_cast<const bool*>(_data);
|
||||
ejson::Array out;
|
||||
for (size_t iii=0; iii<_size; ++iii) {
|
||||
out.add(ejson::Boolean(value[iii]));
|
||||
}
|
||||
return out;
|
||||
*/
|
||||
ejson::Array out;
|
||||
return out;
|
||||
}
|
||||
/*
|
||||
template<> ejson::Value convertBinaryToJson<jus::File>(const uint8_t* _data, uint32_t _size) {
|
||||
ejson::Object out;
|
||||
out.add("type", ejson::String("file"));
|
||||
out.add("mine-type", ejson::String(_value.getMineType()));
|
||||
out.add("size", ejson::Number(_value.getData().size()));
|
||||
if (_value.getData().size() != 0) {
|
||||
_asyncAction.push_back(SenderJusFile(_value, _paramId));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
*/
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,7 +21,7 @@ jus::Client::~Client() {
|
||||
}
|
||||
|
||||
void jus::Client::onClientData(jus::Buffer& _value) {
|
||||
JUS_ERROR("Get Data On the Communication interface that is not understand ... : " << _value.toJson().generateHumanString());
|
||||
JUS_ERROR("Get Data On the Communication interface that is not understand ... : " << _value.generateHumanString());
|
||||
}
|
||||
|
||||
jus::ServiceRemote jus::Client::getService(const std::string& _name) {
|
||||
@ -49,16 +49,6 @@ bool jus::Client::connect(const std::string& _remoteUserToConnect){
|
||||
m_interfaceClient->connect(this, &jus::Client::onClientData);
|
||||
m_interfaceClient->setInterface(std::move(connection));
|
||||
m_interfaceClient->connect();
|
||||
// Force mode binary:
|
||||
JUS_WARNING("Request change in mode Binary");
|
||||
jus::Future<bool> retBin = call("setMode", "BIN").wait();
|
||||
if (retBin.get() == true) {
|
||||
JUS_WARNING(" ==> accepted binary");
|
||||
m_interfaceClient->setMode(jus::connectionMode::modeBinary);
|
||||
JUS_INFO("Connection jump in BINARY ...");
|
||||
} else {
|
||||
// stay in JSON
|
||||
}
|
||||
|
||||
JUS_WARNING("Request connect user " << _remoteUserToConnect);
|
||||
jus::Future<bool> ret = call("connectToUser", _remoteUserToConnect, "jus-client");
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include <jus/TcpString.h>
|
||||
#include <eproperty/Value.h>
|
||||
#include <ejson/ejson.h>
|
||||
#include <jus/debug.h>
|
||||
#include <chrono>
|
||||
#include <unistd.h>
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <jus/debug.h>
|
||||
#include <unistd.h>
|
||||
#include <jus/File.h>
|
||||
#include <ejson/base64.h>
|
||||
|
||||
namespace jus {
|
||||
template<>
|
||||
|
@ -36,25 +36,6 @@ const jus::Buffer& jus::FutureBase::getRaw() {
|
||||
return m_data->m_returnData;
|
||||
}
|
||||
|
||||
jus::FutureBase::FutureBase(uint64_t _transactionId, bool _isFinished, ejson::Object _returnData, jus::FutureData::ObserverFinish _callback) {
|
||||
m_data = std::make_shared<jus::FutureData>();
|
||||
if (m_data == nullptr) {
|
||||
return;
|
||||
}
|
||||
m_data->m_sendTime = std::chrono::steady_clock::now();
|
||||
m_data->m_transactionId = _transactionId;
|
||||
m_data->m_isFinished = _isFinished;
|
||||
m_data->m_isSynchronous = false;
|
||||
m_data->m_returnData.fromJson(_returnData);
|
||||
m_data->m_callbackFinish = _callback;
|
||||
if (m_data->m_isFinished == true) {
|
||||
m_data->m_receiveTime = std::chrono::steady_clock::now();
|
||||
if (m_data->m_callbackFinish != nullptr) {
|
||||
m_data->m_callbackFinish(*this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jus::FutureBase::FutureBase(uint64_t _transactionId, bool _isFinished, jus::Buffer _returnData, jus::FutureData::ObserverFinish _callback) {
|
||||
m_data = std::make_shared<jus::FutureData>();
|
||||
if (m_data == nullptr) {
|
||||
@ -88,12 +69,6 @@ jus::FutureBase jus::FutureBase::operator= (const jus::FutureBase& _base) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool jus::FutureBase::setAnswer(const ejson::Object& _returnValue) {
|
||||
jus::Buffer tmp;
|
||||
tmp.fromJson(_returnValue);
|
||||
return setAnswer(tmp);
|
||||
}
|
||||
|
||||
bool jus::FutureBase::setAnswer(const jus::Buffer& _returnValue) {
|
||||
if (m_data == nullptr) {
|
||||
JUS_ERROR(" Not a valid future ...");
|
||||
|
@ -15,10 +15,8 @@ namespace jus {
|
||||
FutureBase(const jus::FutureBase& _base);
|
||||
FutureBase();
|
||||
FutureBase(uint64_t _transactionId, jus::FutureData::ObserverFinish _callback=nullptr);
|
||||
FutureBase(uint64_t _transactionId, bool _isFinished, ejson::Object _returnData, jus::FutureData::ObserverFinish _callback=nullptr);
|
||||
FutureBase(uint64_t _transactionId, bool _isFinished, jus::Buffer _returnData, jus::FutureData::ObserverFinish _callback=nullptr);
|
||||
jus::FutureBase operator= (const jus::FutureBase& _base);
|
||||
bool setAnswer(const ejson::Object& _returnValue);
|
||||
bool setAnswer(const jus::Buffer& _returnValue);
|
||||
void setSynchronous();
|
||||
uint64_t getTransactionId();
|
||||
|
@ -6,7 +6,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <ejson/ejson.h>
|
||||
#include <jus/Buffer.h>
|
||||
|
||||
|
||||
@ -20,7 +19,7 @@ namespace jus {
|
||||
bool m_isSynchronous;
|
||||
bool m_isFinished;
|
||||
jus::Buffer m_returnData;
|
||||
std::vector<ejson::Value> m_returnDataPart;
|
||||
//std::vector<ejson::Value> m_returnDataPart;
|
||||
ObserverFinish m_callbackFinish;
|
||||
std::chrono::steady_clock::time_point m_sendTime;
|
||||
std::chrono::steady_clock::time_point m_receiveTime;
|
||||
|
@ -6,7 +6,6 @@
|
||||
#pragma once
|
||||
#include <jus/GateWayService.h>
|
||||
#include <jus/GateWayClient.h>
|
||||
#include <ejson/ejson.h>
|
||||
|
||||
namespace jus {
|
||||
class TcpServerInput;
|
||||
|
@ -1,15 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace jus {
|
||||
enum class connectionMode {
|
||||
modeJson,
|
||||
modeXml,
|
||||
modeBinary,
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user