2016-05-12 22:45:40 +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 <ememory/memory.h>
|
|
|
|
#include <esignal/Signal.h>
|
2016-05-22 22:40:42 +02:00
|
|
|
#include <jus/GateWayService.h>
|
2016-05-12 22:45:40 +02:00
|
|
|
|
2016-05-25 21:25:33 +02:00
|
|
|
|
|
|
|
|
2016-05-12 22:45:40 +02:00
|
|
|
namespace jus {
|
2016-05-22 22:40:42 +02:00
|
|
|
class GateWay;
|
2016-05-12 22:45:40 +02:00
|
|
|
class GateWayClient {
|
2016-05-25 23:26:59 +02:00
|
|
|
private:
|
|
|
|
using Observer = std::function<void(ejson::Object& _data)>;
|
|
|
|
enum class state {
|
|
|
|
unconnect, // starting sate
|
|
|
|
connect, // just get a TCP connection
|
|
|
|
userIdentify, // client set the user it want to access
|
|
|
|
clientIdentify, // client defien the mode of the acces (anonymous,client/user)
|
|
|
|
disconnect // client is dead or loal disconnection
|
|
|
|
};
|
|
|
|
enum state m_state; // state machine ...
|
2016-05-22 22:40:42 +02:00
|
|
|
private:
|
|
|
|
jus::GateWay* m_gatewayInterface;
|
2016-05-12 22:45:40 +02:00
|
|
|
jus::TcpString m_interfaceClient;
|
2016-05-25 23:26:59 +02:00
|
|
|
void protocolError(const std::string& _errorHelp);
|
|
|
|
void returnBool(int32_t _transactionId, bool _value);
|
2016-05-23 21:18:37 +02:00
|
|
|
public:
|
2016-05-12 22:45:40 +02:00
|
|
|
esignal::Signal<bool> signalIsConnected;
|
2016-05-25 21:25:33 +02:00
|
|
|
ememory::SharedPtr<jus::GateWayService> m_userService;
|
2016-05-22 22:40:42 +02:00
|
|
|
std::vector<ememory::SharedPtr<jus::GateWayService>> m_listConnectedService;
|
2016-05-26 22:12:37 +02:00
|
|
|
uint64_t m_uid;
|
|
|
|
uint64_t m_uid2;
|
2016-05-22 23:15:09 +02:00
|
|
|
std::string m_userConnectionName;
|
2016-05-25 21:25:33 +02:00
|
|
|
std::string m_clientName;
|
|
|
|
std::vector<std::string> m_clientgroups;
|
|
|
|
std::mutex m_mutex;
|
|
|
|
std::vector<std::pair<int32_t, Observer>> m_actions;
|
|
|
|
int32_t m_transactionLocalId;
|
2016-05-12 22:45:40 +02:00
|
|
|
public:
|
2016-05-23 21:18:37 +02:00
|
|
|
GateWayClient(enet::Tcp _connection, jus::GateWay* _gatewayInterface);
|
2016-05-12 22:45:40 +02:00
|
|
|
virtual ~GateWayClient();
|
2016-05-26 22:12:37 +02:00
|
|
|
void start(uint64_t _uid, uint64_t _uid2);
|
2016-05-12 22:45:40 +02:00
|
|
|
void stop();
|
2016-05-24 23:00:56 +02:00
|
|
|
void onClientData(std::string _value);
|
2016-05-22 22:40:42 +02:00
|
|
|
void returnMessage(ejson::Object _data);
|
2016-05-26 22:12:37 +02:00
|
|
|
bool checkId(uint64_t _id) const {
|
|
|
|
return m_uid == _id
|
|
|
|
|| m_uid2 == _id;
|
2016-05-23 21:18:37 +02:00
|
|
|
}
|
2016-05-24 22:29:03 +02:00
|
|
|
bool isAlive();
|
2016-05-12 22:45:40 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|