diff options
author | Conlain Kelly <conlain.k@gmail.com> | 2018-07-18 13:11:19 -0400 |
---|---|---|
committer | Conlain Kelly <conlain.k@gmail.com> | 2018-07-18 13:11:25 -0400 |
commit | e380ed1779e4317437cea63f070a8345b41f2d33 (patch) | |
tree | b2d6669663b91a3f235c2ce4a00c0c888751ff20 /src/components/dbus/include/dbus | |
parent | 09c941dd2ffd4f98ba706895a67133318c3c5007 (diff) | |
parent | 4f21cbafb247664bd7b89bf2d39944764b1763b1 (diff) | |
download | sdl_core-e380ed1779e4317437cea63f070a8345b41f2d33.tar.gz |
Merge branch 'develop' into feature/boost_lock_implementation
Diffstat (limited to 'src/components/dbus/include/dbus')
-rw-r--r-- | src/components/dbus/include/dbus/dbus_adapter.h | 375 | ||||
-rw-r--r-- | src/components/dbus/include/dbus/dbus_message.h | 179 | ||||
-rw-r--r-- | src/components/dbus/include/dbus/dbus_message_controller.h | 97 | ||||
-rw-r--r-- | src/components/dbus/include/dbus/dbus_message_inl.h | 214 | ||||
-rw-r--r-- | src/components/dbus/include/dbus/message_descriptions.h | 73 | ||||
-rw-r--r-- | src/components/dbus/include/dbus/schema.h | 98 |
6 files changed, 0 insertions, 1036 deletions
diff --git a/src/components/dbus/include/dbus/dbus_adapter.h b/src/components/dbus/include/dbus/dbus_adapter.h deleted file mode 100644 index 42a2ac1140..0000000000 --- a/src/components/dbus/include/dbus/dbus_adapter.h +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Copyright (c) 2013-2014, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef SRC_COMPONENTS_DBUS_INCLUDE_DBUS_DBUS_ADAPTER_H_ -#define SRC_COMPONENTS_DBUS_INCLUDE_DBUS_DBUS_ADAPTER_H_ - -#include <string> -#include "smart_objects/smart_object.h" -#include "dbus/schema.h" -#include "dbus/message_descriptions.h" - -struct DBusConnection; -struct DBusMessage; -struct DBusMessageIter; - -namespace dbus { - -/** - * \brief class for work with DBus - */ -class DBusAdapter { - public: - /** - * \brief constructs DBus adapter - * \param sdlServiceName core service name - * \param sdlObjectPath core object path - * \param hmiServiceName hmi service name - */ - DBusAdapter(const std::string& sdlServiceName, - const std::string& sdlObjectPath, - const std::string& hmiServiceName, - const std::string& hmiObjectPath); - - /** - * \brief destructs DBus adapter - */ - virtual ~DBusAdapter(); - - /** - * \brief inits service - * \return true if success - */ - bool Init(); - - /** - * \brief return schema messages for DBus - * \return schema - */ - const DBusSchema& get_schema() const; - - protected: - /** - * \brief calls method on HMI - * \param id id message - * \param func_id id function in Ford protocol - * \param name pair interface and name of method for call - * \param obj params for call - */ - void MethodCall(uint id, - const MessageId func_id, - const MessageName& name, - const smart_objects::SmartObject& obj); - - /** - * \brief sends signal - * \param id id message - * \param func_id id function in Ford protocol - * \param name pair interface and name of signal for call - * \param obj params for signal - */ - void Signal(const MessageId func_id, - const MessageName& name, - const smart_objects::SmartObject& obj); - - /** - * \brief returns result of call method to HMI - * \param id id message - * \param obj params for return - */ - void MethodReturn(uint id, - const MessageId func_id, - const MessageName& name, - const smart_objects::SmartObject& obj); - - /** - * \brief sends error on message from HMI - * \param id id message - * \param msg message from HMI - * \param name name of error - * \param description description of error - */ - void Error(uint id, const std::string& name, const std::string& description); - - /** - * \brief adds a match rule - * \param rule string rule in the DBus specification - */ - void AddMatch(const std::string& rule); - - /** - * \brief processes incoming message from DBus if queue isn't empty - * and fill obj - * \param obj object for send to core - * \return true if message processed - */ - bool Process(smart_objects::SmartObject& obj); - - /** - * \brief saves link D-Bus serial to Ford message id - * \param serial D-Bus message serial - * \param ids pair correlation id and Ford message id - */ - inline void SaveRequestToHMI(uint32_t serial, - const std::pair<uint, MessageId>& ids); - - /** - * \brief gets Ford message id by serial - * \param serial D-Bus message serial - * \return pair correlation id and Ford message id - */ - inline std::pair<uint, MessageId> GetRequestToHMI(uint32_t serial); - - /** - * \brief saves link D-Bus serial to Ford message id - * \param serial D-Bus message serial - * \param request D-Bus message from HMI - */ - inline void SaveRequestFromHMI(uint32_t serial, DBusMessage* request); - - /** - * \brief gets D-Bus message id by serial - * \param serial DBus message serial - * \return D-Bus message from HMI - */ - inline DBusMessage* GetRequestFromHMI(uint32_t serial); - - std::string sdl_service_name_; - std::string sdl_object_path_; - std::string hmi_service_name_; - std::string hmi_object_path_; - DBusConnection* conn_; - - private: - /** - * \brief schema messages and arguments for DBus - */ - const DBusSchema* schema_; - - /** - * \brief mapping serial message DBus on message id Ford protocol - */ - std::map<uint32_t, std::pair<uint, MessageId> > requests_to_hmi_; - - /** - * \brief mapping message id Ford protocol on message DBus - */ - std::map<uint32_t, DBusMessage*> requests_from_hmi_; - - /** - * \brief processes incoming call of method and fill obj - * \param msg message from DBus - * \param obj object for send to core - * \return true if success - */ - bool ProcessMethodCall(DBusMessage* msg, smart_objects::SmartObject& obj); - - /** - * \brief processes incoming return of method and fill obj - * \param msg message from DBus - * \param obj object for send to core - * \return true if success - */ - bool ProcessMethodReturn(DBusMessage* msg, smart_objects::SmartObject& obj); - - /** - * \brief processes incoming error and fill obj - * \param msg message from DBus - * \param obj object for send to core - * \return true if success - */ - bool ProcessError(DBusMessage* msg, smart_objects::SmartObject& obj); - - /** - * \brief processes incoming signal and fill obj - * \param msg message from DBus - * \param obj object for send to core - * \return true if success - */ - bool ProcessSignal(DBusMessage* msg, smart_objects::SmartObject& obj); - - /** - * \brief sets arguments to message - * \param msg DBus message - * \param rules list of rules for arguments - * \param args map of arguments - * \return true if success - */ - bool SetArguments(DBusMessage* msg, - const ListArgs& rules, - const smart_objects::SmartObject& args); - - /** - * \brief Sets one argument to message - * \param iter DBus message iterator - * \param rules description for argument - * \param param value of argument - * \return true if success - */ - bool SetOneArgument( - DBusMessageIter* iter, - const ford_message_descriptions::ParameterDescription* rules, - const smart_objects::SmartObject& param); - - /** - * \brief sets value for argument - * \param iter DBus message iterator - * \param rules description for argument - * \param param value of argument - * \return true if success - */ - bool SetValue(DBusMessageIter* iter, - const ford_message_descriptions::ParameterDescription* rules, - const smart_objects::SmartObject& param); - - /** - * \brief sets value for every element of argument - * \param iter DBus message iterator - * \param rules description for argument - * \param param array values of argument - * \return true if success - */ - bool SetArrayValue(DBusMessageIter* iter, - const ford_message_descriptions::ArrayDescription* rules, - const smart_objects::SmartObject& param); - - /** - * \brief sets struct value for argument - * \param iter DBus message iter - * \param rules description for argument - * \param param structure - * \return true if success - */ - bool SetStructValue(DBusMessageIter* iter, - const ford_message_descriptions::StructDescription* rules, - const smart_objects::SmartObject& param); - - /** - * \brief sets optional value for argument. - * Optional param is struct bool, value - * \param iter DBus message iterator - * \param rules description for argument - * \param param value of optional argument - * \return true if success - */ - bool SetOptionalValue( - DBusMessageIter* iter, - const ford_message_descriptions::ParameterDescription* rules, - const smart_objects::SmartObject& param); - - /** - * \brief gets arguments from message - * \param iter DBus message iterator - * \param code response code (output) - * \param message response message (output) - * \return true if success - */ - bool GetHeader(DBusMessageIter* iter, int* code, std::string* message); - - /** - * \brief gets arguments from message with header - * \param iter DBus message iterator - * \param rules list of rules for arguments - * \param args map of arguments - * \return true if success - */ - bool GetArguments(DBusMessageIter* iter, - const ListArgs& rules, - smart_objects::SmartObject& args); - - /** - * \brief gets one argument from message - * \param iter DBus message iterator - * \param rules description for argument - * \param args map of arguments - * \return true if success - */ - bool GetOneArgument( - DBusMessageIter* iter, - const ford_message_descriptions::ParameterDescription* rules, - smart_objects::SmartObject& args); - - /** - * \brief gets value for argument - * \param iter DBus message iterator - * \param rules description for argument - * \param param value of argument - * \return true if success - */ - bool GetValue(DBusMessageIter* iter, - const ford_message_descriptions::ParameterDescription* rules, - smart_objects::SmartObject& param); - - /** - * \brief gets value for every element of argument - * \param iter DBus message iterator - * \param rules description for argument - * \param param array values of argument - * \return true if success - */ - bool GetArrayValue(DBusMessageIter* iter, - const ford_message_descriptions::ArrayDescription* rules, - smart_objects::SmartObject& param); - - /** - * \brief gets struct value for argument - * \param iter DBus message iterator - * \param rules description for argument - * \param param structure - * \return true if success - */ - bool GetStructValue(DBusMessageIter* iter, - const ford_message_descriptions::StructDescription* rules, - smart_objects::SmartObject& param); - - /** - * \brief gets optional value for argument. - * Optional param is struct bool, value - * \param iter DBus message iterator - * \param rules description for argument - * \param param value of optional argument - * \return true if success - */ - bool GetOptionalValue( - DBusMessageIter* iter, - const ford_message_descriptions::ParameterDescription* rules, - smart_objects::SmartObject& param); - - /** - * \brief processes request on introspect - * \param msg DBus message - */ - void Introspect(DBusMessage* msg); -}; - -} // namespace dbus - -#endif // SRC_COMPONENTS_DBUS_INCLUDE_DBUS_DBUS_ADAPTER_H_ diff --git a/src/components/dbus/include/dbus/dbus_message.h b/src/components/dbus/include/dbus/dbus_message.h deleted file mode 100644 index 23e672d0fc..0000000000 --- a/src/components/dbus/include/dbus/dbus_message.h +++ /dev/null @@ -1,179 +0,0 @@ -/* Copyright (c) 2014, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SRC_COMPONENTS_DBUS_INCLUDE_DBUS_DBUS_MESSAGE_H_ -#define SRC_COMPONENTS_DBUS_INCLUDE_DBUS_DBUS_MESSAGE_H_ - -#include <stdint.h> -#include <string> - -#include <dbus/dbus.h> - -namespace dbus { - -enum ContainerType { - kArray = DBUS_TYPE_ARRAY, - kStruct = DBUS_TYPE_STRUCT, - kDictEntry = DBUS_TYPE_DICT_ENTRY -}; - -class MessageRefKeeper { - public: - MessageRefKeeper(); - MessageRefKeeper(DBusMessage* message); - ~MessageRefKeeper(); - MessageRefKeeper(const MessageRefKeeper& other); - MessageRefKeeper& operator=(MessageRefKeeper other); - DBusMessage* get() const; - DBusMessage* Pass(); - void swap(MessageRefKeeper& other); - - private: - DBusMessage* raw_message_; -}; - -class MessageRef { - public: - MessageRef(DBusMessage* message); - ~MessageRef(); - std::string GetInterface() const; - std::string GetMember() const; - - protected: - MessageRefKeeper raw_message_ref_; - friend class MessageReader; - friend class MessageWriter; -}; - -class MessageReader { - public: - // Main constructor - MessageReader(const MessageRef& message); - bool has_failed() const; - bool IsAtLastElement() const; - bool HasNext() const; - - // Type checkers - bool NextIsInvalid() const; - bool NextIsBool() const; - bool NextIsByte() const; - bool NextIsInt16() const; - bool NextIsUint16() const; - bool NextIsInt32() const; - bool NextIsUint32() const; - bool NextIsInt64() const; - bool NextIsUint64() const; - bool NextIsDouble() const; - bool NextIsString() const; - bool NextIsArray() const; - bool NextIsStruct() const; - bool NextIsDictEntry() const; - - // Readers - bool TakeBool(); - uint8_t TakeByte(); - int16_t TakeInt16(); - uint16_t TakeUint16(); - int32_t TakeInt32(); - uint32_t TakeUint32(); - int64_t TakeInt64(); - uint64_t TakeUint64(); - double TakeDouble(); - std::string TakeString(); - - MessageReader TakeArrayReader(); - MessageReader TakeStructReader(); - MessageReader TakeDictEntryReader(); - - private: - typedef int DataType; - // Container reader constructor - MessageReader(MessageReader* reader, DataType container_data_type); - void MoveToNext(); - void MarkFailed(); - DataType NextValueType() const; - void ReadNextValue(DataType type, void* value); - - private: - // Fields - MessageReader* parent_reader_; - bool failed_; - DBusMessageIter iterator_; -}; - -class MessageWriter { - public: - // Methods - // Main appending constructor - MessageWriter(const MessageRef& message); - // Container writer constructor - MessageWriter(MessageWriter* parent, - ContainerType type, - const char* array_signature); - ~MessageWriter(); - void PutBool(bool value); - void PutByte(uint8_t value); - void PutInt16(int16_t value); - void PutUint16(uint16_t value); - void PutInt32(int32_t value); - void PutUint32(uint32_t value); - void PutInt64(int64_t value); - void PutUint64(uint64_t value); - void PutDouble(double value); - void PutString(const std::string& value); - - private: - typedef int DataType; - // Main constructor - void WriteAndCheck(DataType value_type, const void* value); - void CloseWriter(); - - private: - // Fields - bool has_opened_subcontainer_; - MessageWriter* parent_writer_; - DBusMessageIter iterator_; - - // Disallow copy and assign - MessageWriter(const MessageWriter& other); - MessageWriter& operator=(const MessageWriter& other); -}; - -MessageRef MethodCall(const char* bus_name, - const char* path, - const char* interface, - const char* method); -MessageRef Signal(const char* path, const char* interface, const char* name); -} // namespace dbus - -#include "dbus/dbus_message_inl.h" - -#endif // SRC_COMPONENTS_DBUS_INCLUDE_DBUS_DBUS_MESSAGE_H_ diff --git a/src/components/dbus/include/dbus/dbus_message_controller.h b/src/components/dbus/include/dbus/dbus_message_controller.h deleted file mode 100644 index a4a3718ce3..0000000000 --- a/src/components/dbus/include/dbus/dbus_message_controller.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2013, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SRC_COMPONENTS_DBUS_INCLUDE_DBUS_DBUS_MESSAGE_CONTROLLER_H_ -#define SRC_COMPONENTS_DBUS_INCLUDE_DBUS_DBUS_MESSAGE_CONTROLLER_H_ - -#include <string> -#include <map> -#include "dbus/dbus_adapter.h" -#include "smart_objects/smart_object.h" - -namespace dbus { - -class DBusMessageController : public DBusAdapter { - public: - /** - * @brief constructs DBus message controller - * @param sdlServiceName name of service SDL - * @param sdlObjectPath path of object SDL - * @param hmiServiceName name of service HMI - * @param hmiObjectPath path of object HMI - */ - DBusMessageController(const std::string& sdlServiceName, - const std::string& sdlObjectPath, - const std::string& hmiServiceName, - const std::string& hmiObjectPath); - - /** - * @brief destructs DBus message controller - */ - virtual ~DBusMessageController(); - - /** - * @brief subscribes to the DBus signal. - * @param interface name of interface in HMI - * @param signal name of signal - */ - void SubscribeTo(const std::string& interface, const std::string& signal); - - /** - * @brief Method for receiving thread. - */ - void* MethodForReceiverThread(void*); - - /** - * @brief Main thread loop. - */ - bool Run(); - - /** - * @brief Signal shutdown for thread loop. - */ - void Shutdown(); - - protected: - /** - * @brief sends message to core - * @param obj - */ - virtual void SendMessageToCore(const smart_objects::SmartObject& obj) = 0; - - private: - bool shutdown_; -}; - -} // namespace dbus - -#endif // SRC_COMPONENTS_DBUS_INCLUDE_DBUS_DBUS_MESSAGE_CONTROLLER_H_ diff --git a/src/components/dbus/include/dbus/dbus_message_inl.h b/src/components/dbus/include/dbus/dbus_message_inl.h deleted file mode 100644 index ba9bfaa78d..0000000000 --- a/src/components/dbus/include/dbus/dbus_message_inl.h +++ /dev/null @@ -1,214 +0,0 @@ -/* Copyright (c) 2014, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SRC_COMPONENTS_DBUS_INCLUDE_DBUS_DBUS_MESSAGE_INL_H_ -#define SRC_COMPONENTS_DBUS_INCLUDE_DBUS_DBUS_MESSAGE_INL_H_ - -#include "dbus/dbus_message.h" - -namespace dbus { -// MessageReader -inline bool MessageReader::has_failed() const { - return failed_; -} - -inline bool MessageReader::IsAtLastElement() const { - DBusMessageIter* iter = const_cast<DBusMessageIter*>(&iterator_); - return dbus_message_iter_has_next(iter) == 0; -} - -inline bool MessageReader::HasNext() const { - return !failed_ && NextValueType() != DBUS_TYPE_INVALID; -} - -inline bool MessageReader::NextIsInvalid() const { - return NextValueType() == DBUS_TYPE_INVALID; -} - -inline bool MessageReader::NextIsBool() const { - return NextValueType() == DBUS_TYPE_BOOLEAN; -} - -inline bool MessageReader::NextIsByte() const { - return NextValueType() == DBUS_TYPE_BYTE; -} - -inline bool MessageReader::NextIsInt16() const { - return NextValueType() == DBUS_TYPE_INT16; -} - -inline bool MessageReader::NextIsUint16() const { - return NextValueType() == DBUS_TYPE_UINT16; -} - -inline bool MessageReader::NextIsInt32() const { - return NextValueType() == DBUS_TYPE_INT32; -} - -inline bool MessageReader::NextIsUint32() const { - return NextValueType() == DBUS_TYPE_UINT32; -} - -inline bool MessageReader::NextIsInt64() const { - return NextValueType() == DBUS_TYPE_INT64; -} - -inline bool MessageReader::NextIsUint64() const { - return NextValueType() == DBUS_TYPE_UINT64; -} - -inline bool MessageReader::NextIsDouble() const { - return NextValueType() == DBUS_TYPE_DOUBLE; -} - -inline bool MessageReader::NextIsString() const { - return NextValueType() == DBUS_TYPE_STRING; -} - -inline bool MessageReader::NextIsArray() const { - return NextValueType() == DBUS_TYPE_ARRAY; -} - -inline bool MessageReader::NextIsStruct() const { - return NextValueType() == DBUS_TYPE_STRUCT; -} - -inline bool MessageReader::TakeBool() { - dbus_bool_t value = 0; - ReadNextValue(DBUS_TYPE_BOOLEAN, &value); - return value != 0; -} - -inline uint8_t MessageReader::TakeByte() { - uint8_t value = 0; - ReadNextValue(DBUS_TYPE_BYTE, &value); - return value; -} - -inline int16_t MessageReader::TakeInt16() { - int16_t value = 0; - ReadNextValue(DBUS_TYPE_INT16, &value); - return value; -} - -inline uint16_t MessageReader::TakeUint16() { - uint16_t value = 0; - ReadNextValue(DBUS_TYPE_UINT16, &value); - return value; -} - -inline int32_t MessageReader::TakeInt32() { - int32_t value = 0; - ReadNextValue(DBUS_TYPE_INT32, &value); - return value; -} - -inline uint32_t MessageReader::TakeUint32() { - uint32_t value = 0; - ReadNextValue(DBUS_TYPE_UINT32, &value); - return value; -} - -inline int64_t MessageReader::TakeInt64() { - int64_t value = 0; - ReadNextValue(DBUS_TYPE_INT64, &value); - return value; -} - -inline uint64_t MessageReader::TakeUint64() { - uint64_t value = 0; - ReadNextValue(DBUS_TYPE_UINT64, &value); - return value; -} - -inline double MessageReader::TakeDouble() { - double value = 0.; - ReadNextValue(DBUS_TYPE_DOUBLE, &value); - return value; -} - -inline std::string MessageReader::TakeString() { - const char* value = ""; - ReadNextValue(DBUS_TYPE_STRING, &value); - return value; -} - -inline MessageReader::DataType MessageReader::NextValueType() const { - DBusMessageIter* iter = const_cast<DBusMessageIter*>(&iterator_); - return failed_ ? DBUS_TYPE_INVALID : dbus_message_iter_get_arg_type(iter); -} - -// Message writer methods -inline void MessageWriter::PutBool(bool value) { - dbus_bool_t dbus_value = value; - WriteAndCheck(DBUS_TYPE_BOOLEAN, &dbus_value); -} - -inline void MessageWriter::PutByte(uint8_t value) { - WriteAndCheck(DBUS_TYPE_BYTE, &value); -} - -inline void MessageWriter::PutInt16(int16_t value) { - WriteAndCheck(DBUS_TYPE_INT16, &value); -} - -inline void MessageWriter::PutUint16(uint16_t value) { - WriteAndCheck(DBUS_TYPE_UINT16, &value); -} - -inline void MessageWriter::PutInt32(int32_t value) { - WriteAndCheck(DBUS_TYPE_INT32, &value); -} - -inline void MessageWriter::PutUint32(uint32_t value) { - WriteAndCheck(DBUS_TYPE_UINT32, &value); -} - -inline void MessageWriter::PutInt64(int64_t value) { - WriteAndCheck(DBUS_TYPE_INT64, &value); -} - -inline void MessageWriter::PutUint64(uint64_t value) { - WriteAndCheck(DBUS_TYPE_UINT64, &value); -} - -inline void MessageWriter::PutDouble(double value) { - WriteAndCheck(DBUS_TYPE_DOUBLE, &value); -} - -inline void MessageWriter::PutString(const std::string& value) { - const char* pointer = value.c_str(); - WriteAndCheck(DBUS_TYPE_STRING, &pointer); -} - -} // namespace dbus - -#endif // SRC_COMPONENTS_DBUS_INCLUDE_DBUS_DBUS_MESSAGE_INL_H_ diff --git a/src/components/dbus/include/dbus/message_descriptions.h b/src/components/dbus/include/dbus/message_descriptions.h deleted file mode 100644 index a9e7a5e141..0000000000 --- a/src/components/dbus/include/dbus/message_descriptions.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2013, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef SRC_COMPONENTS_DBUS_INCLUDE_DBUS_MESSAGE_DESCRIPTIONS_H_ -#define SRC_COMPONENTS_DBUS_INCLUDE_DBUS_MESSAGE_DESCRIPTIONS_H_ - -#include <stdint.h> -#include <stdlib.h> -#include "interfaces/HMI_API.h" - -namespace ford_message_descriptions { - -enum ParameterType { Integer, Boolean, Float, String, Struct, Enum, Array }; - -struct ParameterDescription { - const char* name; - const ParameterType type; - const bool obligatory; // TODO (dchmerev@luxoft.com): rename to 'mandatory' - // as in HMI API description -}; - -struct ArrayDescription { - const ParameterDescription base; - const ParameterDescription* element; - const char* element_dbus_signature; -}; - -struct StructDescription { - const ParameterDescription base; - const ParameterDescription** parameters; -}; - -struct MessageDescription { - const char* interface; - const char* name; - const hmi_apis::messageType::eType message_type; - const hmi_apis::FunctionID::eType function_id; - const ParameterDescription** parameters; -}; - -extern const MessageDescription* message_descriptions[]; - -} // namespace ford_message_descriptions - -#endif // SRC_COMPONENTS_DBUS_INCLUDE_DBUS_MESSAGE_DESCRIPTIONS_H_ diff --git a/src/components/dbus/include/dbus/schema.h b/src/components/dbus/include/dbus/schema.h deleted file mode 100644 index 3dfe49cc95..0000000000 --- a/src/components/dbus/include/dbus/schema.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2013, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef SRC_COMPONENTS_DBUS_INCLUDE_DBUS_SCHEMA_H_ -#define SRC_COMPONENTS_DBUS_INCLUDE_DBUS_SCHEMA_H_ - -#include <string> -#include <vector> -#include <utility> - -#include "dbus/message_descriptions.h" -#include "interfaces/HMI_API.h" - -namespace dbus { - -using ford_message_descriptions::ParameterDescription; -using ford_message_descriptions::MessageDescription; - -struct Description; - -typedef hmi_apis::FunctionID::eType MessageId; -typedef hmi_apis::messageType::eType MessageType; -typedef std::pair<std::string, std::string> MessageName; // interface, message -typedef std::vector<const ParameterDescription*> ListArgs; -typedef std::vector<const Description*> Messages; - -/** - * \brief Wrapper class for message description - */ -class DBusSchema { - public: - explicit DBusSchema(const MessageDescription** array); - - /** - * \brief gets message name by message id - * \param id id message - * \return name message - */ - MessageName getMessageName(MessageId id) const; - - /** - * \brief gets message id by message name - * \param name name message - * \return id message - */ - MessageId getMessageId(const MessageName& name) const; - - /** - * \brief gets list rules for arguments - * \param id id message - * \param type type message - * \return list rules - */ - ListArgs getListArgs(MessageId id, MessageType type) const; - - /** - * \brief gets list rules for arguments - * @param name name message - * @param type type message - * @return list rules - */ - ListArgs getListArgs(const MessageName& name, MessageType type) const; - - private: - Messages msgs_; -}; - -} // namespace dbus - -#endif // SRC_COMPONENTS_DBUS_INCLUDE_DBUS_SCHEMA_H_ |