Added JAVADOC comments to function declarations.
authorLomtev Dmytro <d.lomtev@samsung.com>
Thu, 18 May 2017 13:30:47 +0000 (16:30 +0300)
committerLomtev Dmytro <d.lomtev@samsung.com>
Thu, 18 May 2017 13:30:47 +0000 (16:30 +0300)
device_core/iotivity_lib/inc/report_client.h
device_core/iotivity_lib/src/report_client.cpp
device_core/secserver/report_resource.cpp
device_core/utest/test_iot_dev_manager.cpp

index bd0a624..2baa750 100644 (file)
 
 namespace NetworkManager
 {
-
+/**
+ * @brief The ReportClient class provide connection to report resource
+ */
 class ReportClient
 {
     std::shared_ptr<OC::OCResource> resource;
     std::mutex report_mutex;
     std::condition_variable signal;
 public:
+    /**
+     * @brief Constructor
+     * @param host [in] IoT Cloud host address
+     */
     ReportClient(const std::string& host);
 
+    /**
+     * @brief true if resource found and false otherwise
+     */
     operator bool() const;
 
+    /**
+     * @brief getReport get report from server
+     * @param params [in] parameters used for reports filtering
+     * @return report in JSON format
+     */
     std::string getReport(const OC::QueryParamsMap& params);
 
+    /**
+     * @brief postReport post report to server
+     * @param report [in] report in JSON format
+     */
     void postReport(const std::string& report);
 private:
+    /**
+     * @brief foundResourceCb callback processing resource found events
+     * @param found_resource [in] found resource
+     */
     void foundResourceCb(std::shared_ptr<OC::OCResource> found_resource);
-
-    void onReportObserveCb(const OC::HeaderOptions options, const OC::OCRepresentation& rep,
-                    const int& eCode, const int& sequenceNumber);
 };
 
 } // namespace NetworkManager
index 36ac3ce..72928b6 100644 (file)
@@ -116,35 +116,4 @@ void ReportClient::foundResourceCb(std::shared_ptr<OCResource> found_resource)
     }
 }
 
-void ReportClient::onReportObserveCb(const HeaderOptions /*headerOptions*/, const OCRepresentation& rep,
-                const int& eCode, const int& sequenceNumber)
-{
-    try
-    {
-        if(eCode == OC_STACK_OK && sequenceNumber <= MAX_SEQUENCE_NUMBER)
-        {
-            if(sequenceNumber == OC_OBSERVE_REGISTER)
-            {
-                LOG_I(TAG, "Observe registration action is successful");
-            }
-        }
-        else
-        {
-            if(eCode == OC_STACK_OK)
-            {
-                LOG_D(TAG, "Observe registration failed");
-            }
-            else
-            {
-                LOG_E(TAG, "Observe response error: %d", eCode);
-            }
-        }
-    }
-    catch(std::exception& e)
-    {
-        LOG_E(TAG, "Observe exception: %s", e.what());
-    }
-
-}
-
 } // namespace NetworkManager
index 7d2d591..fdab083 100644 (file)
@@ -236,15 +236,17 @@ OCEntityHandlerResult ReportResource::entityHandler(std::shared_ptr<OCResourceRe
                             std::cout << q.first << ": " << q.second << std::endl;
                         }
 
-                        std::string id = root["id"].asString();
+                        std::string did = root["did"].asString();
                         std::string date = root["date"].asString();
                         std::string name = root["name"].asString();
-                        int result = root["id"].asInt();
+                        int result = root["result"].asInt();
                         std::string data = root["data"].asString();
 
                         try
                         {
-                            Report{id,name,date,data,result}.save();
+                            Report r{did,name,date,data,result};
+                            std::cout << "Report model: " << r << endl;
+                            r.save();
                         }
                         catch(std::exception& e)
                         {
index 59b048c..e9466e7 100644 (file)
@@ -54,7 +54,15 @@ void each_callback(NM_hDeviceList list, const char* uid, void* param)
     NM_freeDeviceInfo(&info);
 }
 
-
+/**
+ * Test checks device discovery use case
+ * 1. Search for unowned devices
+ * 2. Try API for device lists
+ * 3. Search for owned devices
+ * 4. Iterate thoughout the list and print devices info
+ * 5. Search for unowned devices second time and try to own them
+ * 6. Search for owned devices second time and print info
+ */
 TEST_F(IoTDevManagerTest, device_discovery)
 {
     NM_hDeviceList dev_list;
@@ -113,6 +121,11 @@ void deviceStateChangedCb(const char* id, DeviceState state, void* user_data)
     ASSERT_EQ(user_data_str, static_cast<const char*>(user_data));
 }
 
+/**
+ * Test checks device discovery use case
+ * 1. Search for unowned devices
+ * 2. Subscribe for device state changed event
+ */
 TEST_F(IoTDevManagerTest, presenceCallbackTest)
 {
     NM_hDeviceList dev_list;
@@ -126,6 +139,12 @@ TEST_F(IoTDevManagerTest, presenceCallbackTest)
     ASSERT_EQ(EC_OK, NM_freeDeviceList(&dev_list));
 }
 
+/**
+ * Test checks device discovery use case
+ * 1. Get device report for known did
+ * 2. Compare with expected result
+ * 3. Try to post report
+ */
 TEST_F(IoTDevManagerTest, reportTest)
 {
     char* report = nullptr;
@@ -139,8 +158,23 @@ TEST_F(IoTDevManagerTest, reportTest)
       \"name\" : \"sim\",\n      \"result\" : 0\n   }\n]\n";
     ASSERT_EQ(must_be, report);
     ASSERT_NO_THROW(NM_freeCharBuffer(report));
+
+    std::string new_report{"{\
+    \"data\" : \"New report!\",\
+    \"date\" : \"18-05-2017 00:00:00\",\
+    \"did\" : \"00000000-fe92-46fc-a924-488d2339c2ba\",\
+    \"name\" : \"alert\",\
+    \"result\" : 7\
+}"};
+    ASSERT_NO_THROW(IoTivity::getInstance()->postReport(new_report));
 }
 
+/**
+ * Test checks device discovery use case
+ * 1. Get device report for wrong did
+ * 2. Check that return value is NULL
+ * 3. Check NM_freeCharBuffer won't fail with nullptr as input
+ */
 TEST_F(IoTDevManagerTest, reportTestWrongDid)
 {
     char* report = nullptr;