replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / resource-encapsulation / examples / linux / SampleResourceServer.cpp
index 65b9cd6..9e919b6 100644 (file)
@@ -19,6 +19,7 @@
  ******************************************************************/
 
 #include "RCSResourceObject.h"
+#include "RCSRequest.h"
 #include "OCPlatform.h"
 
 using namespace OC::OCPlatform;
@@ -53,7 +54,7 @@ int processUserInput(int min, int max)
 {
     assert(min <= max);
 
-    int input;
+    int input = 0;
 
     std::cin >> input;
 
@@ -102,7 +103,7 @@ void printAttributes(const RCSResourceAttributes& attrs)
     }
 }
 
-RCSGetResponse requestHandlerForGet(const RCSRequest&, RCSResourceAttributes& attrs)
+RCSGetResponse requestHandlerForGet(const RCSRequest & req, RCSResourceAttributes& attrs)
 {
     std::cout << "Received a Get request from Client" << std::endl;
     printAttributes(attrs);
@@ -110,10 +111,21 @@ RCSGetResponse requestHandlerForGet(const RCSRequest&, RCSResourceAttributes& at
     {
         RCSResourceObject::LockGuard lock(g_resource);
         std::cout << "\nSending response to Client : " << std::endl;
-        printAttributes(g_resource->getAttributes());
+        if (req.getInterface() == CUSTOM_INTERFACE)
+        {
+            auto attr = g_resource->getAttributes();
+            static RCSByteString::DataType binval {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8,
+                                                   0x9, 0x0, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF};
+            attr["blob"] = RCSByteString {binval};
+            printAttributes(attr);
+            return RCSGetResponse::create(attr);
+        }
+        else
+        {
+            printAttributes(g_resource->getAttributes());
+            return RCSGetResponse::defaultAction();
+        }
     }
-
-    return RCSGetResponse::defaultAction();
 }
 
 RCSSetResponse requestHandlerForSet(const RCSRequest&, RCSResourceAttributes& attrs)
@@ -178,7 +190,7 @@ void runResourceTypeSelection(int resourceMode)
     std::cout << "========================================================\n";
 
     int resourceType = processUserInput(RESOURCE_TEMP, RESOURCE_LIGHT);
-    DisplayControlMenuFunc displayMenuFunc;
+    DisplayControlMenuFunc displayMenuFunc = nullptr;
     std::string attrKey;
 
     switch (resourceType)
@@ -264,7 +276,14 @@ int main(void)
 
     if (g_isPresenceStarted)
     {
-        stopPresence();
+        try
+        {
+            stopPresence();
+        }
+        catch(...)
+        {
+            std::cout << "presence stop fail" << std::endl;
+        }
     }
 }