提交 0175c308 编写于 作者: N Nathan Hourt

Add a template for plugins

This is just an empty template plugin which will serve as a starting
point for new plugins.

Also add a helper script, make_new_plugin.sh, which copies the template
plugin to create your new plugin and automatically renames all of the
files/directories/classes/binaries/whatever. Invoke like so:
./make_new_plugin.sh new_plugin
Afterwards, the new_plugin folder will be ready to go.
上级 cf903679
#!/bin/bash
if [ $# -ne 1 ]; then
echo Usage: $0 my_new_plugin
echo ... where my_new_plugin is the name of the plugin you want to create
exit 1
fi
pluginName=$1
echo Copying template...
cp -r template_plugin $pluginName
echo Renaming files/directories...
mv $pluginName/include/eos/template_plugin $pluginName/include/eos/$pluginName
for file in `find $pluginName -type f -name '*template_plugin*'`; do mv $file `sed s/template_plugin/$pluginName/g <<< $file`; done;
echo Renaming in files...
find $pluginName -type f -exec sed -i "s/template_plugin/$pluginName/g" {} \;
echo "Done! $pluginName is ready. Don't forget to add it to CMakeLists.txt!"
file(GLOB HEADERS "include/eos/template_plugin/*.hpp")
add_library( template_plugin
template_plugin.cpp
${HEADERS} )
target_link_libraries( template_plugin appbase fc )
target_include_directories( template_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
install( TARGETS
template_plugin
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
install( FILES ${HEADERS} DESTINATION "include/eos/template_plugin" )
#pragma once
#include <appbase/application.hpp>
namespace eos {
using namespace appbase;
/**
* This is a template plugin, intended to serve as a starting point for making new plugins
*/
class template_plugin : public appbase::plugin<template_plugin>
{
public:
template_plugin();
virtual ~template_plugin();
APPBASE_PLUGIN_REQUIRES()
virtual void set_program_options(options_description&, options_description& cfg) override;
void plugin_initialize(const variables_map& options);
void plugin_startup();
void plugin_shutdown();
private:
std::unique_ptr<class template_plugin_impl> my;
};
}
#include <eos/template_plugin/template_plugin.hpp>
namespace eos {
class template_plugin_impl {
public:
};
template_plugin::template_plugin():my(new template_plugin_impl()){}
template_plugin::~template_plugin(){}
void template_plugin::set_program_options(options_description&, options_description& cfg) {
cfg.add_options()
("option-name", bpo::value<string>()->default_value("default value"),
"Option Description")
;
}
void template_plugin::plugin_initialize(const variables_map& options) {
if(options.count("option-name")) {
// Handle the option
}
}
void template_plugin::plugin_startup() {
// Make the magic happen
}
void template_plugin::plugin_shutdown() {
// OK, that's enough magic
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册