Skip to content

Commit a50c5f7

Browse files
Merge pull request #9 from NikolasK-source/main
Release 1.0.5
2 parents b0b4274 + 2c067f4 commit a50c5f7

File tree

10 files changed

+56
-125
lines changed

10 files changed

+56
-125
lines changed

.github/workflows/cmake.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
name: CMake
22

33
on:
4-
push:
5-
branches: [ "main", "development" ]
6-
pull_request:
7-
branches: [ "main" ]
4+
[push, pull_request ]
85

96
env:
107
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "libs/cxxopts"]
22
path = libs/cxxopts
33
url = https://github.com/NikolasK-source/cxxopts.git
4+
[submodule "libs/cxxshm"]
5+
path = libs/cxxshm
6+
url = https://github.com/NikolasK-source/cxxshm.git

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.13.4 FATAL_ERROR)
44
# ======================================================================================================================
55

66
# project
7-
project(stdin-to-modbus-shm LANGUAGES CXX VERSION 1.0.4)
7+
project(stdin-to-modbus-shm LANGUAGES CXX VERSION 1.0.5)
88

99
# settings
1010
set(Target "stdin-to-modbus-shm") # Executable name (without file extension!)

libs/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
# ---------------------------------------- link libraries --------------------------------------------------------------
88
# ======================================================================================================================
9-
target_link_libraries(${Target} PRIVATE rt)
10-
119
add_subdirectory(cxxopts EXCLUDE_FROM_ALL)
1210
target_link_libraries(${Target} PRIVATE cxxopts)
11+
12+
add_subdirectory(cxxshm EXCLUDE_FROM_ALL)
13+
target_link_libraries(${Target} PRIVATE cxxshm)
14+
15+
target_link_libraries(${Target} PRIVATE rt)

libs/cxxshm

Submodule cxxshm added at dfed3b0

src/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
# ======================================================================================================================
33

44
target_sources(${Target} PRIVATE main.cpp)
5-
target_sources(${Target} PRIVATE SHM.cpp)
65
target_sources(${Target} PRIVATE license.cpp)
76

87

98
# ---------------------------------------- header files (*.jpp, *.h, ...) ----------------------------------------------
109
# ======================================================================================================================
1110

12-
target_sources(${Target} PRIVATE SHM.hpp)
1311
target_sources(${Target} PRIVATE input_parse.hpp)
1412
target_sources(${Target} PRIVATE split_string.hpp)
1513
target_sources(${Target} PRIVATE license.hpp)

src/SHM.cpp

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/SHM.hpp

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/license.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,29 @@ void print_licenses(std::ostream &o) {
5454
o << " LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM," << std::endl;
5555
o << " OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN" << std::endl;
5656
o << " THE SOFTWARE." << std::endl;
57+
o << std::endl;
58+
o << std::endl;
59+
o << "cxxshm Library (https://github.com/NikolasK-source/cxxshm)" << std::endl;
60+
o << std::endl;
61+
o << " MIT License" << std::endl;
62+
o << std::endl;
63+
o << " Copyright (c) 2022 Nikolas Koesling" << std::endl;
64+
o << std::endl;
65+
o << " Permission is hereby granted, free of charge, to any person obtaining a copy" << std::endl;
66+
o << " of this software and associated documentation files (the \"Software\"), to deal" << std::endl;
67+
o << " in the Software without restriction, including without limitation the rights" << std::endl;
68+
o << " to use, copy, modify, merge, publish, distribute, sublicense, and/or sell" << std::endl;
69+
o << " copies of the Software, and to permit persons to whom the Software is" << std::endl;
70+
o << " furnished to do so, subject to the following conditions:" << std::endl;
71+
o << std::endl;
72+
o << " The above copyright notice and this permission notice shall be included in all" << std::endl;
73+
o << " copies or substantial portions of the Software." << std::endl;
74+
o << std::endl;
75+
o << " THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR" << std::endl;
76+
o << " IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY," << std::endl;
77+
o << " FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE" << std::endl;
78+
o << " AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER" << std::endl;
79+
o << " LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM," << std::endl;
80+
o << " OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE" << std::endl;
81+
o << " SOFTWARE." << std::endl;
5782
}

src/main.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* This program is free software. You can redistribute it and/or modify it under the terms of the MIT License.
44
*/
55

6-
#include "SHM.hpp"
76
#include "input_parse.hpp"
87
#include "license.hpp"
98

9+
#include "cxxshm.hpp"
1010
#include <csignal>
1111
#include <cxxopts.hpp>
1212
#include <filesystem>
@@ -36,7 +36,7 @@ int main(int argc, char **argv) {
3636
// establish signal handler
3737
static volatile bool terminate = false;
3838
auto sig_handler = [](int) { terminate = true; };
39-
if (signal(SIGINT, sig_handler) || signal(SIGTERM, sig_handler)) {
39+
if (signal(SIGINT, sig_handler) == SIG_ERR || signal(SIGTERM, sig_handler) == SIG_ERR) {
4040
perror("Failed to establish signal handler");
4141
exit(EX_OSERR);
4242
}
@@ -83,7 +83,8 @@ int main(int argc, char **argv) {
8383
std::cout << std::endl;
8484
std::cout << "This application uses the following libraries:" << std::endl;
8585
std::cout << " - cxxopts by jarro2783 (https://github.com/jarro2783/cxxopts)" << std::endl;
86-
exit(EX_OK);
86+
std::cout << " - cxxshm (https://github.com/NikolasK-source/cxxshm)" << std::endl;
87+
return EX_OK;
8788
}
8889

8990
// print version
@@ -96,62 +97,62 @@ int main(int argc, char **argv) {
9697
// print licenses
9798
if (args.count("license")) {
9899
print_licenses(std::cout);
99-
exit(EX_OK);
100+
return EX_OK;
100101
}
101102

102103
// open shared memory objects
103104
const auto &name_prefix = args["name-prefix"].as<std::string>();
104105

105-
std::unique_ptr<SHM> shm_do;
106-
std::unique_ptr<SHM> shm_di;
107-
std::unique_ptr<SHM> shm_ao;
108-
std::unique_ptr<SHM> shm_ai;
106+
std::unique_ptr<cxxshm::SharedMemory> shm_do;
107+
std::unique_ptr<cxxshm::SharedMemory> shm_di;
108+
std::unique_ptr<cxxshm::SharedMemory> shm_ao;
109+
std::unique_ptr<cxxshm::SharedMemory> shm_ai;
109110

110111
try {
111-
shm_do = std::make_unique<SHM>(name_prefix + "DO");
112-
shm_di = std::make_unique<SHM>(name_prefix + "DI");
113-
shm_ao = std::make_unique<SHM>(name_prefix + "AO");
114-
shm_ai = std::make_unique<SHM>(name_prefix + "AI");
112+
shm_do = std::make_unique<cxxshm::SharedMemory>(name_prefix + "DO");
113+
shm_di = std::make_unique<cxxshm::SharedMemory>(name_prefix + "DI");
114+
shm_ao = std::make_unique<cxxshm::SharedMemory>(name_prefix + "AO");
115+
shm_ai = std::make_unique<cxxshm::SharedMemory>(name_prefix + "AI");
115116
} catch (const std::system_error &e) {
116117
std::cerr << e.what() << std::endl;
117-
exit(EX_OSERR);
118+
return EX_OSERR;
118119
}
119120

120121
// check shared mem
121122
if (shm_do->get_size() > MAX_MODBUS_REGS) {
122123
std::cerr << "shared memory '" << shm_do->get_name() << "is to large to be a valid modbus shared memory."
123124
<< std::endl;
124-
exit(EX_SOFTWARE);
125+
return EX_SOFTWARE;
125126
}
126127

127128
if (shm_di->get_size() > MAX_MODBUS_REGS) {
128129
std::cerr << "shared memory '" << shm_di->get_name() << "' is to large to be a valid modbus shared memory."
129130
<< std::endl;
130-
exit(EX_SOFTWARE);
131+
return EX_SOFTWARE;
131132
}
132133

133134
if (shm_ao->get_size() / 2 > MAX_MODBUS_REGS) {
134135
std::cerr << "shared memory '" << shm_ao->get_name() << "' is to large to be a valid modbus shared memory."
135136
<< std::endl;
136-
exit(EX_SOFTWARE);
137+
return EX_SOFTWARE;
137138
}
138139

139140
if (shm_ai->get_size() / 2 > MAX_MODBUS_REGS) {
140141
std::cerr << "shared memory '" << shm_ai->get_name() << "' is to large to be a valid modbus shared memory."
141142
<< std::endl;
142-
exit(EX_SOFTWARE);
143+
return EX_SOFTWARE;
143144
}
144145

145146
if (shm_ao->get_size() % 2) {
146147
std::cerr << "the size of shared memory '" << shm_ao->get_name() << "' is odd. It is not a valid modbus shm."
147148
<< std::endl;
148-
exit(EX_SOFTWARE);
149+
return EX_SOFTWARE;
149150
}
150151

151152
if (shm_ai->get_size() % 2) {
152153
std::cerr << "the size of shared memory '" << shm_ai->get_name() << "' is odd. It is not a valid modbus shm."
153154
<< std::endl;
154-
exit(EX_SOFTWARE);
155+
return EX_SOFTWARE;
155156
}
156157

157158
const std::size_t do_elements = shm_do->get_size();

0 commit comments

Comments
 (0)