Moved printRepresentation to iotutils. Fixed build for ubuntu
authorAndriy Gudz <a.gudz@samsung.com>
Mon, 19 Jun 2017 06:51:22 +0000 (09:51 +0300)
committerAndriy Gudz <a.gudz@samsung.com>
Mon, 19 Jun 2017 06:54:58 +0000 (09:54 +0300)
device_core/iotivity_lib/inc/iotutils.h [new file with mode: 0644]
device_core/iotivity_lib/src/IOT_DeviceFinder.cpp
device_core/iotivity_lib/src/iotdevice_impl.cpp
device_core/iotivity_lib/src/iotivity.cpp
device_core/iotivity_lib/src/iotutils.cpp [new file with mode: 0644]
device_core/utest/CMakeLists.txt

diff --git a/device_core/iotivity_lib/inc/iotutils.h b/device_core/iotivity_lib/inc/iotutils.h
new file mode 100644 (file)
index 0000000..511610a
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * @brief  TODO
+ * @date   Created 16.06.2017
+ * @author Created 2017 in Samsung Ukraine R&D Center (SURC) under a contract
+ *                between LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine)
+ *                and "Samsung Electronics Co", Ltd (Seoul, Republic of Korea).
+ *         Copyright: (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
+ * @author Mail to: <A HREF="mailto:a.gudz@samsung.com">Andriy Gudz, a.gudz@samsung.com</A>
+ */
+#ifndef IOTUTILS_H
+#define IOTUTILS_H
+
+#include <OCApi.h>
+#include <OCPlatform.h>
+
+/**
+ * @brief The IotUtils class contains utility methods
+ */
+class IotUtils final
+{
+public:
+    /**
+     * @brief IotUtils Constructor
+     */
+    IotUtils();
+
+    /**
+     * @brief printRepresentation used to print complex representaions
+     * @param rep OCRepresentation object
+     */
+    static void printRepresentation(OC::OCRepresentation rep);
+};
+
+#endif // IOTUTILS_H
index c75e22f..d540fb2 100644 (file)
 
 #include "IOT_DeviceFinder.h"
 
-std::vector<std::shared_ptr<OC::OCResource>> IOT_DeviceFinder::operator()(  const std::string& _host /*= ""*/,
-                                                                            const std::string& _request_uri /*= "/oic/res?rt=oic.wk.easysetup"*/,
-                                                                            OCConnectivityType _connectivity_type /*= CT_DEFAULT*/,
-                                                                            OC::QualityOfService _QoS /*= OC::QualityOfService::LowQos*/,
-                                                                            int _wait_for_sec /*= 3*/   )
+using namespace std;
+
+vector<shared_ptr<OC::OCResource>> IOT_DeviceFinder::operator()(
+                                    const std::string& _host /*= ""*/,
+                                    const std::string& _request_uri /*= "/oic/res?rt=oic.wk.easysetup"*/,
+                                    OCConnectivityType _connectivity_type /*= CT_DEFAULT*/,
+                                    OC::QualityOfService _QoS /*= OC::QualityOfService::LowQos*/,
+                                    int _wait_for_sec /*= 3*/   )
 {
     auto find_callback = [this, _connectivity_type](std::vector<std::shared_ptr<OC::OCResource>> _resources)
     {
         std::unique_lock<std::mutex> lock{vector_mtx};
-        for (auto resource: _resources)
+
+        for (auto resource : _resources)
         {
             if (_connectivity_type == CT_DEFAULT || (resource->connectivityType() & _connectivity_type))
             {
index 14ae808..59431ec 100644 (file)
@@ -20,47 +20,6 @@ namespace
 const std::string dev_info_uri{"/oic/d"};
 const std::string dev_type_resource{"oic.d."};
 const std::string dev_type_uri{"/oic/res?rt=oic.wk.d"};
-void printRepresentation(OCRepresentation rep)
-{
-    for (auto itr = rep.begin(); itr != rep.end(); ++itr)
-    {
-        std::cout << "\t" << itr->attrname() << ":\t" << itr->getValueToString() << std::endl;
-        if (itr->type() == AttributeType::Vector)
-        {
-            switch (itr->base_type())
-            {
-            case AttributeType::OCRepresentation:
-                for (auto itr2 : (*itr).getValue<std::vector<OCRepresentation> >())
-                {
-                    printRepresentation(itr2);
-                }
-                break;
-
-            case AttributeType::Integer:
-                for (auto itr2 : (*itr).getValue<std::vector<int> >())
-                {
-                    std::cout << "\t\t" << itr2 << std::endl;
-                }
-                break;
-
-            case AttributeType::String:
-                for (auto itr2 : (*itr).getValue<std::vector<std::string> >())
-                {
-                    std::cout << "\t\t" << itr2 << std::endl;
-                }
-                break;
-
-            default:
-                std::cout << "Unhandled base type " << itr->base_type() << std::endl;
-                break;
-            }
-        }
-        else if (itr->type() == AttributeType::OCRepresentation)
-        {
-            printRepresentation((*itr).getValue<OCRepresentation>());
-        }
-    }
-}
 }
 
 namespace NetworkManager
index 46a3308..f505f65 100644 (file)
@@ -12,6 +12,7 @@
 #include "nmlib.h"
 #include "report_client.h"
 #include "policy_client.h"
+#include "iotutils.h"
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wreorder"
@@ -38,49 +39,6 @@ const std::string NOTIF_FIND = "Notification findResource()";
 const std::string NOTIF_REQUEST = string(OC_RSRVD_WELL_KNOWN_URI) + "?rt=" + NetworkManager::NOTIFICATION_TYPE;
 
 const std::string REP_LIST{"prslist"};
-
-void printRepresentation(OCRepresentation rep)
-{
-    for (auto itr = rep.begin(); itr != rep.end(); ++itr)
-    {
-        std::cout << "\t" << itr->attrname() << ":\t" << itr->getValueToString() << std::endl;
-        if (itr->type() == AttributeType::Vector)
-        {
-            switch (itr->base_type())
-            {
-            case AttributeType::OCRepresentation:
-                for (auto itr2 : (*itr).getValue<std::vector<OCRepresentation> >())
-                {
-                    printRepresentation(itr2);
-                }
-                break;
-
-            case AttributeType::Integer:
-                for (auto itr2 : (*itr).getValue<std::vector<int> >())
-                {
-                    std::cout << "\t\t" << itr2 << std::endl;
-                }
-                break;
-
-            case AttributeType::String:
-                for (auto itr2 : (*itr).getValue<std::vector<std::string> >())
-                {
-                    std::cout << "\t\t" << itr2 << std::endl;
-                }
-                break;
-
-            default:
-                std::cout << "Unhandled base type " << itr->base_type() << std::endl;
-                break;
-            }
-        }
-        else if (itr->type() == AttributeType::OCRepresentation)
-        {
-            printRepresentation((*itr).getValue<OCRepresentation>());
-        }
-    }
-}
-
 }
 
 namespace NetworkManager
diff --git a/device_core/iotivity_lib/src/iotutils.cpp b/device_core/iotivity_lib/src/iotutils.cpp
new file mode 100644 (file)
index 0000000..dd8ec19
--- /dev/null
@@ -0,0 +1,54 @@
+/**
+ * @brief  TODO
+ * @date   Created 16.06.2017
+ * @author Created 2017 in Samsung Ukraine R&D Center (SURC) under a contract
+ *                between LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine)
+ *                and "Samsung Electronics Co", Ltd (Seoul, Republic of Korea).
+ *         Copyright: (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
+ * @author Mail to: <A HREF="mailto:a.gudz@samsung.com">Andriy Gudz, a.gudz@samsung.com</A>
+ */
+#include "iotutils.h"
+
+using namespace OC;
+
+void IotUtils::printRepresentation(OCRepresentation rep)
+{
+    for (auto itr = rep.begin(); itr != rep.end(); ++itr)
+    {
+        std::cout << "\t" << itr->attrname() << ":\t" << itr->getValueToString() << std::endl;
+        if (itr->type() == AttributeType::Vector)
+        {
+            switch (itr->base_type())
+            {
+            case AttributeType::OCRepresentation:
+                for (auto itr2 : (*itr).getValue<std::vector<OCRepresentation> >())
+                {
+                    printRepresentation(itr2);
+                }
+                break;
+
+            case AttributeType::Integer:
+                for (auto itr2 : (*itr).getValue<std::vector<int> >())
+                {
+                    std::cout << "\t\t" << itr2 << std::endl;
+                }
+                break;
+
+            case AttributeType::String:
+                for (auto itr2 : (*itr).getValue<std::vector<std::string> >())
+                {
+                    std::cout << "\t\t" << itr2 << std::endl;
+                }
+                break;
+
+            default:
+                std::cout << "Unhandled base type " << itr->base_type() << std::endl;
+                break;
+            }
+        }
+        else if (itr->type() == AttributeType::OCRepresentation)
+        {
+            printRepresentation((*itr).getValue<OCRepresentation>());
+        }
+    }
+}
index d3c37a3..19b2dd9 100644 (file)
@@ -29,15 +29,16 @@ set (TEST_LINK_LIBRARIES ${GTEST_LIB}
        jsoncpp
 )
 
+if ("${FLAVOR}" STREQUAL "UBUNTU")
+       set (LINK_DLOG "")
+else()
+       set (LINK_DLOG dlog)
+endif()
+
 if ("${SCENARIO}" STREQUAL "PRIMITIVE")
-       if ("${FLAVOR}" STREQUAL "UBUNTU")
-               set (LINK_DLOG "")
-       else()
-               set (LINK_DLOG dlog)
-       endif()
        target_link_libraries(${PROJECT_NAME} ${IOTIVITY_LIB_PROJECT_NAME} ${LINK_DLOG})
 else()
-        set (TEST_LINK_LIBRARIES ${TEST_LINK_LIBRARIES} ${CTRL_APP_LIB_PROJECT_NAME} dlog)
+       set (TEST_LINK_LIBRARIES ${TEST_LINK_LIBRARIES} ${CTRL_APP_LIB_PROJECT_NAME} ${LINK_DLOG})
 endif()
 
 target_link_libraries(${PROJECT_NAME} ${TEST_LINK_LIBRARIES})