add: much

This commit is contained in:
Tobias Reisinger 2020-02-10 00:58:17 +01:00
parent 7b6ee283c6
commit cbb4ac7a86
15 changed files with 159 additions and 56 deletions
include/models

View file

@ -23,24 +23,55 @@ typedef struct controller
* Includes a \0 terminator.
*/
char name[CONTROLLER_NAME_LENGTH + 1];
uint16_t port;
/**
* @brief The command port the controller was bound to
*/
uint16_t command_port;
/**
* @brief The discovery port the controller receives broadcasts on
*/
uint16_t discovery_port;
/**
* @brief Amount of relays available to this controller
*/
uint8_t relay_count;
relay **relays;
} controller;
/**
* @brief Key to save controller information in database
*/
typedef enum controller_db_key
{
KEY_META_UUID,
KEY_META_NAME,
KEY_META_PORT,
KEY_META_RELAY_COUNT,
KEY_META_RELAYS
KEY_META_UUID = 0,
KEY_META_NAME = 1,
KEY_META_COMMAND_PORT = 2,
KEY_META_DISCOVERY_PORT = 3,
KEY_META_RELAY_COUNT = 4,
KEY_META_RELAYS = 5,
} controller_db_key;
/**
* @brief Create a new instance of controller
*
* This should not fail. The instance will be created with malloc and genric default values
*
* @return A new instance of #controller
*/
controller*
controller_create(void);
/**
* @brief Load a controller for database or create a new one
*
* Will return NULL when transaction can't start.
*
* @param mdb_env An opened MDB_env to load from
*
* @return A loaded or new instance of controller or NULL on database error
*/
controller*
controller_load(MDB_env *mdb_env);
@ -55,6 +86,14 @@ controller_load(MDB_env *mdb_env);
int
controller_save(controller *cntrlr, MDB_env *mdb_env);
/**
* @brief Debug an instance of #controller
*
* Will use #LOG_DEBUG to log. So log will be depending on #LOG_LEVEL
*
* @param cntrlr #controller to debug
*/
void
controller_debug(controller *cntrlr);