summaryrefslogtreecommitdiff
path: root/SDL_Core/src/components/policies/include
diff options
context:
space:
mode:
authorJustin Dickow <jjdickow@gmail.com>2014-03-18 13:46:46 -0400
committerJustin Dickow <jjdickow@gmail.com>2014-03-18 13:46:46 -0400
commitba492fb83c258bc60ca68120ce964a95b41133b5 (patch)
treeaf99c087941d65a19831397c1ec5eb34850cfc7f /SDL_Core/src/components/policies/include
parent8504605b01177da2e55bee6abe4c3f20c82da379 (diff)
downloadsmartdevicelink-ba492fb83c258bc60ca68120ce964a95b41133b5.tar.gz
initial commit for API 3.0 (replaced all)
Diffstat (limited to 'SDL_Core/src/components/policies/include')
-rw-r--r--SDL_Core/src/components/policies/include/policies/permissions_calculator.h140
-rw-r--r--SDL_Core/src/components/policies/include/policies/policy_configuration.h96
-rw-r--r--SDL_Core/src/components/policies/include/policies/policy_manager.h197
-rw-r--r--SDL_Core/src/components/policies/include/policies/policy_manager_impl.h126
-rw-r--r--SDL_Core/src/components/policies/include/policies/policy_table.h129
-rw-r--r--SDL_Core/src/components/policies/include/policies/policy_table_schema.h202
-rw-r--r--SDL_Core/src/components/policies/include/policies/preloaded_pt_schema.h75
7 files changed, 965 insertions, 0 deletions
diff --git a/SDL_Core/src/components/policies/include/policies/permissions_calculator.h b/SDL_Core/src/components/policies/include/policies/permissions_calculator.h
new file mode 100644
index 000000000..c96ebaac4
--- /dev/null
+++ b/SDL_Core/src/components/policies/include/policies/permissions_calculator.h
@@ -0,0 +1,140 @@
+/**
+ * @file permissions_calculator.h
+ * @brief Permissions calculator 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 SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_PERMISSIONS_CALCULATOR_H_
+#define SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_PERMISSIONS_CALCULATOR_H_
+
+#include <vector>
+#include <string>
+#include "policies/policy_manager.h"
+#include "interfaces/MOBILE_API.h"
+#include "utils/logger.h"
+
+namespace policies {
+
+class PermissionsCalculator {
+ public:
+ /**
+ * @brief Calculate permissions for application.
+ *
+ * @param pt_object Policy Table as smart object
+ * @param app_id Application identifier
+ * @param rpc Remote procedure call
+ * @param hmi_status HMI level status
+ *
+ * @return result of check permission
+ */
+ static PermissionResult CalcPermissions(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& pt_object,
+ uint32_t app_id,
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& rpc,
+ mobile_apis::HMILevel::eType hmi_status);
+
+ /**
+ * @brief Get priority for app_id
+ *
+ * @param pt_object Policy Table as smart object
+ * @param app_id Application Id
+ *
+ * @return priority for app_id
+ */
+ static Priority::eType GetPriority(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& pt_object,
+ uint32_t app_id);
+
+ private:
+ /**
+ * @brief Find all RPCs in groups listed under section functional_groupings
+ *
+ * @param pt_object Policy Table as smart object
+ * @param rpc_groups Groups of RPCs
+ * @param rpc Remote procedure call
+ * @param hmi_status HMI level status
+ *
+ * @return Map of rpc to all possible HMI levels amongst all
+ * functional groups where RPC is found.
+ * Returned value must be freed by the caller.
+ */
+ static PermissionResult CalcPermissionsByGroups(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& pt_object,
+ const std::vector<std::string>& rpc_groups,
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& rpc,
+ mobile_apis::HMILevel::eType hmi_status);
+
+ /**
+ * @brief Returns a smart object containing an <app_id> section of PolicyTable
+ *
+ * If app_id is not found in the "app_policies" the "default" section is
+ * returned.
+ * @param pt_object Policy Table as a SmartObject
+ * @param app_id Application ID
+ *
+ * @return SmartObject that contains either <app_id> or "default" section
+ * of "app_policies".
+ */
+ static const NsSmartDeviceLink::NsSmartObjects::SmartObject&
+ GetPolicyTableAppIdSection(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& pt_object,
+ uint32_t app_id);
+
+ /**
+ * @brief Convert HMI level value (as number) to string
+ *
+ * @param hmi_status HMI level status
+ * @param hmi_level_string Pointer to a string where the result is
+ * retunred.
+ */
+ static void ConvertHMILevel2String(
+ mobile_apis::HMILevel::eType hmi_status,
+ std::string* hmi_level_string);
+
+ /**
+ * @breif Convert smart object to vector of strings
+ *
+ * @param object Smart object
+ * @param v_strings Pointer to a verctor of strings where result is
+ * returned.
+ */
+ static void ConvertSmartArray2VectorStrings(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& object,
+ std::vector<std::string>* v_strings);
+ /**
+ * @brief Logger
+ */
+ static log4cxx::LoggerPtr logger_;
+};
+
+} // namespace policies
+
+#endif // SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_PERMISSIONS_CALCULATOR_H_
diff --git a/SDL_Core/src/components/policies/include/policies/policy_configuration.h b/SDL_Core/src/components/policies/include/policies/policy_configuration.h
new file mode 100644
index 000000000..8fae80d42
--- /dev/null
+++ b/SDL_Core/src/components/policies/include/policies/policy_configuration.h
@@ -0,0 +1,96 @@
+/**
+ * @file policy_configuration.h
+ * @brief Policy configuration 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 SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_CONFIGURATION_H_
+#define SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_CONFIGURATION_H_
+
+#include <string>
+#include "smart_objects/smart_object.h"
+#include "smart_objects/smart_schema.h"
+
+namespace policies {
+
+/**
+ * @brief Class contains configuration for policy table
+ */
+class PolicyConfiguration {
+ public:
+ /**
+ * @brief Constructor
+ */
+ PolicyConfiguration();
+
+ /**
+ * @brief set file path (with name) for policy table
+ *
+ * @param pt_file_path File path
+ */
+ void set_pt_file_name(const std::string& pt_file_path);
+
+ /**
+ * @brief set file path (with name) for preload policy table
+ *
+ * @param preload_pt_file_path File path
+ **/
+ void set_preload_pt_file_name(const std::string& preload_pt_file_path);
+
+ /**
+ * @brief Get file path of policy table
+ *
+ * @return File path
+ */
+ const std::string& pt_file_name() const;
+
+ /**
+ * @brief Get file path of preload policy table
+ *
+ * @return File path
+ **/
+ const std::string& preload_pt_file_name() const;
+
+ private:
+ /**
+ * @brief policy table file name
+ */
+ std::string pt_file_name_;
+
+ /**
+ * @brief Preload policy table file name
+ **/
+ std::string preload_pt_file_name_;
+};
+
+} // namespace policies
+
+#endif // SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_CONFIGURATION_H_
diff --git a/SDL_Core/src/components/policies/include/policies/policy_manager.h b/SDL_Core/src/components/policies/include/policies/policy_manager.h
new file mode 100644
index 000000000..b47867ad7
--- /dev/null
+++ b/SDL_Core/src/components/policies/include/policies/policy_manager.h
@@ -0,0 +1,197 @@
+/**
+ * @file policy_manager.h
+ * @brief Policy Manager 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 SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_MANAGER_H_
+#define SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_MANAGER_H_
+
+#include "interfaces/MOBILE_API.h"
+#include "policies/policy_configuration.h"
+#include "smart_objects/smart_object.h"
+
+namespace policies {
+
+ /**
+ * @brief enumeration of result for asking permissions by application
+ **/
+enum PermissionResult {
+ /**
+ * @brief RPC is allowed.
+ */
+ PERMISSION_ALLOWED = 0,
+ /**
+ * @brief Initialization of Policy Manager failed.
+ */
+ PERMISSION_INIT_FAILED,
+ /**
+ * @brief Verification of Policy Table failed.
+ *
+ * Policy Table as smart object has failed in verification against schema.
+ */
+ PERMISSION_PT_VERIFICATION_FAILED,
+ /**
+ * @brief RPC is allowed by the PT(backend), but disallowed by the user.
+ */
+ PERMISSION_USER_DISALLOWED,
+ /**
+ * @brief RPC is not allowed by the PT(backend).
+ */
+ PERMISSION_DISALLOWED,
+ /**
+ * @brief RPC is allowed by PT(backend), but user has not been prompted yet.
+ */
+ PERMISSION_PENDING_USER_CONSENT
+};
+
+// Namespace is neseccary because it is used for automatic string<->enum
+// convertion using schema
+namespace Priority {
+enum eType {
+ /**
+ * @brief Mandatory item. Used for enum<->string convertion
+ */
+ INVALID_ENUM = -1,
+ /**
+ * @brief NONE
+ */
+ PRIORITY_NONE = 0,
+ /**
+ * @brief NORMAL
+ */
+ PRIORITY_NORMAL,
+ /**
+ * @brief COMMUNICATION
+ */
+ PRIORITY_COMMUNICATION,
+ /**
+ * @brief NAVIGATION
+ */
+ PRIORITY_NAVIGATION,
+ /**
+ * @brief EMERGENCY
+ */
+ PRIORITY_EMERGENCY,
+};
+} // namespace Priority
+
+/**
+ * @brief Init() result enumeration
+ **/
+enum InitResult {
+ /**
+ * @brief PT file loaded successfully
+ **/
+ INIT_OK = 0,
+ /**
+ * @brief Initialization has failed
+ *
+ * Possible reason: Policy Table file missing, failed verification
+ *
+ **/
+ INIT_FAILED
+};
+
+/**
+ * @brief Enumeration for state wich reflects states of User consent procedure
+ * @TODO (anyone) for future use
+ */
+enum eType {
+ /**
+ * @brief User was not asked for consent
+ */
+ STATE_IDLE = 0,
+ /**
+ * @brief User was asked just now for consent
+ */
+ STATE_PENDING_CONSENT,
+ /**
+ * @brief User answered 'YES' just now
+ */
+ STATE_CONSENT_YES,
+ /**
+ * @brief User answered 'NO' just now
+ */
+ STATE_CONSENT_NO
+};
+
+/**
+ * @biref Struct contains data of result to return when Policy Manager
+ * is requested for CheckPermission()
+ */
+struct CheckPermissionResult {
+ /**
+ * @brief Permission result
+ */
+ PermissionResult result;
+ /**
+ * @brief Stored priority for current application
+ */
+ Priority::eType priority;
+};
+
+/**
+ * @brief Interface class of policy manager.
+ */
+class PolicyManager {
+ public:
+ /**
+ * @brief Destructor
+ *
+ **/
+ virtual ~PolicyManager() {}
+
+ /**
+ * @brief Initialization method
+ *
+ * @param config PolicyManager configuration
+ */
+ virtual InitResult Init(const PolicyConfiguration& config) = 0;
+
+ /**
+ * @brief Checking permissions for application whether rpc is allowed.
+ *
+ * @param app_id Application identifier
+ * @param rpc Remote procedure call
+ * @param hmi_status HMI level status
+ *
+ * @return result of check permission
+ */
+ virtual CheckPermissionResult CheckPermission(uint32_t app_id,
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& rpc,
+ mobile_apis::HMILevel::eType hmi_status) = 0;
+};
+
+} // namespace policies
+
+
+#endif // SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_MANAGER_H_
diff --git a/SDL_Core/src/components/policies/include/policies/policy_manager_impl.h b/SDL_Core/src/components/policies/include/policies/policy_manager_impl.h
new file mode 100644
index 000000000..adfddf834
--- /dev/null
+++ b/SDL_Core/src/components/policies/include/policies/policy_manager_impl.h
@@ -0,0 +1,126 @@
+/**
+ * @file policy_manager_impl.h
+ * @brief Policy Manager implementation 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 SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_MANAGER_IMPL_H_
+#define SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_MANAGER_IMPL_H_
+
+#include "policies/policy_manager.h"
+#include "policies/policy_table.h"
+#include "utils/logger.h"
+#include "utils/singleton.h"
+
+namespace policies {
+
+/**
+ * @brief Interface implementation class of Policy Manager.
+ */
+class PolicyManagerImpl : public PolicyManager,
+ public utils::Singleton<PolicyManagerImpl> {
+ public:
+ /**
+ * @brief Destructor
+ *
+ **/
+ virtual ~PolicyManagerImpl(void);
+
+ /**
+ * @brief Initialization method
+ *
+ * @param config PolicyManager configuration
+ *
+ */
+ virtual InitResult Init(const PolicyConfiguration& config);
+
+ /**
+ * @brief Checking permissions for application whether rpc is allowed.
+ *
+ * @param app_id Application identifier
+ * @param rpc Remote procedure call
+ * @param hmi_status HMI level status
+ *
+ * @return result of check permission
+ */
+ virtual CheckPermissionResult CheckPermission(uint32_t app_id,
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& rpc,
+ mobile_apis::HMILevel::eType hmi_status);
+
+ protected:
+ /**
+ * @brief Hidden constructor.
+ */
+ PolicyManagerImpl();
+
+ /**
+ * @brief Store policy table to filesystem
+ *
+ * @return true if PolicyTable is successfully saved, false - othewise.
+ */
+ bool StorePolicyTable();
+
+ /**
+ * @brief Get PolicyTable pointer (for testing purposes)
+ *
+ * @return PolicyTable* ptr.
+ **/
+ PolicyTable* policy_table() const;
+
+ private:
+ /**
+ * @brief Policy configuration
+ */
+ PolicyConfiguration policy_config_;
+
+ /**
+ * @brief Policy table
+ */
+ PolicyTable* policy_table_;
+
+ /**
+ * @brief Logger
+ */
+ static log4cxx::LoggerPtr logger_;
+
+ /**
+ * @brief Result of call of public method Init()
+ */
+ InitResult init_result_;
+
+ DISALLOW_COPY_AND_ASSIGN(PolicyManagerImpl);
+
+ FRIEND_BASE_SINGLETON_CLASS(PolicyManagerImpl);
+};
+
+} // namespace policies
+
+#endif // SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_MANAGER_IMPL_H_
diff --git a/SDL_Core/src/components/policies/include/policies/policy_table.h b/SDL_Core/src/components/policies/include/policies/policy_table.h
new file mode 100644
index 000000000..a3feacab2
--- /dev/null
+++ b/SDL_Core/src/components/policies/include/policies/policy_table.h
@@ -0,0 +1,129 @@
+/**
+ * @file policy_table.h
+ * @brief Policy table 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 SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_TABLE_H_
+#define SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_TABLE_H_
+
+#include <string>
+#include "smart_objects/smart_object.h"
+#include "smart_objects/smart_schema.h"
+
+namespace policies {
+
+enum PTValidationResult {
+ VALIDATION_OK = 0,
+ VALIDATION_FAILED_BAD_JSON,
+ VALIDATION_FAILED
+};
+
+enum PolicyTableType {
+ TYPE_POLICY_TABLE = 0,
+ TYPE_PT_PRELOAD
+};
+
+class PolicyTable {
+ public:
+ /**
+ * @brief Constructor
+ *
+ * @param policy_table_string String containing policy table
+ * @param pt_type PolicyTable type (PT or Preload)
+ **/
+ PolicyTable(const std::string& policy_table_string,
+ PolicyTableType pt_type);
+
+ /**
+ * @brief Destructor
+ */
+ ~PolicyTable();
+
+ /**
+ * @brief Get policy table as smart object
+ *
+ * @return Policy table as smart object
+ */
+ NsSmartDeviceLink::NsSmartObjects::SmartObject& AsSmartObject();
+
+ /**
+ * @brief Get policy table as a string
+ *
+ * @param policy_table_string pointer to the string where PolicyTable
+ * will be written.
+ *
+ * @return true if PolicyTable correctly converted to string and the string
+ * is returned in "policy_table_string"
+ */
+ bool AsString(std::string* policy_table_string) const;
+
+ /**
+ * @brief Validate policy table.
+ *
+ * Validates policy table against smart schema which should be set before.
+ *
+ * @return validation result as enum
+ **/
+ PTValidationResult Validate();
+
+ /**
+ * @brief Tells wether Policy Table is Preload
+ *
+ * @return whether Policy Table Preload
+ */
+ bool IsPTPreload();
+
+ private:
+ /**
+ * @brief is Policy Table valid
+ **/
+ PTValidationResult pt_validation_result_;
+
+ /**
+ * @brief PolicyTable type
+ **/
+ PolicyTableType pt_type_;
+
+ /**
+ * @brief Schema to verify policy table
+ */
+ NsSmartDeviceLink::NsSmartObjects::CSmartSchema schema_;
+
+ /**
+ * @brief policy table as smart object
+ */
+ NsSmartDeviceLink::NsSmartObjects::SmartObject pt_smart_object_;
+};
+
+} // namespace policies
+
+#endif // SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_TABLE_H_
diff --git a/SDL_Core/src/components/policies/include/policies/policy_table_schema.h b/SDL_Core/src/components/policies/include/policies/policy_table_schema.h
new file mode 100644
index 000000000..85247cc8b
--- /dev/null
+++ b/SDL_Core/src/components/policies/include/policies/policy_table_schema.h
@@ -0,0 +1,202 @@
+/**
+ * @file policy_table_schema.h
+ * @brief Policy table schema 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 SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_TABLE_SCHEMA_H_
+#define SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_TABLE_SCHEMA_H_
+
+#include <string>
+
+#include "smart_objects/smart_schema.h"
+#include "smart_objects/schema_item.h"
+#include "utils/shared_ptr.h"
+
+namespace policies {
+
+class PolicyTableSchema {
+ public:
+ /**
+ * @brief Creates schema for Policy Table
+ *
+ * @note CSmartSchema is a lightweith wrapper around
+ * "SharedPtr<ISchemaItem>". There's no overhead in returning it by value.
+ */
+ static NsSmartDeviceLink::NsSmartObjects::CSmartSchema Create(void);
+
+
+ // TODO(YS): might need to move these constants to the more
+ // appropriate place
+ /**
+ * @brief String constant for "policy_table" section.
+ */
+ static const char* kStrPolicyTable;
+
+ /**
+ * @brief String constant for "module_config" section.
+ */
+ static const char* kStrModuleConfig;
+
+ /**
+ * @brief String constant for "functional_groupings" section.
+ */
+ static const char* kStrFunctionalGroupings;
+
+ /**
+ * @brief String constant for "app_policies" section.
+ */
+ static const char* kStrAppPolicies;
+
+ /**
+ * @brief String constant for "endpoints" section.
+ */
+ static const char* kStrEndpoints;
+
+ /**
+ * @brief String constant for "default" section.
+ */
+ static const char* kStrDefault;
+
+ /**
+ * @brief String constant for "user_consent_prompt" section.
+ */
+ static const char* kStrUserConsentPrompt;
+
+ /**
+ * @brief String constant for "rpcs" section.
+ */
+ static const char* kStrRpcs;
+
+ /**
+ * @brief String constant for "hmi_levels" section.
+ */
+ static const char* kStrHmiLevels;
+
+ /**
+ * @brief String constant for "parameters" section.
+ */
+ static const char* kStrParameters;
+
+ /**
+ * @brief String constant for "groups" section.
+ */
+ static const char* kStrGroups;
+
+ /**
+ * @brief String constant for "nicknames" section.
+ */
+ static const char* kStrNicknames;
+
+ /**
+ * @brief String constant for "priority" section.
+ */
+ static const char* kStrPriority;
+
+ protected:
+ /**
+ * @brief Hidden constructor to prevent missuse. Only called from inside.
+ */
+ PolicyTableSchema(void);
+
+ /**
+ * @brief Virtual destructor.
+ */
+ virtual ~PolicyTableSchema(void) {}
+
+ /**
+ * @brief Returns a schema.
+ *
+ * If schema hasn't been created yet the method creates it and returns
+ * a newly created schema.
+ *
+ * @note CSmartSchema is a lightweith wrapper around
+ * "SharedPtr<ISchemaItem>". There's no overhead in returning it by value.
+ *
+ * @return If the schema has already been created just returns it,
+ * otherwise creates it and returns it.
+ */
+ virtual NsSmartDeviceLink::NsSmartObjects::CSmartSchema GetSchema(void);
+
+ /**
+ * @brief Creates schema for Policy Table
+ *
+ * @brief Root schema item of the newly created schema.
+ */
+ virtual utils::SharedPtr<NsSmartDeviceLink::NsSmartObjects::ISchemaItem>
+ CreateSchema(void);
+
+ /**
+ * @brief Creates "module_config" schema item
+ */
+ virtual utils::SharedPtr<NsSmartDeviceLink::NsSmartObjects::ISchemaItem>
+ CreateModuleConfig(void);
+
+ /**
+ * @brief Creates "functional_groupings" schema item
+ */
+ virtual utils::SharedPtr<NsSmartDeviceLink::NsSmartObjects::ISchemaItem>
+ CreateFunctionalGroupings(void);
+
+ /**
+ * @brief Creates "app_policies" schema item
+ */
+ virtual utils::SharedPtr<NsSmartDeviceLink::NsSmartObjects::ISchemaItem>
+ CreateAppPolicies(void);
+
+ /**
+ * @brief Creates "<app_id>" schema item
+ */
+ virtual utils::SharedPtr<NsSmartDeviceLink::NsSmartObjects::ISchemaItem>
+ CreateAppId(void);
+
+ /**
+ * @brief Creates "priority" schema item for <app_id> and "default" sections
+ */
+ virtual utils::SharedPtr<NsSmartDeviceLink::NsSmartObjects::ISchemaItem>
+ CreatePriority(void);
+
+ /**
+ * @brief Creates "default" schema item of "app_policies"
+ */
+ virtual utils::SharedPtr<NsSmartDeviceLink::NsSmartObjects::ISchemaItem>
+ CreateAppPoliciesDefault(void);
+
+ private:
+ /**
+ * @brief Contains a schema if it is already been created
+ */
+ utils::SharedPtr<NsSmartDeviceLink::NsSmartObjects::ISchemaItem> schema_;
+};
+
+} // namespace policies
+
+#endif // SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_POLICY_TABLE_SCHEMA_H_
diff --git a/SDL_Core/src/components/policies/include/policies/preloaded_pt_schema.h b/SDL_Core/src/components/policies/include/policies/preloaded_pt_schema.h
new file mode 100644
index 000000000..805364089
--- /dev/null
+++ b/SDL_Core/src/components/policies/include/policies/preloaded_pt_schema.h
@@ -0,0 +1,75 @@
+/**
+ * @file preloaded_pt_schema.h
+ * @brief Policy table preload schema 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 SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_PRELOADED_PT_SCHEMA_H_
+#define SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_PRELOADED_PT_SCHEMA_H_
+
+#include "policies/policy_table_schema.h"
+
+namespace policies {
+
+class PreloadedPTSchema : public PolicyTableSchema {
+ public:
+ /**
+ * @brief Creates schema for preloaded Policy Table
+ */
+ static NsSmartDeviceLink::NsSmartObjects::CSmartSchema Create(void);
+
+ protected:
+ /**
+ * @brief Hidden constructor to prevent missuse. Only called from inside.
+ */
+ PreloadedPTSchema(void) {}
+
+ /**
+ * @brief Virtual destructor.
+ */
+ virtual ~PreloadedPTSchema(void) {}
+
+ /**
+ * @brief Creates "<app_id>" schema item
+ */
+ virtual utils::SharedPtr<NsSmartDeviceLink::NsSmartObjects::ISchemaItem>
+ CreateAppId(void);
+
+ /**
+ * @brief Creates "app_policies" schema item
+ */
+ virtual utils::SharedPtr<NsSmartDeviceLink::NsSmartObjects::ISchemaItem>
+ CreateAppPolicies(void);
+};
+
+} // namespace policies
+
+#endif // SRC_COMPONENTS_POLICIES_INCLUDE_POLICIES_PRELOADED_PT_SCHEMA_H_