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-06-15 21:31:30 +02:00
|
|
|
#include <jus/TcpString.h>
|
2016-05-23 21:18:37 +02:00
|
|
|
|
|
|
|
namespace jus {
|
|
|
|
class Client;
|
|
|
|
class ServiceRemote {
|
|
|
|
private:
|
2016-06-15 21:31:30 +02:00
|
|
|
ememory::SharedPtr<jus::TcpString> m_interfaceClient;
|
2016-05-23 21:18:37 +02:00
|
|
|
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:
|
2016-06-15 21:31:30 +02:00
|
|
|
ServiceRemote(ememory::SharedPtr<jus::TcpString> _clientLink, const std::string& _name);
|
2016-05-23 21:18:37 +02:00
|
|
|
~ServiceRemote();
|
2016-05-25 21:25:33 +02:00
|
|
|
bool exist();
|
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-15 21:31:30 +02:00
|
|
|
if (m_interfaceClient == nullptr) {
|
|
|
|
jus::Buffer ret;
|
|
|
|
ret.addError("NULLPTR", "call " + _functionName + " with no interface open");
|
|
|
|
return jus::FutureBase(0, true, ret);
|
2016-06-08 21:40:42 +02:00
|
|
|
}
|
2016-06-15 21:31:30 +02:00
|
|
|
return m_interfaceClient->callService(m_serviceId, _functionName, _args...);
|
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-15 21:31:30 +02:00
|
|
|
if (m_interfaceClient == nullptr) {
|
|
|
|
jus::Buffer ret;
|
|
|
|
ret.addError("NULLPTR", "call " + _functionName + " with no interface open");
|
|
|
|
return jus::FutureBase(0, true, ret, _callback);
|
2016-06-08 21:40:42 +02:00
|
|
|
}
|
2016-06-15 21:31:30 +02:00
|
|
|
return m_interfaceClient->callServiceAction(m_serviceId, _functionName, _args..., _callback);
|
2016-05-27 22:21:32 +02:00
|
|
|
}
|
2016-05-23 21:18:37 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|