#include "NSProviderMemoryCache.h"\r
#include <string.h>\r
\r
+#define NS_PROVIDER_DELETE_REGISTERED_TOPIC_DATA(it, topicData, newObj) \\r
+ { \\r
+ if (it) \\r
+ { \\r
+ NS_LOG(DEBUG, "already registered for topic name"); \\r
+ OICFree(topicData->topicName); \\r
+ OICFree(topicData); \\r
+ OICFree(newObj); \\r
+ pthread_mutex_unlock(&NSCacheMutex); \\r
+ return NS_FAIL; \\r
+ } \\r
+ }\r
+\r
NSCacheList * NSProviderStorageCreate()\r
{\r
pthread_mutex_lock(&NSCacheMutex);\r
NSCacheTopicData * topicData = (NSCacheTopicData *) newObj->data;\r
NSCacheElement * it = NSProviderStorageRead(list, topicData->topicName);\r
\r
- if (it)\r
- {\r
- NS_LOG(DEBUG, "already registered for topic name");\r
- OICFree(topicData->topicName);\r
- OICFree(topicData);\r
- OICFree(newObj);\r
- pthread_mutex_unlock(&NSCacheMutex);\r
- return NS_FAIL;\r
- }\r
+ NS_PROVIDER_DELETE_REGISTERED_TOPIC_DATA(it, topicData, newObj);\r
}\r
else if(type == NS_PROVIDER_CACHE_CONSUMER_TOPIC_NAME)\r
{\r
NSCacheTopicSubData * topicData = (NSCacheTopicSubData *) newObj->data;\r
NSCacheElement * it = NSProviderStorageRead(list, topicData->topicName);\r
\r
- if (it)\r
- {\r
- NS_LOG(DEBUG, "already registered for topic name");\r
- OICFree(topicData->topicName);\r
- OICFree(topicData);\r
- OICFree(newObj);\r
- pthread_mutex_unlock(&NSCacheMutex);\r
- return NS_FAIL;\r
- }\r
+ NS_PROVIDER_DELETE_REGISTERED_TOPIC_DATA(it, topicData, newObj);\r
}\r
else if(type == NS_PROVIDER_CACHE_CONSUMER_TOPIC_CID)\r
{\r
NSCacheTopicSubData * topicData = (NSCacheTopicSubData *) newObj->data;\r
NSCacheElement * it = NSProviderStorageRead(list, topicData->id);\r
\r
- if (it)\r
- {\r
- NS_LOG(DEBUG, "already registered for topic name");\r
- OICFree(topicData->topicName);\r
- OICFree(topicData);\r
- OICFree(newObj);\r
- pthread_mutex_unlock(&NSCacheMutex);\r
- return NS_FAIL;\r
- }\r
+ NS_PROVIDER_DELETE_REGISTERED_TOPIC_DATA(it, topicData, newObj);\r
}\r
\r
if (list->head == NULL)\r
return NS_OK;\r
}\r
\r
-\r
bool NSIsSameObId(NSCacheSubData * data, OCObservationId id)\r
{\r
if (id == data->messageObId || id == data->syncObId || id == data->remote_messageObId ||\r