mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-08 21:40:43 +02:00
add network_io folder
This commit is contained in:
parent
9e96f8b150
commit
f772434072
2
.github/workflows/common-workflow.yml
vendored
2
.github/workflows/common-workflow.yml
vendored
@ -45,7 +45,7 @@ jobs:
|
|||||||
pwd
|
pwd
|
||||||
export PROJECT_ROOT_DIR="."
|
export PROJECT_ROOT_DIR="."
|
||||||
ls build/examples/*_example
|
ls build/examples/*_example
|
||||||
find build/examples -name "*_example" -not -name "zmq_example" | xargs -I {} -n 1 -t bash -c {}
|
find build/examples -name "*_example" -not -name "zmq_*" | xargs -I {} -n 1 -t bash -c {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,11 +148,12 @@ endif()
|
|||||||
add_subdirectory(core)
|
add_subdirectory(core)
|
||||||
add_subdirectory(file_io)
|
add_subdirectory(file_io)
|
||||||
add_subdirectory(utils)
|
add_subdirectory(utils)
|
||||||
|
add_subdirectory(network_io)
|
||||||
|
|
||||||
|
|
||||||
#Overall target to link to when using the library
|
#Overall target to link to when using the library
|
||||||
add_library(aare INTERFACE)
|
add_library(aare INTERFACE)
|
||||||
target_link_libraries(aare INTERFACE core file_io utils)
|
target_link_libraries(aare INTERFACE core file_io utils network_io)
|
||||||
target_include_directories(aare INTERFACE
|
target_include_directories(aare INTERFACE
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
$<INSTALL_INTERFACE:include>
|
$<INSTALL_INTERFACE:include>
|
||||||
|
@ -4,7 +4,6 @@ set(SourceFiles
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/defs.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/defs.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/DType.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/DType.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Frame.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Frame.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ZmqSocket.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -12,7 +11,7 @@ add_library(core STATIC ${SourceFiles})
|
|||||||
target_include_directories(core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
target_include_directories(core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(core PUBLIC fmt::fmt PRIVATE aare_compiler_flags utils libzmq)
|
target_link_libraries(core PUBLIC fmt::fmt PRIVATE aare_compiler_flags utils )
|
||||||
|
|
||||||
if (AARE_PYTHON_BINDINGS)
|
if (AARE_PYTHON_BINDINGS)
|
||||||
set_property(TARGET core PROPERTY POSITION_INDEPENDENT_CODE ON)
|
set_property(TARGET core PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
set(EXAMPLE_LIST "json_example;logger_example;numpy_read_example;multiport_example;raw_example;zmq_example;")
|
set(EXAMPLE_LIST "json_example;logger_example;numpy_read_example;multiport_example;raw_example;")
|
||||||
set(EXAMPLE_LIST "${EXAMPLE_LIST};mythen_example;numpy_write_example")
|
set(EXAMPLE_LIST "${EXAMPLE_LIST};mythen_example;numpy_write_example;zmq_receiver_example;zmq_sender_example;")
|
||||||
foreach(example ${EXAMPLE_LIST})
|
foreach(example ${EXAMPLE_LIST})
|
||||||
add_executable(${example} ${example}.cpp)
|
add_executable(${example} ${example}.cpp)
|
||||||
target_link_libraries(${example} PUBLIC aare PRIVATE aare_compiler_flags)
|
target_link_libraries(${example} PUBLIC aare PRIVATE aare_compiler_flags)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#include "aare/ZmqSocket.hpp"
|
#include "aare/ZmqSocketReceiver.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::string endpoint = "tcp://localhost:5555";
|
std::string endpoint = "tcp://localhost:5555";
|
||||||
aare::ZmqSocket socket(endpoint);
|
aare::ZmqSocketReceiver socket(endpoint);
|
||||||
socket.connect();
|
socket.connect();
|
||||||
char *data = new char[1024 * 1024 * 10];
|
char *data = new char[1024 * 1024 * 10];
|
||||||
aare::zmqHeader header;
|
aare::zmqHeader header;
|
16
examples/zmq_sender_example.cpp
Normal file
16
examples/zmq_sender_example.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include "aare/ZmqSocketReceiver.hpp"
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::string endpoint = "tcp://localhost:5555";
|
||||||
|
aare::ZmqSocketReceiver socket(endpoint);
|
||||||
|
socket.connect();
|
||||||
|
char *data = new char[1024 * 1024 * 10];
|
||||||
|
aare::zmqHeader header;
|
||||||
|
while (true) {
|
||||||
|
int rc = socket.receive(header, reinterpret_cast<std::byte *>(data));
|
||||||
|
}
|
||||||
|
delete[] data;
|
||||||
|
return 0;
|
||||||
|
}
|
15
network_io/CMakeLists.txt
Normal file
15
network_io/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
add_library(network_io STATIC src/ZmqSocketReceiver.cpp)
|
||||||
|
target_include_directories(network_io PUBLIC include)
|
||||||
|
target_link_libraries(network_io PRIVATE libzmq fmt::fmt core utils aare_compiler_flags)
|
||||||
|
|
||||||
|
if(AARE_PYTHON_BINDINGS)
|
||||||
|
set_property(TARGET file_io PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# if(AARE_TESTS)
|
||||||
|
# set(TestSources
|
||||||
|
# ${CMAKE_CURRENT_SOURCE_DIR}/test/NumpyFile.test.cpp
|
||||||
|
# )
|
||||||
|
# target_sources(tests PRIVATE ${TestSources} )
|
||||||
|
# target_link_libraries(tests PRIVATE core network_io)
|
||||||
|
# endif()
|
@ -64,7 +64,7 @@ struct zmqHeader {
|
|||||||
std::array<int, 4> rx_roi{};
|
std::array<int, 4> rx_roi{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class ZmqSocket {
|
class ZmqSocketReceiver {
|
||||||
void *m_context{nullptr};
|
void *m_context{nullptr};
|
||||||
void *m_socket{nullptr};
|
void *m_socket{nullptr};
|
||||||
std::string m_endpoint;
|
std::string m_endpoint;
|
||||||
@ -76,11 +76,11 @@ class ZmqSocket {
|
|||||||
bool decode_header(zmqHeader &h);
|
bool decode_header(zmqHeader &h);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ZmqSocket(const std::string &endpoint);
|
ZmqSocketReceiver(const std::string &endpoint);
|
||||||
~ZmqSocket();
|
~ZmqSocketReceiver();
|
||||||
ZmqSocket(const ZmqSocket &) = delete;
|
ZmqSocketReceiver(const ZmqSocketReceiver &) = delete;
|
||||||
ZmqSocket operator=(const ZmqSocket &) = delete;
|
ZmqSocketReceiver operator=(const ZmqSocketReceiver &) = delete;
|
||||||
ZmqSocket(ZmqSocket &&) = delete;
|
ZmqSocketReceiver(ZmqSocketReceiver &&) = delete;
|
||||||
|
|
||||||
void connect();
|
void connect();
|
||||||
void disconnect();
|
void disconnect();
|
@ -1,14 +1,14 @@
|
|||||||
#include "aare/ZmqSocket.hpp"
|
#include "aare/ZmqSocketReceiver.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include <zmq.h>
|
#include <zmq.h>
|
||||||
|
|
||||||
namespace aare {
|
namespace aare {
|
||||||
|
|
||||||
ZmqSocket::ZmqSocket(const std::string &endpoint) : m_endpoint(endpoint) {
|
ZmqSocketReceiver::ZmqSocketReceiver(const std::string &endpoint) : m_endpoint(endpoint) {
|
||||||
memset(m_header_buffer, 0, m_max_header_size);
|
memset(m_header_buffer, 0, m_max_header_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZmqSocket::connect() {
|
void ZmqSocketReceiver::connect() {
|
||||||
m_context = zmq_ctx_new();
|
m_context = zmq_ctx_new();
|
||||||
m_socket = zmq_socket(m_context, ZMQ_SUB);
|
m_socket = zmq_socket(m_context, ZMQ_SUB);
|
||||||
fmt::print("Setting ZMQ_RCVHWM to {}\n", m_zmq_hwm);
|
fmt::print("Setting ZMQ_RCVHWM to {}\n", m_zmq_hwm);
|
||||||
@ -26,24 +26,24 @@ void ZmqSocket::connect() {
|
|||||||
zmq_setsockopt(m_socket, ZMQ_SUBSCRIBE, "", 0);
|
zmq_setsockopt(m_socket, ZMQ_SUBSCRIBE, "", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZmqSocket::disconnect() {
|
void ZmqSocketReceiver::disconnect() {
|
||||||
zmq_close(m_socket);
|
zmq_close(m_socket);
|
||||||
zmq_ctx_destroy(m_context);
|
zmq_ctx_destroy(m_context);
|
||||||
m_socket = nullptr;
|
m_socket = nullptr;
|
||||||
m_context = nullptr;
|
m_context = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZmqSocket::~ZmqSocket() {
|
ZmqSocketReceiver::~ZmqSocketReceiver() {
|
||||||
if (m_socket)
|
if (m_socket)
|
||||||
disconnect();
|
disconnect();
|
||||||
delete[] m_header_buffer;
|
delete[] m_header_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZmqSocket::set_zmq_hwm(int hwm) { m_zmq_hwm = hwm; }
|
void ZmqSocketReceiver::set_zmq_hwm(int hwm) { m_zmq_hwm = hwm; }
|
||||||
|
|
||||||
void ZmqSocket::set_timeout_ms(int n) { m_timeout_ms = n; }
|
void ZmqSocketReceiver::set_timeout_ms(int n) { m_timeout_ms = n; }
|
||||||
|
|
||||||
int ZmqSocket::receive(zmqHeader &header, std::byte *data) {
|
int ZmqSocketReceiver::receive(zmqHeader &header, std::byte *data) {
|
||||||
|
|
||||||
// receive header
|
// receive header
|
||||||
int header_bytes_received = zmq_recv(m_socket, m_header_buffer, m_max_header_size, 0);
|
int header_bytes_received = zmq_recv(m_socket, m_header_buffer, m_max_header_size, 0);
|
||||||
@ -74,7 +74,7 @@ int ZmqSocket::receive(zmqHeader &header, std::byte *data) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZmqSocket::decode_header(zmqHeader &h) {
|
bool ZmqSocketReceiver::decode_header(zmqHeader &h) {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user