-
Notifications
You must be signed in to change notification settings - Fork 1
/
makemodule
executable file
·110 lines (90 loc) · 2.79 KB
/
makemodule
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage $0 modulename" >&2
exit 1
fi
cd Modules
if [ ! -d $1 ]; then
mkdir $1
mkdir $1/src
mkdir $1/include
cd $1
cat <<EOF > CMakeLists.txt
cmake_minimum_required (VERSION 3.1)
set (CMAKE_CXX_STANDARD 11)
get_filename_component(ProjectId \${CMAKE_CURRENT_LIST_DIR} NAME)
string(REPLACE " " "_" ProjectId \${ProjectId})
project(\${ProjectId} C CXX)
include( \${CMAKE_CURRENT_LIST_DIR}/../../CMakeLists.custom.txt )
# Boost dependency
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package( Boost 1.63.0 REQUIRED COMPONENTS system thread program_options filesystem chrono )
include_directories( \${Boost_INCLUDE_DIRS} )
if(CMAKE_COMPILER_IS_GNUCC)
set (CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -Wall -Wpedantic")
endif(CMAKE_COMPILER_IS_GNUCC)
include_directories(include ../../include)
file(GLOB SOURCES "src/*.cpp")
add_library(\${CMAKE_PROJECT_NAME} SHARED \${SOURCES})
target_link_libraries(\${CMAKE_PROJECT_NAME} \${CUSTOM_TARGET_LINK_LIBS})
EOF
cat <<EOF > src/$1.cpp
#include "$1.h"
/* Declare module details (name, description, cparams, can be source) */
DEFAULT_EXPORT_ALL($1, "$1 module", "", PROCESSING_MODULE)
/* Constructor */
$1::$1(const std::string& mid) : poma::Module<$1, PomaDataType>(mid) {}
/* Method for processing incoming data packets */
void $1::on_incoming_data(PomaPacketType& dta, const std::string& channel)
{
/*
// Enable the following if the module supports dynamic reconfiguration
{
synchronized_scope(); // Prevent race conditions on dynamic properties
if (check_reconfigure_module()) {
// Perform necessary module reconfiguration (if some property has changed)
}
}
*/
submit_data(dta);
}
void $1::setup_cli(boost::program_options::options_description& desc) const
{
boost::program_options::options_description ${1}Options("$1 options");
${1}Options.add_options()
("anoption", boost::program_options::value<std::string>()->default_value("default"), "A sample CLI");
desc.add(${1}Options);
}
void $1::process_cli(boost::program_options::variables_map& vm)
{
m_field = vm["default"].as<std::string>();
}
void $1::initialize()
{
set_reconfigure_module();
}
EOF
cat << EOF > include/$1.h
#ifndef ${1^^}_H
#define ${1^^}_H
#include "PomaDefault.h"
class $1 : public poma::Module<$1, PomaDataType>
{
public:
DECLARE_PROPERTIES((m_field)) // Dynamic properties
$1(const std::string& mid);
void on_incoming_data(PomaPacketType& dta, const std::string& channel) override;
void setup_cli(boost::program_options::options_description& desc) const override;
void process_cli(boost::program_options::variables_map& vm) override;
void initialize() override;
private:
std::string m_field;
};
#endif
EOF
else
echo "Module $1 already exists" >&2
exit 2
fi