-
Notifications
You must be signed in to change notification settings - Fork 649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create plugin script #1302
Merged
+254
−0
Merged
Create plugin script #1302
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a7f14c2
add make_new_plugin script
oxarbitrage 066b676
fix duplicated step
oxarbitrage aa87cd2
remove space id section
oxarbitrage 64505a8
added automatic space_id detection
oxarbitrage 2e4edf9
make review changes
oxarbitrage 3dfa5ac
quote more pluginName
oxarbitrage 59728cb
add more double quotes
oxarbitrage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
# Find next available space id by checking all current plugins | ||
next_space_id () { | ||
SPACE_IDS=() | ||
for i in * ; do | ||
if [ -d "$i" ] && [ "$i" != "CMakeFiles" ]; then | ||
cd "$i/include/graphene/$i" | ||
result=$(grep -rnw '.' -e '#define[[:space:]]*[[:alnum:]]*_SPACE_ID') | ||
B=$(echo $result | cut -d ' ' -f 3) | ||
if [[ $B =~ [[:digit:]] ]]; then | ||
SPACE_IDS+=($B) | ||
fi | ||
cd "../../../.." | ||
fi | ||
done | ||
max=$( printf "%d\n" "${SPACE_IDS[@]}" | sort -n | tail -1 ) | ||
next=$(($max + 1)) | ||
return $next | ||
} | ||
|
||
## create new plugin | ||
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/graphene/template_plugin $pluginName/include/graphene/$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" {} \; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please quote |
||
echo "Assigning next available SPACE_ID..." | ||
next_space_id | ||
find $pluginName -type f -exec sed -i "s/@SPACE_ID@/$?/g" {} \; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please quote |
||
|
||
echo "Done! $pluginName is ready." | ||
echo "Next steps:" | ||
echo "1- Add 'add_subdirectory( $pluginName )' to CmakeLists.txt in this directory." | ||
echo "2- Add 'graphene_$pluginName' to ../../programs/witness_node/CMakeLists.txt with the other plugins." | ||
echo "3- Include plugin header file '#include <graphene/$pluginName/$pluginName.hpp>' to ../../programs/witness_node/main.cpp." | ||
echo "4- Initialize plugin with the others with 'auto ${pluginName}_plug = node->register_plugin<$pluginName::$pluginName>();' in ../../programs/witness_node/main.cpp" | ||
echo "5- cmake and make" | ||
echo "6- Start plugin with './../programs/witness_node/witness_node --plugins \"$pluginName\"'. After the seed nodes are added you start to see see a msgs from the plugin 'onBlock' " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
file(GLOB HEADERS "include/graphene/template_plugin/*.hpp") | ||
|
||
add_library( graphene_template_plugin | ||
template_plugin.cpp | ||
) | ||
|
||
target_link_libraries( graphene_template_plugin graphene_chain graphene_app ) | ||
target_include_directories( graphene_template_plugin | ||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) | ||
|
||
if(MSVC) | ||
set_source_files_properties(template_plugin.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) | ||
endif(MSVC) | ||
|
||
install( TARGETS | ||
graphene_template_plugin | ||
|
||
RUNTIME DESTINATION bin | ||
LIBRARY DESTINATION lib | ||
ARCHIVE DESTINATION lib | ||
) | ||
INSTALL( FILES ${HEADERS} DESTINATION "include/graphene/template_plugin" ) |
70 changes: 70 additions & 0 deletions
70
libraries/plugins/template_plugin/include/graphene/template_plugin/template_plugin.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2018 template_plugin and contributors. | ||
* | ||
* The MIT License | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
#pragma once | ||
|
||
#include <graphene/app/plugin.hpp> | ||
#include <graphene/chain/database.hpp> | ||
|
||
namespace graphene { namespace template_plugin { | ||
using namespace chain; | ||
|
||
// | ||
// Plugins should #define their SPACE_ID's so plugins with | ||
// conflicting SPACE_ID assignments can be compiled into the | ||
// same binary (by simply re-assigning some of the conflicting #defined | ||
// SPACE_ID's in a build script). | ||
// | ||
// Assignment of SPACE_ID's cannot be done at run-time because | ||
// various template automagic depends on them being known at compile | ||
// time. | ||
// | ||
#ifndef template_plugin_SPACE_ID | ||
#define template_plugin_SPACE_ID @SPACE_ID@ | ||
#endif | ||
|
||
|
||
namespace detail | ||
{ | ||
class template_plugin_impl; | ||
} | ||
|
||
class template_plugin : public graphene::app::plugin | ||
{ | ||
public: | ||
template_plugin(); | ||
virtual ~template_plugin(); | ||
|
||
std::string plugin_name()const override; | ||
std::string plugin_description()const override; | ||
virtual void plugin_set_program_options( | ||
boost::program_options::options_description& cli, | ||
boost::program_options::options_description& cfg) override; | ||
virtual void plugin_initialize(const boost::program_options::variables_map& options) override; | ||
virtual void plugin_startup() override; | ||
|
||
friend class detail::template_plugin_impl; | ||
std::unique_ptr<detail::template_plugin_impl> my; | ||
}; | ||
|
||
} } //graphene::template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright (c) 2018 template_plugin and contributors. | ||
* | ||
* The MIT License | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
#include <graphene/template_plugin/template_plugin.hpp> | ||
|
||
namespace graphene { namespace template_plugin { | ||
|
||
namespace detail | ||
{ | ||
|
||
class template_plugin_impl | ||
{ | ||
public: | ||
template_plugin_impl(template_plugin& _plugin) | ||
: _self( _plugin ) | ||
{ } | ||
virtual ~template_plugin_impl(); | ||
|
||
void onBlock( const signed_block& b ); | ||
|
||
graphene::chain::database& database() | ||
{ | ||
return _self.database(); | ||
} | ||
|
||
template_plugin& _self; | ||
|
||
std::string _plugin_option = ""; | ||
|
||
private: | ||
|
||
}; | ||
|
||
void template_plugin_impl::onBlock( const signed_block& b ) | ||
{ | ||
wdump((b.block_num())); | ||
} | ||
|
||
template_plugin_impl::~template_plugin_impl() | ||
{ | ||
return; | ||
} | ||
|
||
} // end namespace detail | ||
|
||
template_plugin::template_plugin() : | ||
my( new detail::template_plugin_impl(*this) ) | ||
{ | ||
} | ||
|
||
template_plugin::~template_plugin() | ||
{ | ||
} | ||
|
||
std::string template_plugin::plugin_name()const | ||
{ | ||
return "template_plugin"; | ||
} | ||
std::string template_plugin::plugin_description()const | ||
{ | ||
return "template_plugin description"; | ||
} | ||
|
||
void template_plugin::plugin_set_program_options( | ||
boost::program_options::options_description& cli, | ||
boost::program_options::options_description& cfg | ||
) | ||
{ | ||
cli.add_options() | ||
("template_plugin_option", boost::program_options::value<std::string>(), "template_plugin option") | ||
; | ||
cfg.add(cli); | ||
} | ||
|
||
void template_plugin::plugin_initialize(const boost::program_options::variables_map& options) | ||
{ | ||
database().applied_block.connect( [&]( const signed_block& b) { | ||
my->onBlock(b); | ||
} ); | ||
|
||
if (options.count("template_plugin")) { | ||
my->_plugin_option = options["template_plugin"].as<std::string>(); | ||
} | ||
} | ||
|
||
void template_plugin::plugin_startup() | ||
{ | ||
ilog("template_plugin: plugin_startup() begin"); | ||
} | ||
|
||
} } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please quote $pluginName here and in the following lines.