Commit 90c38552 authored by Micha Müller's avatar Micha Müller

Add support for entities in pluginGenerator scripts

parent 8d1cbabf
......@@ -13,8 +13,16 @@ cat << EOF > ${PLUGIN_NAME}Configurator.cpp
${PLUGIN_NAME}Configurator::${PLUGIN_NAME}Configurator() {
/*
* TODO
* If you want sensor, group or entity to be named differently in the config file, you can change it here
* If you want sensor or group to be named differently in the config file, you can change it here
*/
EOF
if [ "$enableEntities" = true ]
then
echo " _entityName = \"${ENTITY_NAME_LWC}\";" >> ${PLUGIN_NAME}Configurator.cpp
fi
cat << EOF >> ${PLUGIN_NAME}Configurator.cpp
_groupName = "group";
_baseName = "sensor";
}
......@@ -40,6 +48,42 @@ void ${PLUGIN_NAME}Configurator::sensorGroup(${PLUGIN_NAME}SensorGroup& s, CFG_V
}
}
EOF
if [ "$enableEntities" = true ]
then
cat << EOF >> ${PLUGIN_NAME}Configurator.cpp
void ${PLUGIN_NAME}Configurator::sensorEntity(${PLUGIN_NAME}${ENTITY_NAME}& s, CFG_VAL config) {
ADD {
/*
* TODO
* Add ATTRIBUTE macros for ${ENTITY_NAME} attributes
*/
}
}
bool ${PLUGIN_NAME}Configurator::isEntityOfGroup(${PLUGIN_NAME}${ENTITY_NAME}& e, ${PLUGIN_NAME}SensorGroup& g) {
return (g.get${ENTITY_NAME}() == &e);
}
void ${PLUGIN_NAME}Configurator::setEntityForGroup(${PLUGIN_NAME}${ENTITY_NAME}& e, ${PLUGIN_NAME}SensorGroup& g) {
g.set${ENTITY_NAME}(&e);
}
void ${PLUGIN_NAME}Configurator::finalizeGroup(${PLUGIN_NAME}SensorGroup& g) {
/*
* TODO
* Do final configuration of group depending on its entity.
* If not required this method can be removed.
*/
//e.g. configure MQTT depending on entity
//g.setMqttPart(g.get${ENTITY_NAME}()->getMqttPart() + g.getMqttPart());
}
EOF
fi
cat << EOF >> ${PLUGIN_NAME}Configurator.cpp
void ${PLUGIN_NAME}Configurator::printConfiguratorConfig(LOG_LEVEL ll) {
/*
* TODO
......@@ -47,6 +91,24 @@ void ${PLUGIN_NAME}Configurator::printConfiguratorConfig(LOG_LEVEL ll) {
* not attributes to log.
*/
LOG_VAR(ll) << " NumSpacesAsIndention: " << 2;
EOF
if [ "$enableEntities" = true ]
then
cat << EOF >> ${PLUGIN_NAME}Configurator.cpp
LOG_VAR(ll) << " ${ENTITY_NAME}s:";
if (_sensorEntitys.size() != 0) {
for(auto e : _sensorEntitys) {
e->printConfig(ll);
}
} else {
LOG_VAR(ll) << " No ${ENTITY_NAME}s present!";
}
EOF
fi
cat << EOF >> ${PLUGIN_NAME}Configurator.cpp
}
EOF
......@@ -13,6 +13,14 @@ cat << EOF > ${PLUGIN_NAME}Configurator.h
#include "../../includes/ConfiguratorTemplate.h"
#include "${PLUGIN_NAME}SensorGroup.h"
EOF
if [ "$enableEntities" = true ]
then
echo "#include \"${PLUGIN_NAME}${ENTITY_NAME}.h\"" >> ${PLUGIN_NAME}Configurator.h
fi
cat << EOF >> ${PLUGIN_NAME}Configurator.h
class ${PLUGIN_NAME}Configurator : public ConfiguratorTemplate<${PLUGIN_NAME}SensorBase, ${PLUGIN_NAME}SensorGroup> {
......@@ -24,6 +32,20 @@ protected:
/* Overwritten from ConfiguratorTemplate */
void sensorBase(${PLUGIN_NAME}SensorBase& s, CFG_VAL config) override;
void sensorGroup(${PLUGIN_NAME}SensorGroup& s, CFG_VAL config) override;
EOF
if [ "$enableEntities" = true ]
then
cat << EOF >> ${PLUGIN_NAME}Configurator.h
void sensorEntity(${PLUGIN_NAME}${ENTITY_NAME}& s, CFG_VAL config) override;
bool isEntityOfGroup(${PLUGIN_NAME}${ENTITY_NAME}& e, ${PLUGIN_NAME}SensorGroup& g) override;
void setEntityForGroup(${PLUGIN_NAME}${ENTITY_NAME}& e, ${PLUGIN_NAME}SensorGroup& g) override;
void finalizeGroup(${PLUGIN_NAME}SensorGroup& g) override;
EOF
fi
cat << EOF >> ${PLUGIN_NAME}Configurator.h
void printConfiguratorConfig(LOG_LEVEL ll) override;
};
......
#!/bin/sh
cat << EOF > ${PLUGIN_NAME}${ENTITY_NAME}.cpp
/*
* ${PLUGIN_NAME}${ENTITY_NAME}.cpp
*
* Created on: ${DATE}
* Author: ${AUTHOR}
*/
#include "${PLUGIN_NAME}${ENTITY_NAME}.h"
${PLUGIN_NAME}${ENTITY_NAME}::${PLUGIN_NAME}${ENTITY_NAME}() {
/*
* TODO
* Init attributes
*/
_strand = nullptr;
}
${PLUGIN_NAME}${ENTITY_NAME}::~${PLUGIN_NAME}${ENTITY_NAME}() {
/*
* TODO
* Tear down attributes
*/
if (_strand) {
delete _strand;
}
}
/*
* TODO
* Implement own methods
*/
void ${PLUGIN_NAME}${ENTITY_NAME}::initializeStrand(boost::asio::io_service& io) {
if (!_strand) {
_strand = new boost::asio::io_service::strand(io);
}
}
void ${PLUGIN_NAME}${ENTITY_NAME}::printConfig(LOG_LEVEL ll) {
/*
* TODO
* Log attributes here for debug reasons
*/
LOG_VAR(ll) << " NumSpacesAsIndention: " << 3;
}
EOF
#!/bin/sh
cat << EOF > ${PLUGIN_NAME}${ENTITY_NAME}.h
/*
* ${PLUGIN_NAME}${ENTITY_NAME}.h
*
* Created on: ${DATE}
* Author: ${AUTHOR}
*/
#ifndef ${PLUGIN_NAME_UPC}${ENTITY_NAME_UPC}_H_
#define ${PLUGIN_NAME_UPC}${ENTITY_NAME_UPC}_H_
#include <boost/asio.hpp>
#include "../../includes/Logging.h"
class ${PLUGIN_NAME}${ENTITY_NAME} {
public:
${PLUGIN_NAME}${ENTITY_NAME}();
virtual ~${PLUGIN_NAME}${ENTITY_NAME}();
/*
* TODO
* Add methods the entity provides to the SensorGroups.
* Add getter/setter for the attributes as required.
* To make the entity thread safe if called from multiple SensorGroups at
* once, we use a boost::strand. Feel free to get rid of _strand and related
* methods if your entity is already thread safe.
*/
void initializeStrand(boost::asio::io_service& io);
boost::asio::io_service::strand* getStrand() const { return _strand; }
void printConfig(LOG_LEVEL ll);
private:
/*
* TODO
* Add attributes required for your entity
* If your entity is thread safe you can remove the _strand
*/
boost::asio::io_service::strand* _strand;
LOGGER lg;
};
#endif /* ${PLUGIN_NAME_UPC}${ENTITY_NAME_UPC}_H_ */
EOF
......@@ -12,6 +12,15 @@ cat << EOF > ${PLUGIN_NAME}SensorBase.h
#define ${PLUGIN_NAME_UPC}_${PLUGIN_NAME_UPC}SENSORBASE_H_
#include "../../includes/SensorBase.h"
EOF
if [ "$enableEntities" = true ]
then
echo "" >> ${PLUGIN_NAME}SensorBase.h
echo "#include \"${PLUGIN_NAME}${ENTITY_NAME}.h\"" >> ${PLUGIN_NAME}SensorBase.h
fi
cat << EOF >> ${PLUGIN_NAME}SensorBase.h
/*
* TODO
......
......@@ -14,7 +14,14 @@ cat << EOF > ${PLUGIN_NAME}SensorGroup.cpp
${PLUGIN_NAME}SensorGroup::${PLUGIN_NAME}SensorGroup(const std::string& name) :
SensorGroupTemplate(name) {
EOF
if [ "$enableEntities" = true ]
then
echo " _${ENTITY_NAME_LWC} = nullptr;" >> ${PLUGIN_NAME}SensorGroup.cpp
fi
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
/*
* TODO
* Init attributes
......@@ -22,8 +29,17 @@ ${PLUGIN_NAME}SensorGroup::${PLUGIN_NAME}SensorGroup(const std::string& name) :
}
${PLUGIN_NAME}SensorGroup::${PLUGIN_NAME}SensorGroup(const ${PLUGIN_NAME}SensorGroup& other) :
SensorGroupTemplate(other) {
EOF
if [ "$enableEntities" = true ]
then
echo " SensorGroupTemplate(other)," >> ${PLUGIN_NAME}SensorGroup.cpp
echo " _${ENTITY_NAME_LWC}(other._${ENTITY_NAME_LWC}) {" >> ${PLUGIN_NAME}SensorGroup.cpp
else
echo " SensorGroupTemplate(other) {" >> ${PLUGIN_NAME}SensorGroup.cpp
fi
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
/*
* TODO
* Copy construct attributes
......@@ -34,11 +50,27 @@ ${PLUGIN_NAME}SensorGroup::~${PLUGIN_NAME}SensorGroup() {
/*
* TODO
* Tear down attributes
EOF
if [ "$enableEntities" = true ]
then
echo " * But do not delete _${ENTITY_NAME_LWC}! The configurator takes care of it." >> ${PLUGIN_NAME}SensorGroup.cpp
fi
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
*/
}
${PLUGIN_NAME}SensorGroup& ${PLUGIN_NAME}SensorGroup::operator=(const ${PLUGIN_NAME}SensorGroup& other) {
SensorGroupTemplate::operator=(other);
SensorGroupTemplate::operator=(other);
EOF
if [ "$enableEntities" = true ]
then
echo " _${ENTITY_NAME_LWC} = other._${ENTITY_NAME_LWC};" >> ${PLUGIN_NAME}SensorGroup.cpp
fi
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
/*
* TODO
* Implement assignment operator
......@@ -59,10 +91,31 @@ void ${PLUGIN_NAME}SensorGroup::start() {
* Start plugin specific stuff
*/
_keepRunning = 1;
EOF
if [ "$enableEntities" = true ]
then
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
if (_${ENTITY_NAME_LWC}) {
_keepRunning = 1;
_pendingTasks++;
_timer->async_wait(_${ENTITY_NAME_LWC}->getStrand()->wrap(std::bind(&${PLUGIN_NAME}SensorGroup::readAsync, this)));
LOG(info) << "Sensorgroup " << _groupName << " started.";
} else {
LOG(error) << "No ${ENTITY_NAME} set for sensorgroup " << _groupName << "! Cannot start polling.";
return;
}
EOF
else
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
_keepRunning = 1;
_pendingTasks++;
_timer->async_wait(std::bind(&${PLUGIN_NAME}SensorGroup::readAsync, this));
LOG(info) << "Sensorgroup " << _groupName << " started.";
EOF
fi
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
}
void ${PLUGIN_NAME}SensorGroup::stop() {
......@@ -78,10 +131,30 @@ void ${PLUGIN_NAME}SensorGroup::stop() {
void ${PLUGIN_NAME}SensorGroup::init(boost::asio::io_service& io) {
SensorGroupTemplate::init(io);
EOF
if [ "$enableEntities" = true ]
then
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
if (_${ENTITY_NAME_LWC}) {
_${ENTITY_NAME_LWC}->initializeStrand(io);
} else {
LOG(error)<< "No ${ENTITY_NAME} set for sensorgroup " << _groupName << "! Cannot initialize sensor.";
}
/**
* TODO Initialize here Sensor Group or remove this member function completely
* TODO Initialize here Sensor Group if required
*/
EOF
else
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
/**
* TODO Initialize here Sensor Group or remove this member function completely
* The SensorGroupTemplate::init(io); will then be called
*/
EOF
fi
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
}
void ${PLUGIN_NAME}SensorGroup::read() {
......@@ -94,6 +167,14 @@ void ${PLUGIN_NAME}SensorGroup::read() {
* TODO
* Read a value for every sensor affiliated with this group and store
* it with the appropriate sensor.
EOF
if [ "$enableEntities" = true ]
then
echo " * Make use of _${ENTITY_NAME_LWC} as required." >> ${PLUGIN_NAME}SensorGroup.cpp
fi
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
*/ 0;
s->storeReading(reading);
#ifdef DEBUG
......@@ -109,9 +190,18 @@ void ${PLUGIN_NAME}SensorGroup::readAsync() {
uint64_t now = getTimestamp();
read();
if (_timer && _keepRunning) {
_timer->expires_at(nextReadingTime());
_timer->expires_at(timestamp2ptime(nextReadingTime()));
_pendingTasks++;
_timer->async_wait(std::bind(&${PLUGIN_NAME}SensorGroup::readAsync, this));
EOF
if [ "$enableEntities" = true ]
then
echo " _timer->async_wait(_${ENTITY_NAME_LWC}->getStrand()->wrap(std::bind(&${PLUGIN_NAME}SensorGroup::readAsync, this)));" >> ${PLUGIN_NAME}SensorGroup.cpp
else
echo " _timer->async_wait(std::bind(&${PLUGIN_NAME}SensorGroup::readAsync, this));" >> ${PLUGIN_NAME}SensorGroup.cpp
fi
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
}
_pendingTasks--;
}
......@@ -120,7 +210,16 @@ void ${PLUGIN_NAME}SensorGroup::printConfig(LOG_LEVEL ll) {
/*
* TODO
* Log attributes here for debug reasons
EOF
if [ "$enableEntities" = true ]
then
echo " * Printing the name of _${ENTITY_NAME_LWC} may be a good idea." >> ${PLUGIN_NAME}SensorGroup.cpp
fi
cat << EOF >> ${PLUGIN_NAME}SensorGroup.cpp
*/
LOG_VAR(ll) << " NumSpacesAsIndention: " << 3;
}
EOF
......@@ -30,6 +30,15 @@ public:
* TODO
* Add getter and setters for group attributes if required
*/
EOF
if [ "$enableEntities" = true ]
then
echo " void set${ENTITY_NAME}(${PLUGIN_NAME}${ENTITY_NAME}* ${ENTITY_NAME_LWC}) { _${ENTITY_NAME_LWC} = ${ENTITY_NAME_LWC}; }" >> ${PLUGIN_NAME}SensorGroup.h
echo " ${PLUGIN_NAME}${ENTITY_NAME}* const get${ENTITY_NAME}() const { return _${ENTITY_NAME_LWC}; }" >> ${PLUGIN_NAME}SensorGroup.h
fi
cat << EOF >> ${PLUGIN_NAME}SensorGroup.h
void printConfig(LOG_LEVEL ll) override;
......@@ -41,6 +50,14 @@ private:
* TODO
* Add group internal attributes
*/
EOF
if [ "$enableEntities" = true ]
then
echo " ${PLUGIN_NAME}${ENTITY_NAME}* _${ENTITY_NAME_LWC};" >> ${PLUGIN_NAME}SensorGroup.h
fi
cat << EOF >> ${PLUGIN_NAME}SensorGroup.h
};
#endif /* ${PLUGIN_NAME_UPC}_${PLUGIN_NAME_UPC}SENSORGROUP_H_ */
......
......@@ -9,6 +9,50 @@ global {
;add here other global attributes for your plugin
}
EOF
if [ "$enableEntities" = true ]
then
cat << EOF >> ${PLUGIN_NAME_LWC}.conf
template_group def1 {
;define template groups by appending "template_"
interval 1000
minValues 3
groupAtt 1234
;add other attributes your plugin requires for a sensor group
;define sensors belonging to the group below
sensor temp1 {
sensorAtt 5678
;add other attributes your plugin requires for a sensor
}
}
${ENTITY_NAME_LWC} ent1 {
entityAtt 1234
single_sensor sens1 {
;if you want a group with only one sensor you can use a single_sensor
default temp1
mqttsuffix 0001
;add other attributes your plugin requires for a sensor
}
group g1 {
interval 1000
mqttprefix 01
default def1
;sensor temp1 is taken from def1 and does not need to be redefined
sensor gSens {
mqttsuffix 00
}
}
}
EOF
else
cat << EOF >> ${PLUGIN_NAME_LWC}.conf
template_group def1 {
;define template groups by appending "template_"
interval 1000
......@@ -42,3 +86,4 @@ group g1 {
}
}
EOF
fi
......@@ -2,26 +2,23 @@
# Reminder in shell 0 = true, 1 = false
#TODO: make sensor, group and entity name configurable
echo "NOTE: Entities currently not supported!"
#TODO: add option to create entity class
#TODO: make sensor and group name configurable
# Init variables
DATE=`date '+%d.%m.%Y'`
AUTHOR="Your name goes here!"
PLUGIN_NAME=""
enableGroups=false
enableEntities=false
# parse input
while getopts "hp:ga:" opt; do
while getopts "hp:e:a:" opt; do
case "$opt" in
h)
echo "Usage:"
echo "./generatePlugin.sh -p pluginName"
echo "Options:"
echo "-h\tPrint this help section"
# echo "-e xx\tGenerate files for entity"
echo "-e xx\tGenerate files for entity"
echo "-a xx\tSpecify name of the author which is to be mentioned in the"
echo "\tsource files"
exit 0
......@@ -29,9 +26,10 @@ while getopts "hp:ga:" opt; do
p) PLUGIN_NAME=$OPTARG
echo "Plugin named ${PLUGIN_NAME}"
;;
# e) ENTITY_NAME=$OPTARG
# echo "Generating entity ${ENTITY_NAME}"
# ;;
e) enableEntities=true
ENTITY_NAME=$OPTARG
echo "Generating entity ${ENTITY_NAME}"
;;
a) AUTHOR=$OPTARG
echo "Author: ${AUTHOR}"
;;
......@@ -48,6 +46,11 @@ fi
# Set further variables
PLUGIN_NAME_UPC=`echo $PLUGIN_NAME | tr 'a-z' 'A-Z'`
PLUGIN_NAME_LWC=`echo $PLUGIN_NAME | tr 'A-Z' 'a-z'`
if [ "$enableEntities" = true ]
then
ENTITY_NAME_UPC=`echo $ENTITY_NAME | tr 'a-z' 'A-Z'`
ENTITY_NAME_LWC=`echo $ENTITY_NAME | tr 'A-Z' 'a-z'`
fi
if [ -e ${PLUGIN_NAME_LWC} ]
then
......@@ -70,6 +73,17 @@ echo "Generating ${PLUGIN_NAME}SensorGroup.h ..."
echo "Generating ${PLUGIN_NAME}SensorGroup.cpp ..."
. ../SensorGroup_cpp.sh
if [ "$enableEntities" = true ]
then
# Generate ...$Entity.h
echo "Generating ${PLUGIN_NAME}${ENTITY_NAME}.h ..."
. ../Entity_h.sh
# Generate ...$Entity.cpp
echo "Generating ${PLUGIN_NAME}${ENTITY_NAME}.cpp ..."
. ../Entity_cpp.sh
fi
# Generate ...Configurator.h
echo "Generating ${PLUGIN_NAME}Configurator.h ..."
. ../Configurator_h.sh
......
......@@ -5,7 +5,16 @@ Append to PLUGINS variable: ${PLUGIN_NAME_LWC}
Append at end of Makefile:
libdcdbplugin_${PLUGIN_NAME_LWC}.\$(LIBEXT): src/sensors/${PLUGIN_NAME_LWC}/${PLUGIN_NAME}SensorGroup.o src/sensors/${PLUGIN_NAME_LWC}/${PLUGIN_NAME}Configurator.o
EOF
if [ "$enableEntities" = true ]
then
echo "libdcdbplugin_${PLUGIN_NAME_LWC}.\$(LIBEXT): src/sensors/${PLUGIN_NAME_LWC}/${PLUGIN_NAME}SensorGroup.o src/sensors/${PLUGIN_NAME_LWC}/${PLUGIN_NAME}Configurator.o src/sensors/${PLUGIN_NAME_LWC}/${PLUGIN_NAME}${ENTITY_NAME}.o" >> appendToMakefile.txt
else
echo "libdcdbplugin_${PLUGIN_NAME_LWC}.\$(LIBEXT): src/sensors/${PLUGIN_NAME_LWC}/${PLUGIN_NAME}SensorGroup.o src/sensors/${PLUGIN_NAME_LWC}/${PLUGIN_NAME}Configurator.o" >> appendToMakefile.txt
fi
cat << EOF >> appendToMakefile.txt
\$(CXX) \$(LIBFLAGS)\$@ -o \$@ $^ -L\$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system
NOTE: Probably you will have to append further libraries to the linker for your plugin to compile
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment