Check Device Operational State
[platform/upstream/iotivity.git] / resource / csdk / stack / src / ocstack.c
old mode 100755 (executable)
new mode 100644 (file)
index 139ff3a..8f77cf7
@@ -151,9 +151,6 @@ static const char COAP_TCP_SCHEME[] = "coap+tcp:";
 static const char COAPS_TCP_SCHEME[] = "coaps+tcp:";
 static const char CORESPEC[] = "core";
 
-CAAdapterStateChangedCB g_adapterHandler = NULL;
-CAConnectionStateChangedCB g_connectionHandler = NULL;
-
 #if defined(__WITH_DTLS__) || defined (__WITH_TLS__)
 static OCOtmEventHandler_t g_otmEventHandler = {NULL, NULL};
 #endif
@@ -4009,6 +4006,37 @@ OCStackResult OCBindResourceTypeToResource(OCResourceHandle handle,
     return result;
 }
 
+OCStackResult OCResetResourceTypes(OCResourceHandle handle,
+                                   const char *newResourceType)
+{
+    OCStackResult result = OC_STACK_ERROR;
+    OCResource *resource = NULL;
+
+    resource = findResource((OCResource *) handle);
+    if (!resource)
+    {
+        OIC_LOG(ERROR, TAG, "Resource not found");
+        return OC_STACK_ERROR;
+    }
+
+    // Clear all bound resource types
+    deleteResourceType(resource->rsrcType);
+    resource->rsrcType = NULL;
+
+    // Bind new resource type to resource
+    result = BindResourceTypeToResource(resource, newResourceType);
+
+#ifdef WITH_PRESENCE
+    if(presenceResource.handle)
+    {
+        ((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
+        SendPresenceNotification(resource->rsrcType, OC_PRESENCE_TRIGGER_CHANGE);
+    }
+#endif
+
+    return result;
+}
+
 OCStackResult OCBindResourceInterfaceToResource(OCResourceHandle handle,
         const char *resourceInterfaceName)
 {
@@ -4036,6 +4064,37 @@ OCStackResult OCBindResourceInterfaceToResource(OCResourceHandle handle,
     return result;
 }
 
+OCStackResult OCResetResourceInterfaces(OCResourceHandle handle,
+                                        const char *newResourceInterface)
+{
+    OCStackResult result = OC_STACK_ERROR;
+    OCResource *resource = NULL;
+
+    resource = findResource((OCResource *) handle);
+    if (!resource)
+    {
+        OIC_LOG(ERROR, TAG, "Resource not found");
+        return OC_STACK_ERROR;
+    }
+
+    // Clear all bound interface
+    deleteResourceInterface(resource->rsrcInterface);
+    resource->rsrcInterface = NULL;
+
+    // Bind new interface to resource
+    result = BindResourceInterfaceToResource(resource, newResourceInterface);
+
+#ifdef WITH_PRESENCE
+    if (presenceResource.handle)
+    {
+        ((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
+        SendPresenceNotification(resource->rsrcType, OC_PRESENCE_TRIGGER_CHANGE);
+    }
+#endif
+
+    return result;
+}
+
 OCStackResult OCGetNumberOfResources(uint8_t *numResources)
 {
     OCResource *pointer = headResource;
@@ -5438,19 +5497,14 @@ OCStackResult OCGetHeaderOption(OCHeaderOption* ocHdrOpt, size_t numOptions, uin
 void OCDefaultAdapterStateChangedHandler(CATransportAdapter_t adapter, bool enabled)
 {
     OIC_LOG(DEBUG, TAG, "OCDefaultAdapterStateChangedHandler");
-    if (g_adapterHandler)
-    {
-        g_adapterHandler(adapter, enabled);
-    }
+    
+    OC_UNUSED(adapter);
+    OC_UNUSED(enabled);
 }
 
 void OCDefaultConnectionStateChangedHandler(const CAEndpoint_t *info, bool isConnected)
 {
     OIC_LOG(DEBUG, TAG, "OCDefaultConnectionStateChangedHandler");
-    if (g_connectionHandler)
-    {
-       g_connectionHandler(info, isConnected);
-    }
 
     /*
      * If the client observes one or more resources over a reliable connection,
@@ -5516,6 +5570,17 @@ OCStackResult OCGetDeviceOwnedState(bool *isOwned)
     return ret;
 }
 
+OCStackResult OCGetDeviceOperationalState(bool* isOp)
+{
+    if(NULL != isOp)
+    {
+        *isOp = GetPstatIsop();
+        return OC_STACK_OK;
+    }
+
+    return OC_STACK_ERROR;
+}
+
 void OCClearCallBackList()
 {
     DeleteClientCBList();