Skip to content

Commit 5d45c6d

Browse files
Merge pull request #3 from janekbaraniewski/init
init3
2 parents 7c85d20 + 92ad54c commit 5d45c6d

File tree

13 files changed

+248
-197
lines changed

13 files changed

+248
-197
lines changed

.github/workflows/docker.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ on:
1212
jobs:
1313
build-and-push:
1414
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
component: [server, client]
1518

1619
steps:
1720
- name: Checkout code
@@ -27,11 +30,9 @@ jobs:
2730
username: ${{ github.actor }}
2831
password: ${{ secrets.GITHUB_TOKEN }}
2932

30-
- name: Build and tag the Docker image
31-
run: make build-images
32-
33-
- name: tag images
34-
run: make tag-images
35-
36-
- name: Push Docker images to GitHub Packages
37-
run: make push-images
33+
- name: Build container image
34+
run: make build-${{ matrix.component }}-image
35+
- name: Tag container image
36+
run: make tag-${{ matrix.component }}-image
37+
- name: Push container image
38+
run: make push-${{ matrix.component }}-image

.github/workflows/release.yml

Lines changed: 92 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Release
1+
name: Cross-Platform and Cross-Architecture Release Build
22

33
on:
44
push:
@@ -7,27 +7,66 @@ on:
77

88
jobs:
99
build-and-release:
10-
runs-on: ubuntu-latest
10+
runs-on: ${{ matrix.config.os }}
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
config:
15+
# Define combinations of operating systems and architectures
16+
- {os: ubuntu-latest, arch: x64, server-artifact: serial_server_linux_x64, client-artifact: serial_client_linux_x64}
17+
- {os: ubuntu-latest, arch: arm64, server-artifact: serial_server_linux_arm64, client-artifact: serial_client_linux_arm64}
18+
- {os: windows-latest, arch: x64, server-artifact: serial_server_windows_x64.exe, client-artifact: serial_client_windows_x64.exe}
19+
- {os: windows-latest, arch: arm64, server-artifact: serial_server_windows_arm64.exe, client-artifact: serial_client_windows_arm64.exe}
20+
- {os: macos-latest, arch: x64, server-artifact: serial_server_mac_x64, client-artifact: serial_client_mac_x64}
21+
- {os: macos-latest, arch: arm64, server-artifact: serial_server_mac_arm64, client-artifact: serial_client_mac_arm64}
1122

1223
steps:
1324
- uses: actions/checkout@v3
25+
1426
- name: Set up Python
1527
uses: actions/setup-python@v4
1628
with:
1729
python-version: '3.x'
18-
- name: Install dependencies
30+
31+
- name: Install dependencies (Ubuntu)
32+
if: startsWith(matrix.config.os, 'ubuntu')
1933
run: |
2034
sudo apt-get update
2135
sudo apt-get install -y libboost-all-dev
36+
37+
- name: Install dependencies (macOS)
38+
if: startsWith(matrix.config.os, 'macos')
39+
run: |
40+
brew install boost
41+
42+
- name: Install dependencies (Windows)
43+
if: startsWith(matrix.config.os, 'windows')
44+
run: |
45+
choco install boost-msvc-14.2
46+
47+
- name: Set up CMake (All platforms)
48+
uses: lukka/get-cmake@latest
49+
50+
- name: Configure CMake
51+
run: |
52+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_ARCHITECTURE_ID=${{ matrix.config.arch }}
53+
2254
- name: Build
2355
run: |
24-
cmake -S . -B build
25-
cmake --build build
26-
- name: Archive Production Artifacts
56+
cmake --build build --config Release
57+
58+
- name: Archive Server Production Artifacts
2759
uses: actions/upload-artifact@v3
2860
with:
29-
name: binaries
30-
path: build/
61+
name: ${{ matrix.config.server-artifact }}
62+
path: build/${{ matrix.config.server-artifact }}
63+
64+
- name: Archive Client Production Artifacts
65+
uses: actions/upload-artifact@v3
66+
with:
67+
name: ${{ matrix.config.client-artifact }}
68+
path: build/${{ matrix.config.client-artifact }}
69+
3170
- name: Create Release
3271
id: create_release
3372
uses: actions/create-release@v1
@@ -38,12 +77,54 @@ jobs:
3877
release_name: Release ${{ github.ref }}
3978
draft: false
4079
prerelease: false
41-
- name: Upload Release Asset
80+
81+
- name: Upload Server Release Asset
82+
uses: actions/upload-release-asset@v2
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
with:
86+
upload_url: ${{ steps.create_release.outputs.upload_url }}
87+
asset_path: ./build/${{ matrix.config.server-artifact }}
88+
asset_name: ${{ matrix.config.server-artifact }}
89+
asset_content_type: application/octet-stream
90+
91+
- name: Upload Client Release Asset
4292
uses: actions/upload-release-asset@v2
4393
env:
4494
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4595
with:
4696
upload_url: ${{ steps.create_release.outputs.upload_url }}
47-
asset_path: ./build/serial_server
48-
asset_name: serial_server
97+
asset_path: ./build/${{ matrix.config.client-artifact }}
98+
asset_name: ${{ matrix.config.client-artifact }}
4999
asset_content_type: application/octet-stream
100+
101+
container-image:
102+
runs-on: ubuntu-latest
103+
strategy:
104+
matrix:
105+
component: [server, client]
106+
107+
steps:
108+
- name: Checkout code
109+
uses: actions/checkout@v2
110+
111+
- name: Set up Docker Buildx
112+
uses: docker/setup-buildx-action@v1
113+
114+
- name: Login to GitHub Container Registry
115+
uses: docker/login-action@v3
116+
with:
117+
registry: ghcr.io
118+
username: ${{ github.actor }}
119+
password: ${{ secrets.GITHUB_TOKEN }}
120+
121+
- name: Build container image
122+
run: make build-${{ matrix.component }}-image
123+
124+
- name: Tag containner image
125+
run: make tag-${{ matrix.component }}-image
126+
127+
- name: Push containner images
128+
run: make push-${{ matrix.component }}-images
129+
130+

.github/workflows/test.yml

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,55 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-latest
11+
runs-on: ${{ matrix.config.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
config:
16+
# Define combinations of operating systems and architectures
17+
- {os: ubuntu-latest, arch: x64, server-artifact: serial_server_linux_x64, client-artifact: serial_client_linux_x64}
18+
- {os: ubuntu-latest, arch: arm64, server-artifact: serial_server_linux_arm64, client-artifact: serial_client_linux_arm64}
19+
- {os: windows-latest, arch: x64, server-artifact: serial_server_windows_x64.exe, client-artifact: serial_client_windows_x64.exe}
20+
- {os: windows-latest, arch: arm64, server-artifact: serial_server_windows_arm64.exe, client-artifact: serial_client_windows_arm64.exe}
21+
- {os: macos-latest, arch: x64, server-artifact: serial_server_mac_x64, client-artifact: serial_client_mac_x64}
22+
- {os: macos-latest, arch: arm64, server-artifact: serial_server_mac_arm64, client-artifact: serial_client_mac_arm64}
1223

1324
steps:
1425
- uses: actions/checkout@v3
15-
- name: Install dependencies
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v4
29+
with:
30+
python-version: '3.x'
31+
32+
- name: Install dependencies (Ubuntu)
33+
if: startsWith(matrix.config.os, 'ubuntu')
1634
run: |
1735
sudo apt-get update
1836
sudo apt-get install -y libboost-all-dev
19-
- name: Run tests
20-
run: make test
2137
22-
docker:
38+
- name: Install dependencies (macOS)
39+
if: startsWith(matrix.config.os, 'macos')
40+
run: |
41+
brew install boost
42+
43+
- name: Install dependencies (Windows)
44+
if: startsWith(matrix.config.os, 'windows')
45+
run: |
46+
choco install boost-msvc-14.2
47+
48+
- name: Set up CMake (All platforms)
49+
uses: lukka/get-cmake@latest
50+
51+
- name: make build
52+
run: |
53+
make build
54+
55+
container-image:
2356
runs-on: ubuntu-latest
57+
strategy:
58+
matrix:
59+
component: [server, client]
2460

2561
steps:
2662
- name: Checkout code
@@ -29,5 +65,12 @@ jobs:
2965
- name: Set up Docker Buildx
3066
uses: docker/setup-buildx-action@v1
3167

32-
- name: Build and tag the Docker image
33-
run: make build-images
68+
- name: Login to GitHub Container Registry
69+
uses: docker/login-action@v3
70+
with:
71+
registry: ghcr.io
72+
username: ${{ github.actor }}
73+
password: ${{ secrets.GITHUB_TOKEN }}
74+
75+
- name: Build container image
76+
run: make build-${{ matrix.component }}-image

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ target_link_libraries(logging PUBLIC
3131
Boost::date_time
3232
)
3333

34-
add_library(serial_server_lib src/logging.cpp src/server.cpp src/VirtualSerialPort.cpp) # Include VirtualSerialPort.cpp
34+
add_library(serial_server_lib src/logging.cpp src/SerialServer.cpp src/VirtualSerialPort.cpp)
3535
target_include_directories(serial_server_lib PUBLIC ${CMAKE_SOURCE_DIR}/include)
3636
target_link_libraries(serial_server_lib PRIVATE
3737
Boost::system
@@ -43,7 +43,7 @@ target_link_libraries(serial_server_lib PRIVATE
4343
pthread
4444
)
4545

46-
add_executable(serial_server src/server.cpp)
46+
add_executable(serial_server src/SerialServer.cpp)
4747
target_link_libraries(serial_server PRIVATE
4848
serial_server_lib
4949
logging
@@ -54,7 +54,7 @@ target_link_libraries(serial_server PRIVATE
5454
Boost::date_time
5555
)
5656

57-
add_executable(serial_client src/client.cpp)
57+
add_executable(serial_client src/SerialClient.cpp)
5858
target_link_libraries(serial_client PRIVATE
5959
serial_server_lib
6060
logging

Makefile

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,52 @@ REPO = ghcr.io/janekbaraniewski/ser2net2ser
33
VERSION ?= latest
44
COMMIT_HASH ?= $(shell git rev-parse --short HEAD)
55

6-
clean:
6+
help: ## Show this help message
7+
@echo "Usage: make [target]"
8+
@echo ""
9+
@echo "Available targets:"
10+
@grep -E '^[a-zA-Z_\-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " %-30s %s\n", $$1, $$2}'
11+
12+
clean: ## Clean build directory
713
@rm -rf ${BUILD_DIR}/*
814

15+
build: ## Build with cmake
916
build: clean
1017
@cmake -S . -B build
1118
@cmake --build build
1219

20+
test: ## Build and test
1321
test: build
1422
@cd build && ctest
1523

16-
build-images:
24+
build-images: ## Build container images
25+
build-images: build-server-image build-client-image
26+
27+
build-server-image:
1728
@docker build . -f Dockerfile.server -t $(REPO)/server:$(COMMIT_HASH)
29+
30+
build-client-image:
1831
@docker build . -f Dockerfile.client -t $(REPO)/client:$(COMMIT_HASH)
1932

20-
tag-images:
33+
tag-images: ## Tag container images
34+
tag-images: tag-server-image tag-client-image
35+
36+
tag-server-image:
2137
@docker tag $(REPO)/server:$(COMMIT_HASH) $(REPO)/server:$(VERSION)
38+
39+
tag-client-image:
2240
@docker tag $(REPO)/client:$(COMMIT_HASH) $(REPO)/client:$(VERSION)
2341

24-
push-images: tag-images
42+
43+
push-images: ## Push container images to registry
44+
push-images: tag-images push-server-images push-client-images
45+
46+
push-server-images:
2547
@docker push $(REPO)/server:$(COMMIT_HASH)
2648
@docker push $(REPO)/server:$(VERSION)
49+
50+
push-client-images:
2751
@docker push $(REPO)/client:$(COMMIT_HASH)
2852
@docker push $(REPO)/client:$(VERSION)
2953

30-
help:
31-
@echo "Makefile commands:"
32-
@echo " clean - Remove build directory."
33-
@echo " build - Build the project using cmake."
34-
@echo " test - Run tests after building."
35-
@echo " build-images - Build Docker images for both server and client."
36-
@echo " tag-images - Tag Docker images with the latest or specified version."
37-
@echo " push-images - Push Docker images to the registry."
38-
@echo " help - Show this help message."
39-
40-
.PHONY: clean build test build-images tag-images push-images help
54+
.PHONY: clean build test build-images build-server-image build-client-image tag-images tag-client-image tag-server-image push-images push-client-images push-server-images help

include/SerialClient.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef CLIENT_H
2+
#define CLIENT_H
3+
4+
#include "common.hpp"
5+
#include "VirtualSerialPort.h"
6+
7+
using namespace boost::asio;
8+
using ip::tcp;
9+
using std::string;
10+
11+
class SerialClient {
12+
public:
13+
SerialClient(const string& server_ip, unsigned short server_port, const string& vsp_name);
14+
void run();
15+
16+
private:
17+
io_service io_service_;
18+
tcp::socket socket_;
19+
std::array<char, 256> buffer_;
20+
VirtualSerialPort vsp_;
21+
22+
void do_read_write();
23+
};
24+
25+
26+
#endif // CLIENT_H

include/SerialServer.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef SERVER_H
2+
#define SERVER_H
3+
4+
#include "common.hpp"
5+
#include "ISerialPort.h"
6+
#include "RealSerialPort.h"
7+
8+
using namespace boost::asio;
9+
using ip::tcp;
10+
using std::string;
11+
12+
class SerialServer {
13+
public:
14+
SerialServer(io_service& io, ISerialPort& serial, tcp::acceptor& acceptor);
15+
void run();
16+
17+
private:
18+
io_service& io_service_;
19+
ISerialPort& serial_;
20+
tcp::acceptor& acceptor_;
21+
tcp::socket socket_;
22+
23+
void start_accept();
24+
void do_read_write();
25+
};
26+
27+
#endif // SERVER_H

0 commit comments

Comments
 (0)