3.5 - Smart Objects
authorJustin Dickow <jjdickow@gmail.com>
Thu, 17 Jul 2014 18:17:10 +0000 (14:17 -0400)
committerJustin Dickow <jjdickow@gmail.com>
Thu, 17 Jul 2014 18:17:10 +0000 (14:17 -0400)
Authors

Dmitriy Klimenko
Newton Kim

Signed-off-by: Justin Dickow <jjdickow@gmail.com>
src/components/smart_objects/CMakeLists.txt
src/components/smart_objects/include/smart_objects/object_schema_item.h
src/components/smart_objects/include/smart_objects/schema_item.h
src/components/smart_objects/src/object_schema_item.cc
src/components/smart_objects/src/schema_item.cc

index a64fa61..f1f9c7b 100644 (file)
@@ -1,7 +1,6 @@
 include_directories (
   ./include
   ../utils/include/
-  ../application_manager/include
 )
 
 set (SOURCES
@@ -22,6 +21,7 @@ set (SOURCES
 add_library("SmartObjects" ${SOURCES})
 
 if(ENABLE_LOG)
-  target_link_libraries("SmartObjects" log4cxx)
+  add_dependencies("SmartObjects" liblog4cxx)
+  target_link_libraries("SmartObjects" log4cxx -L${LOG4CXX_LIBS_DIRECTORY})
 endif()
 
index aa3ba7b..183e481 100644 (file)
@@ -121,6 +121,13 @@ class CObjectSchemaItem : public ISchemaItem {
   virtual void BuildObjectBySchema(const SmartObject& pattern_object,
                                    SmartObject& result_object);
 
+  /**
+   * @brief Get size mMembers map
+   *
+   * @return Size of mMembers
+   */
+  virtual uint32_t GetMemberSize();
+
   virtual ~CObjectSchemaItem() {
   }
 
index 85b19e5..724b09a 100644 (file)
@@ -31,6 +31,8 @@
 #ifndef SRC_COMPONENTS_SMART_OBJECTS_INCLUDE_SMART_OBJECTS_SCHEMA_ITEM_H_
 #define SRC_COMPONENTS_SMART_OBJECTS_INCLUDE_SMART_OBJECTS_SCHEMA_ITEM_H_
 
+#include <stdint.h>
+
 #include "smart_objects/errors.h"
 
 namespace NsSmartDeviceLink {
@@ -96,6 +98,13 @@ class ISchemaItem {
       const NsSmartDeviceLink::NsSmartObjects::SmartObject& pattern_object,
       NsSmartDeviceLink::NsSmartObjects::SmartObject& result_object);
 
+  /**
+   * @brief Get value param, depends of children
+   *
+   * @return value of any parameter
+   */
+  virtual uint32_t GetMemberSize();
+
   virtual ~ISchemaItem() {
   }
 };
index df9728e..f4c5931 100644 (file)
 #include "smart_objects/always_false_schema_item.h"
 #include "smart_objects/object_schema_item.h"
 #include "smart_objects/smart_object.h"
-#include "application_manager/smart_object_keys.h"
 
 namespace smart_objects_ns = NsSmartDeviceLink::NsSmartObjects;
 
 namespace NsSmartDeviceLink {
 namespace NsSmartObjects {
 
+const char *kMsgParams = "msg_params";
+
 CObjectSchemaItem::SMember::SMember()
     : mSchemaItem(CAlwaysFalseSchemaItem::create()),
       mIsMandatory(true) {
@@ -66,14 +67,14 @@ Errors::eType CObjectSchemaItem::validate(const SmartObject& Object) {
     for (std::map<std::string, CObjectSchemaItem::SMember>::const_iterator i =
         mMembers.begin(); i != mMembers.end(); ++i) {
       if (objectKeys.end() != objectKeys.find(i->first)) {
-        if (i->first == application_manager::strings::msg_params) {
+        if (kMsgParams == i->first) {
           is_valid = false;
         }
 
         result = i->second.mSchemaItem->validate(Object.getElement(i->first));
 
-        if (i->first == application_manager::strings::msg_params) {
-          if (!is_valid) {
+        if (kMsgParams == i->first) {
+          if ((!is_valid) && ( 0 < (*i->second.mSchemaItem).GetMemberSize())) {
             result = Errors::ERROR;
           }
         }
@@ -84,7 +85,7 @@ Errors::eType CObjectSchemaItem::validate(const SmartObject& Object) {
         }
       }
 
-      if (Errors::OK != result) {
+      if ((Errors::OK != result) && (Errors::UNEXPECTED_PARAMETER != result)) {
         break;
       }
     }
@@ -94,19 +95,20 @@ Errors::eType CObjectSchemaItem::validate(const SmartObject& Object) {
           k != objectKeys.end(); ++k) {
         if (mMembers.end() == mMembers.find(*k)) {
           result = Errors::UNEXPECTED_PARAMETER;
-          break;
+        } else {
+          is_valid = true;
         }
       }
     }
 
-    if (Errors::OK == result) {
-      is_valid = true;
-    }
-
   } else {
     result = Errors::INVALID_VALUE;
   }
 
+  if (Errors::OK == result) {
+    is_valid = true;
+  }
+
   return result;
 }
 
@@ -188,6 +190,10 @@ void CObjectSchemaItem::BuildObjectBySchema(const SmartObject& pattern_object,
   }
 }
 
+uint32_t CObjectSchemaItem::GetMemberSize() {
+  return mMembers.size();
+}
+
 CObjectSchemaItem::CObjectSchemaItem(
     const std::map<std::string, CObjectSchemaItem::SMember>& Members)
     : mMembers(Members) {
index e237341..6e0082f 100644 (file)
@@ -55,5 +55,9 @@ void ISchemaItem::BuildObjectBySchema(const SmartObject& pattern_object,
                                       SmartObject& result_object) {
 }
 
+uint32_t ISchemaItem::GetMemberSize() {
+  return 0;
+}
+
 }  // namespace NsSmartObjects
 }  // namespace NsSmartDeviceLink