From 7a5fdfca6110453fcd3cf0d52e6874cadaddc09a Mon Sep 17 00:00:00 2001 From: KIM JungYong Date: Thu, 8 Sep 2016 19:47:27 +0900 Subject: [PATCH] Add logic for media contents. Media contents parse and copy, remove logic is added at consumer service. Change-Id: If2079e33fcb0f84f983212468786657cfdc91976 Signed-off-by: KIM JungYong Reviewed-on: https://gerrit.iotivity.org/gerrit/11571 Reviewed-by: Uze Choi Tested-by: Uze Choi --- service/notification/src/consumer/NSConsumerCommon.c | 20 ++++++++++++++++---- .../src/consumer/NSConsumerCommunication.c | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/service/notification/src/consumer/NSConsumerCommon.c b/service/notification/src/consumer/NSConsumerCommon.c index 13524bc..3ddd7c9 100644 --- a/service/notification/src/consumer/NSConsumerCommon.c +++ b/service/notification/src/consumer/NSConsumerCommon.c @@ -245,9 +245,18 @@ NSMessage * NSCopyMessage(NSMessage * msg) { newMsg->topic = OICStrdup(msg->topic); } - - // TODO change to copy function. - newMsg->mediaContents = msg->mediaContents; + if (msg->mediaContents) + { + newMsg->mediaContents = (NSMediaContents *)OICMalloc(sizeof(NSMediaContents)); + NS_VERIFY_NOT_NULL_WITH_POST_CLEANING( + newMsg->mediaContents, NULL, NSRemoveMessage(newMsg)); + newMsg->mediaContents->iconImage = + (char *)OICMalloc(sizeof(char)*strlen(msg->mediaContents->iconImage)); + NS_VERIFY_NOT_NULL_WITH_POST_CLEANING( + newMsg->mediaContents->iconImage, NULL, NSRemoveMessage(newMsg)); + memcpy(newMsg->mediaContents->iconImage, msg->mediaContents->iconImage, + strlen(msg->mediaContents->iconImage)); + } return newMsg; } @@ -262,7 +271,10 @@ void NSRemoveMessage(NSMessage * msg) NSOICFree(msg->dateTime); NSOICFree(msg->topic); - // TODO change to remove function. + if (msg->mediaContents) + { + NSOICFree(msg->mediaContents->iconImage); + } NSOICFree(msg->mediaContents); NSOICFree(msg); diff --git a/service/notification/src/consumer/NSConsumerCommunication.c b/service/notification/src/consumer/NSConsumerCommunication.c index 80b9559..5ca27f5 100644 --- a/service/notification/src/consumer/NSConsumerCommunication.c +++ b/service/notification/src/consumer/NSConsumerCommunication.c @@ -250,6 +250,23 @@ NSMessage * NSGetMessage(OCClientResponse * clientResponse) OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_DATETIME, &retMsg->dateTime); OCRepPayloadGetPropInt(payload, NS_ATTRIBUTE_TTL, (int64_t *)&retMsg->ttl); + char * icon = NULL; + OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_ICON_IMAGE, &icon); + + if (icon) + { + NSMediaContents * contents = (NSMediaContents *)OICMalloc(sizeof(NSMediaContents)); + if (contents) + { + contents->iconImage = icon; + retMsg->mediaContents = contents; + } + else + { + NSOICFree(icon); + } + } + 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); -- 2.7.4