zeus/jus/ServiceRemote.h

52 lines
1.6 KiB
C
Raw Normal View History

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>
#include <jus/AbstractFunction.h>
2016-05-23 21:18:37 +02:00
#include <jus/ServiceRemote.h>
#include <jus/Future.h>
2016-06-08 21:40:42 +02:00
#include <jus/connectionMode.h>
#include <jus/TcpString.h>
2016-05-23 21:18:37 +02:00
namespace jus {
class Client;
class ServiceRemote {
private:
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:
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>
jus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) {
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
}
return m_interfaceClient->callService(m_serviceId, _functionName, _args...);
2016-05-23 21:18:37 +02:00
}
template<class... _ARGS>
jus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, jus::FutureData::ObserverFinish _callback) {
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
}
return m_interfaceClient->callServiceAction(m_serviceId, _functionName, _args..., _callback);
}
2016-05-23 21:18:37 +02:00
};
}