add: macro endpoints

add: basic macro support
fix: database locking with lock-pointer
fix: memory leaks
This commit is contained in:
Tobias Reisinger 2020-09-04 00:28:49 +02:00
parent 6a2b94ef1c
commit 9d2c48d645
30 changed files with 606 additions and 213 deletions

View file

@ -3,6 +3,8 @@
#include <sqlite3.h>
typedef int database_transaction_lock;
extern sqlite3 *global_database;
void
@ -15,14 +17,14 @@ void
database_migrate();
int
database_transaction_begin();
void
database_transaction_begin(database_transaction_lock *lock);
void
database_transaction_commit();
database_transaction_commit(database_transaction_lock *lock);
void
database_transaction_rollback();
database_transaction_rollback(database_transaction_lock *lock);
int

View file

@ -0,0 +1,18 @@
#ifndef CORE_ENDPOINTS_API_V1_MACROS_H
#define CORE_ENDPOINTS_API_V1_MACROS_H
#include <router.h>
void
api_v1_macros_GET(struct mg_connection *nc, struct http_message *hm, endpoint_args_t *args, endpoint_response_t *response);
void
api_v1_macros_POST(struct mg_connection *nc, struct http_message *hm, endpoint_args_t *args, endpoint_response_t *response);
//void
//api_v1_tags_STR_GET(struct mg_connection *nc, struct http_message *hm, endpoint_args_t *args, endpoint_response_t *response);
//void
//api_v1_tags_STR_DELETE(struct mg_connection *nc, struct http_message *hm, endpoint_args_t *args, endpoint_response_t *response);
#endif /* CORE_ENDPOINTS_API_V1_MACROS_H */

View file

@ -1,7 +0,0 @@
#ifndef CORE_JUNCTION_MACRO_H
#define CORE_JUNCTION_MACRO_H
int
junction_macro_insert(int macro_id, int relay_id, int schedule_id, uint8_t weekday);
#endif /* CORE_JUNCTION_MACRO_H */

View file

@ -7,6 +7,7 @@
#include <constants.h>
#include <models/period.h>
#include <models/macro_action.h>
typedef struct
{

View file

@ -0,0 +1,27 @@
#ifndef CORE_MODELS_MACRO_ACTION_H
#define CORE_MODELS_MACRO_ACTION_H
typedef struct
{
int macro_id;
int relay_id;
int schedule_id;
uint8_t weekday;
} macro_action_t;
int
macro_action_insert(macro_action_t *macro_action);
macro_action_t**
macro_action_get_for_macro(int macro_id);
void
macro_action_free_list(macro_action_t **macro_actions);
int*
macro_action_get_macro_ids_with_schedule(int schedule_id);
int*
macro_action_get_macro_ids_with_relay(int relay_id);
#endif /* CORE_MODELS_MACRO_ACTION_H */