add: logging
fix: rename branch
This commit is contained in:
parent
9e5718db43
commit
2f9be90ec1
5 changed files with 63 additions and 49 deletions
src/models
|
@ -186,6 +186,11 @@ controller_free_list(controller_t **controllers)
|
|||
cJSON*
|
||||
controller_to_json(controller_t *controller)
|
||||
{
|
||||
char uuid_str[UUID_STR_LEN];
|
||||
uuid_unparse(controller->uid, uuid_str);
|
||||
|
||||
LOGGER_DEBUG("JSONifying controller %s\n", uuid_str);
|
||||
|
||||
cJSON *json = cJSON_CreateObject();
|
||||
|
||||
cJSON *json_name = cJSON_CreateString(controller->name);
|
||||
|
@ -196,8 +201,6 @@ controller_to_json(controller_t *controller)
|
|||
}
|
||||
cJSON_AddItemToObject(json, "name", json_name);
|
||||
|
||||
char uuid_str[UUID_STR_LEN];
|
||||
uuid_unparse(controller->uid, uuid_str);
|
||||
cJSON *json_id = cJSON_CreateString(uuid_str);
|
||||
if(json_name == NULL)
|
||||
{
|
||||
|
@ -253,6 +256,7 @@ controller_to_json(controller_t *controller)
|
|||
controller_t*
|
||||
controller_get_by_id(int id)
|
||||
{
|
||||
LOGGER_DEBUG("getting controller [id=%d] from database\n", id);
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "SELECT * FROM controllers WHERE id = ?1;", -1, &stmt, NULL);
|
||||
|
@ -269,6 +273,9 @@ controller_get_by_id(int id)
|
|||
controller_t*
|
||||
controller_get_by_uid(uuid_t uid)
|
||||
{
|
||||
char uuid_str[UUID_STR_LEN];
|
||||
uuid_unparse(uid, uuid_str);
|
||||
LOGGER_DEBUG("getting controller [uid=%s] from database\n", uuid_str);
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "SELECT * FROM controllers WHERE uid = ?1;", -1, &stmt, NULL);
|
||||
|
@ -285,6 +292,7 @@ controller_get_by_uid(uuid_t uid)
|
|||
controller_t**
|
||||
controller_get_all()
|
||||
{
|
||||
LOGGER_DEBUG("getting all controllers from database\n");
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "SELECT * FROM controllers;", -1, &stmt, NULL);
|
||||
|
|
|
@ -196,6 +196,17 @@ relay_free_list(relay_t **relays)
|
|||
cJSON*
|
||||
relay_to_json(relay_t *relay)
|
||||
{
|
||||
controller_t *controller = controller_get_by_id(relay->controller_id);
|
||||
if(!controller)
|
||||
{
|
||||
LOGGER_WARNING("failed to get controller\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char uuid_str[UUID_STR_LEN];
|
||||
uuid_unparse(controller->uid, uuid_str);
|
||||
LOGGER_DEBUG("JSONifying relay %s:%d\n", uuid_str, relay->number);
|
||||
|
||||
relay_reload_active_schedule(relay);
|
||||
|
||||
cJSON *json = cJSON_CreateObject();
|
||||
|
@ -218,16 +229,6 @@ relay_to_json(relay_t *relay)
|
|||
}
|
||||
cJSON_AddItemToObject(json, "name", json_name);
|
||||
|
||||
controller_t *controller = controller_get_by_id(relay->controller_id);
|
||||
if(!controller)
|
||||
{
|
||||
LOGGER_WARNING("failed to get controller\n");
|
||||
cJSON_Delete(json);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char uuid_str[UUID_STR_LEN];
|
||||
uuid_unparse(controller->uid, uuid_str);
|
||||
cJSON *json_controller_id = cJSON_CreateString(uuid_str);
|
||||
if(json_controller_id == NULL)
|
||||
{
|
||||
|
@ -340,6 +341,7 @@ relay_get_by_uid(uuid_t uid)
|
|||
relay_t**
|
||||
relay_get_all()
|
||||
{
|
||||
LOGGER_DEBUG("getting all relays from database\n");
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "SELECT * FROM relays;", -1, &stmt, NULL);
|
||||
|
@ -350,6 +352,7 @@ relay_get_all()
|
|||
relay_t**
|
||||
relay_get_with_schedule(int schedule_id)
|
||||
{
|
||||
LOGGER_DEBUG("getting relays [schedule_id=%d] from database\n", schedule_id);
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "SELECT DISTINCT relays.* FROM relays INNER JOIN junction_relay_schedule ON relays.id == junction_relay_schedule.relay_id WHERE junction_relay_schedule.schedule_id = ?1;", -1, &stmt, NULL);
|
||||
|
@ -361,6 +364,7 @@ relay_get_with_schedule(int schedule_id)
|
|||
relay_t*
|
||||
relay_get_for_controller(int controller_id, int relay_num)
|
||||
{
|
||||
LOGGER_DEBUG("getting relay [controller_id=%d, relay_num=%d] from database\n", controller_id, relay_num);
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "SELECT * FROM relays WHERE controller_id = ?1 AND number = ?2;", -1, &stmt, NULL);
|
||||
|
@ -379,6 +383,7 @@ relay_get_for_controller(int controller_id, int relay_num)
|
|||
relay_t**
|
||||
relay_get_by_controller_id(int controller_id)
|
||||
{
|
||||
LOGGER_DEBUG("getting relays [controller_id=%d] from database\n", controller_id);
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "SELECT * FROM relays WHERE controller_id = ?1;", -1, &stmt, NULL);
|
||||
|
|
|
@ -218,6 +218,11 @@ schedule_periods_to_blob(schedule_t *schedule)
|
|||
cJSON*
|
||||
schedule_to_json(schedule_t *schedule)
|
||||
{
|
||||
char uuid_str[UUID_STR_LEN];
|
||||
schedule_uid_unparse(schedule->uid, uuid_str);
|
||||
|
||||
LOGGER_DEBUG("JSONifying schedule %s\n", uuid_str);
|
||||
|
||||
cJSON *json = cJSON_CreateObject();
|
||||
|
||||
cJSON *json_name = cJSON_CreateString(schedule->name);
|
||||
|
@ -228,8 +233,6 @@ schedule_to_json(schedule_t *schedule)
|
|||
}
|
||||
cJSON_AddItemToObject(json, "name", json_name);
|
||||
|
||||
char uuid_str[UUID_STR_LEN];
|
||||
schedule_uid_unparse(schedule->uid, uuid_str);
|
||||
cJSON *json_id = cJSON_CreateString(uuid_str);
|
||||
if(json_name == NULL)
|
||||
{
|
||||
|
@ -337,6 +340,7 @@ schedule_get_by_id_or_off(int id)
|
|||
schedule_t*
|
||||
schedule_get_by_id(int id)
|
||||
{
|
||||
LOGGER_DEBUG("getting schedule [id=%d] from database\n", id);
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "SELECT * FROM schedules WHERE id = ?1;", -1, &stmt, NULL);
|
||||
|
@ -353,6 +357,9 @@ schedule_get_by_id(int id)
|
|||
schedule_t*
|
||||
schedule_get_by_uid_or_off(uuid_t uid)
|
||||
{
|
||||
char uuid_str[UUID_STR_LEN];
|
||||
schedule_uid_unparse(uid, uuid_str);
|
||||
LOGGER_DEBUG("getting schedule [uid=%s] or off from database\n", uuid_str);
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "SELECT * FROM schedules WHERE uid = ?1;", -1, &stmt, NULL);
|
||||
|
@ -378,6 +385,9 @@ schedule_get_by_uid_or_off(uuid_t uid)
|
|||
schedule_t*
|
||||
schedule_get_by_uid(uuid_t uid)
|
||||
{
|
||||
char uuid_str[UUID_STR_LEN];
|
||||
schedule_uid_unparse(uid, uuid_str);
|
||||
LOGGER_DEBUG("getting schedule [uid=%s] from database\n", uuid_str);
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "SELECT * FROM schedules WHERE uid = ?1;", -1, &stmt, NULL);
|
||||
|
@ -394,6 +404,7 @@ schedule_get_by_uid(uuid_t uid)
|
|||
schedule_t**
|
||||
schedule_get_relay_weekdays(int relay_id)
|
||||
{
|
||||
LOGGER_DEBUG("getting schedules [relay_id=%d] from database\n", relay_id);
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "SELECT schedules.* FROM schedules INNER JOIN junction_relay_schedule ON schedules.id == junction_relay_schedule.schedule_id WHERE junction_relay_schedule.relay_id = ?1 ORDER BY junction_relay_schedule.weekday ASC", -1, &stmt, NULL);
|
||||
|
@ -405,6 +416,7 @@ schedule_get_relay_weekdays(int relay_id)
|
|||
schedule_t**
|
||||
schedule_get_all()
|
||||
{
|
||||
LOGGER_DEBUG("getting all schedules from database\n");
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "SELECT * FROM schedules;", -1, &stmt, NULL);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue