summaryrefslogtreecommitdiff
path: root/src/components/formatters
diff options
context:
space:
mode:
authorJustin Dickow <jjdickow@gmail.com>2014-10-20 17:44:41 -0400
committerJustin Dickow <jjdickow@gmail.com>2014-10-20 17:44:41 -0400
commit34e7256493ff0e6594029b9857d7e2aa31f5dbeb (patch)
tree367306b507c52d3af211533810adbc22004e0192 /src/components/formatters
parent2eef966e9b5fd4d94dd98820095eb765e200c64b (diff)
downloadsdl_core-34e7256493ff0e6594029b9857d7e2aa31f5dbeb.tar.gz
SDL 3.8!
Signed-off-by: Justin Dickow <jjdickow@gmail.com>
Diffstat (limited to 'src/components/formatters')
-rw-r--r--src/components/formatters/CMakeLists.txt25
-rw-r--r--src/components/formatters/include/formatters/CFormatterJsonBase.hpp122
-rw-r--r--src/components/formatters/include/formatters/CFormatterJsonSDLRPCv1.hpp235
-rw-r--r--src/components/formatters/include/formatters/CFormatterJsonSDLRPCv2.hpp176
-rw-r--r--src/components/formatters/include/formatters/CSmartFactory.hpp422
-rw-r--r--src/components/formatters/include/formatters/formatter_json_rpc.h497
-rw-r--r--src/components/formatters/include/formatters/generic_json_formatter.h71
-rw-r--r--src/components/formatters/include/formatters/meta_formatter.h78
-rw-r--r--src/components/formatters/src/CFormatterJsonBase.cpp118
-rw-r--r--src/components/formatters/src/CFormatterJsonSDLRPCv1.cpp157
-rw-r--r--src/components/formatters/src/CFormatterJsonSDLRPCv2.cpp106
-rw-r--r--src/components/formatters/src/CSmartFactory.cpp46
-rw-r--r--src/components/formatters/src/formatter_json_rpc.cc204
-rw-r--r--src/components/formatters/src/generic_json_formatter.cc63
-rw-r--r--src/components/formatters/src/meta_formatter.cc60
15 files changed, 2380 insertions, 0 deletions
diff --git a/src/components/formatters/CMakeLists.txt b/src/components/formatters/CMakeLists.txt
new file mode 100644
index 0000000000..3f53cf0b7f
--- /dev/null
+++ b/src/components/formatters/CMakeLists.txt
@@ -0,0 +1,25 @@
+include_directories (
+ ./include/
+ ../protocol_handler/include/
+ ../utils/include/
+ ${JSONCPP_INCLUDE_DIRECTORY}
+ ${MESSAGE_BROKER_INCLUDE_DIRECTORY}
+ ../../../src/components/smart_objects/include
+)
+
+set (SOURCES
+ ./src/CSmartFactory.cpp
+)
+
+set (FORMATTER_SOURCES
+ ./src/CFormatterJsonBase.cpp
+ ./src/CFormatterJsonSDLRPCv1.cpp
+ ./src/CFormatterJsonSDLRPCv2.cpp
+ ./src/formatter_json_rpc.cc
+ ./src/meta_formatter.cc
+ ./src/generic_json_formatter.cc
+)
+
+add_library("formatters" ${SOURCES}
+ ${FORMATTER_SOURCES}
+)
diff --git a/src/components/formatters/include/formatters/CFormatterJsonBase.hpp b/src/components/formatters/include/formatters/CFormatterJsonBase.hpp
new file mode 100644
index 0000000000..ef57d9b1b9
--- /dev/null
+++ b/src/components/formatters/include/formatters/CFormatterJsonBase.hpp
@@ -0,0 +1,122 @@
+/**
+ * @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.hpp
new file mode 100644
index 0000000000..03454395b0
--- /dev/null
+++ b/src/components/formatters/include/formatters/CFormatterJsonSDLRPCv1.hpp
@@ -0,0 +1,235 @@
+// 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 __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS__CFORMATTERJSONSDLRPCV1_HPP__
+#define __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS__CFORMATTERJSONSDLRPCV1_HPP__
+
+#include "json/json.h"
+
+#include "smart_objects/smart_object.h"
+#include "smart_objects/enum_schema_item.h"
+
+#include "CFormatterJsonBase.hpp"
+
+#include "formatters/CSmartFactory.hpp"
+#include "formatters/meta_formatter.h"
+
+namespace NsSmartDeviceLink {
+namespace NsJSONHandler {
+namespace Formatters {
+
+/**
+ * @brief Class is used to convert SmartObjects to JSON string and vice versa.
+ *
+ * JSON strings is in SDLRPCv1 format.
+ */
+class CFormatterJsonSDLRPCv1 : public CFormatterJsonBase {
+ private:
+ /**
+ * @brief Hidden constructor.
+ *
+ * The class contains only static methods. Should not be instantiated.
+ */
+ CFormatterJsonSDLRPCv1();
+
+ /**
+ * @brief Hidden copy constructor.
+ *
+ * The class contains only static methods. Should not be instantiated.
+ */
+ CFormatterJsonSDLRPCv1(const CFormatterJsonSDLRPCv1&);
+
+ /**
+ * @brief Extracts a message type from the SmartObject
+ */
+ static const std::string getMessageType(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& obj);
+
+ /**
+ * @brief Extracts a message type from the root JSON object.
+ *
+ * @return Type or empty string if there's no type in the JSON object.
+ */
+ static const std::string getMessageType(const Json::Value& root);
+
+ // SDLRPCv1 string consts
+
+ /**
+ * @brief String constant for REQUEST.
+ */
+ static const std::string S_REQUEST;
+
+ /**
+ * @brief String constant for RESPONSE.
+ */
+ static const std::string S_RESPONSE;
+
+ /**
+ * @brief String constant for NOTIFICATION.
+ */
+ static const std::string S_NOTIFICATION;
+
+ /**
+ * @brief String constant for PARAMETERS.
+ */
+ static const std::string S_PARAMETERS;
+
+ /**
+ * @brief String constant for NAME.
+ */
+ static const std::string S_NAME;
+
+ /**
+ * @brief String constant for CORRELATION_ID.
+ */
+ 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;
+
+ /**
+ * @brief Creates a JSON string from a SmartObject.
+ *
+ * @param obj input SmartObject
+ * @param outStr resulting JSON string
+ * @return true if success, false otherwise
+ */
+ static bool toString(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject &obj,
+ std::string& outStr);
+
+ /**
+ * @brief Creates a SmartObject from a JSON string.
+ *
+ * @param str input JSON string
+ * @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);
+
+ /**
+ * @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 outStr Resulting JSON string
+ * @return formatting error code
+ */
+ static tMetaFormatterErrorCode MetaFormatToString(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& object,
+ const NsSmartDeviceLink::NsSmartObjects::CSmartSchema& schema,
+ std::string& outStr);
+
+};
+
+// ----------------------------------------------------------------------------
+
+template<typename FunctionId, typename MessageType>
+int32_t Formatters::CFormatterJsonSDLRPCv1::fromString(
+ const std::string& str,
+ NsSmartDeviceLink::NsSmartObjects::SmartObject& out) {
+ int32_t result = kSuccess;
+
+ try {
+ Json::Value root;
+ Json::Reader reader;
+ std::string type;
+
+ if (false == reader.parse(str, root)) {
+ result = kParsingError | kMessageTypeNotFound | kFunctionIdNotFound
+ | kCorrelationIdNotFound;
+ }
+
+ if (kSuccess == result) {
+ type = getMessageType(root);
+ if (true == type.empty()) {
+ result = kMessageTypeNotFound | kFunctionIdNotFound
+ | kCorrelationIdNotFound;
+ }
+ }
+
+ FunctionId functionId = FunctionId::INVALID_ENUM;
+ 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 (kSuccess == result) {
+ if (!NsSmartObjects::EnumConversionHelper<FunctionId>::StringToEnum(root[type][S_NAME].asString(),
+ &functionId)) {
+ result = kFunctionIdNotFound;
+ functionId = FunctionId::INVALID_ENUM;
+ }
+ }
+
+ namespace S = NsSmartDeviceLink::NsJSONHandler::strings;
+
+ if (!(result & kMessageTypeNotFound)) {
+ jsonValueToObj(root[type][S_PARAMETERS], out[S::S_MSG_PARAMS]);
+
+ 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
+ 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_PROTOCOL_TYPE] = 0;
+ out[S::S_PARAMS][S::S_PROTOCOL_VERSION] = 1;
+ }
+ } catch (...) {
+ result = kParsingError;
+ }
+
+ return result;
+}
+
+}
+}
+} // namespace NsSmartDeviceLink::NsJSONHandler::Formatters
+
+#endif // __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS__CFORMATTERJSONSDLRPCV1_HPP__
diff --git a/src/components/formatters/include/formatters/CFormatterJsonSDLRPCv2.hpp b/src/components/formatters/include/formatters/CFormatterJsonSDLRPCv2.hpp
new file mode 100644
index 0000000000..3b4e206515
--- /dev/null
+++ b/src/components/formatters/include/formatters/CFormatterJsonSDLRPCv2.hpp
@@ -0,0 +1,176 @@
+// 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 __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS__CFORMATTERJSONSDLRPCV2_HPP__
+#define __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS__CFORMATTERJSONSDLRPCV2_HPP__
+
+#include "json/json.h"
+
+#include "smart_objects/smart_object.h"
+
+#include "CFormatterJsonBase.hpp"
+#include "formatters/CSmartFactory.hpp"
+
+namespace NsSmartDeviceLink {
+namespace NsJSONHandler {
+namespace Formatters {
+
+/**
+ * @brief Class is used to convert SmartObjects to JSON string and vice versa.
+ *
+ * JSON strings is in SDLRPCv2 format.
+ */
+class CFormatterJsonSDLRPCv2 : public CFormatterJsonBase {
+ private:
+
+ /**
+ * @brief Hidden constructor.
+ *
+ * The class contains only static methods. Should not be instantiated.
+ */
+ CFormatterJsonSDLRPCv2();
+
+ /**
+ * @brief Hidden copy constructor.
+ *
+ * The class contains only static methods. Should not be instantiated.
+ */
+ CFormatterJsonSDLRPCv2(const CFormatterJsonSDLRPCv2&);
+
+ public:
+
+ typedef NsSmartDeviceLink::NsJSONHandler::Formatters::meta_formatter_error_code::tMetaFormatterErrorCode tMetaFormatterErrorCode;
+
+ /**
+ * @brief Creates a JSON string from a SmartObject.
+ *
+ * @param obj input SmartObject
+ * @param outStr resulting JSON string
+ * @return true if success, false otherwise
+ */
+ static bool toString(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject &obj,
+ std::string& outStr);
+
+ /**
+ * @brief Creates a SmartObject from a JSON string.
+ *
+ * @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.
+ * @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);
+
+ /**
+ * @brief Creates a SmartObject from a JSON string.
+ *
+ * Version with CorrelationID.
+ *
+ * @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
+ * 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,
+ 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 outStr Resulting JSON string
+ * @return formatting error code
+ */
+ static tMetaFormatterErrorCode MetaFormatToString(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& object,
+ const NsSmartDeviceLink::NsSmartObjects::CSmartSchema& schema,
+ std::string& outStr);
+};
+
+template<typename FunctionId, typename MessageType>
+inline bool CFormatterJsonSDLRPCv2::fromString(
+ const std::string& str, NsSmartDeviceLink::NsSmartObjects::SmartObject& out,
+ FunctionId functionId, MessageType messageType) {
+ bool result = true;
+
+ try {
+ Json::Value root;
+ Json::Reader reader;
+
+ namespace strings = NsSmartDeviceLink::NsJSONHandler::strings;
+ bool result = reader.parse(str, root);
+
+ if (true == result) {
+ out[strings::S_PARAMS][strings::S_MESSAGE_TYPE] = messageType;
+ out[strings::S_PARAMS][strings::S_FUNCTION_ID] = functionId;
+ out[strings::S_PARAMS][strings::S_PROTOCOL_TYPE] = 0;
+ out[strings::S_PARAMS][strings::S_PROTOCOL_VERSION] = 2;
+
+ jsonValueToObj(root, out[strings::S_MSG_PARAMS]);
+ }
+ } catch (...) {
+ result = false;
+ }
+
+ return result;
+}
+
+template<typename FunctionId, typename MessageType>
+inline bool CFormatterJsonSDLRPCv2::fromString(
+ 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;
+
+ if (true == result) {
+ out[strings::S_PARAMS][strings::S_CORRELATION_ID] = correlationId;
+ }
+
+ return result;
+}
+
+}
+}
+} // namespace NsSmartDeviceLink::NsJSONHandler::Formatters
+
+#endif // __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS__CFORMATTERJSONSDLRPCV2_HPP__
diff --git a/src/components/formatters/include/formatters/CSmartFactory.hpp b/src/components/formatters/include/formatters/CSmartFactory.hpp
new file mode 100644
index 0000000000..7cefabaa74
--- /dev/null
+++ b/src/components/formatters/include/formatters/CSmartFactory.hpp
@@ -0,0 +1,422 @@
+/**
+ * @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.
+ *
+ * @return True if operation was successful or false otherwise.
+ */
+ bool attachSchema(NsSmartDeviceLink::NsSmartObjects::SmartObject& object);
+
+ /**
+ * @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)
+ {
+ 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);
+
+ 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);
+
+ 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);
+ 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
new file mode 100644
index 0000000000..26636f4a2b
--- /dev/null
+++ b/src/components/formatters/include/formatters/formatter_json_rpc.h
@@ -0,0 +1,497 @@
+/**
+ * @file formatter_json_rpc.h
+ * @brief FormatterJsonRpc 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 SMARTDEVICELINK_COMPONENTS_JSONHANDLER_INCLUDE_FORMATTERS_FORMATTER_JSON_RPC_H_
+#define SMARTDEVICELINK_COMPONENTS_JSONHANDLER_INCLUDE_FORMATTERS_FORMATTER_JSON_RPC_H_
+
+#include <string>
+#include <sys/stat.h>
+
+#include "smart_objects/smart_object.h"
+#include "smart_objects/enum_schema_item.h"
+#include "json/json.h"
+
+#include "CFormatterJsonBase.hpp"
+#include "formatters/CSmartFactory.hpp"
+
+namespace NsSmartDeviceLink {
+namespace NsJSONHandler {
+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);
+};
+
+template <typename FunctionId, typename MessageType>
+int32_t FormatterJsonRpc::FromString(const std::string& str,
+ NsSmartObjects::SmartObject& out) {
+ int32_t result = kSuccess;
+ try {
+ 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;
+ } 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;
+
+ 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);
+ } 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;
+ }
+ }
+ } else {
+ result |= kUnknownMessageType;
+ }
+
+ if (false == method_container_found) {
+ result |= kMethodNotSpecified | kUnknownMethod;
+ } else if (false == method_container.isObject()) {
+ result |= kInvalidFormat | kMethodNotSpecified | kUnknownMethod;
+ } else {
+ 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 (!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 (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 ((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 == response_value_found) {
+ result |= kResponseCodeNotAvailable;
+ } else {
+ if (false == response_value.isObject()) {
+ result |= kInvalidFormat | kResponseCodeNotAvailable;
+
+ if (true == is_error_response) {
+ result |= kErrorResponseMessageNotAvailable;
+ }
+ } 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 (true == is_error_response) {
+ if (false == response_value.isMember(kMessage)) {
+ result |= kErrorResponseMessageNotAvailable;
+ } else {
+ 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(...) {
+ result = kParsingError;
+ }
+
+ return result;
+}
+
+template <typename FunctionId>
+int32_t FormatterJsonRpc::ParseFunctionId(const Json::Value& method_value,
+ NsSmartObjects::SmartObject& out) {
+ int32_t result = kSuccess;
+
+ if (false == method_value.isString()) {
+ result |= kInvalidFormat | kUnknownMethod;
+ } else {
+ FunctionId function_id;
+
+ if (!NsSmartObjects::EnumConversionHelper<FunctionId>::CStringToEnum(
+ method_value.asCString(), &function_id)) {
+ result |= kUnknownMethod;
+ } else {
+ namespace strings = NsSmartDeviceLink::NsJSONHandler::strings;
+
+ out[strings::S_PARAMS][strings::S_FUNCTION_ID] = function_id;
+ }
+ }
+
+ return result;
+}
+
+} // namespace Formatters
+} // namespace NsJSONHandler
+} // namespace NsSmartDeviceLink
+
+#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
new file mode 100644
index 0000000000..3eaee0b36e
--- /dev/null
+++ b/src/components/formatters/include/formatters/generic_json_formatter.h
@@ -0,0 +1,71 @@
+/**
+ * @file generic_json_formatter.h
+ * @brief Generic JSON formatter 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 SMARTDEVICELINK_COMPONENTS_FORMATTERS_INCLUDE_FORMATTERS_GENERIC_JSON_FORMATTER_H_
+#define SMARTDEVICELINK_COMPONENTS_FORMATTERS_INCLUDE_FORMATTERS_GENERIC_JSON_FORMATTER_H_
+
+#include "CFormatterJsonBase.hpp"
+
+namespace NsSmartDeviceLink {
+namespace NsJSONHandler {
+namespace Formatters {
+
+class GenericJsonFormatter: public CFormatterJsonBase {
+public:
+ /**
+ * @brief Creates a JSON string from a SmartObject.
+ *
+ * @param obj Input SmartObject.
+ * @param out_str Resulting JSON string.
+ */
+ static void ToString(const NsSmartObjects::SmartObject& obj,
+ std::string& out_str);
+
+ /**
+ * @brief Creates a SmartObject from a JSON string.
+ *
+ * @param str input JSON string.
+ * @param out The resulting SmartObject.
+ *
+ * @return true if success, false otherwise.
+ */
+ static bool FromString(const std::string& str,
+ NsSmartObjects::SmartObject& out);
+};
+
+} // namespace Formatters
+} // namespace NsJSONHandler
+} // namespace NsSmartDeviceLink
+
+#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
new file mode 100644
index 0000000000..c1b767d7cf
--- /dev/null
+++ b/src/components/formatters/include/formatters/meta_formatter.h
@@ -0,0 +1,78 @@
+/**
+ * @file meta_fromatter.h
+ * @brief file describes class CMetaFormatter which is designed to format
+ * the smart object against given schema for given formatter
+ */
+// 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 __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS_METAFORMATTER_H__
+#define __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS_METAFORMATTER_H__
+
+#include "smart_objects/smart_object.h"
+#include "smart_objects/smart_schema.h"
+
+namespace NsSmartDeviceLink {
+namespace NsJSONHandler {
+namespace Formatters {
+
+/**
+ * @brief Formats to string the smart object against given schema for given formatter
+ *
+ * Sample usage:
+ * CSmartFactory factory;
+ * SmartObject object;
+ * CSmartSchmema schema;
+ *
+ */
+class CMetaFormatter {
+ public:
+
+ /**
+ * @brief Creates smart object by the given schema having copied
+ * matched tree elements from original object.
+ *
+ * @param object Original smart object which macthed tree elements
+ * will be copied from
+ * @param schema Smart schema which describes result smart object
+ * @param result_object createdsmart object
+ * @return true if successful, false - otherwise
+ */
+ static bool CreateObjectByPattern(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& object,
+ const NsSmartDeviceLink::NsSmartObjects::CSmartSchema& schema,
+ NsSmartDeviceLink::NsSmartObjects::SmartObject& result_object);
+};
+
+}// namespace NsSmartDeviceLink
+}// namespace NsSmartDeviceLink::NsJSONHandler
+}// namespace NsSmartDeviceLink::NsJSONHandler::Formatters
+
+#endif // __SMARTDEVICELINKCORE_JSONHANDLER_FORMATTERS_METAFORMATTER_H__
diff --git a/src/components/formatters/src/CFormatterJsonBase.cpp b/src/components/formatters/src/CFormatterJsonBase.cpp
new file mode 100644
index 0000000000..64a60e4f8f
--- /dev/null
+++ b/src/components/formatters/src/CFormatterJsonBase.cpp
@@ -0,0 +1,118 @@
+/**
+ * @file CFormatterJsonBase.cpp
+ * @brief CFormatterJsonBase source 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.
+#include "json/json.h"
+
+#include "formatters/CFormatterJsonBase.hpp"
+
+void NsSmartDeviceLink::NsJSONHandler::Formatters::CFormatterJsonBase::jsonValueToObj(
+ const Json::Value& value,
+ NsSmartDeviceLink::NsSmartObjects::SmartObject& obj) {
+ try {
+ if (value.type() == Json::objectValue) {
+ obj = NsSmartDeviceLink::NsSmartObjects::SmartObject(
+ NsSmartDeviceLink::NsSmartObjects::SmartType_Map);
+
+ Json::Value::Members members = value.getMemberNames();
+
+ for (uint32_t i = 0; i < members.size(); i++) {
+ jsonValueToObj(value[members[i]], obj[members[i]]);
+ }
+ } else if (value.type() == Json::arrayValue) {
+ obj = NsSmartDeviceLink::NsSmartObjects::SmartObject(
+ NsSmartDeviceLink::NsSmartObjects::SmartType_Array);
+
+ for (uint32_t i = 0; i < value.size(); i++) {
+ jsonValueToObj(value[i], obj[i]);
+ }
+ } else if (value.type() == Json::intValue
+ || value.type() == Json::uintValue) {
+ obj = value.asInt();
+ } else if (value.type() == Json::realValue) {
+ obj = value.asDouble();
+ } else if (value.type() == Json::booleanValue) {
+ obj = value.asBool();
+ } else if (value.type() == Json::stringValue) {
+ obj = value.asString();
+ }
+ } catch (...) {
+ }
+}
+
+// ----------------------------------------------------------------------------
+
+void NsSmartDeviceLink::NsJSONHandler::Formatters::CFormatterJsonBase::objToJsonValue(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject &obj,
+ Json::Value &item) {
+ try {
+ if (NsSmartDeviceLink::NsSmartObjects::SmartType_Array == obj.getType()) {
+ item = Json::arrayValue;
+
+ for (uint32_t i = 0; i < obj.length(); i++) {
+ Json::Value value(Json::nullValue);
+
+ objToJsonValue(obj.getElement(i), value);
+
+ item.append(value);
+ }
+ } else if (NsSmartDeviceLink::NsSmartObjects::SmartType_Map
+ == obj.getType()) {
+ item = Json::objectValue;
+ std::set<std::string> keys = obj.enumerate();
+
+ for (std::set<std::string>::const_iterator key = keys.begin();
+ key != keys.end(); key++) {
+ Json::Value value(Json::nullValue);
+
+ objToJsonValue(obj.getElement(*key), value);
+
+ item[*key] = value;
+ }
+ } else if (NsSmartDeviceLink::NsSmartObjects::SmartType_Boolean
+ == obj.getType()) {
+ item = obj.asBool();
+ } else if (NsSmartDeviceLink::NsSmartObjects::SmartType_Integer
+ == obj.getType()) {
+ item = obj.asInt();
+ } else if (NsSmartDeviceLink::NsSmartObjects::SmartType_Double
+ == obj.getType()) {
+ item = obj.asDouble();
+ } else if (NsSmartDeviceLink::NsSmartObjects::SmartType_Null
+ == obj.getType()) {
+ item = Json::nullValue;
+ } else {
+ item = obj.asString();
+ }
+ } catch (...) {
+ }
+}
diff --git a/src/components/formatters/src/CFormatterJsonSDLRPCv1.cpp b/src/components/formatters/src/CFormatterJsonSDLRPCv1.cpp
new file mode 100644
index 0000000000..407a001883
--- /dev/null
+++ b/src/components/formatters/src/CFormatterJsonSDLRPCv1.cpp
@@ -0,0 +1,157 @@
+// 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.
+#include "formatters/CFormatterJsonSDLRPCv1.hpp"
+#include "formatters/meta_formatter.h"
+
+namespace strings = NsSmartDeviceLink::NsJSONHandler::strings;
+namespace smart_objects_ns = NsSmartDeviceLink::NsSmartObjects;
+
+namespace NsSmartDeviceLink {
+namespace NsJSONHandler {
+namespace Formatters {
+
+// ----------------------------------------------------------------------------
+
+const std::string CFormatterJsonSDLRPCv1::S_REQUEST("request");
+const std::string CFormatterJsonSDLRPCv1::S_RESPONSE("response");
+const std::string CFormatterJsonSDLRPCv1::S_NOTIFICATION("notification");
+const std::string CFormatterJsonSDLRPCv1::S_PARAMETERS("parameters");
+const std::string CFormatterJsonSDLRPCv1::S_NAME("name");
+const std::string CFormatterJsonSDLRPCv1::S_CORRELATION_ID("correlationID");
+
+const int32_t CFormatterJsonSDLRPCv1::kSuccess = 0;
+const int32_t CFormatterJsonSDLRPCv1::kParsingError = 1 << 0;
+const int32_t CFormatterJsonSDLRPCv1::kFunctionIdNotFound = 1 << 1;
+const int32_t CFormatterJsonSDLRPCv1::kMessageTypeNotFound = 1 << 2;
+const int32_t CFormatterJsonSDLRPCv1::kCorrelationIdNotFound = 1 << 3;
+// ----------------------------------------------------------------------------
+
+const std::string CFormatterJsonSDLRPCv1::getMessageType(
+ const smart_objects_ns::SmartObject& obj) {
+ return obj.getElement(strings::S_PARAMS).getElement(strings::S_MESSAGE_TYPE)
+ .asString();
+}
+
+// ----------------------------------------------------------------------------
+
+const std::string CFormatterJsonSDLRPCv1::getMessageType(
+ const Json::Value& root) {
+ std::string type;
+
+ if (true == root.isMember(S_REQUEST)) {
+ type = S_REQUEST;
+ } else if (true == root.isMember(S_RESPONSE)) {
+ type = S_RESPONSE;
+ } else if (true == root.isMember(S_NOTIFICATION)) {
+ type = S_NOTIFICATION;
+ } else {
+ }
+
+ return type;
+}
+
+// ----------------------------------------------------------------------------
+
+bool CFormatterJsonSDLRPCv1::toString(const smart_objects_ns::SmartObject& obj,
+ std::string& outStr) {
+ bool result = false;
+ try {
+ Json::Value root(Json::objectValue);
+ Json::Value params(Json::objectValue);
+
+ smart_objects_ns::SmartObject formattedObj(obj);
+ formattedObj.getSchema().unapplySchema(formattedObj); // converts enums(as int32_t) to strings
+
+ objToJsonValue(formattedObj.getElement(strings::S_MSG_PARAMS), params);
+
+ std::string type = getMessageType(formattedObj);
+ root[type] = Json::Value(Json::objectValue);
+ root[type][S_PARAMETERS] = params;
+
+ if (formattedObj[strings::S_PARAMS].keyExists(strings::S_CORRELATION_ID)) {
+ root[type][S_CORRELATION_ID] =
+ formattedObj[strings::S_PARAMS][strings::S_CORRELATION_ID].asInt();
+ }
+
+ root[type][S_NAME] = formattedObj[strings::S_PARAMS][strings::S_FUNCTION_ID]
+ .asString();
+
+ outStr = root.toStyledString();
+
+ result = true;
+ } catch (...) {
+ result = false;
+ }
+
+ return result;
+}
+
+// ----------------------------------------------------------------------------
+
+CFormatterJsonSDLRPCv1::tMetaFormatterErrorCode CFormatterJsonSDLRPCv1::MetaFormatToString(
+ const smart_objects_ns::SmartObject& object,
+ const smart_objects_ns::CSmartSchema& schema, std::string& outStr) {
+ meta_formatter_error_code::tMetaFormatterErrorCode result_code =
+ meta_formatter_error_code::kErrorOk;
+
+ smart_objects_ns::SmartObject tmp_object;
+
+ if (false
+ == CMetaFormatter::CreateObjectByPattern(object, schema, tmp_object)) {
+ result_code |= meta_formatter_error_code::kErrorFailedCreateObjectBySchema;
+ return result_code;
+ }
+
+ // determine whether smart objects are functions
+ // (in terms of SDLRPC communication)
+ bool is_root_object_created_by_schema = ((tmp_object.getType()
+ == smart_objects_ns::SmartType_Map)
+ && tmp_object.keyExists(strings::S_PARAMS)
+ && tmp_object.keyExists(strings::S_MSG_PARAMS));
+
+ bool is_root_object = ((object.getType() == smart_objects_ns::SmartType_Map)
+ && object.keyExists(strings::S_PARAMS)
+ && object.keyExists(strings::S_MSG_PARAMS));
+
+ if (false == is_root_object) {
+ result_code |= meta_formatter_error_code::kErrorObjectIsNotFunction;
+ }
+ if (false == is_root_object_created_by_schema) {
+ result_code |= meta_formatter_error_code::kErrorSchemaIsNotFunction;
+ }
+
+ CFormatterJsonSDLRPCv1::toString(tmp_object, outStr);
+
+ return result_code;
+}
+
+}
+}
+}
diff --git a/src/components/formatters/src/CFormatterJsonSDLRPCv2.cpp b/src/components/formatters/src/CFormatterJsonSDLRPCv2.cpp
new file mode 100644
index 0000000000..d76e28911c
--- /dev/null
+++ b/src/components/formatters/src/CFormatterJsonSDLRPCv2.cpp
@@ -0,0 +1,106 @@
+// 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.
+
+#include "formatters/CFormatterJsonSDLRPCv2.hpp"
+#include "formatters/meta_formatter.h"
+
+namespace smart_objects_ns = NsSmartDeviceLink::NsSmartObjects;
+namespace strings = NsSmartDeviceLink::NsJSONHandler::strings;
+
+namespace NsSmartDeviceLink {
+namespace NsJSONHandler {
+namespace Formatters {
+
+// ----------------------------------------------------------------------------
+
+bool CFormatterJsonSDLRPCv2::toString(const smart_objects_ns::SmartObject& obj,
+ std::string& outStr) {
+ bool result = true;
+ try {
+ Json::Value root(Json::objectValue);
+
+ smart_objects_ns::SmartObject formattedObj(obj);
+ formattedObj.getSchema().unapplySchema(formattedObj); // converts enums(as int32_t) to strings
+
+ objToJsonValue(formattedObj.getElement(strings::S_MSG_PARAMS), root);
+
+ outStr = root.toStyledString();
+
+ result = true;
+ } catch (...) {
+ result = false;
+ }
+
+ return result;
+}
+
+// ----------------------------------------------------------------------------
+
+CFormatterJsonSDLRPCv2::tMetaFormatterErrorCode CFormatterJsonSDLRPCv2::MetaFormatToString(
+ const smart_objects_ns::SmartObject& object,
+ const smart_objects_ns::CSmartSchema& schema, std::string& outStr) {
+
+ meta_formatter_error_code::tMetaFormatterErrorCode result_code =
+ meta_formatter_error_code::kErrorOk;
+
+ smart_objects_ns::SmartObject tmp_object;
+
+ if (false
+ == CMetaFormatter::CreateObjectByPattern(object, schema, tmp_object)) {
+ result_code |= meta_formatter_error_code::kErrorFailedCreateObjectBySchema;
+ return result_code;
+ }
+
+ // determine whether smart objects are functions
+ // (in terms of SDLRPC communication)
+ bool is_root_object_created_by_schema = ((tmp_object.getType()
+ == smart_objects_ns::SmartType_Map)
+ && tmp_object.keyExists(strings::S_PARAMS)
+ && tmp_object.keyExists(strings::S_MSG_PARAMS));
+
+ bool is_root_object = ((object.getType() == smart_objects_ns::SmartType_Map)
+ && object.keyExists(strings::S_PARAMS)
+ && object.keyExists(strings::S_MSG_PARAMS));
+
+ if (false == is_root_object) {
+ result_code |= meta_formatter_error_code::kErrorObjectIsNotFunction;
+ }
+ if (false == is_root_object_created_by_schema) {
+ result_code |= meta_formatter_error_code::kErrorSchemaIsNotFunction;
+ }
+
+ CFormatterJsonSDLRPCv2::toString(tmp_object, outStr);
+
+ return result_code;
+}
+
+}
+}
+}
diff --git a/src/components/formatters/src/CSmartFactory.cpp b/src/components/formatters/src/CSmartFactory.cpp
new file mode 100644
index 0000000000..363db7696e
--- /dev/null
+++ b/src/components/formatters/src/CSmartFactory.cpp
@@ -0,0 +1,46 @@
+/**
+ * @file CSmartFactory.cpp
+ * @brief CSmartFactory source 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.
+
+#include "formatters/CSmartFactory.hpp"
+
+const std::string NsSmartDeviceLink::NsJSONHandler::strings::S_MSG_PARAMS("msg_params");
+const std::string NsSmartDeviceLink::NsJSONHandler::strings::S_PARAMS("params");
+const std::string NsSmartDeviceLink::NsJSONHandler::strings::S_FUNCTION_ID("function_id");
+const std::string NsSmartDeviceLink::NsJSONHandler::strings::S_MESSAGE_TYPE("message_type");
+const std::string NsSmartDeviceLink::NsJSONHandler::strings::S_PROTOCOL_VERSION("protocol_version");
+const std::string NsSmartDeviceLink::NsJSONHandler::strings::S_PROTOCOL_TYPE("protocol_type");
+const std::string NsSmartDeviceLink::NsJSONHandler::strings::S_CORRELATION_ID("correlation_id");
+const std::string NsSmartDeviceLink::NsJSONHandler::strings::kCode("code");
+const std::string NsSmartDeviceLink::NsJSONHandler::strings::kMessage(
+ "message");
diff --git a/src/components/formatters/src/formatter_json_rpc.cc b/src/components/formatters/src/formatter_json_rpc.cc
new file mode 100644
index 0000000000..8722df46df
--- /dev/null
+++ b/src/components/formatters/src/formatter_json_rpc.cc
@@ -0,0 +1,204 @@
+/**
+ * @file formatter_json_rpc.cc
+ * @brief formatter_json_rpc source 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.
+
+#include "formatters/formatter_json_rpc.h"
+
+namespace NsSmartDeviceLink {
+namespace NsJSONHandler {
+namespace Formatters {
+
+namespace strings = NsJSONHandler::strings;
+
+const char *FormatterJsonRpc::kRequest = "request";
+const char *FormatterJsonRpc::kResponse = "response";
+const char *FormatterJsonRpc::kNotification = "notification";
+const char *FormatterJsonRpc::kErrorResponse = "error_response";
+const char *FormatterJsonRpc::kJsonRpc = "jsonrpc";
+const char *FormatterJsonRpc::kJsonRpcExpectedValue = "2.0";
+const char *FormatterJsonRpc::kId = "id";
+const char *FormatterJsonRpc::kMethod = "method";
+const char *FormatterJsonRpc::kParams = "params";
+const char *FormatterJsonRpc::kResult = "result";
+const char *FormatterJsonRpc::kError = "error";
+const char *FormatterJsonRpc::kCode = "code";
+const char *FormatterJsonRpc::kData = "data";
+const char *FormatterJsonRpc::kMessage = "message";
+
+bool FormatterJsonRpc::ToString(const NsSmartObjects::SmartObject &obj,
+ std::string &out_str) {
+ bool result = true;
+ try {
+ Json::Value root(Json::objectValue);
+
+ root[kJsonRpc] = kJsonRpcExpectedValue;
+
+ NsSmartObjects::SmartObject formatted_object(obj);
+ Json::Value msg_params_json(Json::objectValue);
+ formatted_object.getSchema().unapplySchema(formatted_object);
+
+ bool is_message_params = formatted_object.keyExists(strings::S_MSG_PARAMS);
+ bool empty_message_params = true;
+ if (true == is_message_params) {
+ const NsSmartObjects::SmartObject &msg_params = formatted_object
+ .getElement(strings::S_MSG_PARAMS);
+
+ result = (NsSmartObjects::SmartType_Map == msg_params.getType());
+ if (true == result) {
+ objToJsonValue(msg_params, msg_params_json);
+ }
+ if (0 < msg_params.length()) {
+ empty_message_params = false;
+ }
+ }
+
+ if (false == formatted_object.keyExists(strings::S_PARAMS)) {
+ result = false;
+ } else {
+ const NsSmartObjects::SmartObject &params = formatted_object.getElement(
+ strings::S_PARAMS);
+ if (NsSmartObjects::SmartType_Map != params.getType()) {
+ result = false;
+ } else {
+ const NsSmartObjects::SmartObject &message_type_object = params
+ .getElement(strings::S_MESSAGE_TYPE);
+
+ if (NsSmartObjects::SmartType_String != message_type_object.getType()) {
+ result = false;
+ } else {
+ const std::string message_type = message_type_object.asString();
+
+ if (kRequest == message_type) {
+ if (false == empty_message_params) {
+ root[kParams] = msg_params_json;
+ }
+ result = result && SetMethod(params, root);
+ result = result && SetId(params, root);
+ } else if (kResponse == message_type) {
+ root[kResult] = msg_params_json;
+ result = result && SetMethod(params, root[kResult]);
+ result = result && SetId(params, root);
+
+ if (false == params.keyExists(strings::kCode)) {
+ result = false;
+ } else {
+ const NsSmartObjects::SmartObject &code = params.getElement(
+ strings::kCode);
+
+ if (NsSmartObjects::SmartType_Integer != code.getType()) {
+ result = false;
+ } else {
+ root[kResult][kCode] = code.asInt();
+ }
+ }
+ } else if (kNotification == message_type) {
+ root[kParams] = msg_params_json;
+ result = result && SetMethod(params, root);
+ } else if (kErrorResponse == message_type) {
+ result = result && SetId(params, root);
+ result = result && SetMethod(params, root[kError][kData]);
+ result = result && SetMessage(params, root[kError]);
+
+ const NsSmartObjects::SmartObject &code = params.getElement(
+ strings::kCode);
+ if (NsSmartObjects::SmartType_Integer != code.getType()) {
+ result = false;
+ } else {
+ root[kError][kCode] = code.asInt();
+ }
+ }
+ }
+ }
+ }
+ out_str = root.toStyledString();
+ } catch (...) {
+ result = false;
+ }
+
+ return result;
+}
+
+bool FormatterJsonRpc::SetMethod(const NsSmartObjects::SmartObject &params,
+ Json::Value &method_container) {
+ bool result = false;
+
+ if (true == params.keyExists(strings::S_FUNCTION_ID)) {
+ const NsSmartObjects::SmartObject &function_id =
+ params.getElement(strings::S_FUNCTION_ID);
+
+ if (NsSmartObjects::SmartType_String == function_id.getType()) {
+ method_container[kMethod] = function_id.asString();
+ result = true;
+ }
+ }
+
+ return result;
+}
+
+bool FormatterJsonRpc::SetId(const NsSmartObjects::SmartObject &params,
+ Json::Value &id_container) {
+ bool result = false;
+
+ if (true == params.keyExists(strings::S_CORRELATION_ID)) {
+ const NsSmartObjects::SmartObject &id = params.getElement(
+ strings::S_CORRELATION_ID);
+
+ if (NsSmartObjects::SmartType_Integer == id.getType()) {
+ id_container[kId] = id.asUInt();
+ result = true;
+ }
+ }
+
+ return result;
+}
+
+bool FormatterJsonRpc::SetMessage(const NsSmartObjects::SmartObject &params,
+ Json::Value &message_container) {
+ bool result = false;
+
+ if (true == params.keyExists(strings::kMessage)) {
+ const NsSmartObjects::SmartObject &message = params.getElement(
+ strings::kMessage);
+
+ if (NsSmartObjects::SmartType_String == message.getType()) {
+ message_container[kMessage] = message.asString();
+ result = true;
+ }
+ }
+
+ return result;
+}
+
+} // namespace Formatters
+} // namespace NsJSONHandler
+} // namespace NsSmartDeviceLink
diff --git a/src/components/formatters/src/generic_json_formatter.cc b/src/components/formatters/src/generic_json_formatter.cc
new file mode 100644
index 0000000000..ce1aa03807
--- /dev/null
+++ b/src/components/formatters/src/generic_json_formatter.cc
@@ -0,0 +1,63 @@
+/**
+ * @file generic_json_formatter.cc
+ * @brief Generic JSON formatter source 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.
+
+#include "formatters/generic_json_formatter.h"
+
+namespace NsSmartDeviceLink {
+namespace NsJSONHandler {
+namespace Formatters {
+
+void GenericJsonFormatter::ToString(const NsSmartObjects::SmartObject& obj,
+ std::string& out_str) {
+ Json::Value json_root;
+ objToJsonValue(obj, json_root);
+ out_str = json_root.toStyledString();
+}
+
+bool GenericJsonFormatter::FromString(const std::string& str,
+ NsSmartObjects::SmartObject& out) {
+ Json::Value json_root;
+ Json::Reader reader;
+ bool result = reader.parse(str, json_root);
+
+ if (true == result) {
+ jsonValueToObj(json_root, out);
+ }
+
+ return result;
+}
+
+} // namespace Formatters
+} // namespace NsJSONHandler
+} // namespace NsSmartDeviceLink
diff --git a/src/components/formatters/src/meta_formatter.cc b/src/components/formatters/src/meta_formatter.cc
new file mode 100644
index 0000000000..145020a5e2
--- /dev/null
+++ b/src/components/formatters/src/meta_formatter.cc
@@ -0,0 +1,60 @@
+/**
+ * @file meta_fromatter.cc
+ * @brief implementation of class CMetaFormatter which is designed to format
+ * the smart object against given schema for given formatter
+ */
+// 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.auto
+
+#include <set>
+#include <string>
+
+#include "formatters/meta_formatter.h"
+
+namespace formatter_ns = NsSmartDeviceLink::NsJSONHandler::Formatters;
+namespace smart_objects_ns = NsSmartDeviceLink::NsSmartObjects;
+
+//---------------------------------------------------------------
+
+bool formatter_ns::CMetaFormatter::CreateObjectByPattern(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& object,
+ const NsSmartDeviceLink::NsSmartObjects::CSmartSchema& schema,
+ NsSmartDeviceLink::NsSmartObjects::SmartObject& result_object) {
+
+ if (smart_objects_ns::SmartType_Invalid == result_object.getType()) {
+ return false;
+ }
+
+ schema.BuildObjectBySchema(object, result_object);
+
+ result_object.setSchema(schema);
+
+ return true;
+}