From 5518ab3e83c18a54fe2cc8f555a6f27f89af08b4 Mon Sep 17 00:00:00 2001 From: Thuyen Tran Date: Fri, 23 Oct 2015 16:10:48 -0700 Subject: [PATCH] Added context for callbacks. Change-Id: Ia20cae8abc1e4a4112bc70608fb482174701abbb Signed-off-by: Thuyen Tran Signed-off-by: Joseph Morrow Reviewed-on: https://gerrit.iotivity.org/gerrit/3939 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz --- plugins/samples/linux/IotivityandZigbeeClient.c | 2 +- plugins/zigbee_wrapper/src/zigbee_wrapper.c | 27 ++++++++++------------ .../telegesis_wrapper/include/telegesis_wrapper.h | 9 ++++---- .../telegesis_wrapper/src/telegesis_wrapper.c | 9 ++++---- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/plugins/samples/linux/IotivityandZigbeeClient.c b/plugins/samples/linux/IotivityandZigbeeClient.c index ad0bef5..99b4d3b 100644 --- a/plugins/samples/linux/IotivityandZigbeeClient.c +++ b/plugins/samples/linux/IotivityandZigbeeClient.c @@ -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) diff --git a/plugins/zigbee_wrapper/src/zigbee_wrapper.c b/plugins/zigbee_wrapper/src/zigbee_wrapper.c index 9b09814..57cc6d8 100644 --- a/plugins/zigbee_wrapper/src/zigbee_wrapper.c +++ b/plugins/zigbee_wrapper/src/zigbee_wrapper.c @@ -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) { diff --git a/plugins/zigbee_wrapper/telegesis_wrapper/include/telegesis_wrapper.h b/plugins/zigbee_wrapper/telegesis_wrapper/include/telegesis_wrapper.h index af25e70..7a42ede 100644 --- a/plugins/zigbee_wrapper/telegesis_wrapper/include/telegesis_wrapper.h +++ b/plugins/zigbee_wrapper/telegesis_wrapper/include/telegesis_wrapper.h @@ -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); /** * diff --git a/plugins/zigbee_wrapper/telegesis_wrapper/src/telegesis_wrapper.c b/plugins/zigbee_wrapper/telegesis_wrapper/src/telegesis_wrapper.c index 6af8dc7..6367bca 100644 --- a/plugins/zigbee_wrapper/telegesis_wrapper/src/telegesis_wrapper.c +++ b/plugins/zigbee_wrapper/telegesis_wrapper/src/telegesis_wrapper.c @@ -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; -- 2.7.4