[DEV] change think of the interface to have the capabilities to have object/service/structure and provide it as a client

This commit is contained in:
Edouard DUPIN 2016-11-29 00:33:31 +01:00
parent 42e6f1da59
commit be919abb1e
4 changed files with 143 additions and 74 deletions

View File

@ -96,9 +96,11 @@ void zeus::Buffer::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
} }
void zeus::Buffer::clear() { void zeus::Buffer::clear() {
m_header.transactionID = 1; m_header.transactionId = 1;
m_header.clientID = 0; m_header.sourceId = 0;
m_header.serviceID = 0; m_header.sourceObjectId = 0;
m_header.destinationId = 0;
m_header.destinationObjectId = 0;
m_header.flags = ZEUS_BUFFER_FLAG_FINISH; m_header.flags = ZEUS_BUFFER_FLAG_FINISH;
} }
@ -115,8 +117,8 @@ void zeus::Buffer::generateDisplay(std::ostream& _os) const {
//out += " v=" + etk::to_string(m_header.versionProtocol); // set it in the websocket //out += " v=" + etk::to_string(m_header.versionProtocol); // set it in the websocket
_os << " if=" << etk::to_string(getInterfaceId()); _os << " if=" << etk::to_string(getInterfaceId());
_os << " tr-id=" << etk::to_string(getTransactionId()); _os << " tr-id=" << etk::to_string(getTransactionId());
_os << " cId=" << etk::to_string(getClientId()); _os << " src=" << etk::to_string(getSourceId()) << "/" << etk::to_string(getSourceObjectId());
_os << " sId=" << etk::to_string(getServiceId()); _os << " dst=" << etk::to_string(getDestinationId()) << "/" << etk::to_string(getDestinationObjectId());
if (getPartFinish() == true) { if (getPartFinish() == true) {
_os << " finish"; _os << " finish";
} }
@ -150,28 +152,45 @@ uint32_t zeus::Buffer::getInterfaceId() const {
void zeus::Buffer::setInterfaceId(uint32_t _value) { void zeus::Buffer::setInterfaceId(uint32_t _value) {
m_interfaceID = _value; m_interfaceID = _value;
} }
uint32_t zeus::Buffer::getTransactionId() const { uint32_t zeus::Buffer::getTransactionId() const {
return m_header.transactionID; return m_header.transactionId;
} }
void zeus::Buffer::setTransactionId(uint32_t _value) { void zeus::Buffer::settransactionId(uint16_t _value) {
m_header.transactionID = _value; m_header.transactionId = _value;
} }
uint32_t zeus::Buffer::getClientId() const { uint16_t zeus::Buffer::getSourceId() const {
return m_header.clientID; return m_header.sourceId;
} }
void zeus::Buffer::setClientId(uint32_t _value) { void zeus::Buffer::setSourceId(uint16_t _value) {
m_header.clientID = _value; m_header.sourceId = _value;
} }
uint32_t zeus::Buffer::getServiceId() const { uint16_t zeus::Buffer::getSourceObjectId() const {
return m_header.serviceID; return m_header.sourceObjectId;
} }
void zeus::Buffer::setServiceId(uint32_t _value) { void zeus::Buffer::setSourceObjectId(uint16_t _value) {
m_header.serviceID = _value; m_header.sourceObjectId = _value;
}
uint16_t zeus::Buffer::getDestinationId() const {
return m_header.destinationId;
}
void zeus::Buffer::setDestinationId(uint32_t _value) {
m_header.destinationId = _value;
}
uint16_t zeus::Buffer::getDestinationObjectId() const {
return m_header.destinationObjectId;
}
void zeus::Buffer::setDestinationObjectId(uint16_t _value) {
m_header.destinationObjectId = _value;
} }
bool zeus::Buffer::getPartFinish() const { bool zeus::Buffer::getPartFinish() const {
@ -213,9 +232,11 @@ ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(const std::vector<uint8_t>
if (value == nullptr) { if (value == nullptr) {
return nullptr; return nullptr;
} }
value->setTransactionId(header.transactionID); value->settransactionId(header.transactionId);
value->setClientId(header.clientID); value->setSourceId(header.sourceId);
value->setServiceId(header.serviceID); value->setSourceOjectId(header.sourceObjectId);
value->setDestinationId(header.destinationId);
value->setDestinationObjectId(header.destinationObjectId);
value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0); value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0);
value->composeWith(&_buffer[sizeof(headerBin)], value->composeWith(&_buffer[sizeof(headerBin)],
_buffer.size() - sizeof(headerBin)); _buffer.size() - sizeof(headerBin));
@ -227,9 +248,11 @@ ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(const std::vector<uint8_t>
if (value == nullptr) { if (value == nullptr) {
return nullptr; return nullptr;
} }
value->setTransactionId(header.transactionID); value->settransactionId(header.transactionId);
value->setClientId(header.clientID); value->setSourceId(header.sourceId);
value->setServiceId(header.serviceID); value->setSourceOjectId(header.sourceObjectId);
value->setDestinationId(header.destinationId);
value->setDestinationObjectId(header.destinationObjectId);
value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0); value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0);
value->composeWith(&_buffer[sizeof(headerBin)], value->composeWith(&_buffer[sizeof(headerBin)],
_buffer.size() - sizeof(headerBin)); _buffer.size() - sizeof(headerBin));
@ -241,9 +264,11 @@ ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(const std::vector<uint8_t>
if (value == nullptr) { if (value == nullptr) {
return nullptr; return nullptr;
} }
value->setTransactionId(header.transactionID); value->settransactionId(header.transactionId);
value->setClientId(header.clientID); value->setSourceId(header.sourceId);
value->setServiceId(header.serviceID); value->setSourceOjectId(header.sourceObjectId);
value->setDestinationId(header.destinationId);
value->setDestinationObjectId(header.destinationObjectId);
value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0); value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0);
value->composeWith(&_buffer[sizeof(headerBin)], value->composeWith(&_buffer[sizeof(headerBin)],
_buffer.size() - sizeof(headerBin)); _buffer.size() - sizeof(headerBin));
@ -255,9 +280,11 @@ ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(const std::vector<uint8_t>
if (value == nullptr) { if (value == nullptr) {
return nullptr; return nullptr;
} }
value->setTransactionId(header.transactionID); value->settransactionId(header.transactionId);
value->setClientId(header.clientID); value->setSourceId(header.sourceId);
value->setServiceId(header.serviceID); value->setSourceOjectId(header.sourceObjectId);
value->setDestinationId(header.destinationId);
value->setDestinationObjectId(header.destinationObjectId);
value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0); value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0);
value->composeWith(&_buffer[sizeof(headerBin)], value->composeWith(&_buffer[sizeof(headerBin)],
_buffer.size() - sizeof(headerBin)); _buffer.size() - sizeof(headerBin));

View File

@ -20,21 +20,13 @@ namespace zeus {
class BufferData; class BufferData;
//U32 message lenght //U32 message lenght
#pragma pack(push,1) #pragma pack(push,1)
/*
struct headerBin { struct headerBin {
//uint16_t versionProtocol; // protocol Version (might be 1) //uint16_t versionProtocol; // protocol Version (might be 1)
uint32_t transactionID; uint32_t transactionId; //!< Transaction ID : Note the Upper byte is reserved for next protocol version (like change in protocol v2 with changing header)
uint32_t clientID; // same as sevice ID uint16_t sourceId; //!< Source of the message
int16_t partID; // if < 0 the partId ifs the last (start at 0 if multiple or 0x8000 if single message) uint16_t sourceObjectId; //!< Source Object ID
uint16_t typeMessage; //TypeMessgae (1:call, 2:Answer, 4:event) uint16_t destinationId; //!< Destination of the message
uint16_t numberOfParameter; uint16_t destinationObjectId; //!< Destination Object ID
};
*/
struct headerBin {
//uint16_t versionProtocol; // protocol Version (might be 1)
uint32_t transactionID;
uint32_t clientID; // Client Routing ID
uint32_t serviceID; // service routing ID
uint8_t flags; // List of flags & type message: uint8_t flags; // List of flags & type message:
// - 0-2: Type of the message // - 0-2: Type of the message
// - 3-5: Reserved // - 3-5: Reserved
@ -78,8 +70,8 @@ namespace zeus {
Type is write in ascii in the list end with '\0': Type is write in ascii in the list end with '\0':
- void - void
- bool - bool
- float - float32
- double - float64
- int64 - int64
- int32 - int32
- int16 - int16
@ -90,8 +82,8 @@ namespace zeus {
- uint8 - uint8
- string - string
- vector:bool - vector:bool
- vector:float - vector:float32
- vector:double - vector:float64
- vector:int64 - vector:int64
- vector:int32 - vector:int32
- vector:int16 - vector:int16
@ -102,6 +94,8 @@ namespace zeus {
- vector:uint8 - vector:uint8
- vector:string - vector:string
- obj:file - obj:file
- duration
- time
*/ */
#define ZEUS_BUFFER_FLAG_FINISH (0x80) #define ZEUS_BUFFER_FLAG_FINISH (0x80)
#define ZEUS_BUFFER_FLAG_TYPE_MESSAGE (0x07) #define ZEUS_BUFFER_FLAG_TYPE_MESSAGE (0x07)
@ -181,7 +175,7 @@ namespace zeus {
/** /**
* @brief Get the transaction identifier of the packet * @brief Get the transaction identifier of the packet
* @return value of the transaction * @return value of the transaction
*/ */getTransactionId
uint32_t getTransactionId() const; uint32_t getTransactionId() const;
/** /**
* @brief Set the transaction identifier of the packet * @brief Set the transaction identifier of the packet
@ -189,25 +183,45 @@ namespace zeus {
*/ */
void setTransactionId(uint32_t _value); void setTransactionId(uint32_t _value);
/** /**
* @brief Get the Client identifier of the packet * @brief Get the Source identifier of the packet
* @return Value of the Client identifier * @return Value of the Source identifier
*/ */
uint32_t getClientId() const; uint16_t getSourceId() const;
/** /**
* @brief Set the Client identifier of the packet * @brief Set the Source identifier of the packet
* @param[in] _value New value of the Client identifier * @param[in] _value New value of the Source identifier
*/ */
void setClientId(uint32_t _value); void setSourceId(uint16_t _value);
/** /**
* @brief Get the Service identifier of the packet (same as client) * @brief Get the Source Object identifier of the packet
* @return Value of the Service identifier * @return Value of the Source Object identifier
*/ */
uint32_t getServiceId() const; uint16_t getSourceObjectId() const;
/** /**
* @brief Set the Service identifier of the packet (same as client) * @brief Set the Source Object identifier of the packet
* @param[in] _value New value of the Service identifier * @param[in] _value New value of the Source Object identifier
*/ */
void setServiceId(uint32_t _value); void setSourceObjectId(uint16_t _value);
/**
* @brief Get the Destination identifier of the packet
* @return Value of the Destination identifier
*/
uint16_t getDestinationId() const;
/**
* @brief Set the Destination identifier of the packet
* @param[in] _value New value of the Destination identifier
*/
void setDestinationId(uint16_t _value);
/**
* @brief Get the Destination Object identifier of the packet
* @return Value of the Destination Object identifier
*/
uint16_t getDestinationObjectId() const;
/**
* @brief Set the Destination Object identifier of the packet
* @param[in] _value New value of the Destination Object identifier
*/
void setDestinationObjectId(uint16_t _value);
/** /**
* @brief Check if it is the last packet of the buffer * @brief Check if it is the last packet of the buffer
* @return If "true" The Buffer wait no more datas * @return If "true" The Buffer wait no more datas

View File

@ -24,6 +24,14 @@ void zeus::Client::onClientData(ememory::SharedPtr<zeus::Buffer> _value) {
if (_value == nullptr) { if (_value == nullptr) {
return; return;
} }
// TODO : We will receive here some notification and call ...like :
if (call && id = 0 && objectid == 0) {
we will have :
if call == "ValidateConnection"
in param : local interface ID (can not change it...)
local name like clientname::subID (if multiple connection in parallele)
... and after we can do many thing like provide servies ...
}
ZEUS_ERROR("Get Data On the Communication interface that is not understand ... : " << _value); ZEUS_ERROR("Get Data On the Communication interface that is not understand ... : " << _value);
} }
@ -88,7 +96,24 @@ bool zeus::Client::connectTo(const std::string& _address) {
return true; return true;
} }
bool zeus::Client::connect() {
bool ret = connectTo("srvIO");
if (ret==false) {
return false;
}
zeus::Future<bool> retIdentify = call("anonymous").wait();
if (retIdentify.hasError() == true) {
disconnect();
return false;
}
if (retIdentify.get() == false) {
disconnect();
}
return retIdentify.get();
}
bool zeus::Client::connect(const std::string& _address) { bool zeus::Client::connect(const std::string& _address) {
m_clientName = _address;
bool ret = connectTo(_address); bool ret = connectTo(_address);
if (ret==false) { if (ret==false) {
return false; return false;
@ -105,6 +130,7 @@ bool zeus::Client::connect(const std::string& _address) {
} }
bool zeus::Client::connect(const std::string& _address, const std::string& _userPassword) { bool zeus::Client::connect(const std::string& _address, const std::string& _userPassword) {
m_clientName = _address;
bool ret = connectTo(_address); bool ret = connectTo(_address);
if (ret==false) { if (ret==false) {
return false; return false;
@ -121,6 +147,7 @@ bool zeus::Client::connect(const std::string& _address, const std::string& _user
} }
bool zeus::Client::connect(const std::string& _address, const std::string& _clientName, const std::string& _clientTocken) { bool zeus::Client::connect(const std::string& _address, const std::string& _clientName, const std::string& _clientTocken) {
m_clientName = _clientName;
bool ret = connectTo(_address); bool ret = connectTo(_address);
if (ret==false) { if (ret==false) {
return false; return false;

View File

@ -23,24 +23,11 @@ namespace zeus {
eproperty::Value<std::string> propertyIp; //!< Ip of WebSocket TCP connection eproperty::Value<std::string> propertyIp; //!< Ip of WebSocket TCP connection
eproperty::Value<uint16_t> propertyPort; //!< Port of the WebSocket connection eproperty::Value<uint16_t> propertyPort; //!< Port of the WebSocket connection
private: private:
std::string m_clientName; //!< Local client name to generate the local serrvice name if needed (if direct connection ==> no name)
ememory::SharedPtr<zeus::WebServer> m_interfaceClient; //!< Interface on the Websocket interface ememory::SharedPtr<zeus::WebServer> m_interfaceClient; //!< Interface on the Websocket interface
std::vector<ememory::WeakPtr<zeus::ServiceRemoteBase>> m_listConnectedService; //!< Connect only one time on each service, not needed more. std::vector<ememory::WeakPtr<zeus::ServiceRemoteBase>> m_listConnectedService; //!< Connect only one time on each service, not needed more.
std::vector<ememory::SharedPtr<zeus::Service>> m_listProvicedService; //!< Connect only one time on each service, not needed more.
public: public:
/**
* @brief Create a client on a specific user in a client mode with the tocken associated
* @param[in] _address Address of the user: "ABCD.efgh#atria-soft.com:1993"
* @param[in]
* @param[in]
*/
//Client(const std::string& _address, const std::string& _clientName, const std::string& _clientTocken);
/**
* @brief Create a client on a specific user in a user mode (connect to your personnal account)
* @param[in] _address Address of the user: "ABCD.efgh#atria-soft.com:1993"
* @param[in] _userPassword Password of the user
*/
//Client(const std::string& _address, const std::string& _userPassword);
//Client(const std::string& _address);
/** /**
* @brief * @brief
* @param[in] * @param[in]
@ -60,6 +47,11 @@ namespace zeus {
*/ */
bool connectTo(const std::string& _address); bool connectTo(const std::string& _address);
public: public:
/**
* @brief Direct connection on a GateWay No Identification needed, the Port on the Gateway garenty the connection)
* @note This is exclusively reserve for server service provicers
*/
bool connect();
/** /**
* @brief Create a client on a specific user in an ANONIMOUS way * @brief Create a client on a specific user in an ANONIMOUS way
* @param[in] _address Address of the user: "ABCD.efgh~atria-soft.com:1993" * @param[in] _address Address of the user: "ABCD.efgh~atria-soft.com:1993"
@ -89,6 +81,13 @@ namespace zeus {
* @return Pointer on an interface of remote service * @return Pointer on an interface of remote service
*/ */
zeus::ServiceRemote getService(const std::string& _serviceName); zeus::ServiceRemote getService(const std::string& _serviceName);
/**
* @brief Provide a service with a specific name
* @param[in] _serviceName Name of the service
* @param[in] _service handle on the service provided
* @return true if the service is acepted or false if not
*/
bool provideService(const std::string& _serviceName, ememory::SharedPtr<zeus::Service>& _service);
private: private:
/** /**
* @brief When receive data from the websocket ... call this ... * @brief When receive data from the websocket ... call this ...
@ -102,6 +101,7 @@ namespace zeus {
* @param[in] _args... multiple argument neededs * @param[in] _args... multiple argument neededs
* @return a future that will contain the aswer when receiveed (need to transmit over ethernet) * @return a future that will contain the aswer when receiveed (need to transmit over ethernet)
*/ */
/*
template<class... _ARGS> template<class... _ARGS>
zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) { zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) {
if (m_interfaceClient == nullptr) { if (m_interfaceClient == nullptr) {
@ -111,6 +111,7 @@ namespace zeus {
} }
return m_interfaceClient->call(ZEUS_NO_ID_CLIENT, ZEUS_ID_SERVICE_ROOT, _functionName, _args...); return m_interfaceClient->call(ZEUS_NO_ID_CLIENT, ZEUS_ID_SERVICE_ROOT, _functionName, _args...);
} }
*/
private: private:
/** /**
* @brief Internal (called when user change the Ip of the client interface) * @brief Internal (called when user change the Ip of the client interface)