From 176483d72f80324a42a369e307822fd26a1d08c1 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Tue, 16 Jun 2020 22:05:44 +0200 Subject: [PATCH] REFACTOR --- .gitignore | 4 ++-- CMakeLists.txt | 19 +++++++++---------- enums.h | 15 --------------- {vendor => include}/argparse.h | 0 {vendor => include}/cJSON.h | 0 {vendor => include}/confini.h | 0 {vendor => include}/mongoose.h | 0 {vendor => include}/mpack.h | 0 {vendor => src}/argparse.c | 0 {vendor => src}/cJSON.c | 0 command.c => src/command.c | 0 config.c => src/config.c | 0 {vendor => src}/confini.c | 0 database.c => src/database.c | 0 endpoint.c => src/endpoint.c | 0 .../endpoints}/api_v1_controllers.c | 0 .../endpoints}/api_v1_controllers_STR.c | 0 .../api_v1_controllers_STR_relays.c | 0 .../api_v1_controllers_STR_relays_INT.c | 0 .../endpoints}/api_v1_controllers_discover.c | 0 {endpoints => src/endpoints}/api_v1_relays.c | 0 .../endpoints}/api_v1_relays_tag_STR.c | 0 .../endpoints}/api_v1_schedules.c | 0 .../endpoints}/api_v1_schedules_STR.c | 0 .../endpoints}/api_v1_schedules_list.c | 0 .../endpoints}/api_v1_schedules_tag_STR.c | 0 {endpoints => src/endpoints}/api_v1_tags.c | 0 {handlers => src/handlers}/connection.c | 0 {helpers => src/helpers}/connect_server.c | 0 {helpers => src/helpers}/get_weekday.c | 0 {helpers => src/helpers}/parse_cli.c | 0 logger.c => src/logger.c | 0 main.c => src/main.c | 0 {models => src/models}/controller.c | 0 .../models}/junction_relay_schedule.c | 0 {models => src/models}/junction_tag.c | 0 {models => src/models}/period.c | 0 {models => src/models}/relay.c | 0 {models => src/models}/schedule.c | 0 {models => src/models}/tag.c | 0 {vendor => src}/mongoose.c | 0 {vendor => src}/mpack.c | 0 router.c => src/router.c | 0 {tests => test}/controller.testing.ini | 0 {tests => test}/core.testing.ini | 0 {tests => test}/run_tests.sh | 0 .../tavern_tests/0.0.get_all.tavern.yaml | 0 .../1.0.controllers_basic.tavern.yaml | 0 .../1.1.controller_relays_basic.tavern.yaml | 0 .../1.2.controllers_bad.tavern.yaml | 0 .../2.0.schedules_basic.tavern.yaml | 0 .../2.1.schedules_protected.tavern.yaml | 0 .../2.2.schedules_bad.tavern.yaml | 0 .../tavern_tests/3.0.tags.tavern.yaml | 0 .../tavern_utils/validate_controller.py | 0 .../tavern_utils/validate_relay.py | 0 .../tavern_utils/validate_schedule.py | 0 {tests => test}/tavern_utils/validate_tag.py | 0 toolchain-rpi.cmake | 18 ------------------ 59 files changed, 11 insertions(+), 45 deletions(-) delete mode 100644 enums.h rename {vendor => include}/argparse.h (100%) rename {vendor => include}/cJSON.h (100%) rename {vendor => include}/confini.h (100%) rename {vendor => include}/mongoose.h (100%) rename {vendor => include}/mpack.h (100%) rename {vendor => src}/argparse.c (100%) rename {vendor => src}/cJSON.c (100%) rename command.c => src/command.c (100%) rename config.c => src/config.c (100%) rename {vendor => src}/confini.c (100%) rename database.c => src/database.c (100%) rename endpoint.c => src/endpoint.c (100%) rename {endpoints => src/endpoints}/api_v1_controllers.c (100%) rename {endpoints => src/endpoints}/api_v1_controllers_STR.c (100%) rename {endpoints => src/endpoints}/api_v1_controllers_STR_relays.c (100%) rename {endpoints => src/endpoints}/api_v1_controllers_STR_relays_INT.c (100%) rename {endpoints => src/endpoints}/api_v1_controllers_discover.c (100%) rename {endpoints => src/endpoints}/api_v1_relays.c (100%) rename {endpoints => src/endpoints}/api_v1_relays_tag_STR.c (100%) rename {endpoints => src/endpoints}/api_v1_schedules.c (100%) rename {endpoints => src/endpoints}/api_v1_schedules_STR.c (100%) rename {endpoints => src/endpoints}/api_v1_schedules_list.c (100%) rename {endpoints => src/endpoints}/api_v1_schedules_tag_STR.c (100%) rename {endpoints => src/endpoints}/api_v1_tags.c (100%) rename {handlers => src/handlers}/connection.c (100%) rename {helpers => src/helpers}/connect_server.c (100%) rename {helpers => src/helpers}/get_weekday.c (100%) rename {helpers => src/helpers}/parse_cli.c (100%) rename logger.c => src/logger.c (100%) rename main.c => src/main.c (100%) rename {models => src/models}/controller.c (100%) rename {models => src/models}/junction_relay_schedule.c (100%) rename {models => src/models}/junction_tag.c (100%) rename {models => src/models}/period.c (100%) rename {models => src/models}/relay.c (100%) rename {models => src/models}/schedule.c (100%) rename {models => src/models}/tag.c (100%) rename {vendor => src}/mongoose.c (100%) rename {vendor => src}/mpack.c (100%) rename router.c => src/router.c (100%) rename {tests => test}/controller.testing.ini (100%) rename {tests => test}/core.testing.ini (100%) rename {tests => test}/run_tests.sh (100%) rename {tests => test}/tavern_tests/0.0.get_all.tavern.yaml (100%) rename {tests => test}/tavern_tests/1.0.controllers_basic.tavern.yaml (100%) rename {tests => test}/tavern_tests/1.1.controller_relays_basic.tavern.yaml (100%) rename {tests => test}/tavern_tests/1.2.controllers_bad.tavern.yaml (100%) rename {tests => test}/tavern_tests/2.0.schedules_basic.tavern.yaml (100%) rename {tests => test}/tavern_tests/2.1.schedules_protected.tavern.yaml (100%) rename {tests => test}/tavern_tests/2.2.schedules_bad.tavern.yaml (100%) rename {tests => test}/tavern_tests/3.0.tags.tavern.yaml (100%) rename {tests => test}/tavern_utils/validate_controller.py (100%) rename {tests => test}/tavern_utils/validate_relay.py (100%) rename {tests => test}/tavern_utils/validate_schedule.py (100%) rename {tests => test}/tavern_utils/validate_tag.py (100%) delete mode 100644 toolchain-rpi.cmake diff --git a/.gitignore b/.gitignore index 293edcd..4d3c2a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ build/ docs/ -tests/testing_tmp/ -tests/testing_bak/ +test/testing_tmp/ +test/testing_bak/ include/migrations/*.sql.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e2d682..d242e6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,26 +1,25 @@ cmake_minimum_required (VERSION 3.7) project(core) -add_executable(core main.c) +add_executable(core src/main.c) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wpedantic -Werror -Wall -Wextra -luuid -lsqlite3 -ffile-prefix-map=${CMAKE_SOURCE_DIR}/=/") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wpedantic -Werror -Wall -Wextra -luuid -lsqlite3 -ffile-prefix-map=${CMAKE_SOURCE_DIR}/src/=") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage") add_definitions("-DMG_ENABLE_EXTRA_ERRORS_DESC") -aux_source_directory(vendor VENDOR_SRC) # vendor first to put their warnings on top -aux_source_directory(. SRC_DIR) -aux_source_directory(models MODELS_SRC) -aux_source_directory(helpers HELPERS_SRC) -aux_source_directory(handlers HANDLERS_SRC) -aux_source_directory(endpoints ENDPOINTS_SRC) +aux_source_directory(src/ SRC_DIR) +aux_source_directory(src/models MODELS_SRC) +aux_source_directory(src/helpers HELPERS_SRC) +aux_source_directory(src/handlers HANDLERS_SRC) +aux_source_directory(src/endpoints ENDPOINTS_SRC) configure_file("core.ini" "core.ini" COPYONLY) add_dependencies(core migrations) -target_sources(core PRIVATE ${VENDOR_SRC} ${SRC_DIR} ${HANDLERS_SRC} ${HELPERS_SRC} ${MODELS_SRC} ${ENDPOINTS_SRC}) +target_sources(core PRIVATE ${SRC_DIR} ${HANDLERS_SRC} ${HELPERS_SRC} ${MODELS_SRC} ${ENDPOINTS_SRC}) target_include_directories(core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) target_include_directories(core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/vendor) @@ -53,7 +52,7 @@ add_custom_target(docs add_custom_target(test COMMAND ./run_tests.sh ${CMAKE_BINARY_DIR}/core "dev" DEPENDS core - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test ) add_custom_target(coverage COMMAND gcovr -s --root ${CMAKE_SOURCE_DIR} -e ${CMAKE_SOURCE_DIR}/vendor --html-details ${CMAKE_BINARY_DIR}/coverage.html --html-title "Emgauwa Core Coverage" ${CMAKE_BINARY_DIR}/CMakeFiles/core.dir diff --git a/enums.h b/enums.h deleted file mode 100644 index d773c08..0000000 --- a/enums.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef CORE_ENUM_H -#define CORE_ENUM_H - -enum control_mapping -{ - COMMAND_MAPPING_CODE = 0, - COMMAND_MAPPING_NAME = 1, - COMMAND_MAPPING_RELAY_NUM = 2, - COMMAND_MAPPING_SCHEDULES_ARRAY = 3, - COMMAND_MAPPING_SCHEDULE_ID = 4, - COMMAND_MAPPING_PERIODS_COUNT = 5, - COMMAND_MAPPING_PERIODS_BLOB = 6, -}; - -#endif /* CORE_ENUM_H */ diff --git a/vendor/argparse.h b/include/argparse.h similarity index 100% rename from vendor/argparse.h rename to include/argparse.h diff --git a/vendor/cJSON.h b/include/cJSON.h similarity index 100% rename from vendor/cJSON.h rename to include/cJSON.h diff --git a/vendor/confini.h b/include/confini.h similarity index 100% rename from vendor/confini.h rename to include/confini.h diff --git a/vendor/mongoose.h b/include/mongoose.h similarity index 100% rename from vendor/mongoose.h rename to include/mongoose.h diff --git a/vendor/mpack.h b/include/mpack.h similarity index 100% rename from vendor/mpack.h rename to include/mpack.h diff --git a/vendor/argparse.c b/src/argparse.c similarity index 100% rename from vendor/argparse.c rename to src/argparse.c diff --git a/vendor/cJSON.c b/src/cJSON.c similarity index 100% rename from vendor/cJSON.c rename to src/cJSON.c diff --git a/command.c b/src/command.c similarity index 100% rename from command.c rename to src/command.c diff --git a/config.c b/src/config.c similarity index 100% rename from config.c rename to src/config.c diff --git a/vendor/confini.c b/src/confini.c similarity index 100% rename from vendor/confini.c rename to src/confini.c diff --git a/database.c b/src/database.c similarity index 100% rename from database.c rename to src/database.c diff --git a/endpoint.c b/src/endpoint.c similarity index 100% rename from endpoint.c rename to src/endpoint.c diff --git a/endpoints/api_v1_controllers.c b/src/endpoints/api_v1_controllers.c similarity index 100% rename from endpoints/api_v1_controllers.c rename to src/endpoints/api_v1_controllers.c diff --git a/endpoints/api_v1_controllers_STR.c b/src/endpoints/api_v1_controllers_STR.c similarity index 100% rename from endpoints/api_v1_controllers_STR.c rename to src/endpoints/api_v1_controllers_STR.c diff --git a/endpoints/api_v1_controllers_STR_relays.c b/src/endpoints/api_v1_controllers_STR_relays.c similarity index 100% rename from endpoints/api_v1_controllers_STR_relays.c rename to src/endpoints/api_v1_controllers_STR_relays.c diff --git a/endpoints/api_v1_controllers_STR_relays_INT.c b/src/endpoints/api_v1_controllers_STR_relays_INT.c similarity index 100% rename from endpoints/api_v1_controllers_STR_relays_INT.c rename to src/endpoints/api_v1_controllers_STR_relays_INT.c diff --git a/endpoints/api_v1_controllers_discover.c b/src/endpoints/api_v1_controllers_discover.c similarity index 100% rename from endpoints/api_v1_controllers_discover.c rename to src/endpoints/api_v1_controllers_discover.c diff --git a/endpoints/api_v1_relays.c b/src/endpoints/api_v1_relays.c similarity index 100% rename from endpoints/api_v1_relays.c rename to src/endpoints/api_v1_relays.c diff --git a/endpoints/api_v1_relays_tag_STR.c b/src/endpoints/api_v1_relays_tag_STR.c similarity index 100% rename from endpoints/api_v1_relays_tag_STR.c rename to src/endpoints/api_v1_relays_tag_STR.c diff --git a/endpoints/api_v1_schedules.c b/src/endpoints/api_v1_schedules.c similarity index 100% rename from endpoints/api_v1_schedules.c rename to src/endpoints/api_v1_schedules.c diff --git a/endpoints/api_v1_schedules_STR.c b/src/endpoints/api_v1_schedules_STR.c similarity index 100% rename from endpoints/api_v1_schedules_STR.c rename to src/endpoints/api_v1_schedules_STR.c diff --git a/endpoints/api_v1_schedules_list.c b/src/endpoints/api_v1_schedules_list.c similarity index 100% rename from endpoints/api_v1_schedules_list.c rename to src/endpoints/api_v1_schedules_list.c diff --git a/endpoints/api_v1_schedules_tag_STR.c b/src/endpoints/api_v1_schedules_tag_STR.c similarity index 100% rename from endpoints/api_v1_schedules_tag_STR.c rename to src/endpoints/api_v1_schedules_tag_STR.c diff --git a/endpoints/api_v1_tags.c b/src/endpoints/api_v1_tags.c similarity index 100% rename from endpoints/api_v1_tags.c rename to src/endpoints/api_v1_tags.c diff --git a/handlers/connection.c b/src/handlers/connection.c similarity index 100% rename from handlers/connection.c rename to src/handlers/connection.c diff --git a/helpers/connect_server.c b/src/helpers/connect_server.c similarity index 100% rename from helpers/connect_server.c rename to src/helpers/connect_server.c diff --git a/helpers/get_weekday.c b/src/helpers/get_weekday.c similarity index 100% rename from helpers/get_weekday.c rename to src/helpers/get_weekday.c diff --git a/helpers/parse_cli.c b/src/helpers/parse_cli.c similarity index 100% rename from helpers/parse_cli.c rename to src/helpers/parse_cli.c diff --git a/logger.c b/src/logger.c similarity index 100% rename from logger.c rename to src/logger.c diff --git a/main.c b/src/main.c similarity index 100% rename from main.c rename to src/main.c diff --git a/models/controller.c b/src/models/controller.c similarity index 100% rename from models/controller.c rename to src/models/controller.c diff --git a/models/junction_relay_schedule.c b/src/models/junction_relay_schedule.c similarity index 100% rename from models/junction_relay_schedule.c rename to src/models/junction_relay_schedule.c diff --git a/models/junction_tag.c b/src/models/junction_tag.c similarity index 100% rename from models/junction_tag.c rename to src/models/junction_tag.c diff --git a/models/period.c b/src/models/period.c similarity index 100% rename from models/period.c rename to src/models/period.c diff --git a/models/relay.c b/src/models/relay.c similarity index 100% rename from models/relay.c rename to src/models/relay.c diff --git a/models/schedule.c b/src/models/schedule.c similarity index 100% rename from models/schedule.c rename to src/models/schedule.c diff --git a/models/tag.c b/src/models/tag.c similarity index 100% rename from models/tag.c rename to src/models/tag.c diff --git a/vendor/mongoose.c b/src/mongoose.c similarity index 100% rename from vendor/mongoose.c rename to src/mongoose.c diff --git a/vendor/mpack.c b/src/mpack.c similarity index 100% rename from vendor/mpack.c rename to src/mpack.c diff --git a/router.c b/src/router.c similarity index 100% rename from router.c rename to src/router.c diff --git a/tests/controller.testing.ini b/test/controller.testing.ini similarity index 100% rename from tests/controller.testing.ini rename to test/controller.testing.ini diff --git a/tests/core.testing.ini b/test/core.testing.ini similarity index 100% rename from tests/core.testing.ini rename to test/core.testing.ini diff --git a/tests/run_tests.sh b/test/run_tests.sh similarity index 100% rename from tests/run_tests.sh rename to test/run_tests.sh diff --git a/tests/tavern_tests/0.0.get_all.tavern.yaml b/test/tavern_tests/0.0.get_all.tavern.yaml similarity index 100% rename from tests/tavern_tests/0.0.get_all.tavern.yaml rename to test/tavern_tests/0.0.get_all.tavern.yaml diff --git a/tests/tavern_tests/1.0.controllers_basic.tavern.yaml b/test/tavern_tests/1.0.controllers_basic.tavern.yaml similarity index 100% rename from tests/tavern_tests/1.0.controllers_basic.tavern.yaml rename to test/tavern_tests/1.0.controllers_basic.tavern.yaml diff --git a/tests/tavern_tests/1.1.controller_relays_basic.tavern.yaml b/test/tavern_tests/1.1.controller_relays_basic.tavern.yaml similarity index 100% rename from tests/tavern_tests/1.1.controller_relays_basic.tavern.yaml rename to test/tavern_tests/1.1.controller_relays_basic.tavern.yaml diff --git a/tests/tavern_tests/1.2.controllers_bad.tavern.yaml b/test/tavern_tests/1.2.controllers_bad.tavern.yaml similarity index 100% rename from tests/tavern_tests/1.2.controllers_bad.tavern.yaml rename to test/tavern_tests/1.2.controllers_bad.tavern.yaml diff --git a/tests/tavern_tests/2.0.schedules_basic.tavern.yaml b/test/tavern_tests/2.0.schedules_basic.tavern.yaml similarity index 100% rename from tests/tavern_tests/2.0.schedules_basic.tavern.yaml rename to test/tavern_tests/2.0.schedules_basic.tavern.yaml diff --git a/tests/tavern_tests/2.1.schedules_protected.tavern.yaml b/test/tavern_tests/2.1.schedules_protected.tavern.yaml similarity index 100% rename from tests/tavern_tests/2.1.schedules_protected.tavern.yaml rename to test/tavern_tests/2.1.schedules_protected.tavern.yaml diff --git a/tests/tavern_tests/2.2.schedules_bad.tavern.yaml b/test/tavern_tests/2.2.schedules_bad.tavern.yaml similarity index 100% rename from tests/tavern_tests/2.2.schedules_bad.tavern.yaml rename to test/tavern_tests/2.2.schedules_bad.tavern.yaml diff --git a/tests/tavern_tests/3.0.tags.tavern.yaml b/test/tavern_tests/3.0.tags.tavern.yaml similarity index 100% rename from tests/tavern_tests/3.0.tags.tavern.yaml rename to test/tavern_tests/3.0.tags.tavern.yaml diff --git a/tests/tavern_utils/validate_controller.py b/test/tavern_utils/validate_controller.py similarity index 100% rename from tests/tavern_utils/validate_controller.py rename to test/tavern_utils/validate_controller.py diff --git a/tests/tavern_utils/validate_relay.py b/test/tavern_utils/validate_relay.py similarity index 100% rename from tests/tavern_utils/validate_relay.py rename to test/tavern_utils/validate_relay.py diff --git a/tests/tavern_utils/validate_schedule.py b/test/tavern_utils/validate_schedule.py similarity index 100% rename from tests/tavern_utils/validate_schedule.py rename to test/tavern_utils/validate_schedule.py diff --git a/tests/tavern_utils/validate_tag.py b/test/tavern_utils/validate_tag.py similarity index 100% rename from tests/tavern_utils/validate_tag.py rename to test/tavern_utils/validate_tag.py diff --git a/toolchain-rpi.cmake b/toolchain-rpi.cmake deleted file mode 100644 index 21fe457..0000000 --- a/toolchain-rpi.cmake +++ /dev/null @@ -1,18 +0,0 @@ -set(CMAKE_C_COMPILER /usr/bin/arm-none-eabi-gcc) -set(CMAKE_C_COMPILER_WORKS 1) - -set(ARM-SYSROOT /usr/arm-none-eabi) - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv6zk+fp") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=arm1176jzf-s") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=arm1176jzf-s") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${ARM-SYSROOT}" CACHE INTERNAL "" FORCE) - -set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --sysroot=${ARM-SYSROOT}" CACHE INTERNAL "" FORCE) - -set(CMAKE_FIND_ROOT_PATH ${ARM-SYSROOT}) -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)