Added logic for remove NSProvider. 93/9493/5
authorKIM JungYong <jyong2.kim@samsung.com>
Fri, 22 Jul 2016 02:19:01 +0000 (11:19 +0900)
committerUze Choi <uzchoi@samsung.com>
Fri, 22 Jul 2016 08:18:42 +0000 (08:18 +0000)
When subscribe cancel API called by user,
information of target provider need to be removed in storage.

NSProvider is removed when user call subscribe cancel API.

Conflicts:
        service/notification/src/consumer/NSConsumerCommunication.c

Change-Id: I480f2253d3eb52af62bab01235ba5cb2888fda8a
Signed-off-by: KIM JungYong <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9493
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
service/notification/examples/linux/notificationconsumer.c
service/notification/include/NSCommon.h
service/notification/src/common/NSStructs.h
service/notification/src/common/NSUtil.c
service/notification/src/consumer/NSConsumerCommon.c
service/notification/src/consumer/NSConsumerCommon.h
service/notification/src/consumer/NSConsumerCommunication.c
service/notification/src/consumer/NSConsumerInterface.c
service/notification/src/consumer/NSConsumerInternalTaskController.c
service/notification/src/consumer/NSConsumerScheduler.c
service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c

index 9d526e7..4d72807 100644 (file)
@@ -33,7 +33,7 @@ void onSubscriptionAccepted(NSProvider * provider)
 
 void onNotificationPosted(NSMessage * notification)
 {
-    printf("id : %lld\n", notification->messageId);
+    printf("id : %lld\n", (long long int)notification->messageId);
     printf("title : %s\n", notification->title);
     printf("content : %s\n", notification->contentText);
     printf("source : %s\n", notification->sourceName);
@@ -42,7 +42,7 @@ void onNotificationPosted(NSMessage * notification)
 
 void onNotificationSync(NSSyncInfo * sync)
 {
-    printf("Sync ID : %lld\n", sync->messageId);
+    printf("Sync ID : %lld\n", (long long int)sync->messageId);
     printf("Sync STATE : %d\n", sync->state);
 }
 
index e5c64bb..41beb5d 100644 (file)
@@ -27,6 +27,8 @@
 #ifndef _NS_COMMON_H_
 #define _NS_COMMON_H_
 
+#include <stdint.h>
+
 #define NS_ATTRIBUTE_POLICY "ACCEPTER"
 #define NS_ATTRIBUTE_MESSAGE "MESSAGE_URI"
 #define NS_ATTRIBUTE_SYNC "SYNC_URI"
index 777113a..47e30ed 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdlib.h>\r
 #include <stdio.h>\r
 #include <stdbool.h>\r
+#include <octypes.h>\r
 #include "NSCommon.h"\r
 #include "NSConstants.h"\r
 \r
index 6945199..5b6f41b 100755 (executable)
@@ -272,7 +272,7 @@ NSSyncInfo * NSGetSyncInfo(OCPayload * payload)
     OICFree(providerId);
 
     NS_LOG_V(DEBUG, "Provider ID : %s", retSync->providerId);
-    NS_LOG_V(DEBUG, "Sync ID : %lld", retSync->messageId);
+    NS_LOG_V(DEBUG, "Sync ID : %lld", (long long int)retSync->messageId);
     NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->state);
 
     NS_LOG(DEBUG, "NSGetSyncInfo - OUT");
index 87b3d40..2004680 100644 (file)
@@ -241,9 +241,6 @@ NSMessage_consumer * NSCopyMessage(NSMessage_consumer * msg)
     NS_VERIFY_NOT_NULL(newMsg, NULL);
 
     OICStrcpy(newMsg->providerId, NS_DEVICE_ID_LENGTH, msg->providerId);
-    newMsg->i_addr = (OCDevAddr *)OICMalloc(sizeof(OCDevAddr));
-    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(newMsg, NULL, NSOICFree(newMsg));
-    memcpy(newMsg->i_addr, msg->i_addr, sizeof(OCDevAddr));
 
     newMsg->messageId = msg->messageId;
     newMsg->title = OICStrdup(msg->title);
@@ -261,7 +258,10 @@ void NSRemoveMessage(NSMessage_consumer * msg)
     NSOICFree(msg->title);
     NSOICFree(msg->contentText);
     NSOICFree(msg->sourceName);
-    NSOICFree(msg->i_addr);
+    NSOICFree(msg->dateTime);
+
+    // TODO change to remove function.
+    NSOICFree(msg->mediaContents);
 
     NSOICFree(msg);
 }
@@ -312,6 +312,7 @@ NSProviderConnectionInfo * NSCopyProviderConnections(NSProviderConnectionInfo *
     NSProviderConnectionInfo * tmp = conn;
 
     NSProviderConnectionInfo * retInfo = NSCreateProviderConnections(tmp->addr);
+    NS_VERIFY_NOT_NULL(retInfo, NULL);
     tmp = tmp->next;
     NSProviderConnectionInfo * copyInfo = retInfo;
 
index d2d4f3e..d1e9272 100644 (file)
@@ -181,10 +181,8 @@ typedef struct
     char * title;
     char * contentText;
     char * sourceName;
-    NSMediaContents mediaContents;
+    NSMediaContents mediaContents;
 
-    OCDevAddr * i_addr;
-    NSSyncType i_messageTypes;
 } NSMessage_consumer;
 
 bool NSIsStartedConsumer();
index 274e007..249828a 100644 (file)
@@ -204,19 +204,11 @@ NSMessage_consumer * NSGetMessage(OCClientResponse * clientResponse)
     NS_LOG_V (DEBUG, "provider id: %s", pId);
     NS_VERIFY_NOT_NULL(getResult == true ? (void *) 1 : NULL, NULL);
 
-    NS_LOG(DEBUG, "get provider address");
-    OCDevAddr * addr = (OCDevAddr *)OICMalloc(sizeof(OCDevAddr));
-    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(addr, NULL, NSGetMessagePostClean(pId, addr));
-    memcpy(addr, clientResponse->addr, sizeof(OCDevAddr));
-
     NS_LOG(DEBUG, "create NSMessage");
     NSMessage_consumer * retMsg = NSCreateMessage_internal(id, pId);
-    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(retMsg, NULL, NSGetMessagePostClean(pId, addr));
+    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(retMsg, NULL, NSOICFree(pId));
     NSOICFree(pId);
 
-    retMsg->i_addr = addr;
-    retMsg->i_messageTypes = NS_SYNC_UNREAD;
-
     NS_LOG(DEBUG, "get msg optional field");
     OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_TITLE, &retMsg->title);
     OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_TEXT, &retMsg->contentText);
@@ -226,14 +218,13 @@ NSMessage_consumer * NSGetMessage(OCClientResponse * clientResponse)
     OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_DATETIME, &retMsg->dateTime);
     OCRepPayloadGetPropInt(payload, NS_ATTRIBUTE_TTL, (int64_t *)&retMsg->ttl);
 
-    NS_LOG_V(DEBUG, "Msg Address : %s", retMsg->i_addr->addr);
-    NS_LOG_V(DEBUG, "Msg ID      : %lld", retMsg->messageId);
+    NS_LOG_V(DEBUG, "Msg ID      : %lld", (long long int)retMsg->messageId);
     NS_LOG_V(DEBUG, "Msg Title   : %s", retMsg->title);
     NS_LOG_V(DEBUG, "Msg Content : %s", retMsg->contentText);
     NS_LOG_V(DEBUG, "Msg Source  : %s", retMsg->sourceName);
     NS_LOG_V(DEBUG, "Msg Type    : %d", retMsg->type);
     NS_LOG_V(DEBUG, "Msg Date    : %s", retMsg->dateTime);
-    NS_LOG_V(DEBUG, "Msg ttl     : %lld", retMsg->ttl);
+    NS_LOG_V(DEBUG, "Msg ttl     : %lld", (long long int)retMsg->ttl);
 
     return retMsg;
 }
@@ -263,7 +254,7 @@ NSSyncInfo * NSGetSyncInfoc(OCClientResponse * clientResponse)
     NSSyncInfo * retSync = NSCreateSyncInfo_consumer(id, pId, (NSSyncType)state);
     NS_VERIFY_NOT_NULL(retSync, NULL);
 
-    NS_LOG_V(DEBUG, "Sync ID : %lld", retSync->messageId);
+    NS_LOG_V(DEBUG, "Sync ID : %lld", (long long int)retSync->messageId);
     NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->state);
     NS_LOG_V(DEBUG, "Sync Provider ID : %s", retSync->providerId);
 
@@ -283,7 +274,7 @@ NSMessage_consumer * NSCreateMessage_internal(uint64_t id, const char * provider
     retMsg->type = NS_MESSAGE_INFO;
     retMsg->dateTime = NULL;
     retMsg->ttl = 0;
-    retMsg->i_addr = NULL;
+    retMsg->mediaContents = NULL;
 
     return retMsg;
 }
index 4425ac1..60cf0c3 100644 (file)
@@ -124,7 +124,7 @@ NSProvider * NSConsumerGetProvider(const char * providerId)
 NSMessage * NSConsumerGetMessage(uint64_t messageId)
 {
     char msgId[NS_DEVICE_ID_LENGTH] = { 0, };
-    snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", messageId);
+    snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", (long long int)messageId);
 
     return (NSMessage *) NSConsumerFindNSMessage(msgId);
 }
index 8e8f7a0..a00e42a 100644 (file)
@@ -237,8 +237,13 @@ void NSConsumerHandleProviderDiscovered(NSProvider_internal * provider)
 
 void NSConsumerHandleProviderDeleted(NSProvider_internal * provider)
 {
-    // TODO delete provider infomation on storage list.
-    (void) provider;
+    NS_VERIFY_NOT_NULL_V(provider);
+
+    NSCacheList * providerCache = *(NSGetProviderCacheList());
+    NS_VERIFY_NOT_NULL_V(providerCache);
+
+    NSResult ret = NSStorageDelete(providerCache, provider->providerId);
+    NS_VERIFY_NOT_NULL_V(ret == NS_OK ? (void *)1 : NULL);
 }
 
 void NSConsumerHandleRecvSubscriptionConfirmed(NSMessage_consumer * msg)
@@ -270,7 +275,7 @@ void NSConsumerHandleRecvSyncInfo(NSSyncInfo * sync)
     NS_VERIFY_NOT_NULL_V(sync);
 
     char msgId[NS_DEVICE_ID_LENGTH] = { 0, };
-    snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", sync->messageId);
+    snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", (long long int)sync->messageId);
 
     NSMessage_consumer * msg = NSMessageCacheFind(msgId);
     NS_VERIFY_NOT_NULL_V(msg);
index 82a9740..6e1ccf7 100644 (file)
@@ -212,12 +212,21 @@ void NSConsumerTaskProcessing(NSTask * task)
         break;
     }
     case TASK_CONSUMER_REQ_SUBSCRIBE:
-    case TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL:
     case TASK_SEND_SYNCINFO:
     {
         NSConsumerCommunicationTaskProcessing(task);
         break;
     }
+    case TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL:
+    {
+        NSProvider_internal * data = NSCopyProvider((NSProvider_internal *)task->taskData);
+        NS_VERIFY_NOT_NULL_V(data);
+        NSTask * conTask = NSMakeTask(TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL, data);
+        NS_VERIFY_NOT_NULL_V(conTask);
+        NSConsumerCommunicationTaskProcessing(task);
+        NSConsumerInternalTaskProcessing(conTask);
+        break;
+    }
     case TASK_RECV_SYNCINFO:
     case TASK_CONSUMER_RECV_MESSAGE:
     case TASK_CONSUMER_PROVIDER_DISCOVERED:
index 81fb11a..56fc5c7 100644 (file)
@@ -211,7 +211,7 @@ NSResult NSConsumerCacheWriteMessage(NSCacheList * list, NSCacheElement * newObj
 
     pthread_mutex_unlock(mutex);
     char msgId[NS_DEVICE_ID_LENGTH] = {0, };
-    snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", newMsgObj->messageId);
+    snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", (long long int)newMsgObj->messageId);
     NSCacheElement * it = NSStorageRead(list, msgId);
     pthread_mutex_lock(mutex);
 
@@ -427,7 +427,7 @@ bool NSConsumerCompareIdCacheData(NSCacheType type, void * data, const char * id
         NSMessage_consumer * msg = (NSMessage_consumer *) data;
 
         char msgId[NS_DEVICE_ID_LENGTH] = {0, };
-        snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", msg->messageId);
+        snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", (long long int)msg->messageId);
         if (!strcmp(msgId, id))
         {
             return true;