X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fnotification%2Fsrc%2Fprovider%2FNSProviderNotification.c;h=01191164e8294df50d15290c817c3fd63c5929ed;hb=refs%2Ftags%2Ftizen_4.0.m2_release;hp=3b1dcedda5d497a09d4933eeb46edaf4f215a0ea;hpb=4ed8d73b591a245d828e97f79a47a2e572475bd3;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/notification/src/provider/NSProviderNotification.c b/service/notification/src/provider/NSProviderNotification.c index 3b1dced..0119116 100644 --- a/service/notification/src/provider/NSProviderNotification.c +++ b/service/notification/src/provider/NSProviderNotification.c @@ -19,23 +19,14 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #include "NSProviderNotification.h" - -NSResult NSInitMessageList() -{ - NS_LOG(DEBUG, "NSInitMessageList - IN"); - - messageList = NSStorageCreate(); - messageList->cacheType = NS_PROVIDER_CACHE_MESSAGE; - - NS_LOG(DEBUG, "NSInitMessageList - OUT"); - return NS_OK; -} +#include "NSProviderListener.h" +#include "NSProviderSystem.h" NSResult NSSetMessagePayload(NSMessage *msg, OCRepPayload** msgPayload) { NS_LOG(DEBUG, "NSSetMessagePayload - IN"); - *msgPayload = OCRepPayloadCreate(); + *msgPayload = msg->extraInfo != NULL ? msg->extraInfo : OCRepPayloadCreate(); if (!*msgPayload) { @@ -48,11 +39,18 @@ NSResult NSSetMessagePayload(NSMessage *msg, OCRepPayload** msgPayload) OCRepPayloadSetPropString(*msgPayload, NS_ATTRIBUTE_PROVIDER_ID, msg->providerId); NSDuplicateSetPropertyInt(msgPayload, NS_ATTRIBUTE_TYPE, msg->type); - NSDuplicateSetPropertyInt(msgPayload, NS_ATTRIBUTE_MESSAGE_ID, msg->ttl); + NSDuplicateSetPropertyInt(msgPayload, NS_ATTRIBUTE_TTL, msg->ttl); NSDuplicateSetPropertyString(msgPayload, NS_ATTRIBUTE_DATETIME, msg->dateTime); NSDuplicateSetPropertyString(msgPayload, NS_ATTRIBUTE_TITLE, msg->title); NSDuplicateSetPropertyString(msgPayload, NS_ATTRIBUTE_TEXT, msg->contentText); NSDuplicateSetPropertyString(msgPayload, NS_ATTRIBUTE_SOURCE, msg->sourceName); + NSDuplicateSetPropertyString(msgPayload, NS_ATTRIBUTE_TOPIC_NAME, msg->topic); + + if (msg->mediaContents) + { + NSDuplicateSetPropertyString(msgPayload, NS_ATTRIBUTE_ICON_IMAGE, + msg->mediaContents->iconImage); + } NS_LOG(DEBUG, "NSSetMessagePayload - OUT"); return NS_OK; @@ -80,6 +78,31 @@ NSResult NSSetSyncPayload(NSSyncInfo *sync, OCRepPayload** syncPayload) return NS_OK; } +#ifdef WITH_MQ +OCStackResult NSProviderPublishTopic(OCRepPayload * payload, OCClientResponseHandler response) +{ + NS_LOG(DEBUG, "NSProviderPublishTopic - IN"); + OCCallbackData cbData; + memset(&cbData, 0, sizeof(OCCallbackData)); + cbData.cb = response; + cbData.cd = NULL; + cbData.context = NULL; + + NSMQServerInfo * serverInfo = NSGetMQServerInfo(); + + if (!serverInfo) + { + NS_LOG(DEBUG, "serverInfo is not NULL"); + NS_LOG_V(DEBUG, "serverInfo->serverUri = %s", serverInfo->serverUri); + } + + NS_LOG(DEBUG, "NSProviderPublishTopic - OUT"); + + return OCDoResource(NULL, OC_REST_POST, serverInfo->serverUri, serverInfo->devAddr, + (OCPayload *)payload, CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0); +} +#endif + NSResult NSSendNotification(NSMessage *msg) { NS_LOG(DEBUG, "NSSendMessage - IN"); @@ -94,17 +117,26 @@ NSResult NSSendNotification(NSMessage *msg) return NS_ERROR; } - if (consumerSubList->head == NULL) + OCRepPayload* payload = NULL; + + if (NSSetMessagePayload(msg, &payload) != NS_OK) { - NS_LOG(ERROR, "SubList->head is NULL, empty SubList"); + NS_LOG(ERROR, "fail to Get message payload"); return NS_ERROR; } - OCRepPayload* payload = NULL; +#ifdef WITH_MQ + if (NSGetMQServerInfo()) + { + NSProviderPublishTopic(OCRepPayloadClone(payload), NSProviderPublishMQResponseCB); + } +#endif - if (NSSetMessagePayload(msg, &payload) != NS_OK) + if (consumerSubList->head == NULL) { - NS_LOG(ERROR, "fail to Get message payload"); + NS_LOG(ERROR, "SubList->head is NULL, empty SubList"); + OCRepPayloadDestroy(payload); + msg->extraInfo = NULL; return NS_ERROR; } @@ -113,7 +145,7 @@ NSResult NSSendNotification(NSMessage *msg) while (it) { NSCacheSubData * subData = (NSCacheSubData *) it->data; - NS_LOG_V(DEBUG, "message subData->id = %s", subData->id); + NS_LOG_V(INFO_PRIVATE, "message subData->id = %s", subData->id); NS_LOG_V(DEBUG, "subData->messageId = %d", subData->messageObId); NS_LOG_V(DEBUG, "subData->cloud_messageId = %d", subData->remote_messageObId); NS_LOG_V(DEBUG, "subData->syncId = %d", subData->syncObId); @@ -124,13 +156,36 @@ NSResult NSSendNotification(NSMessage *msg) { if(subData->messageObId != 0) { - obArray[obCount++] = subData->messageObId; + if (msg->topic && (msg->topic)[0] != '\0') + { + NS_LOG_V(DEBUG, "this is topic message: %s", msg->topic); + + if (NSProviderIsTopicSubScribed(consumerTopicList->head, subData->id, msg->topic)) + { + obArray[obCount++] = subData->messageObId; + } + } + else + { + obArray[obCount++] = subData->messageObId; + } } -#ifdef WITH_CLOUD - if(subData->remote_messageObId != 0) +#if (defined WITH_CLOUD) + if (subData->remote_messageObId != 0) { - obArray[obCount++] = subData->remote_messageObId; + if (msg->topic && (msg->topic)[0] != '\0') + { + NS_LOG_V(DEBUG, "this is topic message via remote server: %s", msg->topic); + if (NSProviderIsTopicSubScribed(consumerTopicList->head, subData->id, msg->topic)) + { + obArray[obCount++] = subData->remote_messageObId; + } + } + else + { + obArray[obCount++] = subData->remote_messageObId; + } } #endif @@ -145,14 +200,16 @@ NSResult NSSendNotification(NSMessage *msg) NS_LOG(DEBUG, "-------------------------------------------------------message\n"); } - if(!obCount) + if (!obCount) { NS_LOG(ERROR, "observer count is zero"); + OCRepPayloadDestroy(payload); + msg->extraInfo = NULL; return NS_ERROR; } OCStackResult ocstackResult = OCNotifyListOfObservers(rHandle, obArray, obCount, payload, - OC_HIGH_QOS); + OC_LOW_QOS); NS_LOG_V(DEBUG, "Message ocstackResult = %d", ocstackResult); @@ -160,13 +217,14 @@ NSResult NSSendNotification(NSMessage *msg) { NS_LOG(ERROR, "fail to send message"); OCRepPayloadDestroy(payload); + msg->extraInfo = NULL; return NS_ERROR; } + OCRepPayloadDestroy(payload); - NSFreeMessage(msg); + msg->extraInfo = NULL; NS_LOG(DEBUG, "NSSendMessage - OUT"); - return NS_OK; } @@ -190,7 +248,7 @@ NSResult NSSendSync(NSSyncInfo *sync) while (it) { NSCacheSubData * subData = (NSCacheSubData *) it->data; - NS_LOG_V(DEBUG, "sync subData->id = %s", subData->id); + NS_LOG_V(INFO_PRIVATE, "sync subData->id = %s", subData->id); NS_LOG_V(DEBUG, "subData->messageId = %d", subData->messageObId); NS_LOG_V(DEBUG, "subData->cloud_messageId = %d", subData->remote_messageObId); NS_LOG_V(DEBUG, "subData->syncId = %d", subData->syncObId); @@ -199,13 +257,13 @@ NSResult NSSendSync(NSSyncInfo *sync) if (subData->isWhite) { - if(subData->syncObId != 0) + if (subData->syncObId != 0) { obArray[obCount++] = subData->syncObId; } -#ifdef WITH_CLOUD - if(subData->remote_syncObId != 0) +#if (defined WITH_CLOUD) + if (subData->remote_syncObId != 0) { obArray[obCount++] = subData->remote_syncObId; } @@ -214,13 +272,33 @@ NSResult NSSendSync(NSSyncInfo *sync) it = it->next; } - OCRepPayload* payload; + OCRepPayload* payload = NULL; if (NSSetSyncPayload(sync, &payload) != NS_OK) { NS_LOG(ERROR, "Failed to allocate payload"); return NS_ERROR; } +#ifdef WITH_MQ + if (NSGetMQServerInfo()) + { + OCRepPayload* MQPayload = OCRepPayloadClone(payload); + NSMessageType MQType = 0; + + if (sync->state == NS_SYNC_READ) + { + MQType = NS_MESSAGE_READ; + } + else if (sync->state == NS_SYNC_DELETED) + { + MQType = NS_MESSAGE_DELETED; + } + + OCRepPayloadSetPropInt(MQPayload, NS_ATTRIBUTE_TYPE, (int64_t) MQType); + NSProviderPublishTopic(MQPayload, NSProviderPublishMQResponseCB); + } +#endif + for (i = 0; i < obCount; ++i) { NS_LOG(DEBUG, "-------------------------------------------------------message\n"); @@ -229,10 +307,9 @@ NSResult NSSendSync(NSSyncInfo *sync) } OCStackResult ocstackResult = OCNotifyListOfObservers(rHandle, obArray, - obCount, payload, OC_HIGH_QOS); + obCount, payload, OC_LOW_QOS); NS_LOG_V(DEBUG, "Sync ocstackResult = %d", ocstackResult); - if (ocstackResult != OC_STACK_OK) { NS_LOG(ERROR, "fail to send Sync"); @@ -269,8 +346,9 @@ void * NSNotificationSchedule(void *ptr) { NS_LOG(DEBUG, "CASE TASK_SEND_NOTIFICATION : "); NSSendNotification((NSMessage *)node->taskData); - break; + NSFreeMessage((NSMessage *)node->taskData); } + break; case TASK_SEND_READ: NS_LOG(DEBUG, "CASE TASK_SEND_READ : "); NSSendSync((NSSyncInfo*) node->taskData); @@ -286,11 +364,10 @@ void * NSNotificationSchedule(void *ptr) break; } - OICFree(node); + NSOICFree(node); } pthread_mutex_unlock(&NSMutex[NOTIFICATION_SCHEDULER]); - } NS_LOG(INFO, "Destroy NSNotificationSchedule");