From f4ad730cc4637f3b98cd6159c714504538af1cd0 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 4 Nov 2019 22:39:27 +1100 Subject: [PATCH] [arbiter] initial arbiter program for porthole communications --- VERSION | 2 +- arbiter/.gitignore | 3 ++ arbiter/CMakeLists.txt | 62 ++++++++++++++++++++++++++++++++++++++++++ arbiter/src/main.c | 55 +++++++++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 arbiter/.gitignore create mode 100644 arbiter/CMakeLists.txt create mode 100644 arbiter/src/main.c diff --git a/VERSION b/VERSION index baf037d0..485b77cb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -B1-29-g27c3a93d15+1 \ No newline at end of file +B1-30-g67ddb70932+1 \ No newline at end of file diff --git a/arbiter/.gitignore b/arbiter/.gitignore new file mode 100644 index 00000000..0824b6c0 --- /dev/null +++ b/arbiter/.gitignore @@ -0,0 +1,3 @@ +bin/ +build/ +*.swp diff --git a/arbiter/CMakeLists.txt b/arbiter/CMakeLists.txt new file mode 100644 index 00000000..cab64878 --- /dev/null +++ b/arbiter/CMakeLists.txt @@ -0,0 +1,62 @@ +cmake_minimum_required(VERSION 3.0) +project(looking-glass-arbiter C) + +set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/") + +include(GNUInstallDirs) +include(CheckCCompilerFlag) +include(FeatureSummary) + +option(OPTIMIZE_FOR_NATIVE "Build with -march=native" ON) +if(OPTIMIZE_FOR_NATIVE) + CHECK_C_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) + if(COMPILER_SUPPORTS_MARCH_NATIVE) + add_compile_options("-march=native") + endif() +endif() + +add_compile_options( + "-Wall" + "-Werror" + "-Wfatal-errors" + "-ffast-math" + "-fdata-sections" + "-ffunction-sections" + "$<$:-O0;-g3;-ggdb>" +) + +set(EXE_FLAGS "-Wl,--gc-sections") +set(CMAKE_C_STANDARD 11) + +execute_process( + COMMAND cat ../VERSION + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE BUILD_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +add_definitions(-D BUILD_VERSION='"${BUILD_VERSION}"') +get_filename_component(PROJECT_TOP "${PROJECT_SOURCE_DIR}/.." ABSOLUTE) + +include_directories( + ${PROJECT_SOURCE_DIR}/include + ${CMAKE_BINARY_DIR}/include +) + +set(SOURCES + src/main.c +) + +add_subdirectory("${PROJECT_TOP}/common" "${CMAKE_BINARY_DIR}/common") +add_subdirectory("${PROJECT_TOP}/porthole" "${CMAKE_BINARY_DIR}/porthole") + +add_executable(looking-glass-arbiter ${SOURCES}) +target_link_libraries(looking-glass-arbiter + ${EXE_FLAGS} + lg_common + porthole +) + +install(PROGRAMS ${CMAKE_BINARY_DIR}/looking-glass-arbiter DESTINATION bin/ COMPONENT binary) + +feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES) diff --git a/arbiter/src/main.c b/arbiter/src/main.c new file mode 100644 index 00000000..71cfe242 --- /dev/null +++ b/arbiter/src/main.c @@ -0,0 +1,55 @@ +#include "common/debug.h" +#include "common/option.h" +#include "porthole/client.h" + +static struct Option options[] = +{ + // app options + { + .module = "host", + .name = "socket", + .description = "The porthole host socket", + .type = OPTION_TYPE_STRING, + .value.x_string = "/var/tmp/porthole", + }, + {0} +}; + +static void map_event(uint32_t type, PortholeMap * map) +{ + DEBUG_INFO("map_event: %u, %u, %u", type, map->id, map->size); +} + +static void unmap_event(uint32_t id) +{ + DEBUG_INFO("unmap_event: %u", id); +} + +static void discon_event() +{ + DEBUG_INFO("discon_event"); +} + +int main(int argc, char * argv[]) +{ + option_register(options); + if (!option_parse(argc, argv)) + return -1; + + if (!option_validate()) + return -1; + + PortholeClient phc; + if (!porthole_client_open( + &phc, + option_get_string("host", "socket"), + map_event, + unmap_event, + discon_event)) + { + return -1; + } + + porthole_client_close(&phc); + return 0; +} \ No newline at end of file