forked from Yurii-huang/pluma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
FunNing
committed
Sep 23, 2020
1 parent
f4da2e2
commit b54469c
Showing
15 changed files
with
865 additions
and
6 deletions.
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,41 @@ | ||
cmake_minimum_required(VERSION 2.8.0) | ||
|
||
project(Pluma) | ||
|
||
set(CMAKE_BUILD_RPATH ${CMAKE_CURRENT_SOURCE_DIR}/build) | ||
message(${CMAKE_BUILD_RPATH}) | ||
|
||
add_definitions( | ||
-DPLUMA_EXPORTS | ||
) | ||
|
||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BUILD_RPATH}/lib_Debug) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BUILD_RPATH}/lib_Release) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BUILD_RPATH}/lib_MinSizeRel) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BUILD_RPATH}/lib_RelInfoDebug) | ||
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BUILD_RPATH}/bin_Debug) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BUILD_RPATH}/bin_Release) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BUILD_RPATH}/bin_MinSizeRel) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BUILD_RPATH}/bin_RelInfoDebug) | ||
|
||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BUILD_RPATH}/lib_Debug) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BUILD_RPATH}/lib_Release) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BUILD_RPATH}/lib_MinSizeRel) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BUILD_RPATH}/lib_RelInfoDebug) | ||
|
||
set(SOURCE_HEAD ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
set(SOURCE_CPP ${CMAKE_CURRENT_SOURCE_DIR}/src) | ||
|
||
include_directories( | ||
${SOURCE_HEAD} | ||
${SOURCE_HEAD}/Pluma | ||
${SOURCE_CPP} | ||
${SOURCE_CPP}/Pluma | ||
) | ||
|
||
aux_source_directory(${SOURCE_CPP}/Pluma PlumaStaticSRC) | ||
|
||
add_library(Pluma STATIC ${PlumaStaticSRC}) | ||
|
||
subdirs(${CMAKE_CURRENT_SOURCE_DIR}/example) |
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
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,215 @@ | ||
#include <iostream> | ||
#include "PlumaCore.hpp" | ||
#include "PlumaPipe.hpp" | ||
|
||
class test2 | ||
{ | ||
public: | ||
test2(){} | ||
|
||
int rihandler(int ar){PDebug() << FUNCTION_INFO << ar; return ar*2;} | ||
|
||
void handler(int ar){PDebug() << FUNCTION_INFO << ar;} | ||
|
||
void handler(){PDebug()<< FUNCTION_INFO;} | ||
|
||
void handlerTh1Join(){PDebug()<< FUNCTION_INFO;} | ||
|
||
void handlerTh2Join(){PDebug() << FUNCTION_INFO;} | ||
|
||
void handlerTh1Dirc() | ||
{ | ||
while(1){PDebug()<< FUNCTION_INFO;} | ||
} | ||
|
||
void handlerTh2Dirc() | ||
{ | ||
while(1){PDebug()<< FUNCTION_INFO;} | ||
} | ||
|
||
static void shandler(int ar){PDebug() << FUNCTION_INFO << ar;} | ||
}; | ||
|
||
|
||
static void testFunc() | ||
{ | ||
std::cout << FUNCTION_INFO << std::endl; | ||
} | ||
|
||
//argument -Core in Args | ||
static void coreProc(std::string& coreName) | ||
{ | ||
std::cout<< FUNCTION_INFO << coreName << std::endl; | ||
} | ||
|
||
//argument -Plugin in Args | ||
static void pluginPathProc(std::string& pluginPath) | ||
{ | ||
std::cout<< FUNCTION_INFO << pluginPath << std::endl; | ||
} | ||
|
||
static void interfaceProc(std::string& interfaces) | ||
{ | ||
std::cout<< FUNCTION_INFO << interfaces << std::endl; | ||
} | ||
|
||
static void deviceProc(std::string& devices) | ||
{ | ||
std::cout<< FUNCTION_INFO << devices << std::endl; | ||
} | ||
|
||
/* 0: defualt model is keypress 存在输入提示 | ||
* 1: process model not keypress 关闭输入提示 | ||
* */ | ||
static int s_RunModel = 0; | ||
static void runmodelProc(std::string& model) | ||
{ | ||
if(model == "ShowKeyPress") | ||
s_RunModel = 0; | ||
|
||
if(model == "HideKeyPress") | ||
s_RunModel = 1; | ||
|
||
if(model == "JsonFormat") | ||
s_RunModel = 2; | ||
} | ||
|
||
|
||
|
||
static void readChannel() | ||
{ | ||
PDebug()<< FUNCTION_INFO; | ||
} | ||
|
||
static void writeChannel() | ||
{ | ||
PDebug()<< FUNCTION_INFO; | ||
} | ||
|
||
static void helpChannel() | ||
{ | ||
std::map<std::string,std::string> helpInfor; | ||
|
||
helpInfor.insert({ | ||
"help", | ||
"show command help" | ||
}); | ||
|
||
helpInfor.insert({ | ||
"readChannel", | ||
std::string("std::cout from current process out data") + | ||
", current application: " + | ||
PlumaCore::Application::name() | ||
}); | ||
|
||
helpInfor.insert({ | ||
"writeCahnnel", | ||
std::string("need transfer data to current process") + | ||
", current application: " + | ||
PlumaCore::Application::name() | ||
}); | ||
|
||
PDebug() << "command help:"; | ||
for(auto val: helpInfor) | ||
{ | ||
PDebug() << " " << val.first << " : " << val.second; | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
PlumaCore::Application a(argc,argv); | ||
|
||
for(auto var: PlumaCore::Application::arguments()){std::cout << var << std::endl;} | ||
std::cout << "\n" << std::endl; | ||
std::cout << PlumaCore::Application::runPath() << std::endl; | ||
std::cout << PlumaCore::Application::runDir() << std::endl; | ||
std::cout << PlumaCore::Application::name() << std::endl; | ||
|
||
PlumaCore::Application::regArgsCalled("-interface",interfaceProc); | ||
PlumaCore::Application::regArgsCalled("-pluginPath",pluginPathProc); | ||
PlumaCore::Application::regArgsCalled("-core",coreProc); | ||
PlumaCore::Application::regArgsCalled("-devices",deviceProc); | ||
PlumaCore::Application::regArgsCalled("-runModel",runmodelProc); | ||
PlumaCore::Application::argsCall(); | ||
|
||
PDebug() << std::hex << std::uppercase << 255 << 10 << 16; | ||
PDebug() << PlumaCore::Application::argumentMapping(); | ||
PDebug() << PlumaCore::Application::arguments(); | ||
PDebug() << std::hex << std::list<int>{255,10,16}; | ||
PDebug() << std::list<std::string>{"hhh","ggg","jjj"}; | ||
PDebug() << std::vector<int>{2,3,4}; | ||
|
||
auto foo = [=](){std::cout << FUNCTION_INFO << std::endl;}; | ||
|
||
test2 t2; | ||
|
||
class varient: std::array<unsigned char,8> | ||
{ | ||
|
||
}; | ||
|
||
std::array<unsigned char,sizeof(test2*)> CBaseAddress = PlumaCore::_ConvtAnyBAToFormat(&t2); | ||
PlumaCore::_ConvtAnyFormatToBA<test2*>(CBaseAddress)->handler(10); | ||
|
||
std::array<unsigned char, sizeof(void (test2::*)(int))> handlerBA = PlumaCore::_ConvtAnyBAToFormat<void (test2::*)(int)>(&test2::handler); //类型需要指定否则函数重载将不会被识别 | ||
(t2.*PlumaCore::_ConvtAnyFormatToBA<void (test2::*)(int)>(handlerBA))(20); | ||
PlumaCore::Functor<test2,void,int>(&t2,&test2::handler).call(1000); | ||
|
||
|
||
std::array<unsigned char,sizeof(void (test2::*)())> handlerBA1 = PlumaCore::_ConvtAnyBAToFormat<void (test2::*)()>(&test2::handler); //空参数 | ||
(t2.*PlumaCore::_ConvtAnyFormatToBA<void (test2::*)()>(handlerBA1))(); | ||
PlumaCore::Functor<test2,void>(&t2,&test2::handler).call(); | ||
|
||
|
||
std::array<unsigned char,sizeof(int (test2::*)(int))> rihandler = PlumaCore::_ConvtAnyBAToFormat<int (test2::*)(int)>(&test2::rihandler); | ||
PDebug() << (t2.*PlumaCore::_ConvtAnyFormatToBA<int (test2::*)(int)>(rihandler))(30) ; | ||
PDebug() << PlumaCore::Functor<test2,int,int>(&t2,&test2::rihandler).call(100); | ||
|
||
|
||
std::array<unsigned char,sizeof(void (*)(int))> shandlerBA = PlumaCore::_ConvtAnyBAToFormat(&test2::shandler); //静态函数 | ||
(*PlumaCore::_ConvtAnyFormatToBA<decltype(&test2::shandler)>(shandlerBA))(40); | ||
(PlumaCore::_ConvtAnyFormatToBA<test2*>(CBaseAddress)->*PlumaCore::_ConvtAnyFormatToBA<void (test2::*)()>(handlerBA1))(); //索引调用 | ||
|
||
PDebug() << PlumaCore::_SysClassPSize << "|" << PlumaCore::_SysClassFSize; | ||
PDebug() << sizeof(&test2::rihandler); | ||
|
||
PlumaPipe<> pipe; | ||
pipe.connect(&t2,&test2::handler); | ||
pipe.connect(&t2,&test2::handler); | ||
pipe.connect(&t2,&test2::handler); | ||
|
||
pipe.connect(&t2,&test2::handlerTh1Join,PlumaPipe<>::Ct_ThJoined); | ||
pipe.connect(&t2,&test2::handlerTh2Join,PlumaPipe<>::Ct_ThJoined); | ||
|
||
// pipe.connect(&t2,&test2::handlerTh1Dirc,PlumaPipe<>::Ct_ThDirect); | ||
// pipe.connect(&t2,&test2::handlerTh2Dirc,PlumaPipe<>::Ct_ThDirect); | ||
|
||
pipe.send(); | ||
|
||
pipe.disconnect(&t2,&test2::handler); | ||
|
||
pipe.send(); | ||
|
||
PlumaPipe<int> pipe1; | ||
pipe1.connect(&t2,&test2::handler); | ||
pipe1.connect(&t2,&test2::handler); | ||
pipe1.connect(&t2,&test2::handler); | ||
pipe1.send(30); | ||
|
||
//注册交互回调 | ||
PlumaCore::Application::regChannelCalled("readChannel",readChannel); | ||
PlumaCore::Application::regChannelCalled("writeChannel",writeChannel); | ||
PlumaCore::Application::regChannelCalled("help",helpChannel); | ||
|
||
PDebug() << "Any channel keypress from :\n" << PlumaCore::Application::channels(); | ||
|
||
while(1) | ||
{ | ||
std::string str; | ||
PDebug() << ">"; | ||
std::cin >> str; | ||
a.channelCall(str); | ||
} | ||
return 0; | ||
} |
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,34 @@ | ||
#ifndef WARRIOR_HPP | ||
#define WARRIOR_HPP | ||
|
||
#include <Pluma/Pluma.hpp> | ||
|
||
///////////////////////////////////////////////////////// | ||
/// Warrior Interface | ||
/// That's the kind of objects that plugins will provide. | ||
///////////////////////////////////////////////////////// | ||
class Warrior{ | ||
public: | ||
virtual std::string getDescription() = 0; | ||
// (...) | ||
}; | ||
|
||
|
||
///////////////////////////////////////////////////////// | ||
/// WarriorProvider Interface | ||
/// Plugins will provide host with new Warriors throgh WarriorProvider | ||
/// implementations. Host automatically check version compatibility. | ||
///////////////////////////////////////////////////////// | ||
// PLUMA_GEN_PROVIDER(Type, current_version, lowest_compatible_version) | ||
PLUMA_PROVIDER_HEADER(Warrior); | ||
PLUMA_PROVIDER_SOURCE(Warrior, 1, 1); | ||
|
||
// - Advanced example of provider header generation | ||
//PLUMA_PROVIDER_HEADER_BEGIN(Warrior) | ||
// public: | ||
// virtual Warrior* create(int energy) = 0; | ||
// virtual void populate(std::vector<Warrior*>& army, int numSoldiers) = 0; | ||
//PLUMA_PROVIDER_HEADER_END | ||
|
||
|
||
#endif // WARRIOR_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,34 @@ | ||
#include <Pluma/Pluma.hpp> | ||
#include "Warrior.hpp" | ||
#include <iostream> | ||
|
||
int main(int argc,char* argv[]) | ||
{ | ||
pluma::Pluma pluma; | ||
pluma.acceptProviderType<WarriorProvider>(); | ||
|
||
// // Add a default warrior provider | ||
// pluma.addProvider(new SimpleWarriorProvider() ); | ||
|
||
// Load libraries | ||
std::cout<<"load plugin number:"<< pluma.loadFromFolder("./") << std::endl; | ||
|
||
// Get warrior providers into a vector | ||
std::vector<WarriorProvider*> providers; | ||
pluma.getProviders(providers); | ||
|
||
// Create a Warrior from each provider | ||
std::vector<WarriorProvider*>::iterator it; | ||
for (it = providers.begin() ; it != providers.end() ; ++it){ | ||
// Create a warrior | ||
Warrior* warrior = (*it)->create(); | ||
// Display it's description | ||
std::cout << warrior->getDescription() << std::endl; | ||
// (...) | ||
// don't forget to delete it | ||
delete warrior; | ||
} | ||
pluma.unloadAll(); | ||
|
||
return 0; | ||
} |
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,6 @@ | ||
#include "Eagle.hpp" | ||
|
||
std::string Eagle::getDescription() | ||
{ | ||
return "Eagle Warrior: soldier of the sun"; | ||
} |
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,23 @@ | ||
#ifndef EAGLE_HPP | ||
#define EAGLE_HPP | ||
|
||
#include "Warrior.hpp" | ||
#include <Pluma/Connector.hpp> | ||
|
||
///////////////////////////////////////////////////////// | ||
/// An Eagle is a Warrior | ||
///////////////////////////////////////////////////////// | ||
class Eagle: public Warrior{ | ||
public: | ||
std::string getDescription(); | ||
}; | ||
|
||
///////////////////////////////////////////////////////// | ||
/// An EagleProvider is a WarriorProvider, | ||
/// provide warriors of type Eagle | ||
///////////////////////////////////////////////////////// | ||
PLUMA_INHERIT_PROVIDER(Eagle, Warrior); | ||
|
||
PLUMA_CONNECTOR bool connect(pluma::Host& host){ host.add( new EagleProvider() ); return true;} | ||
|
||
#endif // EAGLE_HPP |
Oops, something went wrong.