diff --git a/zeus/Buffer.cpp b/zeus/Buffer.cpp index d32b083..7e4eab0 100644 --- a/zeus/Buffer.cpp +++ b/zeus/Buffer.cpp @@ -96,9 +96,11 @@ void zeus::Buffer::composeWith(const uint8_t* _buffer, uint32_t _lenght) { } void zeus::Buffer::clear() { - m_header.transactionID = 1; - m_header.clientID = 0; - m_header.serviceID = 0; + m_header.transactionId = 1; + m_header.sourceId = 0; + m_header.sourceObjectId = 0; + m_header.destinationId = 0; + m_header.destinationObjectId = 0; 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 _os << " if=" << etk::to_string(getInterfaceId()); _os << " tr-id=" << etk::to_string(getTransactionId()); - _os << " cId=" << etk::to_string(getClientId()); - _os << " sId=" << etk::to_string(getServiceId()); + _os << " src=" << etk::to_string(getSourceId()) << "/" << etk::to_string(getSourceObjectId()); + _os << " dst=" << etk::to_string(getDestinationId()) << "/" << etk::to_string(getDestinationObjectId()); if (getPartFinish() == true) { _os << " finish"; } @@ -150,28 +152,45 @@ uint32_t zeus::Buffer::getInterfaceId() const { void zeus::Buffer::setInterfaceId(uint32_t _value) { m_interfaceID = _value; } + uint32_t zeus::Buffer::getTransactionId() const { - return m_header.transactionID; + return m_header.transactionId; } -void zeus::Buffer::setTransactionId(uint32_t _value) { - m_header.transactionID = _value; +void zeus::Buffer::settransactionId(uint16_t _value) { + m_header.transactionId = _value; } -uint32_t zeus::Buffer::getClientId() const { - return m_header.clientID; +uint16_t zeus::Buffer::getSourceId() const { + return m_header.sourceId; } -void zeus::Buffer::setClientId(uint32_t _value) { - m_header.clientID = _value; +void zeus::Buffer::setSourceId(uint16_t _value) { + m_header.sourceId = _value; } -uint32_t zeus::Buffer::getServiceId() const { - return m_header.serviceID; +uint16_t zeus::Buffer::getSourceObjectId() const { + return m_header.sourceObjectId; } -void zeus::Buffer::setServiceId(uint32_t _value) { - m_header.serviceID = _value; +void zeus::Buffer::setSourceObjectId(uint16_t _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 { @@ -213,9 +232,11 @@ ememory::SharedPtr zeus::Buffer::create(const std::vector if (value == nullptr) { return nullptr; } - value->setTransactionId(header.transactionID); - value->setClientId(header.clientID); - value->setServiceId(header.serviceID); + value->settransactionId(header.transactionId); + value->setSourceId(header.sourceId); + value->setSourceOjectId(header.sourceObjectId); + value->setDestinationId(header.destinationId); + value->setDestinationObjectId(header.destinationObjectId); value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0); value->composeWith(&_buffer[sizeof(headerBin)], _buffer.size() - sizeof(headerBin)); @@ -227,9 +248,11 @@ ememory::SharedPtr zeus::Buffer::create(const std::vector if (value == nullptr) { return nullptr; } - value->setTransactionId(header.transactionID); - value->setClientId(header.clientID); - value->setServiceId(header.serviceID); + value->settransactionId(header.transactionId); + value->setSourceId(header.sourceId); + value->setSourceOjectId(header.sourceObjectId); + value->setDestinationId(header.destinationId); + value->setDestinationObjectId(header.destinationObjectId); value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0); value->composeWith(&_buffer[sizeof(headerBin)], _buffer.size() - sizeof(headerBin)); @@ -241,9 +264,11 @@ ememory::SharedPtr zeus::Buffer::create(const std::vector if (value == nullptr) { return nullptr; } - value->setTransactionId(header.transactionID); - value->setClientId(header.clientID); - value->setServiceId(header.serviceID); + value->settransactionId(header.transactionId); + value->setSourceId(header.sourceId); + value->setSourceOjectId(header.sourceObjectId); + value->setDestinationId(header.destinationId); + value->setDestinationObjectId(header.destinationObjectId); value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0); value->composeWith(&_buffer[sizeof(headerBin)], _buffer.size() - sizeof(headerBin)); @@ -255,9 +280,11 @@ ememory::SharedPtr zeus::Buffer::create(const std::vector if (value == nullptr) { return nullptr; } - value->setTransactionId(header.transactionID); - value->setClientId(header.clientID); - value->setServiceId(header.serviceID); + value->settransactionId(header.transactionId); + value->setSourceId(header.sourceId); + value->setSourceOjectId(header.sourceObjectId); + value->setDestinationId(header.destinationId); + value->setDestinationObjectId(header.destinationObjectId); value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0); value->composeWith(&_buffer[sizeof(headerBin)], _buffer.size() - sizeof(headerBin)); diff --git a/zeus/Buffer.hpp b/zeus/Buffer.hpp index 024270b..319129d 100644 --- a/zeus/Buffer.hpp +++ b/zeus/Buffer.hpp @@ -20,21 +20,13 @@ namespace zeus { class BufferData; //U32 message lenght #pragma pack(push,1) - /* struct headerBin { //uint16_t versionProtocol; // protocol Version (might be 1) - uint32_t transactionID; - uint32_t clientID; // same as sevice ID - int16_t partID; // if < 0 the partId ifs the last (start at 0 if multiple or 0x8000 if single message) - uint16_t typeMessage; //TypeMessgae (1:call, 2:Answer, 4:event) - uint16_t numberOfParameter; - }; - */ - 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 + uint32_t transactionId; //!< Transaction ID : Note the Upper byte is reserved for next protocol version (like change in protocol v2 with changing header) + uint16_t sourceId; //!< Source of the message + uint16_t sourceObjectId; //!< Source Object ID + uint16_t destinationId; //!< Destination of the message + uint16_t destinationObjectId; //!< Destination Object ID uint8_t flags; // List of flags & type message: // - 0-2: Type of the message // - 3-5: Reserved @@ -73,13 +65,13 @@ namespace zeus { [param 3] [param 4] --------------------------- - parameter and return value is contituated like : + parameter and return value is contituated like: TYPE,DATAs....(in raw) Type is write in ascii in the list end with '\0': - void - bool - - float - - double + - float32 + - float64 - int64 - int32 - int16 @@ -90,8 +82,8 @@ namespace zeus { - uint8 - string - vector:bool - - vector:float - - vector:double + - vector:float32 + - vector:float64 - vector:int64 - vector:int32 - vector:int16 @@ -102,6 +94,8 @@ namespace zeus { - vector:uint8 - vector:string - obj:file + - duration + - time */ #define ZEUS_BUFFER_FLAG_FINISH (0x80) #define ZEUS_BUFFER_FLAG_TYPE_MESSAGE (0x07) @@ -181,7 +175,7 @@ namespace zeus { /** * @brief Get the transaction identifier of the packet * @return value of the transaction - */ + */getTransactionId uint32_t getTransactionId() const; /** * @brief Set the transaction identifier of the packet @@ -189,25 +183,45 @@ namespace zeus { */ void setTransactionId(uint32_t _value); /** - * @brief Get the Client identifier of the packet - * @return Value of the Client identifier + * @brief Get the Source identifier of the packet + * @return Value of the Source identifier */ - uint32_t getClientId() const; + uint16_t getSourceId() const; /** - * @brief Set the Client identifier of the packet - * @param[in] _value New value of the Client identifier + * @brief Set the Source identifier of the packet + * @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) - * @return Value of the Service identifier + * @brief Get the Source Object identifier of the packet + * @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) - * @param[in] _value New value of the Service identifier + * @brief Set the Source Object identifier of the packet + * @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 * @return If "true" The Buffer wait no more datas diff --git a/zeus/Client.cpp b/zeus/Client.cpp index c6758d9..47e1315 100644 --- a/zeus/Client.cpp +++ b/zeus/Client.cpp @@ -24,6 +24,14 @@ void zeus::Client::onClientData(ememory::SharedPtr _value) { if (_value == nullptr) { 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); } @@ -88,7 +96,24 @@ bool zeus::Client::connectTo(const std::string& _address) { return true; } +bool zeus::Client::connect() { + bool ret = connectTo("srvIO"); + if (ret==false) { + return false; + } + zeus::Future 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) { + m_clientName = _address; bool ret = connectTo(_address); if (ret==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) { + m_clientName = _address; bool ret = connectTo(_address); if (ret==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) { + m_clientName = _clientName; bool ret = connectTo(_address); if (ret==false) { return false; diff --git a/zeus/Client.hpp b/zeus/Client.hpp index d2af713..3129cf8 100644 --- a/zeus/Client.hpp +++ b/zeus/Client.hpp @@ -23,24 +23,11 @@ namespace zeus { eproperty::Value propertyIp; //!< Ip of WebSocket TCP connection eproperty::Value propertyPort; //!< Port of the WebSocket connection private: + std::string m_clientName; //!< Local client name to generate the local serrvice name if needed (if direct connection ==> no name) ememory::SharedPtr m_interfaceClient; //!< Interface on the Websocket interface std::vector> m_listConnectedService; //!< Connect only one time on each service, not needed more. + std::vector> m_listProvicedService; //!< Connect only one time on each service, not needed more. 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 * @param[in] @@ -60,6 +47,11 @@ namespace zeus { */ bool connectTo(const std::string& _address); 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 * @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 */ 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& _service); private: /** * @brief When receive data from the websocket ... call this ... @@ -102,6 +101,7 @@ namespace zeus { * @param[in] _args... multiple argument neededs * @return a future that will contain the aswer when receiveed (need to transmit over ethernet) */ + /* template zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) { if (m_interfaceClient == nullptr) { @@ -111,6 +111,7 @@ namespace zeus { } return m_interfaceClient->call(ZEUS_NO_ID_CLIENT, ZEUS_ID_SERVICE_ROOT, _functionName, _args...); } + */ private: /** * @brief Internal (called when user change the Ip of the client interface)