2016-05-23 21:18:37 +02:00
|
|
|
/** @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/debug.h>
|
2016-05-26 22:12:37 +02:00
|
|
|
#include <jus/AbstractFunction.h>
|
2016-05-23 21:18:37 +02:00
|
|
|
#include <jus/ServiceRemote.h>
|
2016-05-27 00:08:02 +02:00
|
|
|
#include <jus/Future.h>
|
2016-06-08 21:40:42 +02:00
|
|
|
#include <jus/connectionMode.h>
|
2016-05-23 21:18:37 +02:00
|
|
|
|
|
|
|
namespace jus {
|
|
|
|
class Client;
|
|
|
|
class ServiceRemote {
|
|
|
|
private:
|
|
|
|
jus::Client* m_clientInterface;
|
|
|
|
std::string m_name;
|
2016-06-08 21:40:42 +02:00
|
|
|
uint32_t m_serviceId;
|
2016-05-25 21:25:33 +02:00
|
|
|
bool m_isLinked;
|
2016-05-23 21:18:37 +02:00
|
|
|
public:
|
|
|
|
ServiceRemote(jus::Client* _clientInterface, const std::string& _name);
|
|
|
|
~ServiceRemote();
|
2016-05-25 21:25:33 +02:00
|
|
|
bool exist();
|
2016-05-23 21:18:37 +02:00
|
|
|
private:
|
2016-06-03 23:45:01 +02:00
|
|
|
jus::FutureBase callJson(uint64_t _transactionId, const ejson::Object& _obj, const std::vector<ActionAsyncClient>& _async, jus::FutureData::ObserverFinish _callback=nullptr);
|
2016-06-09 22:32:24 +02:00
|
|
|
jus::FutureBase callBinary(uint64_t _transactionId, jus::Buffer& _obj, const std::vector<ActionAsyncClient>& _async, jus::FutureData::ObserverFinish _callback=nullptr);
|
2016-05-26 22:12:37 +02:00
|
|
|
uint64_t getId();
|
2016-06-08 21:40:42 +02:00
|
|
|
enum jus::connectionMode getMode();
|
2016-05-23 21:18:37 +02:00
|
|
|
public:
|
|
|
|
template<class... _ARGS>
|
2016-05-27 00:08:02 +02:00
|
|
|
jus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) {
|
2016-06-14 22:29:55 +02:00
|
|
|
return m_clientInterface->m_interfaceClient.callService(m_serviceId, _functionName, _args...);
|
|
|
|
/*
|
2016-05-27 00:08:02 +02:00
|
|
|
uint64_t id = getId();
|
2016-06-03 23:45:01 +02:00
|
|
|
std::vector<ActionAsyncClient> asyncActionToDo;
|
2016-06-08 21:40:42 +02:00
|
|
|
if (getMode() == jus::connectionMode::modeJson) {
|
|
|
|
ejson::Object callElem = jus::createCallService(asyncActionToDo, id, m_serviceId, _functionName, std::forward<_ARGS>(_args)...);
|
|
|
|
return callJson(id, callElem, asyncActionToDo);
|
|
|
|
} else {
|
|
|
|
jus::Buffer callElem = jus::createBinaryCallService(asyncActionToDo, id, m_serviceId, _functionName, std::forward<_ARGS>(_args)...);
|
|
|
|
return callBinary(id, callElem, asyncActionToDo);
|
|
|
|
}
|
2016-06-14 22:29:55 +02:00
|
|
|
*/
|
2016-05-23 21:18:37 +02:00
|
|
|
}
|
2016-05-27 22:21:32 +02:00
|
|
|
template<class... _ARGS>
|
|
|
|
jus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, jus::FutureData::ObserverFinish _callback) {
|
2016-06-14 22:29:55 +02:00
|
|
|
return m_clientInterface->m_interfaceClient.callServiceAction(m_serviceId, _functionName, _args..., _callback);
|
|
|
|
/*
|
2016-05-27 22:21:32 +02:00
|
|
|
uint64_t id = getId();
|
2016-06-03 23:45:01 +02:00
|
|
|
std::vector<ActionAsyncClient> asyncActionToDo;
|
2016-06-08 21:40:42 +02:00
|
|
|
if (getMode() == jus::connectionMode::modeJson) {
|
|
|
|
ejson::Object callElem = jus::createCallService(asyncActionToDo, id, m_serviceId, _functionName, std::forward<_ARGS>(_args)...);
|
|
|
|
return callJson(id, callElem, asyncActionToDo, _callback);
|
|
|
|
} else {
|
|
|
|
jus::Buffer callElem = jus::createBinaryCallService(asyncActionToDo, id, m_serviceId, _functionName, std::forward<_ARGS>(_args)...);
|
|
|
|
return callBinary(id, callElem, asyncActionToDo, _callback);
|
|
|
|
}
|
2016-06-14 22:29:55 +02:00
|
|
|
*/
|
2016-05-27 22:21:32 +02:00
|
|
|
}
|
2016-05-23 21:18:37 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|