Added context for callbacks.
authorThuyen Tran <thuyen.c.tran@intel.com>
Fri, 23 Oct 2015 23:10:48 +0000 (16:10 -0700)
committerJon A. Cruz <jonc@osg.samsung.com>
Tue, 15 Dec 2015 00:21:57 +0000 (00:21 +0000)
Change-Id: Ia20cae8abc1e4a4112bc70608fb482174701abbb
Signed-off-by: Thuyen Tran <thuyen.c.tran@intel.com>
Signed-off-by: Joseph Morrow <joseph.l.morrow@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3939
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
plugins/samples/linux/IotivityandZigbeeClient.c
plugins/zigbee_wrapper/src/zigbee_wrapper.c
plugins/zigbee_wrapper/telegesis_wrapper/include/telegesis_wrapper.h
plugins/zigbee_wrapper/telegesis_wrapper/src/telegesis_wrapper.c

index ad0bef5..99b4d3b 100644 (file)
@@ -43,7 +43,7 @@
 #define MAX_URI_SIZE                (256)
 #define MAX_RESOURCE_TYPE_SIZE      (32)
 #define MAX_RESOURCE_TYPE_LENGTH    (MAX_RESOURCE_TYPE_SIZE - 1)
-#define MAX_RESOURCES_REMEMBERED    (10)
+#define MAX_RESOURCES_REMEMBERED    (100)
 
 #define MAX_USER_INPUT              (100)
 
index 9b09814..57cc6d8 100644 (file)
@@ -120,8 +120,6 @@ static const char* OIC_MOTION_ATTRIBUTE = "value";
 static const char* OIC_ON_OFF_ATTRIBUTE = "value";
 static const char* OIC_COLOUR_TEMPERATURE_ATTRIBUTE = "colourspacevalue";
 
-PIPlugin_Zigbee ** gPlugin = NULL;
-
 typedef enum
 {
     ZB_NULL,   // No Data
@@ -199,7 +197,7 @@ bool getZigBeeAttributesIfValid(const char * OICResourceType,
                                     AttributeList *attributeList,
                                     OCRepPayload *payload);
 
-const char * getResourceTypeForIASZoneType(TWDevice *device)
+const char * getResourceTypeForIASZoneType(TWDevice *device, PIPluginBase* plugin)
 {
     if (!device)
     {
@@ -217,7 +215,7 @@ const char * getResourceTypeForIASZoneType(TWDevice *device)
         ZB_IAS_ZONE_TYPE_ATTRIBUTE_ID,
         &IASZoneType,
         &length,
-        *gPlugin
+        (PIPlugin_Zigbee*)plugin
     );
 
     if (ret != OC_STACK_OK || !IASZoneType)
@@ -318,7 +316,7 @@ exit:
     return OC_STACK_NO_MEMORY;
 }
 
-void foundZigbeeCallback(TWDevice *device)
+void foundZigbeeCallback(TWDevice *device, PIPlugin_Zigbee* plugin)
 {
     if (!device)
     {
@@ -334,7 +332,7 @@ void foundZigbeeCallback(TWDevice *device)
             OC_LOG(ERROR, TAG, "Out of memory");
             return;
         }
-        piResource->header.plugin = (PIPluginBase *)gPlugin;
+        piResource->header.plugin = (PIPluginBase *)plugin;
 
         OCStackResult result = buildURI(&piResource->header.piResource.uri,
                                 PI_ZIGBEE_PREFIX,
@@ -354,11 +352,11 @@ void foundZigbeeCallback(TWDevice *device)
         if (strcmp(foundClusterID, ZB_IAS_ZONE_CLUSTER) == 0)
         {
             piResource->header.piResource.resourceTypeName
-                = getResourceTypeForIASZoneType(device);
+                = getResourceTypeForIASZoneType (device, (PIPluginBase *)plugin);
 
             OCStackResult ret = TWListenForStatusUpdates(device->nodeId,
                                                           device->endpointOfInterest->endpointId,
-                                                          *gPlugin);
+                                                          plugin);
 
             if (ret != OC_STACK_OK)
             {
@@ -391,11 +389,11 @@ void foundZigbeeCallback(TWDevice *device)
         piResource->endpointId = OICStrdup(device->endpointOfInterest->endpointId);
         piResource->clusterId =
             OICStrdup(device->endpointOfInterest->clusterList->clusterIds[i].clusterId);
-        (*gPlugin)->header.NewResourceFoundCB(&(*gPlugin)->header, &piResource->header);
+        plugin->header.NewResourceFoundCB(&(plugin)->header, &piResource->header);
     }
 }
 
-void zigbeeZoneStatusUpdate(TWUpdate * update)
+void zigbeeZoneStatusUpdate(TWUpdate * update, PIPlugin_Zigbee* plugin)
 {
     if (!update)
     {
@@ -414,7 +412,7 @@ void zigbeeZoneStatusUpdate(TWUpdate * update)
         return;
     }
 
-    (*gPlugin)->header.ObserveNotificationUpdate((PIPluginBase *)*gPlugin, uri);
+    plugin->header.ObserveNotificationUpdate((PIPluginBase *)plugin, uri);
     OICFree(uri);
 }
 
@@ -439,14 +437,13 @@ OCStackResult ZigbeeInit(const char * comPort, PIPlugin_Zigbee ** plugin,
     ((*plugin)->header).resourceList = NULL;
     ((*plugin)->header).processEHRequest = ProcessEHRequest;
 
-    gPlugin = plugin;
-    OCStackResult result = TWInitialize(*gPlugin, comPort);
+    OCStackResult result = TWInitialize(*plugin, comPort);
     if (result != OC_STACK_OK)
     {
         return result;
     }
 
-    return TWSetStatusUpdateCallback(zigbeeZoneStatusUpdate, *gPlugin);
+    return TWSetStatusUpdateCallback(zigbeeZoneStatusUpdate, *plugin);
 }
 
 OCStackResult ZigbeeDiscover(PIPlugin_Zigbee * plugin)
@@ -843,7 +840,7 @@ OCEntityHandlerResult processGetRequest(PIPluginBase * plugin,
                                      attributeList.list[i].zigBeeAttribute,
                                      &outVal,
                                      &outValLength,
-                                     *gPlugin);
+                                     (PIPlugin_Zigbee *)plugin);
 
         if (stackResult != OC_STACK_OK || !outVal)
         {
index af25e70..7a42ede 100644 (file)
@@ -129,10 +129,11 @@ typedef struct
     char eui[SIZE_EUI];
 } TWEnrollee;
 
-typedef void (*TWDeviceFoundCallback)(TWDevice* device);
-typedef void (*TWEnrollmentSucceedCallback)(TWEnrollee* enrollee);
-typedef void (*TWDeviceStatusUpdateCallback)(TWUpdate* update);
-typedef void (*TWDeviceNodeIdChangedCallback)(const char* eui, const char* nodeId);
+typedef void (*TWDeviceFoundCallback)(TWDevice* device, PIPlugin_Zigbee* plugin);
+typedef void (*TWEnrollmentSucceedCallback)(TWEnrollee* enrollee, PIPlugin_Zigbee* plugin);
+typedef void (*TWDeviceStatusUpdateCallback)(TWUpdate* update, PIPlugin_Zigbee* plugin);
+typedef void (*TWDeviceNodeIdChangedCallback)(const char* eui, const char* nodeId,
+                                              PIPlugin_Zigbee* plugin);
 
 /**
  *
index 6af8dc7..6367bca 100644 (file)
@@ -1413,7 +1413,7 @@ TWResultCode processEntryMatchDesc(TWEntry* entry, TWContext* ctx)
                 if (ctx->g_DeviceFoundCallback != NULL)
                 {
                     OC_LOG(INFO, TAG, "Found a match node -- invoke callback");
-                    ctx->g_DeviceFoundCallback(ctx->g_WIPDevice);
+                    ctx->g_DeviceFoundCallback(ctx->g_WIPDevice, ctx->g_plugin);
                 }
                 ret =  TW_RESULT_OK;
             }
@@ -2314,7 +2314,8 @@ TWResultCode TelEndDeviceJoinHandler(int count, char* tokens[], TWContext* ctx)
     if (ctx->g_EndDeviceNodeIdChangedCallback != NULL)
     {
         ctx->g_EndDeviceNodeIdChangedCallback(tokens[TOKEN_PJOIN_RESPONSE_IEEE_ADDRESS],
-                                              tokens[TOKEN_PJOIN_RESPONSE_NODEID]);
+                                              tokens[TOKEN_PJOIN_RESPONSE_NODEID],
+                                              ctx->g_plugin);
     }
 
     ret = TW_RESULT_OK;
@@ -2891,7 +2892,7 @@ TWResultCode TelEnrolledHandler(int count, char* tokens[], TWContext* ctx)
     if (ctx->g_EnrollmentSucceedCallback != NULL)
     {
         OC_LOG_V(INFO, TAG, "Enrolled - Invoke callback");
-        ctx->g_EnrollmentSucceedCallback(&enrollee);
+        ctx->g_EnrollmentSucceedCallback(&enrollee, ctx->g_plugin);
     }
     ret = TW_RESULT_OK;
 
@@ -2931,7 +2932,7 @@ TWResultCode TelZoneStatusHandler(int count, char* tokens[], TWContext* ctx)
     if (ctx->g_DeviceStatusUpdateCallback != NULL)
     {
         OC_LOG(INFO, TAG, "device status update - invoke callback");
-        ctx->g_DeviceStatusUpdateCallback(&update);
+        ctx->g_DeviceStatusUpdateCallback(&update, ctx->g_plugin);
         OC_LOG(INFO, TAG, "device status update - callback done");
     }
     ret = TW_RESULT_OK;