diff options
Diffstat (limited to 'src/components/formatters/include')
-rw-r--r-- | src/components/formatters/include/formatters/CFormatterJsonBase.h | 119 | ||||
-rw-r--r-- | src/components/formatters/include/formatters/CFormatterJsonBase.hpp | 122 | ||||
-rw-r--r-- | src/components/formatters/include/formatters/CFormatterJsonSDLRPCv1.h (renamed from src/components/formatters/include/formatters/CFormatterJsonSDLRPCv1.hpp) | 56 | ||||
-rw-r--r-- | src/components/formatters/include/formatters/CFormatterJsonSDLRPCv2.h (renamed from src/components/formatters/include/formatters/CFormatterJsonSDLRPCv2.hpp) | 69 | ||||
-rw-r--r-- | src/components/formatters/include/formatters/CSmartFactory.h | 410 | ||||
-rw-r--r-- | src/components/formatters/include/formatters/CSmartFactory.hpp | 428 | ||||
-rw-r--r-- | src/components/formatters/include/formatters/formatter_json_rpc.h | 736 | ||||
-rw-r--r-- | src/components/formatters/include/formatters/generic_json_formatter.h | 14 | ||||
-rw-r--r-- | src/components/formatters/include/formatters/meta_formatter.h | 18 |
9 files changed, 983 insertions, 989 deletions
diff --git a/src/components/formatters/include/formatters/CFormatterJsonBase.h b/src/components/formatters/include/formatters/CFormatterJsonBase.h new file mode 100644 index 0000000000..be4ee3e2cc --- /dev/null +++ b/src/components/formatters/include/formatters/CFormatterJsonBase.h @@ -0,0 +1,119 @@ +/** + * @file CFormatterJsonBase.hpp + * @brief CFormatterJsonBase header file. + */ +// 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 __CFORMATTERJSONBASE_HPP__ +#define __CFORMATTERJSONBASE_HPP__ + +#include "smart_objects/smart_object.h" +#include "json/json.h" + +namespace NsSmartDeviceLink { +namespace NsJSONHandler { +namespace Formatters { + +namespace meta_formatter_error_code { +/** + * @brief Error codes of MetaFormatter represented as bitmask + **/ +typedef long tMetaFormatterErrorCode; + +/** + * @brief OK, no error + */ +static const tMetaFormatterErrorCode kErrorOk = 0x0; + +/** + * @brief origin smart object is not function + */ +static const tMetaFormatterErrorCode kErrorObjectIsNotFunction = 0x01; + +/** + * @brief smart shema describes object which is not function + */ +static const tMetaFormatterErrorCode kErrorSchemaIsNotFunction = 0x02; + +/** + * @brief result smart object has invalid type (SmartType_Invalid) + * before passing to MetaFormatter, i.e. result object can not + * be changed, i.e. result object can not be built + * + */ +static const tMetaFormatterErrorCode kErrorFailedCreateObjectBySchema = 0x04; +} + +/** + * @brief The base class for all JSON based formatters. + */ +class CFormatterJsonBase { + private: + /** + * @brief Constructor. + */ + CFormatterJsonBase(); + + /** + * @brief Copy constructor. + * + * @param obj Object to copy. + */ + CFormatterJsonBase(const CFormatterJsonBase& obj); + + protected: + public: + /** + * @brief The method constructs a SmartObject from the input JSON object + * + * @param value Input JSON object. + * @param obj The resulting SmartObject. + */ + static void jsonValueToObj( + const Json::Value& value, + NsSmartDeviceLink::NsSmartObjects::SmartObject& obj); + + /** + * @brief The method constructs a JSON object from the input SmartObject + * + * @param obj Input SmartObject. Can contain a complex structure of objects. + * @param value The resulting JSON object. It has the same structure as the + *input SmartObject. + */ + static void objToJsonValue( + const NsSmartDeviceLink::NsSmartObjects::SmartObject& obj, + Json::Value& value); +}; +} +} +} // namespace NsSmartDeviceLink::NsJSONHandler::Formatters + +#endif // __CFORMATTERJSONBASE_HPP__ diff --git a/src/components/formatters/include/formatters/CFormatterJsonBase.hpp b/src/components/formatters/include/formatters/CFormatterJsonBase.hpp deleted file mode 100644 index ef57d9b1b9..0000000000 --- a/src/components/formatters/include/formatters/CFormatterJsonBase.hpp +++ /dev/null @@ -1,122 +0,0 @@ -/** - * @file CFormatterJsonBase.hpp - * @brief CFormatterJsonBase header file. - */ -// 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 __CFORMATTERJSONBASE_HPP__ -#define __CFORMATTERJSONBASE_HPP__ - -#include "smart_objects/smart_object.h" -#include "json/json.h" - -namespace NsSmartDeviceLink { -namespace NsJSONHandler { -namespace Formatters { - -namespace meta_formatter_error_code { - /** - * @brief Error codes of MetaFormatter represented as bitmask - **/ - typedef long tMetaFormatterErrorCode ; - - /** - * @brief OK, no error - */ - static const tMetaFormatterErrorCode kErrorOk = 0x0; - - /** - * @brief origin smart object is not function - */ - static const tMetaFormatterErrorCode kErrorObjectIsNotFunction = 0x01; - - /** - * @brief smart shema describes object which is not function - */ - static const tMetaFormatterErrorCode kErrorSchemaIsNotFunction = 0x02; - - /** - * @brief result smart object has invalid type (SmartType_Invalid) - * before passing to MetaFormatter, i.e. result object can not - * be changed, i.e. result object can not be built - * - */ - static const tMetaFormatterErrorCode kErrorFailedCreateObjectBySchema = 0x04; -} - - /** - * @brief The base class for all JSON based formatters. - */ - class CFormatterJsonBase - { - private: - - /** - * @brief Constructor. - */ - CFormatterJsonBase(); - - /** - * @brief Copy constructor. - * - * @param obj Object to copy. - */ - CFormatterJsonBase(const CFormatterJsonBase &obj); - - protected: - - - public: - - /** - * @brief The method constructs a SmartObject from the input JSON object - * - * @param value Input JSON object. - * @param obj The resulting SmartObject. - */ - static void jsonValueToObj(const Json::Value &value, - NsSmartDeviceLink::NsSmartObjects::SmartObject &obj); - - /** - * @brief The method constructs a JSON object from the input SmartObject - * - * @param obj Input SmartObject. Can contain a complex structure of objects. - * @param value The resulting JSON object. It has the same structure as the input SmartObject. - */ - static void objToJsonValue(const NsSmartDeviceLink::NsSmartObjects::SmartObject &obj, - Json::Value &value); - }; - -} -} -} // namespace NsSmartDeviceLink::NsJSONHandler::Formatters - -#endif // __CFORMATTERJSONBASE_HPP__ diff --git a/src/components/formatters/include/formatters/CFormatterJsonSDLRPCv1.hpp b/src/components/formatters/include/formatters/CFormatterJsonSDLRPCv1.h index 03454395b0..e78a115f6c 100644 --- a/src/components/formatters/include/formatters/CFormatterJsonSDLRPCv1.hpp +++ b/src/components/formatters/include/formatters/CFormatterJsonSDLRPCv1.h @@ -35,9 +35,9 @@ #include "smart_objects/smart_object.h" #include "smart_objects/enum_schema_item.h" -#include "CFormatterJsonBase.hpp" +#include "CFormatterJsonBase.h" -#include "formatters/CSmartFactory.hpp" +#include "formatters/CSmartFactory.h" #include "formatters/meta_formatter.h" namespace NsSmartDeviceLink { @@ -111,14 +111,15 @@ class CFormatterJsonSDLRPCv1 : public CFormatterJsonBase { static const std::string S_CORRELATION_ID; public: - static const int32_t kSuccess; static const int32_t kParsingError; static const int32_t kFunctionIdNotFound; static const int32_t kMessageTypeNotFound; static const int32_t kCorrelationIdNotFound; - typedef NsSmartDeviceLink::NsJSONHandler::Formatters::meta_formatter_error_code::tMetaFormatterErrorCode tMetaFormatterErrorCode; + typedef NsSmartDeviceLink::NsJSONHandler::Formatters:: + meta_formatter_error_code::tMetaFormatterErrorCode + tMetaFormatterErrorCode; /** * @brief Creates a JSON string from a SmartObject. @@ -128,7 +129,7 @@ class CFormatterJsonSDLRPCv1 : public CFormatterJsonBase { * @return true if success, false otherwise */ static bool toString( - const NsSmartDeviceLink::NsSmartObjects::SmartObject &obj, + const NsSmartDeviceLink::NsSmartObjects::SmartObject& obj, std::string& outStr); /** @@ -138,15 +139,17 @@ class CFormatterJsonSDLRPCv1 : public CFormatterJsonBase { * @param out The resulting SmartObject * @return true if success, otherwise - false */ - template<typename FunctionId, typename MessageType> - static int32_t fromString(const std::string &str, - NsSmartDeviceLink::NsSmartObjects::SmartObject &out); + template <typename FunctionId, typename MessageType> + static int32_t fromString( + const std::string& str, + NsSmartDeviceLink::NsSmartObjects::SmartObject& out); /** * @brief Converts to string the smart object against the given schema * * @param object Original smart object - * @param schema Smart schema which describes 'fake' smart object to be formatted + * @param schema Smart schema which describes 'fake' smart object to be + *formatted * @param outStr Resulting JSON string * @return formatting error code */ @@ -154,12 +157,11 @@ class CFormatterJsonSDLRPCv1 : public CFormatterJsonBase { const NsSmartDeviceLink::NsSmartObjects::SmartObject& object, const NsSmartDeviceLink::NsSmartObjects::CSmartSchema& schema, std::string& outStr); - }; // ---------------------------------------------------------------------------- -template<typename FunctionId, typename MessageType> +template <typename FunctionId, typename MessageType> int32_t Formatters::CFormatterJsonSDLRPCv1::fromString( const std::string& str, NsSmartDeviceLink::NsSmartObjects::SmartObject& out) { @@ -171,15 +173,15 @@ int32_t Formatters::CFormatterJsonSDLRPCv1::fromString( std::string type; if (false == reader.parse(str, root)) { - result = kParsingError | kMessageTypeNotFound | kFunctionIdNotFound - | kCorrelationIdNotFound; + result = kParsingError | kMessageTypeNotFound | kFunctionIdNotFound | + kCorrelationIdNotFound; } if (kSuccess == result) { type = getMessageType(root); if (true == type.empty()) { - result = kMessageTypeNotFound | kFunctionIdNotFound - | kCorrelationIdNotFound; + result = + kMessageTypeNotFound | kFunctionIdNotFound | kCorrelationIdNotFound; } } @@ -187,16 +189,18 @@ int32_t Formatters::CFormatterJsonSDLRPCv1::fromString( MessageType messageType = MessageType::INVALID_ENUM; if (kSuccess == result) { - if (!NsSmartObjects::EnumConversionHelper<MessageType>::StringToEnum(type, &messageType)) { - // If MessageType is not found than FunctionId and CorrelationId can not be found either - result = kMessageTypeNotFound | kFunctionIdNotFound - | kCorrelationIdNotFound; + if (!NsSmartObjects::EnumConversionHelper<MessageType>::StringToEnum( + type, &messageType)) { + // If MessageType is not found than FunctionId and CorrelationId can not + // be found either + result = + kMessageTypeNotFound | kFunctionIdNotFound | kCorrelationIdNotFound; } } if (kSuccess == result) { - if (!NsSmartObjects::EnumConversionHelper<FunctionId>::StringToEnum(root[type][S_NAME].asString(), - &functionId)) { + if (!NsSmartObjects::EnumConversionHelper<FunctionId>::StringToEnum( + root[type][S_NAME].asString(), &functionId)) { result = kFunctionIdNotFound; functionId = FunctionId::INVALID_ENUM; } @@ -210,13 +214,14 @@ int32_t Formatters::CFormatterJsonSDLRPCv1::fromString( out[S::S_PARAMS][S::S_MESSAGE_TYPE] = messageType; out[S::S_PARAMS][S::S_FUNCTION_ID] = functionId; if (true == root[type][S_CORRELATION_ID].empty()) { - if (type != S_NOTIFICATION) { // Notification may not have CorrelationId + if (type != + S_NOTIFICATION) { // Notification may not have CorrelationId result |= kCorrelationIdNotFound; out[S::S_PARAMS][S::S_CORRELATION_ID] = -1; } } else { - out[S::S_PARAMS][S::S_CORRELATION_ID] = root[type][S_CORRELATION_ID] - .asInt(); + out[S::S_PARAMS][S::S_CORRELATION_ID] = + root[type][S_CORRELATION_ID].asInt(); } out[S::S_PARAMS][S::S_PROTOCOL_TYPE] = 0; out[S::S_PARAMS][S::S_PROTOCOL_VERSION] = 1; @@ -227,9 +232,8 @@ int32_t Formatters::CFormatterJsonSDLRPCv1::fromString( return result; } - } } } // namespace NsSmartDeviceLink::NsJSONHandler::Formatters -#endif // __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS__CFORMATTERJSONSDLRPCV1_HPP__ +#endif // __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS__CFORMATTERJSONSDLRPCV1_HPP__ diff --git a/src/components/formatters/include/formatters/CFormatterJsonSDLRPCv2.hpp b/src/components/formatters/include/formatters/CFormatterJsonSDLRPCv2.h index 3b4e206515..a260ecd080 100644 --- a/src/components/formatters/include/formatters/CFormatterJsonSDLRPCv2.hpp +++ b/src/components/formatters/include/formatters/CFormatterJsonSDLRPCv2.h @@ -35,8 +35,8 @@ #include "smart_objects/smart_object.h" -#include "CFormatterJsonBase.hpp" -#include "formatters/CSmartFactory.hpp" +#include "CFormatterJsonBase.h" +#include "formatters/CSmartFactory.h" namespace NsSmartDeviceLink { namespace NsJSONHandler { @@ -49,7 +49,6 @@ namespace Formatters { */ class CFormatterJsonSDLRPCv2 : public CFormatterJsonBase { private: - /** * @brief Hidden constructor. * @@ -65,8 +64,9 @@ class CFormatterJsonSDLRPCv2 : public CFormatterJsonBase { CFormatterJsonSDLRPCv2(const CFormatterJsonSDLRPCv2&); public: - - typedef NsSmartDeviceLink::NsJSONHandler::Formatters::meta_formatter_error_code::tMetaFormatterErrorCode tMetaFormatterErrorCode; + typedef NsSmartDeviceLink::NsJSONHandler::Formatters:: + meta_formatter_error_code::tMetaFormatterErrorCode + tMetaFormatterErrorCode; /** * @brief Creates a JSON string from a SmartObject. @@ -76,7 +76,7 @@ class CFormatterJsonSDLRPCv2 : public CFormatterJsonBase { * @return true if success, false otherwise */ static bool toString( - const NsSmartDeviceLink::NsSmartObjects::SmartObject &obj, + const NsSmartDeviceLink::NsSmartObjects::SmartObject& obj, std::string& outStr); /** @@ -84,14 +84,17 @@ class CFormatterJsonSDLRPCv2 : public CFormatterJsonBase { * * @param str Input JSON string in SDLRPCv2 format * @param out Output SmartObject - * @param functionId The corresponding field in SmartObject is filled with this param. - * @param messageType The corresponding field in SmartObject is filled with this param. + * @param functionId The corresponding field in SmartObject is filled with + *this param. + * @param messageType The corresponding field in SmartObject is filled with + *this param. * @return true if success, otherwise - false */ - template<typename FunctionId, typename MessageType> - static bool fromString(const std::string &str, - NsSmartDeviceLink::NsSmartObjects::SmartObject &out, - FunctionId functionId, MessageType messageType); + template <typename FunctionId, typename MessageType> + static bool fromString(const std::string& str, + NsSmartDeviceLink::NsSmartObjects::SmartObject& out, + FunctionId functionId, + MessageType messageType); /** * @brief Creates a SmartObject from a JSON string. @@ -100,23 +103,28 @@ class CFormatterJsonSDLRPCv2 : public CFormatterJsonBase { * * @param str Input JSON string in SDLRPCv2 format * @param out Output SmartObject - * @param functionId The corresponding field in SmartObject is filled with this param. - * @param messageType The corresponding field in SmartObject is filled with this param. - * @param correlatioId It's like sequence number. The corresponding field in SmartObject + * @param functionId The corresponding field in SmartObject is filled with + *this param. + * @param messageType The corresponding field in SmartObject is filled with + *this param. + * @param correlatioId It's like sequence number. The corresponding field in + *SmartObject * is filled with this param. * @return true if success, otherwise - false */ - template<typename FunctionId, typename MessageType> - static bool fromString(const std::string &str, - NsSmartDeviceLink::NsSmartObjects::SmartObject &out, - FunctionId functionId, MessageType messageType, + template <typename FunctionId, typename MessageType> + static bool fromString(const std::string& str, + NsSmartDeviceLink::NsSmartObjects::SmartObject& out, + FunctionId functionId, + MessageType messageType, int32_t correlationId); /** * @brief Converts to string the smart object against the given schema * * @param object Original smart object - * @param schema Smart schema which describes 'fake' smart object to be formatted + * @param schema Smart schema which describes 'fake' smart object to be + *formatted * @param outStr Resulting JSON string * @return formatting error code */ @@ -126,10 +134,12 @@ class CFormatterJsonSDLRPCv2 : public CFormatterJsonBase { std::string& outStr); }; -template<typename FunctionId, typename MessageType> +template <typename FunctionId, typename MessageType> inline bool CFormatterJsonSDLRPCv2::fromString( - const std::string& str, NsSmartDeviceLink::NsSmartObjects::SmartObject& out, - FunctionId functionId, MessageType messageType) { + const std::string& str, + NsSmartDeviceLink::NsSmartObjects::SmartObject& out, + FunctionId functionId, + MessageType messageType) { bool result = true; try { @@ -154,11 +164,13 @@ inline bool CFormatterJsonSDLRPCv2::fromString( return result; } -template<typename FunctionId, typename MessageType> +template <typename FunctionId, typename MessageType> inline bool CFormatterJsonSDLRPCv2::fromString( - const std::string& str, NsSmartDeviceLink::NsSmartObjects::SmartObject& out, - FunctionId functionId, MessageType messageType, int32_t correlationId) { - + const std::string& str, + NsSmartDeviceLink::NsSmartObjects::SmartObject& out, + FunctionId functionId, + MessageType messageType, + int32_t correlationId) { bool result = fromString(str, out, functionId, messageType); namespace strings = NsSmartDeviceLink::NsJSONHandler::strings; @@ -168,9 +180,8 @@ inline bool CFormatterJsonSDLRPCv2::fromString( return result; } - } } } // namespace NsSmartDeviceLink::NsJSONHandler::Formatters -#endif // __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS__CFORMATTERJSONSDLRPCV2_HPP__ +#endif // __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS__CFORMATTERJSONSDLRPCV2_HPP__ diff --git a/src/components/formatters/include/formatters/CSmartFactory.h b/src/components/formatters/include/formatters/CSmartFactory.h new file mode 100644 index 0000000000..223d22fbbe --- /dev/null +++ b/src/components/formatters/include/formatters/CSmartFactory.h @@ -0,0 +1,410 @@ +/** + * @file CSmartFactory.hpp + * @brief CSmartFactory header file. + */ +// 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 __CSMARTFACTORY_HPP__ +#define __CSMARTFACTORY_HPP__ + +#include "smart_objects/smart_object.h" +#include "smart_objects/smart_schema.h" +#include <map> +#include <string> + +namespace NsSmartDeviceLink { +namespace NsJSONHandler { +/** + * @brief String constants used by SmartFactory. + */ +namespace strings { +/** + * @brief String constant for MSG_PARAMS. + */ +extern const std::string S_MSG_PARAMS; + +/** + * @brief String constant for PARAMS. + */ +extern const std::string S_PARAMS; + +/** + * @brief String constant for FUNCTION_ID. + */ +extern const std::string S_FUNCTION_ID; + +/** + * @brief String constant for MESSAGE_TYPE. + */ +extern const std::string S_MESSAGE_TYPE; + +/** + * @brief String constant for PROTOCOL_VERSION. + */ +extern const std::string S_PROTOCOL_VERSION; + +/** + * @brief String constant for PROTOCOL_TYPE. + */ +extern const std::string S_PROTOCOL_TYPE; + +/** + * @brief String constant for CORRELATION_ID. + */ +extern const std::string S_CORRELATION_ID; + +/** + * @brief String constant for "code" param name. + */ +extern const std::string kCode; + +/** + * @brief String constant for "message" param name. + */ +extern const std::string kMessage; +} + +/** + * @brief Smart Schema key. + * + * @tparam FunctionIdEnum Type of function ID enum. + * @tparam MessageTypeEnum Type of messageType enum. + */ +template <class FunctionIdEnum, class MessageTypeEnum> +struct SmartSchemaKey { + /** + * @brief Value of function ID for the key. + */ + FunctionIdEnum functionId; + + /** + * @brief Value of messageType for the key. + */ + MessageTypeEnum messageType; + + /** + * @brief Constructor. + * + * @param functionIdParam Value of function ID. + * @param messageTypeParam Value of message type. + */ + SmartSchemaKey(FunctionIdEnum functionIdParam, + MessageTypeEnum messageTypeParam); +}; + +/** + * @brief Smart Factory. + * + * This class is used as base class for generated factories. + * Clients should use methods of this class to access all + * SmartSchema validation features. + * + * @tparam FunctionIdEnum Type of function ID enum. + * @tparam MessageTypeEnum Type of messageType enum. + * @tparam StructIdEnum Type of StructId enum. + */ +template <class FunctionIdEnum, class MessageTypeEnum, class StructIdEnum> +class CSmartFactory { + public: + /** + * @brief Constructor. + */ + CSmartFactory(void); + + /** + * @brief Attach schema to the function SmartObject. + * + * @param object SmartObject to attach schema for. + * + * @param RemoveFakeParameters contains true if need + * to remove fake parameters from smart object otherwise contains false. + * + * @return True if operation was successful or false otherwise. + */ + bool attachSchema(NsSmartDeviceLink::NsSmartObjects::SmartObject& object, + const bool RemoveFakeParameters); + + /** + * @brief Attach schema to the struct SmartObject. + * + * @param struct_id Identifier of the struct. + * @param object SmartObject to attach schema for. + * + * @return True if operation was successful of false otherwise. + */ + bool AttachSchema(const StructIdEnum struct_id, + NsSmartDeviceLink::NsSmartObjects::SmartObject& object); + + /** + * @brief Create new SmartObject with attached function SmartSchema. + * + * @param function_id FunctionID of the function. + * @param message_type messageType of the function. + * + * @return If function succeeded it returns new SmartObject with + * map type and attached SmartSchema. Client can use such + * object to store specific function and perform validation. + * Otherwise (if SmartSchema was not attached to the + * SmartObject) function returns empty SmartObject with + * null type. + */ + NsSmartDeviceLink::NsSmartObjects::SmartObject CreateSmartObject( + const FunctionIdEnum function_id, const MessageTypeEnum message_type); + + /** + * @brief Create new SmartObject with attached struct SmartSchema. + * + * @param struct_id Identifier of the struct. + * + * @return If function succeeded it returns new SmartObject with + * map type and attached SmartSchema. Client can use such + * object to store specific struct and perform validation. + * Otherwise (if SmartSchema was not attached to the + * SmartObject) function returns empty SmartObject with + * null type. + */ + NsSmartDeviceLink::NsSmartObjects::SmartObject CreateSmartObject( + const StructIdEnum struct_id); + + /** + * @brief Get SmartSchema for specific function. + * + * @param function_id FunctionID of the function. + * @param message_type messageType of the function. + * @param[out] result This value will be copy of the desired + * function SmartSchema if it found (this + * function returns true) or unmodified if + * SmartSchema is not found (this function + * returns false). + * + * @return True if function schema for specified input parameters + * is found or false otherwise. + */ + bool GetSchema(const FunctionIdEnum function_id, + const MessageTypeEnum message_type, + NsSmartDeviceLink::NsSmartObjects::CSmartSchema& result); + + /** + * @brief Get SmartSchema for specific struct. + * + * @param struct_id Identifier of the struct. + * + * @param[out] result This value will be copy of the desired + * struct SmartSchema if it found (this + * function returns true) or unmodified if + * SmartSchema is not found (this function + * returns false). + * + * @return True if struct schema for specified input parameter is + * found or false otherwise. + */ + bool GetSchema(const StructIdEnum struct_id, + NsSmartDeviceLink::NsSmartObjects::CSmartSchema& result); + + protected: + /** + * @brief Defines map of SmartSchemaKeys to the SmartSchemes. + * + * This container type should be used to store SmartSchemes of + * functions. + */ + typedef std::map<SmartSchemaKey<FunctionIdEnum, MessageTypeEnum>, + NsSmartDeviceLink::NsSmartObjects::CSmartSchema> + FuncionsSchemesMap; + + /** + * @brief Defines map of StructIdEnum to the SmartSchemes. + * + * This container type should be used to store SmartSchemes of + * structs. + */ + typedef std::map<StructIdEnum, + NsSmartDeviceLink::NsSmartObjects::CSmartSchema> + StructsSchemesMap; + + /** + * @brief Map of all function schemes for this factory. + */ + FuncionsSchemesMap functions_schemes_; + + /** + * @brief Map of all struct shemes for this factory. + */ + StructsSchemesMap structs_schemes_; +}; + +template <class FunctionIdEnum, class MessageTypeEnum, class StructIdEnum> +CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>::CSmartFactory( + void) + : functions_schemes_(), structs_schemes_() {} + +template <class FunctionIdEnum, class MessageTypeEnum, class StructIdEnum> +bool CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>::attachSchema( + NsSmartDeviceLink::NsSmartObjects::SmartObject& object, + const bool RemoveFakeParameters) { + if (false == object.keyExists(strings::S_PARAMS)) + return false; + if (false == object[strings::S_PARAMS].keyExists(strings::S_MESSAGE_TYPE)) + return false; + if (false == object[strings::S_PARAMS].keyExists(strings::S_FUNCTION_ID)) + return false; + + MessageTypeEnum msgtype( + (MessageTypeEnum) + object[strings::S_PARAMS][strings::S_MESSAGE_TYPE].asInt()); + FunctionIdEnum fid( + (FunctionIdEnum) + object[strings::S_PARAMS][strings::S_FUNCTION_ID].asInt()); + + SmartSchemaKey<FunctionIdEnum, MessageTypeEnum> key(fid, msgtype); + + typename FuncionsSchemesMap::iterator schemaIterator = + functions_schemes_.find(key); + + if (schemaIterator == functions_schemes_.end()) { + // Schema was not found + return false; + } + + object.setSchema(schemaIterator->second); + schemaIterator->second.applySchema(object, RemoveFakeParameters); + + return true; +} + +template <class FunctionIdEnum, class MessageTypeEnum, class StructIdEnum> +bool CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>::AttachSchema( + const StructIdEnum struct_id, + NsSmartDeviceLink::NsSmartObjects::SmartObject& object) { + typename StructsSchemesMap::iterator structs_iterator = + structs_schemes_.find(struct_id); + + if (structs_iterator == structs_schemes_.end()) { + return false; + } + + object.setSchema(structs_iterator->second); + structs_iterator->second.applySchema(object, false); + + return true; +} + +template <class FunctionIdEnum, class MessageTypeEnum, class StructIdEnum> +NsSmartDeviceLink::NsSmartObjects::SmartObject +CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>::CreateSmartObject( + const FunctionIdEnum function_id, const MessageTypeEnum message_type) { + SmartSchemaKey<FunctionIdEnum, MessageTypeEnum> key(function_id, + message_type); + + typename FuncionsSchemesMap::iterator schema_iterator = + functions_schemes_.find(key); + + if (schema_iterator != functions_schemes_.end()) { + NsSmartDeviceLink::NsSmartObjects::SmartObject function_object( + NsSmartDeviceLink::NsSmartObjects::SmartType_Map); + function_object.setSchema(schema_iterator->second); + schema_iterator->second.applySchema(function_object, false); + return function_object; + } + + return NsSmartDeviceLink::NsSmartObjects::SmartObject(); +} + +template <class FunctionIdEnum, class MessageTypeEnum, class StructIdEnum> +NsSmartDeviceLink::NsSmartObjects::SmartObject +CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>::CreateSmartObject( + const StructIdEnum struct_id) { + NsSmartDeviceLink::NsSmartObjects::SmartObject struct_object( + NsSmartDeviceLink::NsSmartObjects::SmartType_Map); + if (AttachSchema(struct_id, struct_object)) { + return struct_object; + } + + return NsSmartDeviceLink::NsSmartObjects::SmartObject(); +} + +template <class FunctionIdEnum, class MessageTypeEnum, class StructIdEnum> +bool CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>::GetSchema( + const FunctionIdEnum function_id, + const MessageTypeEnum message_type, + NsSmartDeviceLink::NsSmartObjects::CSmartSchema& result) { + SmartSchemaKey<FunctionIdEnum, MessageTypeEnum> key(function_id, + message_type); + + typename FuncionsSchemesMap::iterator schema_iterator = + functions_schemes_.find(key); + + if (schema_iterator != functions_schemes_.end()) { + result = schema_iterator->second; + return true; + } + + return false; +} + +template <class FunctionIdEnum, class MessageTypeEnum, class StructIdEnum> +bool CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>::GetSchema( + const StructIdEnum struct_id, + NsSmartDeviceLink::NsSmartObjects::CSmartSchema& result) { + typename StructsSchemesMap::iterator structs_iterator = + structs_schemes_.find(struct_id); + + if (structs_iterator != structs_schemes_.end()) { + result = structs_iterator->second; + return true; + } + + return false; +} + +template <class FunctionIdEnum, class MessageTypeEnum> +SmartSchemaKey<FunctionIdEnum, MessageTypeEnum>::SmartSchemaKey( + FunctionIdEnum functionIdParam, MessageTypeEnum messageTypeParam) + : functionId(functionIdParam), messageType(messageTypeParam) {} + +template <class FunctionIdEnum, class MessageTypeEnum> +bool operator<(const SmartSchemaKey<FunctionIdEnum, MessageTypeEnum>& l, + const SmartSchemaKey<FunctionIdEnum, MessageTypeEnum>& r) { + if (l.functionId < r.functionId) + return true; + if (l.functionId > r.functionId) + return false; + + if (l.messageType < r.messageType) + return true; + if (l.messageType > r.messageType) + return false; + + return false; +} +} +} +#endif //__CSMARTFACTORY_HPP__ diff --git a/src/components/formatters/include/formatters/CSmartFactory.hpp b/src/components/formatters/include/formatters/CSmartFactory.hpp deleted file mode 100644 index 55f9a30385..0000000000 --- a/src/components/formatters/include/formatters/CSmartFactory.hpp +++ /dev/null @@ -1,428 +0,0 @@ -/** - * @file CSmartFactory.hpp - * @brief CSmartFactory header file. - */ -// 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 __CSMARTFACTORY_HPP__ -#define __CSMARTFACTORY_HPP__ - -#include "smart_objects/smart_object.h" -#include "smart_objects/smart_schema.h" -#include <map> -#include <string> - -namespace NsSmartDeviceLink -{ - namespace NsJSONHandler - { - /** - * @brief String constants used by SmartFactory. - */ - namespace strings - { - /** - * @brief String constant for MSG_PARAMS. - */ - extern const std::string S_MSG_PARAMS; - - /** - * @brief String constant for PARAMS. - */ - extern const std::string S_PARAMS; - - /** - * @brief String constant for FUNCTION_ID. - */ - extern const std::string S_FUNCTION_ID; - - /** - * @brief String constant for MESSAGE_TYPE. - */ - extern const std::string S_MESSAGE_TYPE; - - /** - * @brief String constant for PROTOCOL_VERSION. - */ - extern const std::string S_PROTOCOL_VERSION; - - /** - * @brief String constant for PROTOCOL_TYPE. - */ - extern const std::string S_PROTOCOL_TYPE; - - /** - * @brief String constant for CORRELATION_ID. - */ - extern const std::string S_CORRELATION_ID; - - /** - * @brief String constant for "code" param name. - */ - extern const std::string kCode; - - /** - * @brief String constant for "message" param name. - */ - extern const std::string kMessage; - } - - /** - * @brief Smart Schema key. - * - * @tparam FunctionIdEnum Type of function ID enum. - * @tparam MessageTypeEnum Type of messageType enum. - */ - template <class FunctionIdEnum, class MessageTypeEnum> - struct SmartSchemaKey - { - /** - * @brief Value of function ID for the key. - */ - FunctionIdEnum functionId; - - /** - * @brief Value of messageType for the key. - */ - MessageTypeEnum messageType; - - /** - * @brief Constructor. - * - * @param functionIdParam Value of function ID. - * @param messageTypeParam Value of message type. - */ - SmartSchemaKey(FunctionIdEnum functionIdParam, MessageTypeEnum messageTypeParam); - }; - - /** - * @brief Smart Factory. - * - * This class is used as base class for generated factories. - * Clients should use methods of this class to access all - * SmartSchema validation features. - * - * @tparam FunctionIdEnum Type of function ID enum. - * @tparam MessageTypeEnum Type of messageType enum. - * @tparam StructIdEnum Type of StructId enum. - */ - template <class FunctionIdEnum, class MessageTypeEnum, class StructIdEnum> - class CSmartFactory - { - public: - - /** - * @brief Constructor. - */ - CSmartFactory(void); - - /** - * @brief Attach schema to the function SmartObject. - * - * @param object SmartObject to attach schema for. - * - * @param RemoveFakeParameters contains true if need - * to remove fake parameters from smart object otherwise contains false. - * - * @return True if operation was successful or false otherwise. - */ - bool attachSchema(NsSmartDeviceLink::NsSmartObjects::SmartObject& object, - const bool RemoveFakeParameters); - - /** - * @brief Attach schema to the struct SmartObject. - * - * @param struct_id Identifier of the struct. - * @param object SmartObject to attach schema for. - * - * @return True if operation was successful of false otherwise. - */ - bool AttachSchema(const StructIdEnum struct_id, - NsSmartDeviceLink::NsSmartObjects::SmartObject &object); - - - /** - * @brief Create new SmartObject with attached function SmartSchema. - * - * @param function_id FunctionID of the function. - * @param message_type messageType of the function. - * - * @return If function succeeded it returns new SmartObject with - * map type and attached SmartSchema. Client can use such - * object to store specific function and perform validation. - * Otherwise (if SmartSchema was not attached to the - * SmartObject) function returns empty SmartObject with - * null type. - */ - NsSmartDeviceLink::NsSmartObjects::SmartObject CreateSmartObject( - const FunctionIdEnum function_id, - const MessageTypeEnum message_type); - - /** - * @brief Create new SmartObject with attached struct SmartSchema. - * - * @param struct_id Identifier of the struct. - * - * @return If function succeeded it returns new SmartObject with - * map type and attached SmartSchema. Client can use such - * object to store specific struct and perform validation. - * Otherwise (if SmartSchema was not attached to the - * SmartObject) function returns empty SmartObject with - * null type. - */ - NsSmartDeviceLink::NsSmartObjects::SmartObject CreateSmartObject( - const StructIdEnum struct_id); - - /** - * @brief Get SmartSchema for specific function. - * - * @param function_id FunctionID of the function. - * @param message_type messageType of the function. - * @param[out] result This value will be copy of the desired - * function SmartSchema if it found (this - * function returns true) or unmodified if - * SmartSchema is not found (this function - * returns false). - * - * @return True if function schema for specified input parameters - * is found or false otherwise. - */ - bool GetSchema( - const FunctionIdEnum function_id, - const MessageTypeEnum message_type, - NsSmartDeviceLink::NsSmartObjects::CSmartSchema &result); - - /** - * @brief Get SmartSchema for specific struct. - * - * @param struct_id Identifier of the struct. - * - * @param[out] result This value will be copy of the desired - * struct SmartSchema if it found (this - * function returns true) or unmodified if - * SmartSchema is not found (this function - * returns false). - * - * @return True if struct schema for specified input parameter is - * found or false otherwise. - */ - bool GetSchema( - const StructIdEnum struct_id, - NsSmartDeviceLink::NsSmartObjects::CSmartSchema &result); - - protected: - - /** - * @brief Defines map of SmartSchemaKeys to the SmartSchemes. - * - * This container type should be used to store SmartSchemes of - * functions. - */ - typedef std::map<SmartSchemaKey<FunctionIdEnum, MessageTypeEnum>, - NsSmartDeviceLink::NsSmartObjects::CSmartSchema> - FuncionsSchemesMap; - - /** - * @brief Defines map of StructIdEnum to the SmartSchemes. - * - * This container type should be used to store SmartSchemes of - * structs. - */ - typedef std::map<StructIdEnum, - NsSmartDeviceLink::NsSmartObjects::CSmartSchema> - StructsSchemesMap; - - /** - * @brief Map of all function schemes for this factory. - */ - FuncionsSchemesMap functions_schemes_; - - /** - * @brief Map of all struct shemes for this factory. - */ - StructsSchemesMap structs_schemes_; - }; - - template <class FunctionIdEnum, class MessageTypeEnum, class StructIdEnum> - CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>::CSmartFactory(void) - : functions_schemes_(), - structs_schemes_() - { - } - - template <class FunctionIdEnum, class MessageTypeEnum, class StructIdEnum> - bool CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>:: - attachSchema(NsSmartDeviceLink::NsSmartObjects::SmartObject &object, - const bool RemoveFakeParameters) - { - if(false == object.keyExists(strings::S_PARAMS)) return false; - if(false == object[strings::S_PARAMS].keyExists(strings::S_MESSAGE_TYPE)) return false; - if(false == object[strings::S_PARAMS].keyExists(strings::S_FUNCTION_ID)) return false; - - MessageTypeEnum msgtype((MessageTypeEnum)object[strings::S_PARAMS][strings::S_MESSAGE_TYPE].asInt()); - FunctionIdEnum fid((FunctionIdEnum)object[strings::S_PARAMS][strings::S_FUNCTION_ID].asInt()); - - SmartSchemaKey<FunctionIdEnum, MessageTypeEnum> key(fid, msgtype); - - typename FuncionsSchemesMap::iterator schemaIterator = functions_schemes_.find(key); - - if(schemaIterator == functions_schemes_.end()) - { - // Schema was not found - return false; - } - - object.setSchema(schemaIterator->second); - schemaIterator->second.applySchema(object, RemoveFakeParameters); - - return true; - } - - template <class FunctionIdEnum, - class MessageTypeEnum, - class StructIdEnum> - bool CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>:: - AttachSchema( - const StructIdEnum struct_id, - NsSmartDeviceLink::NsSmartObjects::SmartObject &object) { - typename StructsSchemesMap::iterator structs_iterator = - structs_schemes_.find(struct_id); - - if (structs_iterator == structs_schemes_.end()) { - return false; - } - - object.setSchema(structs_iterator->second); - structs_iterator->second.applySchema(object, false); - - return true; - } - - template <class FunctionIdEnum, - class MessageTypeEnum, - class StructIdEnum> - NsSmartDeviceLink::NsSmartObjects::SmartObject - CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>:: - CreateSmartObject( - const FunctionIdEnum function_id, - const MessageTypeEnum message_type) { - SmartSchemaKey<FunctionIdEnum, MessageTypeEnum> key( - function_id, message_type); - - typename FuncionsSchemesMap::iterator schema_iterator = - functions_schemes_.find(key); - - if(schema_iterator != functions_schemes_.end()) { - NsSmartDeviceLink::NsSmartObjects::SmartObject function_object( - NsSmartDeviceLink::NsSmartObjects::SmartType_Map); - function_object.setSchema(schema_iterator->second); - schema_iterator->second.applySchema(function_object, false); - return function_object; - } - - return NsSmartDeviceLink::NsSmartObjects::SmartObject(); - } - - template <class FunctionIdEnum, - class MessageTypeEnum, - class StructIdEnum> - NsSmartDeviceLink::NsSmartObjects::SmartObject - CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>:: - CreateSmartObject(const StructIdEnum struct_id) { - NsSmartDeviceLink::NsSmartObjects::SmartObject struct_object( - NsSmartDeviceLink::NsSmartObjects::SmartType_Map); - if (AttachSchema(struct_id, struct_object)) { - return struct_object; - } - - return NsSmartDeviceLink::NsSmartObjects::SmartObject(); - } - - template <class FunctionIdEnum, - class MessageTypeEnum, - class StructIdEnum> - bool CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>:: - GetSchema(const FunctionIdEnum function_id, - const MessageTypeEnum message_type, - NsSmartDeviceLink::NsSmartObjects::CSmartSchema &result) { - SmartSchemaKey<FunctionIdEnum, MessageTypeEnum> key(function_id, - message_type); - - typename FuncionsSchemesMap::iterator schema_iterator = - functions_schemes_.find(key); - - if(schema_iterator != functions_schemes_.end()) { - result = schema_iterator->second; - return true; - } - - return false; - } - - template <class FunctionIdEnum, - class MessageTypeEnum, - class StructIdEnum> - bool CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>:: - GetSchema(const StructIdEnum struct_id, - NsSmartDeviceLink::NsSmartObjects::CSmartSchema &result) { - typename StructsSchemesMap::iterator structs_iterator = - structs_schemes_.find(struct_id); - - if(structs_iterator != structs_schemes_.end()) { - result = structs_iterator->second; - return true; - } - - return false; - } - - template <class FunctionIdEnum, class MessageTypeEnum> - SmartSchemaKey<FunctionIdEnum, MessageTypeEnum>::SmartSchemaKey(FunctionIdEnum functionIdParam, MessageTypeEnum messageTypeParam) - : functionId(functionIdParam) - , messageType(messageTypeParam) - { - - } - - template <class FunctionIdEnum, class MessageTypeEnum> - bool operator<(const SmartSchemaKey< FunctionIdEnum, MessageTypeEnum >& l, const SmartSchemaKey< FunctionIdEnum, MessageTypeEnum >& r) - { - if (l.functionId < r.functionId) return true; - if (l.functionId > r.functionId) return false; - - if (l.messageType < r.messageType) return true; - if (l.messageType > r.messageType) return false; - - return false; - } - } -} -#endif //__CSMARTFACTORY_HPP__ diff --git a/src/components/formatters/include/formatters/formatter_json_rpc.h b/src/components/formatters/include/formatters/formatter_json_rpc.h index d4653ef565..db122fa1a2 100644 --- a/src/components/formatters/include/formatters/formatter_json_rpc.h +++ b/src/components/formatters/include/formatters/formatter_json_rpc.h @@ -42,8 +42,8 @@ #include "smart_objects/enum_schema_item.h" #include "json/json.h" -#include "CFormatterJsonBase.hpp" -#include "formatters/CSmartFactory.hpp" +#include "CFormatterJsonBase.h" +#include "formatters/CSmartFactory.h" namespace NsSmartDeviceLink { namespace NsJSONHandler { @@ -52,415 +52,415 @@ namespace Formatters { /** * @brief Formatter for JSON RPC format. */ -class FormatterJsonRpc: public CFormatterJsonBase { - public: - /** - * @brief No errors occurred during the parsing of the input JSON string. - */ - static const int32_t kSuccess = 0; - - /** - * @brief Input JSON string cannot be parsed. - */ - static const int32_t kParsingError = 1; - - /** - * @brief Input JSON string has invalid format. - */ - static const int32_t kInvalidFormat = 2; - - /** - * @brief Method in input JSON string is not - * specified or specified incorrectly. - */ - static const int32_t kMethodNotSpecified = 4; - - /** - * @brief Method is unknown. - */ - static const int32_t kUnknownMethod = 8; - - /** - * @brief Message type is unknown. - */ - static const int32_t kUnknownMessageType = 16; - - /** - * @brief Id of request or response is invalid. - */ - static const int32_t kInvalidId = 32; - - /** - * @brief Response code is not available. - */ - static const int32_t kResponseCodeNotAvailable = 64; - - /** - * @brief Message for error response is not available. - */ - static const int32_t kErrorResponseMessageNotAvailable = 128; - - /** - * @brief Creates a JSON string from a SmartObject. - * - * @param obj Input SmartObject. - * @param out_str Resulting JSON string. - * - * @return true if success, false otherwise. - */ - static bool ToString(const NsSmartObjects::SmartObject& obj, - std::string& out_str); - - /** - * @brief Creates a SmartObject from a JSON string. - * - * @tparam FunctionId Type of function id enumeration. - * @tparam MessageType Type of message type enumeration. - * - * @param str input JSON string. - * @param out The resulting SmartObject. - * - * @return An integer that is a bitwise-or of all error codes occurred - * during the parsing of the input string. 0 if no errors occurred. - */ - template <typename FunctionId, typename MessageType> - static int32_t FromString(const std::string& str, - NsSmartObjects::SmartObject& out); - - private: - /** - * @brief Request. - */ - static const char* kRequest; - - /** - * @brief Response. - */ - static const char* kResponse; - - /** - * @brief Notification. - */ - static const char* kNotification; - - /** - * @brief Error reponse. - */ - static const char* kErrorResponse; - - /** - * @brief Name of "jsonrpc" message field. - */ - static const char* kJsonRpc; - - /** - * @brief Expected value of "jsonrpc" message field ("2.0"). - */ - static const char* kJsonRpcExpectedValue; - - /** - * @brief Name of "id" message field. - */ - static const char* kId; - - /** - * @brief Name of "method" field. - */ - static const char* kMethod; - - /** - * @brief Name of "params" field. - */ - static const char* kParams; - - /** - * @brief Name of "result" field. - */ - static const char* kResult; - - /** - * @brief Name of "error" field. - */ - static const char* kError; - - /** - * @brief Name of "code" field. - */ - static const char* kCode; - - /** - * @brief Name of "data" field. - */ - static const char* kData; - - /** - * @brief Name of "message" field. - */ - static const char* kMessage; - - /** - * @brief Constructor. - */ - FormatterJsonRpc(); - - /** - * @brief Copy constructor. - * - * @param unused Unused parameter. - */ - FormatterJsonRpc(const FormatterJsonRpc& unused); - - /** - * @brief Parse function id. - * - * @tparam FunctionId Type of function id enumeration. - * - * @param method_value JSON value with function id. - * @param out The resulting SmartObject. - * - * @return An integer that is a bitwise-or of all error codes occurred - * during the parsing of the function id. 0 if no errors occurred. - */ - template <typename FunctionId> - static int32_t ParseFunctionId(const Json::Value& method_value, - NsSmartObjects::SmartObject& out); - - /** - * @brief Set method. - * - * Try to extract function id from the message object and set the "method" - * field of the container. - * - * @param params Message parameters object. - * @param method_container Container for the "method" field. - * - * @return true if function id was extracted successfully and set as a - * value of "method" field. - */ - static bool SetMethod(const NsSmartObjects::SmartObject& params, - Json::Value& method_container); - - /** - * @brief Set id. - * - * Try to extract request/response id from the message object and set the - * "id" field of the container. - * - * @param params Message parameters object. - * @param id_container Container for the "id" field. - * - * @return true if request/response id was extracted successfully and set - * as a value of "id" field. - */ - static bool SetId(const NsSmartObjects::SmartObject& params, - Json::Value& id_container); - - /** - * @brief Set message - * - * Try to extract message from response error object and set "message" field for the container - * - * @param params Message parameters object. - * @param id_container Container of the "message" field - * - * @return true if message string was extracted successfully and set - * as a value of "message" field. - */ - static bool SetMessage(const NsSmartObjects::SmartObject& params, - Json::Value& id_container); +class FormatterJsonRpc : public CFormatterJsonBase { + public: + /** + * @brief No errors occurred during the parsing of the input JSON string. + */ + static const int32_t kSuccess = 0; + + /** + * @brief Input JSON string cannot be parsed. + */ + static const int32_t kParsingError = 1; + + /** + * @brief Input JSON string has invalid format. + */ + static const int32_t kInvalidFormat = 2; + + /** + * @brief Method in input JSON string is not + * specified or specified incorrectly. + */ + static const int32_t kMethodNotSpecified = 4; + + /** + * @brief Method is unknown. + */ + static const int32_t kUnknownMethod = 8; + + /** + * @brief Message type is unknown. + */ + static const int32_t kUnknownMessageType = 16; + + /** + * @brief Id of request or response is invalid. + */ + static const int32_t kInvalidId = 32; + + /** + * @brief Response code is not available. + */ + static const int32_t kResponseCodeNotAvailable = 64; + + /** + * @brief Message for error response is not available. + */ + static const int32_t kErrorResponseMessageNotAvailable = 128; + + /** + * @brief Creates a JSON string from a SmartObject. + * + * @param obj Input SmartObject. + * @param out_str Resulting JSON string. + * + * @return true if success, false otherwise. + */ + static bool ToString(const NsSmartObjects::SmartObject& obj, + std::string& out_str); + + /** + * @brief Creates a SmartObject from a JSON string. + * + * @tparam FunctionId Type of function id enumeration. + * @tparam MessageType Type of message type enumeration. + * + * @param str input JSON string. + * @param out The resulting SmartObject. + * + * @return An integer that is a bitwise-or of all error codes occurred + * during the parsing of the input string. 0 if no errors occurred. + */ + template <typename FunctionId, typename MessageType> + static int32_t FromString(const std::string& str, + NsSmartObjects::SmartObject& out); + + private: + /** + * @brief Request. + */ + static const char* kRequest; + + /** + * @brief Response. + */ + static const char* kResponse; + + /** + * @brief Notification. + */ + static const char* kNotification; + + /** + * @brief Error reponse. + */ + static const char* kErrorResponse; + + /** + * @brief Name of "jsonrpc" message field. + */ + static const char* kJsonRpc; + + /** + * @brief Expected value of "jsonrpc" message field ("2.0"). + */ + static const char* kJsonRpcExpectedValue; + + /** + * @brief Name of "id" message field. + */ + static const char* kId; + + /** + * @brief Name of "method" field. + */ + static const char* kMethod; + + /** + * @brief Name of "params" field. + */ + static const char* kParams; + + /** + * @brief Name of "result" field. + */ + static const char* kResult; + + /** + * @brief Name of "error" field. + */ + static const char* kError; + + /** + * @brief Name of "code" field. + */ + static const char* kCode; + + /** + * @brief Name of "data" field. + */ + static const char* kData; + + /** + * @brief Name of "message" field. + */ + static const char* kMessage; + + /** + * @brief Constructor. + */ + FormatterJsonRpc(); + + /** + * @brief Copy constructor. + * + * @param unused Unused parameter. + */ + FormatterJsonRpc(const FormatterJsonRpc& unused); + + /** + * @brief Parse function id. + * + * @tparam FunctionId Type of function id enumeration. + * + * @param method_value JSON value with function id. + * @param out The resulting SmartObject. + * + * @return An integer that is a bitwise-or of all error codes occurred + * during the parsing of the function id. 0 if no errors occurred. + */ + template <typename FunctionId> + static int32_t ParseFunctionId(const Json::Value& method_value, + NsSmartObjects::SmartObject& out); + + /** + * @brief Set method. + * + * Try to extract function id from the message object and set the "method" + * field of the container. + * + * @param params Message parameters object. + * @param method_container Container for the "method" field. + * + * @return true if function id was extracted successfully and set as a + * value of "method" field. + */ + static bool SetMethod(const NsSmartObjects::SmartObject& params, + Json::Value& method_container); + + /** + * @brief Set id. + * + * Try to extract request/response id from the message object and set the + * "id" field of the container. + * + * @param params Message parameters object. + * @param id_container Container for the "id" field. + * + * @return true if request/response id was extracted successfully and set + * as a value of "id" field. + */ + static bool SetId(const NsSmartObjects::SmartObject& params, + Json::Value& id_container); + + /** + * @brief Set message + * + * Try to extract message from response error object and set "message" field + *for the container + * + * @param params Message parameters object. + * @param id_container Container of the "message" field + * + * @return true if message string was extracted successfully and set + * as a value of "message" field. + */ + static bool SetMessage(const NsSmartObjects::SmartObject& params, + Json::Value& id_container); }; template <typename FunctionId, typename MessageType> int32_t FormatterJsonRpc::FromString(const std::string& str, - NsSmartObjects::SmartObject& out) { + NsSmartObjects::SmartObject& out) { int32_t result = kSuccess; try { - Json::Value root; - Json::Reader reader; - namespace strings = NsSmartDeviceLink::NsJSONHandler::strings; + Json::Value root; + Json::Reader reader; + namespace strings = NsSmartDeviceLink::NsJSONHandler::strings; - if (false == reader.parse(str, root)) { - result = kParsingError | kMethodNotSpecified | kUnknownMethod | - kUnknownMessageType; - } else { - if (false == root.isMember(kJsonRpc)) { - result |= kInvalidFormat; + if (false == reader.parse(str, root)) { + result = kParsingError | kMethodNotSpecified | kUnknownMethod | + kUnknownMessageType; } else { - const Json::Value& jsonRpcValue = root[kJsonRpc]; - - if ((false == jsonRpcValue.isString()) || - (jsonRpcValue.asString() != kJsonRpcExpectedValue)) { + if (false == root.isMember(kJsonRpc)) { result |= kInvalidFormat; + } else { + const Json::Value& jsonRpcValue = root[kJsonRpc]; + + if ((false == jsonRpcValue.isString()) || + (jsonRpcValue.asString() != kJsonRpcExpectedValue)) { + result |= kInvalidFormat; + } } - } - std::string message_type_string; - Json::Value response_value; - bool response_value_found = false; - bool is_error_response = false; + std::string message_type_string; + Json::Value response_value; + bool response_value_found = false; + bool is_error_response = false; - if (false == root.isMember(kId)) { - message_type_string = kNotification; + if (false == root.isMember(kId)) { + message_type_string = kNotification; - if (false == root.isMember(kMethod)) { - result |= kMethodNotSpecified | kUnknownMethod; - } else { - result |= ParseFunctionId<FunctionId>(root[kMethod], out); - } - out[strings::S_MSG_PARAMS] - = NsSmartObjects::SmartObject(NsSmartObjects::SmartType_Map); - } else { - const Json::Value& id_value = root[kId]; - - if (true == id_value.isString()) { - out[strings::S_PARAMS][strings::S_CORRELATION_ID] = - id_value.asString(); - } else if (true == id_value.isInt()) { - out[strings::S_PARAMS][strings::S_CORRELATION_ID] = - id_value.asInt(); - } else if (true == id_value.isDouble()) { - out[strings::S_PARAMS][strings::S_CORRELATION_ID] = - id_value.asDouble(); - } else if (true == id_value.isNull()) { - out[strings::S_PARAMS][strings::S_CORRELATION_ID] = - NsSmartObjects::SmartObject(NsSmartObjects::SmartType_Null); - } else { - result |= kInvalidFormat | kInvalidId; - } - - if (true == root.isMember(kMethod)) { - message_type_string = kRequest; - result |= ParseFunctionId<FunctionId>(root[kMethod], out); - out[strings::S_MSG_PARAMS] - = NsSmartObjects::SmartObject(NsSmartObjects::SmartType_Map); + if (false == root.isMember(kMethod)) { + result |= kMethodNotSpecified | kUnknownMethod; + } else { + result |= ParseFunctionId<FunctionId>(root[kMethod], out); + } + out[strings::S_MSG_PARAMS] = + NsSmartObjects::SmartObject(NsSmartObjects::SmartType_Map); } else { - Json::Value method_container; - bool method_container_found = false; - - if (true == root.isMember(kResult)) { - out[strings::S_MSG_PARAMS] - = NsSmartObjects::SmartObject(NsSmartObjects::SmartType_Map); - - message_type_string = kResponse; - response_value = root[kResult]; - response_value_found = true; - method_container = root[kResult]; - method_container_found = true; - } else if (true == root.isMember(kError)) { - out[strings::S_MSG_PARAMS] - = NsSmartObjects::SmartObject(NsSmartObjects::SmartType_Map); - message_type_string = kErrorResponse; - response_value = root[kError]; - response_value_found = true; - is_error_response = true; - - if (true == response_value.isObject()) { - if (true == response_value.isMember(kData)) { - method_container = response_value[kData]; - method_container_found = true; - } - } + const Json::Value& id_value = root[kId]; + + if (true == id_value.isString()) { + out[strings::S_PARAMS][strings::S_CORRELATION_ID] = + id_value.asString(); + } else if (true == id_value.isInt()) { + out[strings::S_PARAMS][strings::S_CORRELATION_ID] = id_value.asInt(); + } else if (true == id_value.isDouble()) { + out[strings::S_PARAMS][strings::S_CORRELATION_ID] = + id_value.asDouble(); + } else if (true == id_value.isNull()) { + out[strings::S_PARAMS][strings::S_CORRELATION_ID] = + NsSmartObjects::SmartObject(NsSmartObjects::SmartType_Null); } else { - result |= kUnknownMessageType; + result |= kInvalidFormat | kInvalidId; } - if (false == method_container_found) { - result |= kMethodNotSpecified | kUnknownMethod; - } else if (false == method_container.isObject()) { - result |= kInvalidFormat | kMethodNotSpecified | kUnknownMethod; + if (true == root.isMember(kMethod)) { + message_type_string = kRequest; + result |= ParseFunctionId<FunctionId>(root[kMethod], out); + out[strings::S_MSG_PARAMS] = + NsSmartObjects::SmartObject(NsSmartObjects::SmartType_Map); } else { - if (false == method_container.isMember(kMethod)) { + Json::Value method_container; + bool method_container_found = false; + + if (true == root.isMember(kResult)) { + out[strings::S_MSG_PARAMS] = + NsSmartObjects::SmartObject(NsSmartObjects::SmartType_Map); + + message_type_string = kResponse; + response_value = root[kResult]; + response_value_found = true; + method_container = root[kResult]; + method_container_found = true; + } else if (true == root.isMember(kError)) { + out[strings::S_MSG_PARAMS] = + NsSmartObjects::SmartObject(NsSmartObjects::SmartType_Map); + message_type_string = kErrorResponse; + response_value = root[kError]; + response_value_found = true; + is_error_response = true; + + if (true == response_value.isObject()) { + if (true == response_value.isMember(kData)) { + method_container = response_value[kData]; + method_container_found = true; + } + } + } else { + result |= kUnknownMessageType; + } + + if (false == method_container_found) { result |= kMethodNotSpecified | kUnknownMethod; + } else if (false == method_container.isObject()) { + result |= kInvalidFormat | kMethodNotSpecified | kUnknownMethod; } else { - result |= ParseFunctionId<FunctionId>(method_container[kMethod], - out); + if (false == method_container.isMember(kMethod)) { + result |= kMethodNotSpecified | kUnknownMethod; + } else { + result |= + ParseFunctionId<FunctionId>(method_container[kMethod], out); + } } } } - } - if (0 == (result & kUnknownMessageType)) { - MessageType message_type; + if (0 == (result & kUnknownMessageType)) { + MessageType message_type; - if (!NsSmartObjects::EnumConversionHelper<MessageType>::StringToEnum( - message_type_string, &message_type)) { - result |= kUnknownMessageType; - } else { - out[strings::S_PARAMS][strings::S_MESSAGE_TYPE] = message_type; + if (!NsSmartObjects::EnumConversionHelper<MessageType>::StringToEnum( + message_type_string, &message_type)) { + result |= kUnknownMessageType; + } else { + out[strings::S_PARAMS][strings::S_MESSAGE_TYPE] = message_type; + } } - } - if (true == root.isMember(kParams)) { - const Json::Value& params_value = root[kParams]; - - if (false == params_value.isObject()) { - result |= kInvalidFormat; - } else { - jsonValueToObj(root[kParams], out[strings::S_MSG_PARAMS]); - } - } else if (true == root.isMember(kResult)) { - const Json::Value& result_value = root[kResult]; + if (true == root.isMember(kParams)) { + const Json::Value& params_value = root[kParams]; - if (false == result_value.isObject()) { - result |= kInvalidFormat; - } else { - jsonValueToObj(root[kResult], out[strings::S_MSG_PARAMS]); - } - } else if (true == is_error_response) { - jsonValueToObj(response_value[kData], out[strings::S_PARAMS][kData]); - } + if (false == params_value.isObject()) { + result |= kInvalidFormat; + } else { + jsonValueToObj(root[kParams], out[strings::S_MSG_PARAMS]); + } + } else if (true == root.isMember(kResult)) { + const Json::Value& result_value = root[kResult]; - if ((kResponse == message_type_string) || - (kErrorResponse == message_type_string)) { - if (true == out.keyExists(strings::S_MSG_PARAMS)) { - out[strings::S_MSG_PARAMS].erase(kMethod); - out[strings::S_MSG_PARAMS].erase(kCode); + if (false == result_value.isObject()) { + result |= kInvalidFormat; + } else { + jsonValueToObj(root[kResult], out[strings::S_MSG_PARAMS]); + } + } else if (true == is_error_response) { + jsonValueToObj(response_value[kData], out[strings::S_PARAMS][kData]); } - if (false == response_value_found) { - result |= kResponseCodeNotAvailable; - } else { - if (false == response_value.isObject()) { - result |= kInvalidFormat | kResponseCodeNotAvailable; + if ((kResponse == message_type_string) || + (kErrorResponse == message_type_string)) { + if (true == out.keyExists(strings::S_MSG_PARAMS)) { + out[strings::S_MSG_PARAMS].erase(kMethod); + out[strings::S_MSG_PARAMS].erase(kCode); + } - if (true == is_error_response) { - result |= kErrorResponseMessageNotAvailable; - } + if (false == response_value_found) { + result |= kResponseCodeNotAvailable; } else { - if (false == response_value.isMember(kCode)) { - result |= kResponseCodeNotAvailable; - } else { - const Json::Value& code_value = response_value[kCode]; - - if (false == code_value.isInt()) { - result |= kInvalidFormat | kResponseCodeNotAvailable; - } else { - out[strings::S_PARAMS][strings::kCode] = code_value.asInt(); - } - } + if (false == response_value.isObject()) { + result |= kInvalidFormat | kResponseCodeNotAvailable; - if (true == is_error_response) { - if (false == response_value.isMember(kMessage)) { + if (true == is_error_response) { result |= kErrorResponseMessageNotAvailable; + } + } else { + if (false == response_value.isMember(kCode)) { + result |= kResponseCodeNotAvailable; } else { - const Json::Value& message_value = response_value[kMessage]; + const Json::Value& code_value = response_value[kCode]; - if (false == message_value.isString()) { + if (false == code_value.isInt()) { + result |= kInvalidFormat | kResponseCodeNotAvailable; + } else { + out[strings::S_PARAMS][strings::kCode] = code_value.asInt(); + } + } + + if (true == is_error_response) { + if (false == response_value.isMember(kMessage)) { result |= kErrorResponseMessageNotAvailable; } else { - out[strings::S_PARAMS][strings::kMessage] = - message_value.asString(); + const Json::Value& message_value = response_value[kMessage]; + + if (false == message_value.isString()) { + result |= kErrorResponseMessageNotAvailable; + } else { + out[strings::S_PARAMS][strings::kMessage] = + message_value.asString(); + } } } } } } } - } - out[strings::S_PARAMS][strings::S_PROTOCOL_TYPE] = 1; - out[strings::S_PARAMS][strings::S_PROTOCOL_VERSION] = 2; - } catch(...) { + out[strings::S_PARAMS][strings::S_PROTOCOL_TYPE] = 1; + out[strings::S_PARAMS][strings::S_PROTOCOL_VERSION] = 2; + } catch (...) { result = kParsingError; } @@ -469,7 +469,7 @@ int32_t FormatterJsonRpc::FromString(const std::string& str, template <typename FunctionId> int32_t FormatterJsonRpc::ParseFunctionId(const Json::Value& method_value, - NsSmartObjects::SmartObject& out) { + NsSmartObjects::SmartObject& out) { int32_t result = kSuccess; if (false == method_value.isString()) { @@ -478,7 +478,7 @@ int32_t FormatterJsonRpc::ParseFunctionId(const Json::Value& method_value, FunctionId function_id; if (!NsSmartObjects::EnumConversionHelper<FunctionId>::CStringToEnum( - method_value.asCString(), &function_id)) { + method_value.asCString(), &function_id)) { result |= kUnknownMethod; } else { namespace strings = NsSmartDeviceLink::NsJSONHandler::strings; @@ -494,4 +494,4 @@ int32_t FormatterJsonRpc::ParseFunctionId(const Json::Value& method_value, } // namespace NsJSONHandler } // namespace NsSmartDeviceLink -#endif // SMARTDEVICELINK_COMPONENTS_JSONHANDLER_INCLUDE_FORMATTERS_FORMATTER_JSON_RPC_H_ +#endif // SMARTDEVICELINK_COMPONENTS_JSONHANDLER_INCLUDE_FORMATTERS_FORMATTER_JSON_RPC_H_ diff --git a/src/components/formatters/include/formatters/generic_json_formatter.h b/src/components/formatters/include/formatters/generic_json_formatter.h index a4b3f3f712..580a49d73a 100644 --- a/src/components/formatters/include/formatters/generic_json_formatter.h +++ b/src/components/formatters/include/formatters/generic_json_formatter.h @@ -35,14 +35,14 @@ #ifndef SMARTDEVICELINK_COMPONENTS_FORMATTERS_INCLUDE_FORMATTERS_GENERIC_JSON_FORMATTER_H_ #define SMARTDEVICELINK_COMPONENTS_FORMATTERS_INCLUDE_FORMATTERS_GENERIC_JSON_FORMATTER_H_ -#include "CFormatterJsonBase.hpp" +#include "CFormatterJsonBase.h" namespace NsSmartDeviceLink { namespace NsJSONHandler { namespace Formatters { -class GenericJsonFormatter: public CFormatterJsonBase { -public: +class GenericJsonFormatter : public CFormatterJsonBase { + public: /** * @brief Creates a JSON string from a SmartObject. * @@ -64,8 +64,8 @@ public: NsSmartObjects::SmartObject& out); }; -} // namespace Formatters -} // namespace NsJSONHandler -} // namespace NsSmartDeviceLink +} // namespace Formatters +} // namespace NsJSONHandler +} // namespace NsSmartDeviceLink -#endif // SMARTDEVICELINK_COMPONENTS_FORMATTERS_INCLUDE_FORMATTERS_GENERIC_JSON_FORMATTER_H_ +#endif // SMARTDEVICELINK_COMPONENTS_FORMATTERS_INCLUDE_FORMATTERS_GENERIC_JSON_FORMATTER_H_ diff --git a/src/components/formatters/include/formatters/meta_formatter.h b/src/components/formatters/include/formatters/meta_formatter.h index f9fd6fad72..65b8c19863 100644 --- a/src/components/formatters/include/formatters/meta_formatter.h +++ b/src/components/formatters/include/formatters/meta_formatter.h @@ -44,7 +44,8 @@ namespace NsJSONHandler { namespace Formatters { /** - * @brief Formats to string the smart object against given schema for given formatter + * @brief Formats to string the smart object against given schema for given + *formatter * * Sample usage: * CSmartFactory factory; @@ -54,7 +55,6 @@ namespace Formatters { */ class CMetaFormatter { public: - /** * @brief Creates smart object by the given schema having copied * matched tree elements from original object. @@ -66,13 +66,13 @@ class CMetaFormatter { * @return true if successful, false - otherwise */ static bool CreateObjectByPattern( - const NsSmartDeviceLink::NsSmartObjects::SmartObject& object, - const NsSmartDeviceLink::NsSmartObjects::CSmartSchema& schema, - NsSmartDeviceLink::NsSmartObjects::SmartObject& result_object); + const NsSmartDeviceLink::NsSmartObjects::SmartObject& object, + const NsSmartDeviceLink::NsSmartObjects::CSmartSchema& schema, + NsSmartDeviceLink::NsSmartObjects::SmartObject& result_object); }; -}// namespace NsSmartDeviceLink -}// namespace NsSmartDeviceLink::NsJSONHandler -}// namespace NsSmartDeviceLink::NsJSONHandler::Formatters +} // namespace NsSmartDeviceLink +} // namespace NsSmartDeviceLink::NsJSONHandler +} // namespace NsSmartDeviceLink::NsJSONHandler::Formatters -#endif // __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS_METAFORMATTER_H__ +#endif // __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS_METAFORMATTER_H__ |