Change the type of "rt" in /oic/p from string to array.
[platform/upstream/iotivity.git] / resource / src / OCRepresentation.cpp
index 0de857c..f0e8dca 100644 (file)
@@ -73,15 +73,9 @@ namespace OC
         }
 
         OCRepresentation rep;
-        char uuidString[UUID_STRING_SIZE];
-        if (payload->sid && RAND_UUID_OK == OCConvertUuidToString(payload->sid, uuidString))
-        {
-            rep[OC_RSRVD_DEVICE_ID] = std::string(uuidString);
-        }
-        else
-        {
-            rep[OC_RSRVD_DEVICE_ID] = std::string();
-        }
+        rep[OC_RSRVD_DEVICE_ID] = (payload->sid) ?
+            std::string(payload->sid) :
+            std::string();
         rep[OC_RSRVD_DEVICE_NAME] = payload->deviceName ?
             std::string(payload->deviceName) :
             std::string();
@@ -91,6 +85,10 @@ namespace OC
         rep[OC_RSRVD_DATA_MODEL_VERSION] = payload->dataModelVersion ?
             std::string(payload->dataModelVersion) :
             std::string();
+        for (OCStringLL *strll = payload->types; strll; strll = strll->next)
+        {
+           rep.addResourceType(strll->value);
+        }
         m_reps.push_back(std::move(rep));
     }
 
@@ -136,6 +134,15 @@ namespace OC
             std::string(payload->info.systemTime) :
             std::string();
 
+        for (OCStringLL *strll = payload->rt; strll; strll = strll->next)
+        {
+            rep.addResourceType(strll->value);
+        }
+        for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
+        {
+            rep.addResourceInterface(strll->value);
+        }
+
         m_reps.push_back(std::move(rep));
     }
 
@@ -424,6 +431,11 @@ namespace OC
                 case AttributeType::Vector:
                     getPayloadArray(root, val);
                     break;
+                case AttributeType::Binary:
+                    OCRepPayloadSetPropByteString(root, val.attrname().c_str(),
+                            OCByteString{const_cast<uint8_t*>(val.getValue<std::vector<uint8_t>>().data()),
+                            val.getValue<std::vector<uint8_t>>().size()});
+                    break;
                 default:
                     throw std::logic_error(std::string("Getpayload: Not Implemented") +
                             std::to_string((int)val.type()));
@@ -628,6 +640,12 @@ namespace OC
                 case OCREP_PROP_ARRAY:
                     setPayloadArray(val);
                     break;
+                case OCREP_PROP_BYTE_STRING:
+                    setValue(val->name,
+                            std::vector<uint8_t>
+                            (val->ocByteStr.bytes, val->ocByteStr.bytes + val->ocByteStr.len)
+                            );
+                    break;
                 default:
                     throw std::logic_error(std::string("Not Implemented!") +
                             std::to_string((int)val->type));
@@ -834,6 +852,8 @@ namespace OC
             case AttributeType::Vector:
                 os << "Vector";
                 break;
+            case AttributeType::Binary:
+                os<< "Binary";
         }
         return os;
     }
@@ -881,7 +901,13 @@ namespace OC
     };
 
     template<typename T>
-    struct type_info<T, typename std::enable_if<is_vector<T>::value>::type>
+    struct type_info<
+        T,
+        typename std::enable_if<
+            is_vector<T>::value &&
+            !std::is_same<uint8_t, typename T::value_type>::value
+        >::type
+    >
     {
         typedef T type;
         typedef typename type_info<typename T::value_type>::base_type base_type;
@@ -892,6 +918,18 @@ namespace OC
             type_info<typename T::value_type>::depth;
     };
 
+    // special case for binary data, which is a std::vector<uint8_t>
+    template<>
+    struct type_info<std::vector<uint8_t>, void>
+    {
+        typedef std::vector<uint8_t> type;
+        typedef std::vector<uint8_t> base_type;
+        constexpr static AttributeType enum_type = AttributeType::Binary;
+        constexpr static AttributeType enum_base_type = AttributeType::Binary;
+        constexpr static size_t depth = 0;
+    };
+
+
     struct type_introspection_visitor : boost::static_visitor<>
     {
         AttributeType type;