Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / resource / include / OCSerialization.h
index f611407..898fde7 100644 (file)
@@ -122,6 +122,15 @@ namespace OC
                 }
                 try
                 {
+                    ar(cereal::make_nvp(OC::Key::SERVERIDKEY, m_serverId));
+                    m_loaded=true;
+                }
+                catch(cereal::Exception&)
+                {
+                    ar.setNextName(nullptr);
+                }
+                try
+                {
                     ar(cereal::make_nvp(OC::Key::PROPERTYKEY, m_props));
                     m_loaded=true;
                 }
@@ -133,6 +142,7 @@ namespace OC
 
 
             std::string m_uri;
+            std::string m_serverId;
             bool m_loaded;
             ListenResourcePropertiesContainer m_props;
 
@@ -177,8 +187,8 @@ namespace OC
             }
         public:
             ListenOCContainer(std::weak_ptr<IClientWrapper> cw, const OCDevAddr& address,
-                    std::stringstream& json):
-                m_clientWrapper(cw), m_address(address)
+                    OCConnectivityType connectivityType, std::stringstream& json):
+                m_clientWrapper(cw), m_address(address), m_connectivityType(connectivityType)
             {
                 LoadFromJson(json);
             }
@@ -191,10 +201,8 @@ namespace OC
         private:
             std::string ConvertOCAddrToString(OCSecureType sec, int secureport)
             {
-                char stringAddress[DEV_ADDR_SIZE_MAX];
                 uint16_t port;
-
-                ostringstream os;
+                std::ostringstream os;
 
                 if(sec== OCSecureType::IPv4)
                 {
@@ -210,18 +218,19 @@ namespace OC
                     throw ResourceInitException(false, false, false, false, false, true);
                 }
 
-                if(0== OCDevAddrToString(&m_address, stringAddress))
-                {
-                    // nothing to do, successful case.
-                }
-                else
+                uint8_t a;
+                uint8_t b;
+                uint8_t c;
+                uint8_t d;
+                if(OCDevAddrToIPv4Addr(&m_address, &a, &b, &c, &d) != 0)
                 {
                     oclog() << "ConvertOCAddrToString(): Invalid Ip"
-                        << std::flush;
+                            << std::flush;
                     throw ResourceInitException(false, false, false, false, false, true);
                 }
 
-                os<<stringAddress;
+                os<<static_cast<int>(a)<<"."<<static_cast<int>(b)
+                        <<"."<<static_cast<int>(c)<<"."<<static_cast<int>(d);
 
                 if(sec == OCSecureType::IPv4Secure && secureport>0 && secureport<=65535)
                 {
@@ -234,7 +243,7 @@ namespace OC
                 else
                 {
                     oclog() << "ConvertOCAddrToString() : Invalid Port"
-                        <<std::flush;
+                            <<std::flush;
                     throw ResourceInitException(false, false, false, false, true, false);
                 }
 
@@ -261,8 +270,8 @@ namespace OC
                             m_resources.push_back(std::shared_ptr<OCResource>(
                                 new OCResource(m_clientWrapper,
                                     ConvertOCAddrToString(res.secureType(),res.port()),
-                                    res.m_uri, res.observable(), res.resourceTypes(),
-                                    res.interfaces())));
+                                    res.m_uri, res.m_serverId, m_connectivityType, res.observable(),
+                                    res.resourceTypes(), res.interfaces())));
                         }
 
                     }
@@ -276,5 +285,7 @@ namespace OC
             std::vector<std::shared_ptr<OC::OCResource>> m_resources;
             std::weak_ptr<IClientWrapper> m_clientWrapper;
             OCDevAddr m_address;
+            OCConnectivityType m_connectivityType;
     };
 }
+