/* * @brief Republish message with new data from our matching identities. */ static void IdentityMap_RepublishC2D( IDENTITY_MAP_DATA * idModule, MESSAGE_HANDLE messageHandle, IDENTITY_MAP_CONFIG * match) { CONSTMAP_HANDLE properties = Message_GetProperties(messageHandle); if (properties == NULL) { LogError("Could not extract message properties"); } else { /*Codes_SRS_IDMAP_17_049: [ On a C2D message received, IdentityMap_Receive shall call ConstMap_CloneWriteable on the message properties. ]*/ MAP_HANDLE newProperties = ConstMap_CloneWriteable(properties); if (newProperties == NULL) { /*Codes_SRS_IDMAP_17_050: [ If ConstMap_CloneWriteable fails, IdentityMap_Receive shall deallocate any resources and return. ]*/ LogError("Could not make writeable new properties map"); } else { /*Codes_SRS_IDMAP_17_051: [ IdentityMap_Receive shall call Map_AddOrUpdate with key of "macAddress" and value of found macAddress. ]*/ if (Map_AddOrUpdate(newProperties, GW_MAC_ADDRESS_PROPERTY, match->macAddress) != MAP_OK) { /*Codes_SRS_IDMAP_17_052: [ If adding macAddress fails, IdentityMap_Receive shall deallocate all resources and return. ]*/ LogError("Could not attach %s property to message", GW_MAC_ADDRESS_PROPERTY); } /*Codes_SRS_IDMAP_17_032: [IdentityMap_Receive shall call Map_AddOrUpdate with key of "source" and value of "mapping".]*/ else if (Map_AddOrUpdate(newProperties, GW_SOURCE_PROPERTY, GW_IDMAP_MODULE) != MAP_OK) { /*Codes_SRS_IDMAP_17_033: [If adding source fails, IdentityMap_Receive shall deallocate all resources and return.]*/ LogError("Could not attach %s property to message", GW_SOURCE_PROPERTY); } /*Codes_SRS_IDMAP_17_055: [ IdentityMap_Receive shall call Map_Delete to remove the "deviceName" property. ]*/ else if (Map_Delete(newProperties, GW_DEVICENAME_PROPERTY) != MAP_OK) { /*Codes_SRS_IDMAP_17_056: [ If deleting the device name fails, IdentityMap_Receive shall deallocate all resources and return. ]*/ LogError("Could not remove %s property from message", GW_DEVICENAME_PROPERTY); } /*Codes_SRS_IDMAP_17_057: [ IdentityMap_Receive shall call Map_Delete to remove the "deviceKey" property. ]*/ else if (Map_Delete(newProperties, GW_DEVICEKEY_PROPERTY) == MAP_INVALIDARG) { /*Codes_SRS_IDMAP_17_058: [ If deleting the device key does not return MAP_OK or MAP_KEYNOTFOUND, IdentityMap_Receive shall deallocate all resources and return. ]*/ LogError("Could not remove %s property from message", GW_DEVICEKEY_PROPERTY); } else { publish_with_new_properties(newProperties, messageHandle, idModule); } Map_Destroy(newProperties); } ConstMap_Destroy(properties); } }
/* * @brief Republish message with new data from our matching identities. */ static void IdentityMap_RepublishD2C( IDENTITY_MAP_DATA * idModule, MESSAGE_HANDLE messageHandle, IDENTITY_MAP_CONFIG * match) { CONSTMAP_HANDLE properties = Message_GetProperties(messageHandle); if (properties == NULL) { LogError("Could not extract message properties"); } else { /*Codes_SRS_IDMAP_17_026: [On a message which passes all checks, IdentityMap_Receive shall call ConstMap_CloneWriteable on the message properties.]*/ MAP_HANDLE newProperties = ConstMap_CloneWriteable(properties); if (newProperties == NULL) { /*Codes_SRS_IDMAP_17_027: [If ConstMap_CloneWriteable fails, IdentityMap_Receive shall deallocate any resources and return.] */ LogError("Could not make writeable new properties map"); } else { /*Codes_SRS_IDMAP_17_028: [IdentityMap_Receive shall call Map_AddOrUpdate with key of "deviceName" and value of found deviceId.]*/ if (Map_AddOrUpdate(newProperties, GW_DEVICENAME_PROPERTY, match->deviceId) != MAP_OK) { /*Codes_SRS_IDMAP_17_029: [If adding deviceName fails,IdentityMap_Receive shall deallocate all resources and return.]*/ LogError("Could not attach %s property to message", GW_DEVICENAME_PROPERTY); } /*Codes_SRS_IDMAP_17_030: [IdentityMap_Receive shall call Map_AddOrUpdate with key of "deviceKey" and value of found deviceKey.]*/ else if (Map_AddOrUpdate(newProperties, GW_DEVICEKEY_PROPERTY, match->deviceKey) != MAP_OK) { /*Codes_SRS_IDMAP_17_031: [If adding deviceKey fails, IdentityMap_Receive shall deallocate all resources and return.]*/ LogError("Could not attach %s property to message", GW_DEVICEKEY_PROPERTY); } /*Codes_SRS_IDMAP_17_032: [IdentityMap_Receive shall call Map_AddOrUpdate with key of "source" and value of "mapping".]*/ else if (Map_AddOrUpdate(newProperties, GW_SOURCE_PROPERTY, GW_IDMAP_MODULE) != MAP_OK) { /*Codes_SRS_IDMAP_17_033: [If adding source fails, IdentityMap_Receive shall deallocate all resources and return.]*/ LogError("Could not attach %s property to message", GW_SOURCE_PROPERTY); } /*Codes_SRS_IDMAP_17_053: [ IdentityMap_Receive shall call Map_Delete to remove the "macAddress" property. ]*/ else if (Map_Delete(newProperties, GW_MAC_ADDRESS_PROPERTY) != MAP_OK) { /*Codes_SRS_IDMAP_17_054: [ If deleting the MAC Address fails, IdentityMap_Receive shall deallocate all resources and return. ]*/ LogError("Could not remove %s property from message", GW_MAC_ADDRESS_PROPERTY); } else { publish_with_new_properties(newProperties, messageHandle, idModule); } Map_Destroy(newProperties); } ConstMap_Destroy(properties); } }
int IOCP_Destroy(IOCP* iocp) { HANDLE curThread = NULL; int i = 0; if(iocp->hThreads) { curThread = GetCurrentThread(); for(i = 0; i < iocp->threads; ++i) { if(curThread == iocp->hThreads[i]) return IOCP_DESTROYFAILED; } } iocp->inited = FALSE; if(iocp->hThreads) { if(iocp->iocpHandle) { for(i = 0; i < iocp->threads; ++i){ PostQueuedCompletionStatus(iocp->iocpHandle, 0, (ULONG_PTR)NULL, NULL); } } for(i = 0; i < iocp->threads; ++i) { if( iocp->hThreads[i] ) { WaitForSingleObject(iocp->hThreads[i], INFINITE); CloseHandle(iocp->hThreads[i]); } } xFree(iocp->hThreads); } iocp->hThreads = NULL; iocp->threads = 0; if(iocp->iocpHandle) { if(!CloseHandle(iocp->iocpHandle)){ } iocp->iocpHandle = NULL; } TimerQueue_Destory(&iocp->timerQueue); Map_Foreach(iocp->contextMap, IOCP_ContextHandler); Map_Delete(iocp->contextMap); LockPool_Destroy(&iocp->lockPool); DeleteCriticalSection(&iocp->cs); return IOCP_SUCESS; }