Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / csdk / stack / samples / linux / SimpleClientServer / ocserver.cpp
index d263b09..e40f06a 100644 (file)
@@ -29,7 +29,7 @@
 #include <array>
 #include "ocstack.h"
 #include "logger.h"
-#include "cJSON.h"
+#include "ocpayload.h"
 #include "ocserver.h"
 
 //string length of "/a/light/" + std::numeric_limits<int>::digits10 + '\0'"
@@ -55,24 +55,11 @@ static int stopPresenceCount = 10;
 #define numPresenceResources (2)
 #endif
 
-//TODO: Follow the pattern used in constructJsonResponse() when the payload is decided.
-const char responsePayloadDeleteOk[] =
-        "{App determines payload: Delete Resource operation succeeded.}";
-const char responsePayloadDeleteNotOK[] =
-        "{App determines payload: Delete Resource operation failed.}";
-const char responsePayloadResourceDoesNotExist[] =
-        "{App determines payload: The resource does not exist.}";
-const char responsePayloadDeleteResourceNotSupported[] =
-        "{App determines payload: The request is received for a non-support resource.}";
-
-
 char *gResourceUri= (char *)"/a/light";
-const char *contentType = "myContentType";
 const char *dateOfManufacture = "myDateOfManufacture";
 const char *deviceName = "myDeviceName";
 const char *deviceUUID = "myDeviceUUID";
 const char *firmwareVersion = "myFirmwareVersion";
-const char *hostName = "myHostName";
 const char *manufacturerName = "myName";
 const char *operatingSystemVersion = "myOS";
 const char *hardwareVersion = "myHardwareVersion";
@@ -90,14 +77,35 @@ const char *resourceTypeName = "core.light";
 const char *resourceInterface = OC_RSRVD_INTERFACE_DEFAULT;
 
 OCPlatformInfo platformInfo;
+OCDeviceInfo deviceInfo;
+
+OCRepPayload* getPayload(const char* uri, int64_t power, bool state)
+{
+    OCRepPayload* payload = OCRepPayloadCreate();
+    if(!payload)
+    {
+        OC_LOG(ERROR, TAG, PCF("Failed to allocate Payload"));
+        return nullptr;
+    }
+
+    OCRepPayloadSetUri(payload, uri);
+    OCRepPayloadSetPropBool(payload, "state", state);
+    OCRepPayloadSetPropInt(payload, "power", power);
+
+    return payload;
+}
 
 //This function takes the request as an input and returns the response
-//in JSON format.
-char* constructJsonResponse (OCEntityHandlerRequest *ehRequest)
+OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest)
 {
-    cJSON *json = cJSON_CreateObject();
-    cJSON *format;
-    char *jsonResponse;
+    if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
+    {
+        OC_LOG(ERROR, TAG, PCF("Incoming payload not a representation"));
+        return nullptr;
+    }
+
+    OCRepPayload* input = reinterpret_cast<OCRepPayload*>(ehRequest->payload);
+
     LightResource *currLightResource = &Light;
 
     if (ehRequest->resource == gLightInstance[0].handle)
@@ -113,49 +121,26 @@ char* constructJsonResponse (OCEntityHandlerRequest *ehRequest)
 
     if(OC_REST_PUT == ehRequest->method)
     {
-        // Get cJSON pointer to query
-        cJSON *putJson = cJSON_Parse(ehRequest->reqJSONPayload);
-
-        if(!putJson)
-        {
-            OC_LOG_V(ERROR, TAG, "Failed to parse JSON: %s", ehRequest->reqJSONPayload);
-            return NULL;
-        }
-
-        // Get root of JSON payload, then the 1st resource.
-        cJSON* carrier = cJSON_GetObjectItem(putJson, "oc");
-        carrier = cJSON_GetArrayItem(carrier, 0);
-        carrier = cJSON_GetObjectItem(carrier, "rep");
-
-        cJSON* prop = cJSON_GetObjectItem(carrier,"power");
-        if (prop)
+        // Get pointer to query
+        int64_t pow;
+        if(OCRepPayloadGetPropInt(input, "power", &pow))
         {
-            currLightResource->power =prop->valueint;
+            currLightResource->power =pow;
         }
 
-        prop = cJSON_GetObjectItem(carrier,"state");
-        if (prop)
+        bool state;
+        if(OCRepPayloadGetPropBool(input, "state", &state))
         {
-            currLightResource->state = prop->valueint;
+            currLightResource->state = state;
         }
-
-        cJSON_Delete(putJson);
     }
 
-    cJSON_AddStringToObject(json,"href",gResourceUri);
-    cJSON_AddItemToObject(json, "rep", format=cJSON_CreateObject());
-    cJSON_AddBoolToObject(format, "state", currLightResource->state);
-    cJSON_AddNumberToObject(format, "power", currLightResource->power);
-
-    jsonResponse = cJSON_Print(json);
-    cJSON_Delete(json);
-
-    return jsonResponse;
+    return getPayload(gResourceUri, currLightResource->power, currLightResource->state);
 }
 
 /*
  * Very simple example of query parsing.
- * The query may have multiple filters separated by '&'.
+ * The query may have multiple filters separated by ';'.
  * It is upto the entity handler to parse the query for the individual filters,
  * VALIDATE them and respond as it sees fit.
 
@@ -194,7 +179,7 @@ OCEntityHandlerResult ValidateQueryParams (OCEntityHandlerRequest *entityHandler
 }
 
 OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-        char *payload, uint16_t maxPayloadSize)
+        OCRepPayload **payload)
 {
     OCEntityHandlerResult ehResult;
     bool queryPassed = checkIfQueryForPowerPassed(ehRequest->query);
@@ -202,26 +187,15 @@ OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
     // Empty payload if the query has no match.
     if (queryPassed)
     {
-        char *getResp = constructJsonResponse(ehRequest);
+        OCRepPayload *getResp = constructResponse(ehRequest);
         if(!getResp)
         {
-            OC_LOG(ERROR, TAG, "constructJsonResponse failed");
+            OC_LOG(ERROR, TAG, "constructResponse failed");
             return OC_EH_ERROR;
         }
 
-        if (maxPayloadSize > strlen (getResp))
-        {
-            strncpy(payload, getResp, strlen(getResp));
-            ehResult = OC_EH_OK;
-        }
-        else
-        {
-            OC_LOG_V (INFO, TAG, "Response buffer: %d bytes is too small",
-                    maxPayloadSize);
-            ehResult = OC_EH_ERROR;
-        }
-
-        free(getResp);
+        *payload = getResp;
+        ehResult = OC_EH_OK;
     }
     else
     {
@@ -232,10 +206,10 @@ OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
 }
 
 OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-        char *payload, uint16_t maxPayloadSize)
+        OCRepPayload** payload)
 {
     OCEntityHandlerResult ehResult;
-    char *putResp = constructJsonResponse(ehRequest);
+    OCRepPayload *putResp = constructResponse(ehRequest);
 
     if(!putResp)
     {
@@ -243,30 +217,17 @@ OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
         return OC_EH_ERROR;
     }
 
-    if (maxPayloadSize > strlen ((char *)putResp))
-    {
-        strncpy(payload, putResp, strlen((char *)putResp));
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        OC_LOG_V (INFO, TAG, "Response buffer: %d bytes is too small",
-                maxPayloadSize);
-        ehResult = OC_EH_ERROR;
-    }
-
-    free(putResp);
+    *payload = putResp;
+    ehResult = OC_EH_OK;
 
     return ehResult;
 }
 
 OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-        OCEntityHandlerResponse *response, char *payload, uint16_t maxPayloadSize)
+        OCEntityHandlerResponse *response, OCRepPayload** payload)
 {
     OCEntityHandlerResult ehResult = OC_EH_OK;
-    char *respPLPost_light = NULL;
-    cJSON *json;
-    cJSON *format;
+    OCRepPayload *respPLPost_light = nullptr;
 
     /*
      * The entity handler determines how to process a POST request.
@@ -287,10 +248,9 @@ OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
             char newLightUri[URI_MAXSIZE];
             snprintf(newLightUri, URI_MAXSIZE, "/a/light/%d", gCurrLightInstance);
 
-            json = cJSON_CreateObject();
-            cJSON_AddStringToObject(json,"href",gResourceUri);
-            cJSON_AddItemToObject(json, "rep", format=cJSON_CreateObject());
-            cJSON_AddStringToObject(format, "createduri", (char *) newLightUri);
+            respPLPost_light = OCRepPayloadCreate();
+            OCRepPayloadSetUri(respPLPost_light, gResourceUri);
+            OCRepPayloadSetPropString(respPLPost_light, "createduri", newLightUri);
 
             if (0 == createLightResource (newLightUri, &gLightInstance[gCurrLightInstance]))
             {
@@ -298,19 +258,16 @@ OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
                 gLightInstance[gCurrLightInstance].state = 0;
                 gLightInstance[gCurrLightInstance].power = 0;
                 gCurrLightInstance++;
-                respPLPost_light = cJSON_Print(json);
                 strncpy ((char *)response->resourceUri, newLightUri, MAX_URI_LENGTH);
                 ehResult = OC_EH_RESOURCE_CREATED;
             }
-
-            cJSON_Delete(json);
         }
         else
         {
             // Update repesentation of /a/light
             Light.state = true;
             Light.power = 11;
-            respPLPost_light = constructJsonResponse(ehRequest);
+            respPLPost_light = constructResponse(ehRequest);
         }
     }
     else
@@ -323,34 +280,31 @@ OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
                 gLightInstance[i].power = 22;
                 if (i == 0)
                 {
-                    respPLPost_light = constructJsonResponse(ehRequest);
+                    respPLPost_light = constructResponse(ehRequest);
                     break;
                 }
                 else if (i == 1)
                 {
-                    respPLPost_light = constructJsonResponse(ehRequest);
+                    respPLPost_light = constructResponse(ehRequest);
                 }
             }
         }
     }
 
-    if ((respPLPost_light != NULL) && (maxPayloadSize > strlen ((char *)respPLPost_light)))
+    if ((respPLPost_light != NULL))
     {
-        strncpy(payload, respPLPost_light, strlen((char *)respPLPost_light));
+        *payload = respPLPost_light;
     }
     else
     {
-        OC_LOG_V (INFO, TAG, "Response buffer: %d bytes is too small",
-                maxPayloadSize);
+        OC_LOG(INFO, TAG, "Payload was NULL");
         ehResult = OC_EH_ERROR;
     }
 
-    free(respPLPost_light);
     return ehResult;
 }
 
-OCEntityHandlerResult ProcessDeleteRequest (OCEntityHandlerRequest *ehRequest,
-        char *payload, uint16_t maxPayloadSize)
+OCEntityHandlerResult ProcessDeleteRequest (OCEntityHandlerRequest *ehRequest)
 {
     if(ehRequest == NULL)
     {
@@ -370,8 +324,6 @@ OCEntityHandlerResult ProcessDeleteRequest (OCEntityHandlerRequest *ehRequest,
      * 2. optionally, app removes observers out of its array 'interestedObservers'
      */
 
-    const char* deleteResponse = NULL;
-
     if ((ehRequest != NULL) && (ehRequest->resource == Light.handle))
     {
         //Step 1: Ask stack to do the work.
@@ -381,7 +333,6 @@ OCEntityHandlerResult ProcessDeleteRequest (OCEntityHandlerRequest *ehRequest,
         {
             OC_LOG (INFO, TAG, "\n\nDelete Resource operation succeeded.");
             ehResult = OC_EH_OK;
-            deleteResponse = responsePayloadDeleteOk;
 
             //Step 2: clear observers who wanted to observe this resource at the app level.
             for (uint8_t i = 0; i < SAMPLE_MAX_NUM_OBSERVATIONS; i++)
@@ -397,13 +348,11 @@ OCEntityHandlerResult ProcessDeleteRequest (OCEntityHandlerRequest *ehRequest,
         else if (result == OC_STACK_NO_RESOURCE)
         {
             OC_LOG(INFO, TAG, "\n\nThe resource doesn't exist or it might have been deleted.");
-            deleteResponse = responsePayloadResourceDoesNotExist;
             ehResult = OC_EH_RESOURCE_DELETED;
         }
         else
         {
             OC_LOG(INFO, TAG, "\n\nEncountered error from OCDeleteResource().");
-            deleteResponse = responsePayloadDeleteNotOK;
             ehResult = OC_EH_ERROR;
         }
     }
@@ -412,43 +361,16 @@ OCEntityHandlerResult ProcessDeleteRequest (OCEntityHandlerRequest *ehRequest,
         //Let's this app not supporting DELETE on some resources so
         //consider the DELETE request is received for a non-support resource.
         OC_LOG_V(INFO, TAG, "\n\nThe request is received for a non-support resource.");
-        deleteResponse = responsePayloadDeleteResourceNotSupported;
         ehResult = OC_EH_FORBIDDEN;
     }
 
-    if (maxPayloadSize > strlen ((char *)deleteResponse))
-    {
-        strncpy(payload, deleteResponse, strlen((char *)deleteResponse));
-    }
-    else
-    {
-        OC_LOG_V (INFO, TAG, "Response buffer: %d bytes is too small",
-                maxPayloadSize);
-        ehResult = OC_EH_ERROR;
-    }
-
     return ehResult;
 }
 
-OCEntityHandlerResult ProcessNonExistingResourceRequest(OCEntityHandlerRequest *ehRequest,
-        char *payload, uint16_t maxPayloadSize)
+OCEntityHandlerResult ProcessNonExistingResourceRequest(OCEntityHandlerRequest *ehRequest)
 {
     OC_LOG_V(INFO, TAG, "\n\nExecuting %s ", __func__);
 
-    const char* response = NULL;
-    response = responsePayloadResourceDoesNotExist;
-
-    if ( (ehRequest != NULL) &&
-         (maxPayloadSize > strlen ((char *)response)) )
-    {
-        strncpy((char *)payload, response, strlen((char *)response));
-    }
-    else
-    {
-        OC_LOG_V (ERROR, TAG, "Response buffer: %d bytes is too small",
-                maxPayloadSize);
-    }
-
     return OC_EH_RESOURCE_NOT_FOUND;
 }
 
@@ -492,13 +414,12 @@ void ProcessObserveDeregister (OCEntityHandlerRequest *ehRequest)
 
 OCEntityHandlerResult
 OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest, char* uri)
+        OCEntityHandlerRequest *entityHandlerRequest, char* uri, void* callbackParam)
 {
     OC_LOG_V (INFO, TAG, "Inside device default entity handler - flags: 0x%x, uri: %s", flag, uri);
 
     OCEntityHandlerResult ehResult = OC_EH_OK;
     OCEntityHandlerResponse response;
-    char payload[MAX_RESPONSE_LENGTH] = {0};
 
     // Validate pointer
     if (!entityHandlerRequest)
@@ -511,6 +432,7 @@ OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag,
     memset(response.sendVendorSpecificHeaderOptions, 0,
             sizeof response.sendVendorSpecificHeaderOptions);
     memset(response.resourceUri, 0, sizeof response.resourceUri);
+    OCRepPayload* payload = nullptr;
 
 
     if (flag & OC_REQUEST_FLAG)
@@ -520,23 +442,22 @@ OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag,
         if (entityHandlerRequest->resource == NULL)
         {
             OC_LOG (INFO, TAG, "Received request from client to a non-existing resource");
-            ehResult = ProcessNonExistingResourceRequest(entityHandlerRequest,
-                           payload, sizeof(payload) - 1);
+            ehResult = ProcessNonExistingResourceRequest(entityHandlerRequest);
         }
         else if (OC_REST_GET == entityHandlerRequest->method)
         {
             OC_LOG (INFO, TAG, "Received OC_REST_GET from client");
-            ehResult = ProcessGetRequest (entityHandlerRequest, payload, sizeof(payload) - 1);
+            ehResult = ProcessGetRequest (entityHandlerRequest, &payload);
         }
         else if (OC_REST_PUT == entityHandlerRequest->method)
         {
             OC_LOG (INFO, TAG, "Received OC_REST_PUT from client");
-            ehResult = ProcessPutRequest (entityHandlerRequest, payload, sizeof(payload) - 1);
+            ehResult = ProcessPutRequest (entityHandlerRequest, &payload);
         }
         else if (OC_REST_DELETE == entityHandlerRequest->method)
         {
             OC_LOG (INFO, TAG, "Received OC_REST_DELETE from client");
-            ehResult = ProcessDeleteRequest (entityHandlerRequest, payload, sizeof(payload) - 1);
+            ehResult = ProcessDeleteRequest (entityHandlerRequest);
         }
         else
         {
@@ -551,8 +472,7 @@ OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag,
             response.requestHandle = entityHandlerRequest->requestHandle;
             response.resourceHandle = entityHandlerRequest->resource;
             response.ehResult = ehResult;
-            response.payload = payload;
-            response.payloadSize = strlen(payload);
+            response.payload = reinterpret_cast<OCPayload*>(payload);
             // Indicate that response is NOT in a persistent buffer
             response.persistentBufferFlag = 0;
 
@@ -582,7 +502,7 @@ OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag,
 
 OCEntityHandlerResult
 OCNOPEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest)
+        OCEntityHandlerRequest *entityHandlerRequest, void* callbackParam)
 {
     // This is callback is associated with the 2 presence notification
     // resources. They are non-operational.
@@ -591,13 +511,12 @@ OCNOPEntityHandlerCb (OCEntityHandlerFlag flag,
 
 OCEntityHandlerResult
 OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest)
+        OCEntityHandlerRequest *entityHandlerRequest, void* callback)
 {
     OC_LOG_V (INFO, TAG, "Inside entity handler - flags: 0x%x", flag);
 
     OCEntityHandlerResult ehResult = OC_EH_OK;
-    OCEntityHandlerResponse response;
-    char payload[MAX_RESPONSE_LENGTH] = {0};
+    OCEntityHandlerResponse response = { 0 };
 
     // Validate pointer
     if (!entityHandlerRequest)
@@ -611,6 +530,7 @@ OCEntityHandlerCb (OCEntityHandlerFlag flag,
     memset(response.sendVendorSpecificHeaderOptions,
             0, sizeof response.sendVendorSpecificHeaderOptions);
     memset(response.resourceUri, 0, sizeof response.resourceUri);
+    OCRepPayload* payload = nullptr;
 
     if (flag & OC_REQUEST_FLAG)
     {
@@ -619,22 +539,22 @@ OCEntityHandlerCb (OCEntityHandlerFlag flag,
         if (OC_REST_GET == entityHandlerRequest->method)
         {
             OC_LOG (INFO, TAG, "Received OC_REST_GET from client");
-            ehResult = ProcessGetRequest (entityHandlerRequest, payload, sizeof(payload) - 1);
+            ehResult = ProcessGetRequest (entityHandlerRequest, &payload);
         }
         else if (OC_REST_PUT == entityHandlerRequest->method)
         {
             OC_LOG (INFO, TAG, "Received OC_REST_PUT from client");
-            ehResult = ProcessPutRequest (entityHandlerRequest, payload, sizeof(payload) - 1);
+            ehResult = ProcessPutRequest (entityHandlerRequest, &payload);
         }
         else if (OC_REST_POST == entityHandlerRequest->method)
         {
             OC_LOG (INFO, TAG, "Received OC_REST_POST from client");
-            ehResult = ProcessPostRequest (entityHandlerRequest, &response, payload, sizeof(payload) - 1);
+            ehResult = ProcessPostRequest (entityHandlerRequest, &response, &payload);
         }
         else if (OC_REST_DELETE == entityHandlerRequest->method)
         {
             OC_LOG (INFO, TAG, "Received OC_REST_DELETE from client");
-            ehResult = ProcessDeleteRequest (entityHandlerRequest, payload, sizeof(payload) - 1);
+            ehResult = ProcessDeleteRequest (entityHandlerRequest);
         }
         else
         {
@@ -649,8 +569,7 @@ OCEntityHandlerCb (OCEntityHandlerFlag flag,
             response.requestHandle = entityHandlerRequest->requestHandle;
             response.resourceHandle = entityHandlerRequest->resource;
             response.ehResult = ehResult;
-            response.payload = payload;
-            response.payloadSize = strlen(payload);
+            response.payload = reinterpret_cast<OCPayload*>(payload);
             // Indicate that response is NOT in a persistent buffer
             response.persistentBufferFlag = 0;
 
@@ -711,6 +630,7 @@ OCEntityHandlerCb (OCEntityHandlerFlag flag,
         }
     }
 
+    OCPayloadDestroy(response.payload);
     return ehResult;
 }
 
@@ -752,17 +672,10 @@ void *ChangeLightRepresentation (void *param)
                     }
                 }
 
-                cJSON *json = cJSON_CreateObject();
-                cJSON *format;
-                cJSON_AddStringToObject(json,"href",gResourceUri);
-                cJSON_AddItemToObject(json, "rep", format=cJSON_CreateObject());
-                cJSON_AddBoolToObject(format, "state", Light.state);
-                cJSON_AddNumberToObject(format, "power", Light.power);
-                char * obsResp = cJSON_Print(json);
-                cJSON_Delete(json);
+                OCRepPayload* payload = getPayload(gResourceUri, Light.power, Light.state);
                 result = OCNotifyListOfObservers (Light.handle, obsNotify, j,
-                        obsResp, OC_NA_QOS);
-                free(obsResp);
+                        payload, OC_NA_QOS);
+                OCRepPayloadDestroy(payload);
             }
             else if (gObserveNotifyType == 0)
             {
@@ -798,7 +711,7 @@ void *ChangeLightRepresentation (void *param)
 #ifdef WITH_PRESENCE
 void *presenceNotificationGenerator(void *param)
 {
-    sleep(5);
+    sleep(10);
     (void)param;
     OCDoHandle presenceNotificationHandles[numPresenceResources];
     OCStackResult res = OC_STACK_OK;
@@ -820,6 +733,7 @@ void *presenceNotificationGenerator(void *param)
                     OC_RSRVD_INTERFACE_DEFAULT,
                     presenceNotificationUris.at(i).c_str(),
                     OCNOPEntityHandlerCb,
+                    NULL,
                     OC_DISCOVERABLE|OC_OBSERVABLE);
         }
         if(res != OC_STACK_OK)
@@ -867,6 +781,7 @@ int createLightResource (char *uri, LightResource *lightResource)
             "oc.mi.def",
             uri,
             OCEntityHandlerCb,
+            NULL,
             OC_DISCOVERABLE|OC_OBSERVABLE);
     OC_LOG_V(INFO, TAG, "Created Light resource with result: %s", getResult(res));
 
@@ -888,6 +803,11 @@ void DeletePlatformInfo()
     free (platformInfo.systemTime);
 }
 
+void DeleteDeviceInfo()
+{
+    free (deviceInfo.deviceName);
+}
+
 bool DuplicateString(char** targetString, const char* sourceString)
 {
     if(!sourceString)
@@ -989,6 +909,15 @@ OCStackResult SetPlatformInfo(const char* platformID, const char *manufacturerNa
     return OC_STACK_ERROR;
 }
 
+OCStackResult SetDeviceInfo(const char* deviceName)
+{
+    if(!DuplicateString(&deviceInfo.deviceName, deviceName))
+    {
+        return OC_STACK_ERROR;
+    }
+    return OC_STACK_OK;
+}
+
 static void PrintUsage()
 {
     OC_LOG(INFO, TAG, "Usage : ocserver -o <0|1>");
@@ -1020,6 +949,18 @@ int main(int argc, char* argv[])
         PrintUsage();
         return -1;
     }
+    #ifdef RA_ADAPTER
+    OCRAInfo_t rainfo;
+    rainfo.hostname = "localhost";
+    rainfo.port = 5222;
+    rainfo.xmpp_domain = "localhost";
+    rainfo.username = "test1";
+    rainfo.password = "intel123";
+    rainfo.resource = "";
+    rainfo.user_jid = "";
+
+    OCSetRAInfo(&rainfo);
+    #endif
 
     OC_LOG(DEBUG, TAG, "OCServer is starting...");
 
@@ -1036,27 +977,43 @@ int main(int argc, char* argv[])
     }
 #endif
 
-    OCSetDefaultDeviceEntityHandler(OCDeviceEntityHandlerCb);
+    OCSetDefaultDeviceEntityHandler(OCDeviceEntityHandlerCb, NULL);
 
-    OCStackResult platformRegistrationResult =
+    OCStackResult registrationResult =
         SetPlatformInfo(platformID, manufacturerName, manufacturerUrl, modelNumber,
             dateOfManufacture, platformVersion,  operatingSystemVersion,  hardwareVersion,
             firmwareVersion,  supportUrl, systemTime);
 
-    if (platformRegistrationResult != OC_STACK_OK)
+    if (registrationResult != OC_STACK_OK)
     {
         OC_LOG(INFO, TAG, "Platform info setting failed locally!");
         exit (EXIT_FAILURE);
     }
 
-    platformRegistrationResult = OCSetPlatformInfo(platformInfo);
+    registrationResult = OCSetPlatformInfo(platformInfo);
 
-    if (platformRegistrationResult != OC_STACK_OK)
+    if (registrationResult != OC_STACK_OK)
     {
         OC_LOG(INFO, TAG, "Platform Registration failed!");
         exit (EXIT_FAILURE);
     }
 
+    registrationResult = SetDeviceInfo(deviceName);
+
+    if (registrationResult != OC_STACK_OK)
+    {
+        OC_LOG(INFO, TAG, "Device info setting failed locally!");
+        exit (EXIT_FAILURE);
+    }
+
+    registrationResult = OCSetDeviceInfo(deviceInfo);
+
+    if (registrationResult != OC_STACK_OK)
+    {
+        OC_LOG(INFO, TAG, "Device Registration failed!");
+        exit (EXIT_FAILURE);
+    }
+
     /*
      * Declare and create the example resource: Light
      */
@@ -1084,8 +1041,12 @@ int main(int argc, char* argv[])
 
     // Break from loop with Ctrl-C
     OC_LOG(INFO, TAG, "Entering ocserver main loop...");
+
     DeletePlatformInfo();
+    DeleteDeviceInfo();
+
     signal(SIGINT, handleSigInt);
+
     while (!gQuitFlag)
     {
         if (OCProcess() != OC_STACK_OK)
@@ -1113,4 +1074,4 @@ int main(int argc, char* argv[])
     }
 
     return 0;
-}
\ No newline at end of file
+}