WIP: Get Devices.
This commit is contained in:
@@ -109,3 +109,80 @@ int Devices::save (void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn get
|
||||||
|
*
|
||||||
|
* @brief get the list of devices of a specific capabilities.
|
||||||
|
*/
|
||||||
|
std::string Devices::get (const std::string &aCapability)
|
||||||
|
{
|
||||||
|
Json::StyledWriter theWriter;
|
||||||
|
Json::Value theOutput;
|
||||||
|
fprintf (stderr, "Devices::get...\n");
|
||||||
|
|
||||||
|
if (aCapability == "Lights") {
|
||||||
|
|
||||||
|
theOutput[aCapability] = mLights.to_json(true);
|
||||||
|
}
|
||||||
|
else if (aCapability == "Shutters") {
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (aCapability == "Sprinklers") {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return theWriter.write (theOutput).c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn get
|
||||||
|
*
|
||||||
|
* @brief get the device of a specific capabilities, with the ID.
|
||||||
|
*/
|
||||||
|
Json::Value Devices::get (const std::string &aCapability, int anId)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn get
|
||||||
|
*
|
||||||
|
* @brief get the list of devices of a specific capabilities.
|
||||||
|
*/
|
||||||
|
std::string Devices::get (const std::string &aCapability)
|
||||||
|
{
|
||||||
|
Json::StyledWriter theWriter;
|
||||||
|
Json::Value theOutput;
|
||||||
|
|
||||||
|
printf ("Get aCapability: %s\n", aCapability.c_str());
|
||||||
|
|
||||||
|
theOutput[aCapability] = mRoot[aCapability]["data"];
|
||||||
|
return theWriter.write (theOutput).c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn get
|
||||||
|
*
|
||||||
|
* @brief get the device of a specific capabilities, with the ID.
|
||||||
|
*/
|
||||||
|
Json::Value Devices::get (const std::string &aCapability, int anId)
|
||||||
|
{
|
||||||
|
Json::Value theResult;
|
||||||
|
for (const Json::Value& theElement : mRoot[aCapability]["data"]) {
|
||||||
|
|
||||||
|
if (theElement["id"].asInt() == anId) {
|
||||||
|
|
||||||
|
theResult = theElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return theResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -50,6 +50,9 @@ public:
|
|||||||
int load (void);
|
int load (void);
|
||||||
int save (void);
|
int save (void);
|
||||||
|
|
||||||
|
std::string get (const std::string &aCapability);
|
||||||
|
Json::Value get (const std::string &aCapability, int anId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string mFilePath;
|
std::string mFilePath;
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ int LightDevice::load_from_json (Json::Value anElem)
|
|||||||
*
|
*
|
||||||
* @brief Export LightDevice Object as JSON Object.
|
* @brief Export LightDevice Object as JSON Object.
|
||||||
*/
|
*/
|
||||||
Json::Value LightDevice::to_json (void)
|
Json::Value LightDevice::to_json (bool bDataOnly)
|
||||||
{
|
{
|
||||||
Json::Value theResult;
|
Json::Value theResult;
|
||||||
Json::Value data_json(Json::arrayValue);
|
Json::Value data_json(Json::arrayValue);
|
||||||
@@ -98,5 +98,8 @@ Json::Value LightDevice::to_json (void)
|
|||||||
theResult["speach_name"] = mspeach_name;
|
theResult["speach_name"] = mspeach_name;
|
||||||
theResult["data"] = data_json;
|
theResult["data"] = data_json;
|
||||||
|
|
||||||
|
if (bDataOnly == true)
|
||||||
|
return data_json;
|
||||||
|
|
||||||
return theResult;
|
return theResult;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public:
|
|||||||
~LightDevice (void);
|
~LightDevice (void);
|
||||||
|
|
||||||
int load_from_json (Json::Value anElem);
|
int load_from_json (Json::Value anElem);
|
||||||
Json::Value to_json (void);
|
Json::Value to_json (bool bDataOnly = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector <Light> mLights;
|
std::vector <Light> mLights;
|
||||||
|
|||||||
@@ -114,8 +114,6 @@ int main (void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
theDevices.save();
|
|
||||||
|
|
||||||
Capabilities theCapabilities;
|
Capabilities theCapabilities;
|
||||||
CapabilitiesLights theCapLights (&theDevices);
|
CapabilitiesLights theCapLights (&theDevices);
|
||||||
CapabilitiesShutters theCapShutters (&theDevices);
|
CapabilitiesShutters theCapShutters (&theDevices);
|
||||||
|
|||||||
@@ -86,11 +86,11 @@ int CapabilitiesLights::Get (struct ubus_context *aCtx, struct ubus_request_data
|
|||||||
struct blob_buf theBuf = {0};
|
struct blob_buf theBuf = {0};
|
||||||
|
|
||||||
blob_buf_init (&theBuf, 0);
|
blob_buf_init (&theBuf, 0);
|
||||||
/* TODO
|
|
||||||
blobmsg_add_json_from_string (&theBuf, mDevices->get("Lights").c_str());
|
blobmsg_add_json_from_string (&theBuf, mDevices->get("Lights").c_str());
|
||||||
|
|
||||||
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
|
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
|
||||||
*/
|
|
||||||
blob_buf_free (&theBuf);
|
blob_buf_free (&theBuf);
|
||||||
|
|
||||||
return theResult;
|
return theResult;
|
||||||
|
|||||||
@@ -92,9 +92,9 @@ int CapabilitiesShutters::Get (struct ubus_context *aCtx, struct ubus_request_da
|
|||||||
struct blob_buf theBuf = {0};
|
struct blob_buf theBuf = {0};
|
||||||
|
|
||||||
blob_buf_init (&theBuf, 0);
|
blob_buf_init (&theBuf, 0);
|
||||||
/* TODO
|
|
||||||
blobmsg_add_json_from_string (&theBuf, mDevices->get("Shutters").c_str());
|
blobmsg_add_json_from_string (&theBuf, mDevices->get("Shutters").c_str());
|
||||||
*/
|
|
||||||
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
|
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
|
||||||
|
|
||||||
blob_buf_free (&theBuf);
|
blob_buf_free (&theBuf);
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ CapabilitiesSprinklers::CapabilitiesSprinklers (Devices *aDevice) :
|
|||||||
*/
|
*/
|
||||||
CapabilitiesSprinklers::~CapabilitiesSprinklers (void)
|
CapabilitiesSprinklers::~CapabilitiesSprinklers (void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -86,9 +85,9 @@ int CapabilitiesSprinklers::Get (struct ubus_context *aCtx, struct ubus_request_
|
|||||||
struct blob_buf theBuf = {0};
|
struct blob_buf theBuf = {0};
|
||||||
|
|
||||||
blob_buf_init (&theBuf, 0);
|
blob_buf_init (&theBuf, 0);
|
||||||
/*TODO
|
|
||||||
blobmsg_add_json_from_string (&theBuf, mDevices->get("Sprinklers").c_str());
|
blobmsg_add_json_from_string (&theBuf, mDevices->get("Sprinklers").c_str());
|
||||||
*/
|
|
||||||
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
|
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
|
||||||
|
|
||||||
blob_buf_free (&theBuf);
|
blob_buf_free (&theBuf);
|
||||||
|
|||||||
Reference in New Issue
Block a user