Merge remote-tracking branch 'origin/routing-manager'
[platform/upstream/iotivity.git] / resource / src / OCPlatform_impl.cpp
index 8776790..4abcb5a 100644 (file)
@@ -42,6 +42,7 @@
 #include "OCApi.h"
 #include "OCException.h"
 #include "OCUtilities.h"
+#include "ocpayload.h"
 
 #include "oc_logger.hpp"
 
@@ -56,6 +57,7 @@ namespace OC
 
     void OCPlatform_impl::Configure(const PlatformConfig& config)
     {
+        OCRegisterPersistentStorageHandler(config.ps);
         globalConfig() = config;
     }
 
@@ -78,6 +80,7 @@ namespace OC
                 break;
 
             case ModeType::Both:
+            case ModeType::Gateway:
                 m_server = m_WrapperInstance->CreateServerWrapper(m_csdkLock, config);
                 m_client = m_WrapperInstance->CreateClientWrapper(m_csdkLock, config);
                 break;
@@ -131,13 +134,14 @@ namespace OC
          return result_guard(OC_STACK_ERROR);
         }
 
-        std::string payload(pResponse->getResourceRepresentation().getJSONRepresentation());
-
-        return result_guard(
+        OCRepPayload* pl = pResponse->getResourceRepresentation().getPayload();
+        OCStackResult result =
                    OCNotifyListOfObservers(resourceHandle,
                             &observationIds[0], observationIds.size(),
-                            payload.c_str(),
-                            static_cast<OCQualityOfService>(QoS)));
+                            pl,
+                            static_cast<OCQualityOfService>(QoS));
+        OCRepPayloadDestroy(pl);
+        return result_guard(result);
     }
 
     OCResource::Ptr OCPlatform_impl::constructResourceObject(const std::string& host,
@@ -171,9 +175,9 @@ namespace OC
     OCStackResult OCPlatform_impl::findResource(const std::string& host,
                                             const std::string& resourceName,
                                             OCConnectivityType connectivityType,
-                                            FindCallback resourceHandler, QualityOfService QoS)
+                                            FindCallback resourceHandler,
+                                            QualityOfService QoS)
     {
-
         return checked_guard(m_client, &IClientWrapper::ListenForResource,
                              host, resourceName, connectivityType, resourceHandler, QoS);
     }
@@ -197,6 +201,25 @@ namespace OC
                              host, deviceURI, connectivityType, deviceInfoHandler, QoS);
     }
 
+    OCStackResult OCPlatform_impl::getPlatformInfo(const std::string& host,
+                                            const std::string& platformURI,
+                                            OCConnectivityType connectivityType,
+                                            FindPlatformCallback platformInfoHandler)
+    {
+        return result_guard(getPlatformInfo(host, platformURI, connectivityType,
+               platformInfoHandler, m_cfg.QoS));
+    }
+
+    OCStackResult OCPlatform_impl::getPlatformInfo(const std::string& host,
+                                            const std::string& platformURI,
+                                            OCConnectivityType connectivityType,
+                                            FindPlatformCallback platformInfoHandler,
+                                            QualityOfService QoS)
+    {
+        return checked_guard(m_client, &IClientWrapper::ListenForDevice,
+                             host, platformURI, connectivityType, platformInfoHandler, QoS);
+    }
+
     OCStackResult OCPlatform_impl::registerResource(OCResourceHandle& resourceHandle,
                                             std::string& resourceURI,
                                             const std::string& resourceTypeName,
@@ -214,15 +237,20 @@ namespace OC
         return checked_guard(m_server, &IServerWrapper::registerDeviceInfo, deviceInfo);
     }
 
+    OCStackResult OCPlatform_impl::registerPlatformInfo(const OCPlatformInfo platformInfo)
+    {
+        return checked_guard(m_server, &IServerWrapper::registerPlatformInfo, platformInfo);
+    }
+
     OCStackResult OCPlatform_impl::registerResource(OCResourceHandle& resourceHandle,
                                             const std::shared_ptr< OCResource > resource)
     {
         uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
         std::vector<std::string> resourceTypes = resource->getResourceTypes();
 
-        return checked_guard(m_server, &IServerWrapper::registerResourceWithHost,
-                std::ref(resourceHandle), resource->host(), resource->uri(),
-                resourceTypes[0]/*"core.remote"*/, "oc.mi.def",
+        return checked_guard(m_server, &IServerWrapper::registerResource,
+                std::ref(resourceHandle), resource->host() + resource->uri(),
+                resourceTypes[0]/*"core.remote"*/, DEFAULT_INTERFACE,
                 (EntityHandler) nullptr, resourceProperty);
     }
 
@@ -332,5 +360,10 @@ namespace OC
         return checked_guard(m_server, &IServerWrapper::sendResponse,
                              pResponse);
     }
+
+    std::weak_ptr<std::recursive_mutex> OCPlatform_impl::csdkLock()
+    {
+        return m_csdkLock;
+    }
 } //namespace OC