Update response payload parser for samples
authorJee Hyeok Kim <jihyeok13.kim@samsung.com>
Thu, 1 Sep 2016 06:43:09 +0000 (15:43 +0900)
committerJee Hyeok Kim <jihyeok13.kim@samsung.com>
Fri, 2 Sep 2016 01:13:37 +0000 (01:13 +0000)
1. Update response payload parser for samples
   to print all variables

2. Cleanup code

Change-Id: I7fc6f583c43ce4dd6f5a4bf43a3990b4f86d5371
Signed-off-by: Jee Hyeok Kim <jihyeok13.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11247
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
cloud/samples/client/airconditioner/aircon_controlee.cpp
cloud/samples/client/airconditioner/aircon_controller.cpp
cloud/samples/client/group_invite/group_invite.cpp
cloud/samples/client/messagequeue/mq_publisher.cpp
cloud/samples/client/messagequeue/mq_subscriber.cpp
cloud/samples/client/thin_light/thin_room_light.cpp

index 19bf82c2f2a67286e7885e25f530bcb665d30968..6b53aea4cae687b99c20259a1adca0c7ba1b0b99 100644 (file)
@@ -59,9 +59,9 @@ class Resource
             return OCPlatform::bindResource(m_handle, childResource->m_handle);
         }
 
-        OCStackResult sendRepresentation(std::shared_ptr<OCResourceRequest> pRequest)
+        OCStackResult sendRepresentation(shared_ptr<OCResourceRequest> pRequest)
         {
-            auto pResponse = std::make_shared<OC::OCResourceResponse>();
+            auto pResponse = make_shared<OC::OCResourceResponse>();
             pResponse->setRequestHandle(pRequest->getRequestHandle());
             pResponse->setResourceHandle(pRequest->getResourceHandle());
 
@@ -95,8 +95,8 @@ class Resource
         {
             if (m_interestedObservers.size() > 0)
             {
-                std::shared_ptr<OCResourceResponse> resourceResponse =
-                { std::make_shared<OCResourceResponse>() };
+                shared_ptr<OCResourceResponse> resourceResponse =
+                { make_shared<OCResourceResponse>() };
 
                 resourceResponse->setErrorCode(200);
                 resourceResponse->setResourceRepresentation(getRepresentation(), DEFAULT_INTERFACE);
@@ -109,7 +109,7 @@ class Resource
             return OC_STACK_OK;
         }
 
-        virtual OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request) = 0;
+        virtual OCEntityHandlerResult entityHandler(shared_ptr<OCResourceRequest> request) = 0;
 
     protected:
         OCRepresentation    m_representation;
@@ -143,7 +143,7 @@ class BinarySwitchResource : public Resource //oic.r.switch.binary
             }
         }
 
-        OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request)
+        OCEntityHandlerResult entityHandler(shared_ptr<OCResourceRequest> request)
         {
             cout << "\tIn Server Binaryswitch entity handler:\n";
             OCEntityHandlerResult ehResult = OC_EH_ERROR;
@@ -151,7 +151,7 @@ class BinarySwitchResource : public Resource //oic.r.switch.binary
             if (request)
             {
                 // Get the request type and request flag
-                std::string requestType = request->getRequestType();
+                string requestType = request->getRequestType();
                 int requestFlag = request->getRequestHandlerFlag();
 
                 if (requestFlag & RequestHandlerFlag::RequestFlag)
@@ -202,7 +202,7 @@ class BinarySwitchResource : public Resource //oic.r.switch.binary
                     }
                     else if (ObserveAction::ObserveUnregister == observationInfo.action)
                     {
-                        m_interestedObservers.erase(std::remove(
+                        m_interestedObservers.erase(remove(
                                                         m_interestedObservers.begin(),
                                                         m_interestedObservers.end(),
                                                         observationInfo.obsId),
@@ -212,7 +212,7 @@ class BinarySwitchResource : public Resource //oic.r.switch.binary
             }
             else
             {
-                std::cout << "Request invalid" << std::endl;
+                cout << "Request invalid" << endl;
             }
 
             return ehResult;
@@ -262,7 +262,7 @@ class TemperatureResource : public Resource //oic.r.temperature
             }
         }
 
-        OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request)
+        OCEntityHandlerResult entityHandler(shared_ptr<OCResourceRequest> request)
         {
             cout << "\tIn Server Temperature entity handler:\n";
             OCEntityHandlerResult ehResult = OC_EH_ERROR;
@@ -270,7 +270,7 @@ class TemperatureResource : public Resource //oic.r.temperature
             if (request)
             {
                 // Get the request type and request flag
-                std::string requestType = request->getRequestType();
+                string requestType = request->getRequestType();
                 int requestFlag = request->getRequestHandlerFlag();
 
                 if (requestFlag & RequestHandlerFlag::RequestFlag)
@@ -321,7 +321,7 @@ class TemperatureResource : public Resource //oic.r.temperature
                     }
                     else if (ObserveAction::ObserveUnregister == observationInfo.action)
                     {
-                        m_interestedObservers.erase(std::remove(
+                        m_interestedObservers.erase(remove(
                                                         m_interestedObservers.begin(),
                                                         m_interestedObservers.end(),
                                                         observationInfo.obsId),
@@ -331,7 +331,7 @@ class TemperatureResource : public Resource //oic.r.temperature
             }
             else
             {
-                std::cout << "Request invalid" << std::endl;
+                cout << "Request invalid" << endl;
             }
 
             return ehResult;
@@ -349,7 +349,7 @@ class AirConditionerResource : public Resource // oic.d.airconditioner
 
         }
 
-        OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request)
+        OCEntityHandlerResult entityHandler(shared_ptr<OCResourceRequest> request)
         {
             cout << "\tIn Server Airconditioner entity handler:\n";
             OCEntityHandlerResult ehResult = OC_EH_ERROR;
@@ -357,7 +357,7 @@ class AirConditionerResource : public Resource // oic.d.airconditioner
             if (request)
             {
                 // Get the request type and request flag
-                std::string requestType = request->getRequestType();
+                string requestType = request->getRequestType();
                 int requestFlag = request->getRequestHandlerFlag();
 
                 if (requestFlag & RequestHandlerFlag::RequestFlag)
@@ -417,20 +417,20 @@ class AirConditionerResource : public Resource // oic.d.airconditioner
             }
             else
             {
-                std::cout << "Request invalid" << std::endl;
+                cout << "Request invalid" << endl;
             }
 
             return ehResult;
         }
 };
 
-std::condition_variable g_callbackLock;
-std::string             g_uid;
-std::string             g_accesstoken;
+condition_variable g_callbackLock;
+string             g_uid;
+string             g_accesstoken;
 
 void onPublish(const OCRepresentation &, const int &eCode)
 {
-    std::cout << "Publish resource response received, code: " << eCode << std::endl;
+    cout << "Publish resource response received, code: " << eCode << endl;
 
     g_callbackLock.notify_all();
 }
@@ -440,6 +440,40 @@ void printRepresentation(OCRepresentation rep)
     for (auto itr = rep.begin(); itr != rep.end(); ++itr)
     {
         cout << "\t" << itr->attrname() << ":\t" << itr->getValueToString() << endl;
+        if (itr->type() == AttributeType::Vector)
+        {
+            switch (itr->base_type())
+            {
+                case AttributeType::OCRepresentation:
+                    for (auto itr2 : (*itr).getValue<vector<OCRepresentation> >())
+                    {
+                        printRepresentation(itr2);
+                    }
+                    break;
+
+                case AttributeType::Integer:
+                    for (auto itr2 : (*itr).getValue<vector<int> >())
+                    {
+                        cout << "\t\t" << itr2 << endl;
+                    }
+                    break;
+
+                case AttributeType::String:
+                    for (auto itr2 : (*itr).getValue<vector<string> >())
+                    {
+                        cout << "\t\t" << itr2 << endl;
+                    }
+                    break;
+
+                default:
+                    cout << "Unhandled base type " << itr->base_type() << endl;
+                    break;
+            }
+        }
+        else if (itr->type() == AttributeType::OCRepresentation)
+        {
+            printRepresentation((*itr).getValue<OCRepresentation>());
+        }
     }
 }
 
@@ -502,7 +536,7 @@ int main(int argc, char *argv[])
                                        CT_ADAPTER_TCP);
 
     mutex blocker;
-    unique_lock<std::mutex> lock(blocker);
+    unique_lock<mutex> lock(blocker);
 
     if (argc == 5)
     {
@@ -534,8 +568,8 @@ int main(int argc, char *argv[])
                                           uri,
                                           rt,
                                           itf,
-                                          std::bind(&AirConditionerResource::entityHandler
-                                                  , &airConditioner, std::placeholders::_1),
+                                          bind(&AirConditionerResource::entityHandler
+                                                  , &airConditioner, placeholders::_1),
                                           OC_DISCOVERABLE);
 
     if (result != OC_STACK_OK)
@@ -570,8 +604,8 @@ int main(int argc, char *argv[])
                                           uri,
                                           rt,
                                           itf,
-                                          std::bind(&BinarySwitchResource::entityHandler
-                                                  , &binarySwitch, std::placeholders::_1),
+                                          bind(&BinarySwitchResource::entityHandler
+                                                  , &binarySwitch, placeholders::_1),
                                           OC_OBSERVABLE);
 
     uri = temperature.getResourceUri();
@@ -582,8 +616,8 @@ int main(int argc, char *argv[])
                                           uri,
                                           rt,
                                           itf,
-                                          std::bind(&TemperatureResource::entityHandler
-                                                  , &temperature, std::placeholders::_1),
+                                          bind(&TemperatureResource::entityHandler
+                                                  , &temperature, placeholders::_1),
                                           OC_OBSERVABLE);
 
     result = airConditioner.addChildResource(&binarySwitch);
index 2aaae0f82bbdbe3e64328c37a4be827f5bc2c019..2ae86a41ce2e5d2389504d881f10527a15a439c6 100644 (file)
@@ -20,8 +20,8 @@ using namespace std;
 
 
 condition_variable  g_callbackLock;
-std::string         g_uid;
-std::string         g_accesstoken;
+string         g_uid;
+string         g_accesstoken;
 
 string              g_host;
 OC::OCResource::Ptr g_binaryswitchResource;
@@ -31,6 +31,40 @@ void printRepresentation(OCRepresentation rep)
     for (auto itr = rep.begin(); itr != rep.end(); ++itr)
     {
         cout << "\t" << itr->attrname() << ":\t" << itr->getValueToString() << endl;
+        if (itr->type() == AttributeType::Vector)
+        {
+            switch (itr->base_type())
+            {
+                case AttributeType::OCRepresentation:
+                    for (auto itr2 : (*itr).getValue<vector<OCRepresentation> >())
+                    {
+                        printRepresentation(itr2);
+                    }
+                    break;
+
+                case AttributeType::Integer:
+                    for (auto itr2 : (*itr).getValue<vector<int> >())
+                    {
+                        cout << "\t\t" << itr2 << endl;
+                    }
+                    break;
+
+                case AttributeType::String:
+                    for (auto itr2 : (*itr).getValue<vector<string> >())
+                    {
+                        cout << "\t\t" << itr2 << endl;
+                    }
+                    break;
+
+                default:
+                    cout << "Unhandled base type " << itr->base_type() << endl;
+                    break;
+            }
+        }
+        else if (itr->type() == AttributeType::OCRepresentation)
+        {
+            printRepresentation((*itr).getValue<OCRepresentation>());
+        }
     }
 }
 
@@ -92,13 +126,13 @@ void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation &re
             }
 
             cout << "OBSERVE RESULT:" << endl;
-            printResource(rep);
+            printRepresentation(rep);
         }
         else
         {
             if (eCode == OC_STACK_OK)
             {
-                std::cout << "Observe registration failed or de-registration action failed/succeeded" << std::endl;
+                cout << "Observe registration failed or de-registration action failed/succeeded" << endl;
             }
             else
             {
@@ -113,11 +147,11 @@ void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation &re
     }
 }
 
-void onPut(const HeaderOptions & /*headerOptions*/, const OCRepresentation &rep, const int eCode)
+void onPost(const HeaderOptions & /*headerOptions*/, const OCRepresentation &rep, const int eCode)
 {
-    cout << "PUT response: " << eCode << endl;
+    cout << "POST response: " << eCode << endl;
 
-    printResource(rep);
+    printRepresentation(rep);
 }
 
 void turnOnOffSwitch(bool toTurn)
@@ -126,7 +160,8 @@ void turnOnOffSwitch(bool toTurn)
     binarySwitch.setValue("value", toTurn);
 
     QueryParamsMap      query;
-    g_binaryswitchResource->post("oic.r.switch.binary", DEFAULT_INTERFACE, binarySwitch, query, &onPut);
+    g_binaryswitchResource->post("oic.r.switch.binary", DEFAULT_INTERFACE, binarySwitch, query,
+                                 &onPost);
 }
 
 void getCollectionResource(const HeaderOptions &,
@@ -215,7 +250,7 @@ void foundDevice(shared_ptr<OC::OCResource> resource)
     }
 }
 
-void presenceDevice(OCStackResult , const unsigned int i, const std::string &str)
+void presenceDevice(OCStackResult , const unsigned int i, const string &str)
 {
     cout << "Presence received, i=" << i << " str=" << str << endl;
 }
@@ -260,7 +295,7 @@ int main(int argc, char *argv[])
 
 
     mutex blocker;
-    unique_lock<std::mutex> lock(blocker);
+    unique_lock<mutex> lock(blocker);
 
     if (argc == 5)
     {
index c8360233fa90f781bb05e776e8c6fd2b588ceae8..22379efabf3d85c09948d464268ae5c4cfc671a5 100644 (file)
@@ -44,36 +44,40 @@ void printRepresentation(OCRepresentation rep)
     for (auto itr = rep.begin(); itr != rep.end(); ++itr)
     {
         cout << "\t" << itr->attrname() << ":\t" << itr->getValueToString() << endl;
-    }
-}
-
-void onSearchUser(const HeaderOptions & /*headerOptions*/,
-                  const OCRepresentation &rep, const int eCode)
-{
-    if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
-    {
-        cout << "\tSearchUser request was successful" << endl;
-
-        std::vector<OCRepresentation> userList = rep.getValue<std::vector<OCRepresentation>>("ulist");
-
-        for (auto user : userList)
+        if (itr->type() == AttributeType::Vector)
         {
-            // Mandatory field
-            cout << "\tuid: " << user.getValue<string>("uid") << endl;
-
-            // Optional field
-            cout << "\tuinfo: " << endl;
-            OCRepresentation uinfo = user.getValue<OCRepresentation>("uinfo");
-            for (auto itr = uinfo.begin(); itr != uinfo.end(); ++itr)
+            switch (itr->base_type())
             {
-                cout << "\t\t" << itr->attrname() << ":\t" << itr->getValueToString() << endl;
+                case AttributeType::OCRepresentation:
+                    for (auto itr2 : (*itr).getValue<vector<OCRepresentation> >())
+                    {
+                        printRepresentation(itr2);
+                    }
+                    break;
+
+                case AttributeType::Integer:
+                    for (auto itr2 : (*itr).getValue<vector<int> >())
+                    {
+                        cout << "\t\t" << itr2 << endl;
+                    }
+                    break;
+
+                case AttributeType::String:
+                    for (auto itr2 : (*itr).getValue<vector<string> >())
+                    {
+                        cout << "\t\t" << itr2 << endl;
+                    }
+                    break;
+
+                default:
+                    cout << "Unhandled base type " << itr->base_type() << endl;
+                    break;
             }
-            cout << endl;
         }
-    }
-    else
-    {
-        cout << "\tSearchUser Response error: " << eCode << endl;
+        else if (itr->type() == AttributeType::OCRepresentation)
+        {
+            printRepresentation((*itr).getValue<OCRepresentation>());
+        }
     }
 }
 
@@ -83,13 +87,13 @@ void ocPost(const HeaderOptions & /*headerOptions*/,
 {
     if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
     {
-        std::cout << "\tRequest was successful: " << eCode << std::endl;
+        cout << "\tRequest was successful: " << eCode << endl;
 
         printRepresentation(rep);
     }
     else
     {
-        std::cout << "\tResponse error: " << eCode << std::endl;
+        cout << "\tResponse error: " << eCode << endl;
     }
 }
 
@@ -112,7 +116,7 @@ void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation &re
         {
             if (eCode == OC_STACK_OK)
             {
-                std::cout << "Observe registration failed or de-registration action failed/succeeded" << std::endl;
+                cout << "Observe registration failed or de-registration action failed/succeeded" << endl;
             }
             else
             {
@@ -140,9 +144,9 @@ void onDelete(const HeaderOptions & /*headerOptions*/,
     }
 }
 
-std::condition_variable g_callbackLock;
-std::string             g_uid;
-std::string             g_accesstoken;
+condition_variable g_callbackLock;
+string             g_uid;
+string             g_accesstoken;
 
 void handleLoginoutCB(const HeaderOptions &,
                       const OCRepresentation &rep, const int ecode)
@@ -195,7 +199,7 @@ int main(int argc, char *argv[])
                                        CT_ADAPTER_TCP);
 
     mutex blocker;
-    unique_lock<std::mutex> lock(blocker);
+    unique_lock<mutex> lock(blocker);
 
     if (argc == 5)
     {
@@ -211,24 +215,26 @@ int main(int argc, char *argv[])
     }
 
     cout << "---Group & Invite sample---" << endl;
-    cout << "     1 - searchUser" << endl;
-    cout << "     2 - deleteDevice" << endl;
-    cout << "     3 - createGroup" << endl;
-    cout << "     4 - observeGroup" << endl;
-    cout << "     5 - getGroupList" << endl;
-    cout << "     6 - deleteGroup" << endl;
-    cout << "     7 - joinGroup" << endl;
-    cout << "     8 - addDeviceToGroup" << endl;
-    cout << "     9 - getGroupInfo" << endl;
-    cout << "    10 - leaveGroup" << endl;
-    cout << "    11 - deleteDeviceFromGroup" << endl;
-    cout << "    12 - observeInvitation" << endl;
-    cout << "    13 - sendInvitation" << endl;
-    cout << "    14 - cancelInvitation" << endl;
-    cout << "    15 - deleteInvitation" << endl;
-    cout << "    16 - cancelObserveGroup" << endl;
-    cout << "    17 - cancelObserveInvitation" << endl;
-    cout << "    18 - exit" << endl;
+    cout << "     1 - searchUser using user UUID" << endl;
+    cout << "     2 - searchUser using email" << endl;
+    cout << "     3 - searchUser using phone" << endl;
+    cout << "     4 - deleteDevice" << endl;
+    cout << "     5 - createGroup" << endl;
+    cout << "     6 - observeGroup" << endl;
+    cout << "     7 - getGroupList" << endl;
+    cout << "     8 - deleteGroup" << endl;
+    cout << "     9 - joinGroup" << endl;
+    cout << "    10 - addDeviceToGroup" << endl;
+    cout << "    11 - getGroupInfo" << endl;
+    cout << "    12 - leaveGroup" << endl;
+    cout << "    13 - deleteDeviceFromGroup" << endl;
+    cout << "    14 - observeInvitation" << endl;
+    cout << "    15 - sendInvitation" << endl;
+    cout << "    16 - cancelInvitation" << endl;
+    cout << "    17 - deleteInvitation" << endl;
+    cout << "    18 - cancelObserveGroup" << endl;
+    cout << "    19 - cancelObserveInvitation" << endl;
+    cout << "    20 - exit" << endl;
 
     string cmd;
     string cmd2;
@@ -245,82 +251,96 @@ int main(int argc, char *argv[])
             case 1:
                 cout << "Put userUUID to search:" << endl;
                 cin >> cmd;
-                result = accountMgr->searchUser(cmd, &onSearchUser);
+                result = accountMgr->searchUser(cmd, &ocPost);
                 break;
 
             case 2:
+                cout << "Put email to search:" << endl;
+                cin >> cmd;
+                query["email"] = cmd;
+                result = accountMgr->searchUser(query, &ocPost);
+                break;
+
+            case 3:
+                cout << "Put phone number to search:" << endl;
+                cin >> cmd;
+                query["phone"] = cmd;
+                result = accountMgr->searchUser(query, &ocPost);
+                break;
+
+            case 4:
                 cout << "PUT deviceID to delete:";
                 cin >> cmd;
                 result = accountMgr->deleteDevice(cmd, &onDelete);
                 break;
 
-            case 3:
+            case 5:
                 result = accountMgr->createGroup(OC::AclGroupType::PUBLIC, &ocPost);
                 break;
 
-            case 4:
+            case 6:
                 cout << "PUT groupId to observe:";
                 cin >> cmd;
                 result = accountMgr->observeGroup(cmd, &onObserve);
                 break;
 
-            case 5:
+            case 7:
                 result = accountMgr->getGroupList(&ocPost);
                 break;
 
-            case 6:
+            case 8:
                 cout << "PUT groupId to delete:";
                 cin >> cmd;
                 result = accountMgr->deleteGroup(cmd, &onDelete);
                 break;
 
-            case 7:
+            case 9:
                 cout << "PUT groupId to join:";
                 cin >> cmd;
                 result = accountMgr->joinGroup(cmd, &ocPost);
                 break;
 
-            case 8:
+            case 10:
                 cout << "PUT groupId to add device:";
                 cin >> cmd;
                 cout << "PUT deviceId to add to group:";
                 cin >> cmd2;
                 {
-                    std::vector<std::string> deviceIds;
+                    vector<string> deviceIds;
                     deviceIds.push_back(cmd2);
                     result = accountMgr->addDeviceToGroup(cmd, deviceIds, &ocPost);
                 }
                 break;
 
-            case 9:
+            case 11:
                 cout << "PUT groupId to get info:";
                 cin >> cmd;
                 result = accountMgr->getGroupInfo(cmd, &ocPost);
                 break;
 
-            case 10:
+            case 12:
                 cout << "PUT groupId to leave:";
                 cin >> cmd;
                 result = accountMgr->leaveGroup(cmd, &onDelete);
                 break;
 
-            case 11:
+            case 13:
                 cout << "PUT groupId to remove device:";
                 cin >> cmd;
                 cout << "PUT deviceId to remove from group:";
                 cin >> cmd2;
                 {
-                    std::vector<std::string> deviceIds;
+                    vector<string> deviceIds;
                     deviceIds.push_back(cmd2);
                     result = accountMgr->deleteDeviceFromGroup(cmd, deviceIds, &onDelete);
                 }
                 break;
 
-            case 12:
+            case 14:
                 result = accountMgr->observeInvitation(&onObserve);
                 break;
 
-            case 13:
+            case 15:
                 cout << "PUT groupId to invite:";
                 cin >> cmd;
                 cout << "PUT userUUID to invite:";
@@ -328,7 +348,7 @@ int main(int argc, char *argv[])
                 result = accountMgr->sendInvitation(cmd, cmd2, &ocPost);
                 break;
 
-            case 14:
+            case 16:
                 cout << "PUT groupId to cancel invitation:";
                 cin >> cmd;
                 cout << "PUT userUUID to cancel invitation:";
@@ -336,24 +356,23 @@ int main(int argc, char *argv[])
                 result = accountMgr->cancelInvitation(cmd, cmd2, &onDelete);
                 break;
 
-            case 15:
+            case 17:
                 cout << "PUT groupId to delete invitation:";
                 cin >> cmd;
                 result = accountMgr->deleteInvitation(cmd, &onDelete);
                 break;
 
-            case 16:
+            case 18:
                 cout << "PUT groupId to cancel observe:";
                 cin >> cmd;
                 result = accountMgr->cancelObserveGroup(cmd);
                 break;
 
-            case 17:
+            case 19:
                 result = accountMgr->cancelObserveInvitation();
                 break;
 
-            //113 is q
-            case 18:
+            case 20:
                 goto exit;
                 break;
         }
index dbb558ff01203908565f6b1c7cda9e5f8cd8f43c..f04e037afc09533b16a62620af9cd75c621e7341 100644 (file)
@@ -52,32 +52,66 @@ void printRepresentation(OCRepresentation rep)
     for (auto itr = rep.begin(); itr != rep.end(); ++itr)
     {
         cout << "\t" << itr->attrname() << ":\t" << itr->getValueToString() << endl;
+        if (itr->type() == AttributeType::Vector)
+        {
+            switch (itr->base_type())
+            {
+                case AttributeType::OCRepresentation:
+                    for (auto itr2 : (*itr).getValue<vector<OCRepresentation> >())
+                    {
+                        printRepresentation(itr2);
+                    }
+                    break;
+
+                case AttributeType::Integer:
+                    for (auto itr2 : (*itr).getValue<vector<int> >())
+                    {
+                        cout << "\t\t" << itr2 << endl;
+                    }
+                    break;
+
+                case AttributeType::String:
+                    for (auto itr2 : (*itr).getValue<vector<string> >())
+                    {
+                        cout << "\t\t" << itr2 << endl;
+                    }
+                    break;
+
+                default:
+                    cout << "Unhandled base type " << itr->base_type() << endl;
+                    break;
+            }
+        }
+        else if (itr->type() == AttributeType::OCRepresentation)
+        {
+            printRepresentation((*itr).getValue<OCRepresentation>());
+        }
     }
 }
 
 ////////////////////////////////////////Publisher Sample
 
-void createTopicCB(const int ecode, const std::string &originUri,
-                   std::shared_ptr<OC::OCResource> topic)
+void createTopicCB(const int ecode, const string &originUri,
+                   shared_ptr<OC::OCResource> topic)
 {
-    std::cout << "Create topic response received, code: " << ecode << std::endl;
+    cout << "Create topic response received, code: " << ecode << endl;
 
     if (ecode == OCStackResult::OC_STACK_RESOURCE_CREATED)
     {
-        std::cout << "Created topic : " << topic->uri() << std::endl;
+        cout << "Created topic : " << topic->uri() << endl;
     }
     else
     {
-        std::cout << "Topic creation failed : " << originUri << std::endl;
+        cout << "Topic creation failed : " << originUri << endl;
     }
 }
 
 void publishMessageCB(const HeaderOptions &, const OCRepresentation &, const int eCode)
 {
-    std::cout << "Publish message response received, code: " << eCode << std::endl;
+    cout << "Publish message response received, code: " << eCode << endl;
 }
 
-void discoverTopicCB(const int ecode, const std::string &, std::shared_ptr<OC::OCResource> topic)
+void discoverTopicCB(const int ecode, const string &, shared_ptr<OC::OCResource> topic)
 {
     cout << "Topic discovered code: " << ecode << endl;
     gTopicList.push_back(topic);
@@ -85,9 +119,9 @@ void discoverTopicCB(const int ecode, const std::string &, std::shared_ptr<OC::O
 }
 ////////////////////////////////////////End of Publisher Sample
 
-std::condition_variable g_callbackLock;
-std::string             g_uid;
-std::string             g_accesstoken;
+condition_variable g_callbackLock;
+string             g_uid;
+string             g_accesstoken;
 
 void handleLoginoutCB(const HeaderOptions &,
                       const OCRepresentation &rep, const int ecode)
@@ -148,7 +182,7 @@ int main(int argc, char *argv[])
                                        CT_ADAPTER_TCP);
 
     mutex blocker;
-    unique_lock<std::mutex> lock(blocker);
+    unique_lock<mutex> lock(blocker);
 
     if (argc == 5)
     {
index 78d07edb5195852ede45b5510569fa858e68760b..efc4eac79d1063ed82e8da56289886c1344c16da 100644 (file)
@@ -53,6 +53,40 @@ void printRepresentation(OCRepresentation rep)
     for (auto itr = rep.begin(); itr != rep.end(); ++itr)
     {
         cout << "\t" << itr->attrname() << ":\t" << itr->getValueToString() << endl;
+        if (itr->type() == AttributeType::Vector)
+        {
+            switch (itr->base_type())
+            {
+                case AttributeType::OCRepresentation:
+                    for (auto itr2 : (*itr).getValue<vector<OCRepresentation> >())
+                    {
+                        printRepresentation(itr2);
+                    }
+                    break;
+
+                case AttributeType::Integer:
+                    for (auto itr2 : (*itr).getValue<vector<int> >())
+                    {
+                        cout << "\t\t" << itr2 << endl;
+                    }
+                    break;
+
+                case AttributeType::String:
+                    for (auto itr2 : (*itr).getValue<vector<string> >())
+                    {
+                        cout << "\t\t" << itr2 << endl;
+                    }
+                    break;
+
+                default:
+                    cout << "Unhandled base type " << itr->base_type() << endl;
+                    break;
+            }
+        }
+        else if (itr->type() == AttributeType::OCRepresentation)
+        {
+            printRepresentation((*itr).getValue<OCRepresentation>());
+        }
     }
 }
 
@@ -76,7 +110,7 @@ void subscribeCB(const HeaderOptions &,
         {
             if (eCode == OC_STACK_OK)
             {
-                std::cout << "Observe registration failed or de-registration action failed/succeeded" << std::endl;
+                cout << "Observe registration failed or de-registration action failed/succeeded" << endl;
             }
             else
             {
@@ -91,8 +125,8 @@ void subscribeCB(const HeaderOptions &,
     }
 }
 
-void discoverTopicCB(const int ecode, const std::string &brokerUri,
-                     std::shared_ptr<OC::OCResource> topic)
+void discoverTopicCB(const int ecode, const string &brokerUri,
+                     shared_ptr<OC::OCResource> topic)
 {
     cout << "Topic discovered from " << brokerUri << " code: " << ecode << endl;
     gTopicList.push_back(topic);
@@ -101,8 +135,8 @@ void discoverTopicCB(const int ecode, const std::string &brokerUri,
 ////////////////////////////////////////Subscriber Sample
 
 condition_variable  g_callbackLock;
-std::string             g_uid;
-std::string             g_accesstoken;
+string             g_uid;
+string             g_accesstoken;
 
 void handleLoginoutCB(const HeaderOptions &,
                       const OCRepresentation &rep, const int ecode)
@@ -163,7 +197,7 @@ int main(int argc, char *argv[])
                                        CT_ADAPTER_TCP);
 
     mutex blocker;
-    unique_lock<std::mutex> lock(blocker);
+    unique_lock<mutex> lock(blocker);
 
     if (argc == 5)
     {
index 33b690a2a331bc1136ddacb75e25741c98a90b80..2680aba525c76605564f36879856e421b1e3926d 100644 (file)
@@ -35,6 +35,8 @@
 #include "ocpayload.h"
 #include "oicresourcedirectory.h"
 
+using namespace std;
+
 #define DEFAULT_CONTEXT_VALUE 0x99
 #define DEFAULT_AUTH_SIGNUP "/oic/account"
 #define DEFAULT_AUTH_SESSION "/oic/account/session"
@@ -176,7 +178,7 @@ OCRepPayload *responsePayload(int64_t power, bool state)
     OCRepPayload *payload = OCRepPayloadCreate();
     if (!payload)
     {
-        std::cout << "Failed to allocate Payload" << std::endl;
+        cout << "Failed to allocate Payload" << endl;
         return nullptr;
     }
 
@@ -190,7 +192,7 @@ OCRepPayload *constructResponse(OCEntityHandlerRequest *ehRequest)
 {
     if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
     {
-        std::cout << "Incoming payload not a representation" << std::endl;
+        cout << "Incoming payload not a representation" << endl;
         return nullptr;
     }
 
@@ -232,7 +234,7 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest,
     OCRepPayload *getResp = constructResponse(ehRequest);
     if (!getResp)
     {
-        std::cout << "constructResponse failed" << std::endl;
+        cout << "constructResponse failed" << endl;
         return OC_EH_ERROR;
     }
 
@@ -249,7 +251,7 @@ OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest,
 
     if (!putResp)
     {
-        std::cout << "Failed to construct Json response" << std::endl;
+        cout << "Failed to construct Json response" << endl;
         return OC_EH_ERROR;
     }
 
@@ -284,13 +286,13 @@ void *ChangeLightRepresentation(void *param)
 
         if (gLightUnderObservation)
         {
-            std::cout << " =====> Notifying stack of new power level " << gLightInstance[0].power << std::endl;
-            std::cout << " =====> Notifying stack of new power level " << gLightInstance[1].power << std::endl;
+            cout << " =====> Notifying stack of new power level " << gLightInstance[0].power << endl;
+            cout << " =====> Notifying stack of new power level " << gLightInstance[1].power << endl;
             // Notifying all observers
             result = OCNotifyAllObservers(gLightInstance[0].handle, OC_NA_QOS);
             result = OCNotifyAllObservers(gLightInstance[1].handle, OC_NA_QOS);
 
-            std::cout << " =====> Notifying result " << result << std::endl;
+            cout << " =====> Notifying result " << result << endl;
         }
     }
     return NULL;
@@ -298,8 +300,8 @@ void *ChangeLightRepresentation(void *param)
 
 void ProcessObserveRegister(OCEntityHandlerRequest *ehRequest)
 {
-    std::cout << "Received observation registration request with observation Id " <<
-              ehRequest->obsInfo.obsId << std::endl;
+    cout << "Received observation registration request with observation Id " <<
+         ehRequest->obsInfo.obsId << endl;
 
     if (!observeThreadStarted)
     {
@@ -322,8 +324,8 @@ void ProcessObserveDeregister(OCEntityHandlerRequest *ehRequest)
 {
     bool clientStillObserving = false;
 
-    std::cout << "Received observation deregistration request for observation Id " <<
-              ehRequest->obsInfo.obsId << std::endl;
+    cout << "Received observation deregistration request for observation Id " <<
+         ehRequest->obsInfo.obsId << endl;
     for (uint8_t i = 0; i < SAMPLE_MAX_NUM_OBSERVATIONS; i++)
     {
         if (interestedObservers[i].observationId == ehRequest->obsInfo.obsId)
@@ -350,7 +352,7 @@ OCEntityHandlerCb(OCEntityHandlerFlag flag,
     // Validate pointer
     if (!entityHandlerRequest)
     {
-        std::cout << "Invalid request pointer" << std::endl;
+        cout << "Invalid request pointer" << endl;
         return OC_EH_ERROR;
     }
 
@@ -363,22 +365,22 @@ OCEntityHandlerCb(OCEntityHandlerFlag flag,
 
     if (flag & OC_REQUEST_FLAG)
     {
-        std::cout << "Flag includes OC_REQUEST_FLAG" << std::endl;
+        cout << "Flag includes OC_REQUEST_FLAG" << endl;
 
         if (OC_REST_GET == entityHandlerRequest->method)
         {
-            std::cout << "Received OC_REST_GET from client" << std::endl;
+            cout << "Received OC_REST_GET from client" << endl;
             ehResult = ProcessGetRequest(entityHandlerRequest, &payload);
         }
         else if (OC_REST_PUT == entityHandlerRequest->method)
         {
-            std::cout << "Received OC_REST_PUT from client" << std::endl;
+            cout << "Received OC_REST_PUT from client" << endl;
             ehResult = ProcessPutRequest(entityHandlerRequest, &payload);
         }
         else
         {
-            std::cout << "Received unsupported method %d from client " << entityHandlerRequest->method <<
-                      std::endl;
+            cout << "Received unsupported method %d from client " << entityHandlerRequest->method <<
+                 endl;
             ehResult = OC_EH_ERROR;
         }
         // If the result isn't an error or forbidden, send response
@@ -395,7 +397,7 @@ OCEntityHandlerCb(OCEntityHandlerFlag flag,
             // Send the response
             if (OCDoResponse(&response) != OC_STACK_OK)
             {
-                std::cout << "Error sending response" << std::endl;
+                cout << "Error sending response" << endl;
                 ehResult = OC_EH_ERROR;
             }
         }
@@ -403,15 +405,15 @@ OCEntityHandlerCb(OCEntityHandlerFlag flag,
 
     if (flag & OC_OBSERVE_FLAG)
     {
-        std::cout << "Flag includes OC_OBSERVE_FLAG" << std::endl;
+        cout << "Flag includes OC_OBSERVE_FLAG" << endl;
         if (OC_OBSERVE_REGISTER == entityHandlerRequest->obsInfo.action)
         {
-            std::cout << "Received OC_OBSERVE_REGISTER from client" << std::endl;
+            cout << "Received OC_OBSERVE_REGISTER from client" << endl;
             ProcessObserveRegister(entityHandlerRequest);
         }
         else if (OC_OBSERVE_DEREGISTER == entityHandlerRequest->obsInfo.action)
         {
-            std::cout << "Received OC_OBSERVE_DEREGISTER from client" << std::endl;
+            cout << "Received OC_OBSERVE_DEREGISTER from client" << endl;
             ProcessObserveDeregister(entityHandlerRequest);
         }
     }
@@ -424,7 +426,7 @@ int createLightResource(char *uri, LightResource *lightResource)
 {
     if (!uri)
     {
-        std::cout << "Resource URI cannot be NULL" << std::endl;
+        cout << "Resource URI cannot be NULL" << endl;
         return -1;
     }
 
@@ -437,7 +439,7 @@ int createLightResource(char *uri, LightResource *lightResource)
                                          OCEntityHandlerCb,
                                          NULL,
                                          OC_DISCOVERABLE | OC_OBSERVABLE);
-    std::cout << "Created Light resource with result:" << res << std::endl;
+    cout << "Created Light resource with result:" << res << endl;
 
     return res;
 }
@@ -448,21 +450,21 @@ OCStackApplicationResult handlePublishCB(void *ctx,
 {
     if (ctx != (void *)DEFAULT_CONTEXT_VALUE)
     {
-        std::cout << "Invalid Publish callback received" << std::endl;
+        cout << "Invalid Publish callback received" << endl;
     }
 
-    std::cout << "Publish resource response received, code: " << clientResponse->result << std::endl;
+    cout << "Publish resource response received, code: " << clientResponse->result << endl;
 
     return OC_STACK_KEEP_TRANSACTION;
 }
 
-void PublishResources(std::string host)
+void PublishResources(string host)
 {
-    std::cout << "Publishing resources..." << std::endl;
+    cout << "Publishing resources..." << endl;
 
     if (createLightResource((char *)"/a/light/0", &gLightInstance[0]) != 0)
     {
-        std::cout << "Unable to create sample resource" << std::endl;
+        cout << "Unable to create sample resource" << endl;
     }
 
     OCResourceHandle    resourceHandles[1] = { gLightInstance[0].handle,
@@ -472,7 +474,7 @@ void PublishResources(std::string host)
     cbData.context = (void *)DEFAULT_CONTEXT_VALUE;
     cbData.cd = NULL;
 
-    std::cout << "Publish default resources" << std::endl;
+    cout << "Publish default resources" << endl;
 
     OCDeviceInfo        devInfoRoomLight;
     OCStringLL          deviceType;
@@ -488,23 +490,23 @@ void PublishResources(std::string host)
 
     if (res != OC_STACK_OK)
     {
-        std::cout << "Setting device info failed" << std::endl;
+        cout << "Setting device info failed" << endl;
     }
 
     res = OCRDPublish(host.c_str(), CT_ADAPTER_TCP, NULL, 0, &cbData,
                       OC_LOW_QOS);
     if (res != OC_STACK_OK)
     {
-        std::cout << "Unable to publish default resources to cloud" << std::endl;
+        cout << "Unable to publish default resources to cloud" << endl;
     }
 
-    std::cout << "Publish user resources" << std::endl;
+    cout << "Publish user resources" << endl;
 
     res = OCRDPublish(host.c_str(), CT_ADAPTER_TCP, resourceHandles, 1, &cbData,
                       OC_LOW_QOS);
     if (res != OC_STACK_OK)
     {
-        std::cout << "Unable to publish user resources to cloud" << std::endl;
+        cout << "Unable to publish user resources to cloud" << endl;
     }
 }
 
@@ -513,39 +515,39 @@ void printRepresentation(OCRepPayloadValue *value)
 {
     while (value)
     {
-        std::cout << "Key: " << value->name;
+        cout << "Key: " << value->name;
         switch (value->type)
         {
             case OCREP_PROP_NULL:
-                std::cout << " Value: None" << std::endl;
+                cout << " Value: None" << endl;
                 break;
             case OCREP_PROP_INT:
-                std::cout << " Value: " << value->i << std::endl;
+                cout << " Value: " << value->i << endl;
                 break;
             case OCREP_PROP_DOUBLE:
-                std::cout << " Value: " << value->d << std::endl;
+                cout << " Value: " << value->d << endl;
                 break;
             case OCREP_PROP_BOOL:
-                std::cout << " Value: " << value->b << std::endl;
+                cout << " Value: " << value->b << endl;
                 break;
             case OCREP_PROP_STRING:
-                std::cout << " Value: " << value->str << std::endl;
+                cout << " Value: " << value->str << endl;
                 break;
             case OCREP_PROP_BYTE_STRING:
-                std::cout << " Value: Byte String" << std::endl;
+                cout << " Value: Byte String" << endl;
                 break;
             case OCREP_PROP_OBJECT:
-                std::cout << " Value: Object" << std::endl;
+                cout << " Value: Object" << endl;
                 break;
             case OCREP_PROP_ARRAY:
-                std::cout << " Value: Array" << std::endl;
+                cout << " Value: Array" << endl;
                 break;
         }
         value = value->next;
     }
 }
 
-std::string g_host = "coap+tcp://";
+string g_host = "coap+tcp://";
 
 OCStackApplicationResult handleLoginoutCB(void *ctx,
         OCDoHandle /*handle*/,
@@ -553,15 +555,15 @@ OCStackApplicationResult handleLoginoutCB(void *ctx,
 {
     if (ctx != (void *)DEFAULT_CONTEXT_VALUE)
     {
-        std::cout << "Invalid Login/out callback received" << std::endl;
+        cout << "Invalid Login/out callback received" << endl;
     }
 
-    std::cout << "Login/out response received code: " << clientResponse->result << std::endl;
+    cout << "Login/out response received code: " << clientResponse->result << endl;
 
     if (clientResponse->payload != NULL &&
         clientResponse->payload->type == PAYLOAD_TYPE_REPRESENTATION)
     {
-        std::cout << "PAYLOAD_TYPE_REPRESENTATION received" << std::endl;
+        cout << "PAYLOAD_TYPE_REPRESENTATION received" << endl;
 
         OCRepPayloadValue *val = ((OCRepPayload *)clientResponse->payload)->values;
 
@@ -582,17 +584,17 @@ OCStackApplicationResult handleRegisterCB(void *ctx,
 {
     if (ctx != (void *)DEFAULT_CONTEXT_VALUE)
     {
-        std::cout << "Invalid Register callback received" << std::endl;
+        cout << "Invalid Register callback received" << endl;
     }
 
-    std::cout << "Register response received code: " << clientResponse->result << std::endl;
+    cout << "Register response received code: " << clientResponse->result << endl;
 
     if (clientResponse->payload != NULL &&
         clientResponse->payload->type == PAYLOAD_TYPE_REPRESENTATION)
     {
-        std::cout << "PAYLOAD_TYPE_REPRESENTATION received" << std::endl;
-        std::cout << "You can Sign-In using retrieved accesstoken when disconnected or reboot" <<
-                  std::endl;
+        cout << "PAYLOAD_TYPE_REPRESENTATION received" << endl;
+        cout << "You can Sign-In using retrieved accesstoken when disconnected or reboot" <<
+             endl;
 
         OCRepPayloadValue *val = ((OCRepPayload *)clientResponse->payload)->values;
 
@@ -604,15 +606,15 @@ OCStackApplicationResult handleRegisterCB(void *ctx,
 
 void PrintUsage()
 {
-    std::cout << std::endl;
-    std::cout << "Usage : thin_cloud_device <addr:port> <uid> <accesstoken>\n";
-    std::cout << "<addr:port>: Cloud Address, \"127.0.0.1:5683\"\n";
-    std::cout <<
-              "<accesstoken>: String value, Provided by response of onboarding scenario\n\tor kind of registration portal\n\n";
-    std::cout <<
-              "sample: \"cloud_device 127.0.0.1:5683\"\n\t-Sign-Up mode\n\n";
-    std::cout <<
-              "sample: \"cloud_device 127.0.0.1:5683 abcdefg 1234567890123456\"\n\t-Sign-in and Publish resource to registered account\n\n";
+    cout << endl;
+    cout << "Usage : thin_cloud_device <addr:port> <uid> <accesstoken>\n";
+    cout << "<addr:port>: Cloud Address, \"127.0.0.1:5683\"\n";
+    cout <<
+         "<accesstoken>: String value, Provided by response of onboarding scenario\n\tor kind of registration portal\n\n";
+    cout <<
+         "sample: \"cloud_device 127.0.0.1:5683\"\n\t-Sign-Up mode\n\n";
+    cout <<
+         "sample: \"cloud_device 127.0.0.1:5683 abcdefg 1234567890123456\"\n\t-Sign-in and Publish resource to registered account\n\n";
 }
 
 static FILE *client_open(const char * /*path*/, const char *mode)
@@ -622,21 +624,21 @@ static FILE *client_open(const char * /*path*/, const char *mode)
 
 int main(int argc, char *argv[])
 {
-    std::string uId;
-    std::string accessToken;
+    string uId;
+    string accessToken;
 
-    std::string authProvider;
-    std::string authCode;
+    string authProvider;
+    string authCode;
 
     OCMode      stackMode = OC_CLIENT_SERVER;
 
     switch (argc)
     {
         case 2:
-            std::cout << "Put auth provider name(ex: github)" << std::endl;
-            std::cin >> authProvider;
-            std::cout << "Put auth code(provided by auth provider)" << std::endl;
-            std::cin >> authCode;
+            cout << "Put auth provider name(ex: github)" << endl;
+            cin >> authProvider;
+            cout << "Put auth code(provided by auth provider)" << endl;
+            cin >> authCode;
             break;
 
         case 4:
@@ -651,18 +653,18 @@ int main(int argc, char *argv[])
 
     g_host += argv[1];
 
-    std::cout << "Host " << g_host.c_str() << std::endl;
+    cout << "Host " << g_host.c_str() << endl;
 
     OCPersistentStorage ps{ client_open, fread, fwrite, fclose, unlink };
     if (OCRegisterPersistentStorageHandler(&ps) != OC_STACK_OK)
     {
-        std::cout << "OCStack init persistent storage error" << std::endl;
+        cout << "OCStack init persistent storage error" << endl;
         return 0;
     }
 
     if (OCInit(NULL, 0, stackMode) != OC_STACK_OK)
     {
-        std::cout << "OCStack init error" << std::endl;
+        cout << "OCStack init error" << endl;
         return 0;
     }
 
@@ -671,17 +673,17 @@ int main(int argc, char *argv[])
     switch (argc)
     {
         case 2:
-            std::cout << "Sign-Up to cloud using " << authProvider << " " << authCode << std::endl;
+            cout << "Sign-Up to cloud using " << authProvider << " " << authCode << endl;
             res = OCCloudSignup(g_host.c_str(), OCGetServerInstanceIDString(), authProvider.c_str(),
                                 authCode.c_str(), handleRegisterCB);
-            std::cout << "OCCloudSignup return " << res << std::endl;
+            cout << "OCCloudSignup return " << res << endl;
             break;
 
         case 4:
-            std::cout << "Sign-In to cloud using " << accessToken << std::endl;
+            cout << "Sign-In to cloud using " << accessToken << endl;
             res = OCCloudLogin(g_host.c_str(), uId.c_str(), OCGetServerInstanceIDString(), accessToken.c_str(),
                                handleLoginoutCB);
-            std::cout << "OCCloudLogin return " << res << std::endl;
+            cout << "OCCloudLogin return " << res << endl;
             break;
 
         default:
@@ -691,13 +693,13 @@ int main(int argc, char *argv[])
 
 
 
-    std::cout << "Waiting response.." << std::endl;
+    cout << "Waiting response.." << endl;
 
     while (true)
     {
         if (OCProcess() != OC_STACK_OK)
         {
-            std::cout << "OCProcess process error" << std::endl;
+            cout << "OCProcess process error" << endl;
         }
 
         sleep(1);
@@ -705,7 +707,7 @@ int main(int argc, char *argv[])
 
     if (OCStop() != OC_STACK_OK)
     {
-        std::cout << "OCStop process error" << std::endl;
+        cout << "OCStop process error" << endl;
     }
 
     return 0;