Skip to content

Commit

Permalink
Restructured the project so sources weren't in root folder. Fixed an …
Browse files Browse the repository at this point in the history
…error in socket server link
  • Loading branch information
Meulengracht committed Apr 28, 2021
1 parent efe3a86 commit e519e26
Show file tree
Hide file tree
Showing 24 changed files with 171 additions and 104 deletions.
68 changes: 1 addition & 67 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions generator/examples/test_service.gr
Original file line number Diff line number Diff line change
@@ -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);
}
24 changes: 24 additions & 0 deletions generator/examples/test_structs.gr
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 12 additions & 0 deletions generator/examples/test_types.gr
Original file line number Diff line number Diff line change
@@ -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
}
68 changes: 68 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 ()
4 changes: 2 additions & 2 deletions arena.c → runtime/arena.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/

#include <errno.h>
#include "include/debug.h"
#include "include/server_private.h"
#include "debug.h"
#include "server_private.h"
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Expand Down
18 changes: 9 additions & 9 deletions client.c → runtime/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@

#include <assert.h>
#include <errno.h>
#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 <string.h>
#include <stdlib.h>

Expand Down
2 changes: 1 addition & 1 deletion client_config.c → runtime/client_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Gracht Server Configuration Helpers
*/

#include "include/gracht/client.h"
#include "gracht/client.h"
#include <string.h>

void gracht_client_configuration_init(gracht_client_configuration_t* config)
Expand Down
2 changes: 1 addition & 1 deletion control.c → runtime/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand Down
2 changes: 1 addition & 1 deletion crc.c → runtime/crc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions dispatch.c → runtime/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <errno.h>
#include <stdlib.h>

Expand Down
2 changes: 1 addition & 1 deletion hashtable.c → runtime/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* - Open addressed hashtable implementation using round robin for balancing.
*/

#include "include/hashtable.h"
#include "hashtable.h"
#include <assert.h>
#include <errno.h>
#include <string.h>
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions link/socket/server.c → runtime/link/socket/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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"));
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions server.c → runtime/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
*/

#include <errno.h>
#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 <stdlib.h>
#include <string.h>

Expand Down
2 changes: 1 addition & 1 deletion server_config.c → runtime/server_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Gracht Server Configuration Helpers
*/

#include "include/gracht/server.h"
#include "gracht/server.h"
#include <string.h>

void gracht_server_configuration_init(gracht_server_configuration_t* config)
Expand Down
8 changes: 4 additions & 4 deletions shared.c → runtime/shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <errno.h>
#include <stdlib.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e519e26

Please sign in to comment.