This patch is clean the warning code in provider side.
Change-Id: Id9610ebaad4e374818a35eb4982cb40b5dcd9b68
Signed-off-by: jaesick.shin <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8213
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
#include "logger.h"\r
#include "octypes.h"\r
#include "pthread.h"\r
-\r
+#include "oic_string.h"\r
+#include "oic_malloc.h"\r
\r
#define TAG "notiProviderExample"\r
\r
\r
bool isExit = false;\r
\r
-pthread_t processThread;\r
-\r
int id;\r
\r
void OCProcessThread(void * ptr)\r
int main()\r
{\r
int num;\r
+ pthread_t processThread;\r
\r
OIC_LOG(INFO, TAG, "NSStartProvider()");\r
\r
\r
pthread_create(&processThread, NULL, OCProcessThread, NULL);\r
\r
- NSMessage * message = (NSMessage*) OICMalloc(sizeof(NSMessage));\r
- if (!message)\r
- {\r
- OIC_LOG(ERROR, TAG, PCF("Fail to allocate memory"));\r
- return NS_ERROR;\r
- }\r
-\r
while (true)\r
{\r
char dummy;\r
printf("app - mContentText : %s \n", body);\r
\r
\r
- NSMessage * msg = (NSMessage *)malloc(sizeof(NSMessage));\r
+ NSMessage * msg = (NSMessage *)OICMalloc(sizeof(NSMessage));\r
\r
sprintf(charID, "%d", id);\r
\r
msg->mId = strdup(charID);\r
msg->mTitle = strdup(title);\r
- msg->mContentText = strdup(body);\r
+ msg->mContentText = OICStrdup(body);\r
\r
NSSendNotification(msg);\r
\r
\r
case 4:\r
OIC_LOG(INFO, TAG, "NSRead");\r
- NSSync * sync = (NSSync*) malloc(sizeof(NSSync));\r
+ NSSync * sync = (NSSync*) OICMalloc(sizeof(NSSync));\r
\r
- sync->mMessageId = strdup("dev_001");\r
+ sync->mMessageId = OICStrdup("dev_001");\r
sync->mState = 1;\r
\r
- NSSendSync(sync);\r
-\r
break;\r
/*\r
case 5:\r
#include "NSConstants.h"\r
\r
NSCacheList * NSCacheCreate();\r
-NSCacheElement * NSCacheRead(NSCacheList * list, char * findId);\r
+NSCacheElement * NSCacheRead(NSCacheList * list, const char * findId);\r
NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj);\r
-NSResult NSCacheDelete(NSCacheList * list, char * delId);\r
+NSResult NSCacheDelete(NSCacheList * list, const char * delId);\r
NSResult NSCacheDestroy(NSCacheList * list);\r
\r
#endif /* _NS_CACHEADAPTER__H_ */\r
NSTask *node = NSHeadMsg[DISCOVERY_SCHEDULER];\r
NSHeadMsg[DISCOVERY_SCHEDULER] = node->nextTask;\r
\r
- switch ((int)node->taskType)\r
+ switch (node->taskType)\r
{\r
case TASK_START_PRESENCE:\r
NSStartPresence();\r
case TASK_REGISTER_RESOURCE:\r
NSRegisterResource();\r
break;\r
+ default:\r
+ break;\r
}\r
\r
OICFree(node);\r
NSResult NSSendNotification(NSMessage *msg)\r
{\r
OIC_LOG(INFO, INTERFACE_TAG, "Send Notification");\r
-\r
NSPushQueue(NOTIFICATION_SCHEDULER, TASK_SEND_NOTIFICATION, msg);\r
-\r
return NS_OK;\r
}\r
\r
NSResult NSProviderReadCheck(NSMessage *msg)\r
{\r
OIC_LOG(INFO, INTERFACE_TAG, "Read Sync");\r
-\r
NSPushQueue(NOTIFICATION_SCHEDULER, TASK_SEND_READ, msg);\r
-\r
return NS_OK;\r
}\r
\r
return NS_OK;\r
}\r
\r
-/*\r
-NSResult NSGetConsumerList(uint8_t *list, uint32_t size)\r
-{\r
- OIC_LOG(INFO, INTERFACE_TAG, "Get consumer list");\r
-\r
- NSGetObsIdList(list);\r
- size = NSGetNumberOfObsList();\r
-\r
- return NS_OK;\r
-}*/\r
-\r
void * NSResponseSchedule(void * ptr)\r
{\r
if (ptr == NULL)\r
sendOptions[1].optionLength = 10;\r
response.numSendVendorSpecificHeaderOptions = 2;\r
}\r
-\r
-\r
- // Send the response\r
- /*if (OCDoResponse(&response) != OC_STACK_OK)\r
- {\r
- OIC_LOG(ERROR, LISTENER_TAG, "Error sending response");\r
- ehResult = OC_EH_ERROR;\r
- }*/\r
}\r
}\r
\r
}\r
}\r
\r
-\r
OCPayloadDestroy(response.payload);\r
return ehResult;\r
}\r
void NSProviderConnectionStateListener(CATransportAdapter_t adapter, const char *remote_address,\r
bool connected)\r
{\r
+\r
+ // should be implementation\r
+ (void)adapter;\r
+ (void)remote_address;\r
+\r
OIC_LOG (INFO, LISTENER_TAG, "Connection State Changed");\r
\r
if (connected)\r
\r
void NSProviderAdapterStateListener(CATransportAdapter_t adapter, bool enabled)\r
{\r
+ // should be implementation\r
+ (void)adapter;\r
+\r
OIC_LOG (INFO, LISTENER_TAG, "Adapter State Changed");\r
\r
if (enabled)\r
#include "NSProviderSystem.h"\r
#include "NSProviderScheduler.h"\r
#include "cautilinterface.h"\r
+#include "oic_string.h"\r
+#include "oic_malloc.h"\r
\r
OCEntityHandlerResult NSEntityHandlerNotificationCb(OCEntityHandlerFlag flag,\r
OCEntityHandlerRequest *entityHandlerRequest, void* callback);\r
NSResult NSGetMessagePayload(NSMessage *msg, OCRepPayload** msgPayload)
{
-
*msgPayload = OCRepPayloadCreate();
if (!*msgPayload)
NSResult NSGetSyncPayload(NSSync *sync, OCRepPayload** syncPayload)
{
-
*syncPayload = OCRepPayloadCreate();
if (!*syncPayload)
return NS_ERROR;
}
- // Send Notification to subscribers
-
if (consumerSubList->head == NULL)
{
printf("printf - no observers (consumerSubList->head == NULL)\n");
printf("NS_ -------------------------------------------------------message\n");
}
printf("printf - no observers - 10\n");
- // Notify message to subscribers
OCStackResult ocstackResult = OCNotifyListOfObservers(rHandle, obArray, obCount, payload,
OC_LOW_QOS);
NSTask *node = NSHeadMsg[NOTIFICATION_SCHEDULER];
NSHeadMsg[NOTIFICATION_SCHEDULER] = node->nextTask;
- switch (node->taskType)
+ switch ((int)node->taskType)
{
case TASK_SEND_NOTIFICATION:
{
#define _NS_PROVIDER_NOTIFICATION_H_\r
\r
#include <ocstack.h>\r
-#include "../common/NSCacheAdapter.h"\r
+#include "NSCacheAdapter.h"\r
#include "logger.h"\r
#include "NSProviderScheduler.h"\r
#include "NSProviderListener.h"\r
#include "NSProviderResource.h"\r
#include "NSProviderSubscription.h"\r
+#include "oic_string.h"\r
+#include "oic_malloc.h"\r
\r
NSCacheList * messageList;\r
\r
#include "NSProviderResource.h"
-const char* NSType = "oic.r.notification";
-const char* NSMessageType = "oic.r.notification.message";
-const char* NSSyncType = "oic.r.notification.sync";
+char* NSType = "oic.r.notification";
+char* NSMessageType = "oic.r.notification.message";
+char* NSSyncType = "oic.r.notification.sync";
-const char* NSInterface = "oic.if.baseline";
-const char* NSMessgeInterface = "oic.if.baseline.message";
-const char* NSSyncInterface = "oic.if.baseline.sync";
+char* NSInterface = "oic.if.baseline";
+char* NSMessgeInterface = "oic.if.baseline.message";
+char* NSSyncInterface = "oic.if.baseline.sync";
-const char* NSUri = "/notification";
-const char* NSMessageUri = "/notification/message";
-const char* NSSyncUri = "/notification/sync";
+char* NSUri = "/notification";
+char* NSMessageUri = "/notification/message";
+char* NSSyncUri = "/notification/sync";
/* Structure to represent notification resources */
typedef struct
OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to Create Notification Resource"));
return NS_ERROR;
}
-
- printf("NotificationResource.handle = %u\n", NotificationResource.handle);
-
-
}
else if (strcmp(uri, NSMessageUri) == 0)
{
OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to Create Notification Message Resource"));
return NS_ERROR;
}
-
- printf("NotificationMessageResource.handle = %u\n", NotificationMessageResource.handle);
-
-
}
else if (strcmp(uri, NSSyncUri) == 0)
{
NotificationSyncResource.id = NULL;
NotificationSyncResource.state = NULL;
- NotificationSyncResource.device;
+ memset(&NotificationSyncResource.device, 0, sizeof(NSDevice));
NotificationSyncResource.handle = NULL;
if (OCCreateResource(&(NotificationSyncResource.handle), NSSyncType, NSInterface, NSSyncUri,
OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to Create Notification Sync Resource"));
return NS_ERROR;
}
-
- printf("NotificationSyncResource.handle = %u\n", NotificationSyncResource.handle);
-
}
else
{
{
OIC_LOG(INFO, RESOURCE_TAG, "Put notification sync to Resource");
+ //should be implementation
+ (void) sync;
+
*handle = NotificationSyncResource.handle;
return NS_OK;
\r
if (resourceType == NS_RESOURCE_MESSAGE)\r
{\r
- int obId = entityHandlerRequest->obsInfo.obsId;\r
-\r
- NSCacheElement * element = (NSCacheElement *) malloc(sizeof(NSCacheElement));\r
+ NSCacheElement * element = (NSCacheElement *) OICMalloc(sizeof(NSCacheElement));\r
+ NSCacheSubData * subData = (NSCacheSubData *) OICMalloc(sizeof(NSCacheSubData));\r
\r
- NSCacheSubData * subData = (NSCacheSubData *) malloc(sizeof(NSCacheSubData));\r
subData->id = OICStrdup(entityHandlerRequest->devAddr.addr);\r
subData->isWhite = false;\r
subData->messageObId = entityHandlerRequest->obsInfo.obsId;\r
element->data = (void*) subData;\r
element->next = NULL;\r
\r
+ printf("NS_ IP = %s in message ob\n", entityHandlerRequest->devAddr.addr);\r
+ printf("NS_ IP2 = %s in message ob\n", subData->id);\r
printf("NS_ message ob Id = %d\n", subData->messageObId);\r
\r
if (NSCacheWrite(consumerSubList, element) != NS_OK)\r
else if (NSGetSubscriptionAccepter() == NS_ACCEPTER_CONSUMER)\r
{\r
printf("state = 0 - 3\n");\r
- NSSendSubscriptionResponse(entityHandlerRequest, NS_ACCEPTER_CONSUMER, true);\r
+ NSSendSubscriptionResponse(entityHandlerRequest, true);\r
}\r
}\r
else if (resourceType == NS_RESOURCE_SYNC)\r
{\r
- int obId = entityHandlerRequest->obsInfo.obsId;\r
-\r
- NSCacheElement * element = (NSCacheElement *) malloc(sizeof(NSCacheElement));\r
+ NSCacheElement * element = (NSCacheElement *) OICMalloc(sizeof(NSCacheElement));\r
\r
- NSCacheSubData * subData = (NSCacheSubData *) malloc(sizeof(NSCacheSubData));\r
+ NSCacheSubData * subData = (NSCacheSubData *) OICMalloc(sizeof(NSCacheSubData));\r
printf("NS_ entityHandlerRequest->devAddr.addr = %s\n", entityHandlerRequest->devAddr.addr);\r
subData->id = OICStrdup(entityHandlerRequest->devAddr.addr);\r
subData->isWhite = false;\r
{\r
OIC_LOG(INFO, SUBSCRIPTION_TAG, "Start to unsubscription process");\r
\r
- // ProcessObserveUnregister (entityHandlerRequest);\r
-\r
- // write consumer info to cache\r
- int obId = entityHandlerRequest->obsInfo.obsId;\r
-\r
NSCacheElement * element = (NSCacheElement *) OICMalloc(sizeof(NSCacheElement));\r
NSCacheSubData * subData = (NSCacheSubData *) OICMalloc(sizeof(NSCacheSubData));\r
subData->id = OICStrdup(entityHandlerRequest->devAddr.addr);\r
OCRepPayloadSetPropBool(payload, NS_ATTRIBUTE_ACCPETANCE, accepted);\r
\r
NSCacheElement * element = NSCacheRead(consumerSubList, id);\r
- NSCacheSubData * subData = element->data;\r
\r
- if (OCNotifyListOfObservers(rHandle, &subData->messageObId, 1, payload, OC_HIGH_QOS)\r
+ if(element == NULL)\r
+ {\r
+ printf("NS_ NSSendResponse - element is NULL\n");\r
+ return NS_ERROR;\r
+ }\r
+ NSCacheSubData * subData = (NSCacheSubData*) element->data;\r
+\r
+ if (OCNotifyListOfObservers(rHandle, (OCObservationId*)&subData->messageObId, 1, payload, OC_HIGH_QOS)\r
!= OC_STACK_OK)\r
{\r
OIC_LOG(ERROR, SUBSCRIPTION_TAG, "fail to send Acceptance");\r
return NS_OK;\r
}\r
\r
-NSResult NSSendSubscriptionResponse(OCEntityHandlerRequest *entityHandlerRequest,\r
- NSAccessPolicy accepter, bool accepted)\r
+NSResult NSSendSubscriptionResponse(OCEntityHandlerRequest *entityHandlerRequest, bool accepted)\r
{\r
OIC_LOG(INFO, SUBSCRIPTION_TAG, "Send ACCEPT message to consumer");\r
\r
printf("accepted 1 \n");\r
if (accepted)\r
{\r
- int obId = entityHandlerRequest->obsInfo.obsId;\r
-\r
NSCacheElement * element = (NSCacheElement *) OICMalloc(sizeof(NSCacheElement));\r
\r
NSCacheSubData * subData = (NSCacheSubData *) OICMalloc(sizeof(NSCacheSubData));\r
}\r
}\r
\r
- NSSendResponse(&entityHandlerRequest->obsInfo.obsId, accepted);\r
+ NSSendResponse(entityHandlerRequest->devAddr.addr, accepted);\r
\r
return NS_OK;\r
\r
{\r
\r
case TASK_SEND_POLICY:\r
-\r
NSSendAccessPolicyResponse((OCEntityHandlerRequest*) node->taskData);\r
break;\r
\r
NSConsumer * consumer = (NSConsumer *) node->taskData;\r
int * pObId = (int *) consumer->mUserData;\r
\r
- NSCacheSubData * subData = (NSCacheMsgData *) OICMalloc(sizeof(NSCacheSubData));\r
+ NSCacheSubData * subData = (NSCacheSubData *) OICMalloc(sizeof(NSCacheSubData));\r
subData->id = OICStrdup(consumer->mId);\r
subData->isWhite = true;\r
subData->messageObId = 0;\r
NSConsumer * consumer = (NSConsumer *) node->taskData;\r
int * pObId = (int *) consumer->mUserData;\r
\r
- NSCacheSubData * subData = (NSCacheMsgData *) OICMalloc(sizeof(NSCacheSubData));\r
+ NSCacheSubData * subData = (NSCacheSubData *) OICMalloc(sizeof(NSCacheSubData));\r
subData->id = OICStrdup(consumer->mId);\r
subData->isWhite = false;\r
subData->messageObId = 0;\r
NSHandleSubscription((OCEntityHandlerRequest*) node->taskData,\r
NS_RESOURCE_SYNC);\r
break;\r
+ default:\r
+ break;\r
\r
}\r
OICFree(node);\r
#include "NSProviderScheduler.h"\r
#include "NSProviderResource.h"\r
#include "NSCacheAdapter.h"\r
+#include "NSProviderMemoryCache.h"\r
+#include "oic_string.h"\r
\r
NSAccessPolicy NSSubscriptionAccepter;\r
NSCacheList * consumerSubList;\r
void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResourceType resourceType);\r
void NSHandleUnsubscription(OCEntityHandlerRequest *entityHandlerRequest);\r
void NSAskAcceptanceToUser(OCEntityHandlerRequest *entityHandlerRequest);\r
-NSResult NSSendSubscriptionResponse(OCEntityHandlerRequest *entityHandlerRequest,\r
- NSAccessPolicy accepter, bool accepted);\r
+NSResult NSSendSubscriptionResponse(OCEntityHandlerRequest *entityHandlerRequest, bool accepted);\r
\r
#endif /* _NS_PROVIDER_SUBSCRIPTION_H_ */\r
\r
NSConnectionState NSGetProviderConnectionState()\r
{\r
+ OIC_LOG(INFO, SUBSCRIPTION_TAG, "Change Connection State");\r
+\r
return NSProviderConnectionState;\r
}\r
return newList;\r
}\r
\r
-NSCacheElement * NSCacheRead(NSCacheList * list, char * findId)\r
+NSCacheElement * NSCacheRead(NSCacheList * list, const char * findId)\r
{\r
pthread_mutex_lock(&NSCacheMutex);\r
NSCacheElement * iter = list->head;\r
next = iter->next;\r
\r
printf("NS_ findId2 = %s\n", findId);\r
- pthread_mutex_unlock(&NSCacheMutex);\r
\r
if (NSProviderCompareIdCacheData(type, iter->data, findId))\r
{\r
{\r
pthread_mutex_lock(&NSCacheMutex);\r
\r
- NSCacheType type = list->cacheType;\r
-\r
- printf("NS_ NSCacheWrite\n");\r
+ printf("NS_ NSCacheUpdateSubScriptionState\n");\r
\r
if (subData == NULL)\r
{\r
return NS_OK;\r
}\r
\r
-NSResult NSCacheDelete(NSCacheList * list, char * delId)\r
+NSResult NSCacheDelete(NSCacheList * list, const char * delId)\r
{\r
-\r
pthread_mutex_lock(&NSCacheMutex);\r
NSCacheElement * prev = list->head;\r
NSCacheElement * del = list->head;\r
return NS_OK;\r
}\r
\r
-bool NSProviderCompareIdCacheData(NSCacheType type, void * data, char * id)\r
+bool NSProviderCompareIdCacheData(NSCacheType type, void * data, const char * id)\r
{\r
if (data == NULL)\r
{\r
#include "NSStructs.h"\r
#include "NSConstants.h"\r
#include "NSCacheAdapter.h"\r
+#include "oic_malloc.h"\r
+#include "oic_string.h"\r
+#include "NSUtil.h"\r
\r
NSResult NSProviderDeleteCacheData(NSCacheType, void *);\r
\r
-bool NSProviderCompareIdCacheData(NSCacheType, void *, char *);\r
+bool NSProviderCompareIdCacheData(NSCacheType, void *, const char *);\r
\r
bool NSProviderIsFoundCacheData(NSCacheType, void *, void*);\r
\r