-/******************************************************************\r
- *\r
- * Copyright 2015 Samsung Electronics All Rights Reserved.\r
- *\r
- *\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- ******************************************************************/\r
+//******************************************************************\r
+//\r
+// Copyright 2016 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
\r
#include <stdio.h>\r
#include <stdbool.h>\r
#include <stdlib.h>\r
+#include <unistd.h>\r
+\r
+#include "NSProvider.h"\r
#include "NSCommon.h"\r
-#include "NSProviderInterface.h"\r
#include "logger.h"\r
#include "octypes.h"\r
#include "pthread.h"\r
#include "oic_string.h"\r
#include "oic_malloc.h"\r
\r
-#define TAG "notiProviderExample"\r
+#define TAG "NSProviderExample"\r
+\r
+// Input the following values to publish resource to cloud\r
+char REMOTE_SERVER_ADDRESS[50];\r
+char REMOTE_SERVER_SESSION[50];\r
\r
extern char *strdup(const char *s);\r
\r
{\r
if (OCProcess() != OC_STACK_OK)\r
{\r
- OIC_LOG(ERROR, TAG, "OCStack process error");\r
+ printf("OCStack process error");\r
return NULL;\r
}\r
}\r
\r
void subscribeRequestCallback(NSConsumer *consumer)\r
{\r
- OIC_LOG(INFO, TAG, "consumer requested to subscribe");\r
+ printf("consumer requested to subscribe");\r
\r
printf("NS_APP Consumer Device ID: %s\n", consumer->consumerId);\r
\r
\r
void syncCallback(NSSyncInfo *sync)\r
{\r
- OIC_LOG(INFO, TAG, "sync requested");\r
+ printf("sync requested");\r
\r
printf("NS_APP Sync State: %d\n", sync->state);\r
}\r
\r
+OCStackApplicationResult CloudLoginoutCallback(void *ctx,\r
+ OCDoHandle handle, OCClientResponse *clientResponse)\r
+{\r
+ int CtxValue = 0x99;\r
+ if (ctx != (void *)CtxValue)\r
+ {\r
+ printf("Invalid Cloud Login/out callback received");\r
+ }\r
+\r
+ printf("Login/out response received");\r
+\r
+ if (clientResponse->payload != NULL &&\r
+ clientResponse->payload->type == PAYLOAD_TYPE_REPRESENTATION)\r
+ {\r
+ printf("PAYLOAD_TYPE_REPRESENTATION received");\r
+\r
+ OCRepPayloadValue *val = ((OCRepPayload *)clientResponse->payload)->values;\r
+\r
+ printf("Get payload values");\r
+ while (val)\r
+ {\r
+ printf("key: %s / Value: %s", val->name, val->str);\r
+ val = val->next;\r
+ }\r
+\r
+ NSProviderEnableRemoteService(REMOTE_SERVER_ADDRESS);\r
+ }\r
+\r
+ return OC_STACK_KEEP_TRANSACTION;\r
+}\r
+\r
+FILE* server_fopen(const char *path, const char *mode)\r
+{\r
+ (void)path;\r
+ return fopen("oic_ns_provider_db.dat", mode);\r
+}\r
+\r
int main()\r
{\r
int num;\r
pthread_t processThread;\r
\r
- OIC_LOG(INFO, TAG, "NSStartProvider()");\r
+ printf("NSStartProvider()");\r
+\r
+ // open oic_db\r
+ static OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink};\r
+ OCRegisterPersistentStorageHandler(&ps);\r
\r
if (OCInit(NULL, 0, OC_CLIENT_SERVER) != OC_STACK_OK)\r
{\r
- OIC_LOG(INFO, TAG, "OCStack init error");\r
+ printf("OCStack init error");\r
return 0;\r
}\r
\r
- pthread_create(&processThread, NULL, OCProcessThread, NULL);\r
+ pthread_create(&processThread, NULL, OCProcessThread, unlink);\r
\r
while (!isExit)\r
{\r
printf("3. NSSendNotification() \n");\r
printf("4. NSRead \n");\r
printf("5. NSStopProvider() \n");\r
- printf("6. NSGetConsumerList \n");\r
- //printf("7. startPresence \n");\r
- //printf("8. stopPresence \n");\r
+\r
+ printf("11. NSCloudLogin \n");\r
+ printf("12. NSCloudLogout \n");\r
printf("0. Exit() \n");\r
\r
printf("input : ");\r
switch (num)\r
{\r
case 1:\r
- OIC_LOG(INFO, TAG, "NSStartProvider(Accepter: Provider)");\r
+ printf("NSStartProvider(Accepter: Provider)");\r
NSStartProvider(NS_ACCESS_ALLOW, subscribeRequestCallback, syncCallback);\r
break;\r
case 2:\r
- OIC_LOG(INFO, TAG, "NSStartProvider(Accepter: Consumer)");\r
+ printf("NSStartProvider(Accepter: Consumer)");\r
NSStartProvider(NS_ACCESS_DENY, subscribeRequestCallback, syncCallback);\r
break;\r
case 3:\r
- OIC_LOG(INFO, TAG, "NSSendNotification()");\r
+ printf("NSSendNotification()");\r
\r
char title[100];\r
char body[100];\r
break;\r
\r
case 4:\r
- OIC_LOG(INFO, TAG, "NSRead");\r
+ printf("NSRead");\r
NSSyncInfo * sync = (NSSyncInfo*) OICMalloc(sizeof(NSSyncInfo));\r
\r
sync->messageId = OICStrdup("dev_001");\r
case 5:\r
NSStopProvider();\r
break;\r
- case 6:\r
- OIC_LOG(INFO, TAG, "NSGetConsumerList");\r
- break;\r
- case 7:\r
- OIC_LOG(INFO, TAG, "NSStartPresence - not working");\r
- //NSTestStartPresence();\r
+\r
+ case 11:\r
+ printf("NSCloudLogin");\r
+\r
+ printf("Cloud Address: ");\r
+ gets(REMOTE_SERVER_ADDRESS);\r
+\r
+ printf("Session Code: ");\r
+ gets(REMOTE_SERVER_SESSION);\r
+\r
+\r
+ NSCloudLogin(REMOTE_SERVER_ADDRESS, REMOTE_SERVER_SESSION, CloudLoginoutCallback);\r
+ printf("OCCloudLogin requested");\r
break;\r
- case 8:\r
- OIC_LOG(INFO, TAG, "NSStopPresence- not working");\r
- //NSTestStopPresence();\r
+ case 12:\r
+ printf("NSCloudLogout");\r
+\r
+ NSCloudLogout(REMOTE_SERVER_ADDRESS, REMOTE_SERVER_SESSION, CloudLoginoutCallback);\r
+ printf("OCCloudLogout requested");\r
break;\r
case 0:\r
NSStopProvider();\r
isExit = true;\r
break;\r
default:\r
- OIC_LOG(INFO, TAG, "Under Construction");\r
+ printf("Under Construction");\r
break;\r
}\r
\r