X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fnotification%2Fsrc%2Fprovider%2FNSProviderNotification.c;h=01191164e8294df50d15290c817c3fd63c5929ed;hb=c315c87e07c4080ecd0ef488e7a1047bc3c509b2;hp=1b5f893ff7684ebca82ff426c84b72253f2e85ed;hpb=8de9990bc118de9bfe4adb8c037ff2b3a4adab4a;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/notification/src/provider/NSProviderNotification.c b/service/notification/src/provider/NSProviderNotification.c index 1b5f893..0119116 100644 --- a/service/notification/src/provider/NSProviderNotification.c +++ b/service/notification/src/provider/NSProviderNotification.c @@ -19,12 +19,14 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #include "NSProviderNotification.h" +#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) { @@ -37,13 +39,19 @@ 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; } @@ -70,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"); @@ -84,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; } @@ -103,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); @@ -114,11 +156,11 @@ NSResult NSSendNotification(NSMessage *msg) { if(subData->messageObId != 0) { - if(msg->topic) + 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)) + if (NSProviderIsTopicSubScribed(consumerTopicList->head, subData->id, msg->topic)) { obArray[obCount++] = subData->messageObId; } @@ -129,12 +171,16 @@ NSResult NSSendNotification(NSMessage *msg) } } -#ifdef RD_CLIENT - if(subData->remote_messageObId != 0) +#if (defined WITH_CLOUD) + if (subData->remote_messageObId != 0) { - if(NSProviderIsTopicSubScribed(consumerTopicList->head, subData->id, msg->topic)) + if (msg->topic && (msg->topic)[0] != '\0') { - obArray[obCount++] = subData->remote_messageObId; + 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 { @@ -154,9 +200,11 @@ 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; } @@ -169,13 +217,14 @@ NSResult NSSendNotification(NSMessage *msg) { NS_LOG(ERROR, "fail to send message"); OCRepPayloadDestroy(payload); + msg->extraInfo = NULL; return NS_ERROR; } OCRepPayloadDestroy(payload); + msg->extraInfo = NULL; NS_LOG(DEBUG, "NSSendMessage - OUT"); - return NS_OK; } @@ -199,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); @@ -208,13 +257,13 @@ NSResult NSSendSync(NSSyncInfo *sync) if (subData->isWhite) { - if(subData->syncObId != 0) + if (subData->syncObId != 0) { obArray[obCount++] = subData->syncObId; } -#ifdef RD_CLIENT - if(subData->remote_syncObId != 0) +#if (defined WITH_CLOUD) + if (subData->remote_syncObId != 0) { obArray[obCount++] = subData->remote_syncObId; } @@ -223,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"); @@ -241,7 +310,6 @@ NSResult NSSendSync(NSSyncInfo *sync) 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"); @@ -296,11 +364,10 @@ void * NSNotificationSchedule(void *ptr) break; } - OICFree(node); + NSOICFree(node); } pthread_mutex_unlock(&NSMutex[NOTIFICATION_SCHEDULER]); - } NS_LOG(INFO, "Destroy NSNotificationSchedule");