Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build/
dist/
.git/
external/microsoft/vcpkg/
*.o
*.a
*.so
*.dylib
30 changes: 11 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
cmake_minimum_required(VERSION 3.23.5)

file(READ "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" SYNAPSE_CPP_VERSION)
string(STRIP "${SYNAPSE_CPP_VERSION}" SYNAPSE_CPP_VERSION)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" SYNAPSE_CPP_VERSION_FULL)
string(STRIP "${SYNAPSE_CPP_VERSION_FULL}" SYNAPSE_CPP_VERSION_FULL)
# Extract semver (before any -suffix) for CMake VERSION
string(REGEX REPLACE "^([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" SYNAPSE_CPP_VERSION "${SYNAPSE_CPP_VERSION_FULL}")
project(synapse VERSION ${SYNAPSE_CPP_VERSION})

set(CMAKE_CXX_STANDARD 17)
Expand All @@ -10,7 +12,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)

find_package(gRPC CONFIG REQUIRED)
find_package(Protobuf REQUIRED CONFIG)
find_package(science-libndtp REQUIRED CONFIG)
find_package(cppzmq CONFIG REQUIRED)
find_package(science-scipp REQUIRED CONFIG)

add_library(${PROJECT_NAME})
Expand Down Expand Up @@ -70,7 +72,7 @@ target_link_libraries(
PRIVATE
gRPC::grpc++
protobuf::libprotobuf
science::libndtp
cppzmq
science::scipp
)

Expand Down Expand Up @@ -111,21 +113,11 @@ install(
)

if ("examples" IN_LIST VCPKG_MANIFEST_FEATURES)
add_executable(stream_out examples/stream_out/main.cpp)
file(GLOB_RECURSE TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/examples/stream_out/*.cpp")
target_sources(stream_out PRIVATE ${TEST_SOURCES})
target_include_directories(stream_out PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/examples)
target_link_libraries(stream_out PRIVATE ${PROJECT_NAME} science::scipp)
set_target_properties(stream_out PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/examples"
)

add_executable(stats examples/stats/main.cpp)
file(GLOB_RECURSE TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/examples/stats/*.cpp")
target_sources(stats PRIVATE ${TEST_SOURCES})
target_include_directories(stats PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/examples)
target_link_libraries(stats PRIVATE ${PROJECT_NAME} science::scipp)
set_target_properties(stats PROPERTIES
# Tap example
add_executable(tap_example examples/tap/main.cpp)
target_include_directories(tap_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/examples)
target_link_libraries(tap_example PRIVATE ${PROJECT_NAME} science::scipp)
set_target_properties(tap_example PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/examples"
)
endif()
Expand Down
55 changes: 55 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
git \
curl \
zip \
unzip \
tar \
pkg-config \
ninja-build \
autoconf \
automake \
libtool \
python3 \
wget \
gpg \
&& rm -rf /var/lib/apt/lists/*

# Install CMake 3.27 via direct binary download (compatible with preset v6 and older vcpkg)
ARG CMAKE_VERSION=3.27.9
RUN wget -qO- "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-aarch64.tar.gz" \
| tar --strip-components=1 -xz -C /usr/local

# Set up vcpkg (VCPKG_FORCE_SYSTEM_BINARIES required for ARM platforms)
ENV VCPKG_ROOT=/vcpkg
ENV VCPKG_FORCE_SYSTEM_BINARIES=1
RUN git clone https://github.com/microsoft/vcpkg.git $VCPKG_ROOT && \
cd $VCPKG_ROOT && \
git checkout 1751f9f8c732c2e6f9e81ce56c10e4c4aa265b4a && \
./bootstrap-vcpkg.sh

WORKDIR /src

# Copy source files (excluding git dirs and build artifacts via .dockerignore)
COPY . .

# Clone submodules at pinned versions
RUN rm -rf external/sciencecorp/synapse-api && \
git clone --branch v2.1.0 https://github.com/sciencecorp/synapse-api.git external/sciencecorp/synapse-api

RUN if [ ! -d "external/sciencecorp/vcpkg/ports" ]; then \
rm -rf external/sciencecorp/vcpkg && \
git clone https://github.com/sciencecorp/vcpkg.git external/sciencecorp/vcpkg; \
fi

# Configure and build
RUN cmake --preset=static -DCMAKE_BUILD_TYPE=Debug -DVCPKG_MANIFEST_FEATURES="examples;tests"
RUN cmake --build build

# Run tests
CMD ["./build/synapse_tests"]
70 changes: 68 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,72 @@ synapse provides CMake targets:

This library offers a C++ interface to the Synapse API.

See the [examples](./examples) for more details.
### Device Operations

```cpp
#include <science/synapse/device.h>
#include <science/synapse/config.h>

// Connect to a device
synapse::Device device("192.168.1.100:50051");

// Get device info
synapse::DeviceInfo info;
device.info(&info);

// Configure, start, and stop
synapse::Config config;
// ... add nodes to config ...
device.configure(&config);
device.start();
device.stop();

// Query the device
synapse::QueryRequest req;
req.set_query_type(synapse::QueryType::kListTaps);
synapse::QueryResponse res;
device.query(req, &res);
```

### Tap Client (High-Throughput Data Streaming)

```cpp
#include <science/synapse/tap.h>

// Connect to a tap for streaming data
synapse::Tap tap("192.168.1.100:50051");

// List available taps
auto taps = tap.list_taps();

// Connect to a producer tap (read data from device)
tap.connect("broadband_tap");

// Read data
std::vector<uint8_t> data;
while (tap.read(&data).ok()) {
// Process protobuf-encoded data (e.g., BroadbandFrame)
}

https://github.com/sciencecorp/synapse-cpp/blob/main/examples/stream_out/main.cpp
// Or read in batches for higher throughput
std::vector<std::vector<uint8_t>> batch;
size_t count = tap.read_batch(&batch, 100, 10); // up to 100 messages, 10ms timeout
```

### Discovery

```cpp
#include <science/synapse/util/discover.h>

// Discover devices on the network (passive UDP listening)
std::vector<synapse::DeviceAdvertisement> devices;
synapse::discover(5000, &devices); // 5 second timeout

// Or use callback-based discovery
synapse::discover_iter([](const synapse::DeviceAdvertisement& device) {
std::cout << "Found: " << device.name << " at " << device.host << std::endl;
return true; // continue discovery
}, 10000);
```

See the [examples](./examples) for more details.
19 changes: 19 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"

IMAGE_NAME="synapse-cpp-builder"
CONTAINER_NAME="synapse-cpp-build"

echo "Building Docker image..."
docker build -t "$IMAGE_NAME" .

echo "Build successful!"
echo ""
echo "To run tests:"
echo " docker run --rm $IMAGE_NAME"
echo ""
echo "To get an interactive shell:"
echo " docker run --rm -it $IMAGE_NAME /bin/bash"
2 changes: 1 addition & 1 deletion cmake/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

find_package(gRPC REQUIRED CONFIG)
find_package(Protobuf REQUIRED CONFIG)
find_package(science-libndtp REQUIRED CONFIG)
find_package(cppzmq REQUIRED CONFIG)
find_package(science-scipp REQUIRED CONFIG)

include("${CMAKE_CURRENT_LIST_DIR}/synapseTargets.cmake")
Expand Down
152 changes: 0 additions & 152 deletions examples/stats/main.cpp

This file was deleted.

Loading