static uint8_t g_lastRequestTokenLength;
static const char SECURE_COAPS_PREFIX[] = "coaps://";
-static const char SECURE_INFO_DATA[] = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
- "\"if\":[\"oc.mi.def\"],\"obs\":1,\"sec\":1,"
- "\"port\":%d}}]}";
-static const char NORMAL_INFO_DATA[] = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
- "\"if\":[\"oc.mi.def\"],\"obs\":1}}]}";
+
+static const char SECURE_INFO_DATA[]
+ = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
+ "\"if\":[\"oic.if.baseline\"],\"obs\":1,\"sec\":1,\"port\":%d}}]}";
+static const char NORMAL_INFO_DATA[]
+ = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
+ "\"if\":[\"oic.if.baseline\"],\"obs\":1}}]}";
+
static jobject g_responseListenerObject = NULL;
static JavaVM *g_jvm;
static const char SECURE_COAPS_PREFIX[] = "coaps://";
static const char SECURE_INFO_DATA[] =
"{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
- "\"if\":[\"oc.mi.def\"],\"obs\":1,\"sec\":1,\"port\":%d}}]}";
+ "\"if\":[\"oic.if.baseline\"],\"obs\":1,\"sec\":1,\"port\":%d}}]}";
static const char NORMAL_INFO_DATA[] =
"{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
- "\"if\":[\"oc.mi.def\"],\"obs\":1}}]}";
+ "\"if\":[\"oic.if.baseline\"],\"obs\":1}}]}";
#ifdef __WITH_DTLS__
static CADtlsPskCredsBlob_t *pskCredsBlob = NULL;
static const char SECURE_COAPS_PREFIX[] = "coaps://";
static const char SECURE_INFO_DATA[] =
"{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
- "\"if\":[\"oc.mi.def\"],\"obs\":1,\"sec\":1,\"port\":%d}}]}";
+ "\"if\":[\"oic.if.baseline\"],\"obs\":1,\"sec\":1,\"port\":%d}}]}";
static const char NORMAL_INFO_DATA[] =
"{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
- "\"if\":[\"oc.mi.def\"],\"obs\":1}}]}";
+ "\"if\":[\"oic.if.baseline\"],\"obs\":1}}]}";
#ifdef __WITH_DTLS__
static CADtlsPskCredsBlob_t *pskCredsBlob = NULL;
static const char SECURE_INFO_DATA[] =
"{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
- "\"if\":[\"oc.mi.def\"],\"obs\":1,\"sec\":1,\"port\":%d}}]}";
+ "\"if\":[\"oic.if.baseline\"],\"obs\":1,\"sec\":1,\"port\":%d}}]}";
static const char NORMAL_INFO_DATA[] =
"{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
- "\"if\":[\"oc.mi.def\"],\"obs\":1}}]}";
+ "\"if\":[\"oic.if.baseline\"],\"obs\":1}}]}";
#ifdef __WITH_DTLS__
#include "ocserverrequest.h"
/**
- * Attributes used to form a proper OIC conforming JSON message.
- */
-#define OC_RSRVD_OC "oc"
-#define OC_RSRVD_PAYLOAD "payload"
-#define OC_RSRVD_HREF "href"
-#define OC_RSRVD_PROPERTY "prop"
-#define OC_RSRVD_REPRESENTATION "rep"
-#define OC_RSRVD_CONTENT_TYPE "ct"
-#define OC_RSRVD_RESOURCE_TYPE "rt"
-#define OC_RSRVD_RESOURCE_TYPE_PRESENCE "core.presence"
-#define OC_RSRVD_INTERFACE "if"
-#define OC_RSRVD_DEVICE_ID "di"
-#define OC_RSRVD_DEVICE_NAME "dn"
-#define OC_RSRVD_INTERFACE_DEFAULT "oc.mi.def"
-#define OC_RSRVD_INTERFACE_LL "oc.mi.ll"
-#define OC_RSRVD_INTERFACE_BATCH "oc.mi.b"
-#define OC_RSRVD_INTERFACE_GROUP "oc.mi.grp"
-#define OC_RSRVD_MFG_DATE "mndt"
-#define OC_RSRVD_FW_VERSION "mnfv"
-#define OC_RSRVD_HOST_NAME "hn"
-#define OC_RSRVD_MFG_NAME "mnmn"
-#define OC_RSRVD_MFG_URL "mnml"
-#define OC_RSRVD_MODEL_NUM "mnmo"
-#define OC_RSRVD_PLATFORM_VERSION "mnpv"
-#define OC_RSRVD_SUPPORT_URL "mnsl"
-#define OC_RSRVD_VERSION "icv"
-#define OC_RSRVD_OBSERVABLE "obs"
-#define OC_RSRVD_SECURE "sec"
-#define OC_RSRVD_HOSTING_PORT "port"
-#define OC_RSRVD_SERVER_INSTANCE_ID "sid"
-
-/**
* Common JSON string components used by the stack to build JSON strings.
* These details are exposed in ocstackconfig.h file in the form of documentation.
* Remember to update the documentation there if these are changed.
/// operation.
#define OC_MAX_PRESENCE_TTL_SECONDS (60 * 60 * 24) // 60 sec/min * 60 min/hr * 24 hr/day
#define OC_PRESENCE_URI "/oc/presence"
+
+/**
+ * Attributes used to form a proper OIC conforming JSON message.
+ */
+#define OC_RSRVD_OC "oic"
+#define OC_RSRVD_PAYLOAD "payload"
+#define OC_RSRVD_HREF "href"
+#define OC_RSRVD_PROPERTY "prop"
+#define OC_RSRVD_REPRESENTATION "rep"
+#define OC_RSRVD_CONTENT_TYPE "ct"
+#define OC_RSRVD_RESOURCE_TYPE "rt"
+#define OC_RSRVD_RESOURCE_TYPE_PRESENCE "core.presence"
+#define OC_RSRVD_INTERFACE "if"
+#define OC_RSRVD_DEVICE_ID "di"
+#define OC_RSRVD_DEVICE_NAME "dn"
+#define OC_RSRVD_INTERFACE_DEFAULT "oic.if.baseline"
+#define OC_RSRVD_INTERFACE_LL "oic.if.ll"
+#define OC_RSRVD_INTERFACE_BATCH "oic.if.b"
+#define OC_RSRVD_INTERFACE_GROUP "oc.mi.grp"
+#define OC_RSRVD_MFG_DATE "mndt"
+#define OC_RSRVD_FW_VERSION "mnfv"
+#define OC_RSRVD_HOST_NAME "hn"
+#define OC_RSRVD_MFG_NAME "mnmn"
+#define OC_RSRVD_MFG_URL "mnml"
+#define OC_RSRVD_MODEL_NUM "mnmo"
+#define OC_RSRVD_PLATFORM_VERSION "mnpv"
+#define OC_RSRVD_SUPPORT_URL "mnsl"
+#define OC_RSRVD_VERSION "icv"
+#define OC_RSRVD_OBSERVABLE "obs"
+#define OC_RSRVD_SECURE "sec"
+#define OC_RSRVD_HOSTING_PORT "port"
+#define OC_RSRVD_SERVER_INSTANCE_ID "sid"
#endif
//-----------------------------------------------------------------------------
Light.state = false;
OCStackResult res = OCCreateResource(&Light.handle,
"core.light",
- "oc.mi.def",
+ OC_RSRVD_INTERFACE_DEFAULT,
"/a/light",
OCEntityHandlerCb,
OC_DISCOVERABLE|OC_OBSERVABLE);
testToTextMap queryInterface[] = {
{"invalid", TEST_INVALID},
- {"?if=oc.mi.def", TEST_GET_DEFAULT},
- {"?if=oc.mi.b", TEST_GET_BATCH},
- {"?if=oc.mi.ll", TEST_GET_LINK_LIST},
- {"?if=oc.mi.def", TEST_UNKNOWN_RESOURCE_GET_DEFAULT},
- {"?if=oc.mi.b", TEST_UNKNOWN_RESOURCE_GET_BATCH},
- {"?if=oc.mi.ll", TEST_UNKNOWN_RESOURCE_GET_LINK_LIST},
- {"?if=oc.mi.def", TEST_PUT_DEFAULT},
- {"?if=oc.mi.b", TEST_PUT_BATCH},
- {"?if=oc.mi.ll", TEST_PUT_LINK_LIST},
+ {"?if=oic.if.baseline", TEST_GET_DEFAULT},
+ {"?if=oic.if.b", TEST_GET_BATCH},
+ {"?if=oic.if.ll", TEST_GET_LINK_LIST},
+ {"?if=oic.if.baseline", TEST_UNKNOWN_RESOURCE_GET_DEFAULT},
+ {"?if=oic.if.b", TEST_UNKNOWN_RESOURCE_GET_BATCH},
+ {"?if=oic.if.ll", TEST_UNKNOWN_RESOURCE_GET_LINK_LIST},
+ {"?if=oic.if.baseline", TEST_PUT_DEFAULT},
+ {"?if=oic.if.b", TEST_PUT_BATCH},
+ {"?if=oic.if.ll", TEST_PUT_LINK_LIST},
};
static std::string putPayload = "{\"state\":\"off\",\"power\":\"0\"}";
// Entity handler should check for resourceTypeName and ResourceInterface in order to GET
// the existence of a known resource
const char *resourceTypeName = "core.light";
-const char *resourceInterface = "oc.mi.def";
+const char *resourceInterface = OC_RSRVD_INTERFACE_DEFAULT;
OCDeviceInfo deviceInfo;
// This variable determines instance number of the LED resource.
// Used by POST method to create a new instance of LED resource.
static int gCurrLedInstance = 0;
-#define SAMPLE_MAX_NUM_POST_INSTANCE 2
+#define SAMPLE_MAX_NUM_POST_INSTANCE 2
static LEDResource gLedInstance[SAMPLE_MAX_NUM_POST_INSTANCE];
char *gResourceUri= (char *)"/a/led";
ledResource->power= resourcePower;
OCStackResult res = OCCreateResource(&(ledResource->handle),
"core.led",
- "oc.mi.def",
+ OC_RSRVD_INTERFACE_DEFAULT,
uri,
OCEntityHandlerCb,
OC_DISCOVERABLE|OC_OBSERVABLE);
if(OC_REST_GET == ehRequest->method)
{
- if(query.find("oc.mi.def") != std::string::npos)
+ if(query.find(OC_RSRVD_INTERFACE_DEFAULT) != std::string::npos)
{
ret = HandleCallback(ehRequest,
rspGetRoomDefault, rspFailureRoom, payload, sizeof(payload));
rspGetFanCollection, rspFailureFan, payload, sizeof(payload));
}
}
- else if(query.find("oc.mi.ll") != std::string::npos)
+ else if(query.find(OC_RSRVD_INTERFACE_LL) != std::string::npos)
{
ret = HandleCallback(ehRequest,
rspGetRoomCollection, rspFailureRoom, payload, sizeof(payload));
rspGetFanCollection, rspFailureFan, payload, sizeof(payload));
}
}
- else if(query.find("oc.mi.b") != std::string::npos)
+ else if(query.find(OC_RSRVD_INTERFACE_BATCH) != std::string::npos)
{
ret = HandleCallback(ehRequest,
rspGetRoomCollection, rspFailureRoom, payload, sizeof(payload));
}
else if(OC_REST_PUT == ehRequest->method)
{
- if(query.find("oc.mi.def") != std::string::npos)
+ if(query.find(OC_RSRVD_INTERFACE_DEFAULT) != std::string::npos)
{
if(ret != OC_EH_ERROR)
{
rspPutRoomDefault, rspFailureRoom, payload, sizeof(payload));
}
}
- if(query.find("oc.mi.ll") != std::string::npos)
+ if(query.find(OC_RSRVD_INTERFACE_LL) != std::string::npos)
{
if(ret != OC_EH_ERROR)
{
rspPutFanCollection, rspFailureFan, payload, sizeof(payload));
}
}
- if(query.find("oc.mi.b") != std::string::npos)
+ if(query.find(OC_RSRVD_INTERFACE_BATCH ) != std::string::npos)
{
if(ret != OC_EH_ERROR)
{
OCResourceHandle fan;
OCStackResult res = OCCreateResource(&fan,
"core.fan",
- "oc.mi.def",
+ OC_RSRVD_INTERFACE_DEFAULT,
"/a/fan",
OCEntityHandlerFanCb,
OC_DISCOVERABLE|OC_OBSERVABLE);
OCResourceHandle light;
res = OCCreateResource(&light,
"core.light",
- "oc.mi.def",
+ OC_RSRVD_INTERFACE_DEFAULT,
"/a/light",
OCEntityHandlerLightCb,
OC_DISCOVERABLE|OC_OBSERVABLE);
{
res = OCCreateResource(&room,
"core.room",
- "oc.mi.b",
+ OC_RSRVD_INTERFACE_BATCH,
"/a/room",
OCEntityHandlerRoomCb,
OC_DISCOVERABLE);
{
res = OCCreateResource(&room,
"core.room",
- "oc.mi.b",
+ OC_RSRVD_INTERFACE_BATCH,
"/a/room",
NULL,
OC_DISCOVERABLE);
}
OC_LOG_V(INFO, TAG, "Created room resource with result: %s", getResult(res));
- OCBindResourceInterfaceToResource(room, "oc.mi.ll");
- OCBindResourceInterfaceToResource(room, "oc.mi.def");
+ OCBindResourceInterfaceToResource(room, OC_RSRVD_INTERFACE_LL);
+ OCBindResourceInterfaceToResource(room, OC_RSRVD_INTERFACE_DEFAULT);
res = OCBindResource(room, light);
OC_LOG_V(INFO, TAG, "OC Bind Contained Resource to resource: %s", getResult(res));
ledResource->power= resourcePower;
OCStackResult res = OCCreateResource(&(ledResource->handle),
"core.led",
- "oc.mi.def",
+ OC_RSRVD_INTERFACE_DEFAULT,
uri,
OCEntityHandlerCb,
OC_DISCOVERABLE|OC_OBSERVABLE);
ledResource->power= resourcePower;
OCStackResult res = OCCreateResource(&(ledResource->handle),
"core.led",
- "oc.mi.def",
+ OC_RSRVD_INTERFACE_DEFAULT,
uri,
OCEntityHandlerCb,
OC_DISCOVERABLE|OC_OBSERVABLE | OC_SECURE);
url = OCGetResourceUri(handle3);
EXPECT_STREQ("/a/led3", url);
- EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle3, "oc.mi.ll"));
- EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle3, "oc.mi.b"));
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle3, OC_RSRVD_INTERFACE_LL));
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle3, OC_RSRVD_INTERFACE_BATCH));
OCResourceHandle handle4;
EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle4,
EXPECT_STREQ("/a/led4", url);
EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle4, "core.brightled"));
- EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle4, "oc.mi.ll"));
- EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle4, "oc.mi.b"));
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle4, OC_RSRVD_INTERFACE_LL));
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle4, OC_RSRVD_INTERFACE_BATCH));
//EXPECT_EQ(OC_STACK_OK, OCHandleServerRequest(&res, uri, query, req, rsp));
myLight.createResource();
myLight.addType(std::string("core.brightlight"));
- myLight.addInterface(std::string("oc.mi.ll"));
+ myLight.addInterface(std::string(LINK_INTERFACE));
// A condition variable will free the mutex it is given, then do a non-
// intensive block until 'notify' is called on it. In this case, since we
std::cout << "Created resource." << std::endl;
myLight.addType(std::string("core.brightlight"));
- myLight.addInterface(std::string("oc.mi.ll"));
+ myLight.addInterface(std::string(LINK_INTERFACE));
std::cout << "Added Interface and Type" << std::endl;
+
// A condition variable will free the mutex it is given, then do a non-
// intensive block until 'notify' is called on it. In this case, since we
// don't ever call cv.notify, this should be a non-processor intensive version
myLight.createResource();
myLight.addType(std::string("core.brightlight"));
- myLight.addInterface(std::string("oc.mi.ll"));
+ myLight.addInterface(std::string(LINK_INTERFACE));
// A condition variable will free the mutex it is given, then do a non-
// intensive block until 'notify' is called on it. In this case, since we
// const strings for different interfaces
// Default interface
- const std::string DEFAULT_INTERFACE = "oc.mi.def";
+ const std::string DEFAULT_INTERFACE = "oic.if.baseline";
// Used in discovering (GET) links to other resources of a collection.
- const std::string LINK_INTERFACE = "oc.mi.ll";
+ const std::string LINK_INTERFACE = "oic.if.ll";
// Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
- const std::string BATCH_INTERFACE = "oc.mi.b";
+ const std::string BATCH_INTERFACE = "oic.if.b";
// Used in GET, PUT, POST methods on links to other remote resources of a group.
const std::string GROUP_INTERFACE = "oc.mi.grp";
return checked_guard(m_server, &IServerWrapper::registerResourceWithHost,
std::ref(resourceHandle), resource->host(), resource->uri(),
- resourceTypes[0]/*"core.remote"*/, "oc.mi.def",
+ resourceTypes[0]/*"core.remote"*/, DEFAULT_INTERFACE,
(EntityHandler) nullptr, resourceProperty);
}