From 83cce9ed0ab42d4c4968e00ad7ad9b795620725e Mon Sep 17 00:00:00 2001 From: "ch79.cho" Date: Thu, 7 Jul 2016 18:37:46 +0900 Subject: [PATCH] Publish resource to cloud The changes are about cloud notification service on provider side. The provider service publishes its resource through cloud interface. An application is required to call NSEnableRemoteSerivce(..) API to publish it after login process. Change-Id: I271c81858f2d1e63bc49ef0fa0012dde48a9c11a Signed-off-by: ch79.cho Reviewed-on: https://gerrit.iotivity.org/gerrit/9213 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi Tested-by: Uze Choi --- .../examples/linux/notificationprovider.c | 73 ++++- service/notification/include/NSProviderInterface.h | 14 + service/notification/src/common/NSCloudConnector.c | 296 +++++++++++++++++++++ service/notification/src/common/NSCloudConnector.h | 59 ++++ service/notification/src/common/NSConstants.h | 1 + .../src/provider/NSProviderDiscovery.c | 4 + .../src/provider/NSProviderInterface.c | 36 +++ .../notification/src/provider/NSProviderListener.c | 28 +- .../notification/src/provider/NSProviderListener.h | 1 + .../notification/src/provider/NSProviderResource.c | 31 +++ .../notification/src/provider/NSProviderResource.h | 2 + .../notification/src/provider/NSProviderSystem.c | 7 +- 12 files changed, 538 insertions(+), 14 deletions(-) create mode 100644 service/notification/src/common/NSCloudConnector.c create mode 100644 service/notification/src/common/NSCloudConnector.h diff --git a/service/notification/examples/linux/notificationprovider.c b/service/notification/examples/linux/notificationprovider.c index baa9ada..f4313e1 100644 --- a/service/notification/examples/linux/notificationprovider.c +++ b/service/notification/examples/linux/notificationprovider.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "NSCommon.h" #include "NSProviderInterface.h" #include "logger.h" @@ -29,7 +30,7 @@ #include "oic_string.h" #include "oic_malloc.h" -#define TAG "notiProviderExample" +#define TAG "NSProviderExample" extern char *strdup(const char *s); @@ -68,20 +69,68 @@ void syncCallback(NSSyncInfo *sync) printf("NS_APP Sync State: %d\n", sync->state); } +OCStackApplicationResult CloudLoginoutCallback(void *ctx, + OCDoHandle handle, OCClientResponse *clientResponse) +{ + int CtxValue = 0x99; + if (ctx != (void *)CtxValue) + { + OIC_LOG(INFO, TAG, "Invalid Cloud Login/out callback received"); + } + + OIC_LOG(INFO, TAG, "Login/out response received"); + + if (clientResponse->payload != NULL && + clientResponse->payload->type == PAYLOAD_TYPE_REPRESENTATION) + { + OIC_LOG(INFO, TAG, "PAYLOAD_TYPE_REPRESENTATION received"); + + OCRepPayloadValue *val = ((OCRepPayload *)clientResponse->payload)->values; + + OIC_LOG(INFO, TAG, "Get payload values"); + while (val) + { + OIC_LOG_V(INFO, TAG, "key: %s / Value: %s", val->name, val->str); + val = val->next; + } + + char *serverAddress = "coap+tcp://52.69.149.85:5683"; + NSProviderEnableRemoteService(serverAddress); + } + + return OC_STACK_KEEP_TRANSACTION; +} + +FILE* server_fopen(const char *path, const char *mode) +{ + (void)path; + return fopen("oic_ns_provider_db.dat", mode); +} + int main() { int num; pthread_t processThread; + // cloud host address + const char *host = "coap+tcp://52.69.149.85:5683"; + // cloud auth session + const char *auth_session = "gZDRuDyYapZXIcrs"; + + OIC_LOG(INFO, TAG, "NSStartProvider()"); + // open oic_db + static OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink}; + OCRegisterPersistentStorageHandler(&ps); + if (OCInit(NULL, 0, OC_CLIENT_SERVER) != OC_STACK_OK) { OIC_LOG(INFO, TAG, "OCStack init error"); return 0; } - pthread_create(&processThread, NULL, OCProcessThread, NULL); + pthread_create(&processThread, NULL, OCProcessThread, unlink); while (!isExit) { @@ -93,8 +142,8 @@ int main() printf("4. NSRead \n"); printf("5. NSStopProvider() \n"); printf("6. NSGetConsumerList \n"); - //printf("7. startPresence \n"); - //printf("8. stopPresence \n"); + printf("11. NSCloudLogin \n"); + printf("12. NSCloudLogout \n"); printf("0. Exit() \n"); printf("input : "); @@ -156,13 +205,17 @@ int main() case 6: OIC_LOG(INFO, TAG, "NSGetConsumerList"); break; - case 7: - OIC_LOG(INFO, TAG, "NSStartPresence - not working"); - //NSTestStartPresence(); + case 11: + OIC_LOG(INFO, TAG, "NSCloudLogin"); + + NSCloudLogin(host, auth_session, CloudLoginoutCallback); + OIC_LOG(INFO, TAG, "OCCloudLogin requested"); break; - case 8: - OIC_LOG(INFO, TAG, "NSStopPresence- not working"); - //NSTestStopPresence(); + case 12: + OIC_LOG(INFO, TAG, "NSCloudLogout"); + + NSCloudLogout(host, auth_session, CloudLoginoutCallback); + OIC_LOG(INFO, TAG, "OCCloudLogout requested"); break; case 0: NSStopProvider(); diff --git a/service/notification/include/NSProviderInterface.h b/service/notification/include/NSProviderInterface.h index 33c0aff..ebe6091 100644 --- a/service/notification/include/NSProviderInterface.h +++ b/service/notification/include/NSProviderInterface.h @@ -67,6 +67,20 @@ NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subsc NSResult NSStopProvider(); /** + * Request to publish resource to cloud server + * @param[in] server address combined with IP address and port number using delimiter : + * @return ::NS_OK or result code of NSResult + */ +NSResult NSProviderEnableRemoteService(char *serverAddress); + +/** + * Request to cancel remote service using cloud server + * @param[in] server address combined with IP address and port number using delimiter : + * @return ::NS_OK or result code of NSResult + */ +NSResult NSProviderDisableRemoteService(char *serverAddress); + +/** * Send notification message to all subscribers * @param[in] message Notification message including id, title, contentText * @return ::NS_OK or result code of NSResult diff --git a/service/notification/src/common/NSCloudConnector.c b/service/notification/src/common/NSCloudConnector.c new file mode 100644 index 0000000..34c122c --- /dev/null +++ b/service/notification/src/common/NSCloudConnector.c @@ -0,0 +1,296 @@ +//****************************************************************** +// +// Copyright 2016 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +#include "NSCloudConnector.h" +#include "NSUtil.h" + +#include +#include + +#include "oic_string.h" +#include "oic_malloc.h" + +#include "ocpayload.h" + +#include "rdpayload.h" +/* +#define OC_RD_PUBLISH_TTL 86400 +#define DEFAULT_CONTEXT_VALUE 0x99 + +#define DEFAULT_COAP_TCP_HOST "coap+tcp://" +#define DEFAULT_COAP_TCP_PORT 5683 + +#define DEFAULT_COAP_TCP_SECURE_HOST "coaps+tcp://" +#define DEFAULT_COAP_TCP_SECURE_PORT 5864 + +#define DEFAULT_AUTH_REGISTER_LOGIN "/oic/auth/?reqtype=register" +#define DEFAULT_AUTH_LOGIN "/oic/auth/?reqtype=login" +#define DEFAULT_AUTH_LOGOUT "/oic/auth/?reqtype=logout" +*/ +static OCStackResult createStringLL(uint8_t numElements, OCResourceHandle handle, + const char *(*getValue)(OCResourceHandle handle, uint8_t i), OCStringLL **stringLL) +{ + for (uint8_t i = 0; i < numElements; ++i) + { + const char *value = getValue(handle, i); + if (!*stringLL) + { + *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL)); + if (!*stringLL) + { + return OC_STACK_NO_MEMORY; + } + (*stringLL)->value = OICStrdup(value); + if (!(*stringLL)->value) + { + return OC_STACK_NO_MEMORY; + } + } + else + { + OCStringLL *cur = *stringLL; + while (cur->next) + { + cur = cur->next; + } + cur->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL)); + if (!cur->next) + { + return OC_STACK_NO_MEMORY; + } + cur->next->value = OICStrdup(value); + if (!cur->next->value) + { + return OC_STACK_NO_MEMORY; + } + } + } + return OC_STACK_OK; +} + +OCStackResult NSCloudRegisterLogin(const char *host, const char *auth_provider, + const char *auth_code, OCClientResponseHandler response) +{ + char targetUri[MAX_URI_LENGTH * 2] = { 0, }; + snprintf(targetUri, MAX_URI_LENGTH * 2, "%s%s", host, DEFAULT_AUTH_REGISTER_LOGIN); + + OCCallbackData cbData; + memset(&cbData, 0, sizeof(OCCallbackData)); + cbData.cb = response; + cbData.cd = NULL; + cbData.context = (void *)DEFAULT_CONTEXT_VALUE; + + OCRepPayload *registerPayload = OCRepPayloadCreate(); + if (!registerPayload) + { + goto no_memory; + } + + OCRepPayloadSetPropString(registerPayload, "authprovider", auth_provider); + OCRepPayloadSetPropString(registerPayload, "authcode", auth_code); + + return OCDoResource(NULL, OC_REST_POST, targetUri, NULL, (OCPayload *)registerPayload, + CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0); + +no_memory: + OCRepPayloadDestroy(registerPayload); + return OC_STACK_NO_MEMORY; +} + +OCStackResult NSCloudLoginout(const char *host, const char *query, const char *auth_session, + OCClientResponseHandler response) +{ + char targetUri[MAX_URI_LENGTH * 2] = { 0, }; + snprintf(targetUri, MAX_URI_LENGTH * 2, "%s%s", host, query); + + OCCallbackData cbData; + memset(&cbData, 0, sizeof(OCCallbackData)); + cbData.cb = response; + cbData.cd = NULL; + cbData.context = (void *)DEFAULT_CONTEXT_VALUE; + + OCRepPayload *loginoutPayload = OCRepPayloadCreate(); + if (!loginoutPayload) + { + goto no_memory; + } + + OCRepPayloadSetPropString(loginoutPayload, "session", auth_session); + + return OCDoResource(NULL, OC_REST_POST, targetUri, NULL, (OCPayload *)loginoutPayload, + CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0); + +no_memory: + OCRepPayloadDestroy(loginoutPayload); + return OC_STACK_NO_MEMORY; +} + + +OCStackResult NSCloudLogin(const char *host, const char *auth_session, + OCClientResponseHandler response) +{ + return NSCloudLoginout(host, DEFAULT_AUTH_LOGIN, auth_session, response); +} + +OCStackResult NSCloudLogout(const char *host, const char *auth_session, + OCClientResponseHandler response) +{ + return NSCloudLoginout(host, DEFAULT_AUTH_LOGOUT, auth_session, response); +} + + +static unsigned char gInstanceId[37] = {0, }; +OCStackResult NSCloudPublish(const char *host, const char *query, + OCClientResponseHandler response, int numArg, ...) +{ + char targetUri[MAX_URI_LENGTH * 2] = { 0, }; + snprintf(targetUri, MAX_URI_LENGTH * 2, "%s%s", host, query); + + // Gather all resources locally and do publish + OCCallbackData cbData; + memset(&cbData, 0, sizeof(OCCallbackData)); + cbData.cb = response; + cbData.cd = NULL; + cbData.context = (void *)DEFAULT_CONTEXT_VALUE; + + OCTagsPayload *tagsPayload = NULL; + OCLinksPayload *linksPayload = NULL; + OCStringLL *rt = NULL; + OCStringLL *itf = NULL; + OCStringLL *mt = NULL; + + OCRDPayload *rdPayload = OCRDPayloadCreate(); + if (!rdPayload) + { + goto no_memory; + } + + const unsigned char *id = (unsigned char *)OCGetServerInstanceIDString(); + NS_LOG_V(DEBUG, "DeviceID: %s", id); + tagsPayload = OCCopyTagsResources(NULL, id, + NULL, OC_DISCOVERABLE, 0, 0, NULL, NULL, OC_RD_PUBLISH_TTL); + if (!tagsPayload) + { + goto no_memory; + } + + va_list arguments; + va_start(arguments, numArg); + + for (int j = 0; j < numArg; j++) + { + OCResourceHandle handle = va_arg(arguments, OCResourceHandle); + if (handle) + { + rt = itf = mt = NULL; + const char *uri = OCGetResourceUri(handle); + uint8_t numElement; + if (OC_STACK_OK == OCGetNumberOfResourceTypes(handle, &numElement)) + { + OCStackResult res = createStringLL(numElement, handle, OCGetResourceTypeName, &rt); + if (res != OC_STACK_OK || !rt) + { + goto no_memory; + } + } + + if (OC_STACK_OK == OCGetNumberOfResourceInterfaces(handle, &numElement)) + { + OCStackResult res = createStringLL(numElement, handle, OCGetResourceInterfaceName, &itf); + if (res != OC_STACK_OK || !itf) + { + goto no_memory; + } + } + + mt = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL)); + if (!mt) + { + goto no_memory; + } + mt->value = OICStrdup("application/cbor"); + if (!mt->value) + { + goto no_memory; + } + + if (!linksPayload) + { + linksPayload = OCCopyLinksResources(uri, rt, itf, NULL, 0, NULL, + NULL, j, mt);; + if (!linksPayload) + { + goto no_memory; + } + } + else + { + OCLinksPayload *temp = linksPayload; + while (temp->next) + { + temp = temp->next; + } + temp->next = OCCopyLinksResources(uri, rt, itf, NULL, 0, NULL, + NULL, j, mt); + if (!temp->next) + { + goto no_memory; + } + } + OCFreeOCStringLL(rt); + OCFreeOCStringLL(itf); + OCFreeOCStringLL(mt); + } + } + va_end(arguments); + + rdPayload->rdPublish = OCCopyCollectionResource(tagsPayload, linksPayload); + if (!rdPayload->rdPublish) + { + goto no_memory; + } + + return OCDoResource(NULL, OC_REST_POST, targetUri, NULL, (OCPayload *)rdPayload, + CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0); + +no_memory: + va_end(arguments); + if (rt) + { + OCFreeOCStringLL(rt); + } + if (itf) + { + OCFreeOCStringLL(itf); + } + if (mt) + { + OCFreeOCStringLL(mt); + } + if (tagsPayload) + { + OCFreeTagsResource(tagsPayload); + } + if (linksPayload) + { + OCFreeLinksResource(linksPayload); + } + OCRDPayloadDestroy(rdPayload); + return OC_STACK_NO_MEMORY; +} diff --git a/service/notification/src/common/NSCloudConnector.h b/service/notification/src/common/NSCloudConnector.h new file mode 100644 index 0000000..8988f76 --- /dev/null +++ b/service/notification/src/common/NSCloudConnector.h @@ -0,0 +1,59 @@ +//****************************************************************** +// +// Copyright 2016 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +#ifndef _CLOUD_CONNECTOR_H_ +#define _CLOUD_CONNECTOR_H_ + +#include "ocstack.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +#define CLOUD_IP "52.69.149.85" +#define CLOUD_PORT "5683" + +#define OC_RD_PUBLISH_TTL 86400 +#define DEFAULT_CONTEXT_VALUE 0x99 + +#define DEFAULT_COAP_TCP_HOST "coap+tcp://" +#define DEFAULT_COAP_TCP_PORT 5683 + +#define DEFAULT_COAP_TCP_SECURE_HOST "coaps+tcp://" +#define DEFAULT_COAP_TCP_SECURE_PORT 5864 + +#define DEFAULT_AUTH_REGISTER_LOGIN "/oic/auth/?reqtype=register" +#define DEFAULT_AUTH_LOGIN "/oic/auth/?reqtype=login" +#define DEFAULT_AUTH_LOGOUT "/oic/auth/?reqtype=logout" + +OCStackResult NSCloudRegisterLogin(const char *host, const char *auth_provider, + const char *auth_code, OCClientResponseHandler response); +OCStackResult NSCloudLogin(const char *host, const char *auth_session, + OCClientResponseHandler response); +OCStackResult NSCloudLogout(const char *host, const char *auth_session, + OCClientResponseHandler response); +OCStackResult NSCloudPublish(const char *host, const char *query, + OCClientResponseHandler response, int numArg, ...); + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif diff --git a/service/notification/src/common/NSConstants.h b/service/notification/src/common/NSConstants.h index 551d792..fc1f04a 100644 --- a/service/notification/src/common/NSConstants.h +++ b/service/notification/src/common/NSConstants.h @@ -102,6 +102,7 @@ typedef enum eSchedulerType typedef enum eTaskType { TASK_REGISTER_RESOURCE = 1000, + TASK_PUBLISH_RESOURCE = 1001, TASK_START_PRESENCE = 2000, TASK_STOP_PRESENCE = 2001, diff --git a/service/notification/src/provider/NSProviderDiscovery.c b/service/notification/src/provider/NSProviderDiscovery.c index ce10822..37855be 100644 --- a/service/notification/src/provider/NSProviderDiscovery.c +++ b/service/notification/src/provider/NSProviderDiscovery.c @@ -79,6 +79,10 @@ void * NSDiscoverySchedule(void * ptr) NS_LOG(DEBUG, "CASE TASK_REGISTER_RESOURCE : "); NSRegisterResource(); break; + case TASK_PUBLISH_RESOURCE: + NS_LOG(DEBUG, "CASE TASK_PUBLISH_PESOURCE : "); + NSPublishResourceToCloud((char*)node->taskData); + break; default: break; } diff --git a/service/notification/src/provider/NSProviderInterface.c b/service/notification/src/provider/NSProviderInterface.c index 53fc193..6fa5967 100644 --- a/service/notification/src/provider/NSProviderInterface.c +++ b/service/notification/src/provider/NSProviderInterface.c @@ -140,6 +140,42 @@ NSResult NSStopProvider() return NS_OK; } +NSResult NSProviderEnableRemoteService(char *serverAddress) +{ + NS_LOG(DEBUG, "NSProviderEnableRemoteService - IN"); + pthread_mutex_lock(&nsInitMutex); + + if(!initProvider) + { + NS_LOG(DEBUG, "Provider service has not been started yet"); + return NS_FAIL; + } + + NS_LOG_V(DEBUG, "Remote server address: %s", serverAddress); + NSPushQueue(DISCOVERY_SCHEDULER, TASK_PUBLISH_RESOURCE, serverAddress); + + pthread_mutex_unlock(&nsInitMutex); + NS_LOG(DEBUG, "NSProviderEnableRemoteService - OUT"); + return NS_OK; +} + +NSResult NSProviderDisableRemoteService(char *serverAddress) +{ + NS_LOG(DEBUG, "NSProviderDisableRemoteService - IN"); + pthread_mutex_lock(&nsInitMutex); + + if(!initProvider) + { + NS_LOG(DEBUG, "Provider service has not been started yet"); + return NS_FAIL; + } + NS_LOG_V(DEBUG, "Remote server address: %s", serverAddress); + + pthread_mutex_unlock(&nsInitMutex); + NS_LOG(DEBUG, "NSProviderDisableRemoteService - OUT"); + return NS_OK; +} + NSResult NSSendMessage(NSMessage *msg) { NS_LOG(DEBUG, "NSSendNotification - IN"); diff --git a/service/notification/src/provider/NSProviderListener.c b/service/notification/src/provider/NSProviderListener.c index cb76c94..28bec3d 100644 --- a/service/notification/src/provider/NSProviderListener.c +++ b/service/notification/src/provider/NSProviderListener.c @@ -398,7 +398,6 @@ void NSProviderConnectionStateListener(CATransportAdapter_t adapter, const char bool connected) { - // should be implementation (void)adapter; (void)remote_address; @@ -413,6 +412,24 @@ void NSProviderConnectionStateListener(CATransportAdapter_t adapter, const char // Start Presence NSPushQueue(DISCOVERY_SCHEDULER, TASK_START_PRESENCE, NULL); + + if(adapter == CA_ADAPTER_TCP) + { + NS_LOG_V(DEBUG, "TCP Connected remote address: %s", remote_address); + } + } + else + { + + NS_LOG(DEBUG, "DISCONNECTED"); + + // Set Connection State + NSSetProviderConnectionState(DISCONNECTED); + + if(adapter == CA_ADAPTER_TCP) + { + NS_LOG_V(DEBUG, "TCP Disconnected remote address: %s", remote_address); + } } NS_LOG(DEBUG, "NSProviderConnectionStateListener - OUT"); @@ -420,7 +437,6 @@ void NSProviderConnectionStateListener(CATransportAdapter_t adapter, const char void NSProviderAdapterStateListener(CATransportAdapter_t adapter, bool enabled) { - // should be implementation (void)adapter; NS_LOG(DEBUG, "NSProviderAdapterStateListener - IN"); @@ -435,6 +451,14 @@ void NSProviderAdapterStateListener(CATransportAdapter_t adapter, bool enabled) // Start Presence NSPushQueue(DISCOVERY_SCHEDULER, TASK_START_PRESENCE, NULL); } + else + { + + NS_LOG(DEBUG, "DISCONNECTED"); + + // Set Connection State + NSSetProviderConnectionState(DISCONNECTED); + } NS_LOG(DEBUG, "NSProviderAdapterStateListener - OUT"); } diff --git a/service/notification/src/provider/NSProviderListener.h b/service/notification/src/provider/NSProviderListener.h index a4a0c45..75c9d92 100644 --- a/service/notification/src/provider/NSProviderListener.h +++ b/service/notification/src/provider/NSProviderListener.h @@ -34,6 +34,7 @@ #include "oic_malloc.h" #include "NSUtil.h" #include "NSStorageAdapter.h" +#include "NSCloudConnector.h" OCEntityHandlerResult NSEntityHandlerNotificationCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest *entityHandlerRequest, void* callback); diff --git a/service/notification/src/provider/NSProviderResource.c b/service/notification/src/provider/NSProviderResource.c index 01ef948..8da8796 100644 --- a/service/notification/src/provider/NSProviderResource.c +++ b/service/notification/src/provider/NSProviderResource.c @@ -24,6 +24,37 @@ NSNotificationResource NotificationResource; NSMessageResource NotificationMessageResource; NSSyncResource NotificationSyncResource; +OCStackApplicationResult NSHandlePublishCb(void *ctx, OCDoHandle handle, + OCClientResponse *clientResponse) +{ + if (ctx != (void *)DEFAULT_CONTEXT_VALUE) + { + NS_LOG(DEBUG, "Invalid publish callback received"); + } + + NS_LOG_V(DEBUG, "Publish resource response received code: %d", clientResponse->result); + + return OC_STACK_KEEP_TRANSACTION; +} + +NSResult NSPublishResourceToCloud(char *serverAddress) +{ + + NS_LOG(DEBUG, "NSPublishResourceToCloud - IN"); + NS_LOG_V(DEBUG, "Cloud address: %s", serverAddress); + + const char * publishQuery = "/oic/rd?rt=oic.wk.rdpub"; + + if (NSCloudPublish(serverAddress, publishQuery, &NSHandlePublishCb, 1, + NotificationResource.handle) != OC_STACK_OK) + { + NS_LOG(DEBUG, "Unable to publish resources to cloud"); + } + + NS_LOG(DEBUG, "NSPublishResourceToCloud - OUT"); + return NS_OK; +} + NSResult NSCreateResource(char *uri) { NS_LOG(DEBUG, "NSCreateResource - IN"); diff --git a/service/notification/src/provider/NSProviderResource.h b/service/notification/src/provider/NSProviderResource.h index 1927652..4ee6621 100644 --- a/service/notification/src/provider/NSProviderResource.h +++ b/service/notification/src/provider/NSProviderResource.h @@ -30,6 +30,8 @@ NSResult NSCreateResource(char *uri); +NSResult NSPublishResourceToCloud(char *host); + NSResult NSRegisterResource(); NSResult NSUnRegisterResource(); diff --git a/service/notification/src/provider/NSProviderSystem.c b/service/notification/src/provider/NSProviderSystem.c index 2190978..a9a69aa 100644 --- a/service/notification/src/provider/NSProviderSystem.c +++ b/service/notification/src/provider/NSProviderSystem.c @@ -41,7 +41,10 @@ void NSInitProviderInfo() NS_LOG(DEBUG, "NSInitProviderInfo"); providerInfo = (NSProviderInfo *) OICMalloc(sizeof(NSProviderInfo)); - NSGenerateUUIDStr(providerInfo->providerId); + const char * generatedUuid = (char *)OCGetServerInstanceIDString(); + NS_LOG_V(DEBUG, "Generate Provider ID: %s", generatedUuid); + OICStrcpy(providerInfo->providerId, strlen(generatedUuid), generatedUuid); + providerInfo->providerName = NULL; } @@ -67,7 +70,7 @@ void NSDeinitProviderInfo() NSProviderInfo * NSGetProviderInfo() { - NS_LOG(DEBUG, "Change Connection State"); + NS_LOG_V(DEBUG, "ProviderInfo: %s", providerInfo->providerId); return providerInfo; } -- 2.7.4