finish rename ligths as outlets

This commit is contained in:
jbnadal
2018-05-07 11:43:07 +02:00
parent 7d8b653d08
commit 10bfa7ac93
6 changed files with 47 additions and 42 deletions

View File

@@ -36,7 +36,7 @@
*
* @brief Constructor of the Device Collection.
*/
DeviceCollection::DeviceCollection(void)
DeviceCollection::DeviceCollection(void) : m_max_id(0)
{
}
@@ -67,6 +67,12 @@ Device *DeviceCollection::operator[](int a_pos)
int DeviceCollection::add(Device *a_device)
{
m_devices.push_back(std::unique_ptr<Device>(a_device));
if (a_device->get_id() > m_max_id)
{
m_max_id = a_device->get_id();
}
return 0;
}

View File

@@ -53,6 +53,7 @@ class DeviceCollection
private:
std::vector <std::unique_ptr<Device>> m_devices;
uint16_t m_max_id;
};
#endif /* _DEVICE_COLLECTION_H */

View File

@@ -76,7 +76,7 @@ int DevicesManager::load(void)
if (json_object_object_get_ex(the_root_node, kOutletEntry, &the_value_node))
{
load_lights(the_value_node);
load_outlets(the_value_node);
}
if (json_object_object_get_ex(the_root_node, kShutterEntry, &the_value_node))
@@ -136,7 +136,7 @@ std::string DevicesManager::get(const std::string &a_capability)
if (a_capability == kOutletEntry)
{
json_object_object_add(the_output_node, kOutletEntry, m_lights.to_json());
json_object_object_add(the_output_node, kOutletEntry, m_outlets.to_json());
}
else if (a_capability == kShutterEntry)
{
@@ -166,10 +166,10 @@ std::string DevicesManager::get(const std::string &a_capability, uint32_t an_id)
if (a_capability == kOutletEntry)
{
the_pos = m_lights.find(an_id);
the_pos = m_outlets.find(an_id);
if (the_pos != -1)
{
the_output = json_object_to_json_string(m_lights[the_pos]->to_json());
the_output = json_object_to_json_string(m_outlets[the_pos]->to_json());
}
}
@@ -241,32 +241,32 @@ int DevicesManager::set_state(const std::string &a_capability, int an_id, bool a
*/
int DevicesManager::create(const std::string &a_capability, struct json_object *a_node)
{
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn load_lights
* @fn load_outlets
*
* @brief Load Lights Object From a Json Node.
* @brief Load outlets Object From a Json Node.
*/
int DevicesManager::load_lights(struct json_object *a_node)
int DevicesManager::load_outlets(struct json_object *a_node)
{
fprintf(stderr, "DevicesManager::load_lights\n");
fprintf(stderr, "DevicesManager::load_outlets\n");
// Get Lights
// Get Outlets
if (json_object_get_type(a_node) == json_type_array)
{
int the_len;
struct json_object *the_light_node;
struct json_object *the_outlet_node;
the_len = json_object_array_length(a_node);
for (int i = 0; i < the_len; i++)
{
OutletDio* the_outlet = new OutletDio;
the_light_node = json_object_array_get_idx(a_node, i);
the_outlet->from_json(the_light_node);
the_outlet_node = json_object_array_get_idx(a_node, i);
the_outlet->from_json(the_outlet_node);
m_lights.add(the_outlet);
m_outlets.add(the_outlet);
}
}
@@ -274,9 +274,9 @@ int DevicesManager::load_lights(struct json_object *a_node)
}
/*! ----------------------------------------------------------------------------
* @fn load_lights
* @fn load_shutters
*
* @brief Load Lights Object From a Json Node.
* @brief Load Shutters Object From a Json Node.
*/
int DevicesManager::load_shutters(struct json_object *a_node)
{
@@ -304,9 +304,9 @@ int DevicesManager::load_shutters(struct json_object *a_node)
}
/*! ----------------------------------------------------------------------------
* @fn load_lights
* @fn load_sprinklers
*
* @brief Load Lights Object From a Json Node.
* @brief Load Sprinklers Object From a Json Node.
*/
int DevicesManager::load_sprinklers(struct json_object *a_node)
{

View File

@@ -60,14 +60,14 @@ class DevicesManager
int create(const std::string &a_capability, struct json_object *a_node);
private:
int load_lights(struct json_object *a_node);
int load_outlets(struct json_object *a_node);
int load_shutters(struct json_object *a_node);
int load_sprinklers(struct json_object *a_node);
private:
std::string m_file_path;
DeviceCollection m_lights;
DeviceCollection m_outlets;
DeviceCollection m_shutters;
DeviceCollection m_sprinklers;
};

View File

@@ -81,8 +81,6 @@ OutletsController::~OutletsController(void)
*/
int OutletsController::create(struct ubus_context *, struct ubus_request_data *, struct blob_attr *a_msg)
{
int the_result = 0;
struct blob_buf the_buf = {0};
char *the_string;
struct json_object *the_root_node;
printf("%s\n", __PRETTY_FUNCTION__);