add: doxygen

This commit is contained in:
Tobias Reisinger 2020-02-08 15:09:34 +01:00
parent 18804da4d8
commit 7b6ee283c6
7 changed files with 2737 additions and 145 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
.idea/
docs/
build/
cmake-build-debug/

2548
Doxyfile Normal file

File diff suppressed because it is too large Load diff

View file

@ -8,9 +8,20 @@
#include <config.h>
#include <models/relay.h>
/**
* @brief Information about this controller
*/
typedef struct controller
{
/**
* @brief A unique UUID for this controller
*/
uuid_t uuid;
/**
* @brief The name of this controller
*
* Includes a \0 terminator.
*/
char name[CONTROLLER_NAME_LENGTH + 1];
uint16_t port;
uint8_t relay_count;
@ -31,8 +42,16 @@ controller*
controller_create(void);
controller*
controller_read(MDB_env *mdb_env);
controller_load(MDB_env *mdb_env);
/**
* @brief Save a controller to the database
*
* @param cntrlr Instance of a controller
* @param mdb_env Already created MDB_env
*
* @return Indicator to show success (0) or failure (!0)
*/
int
controller_save(controller *cntrlr, MDB_env *mdb_env);

10
main.c
View file

@ -6,6 +6,14 @@
#include <logger.h>
#include <models/controller.h>
/**
* @brief The main function
*
* @param argc UNUSED
* @param argv UNUSED
*
* @return Statuscode to indicate success (0) or failure (!0)
*/
int
main(int argc, char** argv)
{
@ -33,7 +41,7 @@ main(int argc, char** argv)
exit(1);
}
controller *this_cntrlr = controller_read(mdb_env);
controller *this_cntrlr = controller_load(mdb_env);
controller_save(this_cntrlr, mdb_env);
mdb_env_close(mdb_env);

View file

@ -27,149 +27,6 @@ controller_create(void)
return result;
}
void
controller_read_single(MDB_txn *mdb_txn, MDB_dbi mdb_dbi, controller_db_key key_meta, MDB_val *value)
{
int err;
MDB_val key;
key.mv_size = sizeof(controller_db_key);
key.mv_data = &key_meta;
if((err = mdb_get(mdb_txn, mdb_dbi, &key, value)) != 0)
{
fprintf(stderr, "mdb_get error %s\n", mdb_strerror(err));
exit(1);
}
}
controller*
controller_read(MDB_env *mdb_env)
{
int err;
MDB_txn *mdb_txn;
MDB_dbi mdb_dbi;
controller *new_controller;
if((err = mdb_txn_begin(mdb_env, NULL, MDB_RDONLY, &mdb_txn)) != 0)
{
fprintf(stderr, "mdb_txn_begin error %s\n", mdb_strerror(err));
exit(1);
}
if((err = mdb_dbi_open(mdb_txn, "meta", 0, &mdb_dbi)) != 0)
{
switch(err)
{
case MDB_NOTFOUND:
mdb_txn_abort(mdb_txn);
new_controller = controller_create();
controller_save(new_controller, mdb_env);
return new_controller;
default:
fprintf(stderr, "mdb_txn_begin error %s\n", mdb_strerror(err));
exit(1);
}
}
new_controller = malloc(sizeof(*new_controller));
MDB_val value;
controller_read_single(mdb_txn, mdb_dbi, KEY_META_UUID, &value);
memmove(new_controller->uuid, (uuid_t*)value.mv_data, sizeof(uuid_t));
controller_read_single(mdb_txn, mdb_dbi, KEY_META_NAME, &value);
strncpy(new_controller->name, (char*)value.mv_data, CONTROLLER_NAME_LENGTH);
new_controller->name[CONTROLLER_NAME_LENGTH] = '\0';
controller_read_single(mdb_txn, mdb_dbi, KEY_META_PORT, &value);
new_controller->port = ((uint16_t*)value.mv_data)[0];
controller_read_single(mdb_txn, mdb_dbi, KEY_META_RELAY_COUNT, &value);
new_controller->relay_count = ((uint8_t*)value.mv_data)[0];
controller_debug(new_controller);
mdb_txn_abort(mdb_txn); // transaction is read only
return new_controller;
}
int
controller_save_single(MDB_txn *mdb_txn, MDB_dbi mdb_dbi, controller_db_key key_meta, MDB_val value)
{
int err;
MDB_val key;
key.mv_size = sizeof(controller_db_key);
key.mv_data = &key_meta;
if((err = mdb_put(mdb_txn, mdb_dbi, &key, &value, 0)) != 0)
{
fprintf(stderr, "mdb_put error %s\n", mdb_strerror(err));
mdb_txn_abort(mdb_txn);
return 1;
}
return 0;
}
int
controller_save(controller *cntrlr, MDB_env *mdb_env)
{
int err;
MDB_txn *mdb_txn;
MDB_dbi mdb_dbi;
MDB_val value;
controller_debug(cntrlr);
if((err = mdb_txn_begin(mdb_env, NULL, 0, &mdb_txn)) != 0)
{
fprintf(stderr, "mdb_txn_begin error %s\n", mdb_strerror(err));
exit(1);
}
if((err = mdb_dbi_open(mdb_txn, "meta", MDB_CREATE, &mdb_dbi)) != 0)
{
fprintf(stderr, "mdb_dbi_open error %s\n", mdb_strerror(err));
exit(1);
}
value.mv_size = sizeof(cntrlr->uuid);
value.mv_data = cntrlr->uuid;
if(controller_save_single(mdb_txn, mdb_dbi, KEY_META_UUID, value))
{
return 1;
}
value.mv_size = sizeof(char) * strlen(cntrlr->name);
value.mv_data = cntrlr->name;
if(controller_save_single(mdb_txn, mdb_dbi, KEY_META_NAME, value))
{
return 1;
}
value.mv_size = sizeof(cntrlr->port);
value.mv_data = &cntrlr->port;
if(controller_save_single(mdb_txn, mdb_dbi, KEY_META_PORT, value))
{
return 1;
}
value.mv_size = sizeof(cntrlr->relay_count);
value.mv_data = &cntrlr->relay_count;
if(controller_save_single(mdb_txn, mdb_dbi, KEY_META_RELAY_COUNT, value))
{
return 1;
}
mdb_txn_commit(mdb_txn);
return 0;
}
void
controller_debug(controller *cntrlr)
{

77
models/controller_load.c Normal file
View file

@ -0,0 +1,77 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <uuid/uuid.h>
#include <models/controller.h>
#include <macros.h>
static void
controller_load_single(MDB_txn *mdb_txn, MDB_dbi mdb_dbi, controller_db_key key_meta, MDB_val *value)
{
int err;
MDB_val key;
key.mv_size = sizeof(controller_db_key);
key.mv_data = &key_meta;
if((err = mdb_get(mdb_txn, mdb_dbi, &key, value)) != 0)
{
fprintf(stderr, "mdb_get error %s\n", mdb_strerror(err));
exit(1);
}
}
controller*
controller_load(MDB_env *mdb_env)
{
int err;
MDB_txn *mdb_txn;
MDB_dbi mdb_dbi;
controller *new_controller;
if((err = mdb_txn_begin(mdb_env, NULL, MDB_RDONLY, &mdb_txn)) != 0)
{
fprintf(stderr, "mdb_txn_begin error %s\n", mdb_strerror(err));
exit(1);
}
if((err = mdb_dbi_open(mdb_txn, "meta", 0, &mdb_dbi)) != 0)
{
switch(err)
{
case MDB_NOTFOUND:
mdb_txn_abort(mdb_txn);
new_controller = controller_create();
controller_save(new_controller, mdb_env);
return new_controller;
default:
fprintf(stderr, "mdb_txn_begin error %s\n", mdb_strerror(err));
exit(1);
}
}
new_controller = malloc(sizeof(*new_controller));
MDB_val value;
controller_load_single(mdb_txn, mdb_dbi, KEY_META_UUID, &value);
memmove(new_controller->uuid, (uuid_t*)value.mv_data, sizeof(uuid_t));
controller_load_single(mdb_txn, mdb_dbi, KEY_META_NAME, &value);
strncpy(new_controller->name, (char*)value.mv_data, CONTROLLER_NAME_LENGTH);
new_controller->name[CONTROLLER_NAME_LENGTH] = '\0';
controller_load_single(mdb_txn, mdb_dbi, KEY_META_PORT, &value);
new_controller->port = ((uint16_t*)value.mv_data)[0];
controller_load_single(mdb_txn, mdb_dbi, KEY_META_RELAY_COUNT, &value);
new_controller->relay_count = ((uint8_t*)value.mv_data)[0];
controller_debug(new_controller);
mdb_txn_abort(mdb_txn); // transaction is read only
return new_controller;
}

82
models/controller_save.c Normal file
View file

@ -0,0 +1,82 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <uuid/uuid.h>
#include <models/controller.h>
#include <macros.h>
int
controller_save_single(MDB_txn *mdb_txn, MDB_dbi mdb_dbi, controller_db_key key_meta, MDB_val value)
{
int err;
MDB_val key;
key.mv_size = sizeof(controller_db_key);
key.mv_data = &key_meta;
if((err = mdb_put(mdb_txn, mdb_dbi, &key, &value, 0)) != 0)
{
fprintf(stderr, "mdb_put error %s\n", mdb_strerror(err));
mdb_txn_abort(mdb_txn);
return 1;
}
return 0;
}
int
controller_save(controller *cntrlr, MDB_env *mdb_env)
{
int err;
MDB_txn *mdb_txn;
MDB_dbi mdb_dbi;
MDB_val value;
controller_debug(cntrlr);
if((err = mdb_txn_begin(mdb_env, NULL, 0, &mdb_txn)) != 0)
{
fprintf(stderr, "mdb_txn_begin error %s\n", mdb_strerror(err));
exit(1);
}
if((err = mdb_dbi_open(mdb_txn, "meta", MDB_CREATE, &mdb_dbi)) != 0)
{
fprintf(stderr, "mdb_dbi_open error %s\n", mdb_strerror(err));
exit(1);
}
value.mv_size = sizeof(cntrlr->uuid);
value.mv_data = cntrlr->uuid;
if(controller_save_single(mdb_txn, mdb_dbi, KEY_META_UUID, value))
{
return 1;
}
value.mv_size = sizeof(char) * strlen(cntrlr->name);
value.mv_data = cntrlr->name;
if(controller_save_single(mdb_txn, mdb_dbi, KEY_META_NAME, value))
{
return 1;
}
value.mv_size = sizeof(cntrlr->port);
value.mv_data = &cntrlr->port;
if(controller_save_single(mdb_txn, mdb_dbi, KEY_META_PORT, value))
{
return 1;
}
value.mv_size = sizeof(cntrlr->relay_count);
value.mv_data = &cntrlr->relay_count;
if(controller_save_single(mdb_txn, mdb_dbi, KEY_META_RELAY_COUNT, value))
{
return 1;
}
mdb_txn_commit(mdb_txn);
return 0;
}