1 //******************************************************************
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "NSProviderResource.h"
23 char* NSType = "oic.r.notification";
24 char* NSMessageType = "oic.r.notification.message";
25 char* NSSyncType = "oic.r.notification.sync";
27 char* NSInterface = "oic.if.baseline";
28 char* NSMessgeInterface = "oic.if.baseline.message";
29 char* NSSyncInterface = "oic.if.baseline.sync";
31 char* NSUri = "/notification";
32 char* NSMessageUri = "/notification/message";
33 char* NSSyncUri = "/notification/sync";
35 /* Structure to represent notification resources */
38 OCResourceHandle handle;
42 } NSNotificationResource;
46 OCResourceHandle handle;
54 OCResourceHandle handle;
60 NSNotificationResource NotificationResource;
61 NSMessageResource NotificationMessageResource;
62 NSSyncResource NotificationSyncResource;
64 NSResult NSCreateResource(char *uri)
68 OIC_LOG(ERROR, RESOURCE_TAG, "Resource URI cannot be NULL");
72 if (strcmp(uri, NSUri) == 0)
75 NotificationResource.accepter = 0;
76 NotificationResource.message_uri = NSMessageUri;
77 NotificationResource.sync_uri = NSSyncUri;
78 NotificationResource.handle = NULL;
80 if (OCCreateResource(&NotificationResource.handle, NSType, NSInterface, NSUri,
81 NSEntityHandlerNotificationCb, NULL, OC_DISCOVERABLE) != OC_STACK_OK)
83 OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to Create Notification Resource"));
87 else if (strcmp(uri, NSMessageUri) == 0)
90 NotificationMessageResource.id = NULL;
91 NotificationMessageResource.title = NULL;
92 NotificationMessageResource.body = NULL;
93 NotificationMessageResource.handle = NULL;
95 if (OCCreateResource(&NotificationMessageResource.handle, NSMessageType, NSInterface,
96 NSMessageUri, NSEntityHandlerMessageCb, NULL, OC_OBSERVABLE) != OC_STACK_OK)
98 OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to Create Notification Message Resource"));
102 else if (strcmp(uri, NSSyncUri) == 0)
104 NotificationSyncResource.id = NULL;
105 NotificationSyncResource.state = NULL;
106 memset(&NotificationSyncResource.device, 0, sizeof(NSDevice));
107 NotificationSyncResource.handle = NULL;
109 if (OCCreateResource(&(NotificationSyncResource.handle), NSSyncType, NSInterface, NSSyncUri,
110 NSEntityHandlerSyncCb, NULL, OC_OBSERVABLE) != OC_STACK_OK)
112 OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to Create Notification Sync Resource"));
118 OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to create resource with invalid URI"));
125 NSResult NSRegisterResource()
127 OIC_LOG(INFO, RESOURCE_TAG, "NSRegisterResource");
129 if (NSCreateResource(NSSyncUri) != NS_OK)
131 OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to register Sync Resource"));
135 if (NSCreateResource(NSMessageUri) != NS_OK)
137 OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to register Message Resource"));
141 if (NSCreateResource(NSUri) != NS_OK)
143 OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to register Notification Resource"));
150 NSResult NSPutNotificationResource(int accepter, OCResourceHandle * handle)
152 NotificationResource.accepter = accepter;
153 NotificationResource.message_uri = NSMessageUri;
154 NotificationResource.sync_uri = NSSyncUri;
156 *handle = NotificationResource.handle;
161 NSResult NSPutMessageResource(NSMessage *msg, OCResourceHandle * handle)
163 OIC_LOG(INFO, RESOURCE_TAG, "Put notification message to Resource");
167 printf("msg is not null\n");
168 NotificationMessageResource.id = strdup(msg->mId);
169 NotificationMessageResource.title = strdup(msg->mTitle);
170 NotificationMessageResource.body = strdup(msg->mContentText);
174 printf("msg is null\n");
177 *handle = NotificationMessageResource.handle;
182 NSResult NSPutSyncResource(NSSync *sync, OCResourceHandle * handle)
184 OIC_LOG(INFO, RESOURCE_TAG, "Put notification sync to Resource");
186 //should be implementation
189 *handle = NotificationSyncResource.handle;
194 const char* NSGetNotificationUri()
199 const char* NSGetNotificationMessageUri()
204 const char* NSGetNotificationSyncUri()
209 NSResult NSCopyString(char** targetString, const char* sourceString)
213 *targetString = (char *) malloc(strlen(sourceString) + 1);
217 strncpy(*targetString, sourceString, (strlen(sourceString) + 1));