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 NSNotificationResource NotificationResource;
24 NSMessageResource NotificationMessageResource;
25 NSSyncResource NotificationSyncResource;
27 NSResult NSCreateResource(char *uri)
29 NS_LOG(DEBUG, "NSCreateResource - IN");
32 NS_LOG(NS_ERROR, "Resource URI cannot be NULL");
36 if (strcmp(uri, NS_ROOT_URI) == 0)
38 NotificationResource.accepter = 0;
39 NotificationResource.message_uri = NS_COLLECTION_MESSAGE_URI;
40 NotificationResource.sync_uri = NS_COLLECTION_SYNC_URI;
41 NotificationResource.handle = NULL;
43 if (OCCreateResource(&NotificationResource.handle, NS_ROOT_TYPE, NS_DEFAULT_INTERFACE,
44 NS_ROOT_URI, NSEntityHandlerNotificationCb, NULL, OC_DISCOVERABLE) != OC_STACK_OK)
46 NS_LOG(NS_ERROR, "Fail to Create Notification Resource");
50 else if (strcmp(uri, NS_COLLECTION_MESSAGE_URI) == 0)
53 NotificationMessageResource.id = NULL;
54 NotificationMessageResource.title = NULL;
55 NotificationMessageResource.body = NULL;
56 NotificationMessageResource.handle = NULL;
58 if (OCCreateResource(&NotificationMessageResource.handle, NS_COLLECTION_MESSAGE_TYPE,
59 NS_DEFAULT_INTERFACE, NS_COLLECTION_MESSAGE_URI, NSEntityHandlerMessageCb, NULL,
60 OC_OBSERVABLE) != OC_STACK_OK)
62 NS_LOG(NS_ERROR, "Fail to Create Notification Message Resource");
66 else if (strcmp(uri, NS_COLLECTION_SYNC_URI) == 0)
68 NotificationSyncResource.id = NULL;
69 NotificationSyncResource.state = NULL;
70 NotificationSyncResource.handle = NULL;
72 if (OCCreateResource(&(NotificationSyncResource.handle), NS_COLLECTION_SYNC_TYPE,
73 NS_DEFAULT_INTERFACE, NS_COLLECTION_SYNC_URI, NSEntityHandlerSyncCb, NULL,
74 OC_OBSERVABLE) != OC_STACK_OK)
76 NS_LOG(NS_ERROR, "Fail to Create Notification Sync Resource");
82 NS_LOG(ERROR, "Fail to create resource with invalid URI");
86 NS_LOG(DEBUG, "NSCreateResource - OUT");
90 NSResult NSRegisterResource()
92 NS_LOG(DEBUG, "NSRegisterResource - IN");
94 if (NSCreateResource(NS_COLLECTION_SYNC_URI) != NS_OK)
96 NS_LOG(ERROR, "Fail to register Sync Resource");
100 if (NSCreateResource(NS_COLLECTION_MESSAGE_URI) != NS_OK)
102 NS_LOG(ERROR, "Fail to register Message Resource");
106 if (NSCreateResource(NS_ROOT_URI) != NS_OK)
108 NS_LOG(ERROR, "Fail to register Notification Resource");
112 NS_LOG(DEBUG, "NSRegisterResource - OUT");
116 NSResult NSUnRegisterResource()
118 NS_LOG(DEBUG, "NSUnRegisterResource - IN");
120 if (OCDeleteResource(NotificationResource.handle) != OC_STACK_OK)
122 NS_LOG(ERROR, "Fail to Delete Notification Resource");
126 if (OCDeleteResource(NotificationMessageResource.handle) != OC_STACK_OK)
128 NS_LOG(ERROR, "Fail to Delete Notification Message Resource");
132 if (OCDeleteResource(NotificationSyncResource.handle) != OC_STACK_OK)
134 NS_LOG(ERROR, "Fail to Delete Notification Sync Resource");
138 NS_LOG(DEBUG, "NSUnRegisterResource - OUT");
142 NSResult NSPutNotificationResource(int accepter, OCResourceHandle * handle)
144 NS_LOG(DEBUG, "NSPutNotificationResource - IN");
146 NotificationResource.accepter = accepter;
147 NotificationResource.message_uri = NS_COLLECTION_MESSAGE_URI;
148 NotificationResource.sync_uri = NS_COLLECTION_SYNC_URI;
150 *handle = NotificationResource.handle;
152 NS_LOG(DEBUG, "NSPutNotificationResource - OUT");
156 NSResult NSPutMessageResource(NSMessage *msg, OCResourceHandle * handle)
158 NS_LOG(DEBUG, "NSPutMessageResource - IN");
162 NS_LOG(DEBUG, "NSMessage is valid");
164 NotificationMessageResource.id = OICStrdup(msg->mId);
165 NotificationMessageResource.title = OICStrdup(msg->mTitle);
166 NotificationMessageResource.body = OICStrdup(msg->mContentText);
170 NS_LOG(ERROR, "NSMessage is NULL");
173 *handle = NotificationMessageResource.handle;
174 NS_LOG(DEBUG, "NSPutMessageResource - OUT");
179 NSResult NSPutSyncResource(NSSync *sync, OCResourceHandle * handle)
181 NS_LOG(DEBUG, "NSPutSyncResource - IN");
185 *handle = NotificationSyncResource.handle;
187 NS_LOG(DEBUG, "NSPutSyncResource - OUT");