Merge pull request 'Roundtrip with ZeroMQ' (#1) from zmq into master
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #1pull/2/head
commit
169323098d
@ -1,3 +1,7 @@
|
||||
bin
|
||||
build
|
||||
obj
|
||||
|
||||
.idea
|
||||
.vscode
|
||||
cmake-build-debug
|
||||
|
@ -1,19 +1,51 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
|
||||
|
||||
project(planificador)
|
||||
|
||||
add_compile_options(-Wall -Wextra -pedantic)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
tomlplusplus
|
||||
GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
|
||||
GIT_TAG v3.3.0
|
||||
tomlplusplus
|
||||
GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
|
||||
GIT_TAG v3.3.0
|
||||
)
|
||||
FetchContent_MakeAvailable(tomlplusplus)
|
||||
|
||||
file(GLOB nameFile "src/*.cpp")
|
||||
add_executable(planificador src/host.cpp src/runner.cpp src/config.cpp src/main.cpp )
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/libzmq-pkg-config)
|
||||
find_package(ZeroMQ QUIET)
|
||||
|
||||
add_executable(planificador src/host.cpp src/runner.cpp src/network.cpp src/config.cpp src/main.cpp)
|
||||
if (NOT ZeroMQ_FOUND)
|
||||
message(STATUS "ZeroMQ not found, using bundled version")
|
||||
FetchContent_Declare(
|
||||
zmq
|
||||
GIT_REPOSITORY https://github.com/zeromq/libzmq.git
|
||||
GIT_TAG v4.3.5
|
||||
)
|
||||
FetchContent_Declare(
|
||||
cppzmq
|
||||
GIT_REPOSITORY https://github.com/zeromq/cppzmq.git
|
||||
GIT_TAG v4.10.0
|
||||
)
|
||||
set(WITH_PERF_TOOL OFF)
|
||||
set(ENABLE_CPACK OFF)
|
||||
set(ZMQ_BUILD_TESTS OFF)
|
||||
set(WITH_TLS OFF)
|
||||
set(WITH_DOC OFF)
|
||||
set(BUILD_STATIC OFF)
|
||||
set(BUILD_SHARED ON)
|
||||
set(ZMQ_BUILD_TESTS OFF)
|
||||
set(CPPZMQ_BUILD_TESTS OFF)
|
||||
FetchContent_MakeAvailable(zmq cppzmq)
|
||||
include_directories(${zmq_SOURCE_DIR}/include)
|
||||
include_directories(${cppzmq_SOURCE_DIR})
|
||||
target_link_libraries(planificador PRIVATE libzmq)
|
||||
else ()
|
||||
target_link_libraries(planificador PRIVATE zmq)
|
||||
endif ()
|
||||
|
||||
target_compile_options(planificador PUBLIC -Wall -Wextra -pedantic)
|
||||
target_compile_features(planificador PUBLIC cxx_std_17)
|
||||
|
||||
include_directories(${tomlplusplus_SOURCE_DIR}/include)
|
||||
|
@ -0,0 +1,28 @@
|
||||
# Adapted from https://github.com/zeromq/cppzmq/blob/master/CMakeLists.txt
|
||||
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON)
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(PC_LIBZMQ QUIET libzmq)
|
||||
|
||||
set(ZeroMQ_VERSION ${PC_LIBZMQ_VERSION})
|
||||
|
||||
find_path(ZeroMQ_INCLUDE_DIR zmq.h
|
||||
PATHS ${ZeroMQ_DIR}/include
|
||||
${PC_LIBZMQ_INCLUDE_DIRS})
|
||||
|
||||
find_library(ZeroMQ_LIBRARY
|
||||
NAMES zmq
|
||||
PATHS ${ZeroMQ_DIR}/lib
|
||||
${PC_LIBZMQ_LIBDIR}
|
||||
${PC_LIBZMQ_LIBRARY_DIRS})
|
||||
|
||||
if(ZeroMQ_LIBRARY)
|
||||
set(ZeroMQ_FOUND ON)
|
||||
endif()
|
||||
|
||||
set ( ZeroMQ_LIBRARIES ${ZeroMQ_LIBRARY} )
|
||||
set ( ZeroMQ_INCLUDE_DIRS ${ZeroMQ_INCLUDE_DIR} )
|
||||
|
||||
include ( FindPackageHandleStandardArgs )
|
||||
# handle the QUIETLY and REQUIRED arguments and set ZMQ_FOUND to TRUE
|
||||
# if all listed variables are TRUE
|
||||
find_package_handle_standard_args ( ZeroMQ DEFAULT_MSG ZeroMQ_LIBRARIES ZeroMQ_INCLUDE_DIRS )
|
@ -1,23 +1,16 @@
|
||||
#include "host.hpp"
|
||||
|
||||
namespace sk {
|
||||
host::host(const std::string &ip, unsigned int connectionsMax)
|
||||
: ip{ip}, connections{0}, connectionsMax{connectionsMax}, runners{} {}
|
||||
host::host(const std::string &ip, unsigned int connectionsMax) : ip{ip}, connections{0}, connectionsMax{connectionsMax}, runners{} {}
|
||||
|
||||
void host::addConnection(sk::runner& runner) {
|
||||
void host::addConnection(sk::runner &runner) {
|
||||
runners.push(runner);
|
||||
connections += 1;
|
||||
}
|
||||
|
||||
const std::string& host::getIp() const {
|
||||
return ip;
|
||||
}
|
||||
const std::string &host::getIp() const { return ip; }
|
||||
|
||||
unsigned int host::getNbConnections() const {
|
||||
return connections;
|
||||
}
|
||||
unsigned int host::getNbConnections() const { return connections; }
|
||||
|
||||
unsigned int host::getNbConnectionsMax() const {
|
||||
return connectionsMax;
|
||||
}
|
||||
unsigned int host::getNbConnectionsMax() const { return connectionsMax; }
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
#include "network.hpp"
|
||||
|
||||
namespace sk {
|
||||
uint32_t read_uint32(const char *buffer) { return static_cast<uint32_t>(buffer[3]) | static_cast<uint32_t>(buffer[2]) << 8 | static_cast<uint32_t>(buffer[1]) << 16 | static_cast<uint32_t>(buffer[0]) << 24; }
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace sk {
|
||||
uint32_t read_uint32(const char *buffer);
|
||||
}
|
Loading…
Reference in new issue