//string length of "/a/light/" + std::numeric_limits<int>::digits10 + '\0'"
// 9 + 9 + 1 = 19
const int URI_MAXSIZE = 19;
+static const char* DEFAULT_DB_FILE_PATH = "/opt/usr/etc/oic_svr_db_server.dat";
static int gObserveNotifyType = 3;
+static int gSecure = 0;
int gQuitFlag = 0;
int gLightUnderObservation = 0;
}
}
+ OCPayloadDestroy(response.payload);
return ehResult;
}
if(res == OC_STACK_OK)
{
sleep(2);
+
+ uint8_t resourceProperties = OC_DISCOVERABLE | OC_OBSERVABLE;
+ if (gSecure)
+ {
+ resourceProperties |= OC_SECURE;
+ }
+
res = OCCreateResource(&presenceNotificationHandles[i],
presenceNotificationResources.at(i).c_str(),
OC_RSRVD_INTERFACE_DEFAULT,
presenceNotificationUris.at(i).c_str(),
OCNOPEntityHandlerCb,
NULL,
- OC_DISCOVERABLE|OC_OBSERVABLE);
+ resourceProperties);
}
if(res != OC_STACK_OK)
{
lightResource->state = false;
lightResource->power= 0;
+
+ uint8_t resourceProperties = OC_DISCOVERABLE | OC_OBSERVABLE;
+ if (gSecure)
+ {
+ resourceProperties |= OC_SECURE;
+ }
+
OCStackResult res = OCCreateResource(&(lightResource->handle),
"core.light",
"oc.mi.def",
uri,
OCEntityHandlerCb,
NULL,
- OC_DISCOVERABLE|OC_OBSERVABLE);
+ resourceProperties);
cout << "\nCreated Light resource with result " << getResult(res);
return 0;
static void PrintUsage()
{
- cout << "\nUsage : ocserver -o <0|1>";
+ cout << "\nUsage : ocserver -o <0|1> -s <0|1>";
cout << "\n-o 0 : Notify all observers";
cout << "\n-o 1 : Notify list of observers";
+ cout << "\n-s 0 : Non secure resource";
+ cout << "\n-s 1 : Secure resource";
}
void *GMainLoopThread(void *param)
return NULL;
}
+static FILE *server_fopen(const char */*path*/, const char *mode)
+{
+ return fopen(DEFAULT_DB_FILE_PATH, mode);
+}
+
int main(int argc, char* argv[])
{
pthread_t threadId;
return 0;
}
- while ((opt = getopt(argc, argv, "o:")) != -1)
+ while ((opt = getopt(argc, argv, "o:s:")) != -1)
{
switch(opt)
{
case 'o':
gObserveNotifyType = atoi(optarg);
break;
+ case 's':
+ gSecure = atoi(optarg);
+ break;
default:
PrintUsage();
return -1;
}
}
- if ((gObserveNotifyType != 0) && (gObserveNotifyType != 1))
+ if ((gObserveNotifyType != 0) && (gObserveNotifyType != 1) &&
+ (gSecure != 0) && (gSecure != 1))
{
PrintUsage();
return -1;
cout << "\nOCServer is starting...";
+ OCPersistentStorage ps{ server_fopen, fread, fwrite, fclose, unlink };
+ OCRegisterPersistentStorageHandler(&ps);
+
if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
{
cout << "\nOCStack init error";