Merge branch 'rewrite' into dev
This commit is contained in:
commit
b68cdd224e
129 changed files with 40047 additions and 3788 deletions
10
.gitignore
vendored
10
.gitignore
vendored
|
|
@ -1,5 +1,7 @@
|
|||
build
|
||||
cmake-build-debug
|
||||
.idea
|
||||
build/
|
||||
docs/
|
||||
|
||||
sql/*.h
|
||||
tests/testing_tmp/
|
||||
tests/testing_bak/
|
||||
|
||||
include/migrations/*.sql.h
|
||||
|
|
|
|||
3
.gitmodules
vendored
3
.gitmodules
vendored
|
|
@ -1,3 +0,0 @@
|
|||
[submodule "drogon"]
|
||||
path = drogon
|
||||
url = https://github.com/an-tao/drogon.git
|
||||
|
|
@ -1,71 +1,28 @@
|
|||
cmake_minimum_required (VERSION 3.2)
|
||||
cmake_minimum_required (VERSION 3.7)
|
||||
project(core)
|
||||
|
||||
include(CheckIncludeFileCXX)
|
||||
add_executable(core main.c)
|
||||
|
||||
check_include_file_cxx(any HAS_ANY)
|
||||
check_include_file_cxx(string_view HAS_STRING_VIEW)
|
||||
if(HAS_ANY AND HAS_STRING_VIEW)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
else()
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
endif()
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wpedantic -Werror -Wall -Wextra -luuid -lsqlite3 -g -fprofile-arcs -ftest-coverage")
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE)
|
||||
add_definitions("-DSOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}")
|
||||
|
||||
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wall -Wextra -Werror -g -latomic")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g")
|
||||
add_definitions("-DMG_ENABLE_EXTRA_ERRORS_DESC")
|
||||
|
||||
##########
|
||||
# If you include the drogon source code locally in your project, use this method to add drogon
|
||||
# add_subdirectory(drogon)
|
||||
# set(Drogon_DIR ${PROJECT_BINARY_DIR}/drogon)
|
||||
# find_package(Drogon CONFIG REQUIRED NO_DEFAULT_PATH)
|
||||
# include_directories(${DROGON_INCLUDE_DIRS})
|
||||
# link_libraries(${DROGON_LIBRARIES})
|
||||
##########
|
||||
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)
|
||||
|
||||
# find_package(Drogon CONFIG REQUIRED)
|
||||
# include_directories(${DROGON_INCLUDE_DIRS})
|
||||
# link_libraries(${DROGON_LIBRARIES})
|
||||
configure_file("core.ini" "core.ini" COPYONLY)
|
||||
|
||||
if(CMAKE_CXX_STANDARD LESS 17)
|
||||
#With C++14, use boost to support any and string_view
|
||||
message(STATUS "use c++14")
|
||||
find_package(Boost 1.61.0 REQUIRED)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
else()
|
||||
message(STATUS "use c++17")
|
||||
endif()
|
||||
target_sources(core PRIVATE ${VENDOR_SRC} ${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)
|
||||
|
||||
aux_source_directory(./ SRC_DIR)
|
||||
aux_source_directory(controllers CTL_SRC)
|
||||
aux_source_directory(filters FILTER_SRC)
|
||||
aux_source_directory(plugins PLUGIN_SRC)
|
||||
aux_source_directory(models MODEL_SRC)
|
||||
aux_source_directory(helpers HELPER_SRC)
|
||||
|
||||
file(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/views/*.csp)
|
||||
foreach(cspFile ${SCP_LIST})
|
||||
message(STATUS "cspFile:" ${cspFile})
|
||||
EXEC_PROGRAM(basename ARGS "${cspFile} .csp" OUTPUT_VARIABLE classname)
|
||||
message(STATUS "view classname:" ${classname})
|
||||
ADD_CUSTOM_COMMAND(OUTPUT ${classname}.h ${classname}.cc
|
||||
COMMAND drogon_ctl
|
||||
ARGS create view ${cspFile}
|
||||
DEPENDS ${cspFile}
|
||||
VERBATIM )
|
||||
set(VIEWSRC ${VIEWSRC} ${classname}.cc)
|
||||
endforeach()
|
||||
|
||||
configure_file("config.json" "config.json" COPYONLY)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_executable(core ${SRC_DIR} ${CTL_SRC} ${FILTER_SRC} ${VIEWSRC} ${PLUGIN_SRC} ${MODEL_SRC} ${HELPER_SRC})
|
||||
|
||||
add_subdirectory(drogon)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE drogon)
|
||||
|
||||
add_custom_target(migrations
|
||||
COMMAND ./compile_migrations.sh
|
||||
|
|
@ -73,23 +30,32 @@ add_custom_target(migrations
|
|||
)
|
||||
|
||||
add_custom_target(run
|
||||
COMMAND core
|
||||
COMMAND ./core start
|
||||
DEPENDS core
|
||||
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
|
||||
)
|
||||
add_custom_target(debug
|
||||
COMMAND valgrind ./core
|
||||
COMMAND valgrind ./core start
|
||||
DEPENDS core
|
||||
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
|
||||
)
|
||||
add_custom_target(debug-full
|
||||
COMMAND valgrind --leak-check=full --show-leak-kinds=all ./core
|
||||
COMMAND valgrind --leak-check=full --show-leak-kinds=all ./core start
|
||||
DEPENDS core
|
||||
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
|
||||
)
|
||||
add_custom_target(docs
|
||||
COMMAND doxygen
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
|
||||
add_custom_target(test
|
||||
COMMAND ./run_tests.sh ${CMAKE_BINARY_DIR}/core ${CMAKE_SOURCE_DIR}/config.testing.json
|
||||
COMMAND ./run_tests.sh ${CMAKE_BINARY_DIR}/core "dev"
|
||||
DEPENDS core
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tavern_tests
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
|
||||
)
|
||||
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
|
||||
DEPENDS test
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
|
|
|
|||
141
command.c
Normal file
141
command.c
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <command.h>
|
||||
#include <mpack.h>
|
||||
#include <logger.h>
|
||||
#include <helpers.h>
|
||||
#include <enums.h>
|
||||
#include <models/controller.h>
|
||||
|
||||
int
|
||||
command_set_relay_schedule(relay_t *relay)
|
||||
{
|
||||
controller_t *controller = controller_get_by_id(relay->controller_id);
|
||||
if(!controller)
|
||||
{
|
||||
LOG_ERROR("couldn't find controller\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* payload;
|
||||
size_t payload_size;
|
||||
mpack_writer_t writer;
|
||||
mpack_writer_init_growable(&writer, &payload, &payload_size);
|
||||
|
||||
// 3 = code, relay num, relay name, schedules(array)
|
||||
mpack_start_map(&writer, 3);
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_CODE);
|
||||
mpack_write_u8(&writer, COMMAND_CODE_SET_SCHEDULE);
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_RELAY_NUM);
|
||||
mpack_write_u8(&writer, relay->number);
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_SCHEDULES_ARRAY);
|
||||
// 7 = days of week
|
||||
mpack_start_array(&writer, 7);
|
||||
for(int i = 0; i < 7; ++i)
|
||||
{
|
||||
uint16_t *periods_blob = schedule_periods_to_blob(relay->schedules[i]);
|
||||
uint16_t periods_count = periods_blob[0];
|
||||
|
||||
// 3 = code, relaynum, schedules(array)
|
||||
mpack_start_map(&writer, 3);
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_PERIODS_COUNT);
|
||||
mpack_write_u16(&writer, periods_count);
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_SCHEDULE_ID);
|
||||
mpack_write_bin(&writer, (char*)relay->schedules[0]->uid, sizeof(uuid_t));
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_PERIODS_BLOB);
|
||||
// periods + 1 to skip length in periods[0]
|
||||
// periods_count * 2 because each uint16_t is a timestamp. 2 are start and end
|
||||
mpack_write_bin(&writer, (char*)(periods_blob + 1), sizeof(uint16_t) * periods_count * 2);
|
||||
|
||||
mpack_finish_map(&writer);
|
||||
|
||||
free(periods_blob);
|
||||
}
|
||||
mpack_finish_array(&writer);
|
||||
|
||||
mpack_finish_map(&writer);
|
||||
|
||||
// finish writing
|
||||
if (mpack_writer_destroy(&writer) != mpack_ok)
|
||||
{
|
||||
LOG_ERROR("an error occurred encoding the data");
|
||||
controller_free(controller);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int result = command_send(controller, COMMAND_CODE_SET_SCHEDULE, payload, payload_size);
|
||||
|
||||
controller_free(controller);
|
||||
free(payload);
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
command_set_controller_name(controller_t *controller)
|
||||
{
|
||||
char* payload;
|
||||
size_t payload_size;
|
||||
mpack_writer_t writer;
|
||||
mpack_writer_init_growable(&writer, &payload, &payload_size);
|
||||
|
||||
// write the example on the msgpack homepage
|
||||
mpack_start_map(&writer, 2);
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_CODE);
|
||||
mpack_write_u8(&writer, COMMAND_CODE_SET_NAME);
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_NAME);
|
||||
mpack_write_cstr(&writer, controller->name);
|
||||
|
||||
mpack_finish_map(&writer);
|
||||
|
||||
// finish writing
|
||||
if (mpack_writer_destroy(&writer) != mpack_ok)
|
||||
{
|
||||
LOG_ERROR("an error occurred encoding the data");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int result = command_send(controller, COMMAND_CODE_SET_NAME, payload, payload_size);
|
||||
|
||||
free(payload);
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
command_send(controller_t *controller, int command_code, char *payload, uint32_t payload_size)
|
||||
{
|
||||
LOG_DEBUG("commanding %d\n", command_code);
|
||||
|
||||
int bytes_transferred;
|
||||
|
||||
int fd_controller = helper_connect_tcp_server(controller->ip, controller->port);
|
||||
|
||||
if(fd_controller == -1)
|
||||
{
|
||||
LOG_ERROR("can't open command socket %s:%d\n", controller->ip, controller->port);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if((bytes_transferred = send(fd_controller, &payload_size, sizeof(payload_size), 0)) <= 0)
|
||||
{
|
||||
LOG_ERROR("error during sending size\n");
|
||||
return 1;
|
||||
}
|
||||
if((bytes_transferred = send(fd_controller, payload, payload_size, 0)) <= 0)
|
||||
{
|
||||
LOG_ERROR("error during sending\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
close(fd_controller);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ migration_num=0;
|
|||
|
||||
while [ -f sql/migration_$migration_num.sql ]
|
||||
do
|
||||
xxd -i sql/migration_$migration_num.sql | sed 's/\([0-9a-f]\)$/\0, 0x00/' > sql/migration_$migration_num.h
|
||||
xxd -i sql/migration_$migration_num.sql | sed 's/\([0-9a-f]\)$/\0, 0x00/' > include/migrations/$migration_num.sql.h
|
||||
((migration_num++));
|
||||
done;
|
||||
|
||||
|
|
|
|||
74
config.c
Normal file
74
config.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <logger.h>
|
||||
#include <config.h>
|
||||
|
||||
config_t global_config;
|
||||
|
||||
#define CONFINI_IS_KEY(SECTION, KEY) \
|
||||
(ini_array_match(SECTION, disp->append_to, '.', disp->format) && \
|
||||
ini_string_match_ii(KEY, disp->data, disp->format))
|
||||
|
||||
int
|
||||
config_load(IniDispatch *disp, void *config_void)
|
||||
{
|
||||
config_t *config = (config_t*)config_void;
|
||||
|
||||
if(disp->type == INI_KEY)
|
||||
{
|
||||
if(CONFINI_IS_KEY("core", "database"))
|
||||
{
|
||||
config->database = malloc(sizeof(char) * (strlen(disp->value) + 1));
|
||||
strcpy(config->database, disp->value);
|
||||
return 0;
|
||||
}
|
||||
if(CONFINI_IS_KEY("core", "log-level"))
|
||||
{
|
||||
if(strcasecmp(disp->value, "trace") == 0)
|
||||
{
|
||||
config->log_level = LOG_LEVEL_TRACE;
|
||||
return 0;
|
||||
}
|
||||
if(strcasecmp(disp->value, "debug") == 0)
|
||||
{
|
||||
config->log_level = LOG_LEVEL_DEBUG;
|
||||
return 0;
|
||||
}
|
||||
if(strcasecmp(disp->value, "info") == 0)
|
||||
{
|
||||
config->log_level = LOG_LEVEL_INFO;
|
||||
return 0;
|
||||
}
|
||||
if(strcasecmp(disp->value, "warn") == 0)
|
||||
{
|
||||
config->log_level = LOG_LEVEL_WARN;
|
||||
return 0;
|
||||
}
|
||||
if(strcasecmp(disp->value, "error") == 0)
|
||||
{
|
||||
config->log_level = LOG_LEVEL_ERROR;
|
||||
return 0;
|
||||
}
|
||||
if(strcasecmp(disp->value, "fatal") == 0)
|
||||
{
|
||||
config->log_level = LOG_LEVEL_FATAL;
|
||||
return 0;
|
||||
}
|
||||
LOG_WARN("invalid log-level '%s'\n", disp->value);
|
||||
return 0;
|
||||
}
|
||||
if(CONFINI_IS_KEY("core", "discovery-port"))
|
||||
{
|
||||
config->discovery_port = atoi(disp->value);
|
||||
return 0;
|
||||
}
|
||||
if(CONFINI_IS_KEY("core", "server-port"))
|
||||
{
|
||||
strcpy(config->server_port, disp->value);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
23
config.cc
23
config.cc
|
|
@ -1,23 +0,0 @@
|
|||
#include "config.h"
|
||||
|
||||
namespace config
|
||||
{
|
||||
char version[] = "0.0.1";
|
||||
|
||||
uint16_t discover_max_client_backlog = 20;
|
||||
uint16_t discover_port_dev = 4421;
|
||||
uint16_t discover_port_test = 4420;
|
||||
uint16_t discover_port = 4419;
|
||||
uint16_t discover_timeout_ms = 2000;
|
||||
uint8_t discover_code_accept = 0;
|
||||
uint8_t discover_code_reject = 100;
|
||||
|
||||
uint8_t command_code_get_time = 1;
|
||||
uint8_t command_code_get_id = 2;
|
||||
uint8_t command_code_set_name = 100;
|
||||
uint8_t command_code_get_name = 101;
|
||||
uint8_t command_code_set_schedule = 102;
|
||||
uint8_t command_code_get_schedule = 103;
|
||||
uint8_t command_code_set_relay_name = 104;
|
||||
uint8_t command_code_get_relay_name = 105;
|
||||
}
|
||||
27
config.h
27
config.h
|
|
@ -1,27 +0,0 @@
|
|||
#ifndef EMGAUWA_CORE_CONFIG_H
|
||||
#define EMGAUWA_CORE_CONFIG_H
|
||||
|
||||
#include <stdint-gcc.h>
|
||||
|
||||
namespace config
|
||||
{
|
||||
extern char version[];
|
||||
|
||||
extern uint16_t discover_max_client_backlog;
|
||||
extern uint16_t discover_port_dev;
|
||||
extern uint16_t discover_port;
|
||||
extern uint16_t discover_timeout_ms;
|
||||
extern uint8_t discover_code_accept;
|
||||
extern uint8_t discover_code_reject;
|
||||
|
||||
extern uint8_t command_code_get_time;
|
||||
extern uint8_t command_code_get_id;
|
||||
extern uint8_t command_code_set_name;
|
||||
extern uint8_t command_code_get_name;
|
||||
extern uint8_t command_code_set_schedule;
|
||||
extern uint8_t command_code_get_schedule;
|
||||
extern uint8_t command_code_set_relay_name;
|
||||
extern uint8_t command_code_get_relay_name;
|
||||
}
|
||||
|
||||
#endif //EMGAUWA_CORE_CONFIG_H
|
||||
12
config.json
12
config.json
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"listeners": [
|
||||
{
|
||||
"address": "0.0.0.0",
|
||||
"port": 5000,
|
||||
"https": false
|
||||
}
|
||||
],
|
||||
"custom_config": {
|
||||
"db_name": "core.sqlite"
|
||||
}
|
||||
}
|
||||
185
config.template
185
config.template
|
|
@ -1,185 +0,0 @@
|
|||
/* This is a JSON format configuration file
|
||||
*/
|
||||
{
|
||||
/*
|
||||
//ssl:The global ssl files setting
|
||||
"ssl": {
|
||||
"cert": "../../trantor/trantor/tests/server.pem",
|
||||
"key": "../../trantor/trantor/tests/server.pem"
|
||||
},
|
||||
"listeners": [
|
||||
{
|
||||
//address: Ip address,0.0.0.0 by default
|
||||
"address": "0.0.0.0",
|
||||
//port: Port number
|
||||
"port": 80,
|
||||
//https: If true, use https for security,false by default
|
||||
"https": false
|
||||
},
|
||||
{
|
||||
"address": "0.0.0.0",
|
||||
"port": 443,
|
||||
"https": true,
|
||||
//cert,key: Cert file path and key file path, empty by default,
|
||||
//if empty, use the global setting
|
||||
"cert": "",
|
||||
"key": ""
|
||||
}
|
||||
],
|
||||
"db_clients": [
|
||||
{
|
||||
//name: Name of the client,'default' by default
|
||||
//"name":"",
|
||||
//rdbms: Server type, postgresql,mysql or sqlite3, "postgresql" by default
|
||||
"rdbms": "postgresql",
|
||||
//filename: Sqlite3 db file name
|
||||
//"filename":"",
|
||||
//host: Server address,localhost by default
|
||||
"host": "127.0.0.1",
|
||||
//port: Server port, 5432 by default
|
||||
"port": 5432,
|
||||
//dbname: Database name
|
||||
"dbname": "test",
|
||||
//user: 'postgres' by default
|
||||
"user": "",
|
||||
//passwd: '' by default
|
||||
"passwd": "",
|
||||
//is_fast: false by default, if it is true, the client is faster but user can't call
|
||||
//any synchronous interface of it.
|
||||
"is_fast": false,
|
||||
//connection_number: 1 by default, valid only if is_fast is false.
|
||||
"connection_number": 1
|
||||
}
|
||||
],*/
|
||||
"app": {
|
||||
//threads_num: The number of IO threads, 1 by default, if the value is set to 0, the number of threads
|
||||
//is the number of CPU cores
|
||||
"threads_num": 1,
|
||||
//enable_session: False by default
|
||||
"enable_session": false,
|
||||
"session_timeout": 0,
|
||||
//document_root: Root path of HTTP document, defaut path is ./
|
||||
"document_root": "./",
|
||||
//home_page: Set the HTML file of the home page, the default value is "index.html"
|
||||
//If there isn't any handler registered to the path "/", the home page file in the "document_root" is send to clients as a response
|
||||
//to the request for "/".
|
||||
"home_page": "index.html",
|
||||
//upload_path: The path to save the uploaded file. "uploads" by default.
|
||||
//If the path isn't prefixed with /, ./ or ../,
|
||||
//it is relative path of document_root path
|
||||
"upload_path": "uploads",
|
||||
/* file_types:
|
||||
* HTTP download file types,The file types supported by drogon
|
||||
* by default are "html", "js", "css", "xml", "xsl", "txt", "svg",
|
||||
* "ttf", "otf", "woff2", "woff" , "eot", "png", "jpg", "jpeg",
|
||||
* "gif", "bmp", "ico", "icns", etc. */
|
||||
"file_types": [
|
||||
"gif",
|
||||
"png",
|
||||
"jpg",
|
||||
"js",
|
||||
"css",
|
||||
"html",
|
||||
"ico",
|
||||
"swf",
|
||||
"xap",
|
||||
"apk",
|
||||
"cur",
|
||||
"xml"
|
||||
],
|
||||
//max_connections: maximum connections number,100000 by default
|
||||
"max_connections": 100000,
|
||||
//max_connections_per_ip: maximum connections number per clinet,0 by default which means no limit
|
||||
"max_connections_per_ip": 0,
|
||||
//Load_dynamic_views: False by default, when set to true, drogon
|
||||
//compiles and loads dynamically "CSP View Files" in directories defined
|
||||
//by "dynamic_views_path"
|
||||
"load_dynamic_views": false,
|
||||
//dynamic_views_path: If the path isn't prefixed with /, ./ or ../,
|
||||
//it is relative path of document_root path
|
||||
"dynamic_views_path": [
|
||||
"./views"
|
||||
],
|
||||
//log: Set log output, drogon output logs to stdout by default
|
||||
"log": {
|
||||
//log_path: Log file path,empty by default,in which case,logs are output to the stdout
|
||||
//"log_path": "./",
|
||||
//logfile_base_name: Log file base name,empty by default which means drogon names logfile as
|
||||
//drogon.log ...
|
||||
"logfile_base_name": "",
|
||||
//log_size_limit: 100000000 bytes by default,
|
||||
//When the log file size reaches "log_size_limit", the log file is switched.
|
||||
"log_size_limit": 100000000,
|
||||
//log_level: "DEBUG" by default,options:"TRACE","DEBUG","INFO","WARN"
|
||||
//The TRACE level is only valid when built in DEBUG mode.
|
||||
"log_level": "DEBUG"
|
||||
},
|
||||
//run_as_daemon: False by default
|
||||
"run_as_daemon": false,
|
||||
//relaunch_on_error: False by default, if true, the program will be restart by the parent after exiting;
|
||||
"relaunch_on_error": false,
|
||||
//use_sendfile: True by default, if ture, the program
|
||||
//uses sendfile() system-call to send static files to clients;
|
||||
"use_sendfile": true,
|
||||
//use_gzip: True by default, use gzip to compress the response body's content;
|
||||
"use_gzip": true,
|
||||
//static_files_cache_time: 5 (seconds) by default, the time in which the static file response is cached,
|
||||
//0 means cache forever, the negative value means no cache
|
||||
"static_files_cache_time": 5,
|
||||
//simple_controllers_map: Used to configure mapping from path to simple controller
|
||||
"simple_controllers_map": [{
|
||||
"path": "/path/name",
|
||||
"controller": "controllerClassName",
|
||||
"http_methods": [
|
||||
"get",
|
||||
"post"
|
||||
],
|
||||
"filters": [
|
||||
"FilterClassName"
|
||||
]
|
||||
}],
|
||||
//idle_connection_timeout: Defaults to 60 seconds, the lifetime
|
||||
//of the connection without read or write
|
||||
"idle_connection_timeout": 60,
|
||||
//server_header_field: Set the 'server' header field in each response sent by drogon,
|
||||
//empty string by default with which the 'server' header field is set to "Server: drogon/version string\r\n"
|
||||
"server_header_field": "",
|
||||
//keepalive_requests: Set the maximum number of requests that can be served through one keep-alive connection.
|
||||
//After the maximum number of requests are made, the connection is closed.
|
||||
//The default value of 0 means no limit.
|
||||
"keepalive_requests": 0,
|
||||
//pipelining_requests: Set the maximum number of unhandled requests that can be cached in pipelining buffer.
|
||||
//After the maximum number of requests are made, the connection is closed.
|
||||
//The default value of 0 means no limit.
|
||||
"pipelining_requests": 0,
|
||||
//gzip_static: If it is set to true, when the client requests a static file, drogon first finds the compressed
|
||||
//file with the extension ".gz" in the same path and send the compressed file to the client.
|
||||
//The default value of gzip_static is true.
|
||||
"gzip_static": true,
|
||||
//client_max_body_size: Set the maximum body size of HTTP requests received by drogon. The default value is "1M".
|
||||
//One can set it to "1024", "1k", "10M", "1G", etc. Setting it to "" means no limit.
|
||||
"client_max_body_size": "1M",
|
||||
//max_memory_body_size: Set the maximum body size in memory of HTTP requests received by drogon. The default value is "64K" bytes.
|
||||
//If the body size of a HTTP request exceeds this limit, the body is stored to a temporary file for processing.
|
||||
//Setting it to "" means no limit.
|
||||
"client_max_memory_body_size": "64K",
|
||||
//client_max_websocket_message_size: Set the maximum size of messages sent by WebSocket client. The default value is "128K".
|
||||
//One can set it to "1024", "1k", "10M", "1G", etc. Setting it to "" means no limit.
|
||||
"client_max_websocket_message_size": "128K"
|
||||
},
|
||||
//plugins: Define all plugins running in the application
|
||||
"plugins": [{
|
||||
//name: The class name of the plugin
|
||||
//"name": "TestPlugin",
|
||||
//dependencies: Plugins that the plugin depends on. It can be commented out
|
||||
"dependencies": [],
|
||||
//config: The configuration of the plugin. This json object is the parameter to initialize the plugin.
|
||||
//It can be commented out
|
||||
"config": {
|
||||
"heartbeat_interval": 2
|
||||
}
|
||||
|
||||
}],
|
||||
//custom_config: custom configuration for users. This object can be get by the app().getCustomConfig() method.
|
||||
"custom_config": {}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"listeners": [
|
||||
{
|
||||
"address": "0.0.0.0",
|
||||
"port": 5000,
|
||||
"https": false
|
||||
}
|
||||
],
|
||||
"custom_config": {
|
||||
"db_name": "core.testing.sqlite"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,180 +0,0 @@
|
|||
#include <models/controller_dbo.h>
|
||||
#include <config.h>
|
||||
#include <enums.h>
|
||||
#include <mpack.h>
|
||||
#include "api_v1_controllers.h"
|
||||
using namespace api::v1;
|
||||
|
||||
void
|
||||
controllers::get_all(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
|
||||
{
|
||||
controller_dbo **all_controllers = controller_dbo::get_all();
|
||||
Json::Value all_controllers_json(Json::arrayValue);
|
||||
|
||||
for(int i = 0; all_controllers[i] != nullptr; i++)
|
||||
{
|
||||
all_controllers_json.append(all_controllers[i]->to_json());
|
||||
}
|
||||
|
||||
auto resp = HttpResponse::newHttpJsonResponse(all_controllers_json);
|
||||
|
||||
callback(resp);
|
||||
|
||||
controller_dbo::free_list(all_controllers);
|
||||
}
|
||||
|
||||
void
|
||||
controllers::get_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string& controller_id_str)
|
||||
{
|
||||
uuid_t controller_id;
|
||||
if(uuid_parse(controller_id_str.c_str(), controller_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
controller_dbo **controllers = controller_dbo::get_by_simple("id", controller_id, (intptr_t) &sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
if(controllers[0])
|
||||
{
|
||||
auto resp = HttpResponse::newHttpJsonResponse(controllers[0]->to_json());
|
||||
|
||||
callback(resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k404NotFound);
|
||||
|
||||
callback(resp);
|
||||
}
|
||||
controller_dbo::free_list(controllers);
|
||||
}
|
||||
|
||||
void
|
||||
controllers::get_one_by_tag(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string &controller_tag)
|
||||
{
|
||||
controller_dbo **controllers = controller_dbo::get_by_simple("tag", controller_tag.c_str(), (intptr_t) &sqlite3_bind_text, -1);
|
||||
|
||||
if(controllers[0])
|
||||
{
|
||||
auto resp = HttpResponse::newHttpJsonResponse(controllers[0]->to_json());
|
||||
|
||||
callback(resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k404NotFound);
|
||||
|
||||
callback(resp);
|
||||
}
|
||||
controller_dbo::free_list(controllers);
|
||||
}
|
||||
|
||||
void
|
||||
controllers::delete_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, const std::string& controller_id_str)
|
||||
{
|
||||
uuid_t controller_id;
|
||||
if(uuid_parse(controller_id_str.c_str(), controller_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
controller_dbo **controllers = controller_dbo::get_by_simple("id", controller_id, (intptr_t) &sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
if(controllers[0])
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
if(!controllers[0]->remove())
|
||||
{
|
||||
resp->setStatusCode(k500InternalServerError);
|
||||
}
|
||||
|
||||
callback(resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k404NotFound);
|
||||
|
||||
callback(resp);
|
||||
}
|
||||
controller_dbo::free_list(controllers);
|
||||
}
|
||||
|
||||
void
|
||||
controllers::put_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string &controller_id_str)
|
||||
{
|
||||
Json::Value body = *req->getJsonObject();
|
||||
|
||||
uuid_t controller_id;
|
||||
if(uuid_parse(controller_id_str.c_str(), controller_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
controller_dbo **controllers = controller_dbo::get_by_simple("id", controller_id, (intptr_t) &sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
if(controllers[0])
|
||||
{
|
||||
strncpy(controllers[0]->name, body["name"].asCString(), 127);
|
||||
strncpy(controllers[0]->ip, body["ip"].asCString(), 16);
|
||||
|
||||
controllers[0]->name[127] = '\0';
|
||||
controllers[0]->ip[16] = '\0';
|
||||
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
if(controllers[0]->update())
|
||||
{
|
||||
char* data;
|
||||
size_t size;
|
||||
mpack_writer_t writer;
|
||||
mpack_writer_init_growable(&writer, &data, &size);
|
||||
|
||||
// write the example on the msgpack homepage
|
||||
mpack_start_map(&writer, 2);
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_CODE);
|
||||
mpack_write_u8(&writer, config::command_code_set_name);
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_NAME);
|
||||
mpack_write_cstr(&writer, controllers[0]->name);
|
||||
|
||||
mpack_finish_map(&writer);
|
||||
|
||||
// finish writing
|
||||
if (mpack_writer_destroy(&writer) != mpack_ok) {
|
||||
LOG_ERROR << "an error occurred encoding the data";
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k500InternalServerError);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
controllers[0]->command(config::command_code_set_name, data, size);
|
||||
resp = HttpResponse::newHttpJsonResponse(controllers[0]->to_json());
|
||||
}
|
||||
else
|
||||
{
|
||||
resp->setStatusCode(k500InternalServerError);
|
||||
}
|
||||
|
||||
callback(resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k404NotFound);
|
||||
|
||||
callback(resp);
|
||||
}
|
||||
controller_dbo::free_list(controllers);
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
#pragma once
|
||||
#include <drogon/HttpController.h>
|
||||
using namespace drogon;
|
||||
namespace api::v1
|
||||
{
|
||||
class controllers:public drogon::HttpController<controllers>
|
||||
{
|
||||
public:
|
||||
METHOD_LIST_BEGIN
|
||||
METHOD_ADD(controllers::post_discover, "/discover", Post, Options);
|
||||
METHOD_ADD(controllers::get_all, "/", Get, Options);
|
||||
METHOD_ADD(controllers::get_one_by_id, "/{1}", Get, Options);
|
||||
METHOD_ADD(controllers::get_one_by_tag, "/tag/{1}", Get, Options);
|
||||
METHOD_ADD(controllers::delete_one_by_id, "/{1}", Delete, Options);
|
||||
METHOD_ADD(controllers::put_one_by_id, "/{1}", Put, Options, "filters::json_required", "filters::controllers::valid_json");
|
||||
|
||||
METHOD_ADD(controllers::get_relays_all, "/{1}/relays/", Get, Options);
|
||||
METHOD_ADD(controllers::get_relays_one_by_id_and_num, "/{1}/relays/{2}", Get, Options);
|
||||
METHOD_ADD(controllers::put_relays_one_by_id_and_num, "/{1}/relays/{2}", Put, Options, "filters::json_required", "filters::relays::valid_json");
|
||||
METHOD_LIST_END
|
||||
|
||||
static void post_discover(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback);
|
||||
static void get_all(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback);
|
||||
static void get_one_by_id(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id_str);
|
||||
static void get_one_by_tag(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_tag);
|
||||
static void delete_one_by_id(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id_str);
|
||||
static void put_one_by_id(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id);
|
||||
|
||||
static void get_relays_all(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id_str);
|
||||
static void get_relays_one_by_id_and_num(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id_str, int relay_num);
|
||||
static void put_relays_one_by_id_and_num(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id_str, int relay_num);
|
||||
};
|
||||
}
|
||||
|
|
@ -1,187 +0,0 @@
|
|||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <cmath>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include <mpack.h>
|
||||
#include <config.h>
|
||||
#include <helpers.h>
|
||||
#include <models/controller_dbo.h>
|
||||
#include "api_v1_controllers.h"
|
||||
|
||||
using namespace api::v1;
|
||||
|
||||
enum DISCOVERY_MAPPING
|
||||
{
|
||||
DISCOVERY_MAPPING_ID = 0,
|
||||
DISCOVERY_MAPPING_NAME = 1,
|
||||
DISCOVERY_MAPPING_COMMAND_PORT = 2,
|
||||
DISCOVERY_MAPPING_RELAY_COUNT = 3,
|
||||
};
|
||||
|
||||
void controllers::post_discover(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
|
||||
{
|
||||
|
||||
int discover_server_socket = helpers::bind_tcp_server("0.0.0.0", "0", config::discover_max_client_backlog);
|
||||
int discover_server_port = helpers::get_server_port(discover_server_socket);
|
||||
|
||||
if(discover_server_port == -1)
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k500InternalServerError);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
|
||||
int16_t payload[1];
|
||||
payload[0] = discover_server_port;
|
||||
|
||||
if(helpers::send_udp_broadcast("255.255.255.255", config::discover_port_dev, payload, sizeof(payload)) < 0)
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k500InternalServerError);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_storage their_addr{};
|
||||
socklen_t addr_size;
|
||||
int client_fd, s_ret;
|
||||
fd_set accept_fds;
|
||||
struct timeval timeout{};
|
||||
|
||||
uint8_t discover_answer_buf[1];
|
||||
|
||||
controller_dbo **known_controllers = controller_dbo::get_all();
|
||||
|
||||
while(true)
|
||||
{
|
||||
addr_size = sizeof(their_addr);
|
||||
|
||||
FD_ZERO(&accept_fds);
|
||||
FD_SET(discover_server_socket, &accept_fds); // NOLINT(hicpp-signed-bitwise)
|
||||
|
||||
timeout.tv_sec = config::discover_timeout_ms / 1000;
|
||||
timeout.tv_usec = (config::discover_timeout_ms % 1000) * 1000;
|
||||
|
||||
s_ret = select(discover_server_socket + 1, &accept_fds, nullptr, nullptr, &timeout);
|
||||
if(s_ret == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if((client_fd = accept(discover_server_socket, (struct sockaddr *) &their_addr, &addr_size)) < 0)
|
||||
{
|
||||
LOG_ERROR << "Error Accepting client " << strerror(errno);
|
||||
continue;
|
||||
}
|
||||
|
||||
size_t payload_length;
|
||||
|
||||
if(recv(client_fd, &payload_length, sizeof(payload_length), 0) <= 0)
|
||||
{
|
||||
LOG_ERROR << "Error Receiving header from client";
|
||||
continue;
|
||||
}
|
||||
|
||||
char *answer_payload = (char*)malloc((payload_length));
|
||||
ssize_t bytes_transferred;
|
||||
|
||||
if((bytes_transferred = recv(client_fd, answer_payload, payload_length, 0)) <= 0)
|
||||
{
|
||||
LOG_ERROR << "Error Receiving payload from client";
|
||||
continue;
|
||||
}
|
||||
|
||||
struct sockaddr_in addr{};
|
||||
socklen_t client_addr_size = sizeof(struct sockaddr_in);
|
||||
if(getpeername(client_fd, (struct sockaddr *)&addr, &client_addr_size) != 0)
|
||||
{
|
||||
|
||||
LOG_ERROR << "Error Receiving payload from client";
|
||||
continue;
|
||||
}
|
||||
|
||||
uuid_t discovered_id;
|
||||
|
||||
mpack_tree_t tree;
|
||||
mpack_tree_init_data(&tree, answer_payload, payload_length);
|
||||
mpack_tree_parse(&tree);
|
||||
mpack_node_t root = mpack_tree_root(&tree);
|
||||
|
||||
memcpy(discovered_id, mpack_node_data(mpack_node_map_uint(root, DISCOVERY_MAPPING_ID)), sizeof(uuid_t));
|
||||
|
||||
uint16_t discovered_command_port = mpack_node_u16(mpack_node_map_uint(root, DISCOVERY_MAPPING_COMMAND_PORT));
|
||||
uint8_t discovered_relay_count = mpack_node_u8(mpack_node_map_uint(root, DISCOVERY_MAPPING_RELAY_COUNT));
|
||||
const char *discovered_name = mpack_node_str(mpack_node_map_uint(root, DISCOVERY_MAPPING_NAME));
|
||||
|
||||
bool found_discovered_in_list = false;
|
||||
|
||||
for(int i = 0; known_controllers[i] != nullptr; i++)
|
||||
{
|
||||
if(!found_discovered_in_list)
|
||||
{
|
||||
if(uuid_compare(known_controllers[i]->id, discovered_id) == 0)
|
||||
{
|
||||
known_controllers[i]->active = true;
|
||||
strncpy(known_controllers[i]->name, discovered_name, 128);
|
||||
known_controllers[i]->name[127] = '\0';
|
||||
known_controllers[i]->port = discovered_command_port;
|
||||
known_controllers[i]->relay_count = discovered_relay_count;
|
||||
known_controllers[i]->update();
|
||||
delete known_controllers[i];
|
||||
found_discovered_in_list = true;
|
||||
known_controllers[i] = known_controllers[i + 1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
known_controllers[i] = known_controllers[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
if(!found_discovered_in_list)
|
||||
{
|
||||
controller_dbo discovered_controller{};
|
||||
strcpy(discovered_controller.ip, inet_ntoa(addr.sin_addr));
|
||||
memcpy(discovered_controller.id, discovered_id, sizeof(uuid_t));
|
||||
strcpy(discovered_controller.name, discovered_name);
|
||||
discovered_controller.relay_count = discovered_relay_count;
|
||||
discovered_controller.port = discovered_command_port;
|
||||
discovered_controller.active = true;
|
||||
|
||||
discovered_controller.insert();
|
||||
}
|
||||
mpack_tree_destroy(&tree);
|
||||
free(answer_payload);
|
||||
|
||||
discover_answer_buf[0] = config::discover_code_accept;
|
||||
send(client_fd, discover_answer_buf, sizeof(uint8_t), 0);
|
||||
close(client_fd);
|
||||
}
|
||||
}
|
||||
for(int i = 0; known_controllers[i] != nullptr; i++)
|
||||
{
|
||||
known_controllers[i]->active = false;
|
||||
known_controllers[i]->update();
|
||||
LOG_DEBUG << "Lost: " << known_controllers[i]->name;
|
||||
}
|
||||
controller_dbo::free_list(known_controllers);
|
||||
|
||||
controller_dbo **all_controllers = controller_dbo::get_all();
|
||||
Json::Value all_controllers_json(Json::arrayValue);
|
||||
|
||||
for(int i = 0; all_controllers[i] != nullptr; i++)
|
||||
{
|
||||
all_controllers_json.append(all_controllers[i]->to_json());
|
||||
}
|
||||
|
||||
auto resp = HttpResponse::newHttpJsonResponse(all_controllers_json);
|
||||
|
||||
callback(resp);
|
||||
|
||||
controller_dbo::free_list(all_controllers);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,268 +0,0 @@
|
|||
#include <netdb.h>
|
||||
#include <models/relay_dbo.h>
|
||||
#include <helpers.h>
|
||||
#include <mpack.h>
|
||||
#include <models/controller_dbo.h>
|
||||
#include <models/schedule_dbo.h>
|
||||
#include <models/junction_tag_dbo.h>
|
||||
#include <models/tag_dbo.h>
|
||||
#include <config.h>
|
||||
#include <enums.h>
|
||||
#include "api_v1_controllers.h"
|
||||
|
||||
using namespace api::v1;
|
||||
|
||||
void
|
||||
controllers::get_relays_all(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string& controller_id_str)
|
||||
{
|
||||
uuid_t controller_id;
|
||||
if(uuid_parse(controller_id_str.c_str(), controller_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
relay_dbo **all_controller_relays = relay_dbo::get_by_simple("controller_id", (void *) controller_id, (intptr_t) sqlite3_bind_blob, sizeof(uuid_t));
|
||||
Json::Value all_relays_json(Json::arrayValue);
|
||||
|
||||
for(int i = 0; all_controller_relays[i] != nullptr; i++)
|
||||
{
|
||||
all_relays_json.append(all_controller_relays[i]->to_json());
|
||||
}
|
||||
|
||||
auto resp = HttpResponse::newHttpJsonResponse(all_relays_json);
|
||||
|
||||
callback(resp);
|
||||
|
||||
relay_dbo::free_list(all_controller_relays);
|
||||
}
|
||||
|
||||
void
|
||||
controllers::get_relays_one_by_id_and_num(const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback, const std::string& controller_id_str,
|
||||
int relay_num)
|
||||
{
|
||||
uuid_t controller_id;
|
||||
if(uuid_parse(controller_id_str.c_str(), controller_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
relay_dbo *relay = relay_dbo::get_relay_for_controller(controller_id, relay_num);
|
||||
|
||||
if(relay)
|
||||
{
|
||||
auto resp = HttpResponse::newHttpJsonResponse(relay->to_json());
|
||||
|
||||
callback(resp);
|
||||
|
||||
delete relay;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k404NotFound);
|
||||
|
||||
callback(resp);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
controllers::put_relays_one_by_id_and_num(const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback, const std::string& controller_id_str,
|
||||
int relay_num)
|
||||
{
|
||||
uuid_t controller_id;
|
||||
if(uuid_parse(controller_id_str.c_str(), controller_id))
|
||||
{
|
||||
LOG_DEBUG << "bad uuid";
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
if(!relay_dbo::valid_num_for_controller(controller_id, relay_num))
|
||||
{
|
||||
LOG_DEBUG << "invalid num for controller";
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
|
||||
Json::Value body = *req->getJsonObject();
|
||||
bool set_name = body["name"].type() == Json::ValueType::stringValue;
|
||||
bool set_tags = body["tags"].type() == Json::ValueType::arrayValue;
|
||||
bool set_schedules = body["schedules"].type() == Json::ValueType::arrayValue;
|
||||
bool set_active_schedule = body["active_schedule"].type() == Json::ValueType::objectValue;
|
||||
|
||||
relay_dbo *relay = relay_dbo::get_relay_for_controller(controller_id, relay_num);
|
||||
|
||||
schedule_dbo **schedule_list;
|
||||
schedule_dbo *active_schedule;
|
||||
schedule_dbo *schedules[7];
|
||||
|
||||
if(set_schedules)
|
||||
{
|
||||
uuid_t schedules_ids[7];
|
||||
for(int i = 0; i < 7; ++i)
|
||||
{
|
||||
if(schedule_dbo::parse_uid(body["schedules"][i]["id"].asCString(), schedules_ids[i]))
|
||||
{
|
||||
LOG_DEBUG << "parse_uid failed for schedule " << i;
|
||||
auto res = drogon::HttpResponse::newHttpResponse();
|
||||
res->setStatusCode(k400BadRequest);
|
||||
callback(res);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < 7; ++i)
|
||||
{
|
||||
schedule_list = schedule_dbo::get_by_simple("uid", schedules_ids[i], (intptr_t)&sqlite3_bind_blob, sizeof(uuid_t));
|
||||
schedules[i] = schedule_list[0];
|
||||
free(schedule_list);
|
||||
}
|
||||
}
|
||||
|
||||
if(set_active_schedule)
|
||||
{
|
||||
uuid_t active_schedule_id;
|
||||
if(schedule_dbo::parse_uid(body["active_schedule"]["id"].asCString(), active_schedule_id))
|
||||
{
|
||||
LOG_DEBUG << "bad active_schedule uuid";
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
schedule_list = schedule_dbo::get_by_simple("uid", active_schedule_id, (intptr_t)&sqlite3_bind_blob, sizeof(uuid_t));
|
||||
active_schedule = schedule_list[0];
|
||||
free(schedule_list);
|
||||
}
|
||||
|
||||
if(!relay)
|
||||
{
|
||||
relay = new relay_dbo();
|
||||
relay->number = relay_num;
|
||||
uuid_copy(relay->controller_id, controller_id);
|
||||
|
||||
for(int i = 0; i < 7; ++i)
|
||||
{
|
||||
relay->schedules[i] = schedule_dbo::get_by_id_or_off(0);
|
||||
}
|
||||
}
|
||||
|
||||
if(set_name)
|
||||
{
|
||||
strncpy(relay->name, body["name"].asCString(), 127);
|
||||
}
|
||||
|
||||
if(set_tags)
|
||||
{
|
||||
junction_tag_dbo::remove_for_relay(relay->id);
|
||||
|
||||
for(int i = 0; i < body["tags"].size(); ++i)
|
||||
{
|
||||
const char *tag = body["tags"][i].asCString();
|
||||
int tag_id = tag_dbo::get_id(tag);
|
||||
if(tag_id == 0)
|
||||
{
|
||||
tag_dbo::save(tag_id, tag);
|
||||
tag_id = tag_dbo::get_id(tag);
|
||||
}
|
||||
junction_tag_dbo::insert(tag_id, relay->id, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if(set_schedules)
|
||||
{
|
||||
for(int i = 0; i < 7; ++i)
|
||||
{
|
||||
relay->schedules[i] = schedules[i];
|
||||
}
|
||||
relay->active_schedule = schedules[helpers::get_day_of_week()];
|
||||
}
|
||||
|
||||
if(set_active_schedule)
|
||||
{
|
||||
relay->schedules[helpers::get_day_of_week()] = active_schedule;
|
||||
relay->active_schedule = active_schedule;
|
||||
}
|
||||
|
||||
if(!relay->save())
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k500InternalServerError);
|
||||
callback(resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto controllers = controller_dbo::get_by_simple("id", controller_id, (intptr_t)&sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
char* data;
|
||||
size_t size;
|
||||
mpack_writer_t writer;
|
||||
mpack_writer_init_growable(&writer, &data, &size);
|
||||
|
||||
// 3 = code, relay num, relay name, schedules(array)
|
||||
mpack_start_map(&writer, 3);
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_CODE);
|
||||
mpack_write_u8(&writer, config::command_code_set_schedule);
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_RELAY_NUM);
|
||||
mpack_write_u8(&writer, relay->number);
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_SCHEDULES_ARRAY);
|
||||
// 7 = days of week
|
||||
mpack_start_array(&writer, 7);
|
||||
for(int i = 0; i < 7; ++i)
|
||||
{
|
||||
uint16_t *periods = relay->schedules[i]->periods->to_blob();
|
||||
uint16_t periods_count = periods[0];
|
||||
|
||||
// 3 = code, relaynum, schedules(array)
|
||||
mpack_start_map(&writer, 3);
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_PERIODS_COUNT);
|
||||
mpack_write_u16(&writer, periods_count);
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_SCHEDULE_ID);
|
||||
mpack_write_bin(&writer, (char*)relay->schedules[0]->uid, sizeof(uuid_t));
|
||||
|
||||
mpack_write_uint(&writer, COMMAND_MAPPING_PERIODS_BLOB);
|
||||
// periods + 1 to skip length in periods[0]
|
||||
// periods_count * 2 because each uint16_t is a timestamp. 2 are start and end
|
||||
mpack_write_bin(&writer, (char*)(periods + 1), sizeof(uint16_t) * periods_count * 2);
|
||||
|
||||
mpack_finish_map(&writer);
|
||||
|
||||
free(periods);
|
||||
}
|
||||
mpack_finish_array(&writer);
|
||||
|
||||
mpack_finish_map(&writer);
|
||||
|
||||
// finish writing
|
||||
if (mpack_writer_destroy(&writer) != mpack_ok) {
|
||||
LOG_ERROR << "an error occurred encoding the data";
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k500InternalServerError);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
|
||||
controllers[0]->command(config::command_code_set_name, data, size);
|
||||
|
||||
auto resp = HttpResponse::newHttpJsonResponse(relay->to_json());
|
||||
callback(resp);
|
||||
|
||||
controller_dbo::free_list(controllers);
|
||||
}
|
||||
|
||||
delete relay;
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
#include <netdb.h>
|
||||
#include <models/relay_dbo.h>
|
||||
#include <models/tag_dbo.h>
|
||||
#include <models/junction_tag_dbo.h>
|
||||
#include <helpers.h>
|
||||
#include "api_v1_relays.h"
|
||||
using namespace api::v1;
|
||||
|
||||
void
|
||||
relays::get_all(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
|
||||
{
|
||||
relay_dbo **all_relays = relay_dbo::get_all();
|
||||
Json::Value all_relays_json(Json::arrayValue);
|
||||
|
||||
for(int i = 0; all_relays[i] != nullptr; i++)
|
||||
{
|
||||
all_relays_json.append(all_relays[i]->to_json());
|
||||
}
|
||||
|
||||
auto resp = HttpResponse::newHttpJsonResponse(all_relays_json);
|
||||
|
||||
callback(resp);
|
||||
|
||||
relay_dbo::free_list(all_relays);
|
||||
}
|
||||
|
||||
void
|
||||
relays::get_by_tag(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string &tag)
|
||||
{
|
||||
int tag_id = tag_dbo::get_id(tag.c_str());
|
||||
int *relays_ids = junction_tag_dbo::get_relays_for_tag_id(tag_id);
|
||||
if(relays_ids == nullptr)
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k500InternalServerError);
|
||||
callback(resp);
|
||||
}
|
||||
|
||||
Json::Value relays_json(Json::arrayValue);
|
||||
|
||||
for(int i = 0; relays_ids[i] != 0; ++i)
|
||||
{
|
||||
relay_dbo *relay = relay_dbo::get_by_id(relays_ids[i]);
|
||||
if(relay)
|
||||
{
|
||||
relays_json.append(relay->to_json());
|
||||
}
|
||||
}
|
||||
|
||||
auto resp = HttpResponse::newHttpJsonResponse(relays_json);
|
||||
callback(resp);
|
||||
free(relays_ids);
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#pragma once
|
||||
#include <drogon/HttpController.h>
|
||||
using namespace drogon;
|
||||
namespace api::v1
|
||||
{
|
||||
class relays:public drogon::HttpController<relays>
|
||||
{
|
||||
public:
|
||||
METHOD_LIST_BEGIN
|
||||
METHOD_ADD(relays::get_all, "/", Get, Options);
|
||||
METHOD_ADD(relays::get_by_tag, "/tag/{1}", Get, Options);
|
||||
METHOD_LIST_END
|
||||
|
||||
static void get_all(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback);
|
||||
static void get_by_tag(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& tag);
|
||||
};
|
||||
}
|
||||
|
|
@ -1,277 +0,0 @@
|
|||
#include <netdb.h>
|
||||
#include <models/schedule_dbo.h>
|
||||
#include <models/tag_dbo.h>
|
||||
#include <models/junction_tag_dbo.h>
|
||||
#include <helpers.h>
|
||||
#include "api_v1_schedules.h"
|
||||
using namespace api::v1;
|
||||
|
||||
void
|
||||
schedules::get_all(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
|
||||
{
|
||||
schedule_dbo **all_schedules = schedule_dbo::get_all();
|
||||
Json::Value all_schedules_json(Json::arrayValue);
|
||||
|
||||
for(int i = 0; all_schedules[i] != nullptr; i++)
|
||||
{
|
||||
all_schedules_json.append(all_schedules[i]->to_json());
|
||||
}
|
||||
|
||||
Json::StreamWriterBuilder jw;
|
||||
|
||||
auto resp = HttpResponse::newHttpJsonResponse(all_schedules_json);
|
||||
|
||||
callback(resp);
|
||||
|
||||
schedule_dbo::free_list(all_schedules);
|
||||
}
|
||||
|
||||
void
|
||||
schedules::get_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, const std::string& schedule_id_str)
|
||||
{
|
||||
uuid_t schedule_id;
|
||||
if(schedule_dbo::parse_uid(schedule_id_str.c_str(), schedule_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("uid", schedule_id, (intptr_t) &sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
if(schedules[0])
|
||||
{
|
||||
auto resp = HttpResponse::newHttpJsonResponse(schedules[0]->to_json());
|
||||
|
||||
callback(resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k404NotFound);
|
||||
|
||||
callback(resp);
|
||||
}
|
||||
schedule_dbo::free_list(schedules);
|
||||
}
|
||||
|
||||
void
|
||||
schedules::delete_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, const std::string& schedule_id_str)
|
||||
{
|
||||
if(strcmp(schedule_id_str.c_str(), "off") == 0 || strcmp(schedule_id_str.c_str(), "on") == 0)
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k403Forbidden);
|
||||
callback(resp);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
uuid_t schedule_id;
|
||||
if(schedule_dbo::parse_uid(schedule_id_str.c_str(), schedule_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("uid", schedule_id, (intptr_t) &sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
if(schedules[0])
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
if(!schedules[0]->remove())
|
||||
{
|
||||
resp->setStatusCode(k500InternalServerError);
|
||||
}
|
||||
|
||||
callback(resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k404NotFound);
|
||||
|
||||
callback(resp);
|
||||
}
|
||||
schedule_dbo::free_list(schedules);
|
||||
}
|
||||
|
||||
void
|
||||
schedules::post_new(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
|
||||
{
|
||||
Json::Value body = *req->jsonObject();
|
||||
|
||||
bool set_name = body["name"].type() == Json::ValueType::stringValue;
|
||||
bool set_tags = body["tags"].type() == Json::ValueType::arrayValue;
|
||||
//bool set_periods = body["periods"].type() == Json::ValueType::arrayValue;
|
||||
|
||||
if(!set_name || !set_name)
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
}
|
||||
|
||||
schedule_dbo new_schedule{};
|
||||
|
||||
strncpy(new_schedule.name, body["name"].asCString(), 127);
|
||||
new_schedule.name[127] = '\0';
|
||||
uuid_generate(new_schedule.uid);
|
||||
new_schedule.periods = helpers::parse_periods(body["periods"]);
|
||||
|
||||
if(!new_schedule.insert())
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k500InternalServerError);
|
||||
callback(resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto resp = HttpResponse::newHttpJsonResponse(new_schedule.to_json());
|
||||
callback(resp);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
schedules::post_list(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
|
||||
{
|
||||
Json::Value body = *req->jsonObject();
|
||||
|
||||
Json::Value schedules_json(Json::arrayValue);
|
||||
|
||||
for(int i = 0; i < body.size(); ++i)
|
||||
{
|
||||
bool set_name = body[i]["name"].type() == Json::ValueType::stringValue;
|
||||
bool set_tags = body[i]["tags"].type() == Json::ValueType::arrayValue;
|
||||
//bool set_periods = body[i]["periods"].type() == Json::ValueType::arrayValue;
|
||||
|
||||
if(!set_name || !set_name)
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
}
|
||||
|
||||
schedule_dbo new_schedule{};
|
||||
|
||||
strncpy(new_schedule.name, body[i]["name"].asCString(), 127);
|
||||
new_schedule.name[127] = '\0';
|
||||
uuid_generate(new_schedule.uid);
|
||||
new_schedule.periods = helpers::parse_periods(body[i]["periods"]);
|
||||
|
||||
if(new_schedule.insert())
|
||||
{
|
||||
schedules_json.append(new_schedule.to_json());
|
||||
}
|
||||
}
|
||||
|
||||
auto resp = HttpResponse::newHttpJsonResponse(schedules_json);
|
||||
callback(resp);
|
||||
}
|
||||
|
||||
void
|
||||
schedules::put_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string &schedule_id_str)
|
||||
{
|
||||
uuid_t schedule_id;
|
||||
if(schedule_dbo::parse_uid(schedule_id_str.c_str(), schedule_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("uid", schedule_id, (intptr_t) &sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
if(schedules[0] == nullptr)
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k404NotFound);
|
||||
|
||||
callback(resp);
|
||||
}
|
||||
|
||||
Json::Value body = *req->jsonObject();
|
||||
|
||||
bool set_name = body["name"].type() == Json::ValueType::stringValue;
|
||||
bool set_tags = body["tags"].type() == Json::ValueType::arrayValue;
|
||||
bool set_periods = body["periods"].type() == Json::ValueType::arrayValue;
|
||||
|
||||
if(set_name)
|
||||
{
|
||||
strncpy(schedules[0]->name, body["name"].asCString(), 127);
|
||||
schedules[0]->name[127] = '\0';
|
||||
}
|
||||
|
||||
if(set_periods)
|
||||
{
|
||||
// if neither "off" nor "on" allow overwrite of periods
|
||||
if(strcmp(schedule_id_str.c_str(), "off") && strcmp(schedule_id_str.c_str(), "on"))
|
||||
{
|
||||
delete schedules[0]->periods;
|
||||
schedules[0]->periods = helpers::parse_periods(body["periods"]);
|
||||
}
|
||||
}
|
||||
|
||||
if(set_tags)
|
||||
{
|
||||
junction_tag_dbo::remove_for_schedule(schedules[0]->id);
|
||||
|
||||
for(int i = 0; i < body["tags"].size(); ++i)
|
||||
{
|
||||
const char *tag = body["tags"][i].asCString();
|
||||
int tag_id = tag_dbo::get_id(tag);
|
||||
if(tag_id == 0)
|
||||
{
|
||||
tag_dbo::save(tag_id, tag);
|
||||
tag_id = tag_dbo::get_id(tag);
|
||||
}
|
||||
junction_tag_dbo::insert(tag_id, 0, schedules[0]->id);
|
||||
}
|
||||
}
|
||||
|
||||
if(!schedules[0]->update())
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k500InternalServerError);
|
||||
callback(resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto resp = HttpResponse::newHttpJsonResponse(schedules[0]->to_json());
|
||||
callback(resp);
|
||||
}
|
||||
|
||||
schedule_dbo::free_list(schedules);
|
||||
}
|
||||
|
||||
void
|
||||
schedules::get_by_tag(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string &tag)
|
||||
{
|
||||
int tag_id = tag_dbo::get_id(tag.c_str());
|
||||
int *schedules_ids = junction_tag_dbo::get_schedules_for_tag_id(tag_id);
|
||||
if(schedules_ids == nullptr)
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k500InternalServerError);
|
||||
callback(resp);
|
||||
}
|
||||
|
||||
Json::Value schedules_json(Json::arrayValue);
|
||||
|
||||
for(int i = 0; schedules_ids[i] != 0; ++i)
|
||||
{
|
||||
schedule_dbo *schedule = schedule_dbo::get_by_id(schedules_ids[i]);
|
||||
if(schedule)
|
||||
{
|
||||
schedules_json.append(schedule->to_json());
|
||||
}
|
||||
}
|
||||
|
||||
auto resp = HttpResponse::newHttpJsonResponse(schedules_json);
|
||||
callback(resp);
|
||||
free(schedules_ids);
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
#pragma once
|
||||
#include <drogon/HttpController.h>
|
||||
using namespace drogon;
|
||||
namespace api::v1
|
||||
{
|
||||
class schedules:public drogon::HttpController<schedules>
|
||||
{
|
||||
public:
|
||||
METHOD_LIST_BEGIN
|
||||
METHOD_ADD(schedules::post_new, "/", Post, Options, "filters::json_required", "filters::schedules::valid_json");
|
||||
METHOD_ADD(schedules::post_list, "/list", Post, Options, "filters::json_required");
|
||||
METHOD_ADD(schedules::get_all, "/", Get, Options);
|
||||
METHOD_ADD(schedules::get_one_by_id, "/{1}", Get, Options);
|
||||
METHOD_ADD(schedules::delete_one_by_id, "/{1}", Delete, Options);
|
||||
METHOD_ADD(schedules::put_one_by_id, "/{1}", Put, Options, "filters::json_required", "filters::schedules::valid_json");
|
||||
METHOD_ADD(schedules::get_by_tag, "/tag/{1}", Get, Options);
|
||||
//METHOD_ADD(controllers::get_relays_all,"/{1}/relays",Get);
|
||||
//METHOD_ADD(controllers::get_relays_one,"/{1}/relays/{2}",Get);
|
||||
METHOD_LIST_END
|
||||
|
||||
static void post_new(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback);
|
||||
static void post_list(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback);
|
||||
static void get_all(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback);
|
||||
static void get_one_by_id(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& schedule_id);
|
||||
static void delete_one_by_id(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& schedule_id);
|
||||
static void put_one_by_id(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& schedule_id);
|
||||
static void get_by_tag(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& tag);
|
||||
//void get_relays_all(const HttpRequestPtr& req,std::function<void (const HttpResponsePtr &)> &&callback,std::string schedule_id);
|
||||
//void get_relays_one(const HttpRequestPtr& req,std::function<void (const HttpResponsePtr &)> &&callback,std::string schedule_id,std::string relay_id);
|
||||
};
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue