From e519e261914121d782503404bf89ae1614694e51 Mon Sep 17 00:00:00 2001 From: Philip Meulengracht Date: Wed, 28 Apr 2021 12:10:58 +0200 Subject: [PATCH] Restructured the project so sources weren't in root folder. Fixed an error in socket server link --- CMakeLists.txt | 68 +--------------------- generator/examples/test_service.gr | 30 ++++++++++ generator/examples/test_structs.gr | 24 ++++++++ generator/examples/test_types.gr | 12 ++++ runtime/CMakeLists.txt | 68 ++++++++++++++++++++++ arena.c => runtime/arena.c | 4 +- client.c => runtime/client.c | 18 +++--- client_config.c => runtime/client_config.c | 2 +- control.c => runtime/control.c | 2 +- crc.c => runtime/crc.c | 2 +- dispatch.c => runtime/dispatch.c | 8 +-- hashtable.c => runtime/hashtable.c | 2 +- {link => runtime/link}/socket/client.c | 0 {link => runtime/link}/socket/server.c | 3 +- {link => runtime/link}/socket/shared.c | 0 {link => runtime/link}/socket/socket_os.h | 0 {link => runtime/link}/vali-ipc/client.c | 0 {link => runtime/link}/vali-ipc/message.c | 0 {link => runtime/link}/vali-ipc/os.c | 0 {link => runtime/link}/vali-ipc/server.c | 0 server.c => runtime/server.c | 20 +++---- server_config.c => runtime/server_config.c | 2 +- shared.c => runtime/shared.c | 8 +-- tests/CMakeLists.txt | 2 +- 24 files changed, 171 insertions(+), 104 deletions(-) create mode 100644 generator/examples/test_service.gr create mode 100644 generator/examples/test_structs.gr create mode 100644 generator/examples/test_types.gr create mode 100644 runtime/CMakeLists.txt rename arena.c => runtime/arena.c (99%) rename client.c => runtime/client.c (98%) rename client_config.c => runtime/client_config.c (97%) rename control.c => runtime/control.c (99%) rename crc.c => runtime/crc.c (99%) rename dispatch.c => runtime/dispatch.c (98%) rename hashtable.c => runtime/hashtable.c (99%) rename {link => runtime/link}/socket/client.c (100%) rename {link => runtime/link}/socket/server.c (99%) rename {link => runtime/link}/socket/shared.c (100%) rename {link => runtime/link}/socket/socket_os.h (100%) rename {link => runtime/link}/vali-ipc/client.c (100%) rename {link => runtime/link}/vali-ipc/message.c (100%) rename {link => runtime/link}/vali-ipc/os.c (100%) rename {link => runtime/link}/vali-ipc/server.c (100%) rename server.c => runtime/server.c (98%) rename server_config.c => runtime/server_config.c (97%) rename shared.c => runtime/shared.c (93%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a64b17..a2a30c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,79 +6,13 @@ enable_language (C) option (GRACHT_BUILD_TESTS "Build test server and client program for gracht" OFF) option (GRACHT_INSTALL_HEADERS "Install headers and library") -set (WARNING_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-function") -set (SRCS "") - -macro (add_sources) - file (RELATIVE_PATH _relPath "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") - foreach (_src ${ARGN}) - if (_relPath) - list (APPEND SRCS "${_relPath}/${_src}") - else() - list (APPEND SRCS "${_src}") - endif() - endforeach() -endmacro() - -# Configure include paths -if (VALI_BUILD) - include_directories ( - ${CMAKE_BINARY_DIR} - ../libds/include - ../libddk/include - ../libc/include - ../include - ./include - ) -else () - include_directories( - ${CMAKE_BINARY_DIR} - ./include - ) -endif () - include (CheckIncludeFiles) check_include_files (threads.h HAVE_C11_THREADS) check_include_files (pthread.h HAVE_PTHREAD) -if (MOLLENOS) - add_definitions(${WARNING_COMPILE_FLAGS}) - add_sources ( - link/vali-ipc/client.c - link/vali-ipc/message.c - link/vali-ipc/os.c - link/vali-ipc/server.c - ) -endif () - -if (UNIX) - add_definitions(${WARNING_COMPILE_FLAGS}) -endif () - configure_file(config.h.in config.h @ONLY) -add_sources(link/socket/client.c link/socket/server.c link/socket/shared.c) -add_sources(client.c client_config.c crc.c server.c server_config.c shared.c arena.c dispatch.c hashtable.c control.c) -add_library(gracht ${SRCS}) - -if (VALI_BUILD) - install(TARGETS gracht - ARCHIVE DESTINATION vali-ddk/lib - LIBRARY DESTINATION vali-ddk/lib - RUNTIME DESTINATION vali-ddk/bin - ) - install(DIRECTORY include/ DESTINATION vali-ddk/include) - install(DIRECTORY generator/ DESTINATION vali-ddk/share/vali) -else () - install(TARGETS gracht - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin - ) - install(DIRECTORY include/ DESTINATION include) - install(DIRECTORY generator/ DESTINATION share/gracht) - install(FILES protocol.xml DESTINATION share/gracht) -endif () +add_subdirectory(runtime) if (GRACHT_BUILD_TESTS) add_subdirectory(tests) diff --git a/generator/examples/test_service.gr b/generator/examples/test_service.gr new file mode 100644 index 0000000..345ca88 --- /dev/null +++ b/generator/examples/test_service.gr @@ -0,0 +1,30 @@ +/** + * Test example of gracht protocol message version 2 + * Includes example of a test protocol and some test structures + */ + +import "test_structs" +namespace gracht + +// define calculator service with id of 1 +service calculator (0x1) { + func add(int a, int b) : (int result); + func add_many(int[] inputs) : (int result); + func print(string text) : (int result); + + func getHistory() : (string history); + func getHistories() : (string[] histories); + + func transfer(transfer_request request) : (int status); + func transfer_many(transfer_request[] request) : (int[] statuses); + + event error : (int code, string description); + event transfer_complete : transfer_complete_event; +} + +service control (2) { + func subscribe(uint8_t protocol) : (); + func unsubscribe(uint8_t protocol) : (); + + event error : (uint32_t messageId, int errorCode); +} diff --git a/generator/examples/test_structs.gr b/generator/examples/test_structs.gr new file mode 100644 index 0000000..3037796 --- /dev/null +++ b/generator/examples/test_structs.gr @@ -0,0 +1,24 @@ +/** + * Test example of gracht protocol message version 2 + * Includes example of a test protocol and some test structures + */ + +import "test_types" + +struct transfer_device { + string device; +} + +struct transfer_bit { + int start; + int length; +} + +struct transfer_request { + transfer_device device; + transfer_bit[] bits; +} + +struct transfer_complete_event { + uint32_t id; +} diff --git a/generator/examples/test_types.gr b/generator/examples/test_types.gr new file mode 100644 index 0000000..aac21a2 --- /dev/null +++ b/generator/examples/test_types.gr @@ -0,0 +1,12 @@ +/** + * Test example of gracht protocol message version 2 + * Includes example of a test protocol and some test structures + */ + +define uint32_t from "stdint.h" + +enum error_codes { + ok = 0, + invalid_parameters = -1, + invalid_result = -2 +} diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt new file mode 100644 index 0000000..6aea1d6 --- /dev/null +++ b/runtime/CMakeLists.txt @@ -0,0 +1,68 @@ + +set (WARNING_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-function") +set (SRCS "") + +macro (add_sources) + file (RELATIVE_PATH _relPath "${PROJECT_SOURCE_DIR}/runtime" "${CMAKE_CURRENT_SOURCE_DIR}") + foreach (_src ${ARGN}) + if (_relPath) + list (APPEND SRCS "${_relPath}/${_src}") + else() + list (APPEND SRCS "${_src}") + endif() + endforeach() +endmacro() + +# Configure include paths +if (VALI_BUILD) + include_directories ( + ${CMAKE_BINARY_DIR} + ../libds/include + ../libddk/include + ../libc/include + ../include + ) +else () + include_directories( + ${CMAKE_BINARY_DIR} + ../include + ) +endif () + +if (MOLLENOS) + add_definitions(${WARNING_COMPILE_FLAGS}) + add_sources ( + link/vali-ipc/client.c + link/vali-ipc/message.c + link/vali-ipc/os.c + link/vali-ipc/server.c + ) +endif () + +if (UNIX) + add_definitions(${WARNING_COMPILE_FLAGS}) +endif () + +add_sources(link/socket/client.c link/socket/server.c link/socket/shared.c) +add_sources(client.c client_config.c crc.c server.c server_config.c shared.c arena.c dispatch.c hashtable.c control.c) + +add_library(gracht ${SRCS}) + +if (VALI_BUILD) + install(TARGETS gracht + ARCHIVE DESTINATION vali-ddk/lib + LIBRARY DESTINATION vali-ddk/lib + RUNTIME DESTINATION vali-ddk/bin + ) + install(DIRECTORY include/ DESTINATION vali-ddk/include) + install(DIRECTORY generator/ DESTINATION vali-ddk/share/vali) +else () + install(TARGETS gracht + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin + ) + install(DIRECTORY include/ DESTINATION include) + install(DIRECTORY generator/ DESTINATION share/gracht) + install(FILES protocol.xml DESTINATION share/gracht) +endif () diff --git a/arena.c b/runtime/arena.c similarity index 99% rename from arena.c rename to runtime/arena.c index 8fb61de..f0713c4 100644 --- a/arena.c +++ b/runtime/arena.c @@ -19,8 +19,8 @@ */ #include -#include "include/debug.h" -#include "include/server_private.h" +#include "debug.h" +#include "server_private.h" #include #include #include diff --git a/client.c b/runtime/client.c similarity index 98% rename from client.c rename to runtime/client.c index a92bb4b..07490f6 100644 --- a/client.c +++ b/runtime/client.c @@ -24,15 +24,15 @@ #include #include -#include "include/gracht/client.h" -#include "include/client_private.h" -#include "include/arena.h" -#include "include/crc.h" -#include "include/hashtable.h" -#include "include/debug.h" -#include "include/thread_api.h" -#include "include/control.h" -#include "include/utils.h" +#include "gracht/client.h" +#include "client_private.h" +#include "arena.h" +#include "crc.h" +#include "hashtable.h" +#include "debug.h" +#include "thread_api.h" +#include "control.h" +#include "utils.h" #include #include diff --git a/client_config.c b/runtime/client_config.c similarity index 97% rename from client_config.c rename to runtime/client_config.c index 0f113b5..e2584db 100644 --- a/client_config.c +++ b/runtime/client_config.c @@ -18,7 +18,7 @@ * Gracht Server Configuration Helpers */ -#include "include/gracht/client.h" +#include "gracht/client.h" #include void gracht_client_configuration_init(gracht_client_configuration_t* config) diff --git a/control.c b/runtime/control.c similarity index 99% rename from control.c rename to runtime/control.c index 992f011..7949e21 100644 --- a/control.c +++ b/runtime/control.c @@ -20,7 +20,7 @@ * and functionality, refer to the individual things for descriptions */ -#include "include/control.h" +#include "control.h" #define SERIALIZE_VALUE(name, type) static inline void serialize_##name(gracht_buffer_t* buffer, type value) { \ *((type*)&buffer->data[buffer->index]) = value; buffer->index += sizeof(type); \ diff --git a/crc.c b/runtime/crc.c similarity index 99% rename from crc.c rename to runtime/crc.c index 73ed5a8..dad9a71 100644 --- a/crc.c +++ b/runtime/crc.c @@ -31,7 +31,7 @@ * CRC16 cyclic redundancy check values for an incomming byte string. */ -#include "include/crc.h" +#include "crc.h" #define CRC_POLY_16 0xA001 #define CRC_START_16 0x0000 diff --git a/dispatch.c b/runtime/dispatch.c similarity index 98% rename from dispatch.c rename to runtime/dispatch.c index 9df7aa7..7bc275c 100644 --- a/dispatch.c +++ b/runtime/dispatch.c @@ -18,10 +18,10 @@ * Gracht Server Dispatcher */ -#include "include/debug.h" -#include "include/thread_api.h" -#include "include/queue.h" -#include "include/server_private.h" +#include "debug.h" +#include "thread_api.h" +#include "queue.h" +#include "server_private.h" #include #include diff --git a/hashtable.c b/runtime/hashtable.c similarity index 99% rename from hashtable.c rename to runtime/hashtable.c index 6f9ab3a..e2919c2 100644 --- a/hashtable.c +++ b/runtime/hashtable.c @@ -18,7 +18,7 @@ * - Open addressed hashtable implementation using round robin for balancing. */ -#include "include/hashtable.h" +#include "hashtable.h" #include #include #include diff --git a/link/socket/client.c b/runtime/link/socket/client.c similarity index 100% rename from link/socket/client.c rename to runtime/link/socket/client.c diff --git a/link/socket/server.c b/runtime/link/socket/server.c similarity index 99% rename from link/socket/server.c rename to runtime/link/socket/server.c index 7d27bb8..0681fe1 100644 --- a/link/socket/server.c +++ b/runtime/link/socket/server.c @@ -104,7 +104,7 @@ static int socket_link_recv_client(struct socket_link_client* client, context->client = client->socket; context->index = 0; - context->size = (uint32_t)bytesRead; + context->size = *((uint32_t*)&context->payload[4]); return 0; } @@ -212,7 +212,6 @@ static int socket_link_accept(struct socket_link_manager* linkManager, struct gr memset(client, 0, sizeof(struct socket_link_client)); - // TODO handle disconnects in accept in netmanager client->socket = accept(linkManager->client_socket, (struct sockaddr*)&client->address, &address_length); if (client->socket < 0) { GRERROR(GRSTR("link_server: failed to accept client")); diff --git a/link/socket/shared.c b/runtime/link/socket/shared.c similarity index 100% rename from link/socket/shared.c rename to runtime/link/socket/shared.c diff --git a/link/socket/socket_os.h b/runtime/link/socket/socket_os.h similarity index 100% rename from link/socket/socket_os.h rename to runtime/link/socket/socket_os.h diff --git a/link/vali-ipc/client.c b/runtime/link/vali-ipc/client.c similarity index 100% rename from link/vali-ipc/client.c rename to runtime/link/vali-ipc/client.c diff --git a/link/vali-ipc/message.c b/runtime/link/vali-ipc/message.c similarity index 100% rename from link/vali-ipc/message.c rename to runtime/link/vali-ipc/message.c diff --git a/link/vali-ipc/os.c b/runtime/link/vali-ipc/os.c similarity index 100% rename from link/vali-ipc/os.c rename to runtime/link/vali-ipc/os.c diff --git a/link/vali-ipc/server.c b/runtime/link/vali-ipc/server.c similarity index 100% rename from link/vali-ipc/server.c rename to runtime/link/vali-ipc/server.c diff --git a/server.c b/runtime/server.c similarity index 98% rename from server.c rename to runtime/server.c index aca3ef0..cd7aa04 100644 --- a/server.c +++ b/runtime/server.c @@ -21,16 +21,16 @@ */ #include -#include "include/aio.h" -#include "include/arena.h" -#include "include/debug.h" -#include "include/gracht/server.h" -#include "include/gracht/link/link.h" -#include "include/thread_api.h" -#include "include/utils.h" -#include "include/server_private.h" -#include "include/hashtable.h" -#include "include/control.h" +#include "aio.h" +#include "arena.h" +#include "debug.h" +#include "gracht/server.h" +#include "gracht/link/link.h" +#include "thread_api.h" +#include "utils.h" +#include "server_private.h" +#include "hashtable.h" +#include "control.h" #include #include diff --git a/server_config.c b/runtime/server_config.c similarity index 97% rename from server_config.c rename to runtime/server_config.c index 7eadd5e..b311e70 100644 --- a/server_config.c +++ b/runtime/server_config.c @@ -18,7 +18,7 @@ * Gracht Server Configuration Helpers */ -#include "include/gracht/server.h" +#include "gracht/server.h" #include void gracht_server_configuration_init(gracht_server_configuration_t* config) diff --git a/shared.c b/runtime/shared.c similarity index 93% rename from shared.c rename to runtime/shared.c index c9c40de..e93c355 100644 --- a/shared.c +++ b/runtime/shared.c @@ -20,10 +20,10 @@ * and functionality, refer to the individual things for descriptions */ -#include "include/gracht/types.h" -#include "include/hashtable.h" -#include "include/debug.h" -#include "include/utils.h" +#include "gracht/types.h" +#include "hashtable.h" +#include "debug.h" +#include "utils.h" #include #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 99243d2..900aa01 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -33,7 +33,7 @@ macro (add_client_test) endif () endmacro() -include_directories(${CMAKE_CURRENT_BINARY_DIR}) +include_directories(${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR} ../include) add_custom_command( OUTPUT test_utils_service_server.c test_utils_service_server.h test_utils_service_client.c test_utils_service_client.h test_utils_service.h