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
}
}
-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
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)
{
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;
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;
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;
\"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;