diff --git a/0001-fix-issues.patch b/0001-fix-issues.patch deleted file mode 100644 index ee6b360..0000000 --- a/0001-fix-issues.patch +++ /dev/null @@ -1,1204 +0,0 @@ -From 75c6db6769e7b08c1f842d6984fd3bfb341ab1ad Mon Sep 17 00:00:00 2001 -From: fly_1997 -Date: Wed, 15 May 2024 17:01:35 +0800 -Subject: [PATCH] fix issues - ---- - src/client/CMakeLists.txt | 2 +- - src/client/arg_parse.cpp | 23 ++++---- - src/client/arg_parse.h | 22 ++++---- - src/client/client.cpp | 31 +++++------ - src/client/client.h | 10 ++-- - src/client/cmd_handler.cpp | 41 +++++++------- - src/client/cmd_handler.h | 27 +++++----- - src/client/main.cpp | 1 - - src/client/tcp_socket.cpp | 10 +--- - src/client/tcp_socket.h | 6 ++- - src/common/CMakeLists.txt | 2 +- - src/common/message_protocol.cpp | 34 ++++++------ - src/common/message_protocol.h | 71 +++++++++++++------------ - src/plugin_mgr/CMakeLists.txt | 2 +- - src/plugin_mgr/config.cpp | 16 +++--- - src/plugin_mgr/config.h | 4 +- - src/plugin_mgr/dep_handler.h | 4 +- - src/plugin_mgr/error_code.cpp | 11 ++++ - src/plugin_mgr/error_code.h | 11 ++++ - src/plugin_mgr/instance_run_handler.cpp | 48 ++++++++++++----- - src/plugin_mgr/main.cpp | 2 +- - src/plugin_mgr/message_manager.cpp | 9 ++-- - src/plugin_mgr/message_manager.h | 5 +- - src/plugin_mgr/plugin.h | 4 +- - src/plugin_mgr/plugin_manager.cpp | 37 +++++++------ - 25 files changed, 243 insertions(+), 190 deletions(-) - -diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt -index d584d7d..11f9a5b 100644 ---- a/src/client/CMakeLists.txt -+++ b/src/client/CMakeLists.txt -@@ -1,7 +1,7 @@ - cmake_minimum_required (VERSION 3.22) - project(oeAware-client) - --SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++11 -g -Wl,-z,relro,-z,now") -+SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++11 -g -Wl,-z,relro,-z,now -O2 -Wall -Wextra") - - aux_source_directory(. SOURCE) - include_directories(../common) -diff --git a/src/client/arg_parse.cpp b/src/client/arg_parse.cpp -index 805f5a7..947c4c4 100644 ---- a/src/client/arg_parse.cpp -+++ b/src/client/arg_parse.cpp -@@ -13,7 +13,7 @@ - #include - #include - --const std::string ArgParse::OPT_STRING = "Qqd:t:l:r:e:"; -+const std::string ArgParse::OPT_STRING = "Qqd:t:l:r:e:i:"; - const struct option ArgParse::long_options[] = { - {"help", no_argument, NULL, 'h'}, - {"load", required_argument, NULL, 'l'}, -@@ -58,7 +58,7 @@ void ArgParse::print_help() { - " -Q query all instances dependencies.\n" - " --query-dep [instance] query the instance dependency.\n" - " --list the list of supported plugins.\n" -- " --install [plugin] install plugin from the list.\n" -+ " -i|--install [plugin] install plugin from the list.\n" - " --help show this help message.\n"; - } - -@@ -69,7 +69,6 @@ void ArgParse::init_opts() { - opts.insert('Q'); - opts.insert('e'); - opts.insert('d'); -- opts.insert('L'); - opts.insert('i'); - opts.insert('t'); - } -@@ -90,13 +89,18 @@ int ArgParse::init(int argc, char *argv[]) { - help = true; - break; - case '?': { -- std::string err; -- err += optopt; -+ std::string opt_string; -+ if (optind == argc) { -+ opt_string += argv[optind - 1]; -+ } else { -+ opt_string += argv[optind]; -+ } - if (!opts.count(optopt)) { -- arg_error("unknown option '-" + err + "'."); -+ arg_error("unknown option '" + opt_string + "'."); - } else{ -- arg_error("option -" + err + " requires an argument."); -+ arg_error("option " + opt_string + " requires an argument."); - } -+ break; - } - default: { - if (opt == 'l' || opt == 'r' || opt == 'q' || opt == 'Q' || opt == 'e' || opt == 'd' || opt == 'L' || opt == 'i') { -@@ -109,19 +113,20 @@ int ArgParse::init(int argc, char *argv[]) { - set_arg(optarg); - } - } -+ break; - } - - } - } - if (cmd == 'l' && type.empty()) { -- arg_error("option '-t' is required."); -+ arg_error("missing arguments."); - } - if (help) { - print_help(); - exit(EXIT_SUCCESS); - } - if (cmd < 0) { -- arg_error("no option."); -+ arg_error("option error."); - } - return cmd; - } -diff --git a/src/client/arg_parse.h b/src/client/arg_parse.h -index 682f0e5..6a0a25b 100644 ---- a/src/client/arg_parse.h -+++ b/src/client/arg_parse.h -@@ -18,20 +18,20 @@ class ArgParse { - public: - static void arg_error(const std::string &msg); - static void print_help(); -- int init(int argc, char *argv[]); -- void init_opts(); -- void set_type(char* _type); -- void set_arg(char* _arg); -- std::string get_type() const { -- return this->type; -+ static int init(int argc, char *argv[]); -+ static void init_opts(); -+ static void set_type(char* _type); -+ static void set_arg(char* _arg); -+ static std::string get_type() { -+ return type; - } -- std::string get_arg() const { -- return this->arg; -+ static std::string get_arg() { -+ return arg; - } - private: -- std::string arg; -- std::string type; -- std::unordered_set opts; -+ static std::string arg; -+ static std::string type; -+ static std::unordered_set opts; - static const std::string OPT_STRING; - static const int MAX_OPT_SIZE = 20; - static const struct option long_options[MAX_OPT_SIZE]; -diff --git a/src/client/client.cpp b/src/client/client.cpp -index 39a0072..afaa189 100644 ---- a/src/client/client.cpp -+++ b/src/client/client.cpp -@@ -11,18 +11,23 @@ - ******************************************************************************/ - #include "client.h" - -+std::string ArgParse::arg; -+std::string ArgParse::type; -+std::unordered_set ArgParse::opts; -+ - void Client::cmd_groups_init() { -- cmd_handler_groups.insert(std::make_pair('l', new LoadHandler())); -- cmd_handler_groups.insert(std::make_pair('q', new QueryHandler())); -- cmd_handler_groups.insert(std::make_pair('r', new RemoveHandler())); -- cmd_handler_groups.insert(std::make_pair('Q', new QueryTopHandler())); -- cmd_handler_groups.insert(std::make_pair('e', new EnabledHandler())); -- cmd_handler_groups.insert(std::make_pair('d', new DisabledHandler())); -- cmd_handler_groups.insert(std::make_pair('L', new ListHandler())); -- cmd_handler_groups.insert(std::make_pair('i', new InstallHandler(arg_parse.get_arg()))); -+ cmd_handler_groups.insert(std::make_pair('l', std::make_shared())); -+ cmd_handler_groups.insert(std::make_pair('q', std::make_shared())); -+ cmd_handler_groups.insert(std::make_pair('r', std::make_shared())); -+ cmd_handler_groups.insert(std::make_pair('Q', std::make_shared())); -+ cmd_handler_groups.insert(std::make_pair('e', std::make_shared())); -+ cmd_handler_groups.insert(std::make_pair('d', std::make_shared())); -+ cmd_handler_groups.insert(std::make_pair('L', std::make_shared())); -+ cmd_handler_groups.insert(std::make_pair('i', std::make_shared())); - } -+ - bool Client::init(int argc, char *argv[]) { -- if ((cmd = arg_parse.init(argc, argv)) < 0) { -+ if ((cmd = ArgParse::init(argc, argv)) < 0) { - return false; - } - cmd_groups_init(); -@@ -34,8 +39,8 @@ void Client::run_cmd() { - Msg res; - MessageHeader header; - this->cmd_handler = cmd_handler_groups[cmd]; -- this->cmd_handler->handler(arg_parse, msg); -- if(!this->tcp_socket.send_msg(msg)) { -+ this->cmd_handler->handler(msg); -+ if(!this->tcp_socket.send_msg(msg, header)) { - return; - } - if (!this->tcp_socket.recv_msg(res, header)) { -@@ -43,7 +48,3 @@ void Client::run_cmd() { - } - this->cmd_handler->res_handler(res); - } -- --void Client::close() { -- tcp_socket.clear(); --} -diff --git a/src/client/client.h b/src/client/client.h -index 9e60251..82cf613 100644 ---- a/src/client/client.h -+++ b/src/client/client.h -@@ -14,14 +14,11 @@ - #include "tcp_socket.h" - #include "cmd_handler.h" - #include -+#include - - class Client { - public: - Client() : cmd_handler(nullptr) { } -- ~Client() { -- if (cmd_handler) -- delete cmd_handler; -- } - bool init(int argc, char *argv[]); - void run_cmd(); - void close(); -@@ -30,9 +27,8 @@ private: - - int cmd; - TcpSocket tcp_socket; -- ArgParse arg_parse; -- CmdHandler *cmd_handler; -- std::unordered_map cmd_handler_groups; -+ std::shared_ptr cmd_handler; -+ std::unordered_map> cmd_handler_groups; - }; - - #endif // !CLIENT_H -diff --git a/src/client/cmd_handler.cpp b/src/client/cmd_handler.cpp -index b410968..6f3f760 100644 ---- a/src/client/cmd_handler.cpp -+++ b/src/client/cmd_handler.cpp -@@ -15,16 +15,16 @@ - - std::unordered_set LoadHandler::types = {"collector", "scenario", "tune"}; - --void LoadHandler::check(const std::string &arg, const std::string &type) { -+void LoadHandler::check(const std::string &type) { - if (!types.count(type)) { - ArgParse::arg_error("type '" + type + "' is not supported."); - } - } - --void LoadHandler::handler(const ArgParse &arg_parse, Msg &msg) { -- std::string arg = arg_parse.get_arg(); -- std::string type = arg_parse.get_type(); -- check(arg, type); -+void LoadHandler::handler(Msg &msg) { -+ std::string arg = ArgParse::get_arg(); -+ std::string type = ArgParse::get_type(); -+ check(type); - msg.add_payload(arg); - msg.add_payload(type); - msg.set_opt(Opt::LOAD); -@@ -47,8 +47,8 @@ void LoadHandler::res_handler(Msg &msg) { - - } - --void QueryHandler::handler(const ArgParse &arg_parse, Msg &msg) { -- std::string arg = arg_parse.get_arg(); -+void QueryHandler::handler(Msg &msg) { -+ std::string arg = ArgParse::get_arg(); - if (arg.empty()) { - msg.set_opt(Opt::QUERY_ALL); - } else { -@@ -80,8 +80,8 @@ void QueryHandler::res_handler(Msg &msg) { - print_format(); - } - --void RemoveHandler::handler(const ArgParse &arg_parse, Msg &msg) { -- std::string arg = arg_parse.get_arg(); -+void RemoveHandler::handler(Msg &msg) { -+ std::string arg = ArgParse::get_arg(); - msg.add_payload(arg); - msg.set_opt(Opt::REMOVE); - } -@@ -106,8 +106,8 @@ void write_to_file(const std::string &file_name, const std::string &text) { - out.close(); - } - --void QueryTopHandler::handler(const ArgParse &arg_parse, Msg &msg) { -- std::string arg = arg_parse.get_arg(); -+void QueryTopHandler::handler(Msg &msg) { -+ std::string arg = ArgParse::get_arg(); - if (arg.empty()) { - msg.set_opt(Opt::QUERY_ALL_TOP); - } else { -@@ -127,8 +127,8 @@ void QueryTopHandler::res_handler(Msg &msg) { - std::cout << "Generate dependencies graph dep.png.\n"; - } - --void EnabledHandler::handler(const ArgParse &arg_parse, Msg &msg) { -- std::string arg = arg_parse.get_arg(); -+void EnabledHandler::handler(Msg &msg) { -+ std::string arg = ArgParse::get_arg(); - msg.add_payload(arg); - msg.set_opt(Opt::ENABLED); - } -@@ -141,8 +141,8 @@ void EnabledHandler::res_handler(Msg &msg) { - } - } - --void DisabledHandler::handler(const ArgParse &arg_parse, Msg &msg) { -- std::string arg = arg_parse.get_arg(); -+void DisabledHandler::handler(Msg &msg) { -+ std::string arg = ArgParse::get_arg(); - msg.add_payload(arg); - msg.set_opt(Opt::DISABLED); - } -@@ -155,7 +155,7 @@ void DisabledHandler::res_handler(Msg &msg) { - } - } - --void ListHandler::handler(const ArgParse &arg_parse, Msg &msg) { -+void ListHandler::handler(Msg &msg) { - msg.set_opt(Opt::LIST); - } - -@@ -172,18 +172,19 @@ void ListHandler::res_handler(Msg &msg) { - std::cout << "------------------------------------------------------------\n"; - } - --void InstallHandler::handler(const ArgParse &arg_parse, Msg &msg) { -- std::string arg = arg_parse.get_arg(); -+void InstallHandler::handler(Msg &msg) { -+ std::string arg = ArgParse::get_arg(); - msg.set_opt(Opt::DOWNLOAD); - msg.add_payload(arg); - } - - void InstallHandler::res_handler(Msg &msg) { -+ std::string arg = ArgParse::get_arg(); - if (msg.get_opt() == Opt::RESPONSE_ERROR) { -- std::cout << "Download failed, because " << msg.payload(0) <<": " << this->arg.c_str() << '\n'; -+ std::cout << "Download failed, because " << msg.payload(0) <<": " << arg.c_str() << '\n'; - return; - } -- std::string path = this->arg; -+ std::string path = arg; - std::string url = msg.payload(0); - if (!download(url, path)) { - std::cout << "Download failed, please check url or your network.\n"; -diff --git a/src/client/cmd_handler.h b/src/client/cmd_handler.h -index 1b6f1c1..2e32098 100644 ---- a/src/client/cmd_handler.h -+++ b/src/client/cmd_handler.h -@@ -19,23 +19,25 @@ - - class CmdHandler { - public: -- virtual void handler(const ArgParse &arg_parse, Msg &msg) = 0; -+ virtual void handler(Msg &msg) = 0; - virtual void res_handler(Msg &msg) = 0; --private: -+ -+ static ArgParse &arg_parse; - }; - - class LoadHandler : public CmdHandler { - public: -- void handler(const ArgParse &arg_parse, Msg &msg) override; -+ // LoadHandler(const ArgParse &arg_parse) { } -+ void handler(Msg &msg) override; - void res_handler(Msg &msg) override; - private: -- void check(const std::string &arg, const std::string &type); -+ void check(const std::string &type); - static std::unordered_set types; - }; - - class QueryHandler : public CmdHandler { - public: -- void handler(const ArgParse &arg_parse, Msg &msg) override; -+ void handler(Msg &msg) override; - void res_handler(Msg &msg) override; - private: - void print_format(); -@@ -43,42 +45,39 @@ private: - - class RemoveHandler : public CmdHandler { - public: -- void handler(const ArgParse &arg_parse, Msg &msg) override; -+ void handler(Msg &msg) override; - void res_handler(Msg &msg) override; - }; - - - class QueryTopHandler : public CmdHandler { - public: -- void handler(const ArgParse &arg_parse, Msg &msg) override; -+ void handler(Msg &msg) override; - void res_handler(Msg &msg) override; - }; - - class EnabledHandler : public CmdHandler { - public: -- void handler(const ArgParse &arg_parse, Msg &msg) override; -+ void handler(Msg &msg) override; - void res_handler(Msg &msg) override; - }; - - class DisabledHandler : public CmdHandler { - public: -- void handler(const ArgParse &arg_parse, Msg &msg) override; -+ void handler(Msg &msg) override; - void res_handler(Msg &msg) override; - }; - - class ListHandler : public CmdHandler { - public: -- void handler(const ArgParse &arg_parse, Msg &msg) override; -+ void handler(Msg &msg) override; - void res_handler(Msg &msg) override; - }; - - class InstallHandler : public CmdHandler { - public: -- InstallHandler(const std::string &arg) : arg(arg) { } -- void handler(const ArgParse &arg_parse, Msg &msg) override; -+ void handler(Msg &msg) override; - void res_handler(Msg &msg) override; --private: -- std::string arg; - }; - - #endif // !CLIENT_CMD_HANDLER_H -diff --git a/src/client/main.cpp b/src/client/main.cpp -index 62b7ca5..e47c523 100644 ---- a/src/client/main.cpp -+++ b/src/client/main.cpp -@@ -17,6 +17,5 @@ int main(int argc, char *argv[]) { - exit(EXIT_FAILURE); - } - client.run_cmd(); -- client.close(); - return 0; - } -diff --git a/src/client/tcp_socket.cpp b/src/client/tcp_socket.cpp -index d0721cc..7781183 100644 ---- a/src/client/tcp_socket.cpp -+++ b/src/client/tcp_socket.cpp -@@ -15,7 +15,7 @@ - - bool TcpSocket::recv_msg(Msg &res, MessageHeader &header) { - MessageProtocol proto; -- if (handle_request(stream, proto) < 0) { -+ if (!handle_request(stream, proto)) { - printf("can't connect to server!\n"); - return false; - } -@@ -24,8 +24,7 @@ bool TcpSocket::recv_msg(Msg &res, MessageHeader &header) { - return true; - } - --bool TcpSocket::send_msg(Msg &msg) { -- MessageHeader header; -+bool TcpSocket::send_msg(Msg &msg, MessageHeader &header) { - if (!send_response(stream, msg, header)) { - return false; - } -@@ -52,13 +51,8 @@ bool TcpSocket::init() { - return -1; - } - if (file_connect(SOCK_PATH.c_str()) < 0) { -- close(sock); - return false; - } - stream.set_sock(sock); - return true; - } -- --void TcpSocket::clear() { -- close(sock); --} -\ No newline at end of file -diff --git a/src/client/tcp_socket.h b/src/client/tcp_socket.h -index fa0073b..1a3dfef 100644 ---- a/src/client/tcp_socket.h -+++ b/src/client/tcp_socket.h -@@ -16,11 +16,13 @@ - class TcpSocket { - public: - TcpSocket() { } -+ ~TcpSocket() { -+ close(sock); -+ } - bool recv_msg(Msg &res, MessageHeader &header); -- bool send_msg(Msg &msg); -+ bool send_msg(Msg &msg, MessageHeader &header); - int file_connect(const char *name); - bool init(); -- void clear(); - private: - int sock; - SocketStream stream; -diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt -index dece483..ac7525b 100644 ---- a/src/common/CMakeLists.txt -+++ b/src/common/CMakeLists.txt -@@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.22) - project(common) - - aux_source_directory(. SOURCE) --SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++11 -g -Wl,-z,relro,-z,now") -+SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++11 -g -Wl,-z,relro,-z,now -Wall -Wextra -fPIC -O2") - - - include_directories(/usr/include/yaml-cpp) -diff --git a/src/common/message_protocol.cpp b/src/common/message_protocol.cpp -index 05d437c..a813a6c 100644 ---- a/src/common/message_protocol.cpp -+++ b/src/common/message_protocol.cpp -@@ -13,7 +13,7 @@ - #include - - template --inline ssize_t handle_EINTR(T fn) { -+inline ssize_t handle_error(T fn) { - ssize_t res = 0; - while (true) { - res = fn(); -@@ -25,27 +25,27 @@ inline ssize_t handle_EINTR(T fn) { - return res; - } - --inline ssize_t read_socket(int sock, void *ptr, size_t size, int flags) { -- return handle_EINTR([&]() { -- return recv(sock, ptr, size, flags); -+inline ssize_t read_socket(int sock, void *buf, size_t size, int flags) { -+ return handle_error([&]() { -+ return recv(sock, buf, size, flags); - }); - } - --inline ssize_t send_socket(int sock, const void *ptr, size_t size, int flags) { -- return handle_EINTR([&]() { -- return send(sock, ptr, size, flags); -+inline ssize_t send_socket(int sock, const void *buf, size_t size, int flags) { -+ return handle_error([&]() { -+ return send(sock, buf, size, flags); - }); - } - --ssize_t SocketStream::read(char *ptr, size_t size) { -+ssize_t SocketStream::read(char *buf, size_t size) { - if (read_buff_off < read_buff_content_size) { - auto remaining_size = read_buff_content_size - read_buff_off; - if (size <= remaining_size) { -- memcpy(ptr, read_buff.data() + read_buff_off, size); -+ memcpy(buf, read_buff.data() + read_buff_off, size); - read_buff_off += size; - return size; - } else { -- memcpy(ptr, read_buff.data() + read_buff_off, remaining_size); -+ memcpy(buf, read_buff.data() + read_buff_off, remaining_size); - read_buff_off += remaining_size; - return remaining_size; - } -@@ -56,22 +56,22 @@ ssize_t SocketStream::read(char *ptr, size_t size) { - auto n = read_socket(sock, read_buff.data(), MAX_BUFF_SIZE, 0); - if (n <= 0) { - return n; -- } else if (n < size) { -- memcpy(ptr, read_buff.data(), n); -+ } else if (static_cast(n) < size) { -+ memcpy(buf, read_buff.data(), n); - return n; - } else { -- memcpy(ptr, read_buff.data(), size); -+ memcpy(buf, read_buff.data(), size); - read_buff_off = size; - read_buff_content_size = n; - return size; - } - } else { -- return read_socket(sock, ptr, size, 0); -+ return read_socket(sock, buf, size, 0); - } - } - --ssize_t SocketStream::write(const char *ptr, size_t size) { -- return send_socket(sock, ptr, size, 0); -+ssize_t SocketStream::write(const char *buf, size_t size) { -+ return send_socket(sock, buf, size, 0); - } - - static std::string to_hex(size_t x) { -@@ -80,7 +80,7 @@ static std::string to_hex(size_t x) { - ss << std::hex << std::uppercase << x; - result = ss.str(); - std::string zero = ""; -- for (int i = result.length(); i < sizeof(size_t); ++i) { -+ for (size_t i = result.length(); i < sizeof(size_t); ++i) { - zero += "0"; - } - result = zero + result; -diff --git a/src/common/message_protocol.h b/src/common/message_protocol.h -index 3771298..b2c3c0d 100644 ---- a/src/common/message_protocol.h -+++ b/src/common/message_protocol.h -@@ -44,38 +44,39 @@ enum class Opt { - }; - - class Msg { -- private: -- friend class boost::serialization::access; -- template -- void serialize(Archive &ar, const unsigned int version) { -- ar & _opt; -- ar & _payload; -- } -- public: -- int payload_size() const { -- return this->_payload.size(); -- } -- std::string payload(int id) const { -- return this->_payload[id]; -- } -- Opt opt() { -- return this->_opt; -- } -- void add_payload(std::string &context) { -- this->_payload.emplace_back(context); -- } -- void add_payload(std::string &&context) { -- this->_payload.emplace_back(context); -- } -- void set_opt(Opt opt) { -- this->_opt = opt; -- } -- Opt get_opt() const { -- return this->_opt; -- } -- private: -- Opt _opt; -- std::vector _payload; -+private: -+ friend class boost::serialization::access; -+ template -+ void serialize(Archive &ar, const unsigned int version) { -+ ar & _opt; -+ ar & _payload; -+ } -+public: -+ Msg() { } -+ int payload_size() const { -+ return this->_payload.size(); -+ } -+ std::string payload(int id) const { -+ return this->_payload[id]; -+ } -+ Opt opt() { -+ return this->_opt; -+ } -+ void add_payload(std::string &context) { -+ this->_payload.emplace_back(context); -+ } -+ void add_payload(std::string &&context) { -+ this->_payload.emplace_back(context); -+ } -+ void set_opt(Opt opt) { -+ this->_opt = opt; -+ } -+ Opt get_opt() const { -+ return this->_opt; -+ } -+private: -+ Opt _opt; -+ std::vector _payload; - }; - - class MessageHeader { -@@ -86,6 +87,7 @@ private: - ar & code; - } - public: -+ MessageHeader() { } - void set_state_code(int code) { - this->code = code; - } -@@ -109,8 +111,8 @@ class SocketStream { - public: - SocketStream() : read_buff(MAX_BUFF_SIZE, 0) { } - SocketStream(int sock) : sock(sock), read_buff(MAX_BUFF_SIZE, 0) { } -- ssize_t read(char *ptr, size_t size); -- ssize_t write(const char *ptr, size_t size); -+ ssize_t read(char *buf, size_t size); -+ ssize_t write(const char *buf, size_t size); - void set_sock(int sock) { - this->sock = sock; - } -@@ -135,7 +137,6 @@ std::string encode(const T &msg) { - - template - int decode(T &msg, const std::string &content) { -- int len = 0; - try { - std::stringstream ss(content); - boost::archive::binary_iarchive ia(ss); -diff --git a/src/plugin_mgr/CMakeLists.txt b/src/plugin_mgr/CMakeLists.txt -index a32c800..8642a63 100644 ---- a/src/plugin_mgr/CMakeLists.txt -+++ b/src/plugin_mgr/CMakeLists.txt -@@ -1,7 +1,7 @@ - cmake_minimum_required (VERSION 3.22) - project(oeAware-server) - --SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++11 -g -Wl,-z,relro,-z,now") -+SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++11 -g -Wl,-z,relro,-z,now -Wall -Wextra -O2") - - if("${OEAWARE_DEBUG}" EQUAL 1) - add_definitions(-DOEAWARE_DEBUG) -diff --git a/src/plugin_mgr/config.cpp b/src/plugin_mgr/config.cpp -index f50399b..588eda0 100644 ---- a/src/plugin_mgr/config.cpp -+++ b/src/plugin_mgr/config.cpp -@@ -32,11 +32,11 @@ bool create_dir(const std::string &path) { - - bool check_plugin_list(YAML::Node plugin_list_item) { - if (plugin_list_item["name"].IsNull()) { -- std::cerr << "Warn: null name in plugin_list.\n"; -+ std::cerr << "WARN: null name in plugin_list.\n"; - return false; - } - if (plugin_list_item["url"].IsNull()) { -- std::cerr << "Warn: null url in plugin_list.\n"; -+ std::cerr << "WARN: null url in plugin_list.\n"; - return false; - } - return true; -@@ -60,7 +60,7 @@ bool Config::load(const std::string path) { - if (!node["plugin_list"].IsNull()) { - YAML::Node plugin_list = node["plugin_list"]; - if (plugin_list.IsSequence()) { -- for (int i = 0; i < plugin_list.size(); ++i) { -+ for (size_t i = 0; i < plugin_list.size(); ++i) { - if (!check_plugin_list(plugin_list[i])){ - continue; - } -@@ -81,15 +81,14 @@ bool Config::load(const std::string path) { - if (!node["enable_list"].IsNull()) { - YAML::Node enable_list = node["enable_list"]; - if (enable_list.IsSequence()) { -- for (int i = 0; i < enable_list.size(); ++i) { -- YAML::Node plugin = enable_list[i]["name"]; -+ for (size_t i = 0; i < enable_list.size(); ++i) { - std::string name = enable_list[i]["name"].as(); - YAML::Node instances = enable_list[i]["instances"]; - EnableItem enable_item(name); -- if (instances.IsNull()) { -+ if (!instances.IsDefined() || instances.IsNull()) { - enable_item.set_enabled(true); - } else { -- for (int j = 0; j < instances.size(); ++j) { -+ for (size_t j = 0; j < instances.size(); ++j) { - std::string i_name = instances[j].as(); - enable_item.add_instance(i_name); - } -@@ -118,6 +117,9 @@ std::string get_path(PluginType type) { - case PluginType::TUNE: { - return DEFAULT_TUNE_PATH; - } -+ default: { -+ break; -+ } - } - return ""; - } -\ No newline at end of file -diff --git a/src/plugin_mgr/config.h b/src/plugin_mgr/config.h -index 6d0ee4d..c2d1f37 100644 ---- a/src/plugin_mgr/config.h -+++ b/src/plugin_mgr/config.h -@@ -72,9 +72,9 @@ public: - return this->name; - } - private: -- bool enabled; -- std::string name; - std::vector instance; -+ std::string name; -+ bool enabled; - }; - - class Config { -diff --git a/src/plugin_mgr/dep_handler.h b/src/plugin_mgr/dep_handler.h -index 76abf49..b81d574 100644 ---- a/src/plugin_mgr/dep_handler.h -+++ b/src/plugin_mgr/dep_handler.h -@@ -33,8 +33,8 @@ struct Node { - int cnt; - int real_cnt; - bool state; // dependency closed-loop -- Node() : next(nullptr), head(nullptr), state(true), cnt(0), real_cnt(0) {} -- Node(std::string name): name(name), next(nullptr), head(nullptr), state(true), cnt(0), real_cnt(0) {} -+ Node() : next(nullptr), head(nullptr), cnt(0), real_cnt(0), state(true) {} -+ Node(std::string name): next(nullptr), head(nullptr), name(name), cnt(0), real_cnt(0), state(true) {} - }; - - class DepHandler { -diff --git a/src/plugin_mgr/error_code.cpp b/src/plugin_mgr/error_code.cpp -index 30cc4f8..09f0eb9 100644 ---- a/src/plugin_mgr/error_code.cpp -+++ b/src/plugin_mgr/error_code.cpp -@@ -1,3 +1,14 @@ -+/****************************************************************************** -+ * Copyright (c) 2024 Huawei Technologies Co., Ltd. -+ * oeAware is licensed under Mulan PSL v2. -+ * You can use this software according to the terms and conditions of the Mulan PSL v2. -+ * You may obtain a copy of Mulan PSL v2 at: -+ * http://license.coscl.org.cn/MulanPSL2 -+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, -+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, -+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. -+ * See the Mulan PSL v2 for more details. -+ ******************************************************************************/ - #include "error_code.h" - - const std::unordered_map ErrorText::error_codes = { -diff --git a/src/plugin_mgr/error_code.h b/src/plugin_mgr/error_code.h -index 7c06054..dd028f3 100644 ---- a/src/plugin_mgr/error_code.h -+++ b/src/plugin_mgr/error_code.h -@@ -1,3 +1,14 @@ -+/****************************************************************************** -+ * Copyright (c) 2024 Huawei Technologies Co., Ltd. -+ * oeAware is licensed under Mulan PSL v2. -+ * You can use this software according to the terms and conditions of the Mulan PSL v2. -+ * You may obtain a copy of Mulan PSL v2 at: -+ * http://license.coscl.org.cn/MulanPSL2 -+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, -+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, -+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. -+ * See the Mulan PSL v2 for more details. -+ ******************************************************************************/ - #ifndef PLUGIN_MGR_ERROR_CODE_H - #define PLUGIN_MGR_ERROR_CODE_H - #include -diff --git a/src/plugin_mgr/instance_run_handler.cpp b/src/plugin_mgr/instance_run_handler.cpp -index 862e806..8ba10db 100644 ---- a/src/plugin_mgr/instance_run_handler.cpp -+++ b/src/plugin_mgr/instance_run_handler.cpp -@@ -18,12 +18,18 @@ static void* get_ring_buf(std::shared_ptr instance) { - return nullptr; - } - switch (instance->get_type()) { -- case PluginType::COLLECTOR: -+ case PluginType::COLLECTOR: { - return (std::dynamic_pointer_cast(instance))->get_interface()->get_ring_buf(); -- case PluginType::SCENARIO: -+ } -+ case PluginType::SCENARIO: { - return (std::dynamic_pointer_cast(instance))->get_interface()->get_ring_buf(); -- case PluginType::TUNE: -+ } -+ case PluginType::TUNE: { - break; -+ } -+ default: { -+ break; -+ } - } - return nullptr; - } -@@ -34,7 +40,7 @@ static void reflash_ring_buf(std::shared_ptr instance) { - - void InstanceRunHandler::run_aware(std::shared_ptr instance, std::vector &deps) { - void *a[MAX_DEPENDENCIES_SIZE]; -- for (int i = 0; i < deps.size(); ++i) { -+ for (size_t i = 0; i < deps.size(); ++i) { - std::shared_ptr ins = memory_store.get_instance(deps[i]); - a[i] = get_ring_buf(ins); - } -@@ -43,7 +49,7 @@ void InstanceRunHandler::run_aware(std::shared_ptr instance, std::vect - - void InstanceRunHandler::run_tune(std::shared_ptr instance, std::vector &deps) { - void *a[MAX_DEPENDENCIES_SIZE]; -- for (int i = 0; i < deps.size(); ++i) { -+ for (size_t i = 0; i < deps.size(); ++i) { - std::shared_ptr ins = memory_store.get_instance(deps[i]); - a[i] = get_ring_buf(ins); - } -@@ -52,36 +58,48 @@ void InstanceRunHandler::run_tune(std::shared_ptr instance, std::vecto - - void InstanceRunHandler::insert_instance(std::shared_ptr instance) { - switch (instance->get_type()) { -- case PluginType::COLLECTOR: -+ case PluginType::COLLECTOR: { - collector[instance->get_name()] = instance; - (std::dynamic_pointer_cast(instance))->get_interface()->enable(); - break; -- case PluginType::SCENARIO: -+ } -+ case PluginType::SCENARIO: { - scenario[instance->get_name()] = instance; - (std::dynamic_pointer_cast(instance))->get_interface()->enable(); - break; -- case PluginType::TUNE: -+ } -+ case PluginType::TUNE: { - tune[instance->get_name()] = instance; - (std::dynamic_pointer_cast(instance))->get_interface()->enable(); - break; -+ } -+ default: { -+ break; -+ } - } - INFO("[PluginManager] " << instance->get_name() << " instance insert into running queue."); - } - - void InstanceRunHandler::delete_instance(std::shared_ptr instance) { - switch (instance->get_type()) { -- case PluginType::COLLECTOR: -+ case PluginType::COLLECTOR: { - collector.erase(instance->get_name()); - (std::dynamic_pointer_cast(instance))->get_interface()->disable(); - break; -- case PluginType::SCENARIO: -+ } -+ case PluginType::SCENARIO: { - scenario.erase(instance->get_name()); - (std::dynamic_pointer_cast(instance))->get_interface()->disable(); - break; -- case PluginType::TUNE: -+ } -+ case PluginType::TUNE: { - tune.erase(instance->get_name()); - (std::dynamic_pointer_cast(instance))->get_interface()->disable(); - break; -+ } -+ default: { -+ break; -+ } - } - INFO("[PluginManager] " << instance->get_name() << " instance delete from running queue."); - } -@@ -91,12 +109,14 @@ void InstanceRunHandler::handle_instance() { - while(this->recv_queue_try_pop(msg)){ - std::shared_ptr instance = msg.get_instance(); - switch (msg.get_type()){ -- case RunType::ENABLED: -+ case RunType::ENABLED: { - insert_instance(std::move(instance)); - break; -- case RunType::DISABLED: -+ } -+ case RunType::DISABLED: { - delete_instance(std::move(instance)); - break; -+ } - } - } - } -@@ -107,7 +127,7 @@ static std::vector get_deps(std::shared_ptr instance) { - std::string deps = (t_instance)->get_interface()->get_dep(); - std::string dep = ""; - std::vector vec; -- for (int i = 0; i < deps.length(); ++i) { -+ for (size_t i = 0; i < deps.length(); ++i) { - if (deps[i] != '-') { - dep += deps[i]; - }else { -diff --git a/src/plugin_mgr/main.cpp b/src/plugin_mgr/main.cpp -index 92f48bb..4e6acdc 100644 ---- a/src/plugin_mgr/main.cpp -+++ b/src/plugin_mgr/main.cpp -@@ -48,7 +48,7 @@ int main(int argc, char **argv) { - SafeQueue res_msg; - INFO("[MessageManager] Start message manager!"); - MessageManager message_manager(&handler_msg, &res_msg); -- message_manager.init(&config); -+ message_manager.init(); - message_manager.run(); - INFO("[PluginManager] Start plugin manager!"); - PluginManager plugin_manager(config, handler_msg, res_msg); -diff --git a/src/plugin_mgr/message_manager.cpp b/src/plugin_mgr/message_manager.cpp -index f081f20..815122c 100644 ---- a/src/plugin_mgr/message_manager.cpp -+++ b/src/plugin_mgr/message_manager.cpp -@@ -44,7 +44,6 @@ bool TcpSocket::init() { - return false; - } - if (domain_listen(path.c_str()) < 0) { -- close(sock); - return false; - } - epfd = epoll_create(1); -@@ -52,6 +51,9 @@ bool TcpSocket::init() { - ev.events = EPOLLIN; - ev.data.fd = sock; - int ret = epoll_ctl(epfd, EPOLL_CTL_ADD, sock, &ev); -+ if (ret < 0) { -+ return false; -+ } - return true; - - } -@@ -64,7 +66,7 @@ static void send_msg(Msg &msg, SafeQueue *handler_msg) { - } - handler_msg->push(message); - } --static void recv_msg(Msg &msg, MessageHeader &header, SafeQueue *res_msg) { -+static void recv_msg(Msg &msg, SafeQueue *res_msg) { - Message res; - res_msg->wait_and_pop(res); - msg.set_opt(res.get_opt()); -@@ -76,7 +78,6 @@ static void recv_msg(Msg &msg, MessageHeader &header, SafeQueue *res_ms - void TcpSocket::serve_accept(SafeQueue *handler_msg, SafeQueue *res_msg){ - struct epoll_event evs[MAX_EVENT_SIZE]; - int sz = sizeof(evs) / sizeof(struct epoll_event); -- char buf[MAX_RECV_BUFF_SIZE]; - while (true) { - int num = epoll_wait(epfd, evs, sz, -1); - for (int i = 0; i < num; ++i) { -@@ -102,7 +103,7 @@ void TcpSocket::serve_accept(SafeQueue *handler_msg, SafeQueue - } - decode(client_msg, msg_protocol.body); - send_msg(client_msg, handler_msg); -- recv_msg(internal_msg, header, res_msg); -+ recv_msg(internal_msg, res_msg); - if (!send_response(stream, internal_msg, header)) { - WARN("[MessageManager] send msg to client failed!"); - } -diff --git a/src/plugin_mgr/message_manager.h b/src/plugin_mgr/message_manager.h -index 4cd7311..416be48 100644 ---- a/src/plugin_mgr/message_manager.h -+++ b/src/plugin_mgr/message_manager.h -@@ -62,6 +62,9 @@ private: - class TcpSocket { - public: - TcpSocket() {} -+ ~TcpSocket() { -+ close(sock); -+ } - bool init(); - void serve_accept(SafeQueue *handler_msg, SafeQueue *res_msg); - private: -@@ -77,7 +80,7 @@ public: - this->handler_msg = handler_msg; - this->res_msg = res_msg; - } -- void init(Config *config){ -+ void init(){ - this->tcp_socket = new TcpSocket(); - } - void run(); -diff --git a/src/plugin_mgr/plugin.h b/src/plugin_mgr/plugin.h -index a2a1815..d59ab8a 100644 ---- a/src/plugin_mgr/plugin.h -+++ b/src/plugin_mgr/plugin.h -@@ -148,10 +148,10 @@ public: - return handler; - } - private: -- void *handler; - std::vector> instances; -- PluginType type; - std::string name; -+ PluginType type; -+ void *handler; - }; - - #endif -diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp -index 77acc40..5324512 100644 ---- a/src/plugin_mgr/plugin_manager.cpp -+++ b/src/plugin_mgr/plugin_manager.cpp -@@ -34,7 +34,7 @@ ErrorCode PluginManager::remove(const std::string &name) { - } - std::shared_ptr plugin = memory_store.get_plugin(name); - std::vector instance_names; -- for (int i = 0; i < plugin->get_instance_len(); ++i) { -+ for (size_t i = 0; i < plugin->get_instance_len(); ++i) { - std::shared_ptr instance = plugin->get_instance(i); - std::string iname = instance->get_name(); - if (instance->get_enabled()) { -@@ -57,7 +57,7 @@ ErrorCode PluginManager::query_all_plugins(std::string &res) { - std::vector> all_plugins = memory_store.get_all_plugins(); - for (auto &p : all_plugins) { - res += p->get_name() + "\n"; -- for (int i = 0; i < p->get_instance_len(); ++i) { -+ for (size_t i = 0; i < p->get_instance_len(); ++i) { - std::string info = p->get_instance(i)->get_info(); - res += "\t" + info + "\n"; - } -@@ -71,7 +71,7 @@ ErrorCode PluginManager::query_plugin(const std::string &name, std::string &res) - } - std::shared_ptr plugin = memory_store.get_plugin(name); - res += name + "\n"; -- for (int i = 0; i < plugin->get_instance_len(); ++i) { -+ for (size_t i = 0; i < plugin->get_instance_len(); ++i) { - std::string info = plugin->get_instance(i)->get_info(); - res += "\t" + info + "\n"; - } -@@ -92,7 +92,6 @@ int PluginManager::load_dl_instance(std::shared_ptr plugin, T **interfac - - template - std::vector get_dep(T *interface) { -- int dep_len = 0; - char *deps = interface->get_dep(); - std::vector res; - std::string dep; -@@ -152,12 +151,16 @@ bool PluginManager::load_instance(std::shared_ptr plugin) { - save_instance(plugin, interface_list, len); - break; - } -- case PluginType::TUNE: -+ case PluginType::TUNE: { - TuneInterface *interface_list = nullptr; - len = load_dl_instance(plugin, &interface_list); - if (len == -1) return false; - save_instance(plugin, interface_list, len); - break; -+ } -+ default: { -+ return false; -+ } - } - update_instance_state(); - return true; -@@ -211,9 +214,13 @@ std::string generate_dot(MemoryStore &memory_store, const std::vectorget_plugin_name()].insert(vec[1]); -- res += vec[0] + "->" + vec[1] + ";"; -+ if (memory_store.is_instance_exist(vec[1])) { -+ instance = memory_store.get_instance(vec[1]); -+ sub_graph[instance->get_plugin_name()].insert(vec[1]); -+ } else { -+ res += vec[1] + "[label=\"(missing)\\n" + vec[1] + "\", fontcolor=red];\n"; -+ } -+ res += vec[0] + "->" + vec[1] + ";\n"; - } - int id = 0; - for (auto &p : sub_graph) { -@@ -339,7 +346,7 @@ ErrorCode PluginManager::download(const std::string &name, std::string &res) { - } - - void PluginManager::pre_enable() { -- for (int i = 0; i < config.get_enable_list_size(); ++i) { -+ for (size_t i = 0; i < config.get_enable_list_size(); ++i) { - EnableItem item = config.get_enable_list(i); - if (item.get_enabled()) { - std::string name = item.get_name(); -@@ -348,11 +355,11 @@ void PluginManager::pre_enable() { - continue; - } - std::shared_ptr plugin = memory_store.get_plugin(name); -- for (int j = 0; j < plugin->get_instance_len(); ++j) { -+ for (size_t j = 0; j < plugin->get_instance_len(); ++j) { - instance_enabled(plugin->get_instance(j)->get_name()); - } - } else { -- for (int j = 0; j < item.get_instance_size(); ++j) { -+ for (size_t j = 0; j < item.get_instance_size(); ++j) { - std::string name = item.get_instance_name(j); - if (!memory_store.is_instance_exist(name)) { - WARN("[PluginManager] instance " << name << " cannot be enabled, because it does not exist."); -@@ -410,7 +417,7 @@ void* PluginManager::get_data_buffer(std::string name) { - std::string PluginManager::instance_dep_check(const std::string &name) { - std::shared_ptr plugin = memory_store.get_plugin(name); - std::string res; -- for (int i = 0; i < plugin->get_instance_len(); ++i) { -+ for (size_t i = 0; i < plugin->get_instance_len(); ++i) { - std::string instance_name = plugin->get_instance(i)->get_name(); - std::vector> query; - dep_handler.query_node(instance_name, query); -@@ -422,9 +429,9 @@ std::string PluginManager::instance_dep_check(const std::string &name) { - } - } - if (!lack.empty()) { -- for (int i = 0; i < lack.size(); ++i) { -- res += "\t" + lack[i]; -- if (i != lack.size() - 1) res += '\n'; -+ for (size_t j = 0; j < lack.size(); ++j) { -+ res += "\t" + lack[j]; -+ if (j != lack.size() - 1) res += '\n'; - } - } - } --- -2.33.0 - diff --git a/0002-refactor-plugin-interface.patch b/0002-refactor-plugin-interface.patch deleted file mode 100644 index db9666a..0000000 --- a/0002-refactor-plugin-interface.patch +++ /dev/null @@ -1,1032 +0,0 @@ -From 3d8160661afa6dfd045dc51577c4bb040c25b591 Mon Sep 17 00:00:00 2001 -From: fly_1997 -Date: Sat, 25 May 2024 15:48:33 +0800 -Subject: [PATCH 1/4] refactor plugin interface - ---- - src/common/default_path.h | 4 +- - src/plugin_mgr/config.cpp | 20 +-- - src/plugin_mgr/config.h | 8 +- - src/plugin_mgr/dep_handler.cpp | 7 +- - src/plugin_mgr/dep_handler.h | 6 +- - src/plugin_mgr/error_code.cpp | 1 + - src/plugin_mgr/error_code.h | 1 + - src/plugin_mgr/instance_run_handler.cpp | 181 ++++-------------------- - src/plugin_mgr/instance_run_handler.h | 25 ++-- - src/plugin_mgr/interface.h | 44 +++--- - src/plugin_mgr/message_manager.h | 2 +- - src/plugin_mgr/plugin.cpp | 23 ++- - src/plugin_mgr/plugin.h | 84 ++--------- - src/plugin_mgr/plugin_manager.cpp | 142 +++++++------------ - src/plugin_mgr/plugin_manager.h | 12 +- - 15 files changed, 166 insertions(+), 394 deletions(-) - -diff --git a/src/common/default_path.h b/src/common/default_path.h -index 4ce68b4..0ef3aae 100644 ---- a/src/common/default_path.h -+++ b/src/common/default_path.h -@@ -14,9 +14,7 @@ - - #include - --const std::string DEFAULT_COLLECTOR_PATH = "/usr/lib64/oeAware-plugin/collector"; --const std::string DEFAULT_SCENARIO_PATH = "/usr/lib64/oeAware-plugin/scenario"; --const std::string DEFAULT_TUNE_PATH = "/usr/lib64/oeAware-plugin/tune"; -+const std::string DEFAULT_PLUGIN_PATH = "/usr/lib64/oeAware-plugin"; - const std::string DEFAULT_RUN_PATH = "/var/run/oeAware"; - const std::string DEFAULT_LOG_PATH = "/var/log/oeAware"; - -diff --git a/src/plugin_mgr/config.cpp b/src/plugin_mgr/config.cpp -index 588eda0..6e0e231 100644 ---- a/src/plugin_mgr/config.cpp -+++ b/src/plugin_mgr/config.cpp -@@ -42,7 +42,7 @@ bool check_plugin_list(YAML::Node plugin_list_item) { - return true; - } - --bool Config::load(const std::string path) { -+bool Config::load(const std::string &path) { - YAML::Node node; - struct stat buffer; - if (stat(path.c_str(), &buffer) != 0) { -@@ -106,20 +106,6 @@ bool Config::load(const std::string path) { - return true; - } - --std::string get_path(PluginType type) { -- switch (type) { -- case PluginType::COLLECTOR:{ -- return DEFAULT_COLLECTOR_PATH; -- } -- case PluginType::SCENARIO: { -- return DEFAULT_SCENARIO_PATH; -- } -- case PluginType::TUNE: { -- return DEFAULT_TUNE_PATH; -- } -- default: { -- break; -- } -- } -- return ""; -+std::string get_path() { -+ return DEFAULT_PLUGIN_PATH; - } -\ No newline at end of file -diff --git a/src/plugin_mgr/config.h b/src/plugin_mgr/config.h -index c2d1f37..3844f71 100644 ---- a/src/plugin_mgr/config.h -+++ b/src/plugin_mgr/config.h -@@ -22,7 +22,7 @@ static int log_levels[] = {0, 10000, 20000, 30000, 40000, 50000, 60000}; - - class PluginInfo { - public: -- PluginInfo(std::string name, std::string description, std::string url) : name(name), description(description), url(url) { } -+ PluginInfo(const std::string &name, const std::string &description, const std::string &url) : name(name), description(description), url(url) { } - std::string get_name() const { - return this->name; - } -@@ -52,7 +52,7 @@ namespace std { - - class EnableItem { - public: -- EnableItem(std::string name) : name(name), enabled(false) { } -+ EnableItem(const std::string &name) : name(name), enabled(false) { } - void set_enabled(bool enabled) { - this->enabled = enabled; - } -@@ -82,7 +82,7 @@ public: - Config() { - this->log_level = log_levels[2]; - } -- bool load(const std::string path); -+ bool load(const std::string &path); - int get_log_level() const { - return this->log_level; - } -@@ -122,7 +122,7 @@ private: - std::vector enable_list; - }; - --std::string get_path(PluginType type); -+std::string get_path(); - bool create_dir(const std::string &path); - - #endif -\ No newline at end of file -diff --git a/src/plugin_mgr/dep_handler.cpp b/src/plugin_mgr/dep_handler.cpp -index 816056d..c6d0985 100644 ---- a/src/plugin_mgr/dep_handler.cpp -+++ b/src/plugin_mgr/dep_handler.cpp -@@ -39,7 +39,7 @@ void DepHandler::add_arc_node(std::shared_ptr node, const std::vector dep_nodes) { -+void DepHandler::add_node(const std::string &name, const std::vector &dep_nodes) { - std::shared_ptr cur_node = add_new_node(name); - this->nodes[name] = cur_node; - add_arc_node(cur_node, dep_nodes); -@@ -52,11 +52,10 @@ void DepHandler::del_node(const std::string &name) { - } - - --std::shared_ptr DepHandler::get_node(std::string name) { -+std::shared_ptr DepHandler::get_node(const std::string &name) { - return this->nodes[name]; - } - -- - std::shared_ptr DepHandler::add_new_node(std::string name) { - std::shared_ptr cur_node = std::make_shared(name); - cur_node->head = std::make_shared(); -@@ -80,6 +79,7 @@ void DepHandler::del_node_and_arc_nodes(std::shared_ptr node) { - arc = tmp; - } - } -+ - void DepHandler::change_arc_nodes(std::string name, bool state) { - if (!nodes[name]->state || !arc_nodes.count(name)) return; - std::unordered_map, bool> &mp = arc_nodes[name]; -@@ -101,7 +101,6 @@ void DepHandler::change_arc_nodes(std::string name, bool state) { - } - } - -- - void DepHandler::query_all_top(std::vector> &query) { - for (auto &p : nodes) { - query_node_top(p.first, query); -diff --git a/src/plugin_mgr/dep_handler.h b/src/plugin_mgr/dep_handler.h -index b81d574..40b8748 100644 ---- a/src/plugin_mgr/dep_handler.h -+++ b/src/plugin_mgr/dep_handler.h -@@ -34,7 +34,7 @@ struct Node { - int real_cnt; - bool state; // dependency closed-loop - Node() : next(nullptr), head(nullptr), cnt(0), real_cnt(0), state(true) {} -- Node(std::string name): next(nullptr), head(nullptr), name(name), cnt(0), real_cnt(0), state(true) {} -+ Node(const std::string &name): next(nullptr), head(nullptr), name(name), cnt(0), real_cnt(0), state(true) {} - }; - - class DepHandler { -@@ -43,11 +43,11 @@ public: - this->head = std::make_shared(); - this->tail = head; - } -- std::shared_ptr get_node(std::string name); -+ std::shared_ptr get_node(const std::string &name); - bool get_node_state(std::string name) { - return this->nodes[name]->state; - } -- void add_node(const std::string &name, std::vector dep_nodes = {}); -+ void add_node(const std::string &name, const std::vector &dep_nodes = {}); - void del_node(const std::string &name); - std::vector get_pre_dependencies(const std::string &name); - // query instance dependency -diff --git a/src/plugin_mgr/error_code.cpp b/src/plugin_mgr/error_code.cpp -index 09f0eb9..8c7af00 100644 ---- a/src/plugin_mgr/error_code.cpp -+++ b/src/plugin_mgr/error_code.cpp -@@ -15,6 +15,7 @@ const std::unordered_map ErrorText::error_codes = { - {ErrorCode::ENABLE_INSTANCE_NOT_LOAD, "instance is not loaded"}, - {ErrorCode::ENABLE_INSTANCE_UNAVAILABLE, "instance is unavailable"}, - {ErrorCode::ENABLE_INSTANCE_ALREADY_ENABLED, "instance is already enabled"}, -+ {ErrorCode::ENABLE_INSTANCE_ENV, "instance init environment failed"}, - {ErrorCode::DISABLE_INSTANCE_NOT_LOAD, "instance is not loaded"}, - {ErrorCode::DISABLE_INSTANCE_UNAVAILABLE, "instance is unavailable"}, - {ErrorCode::DISABLE_INSTANCE_ALREADY_DISABLED, "instance is already disabled"}, -diff --git a/src/plugin_mgr/error_code.h b/src/plugin_mgr/error_code.h -index dd028f3..cdbf542 100644 ---- a/src/plugin_mgr/error_code.h -+++ b/src/plugin_mgr/error_code.h -@@ -18,6 +18,7 @@ enum class ErrorCode { - ENABLE_INSTANCE_NOT_LOAD, - ENABLE_INSTANCE_UNAVAILABLE, - ENABLE_INSTANCE_ALREADY_ENABLED, -+ ENABLE_INSTANCE_ENV, - DISABLE_INSTANCE_NOT_LOAD, - DISABLE_INSTANCE_UNAVAILABLE, - DISABLE_INSTANCE_ALREADY_DISABLED, -diff --git a/src/plugin_mgr/instance_run_handler.cpp b/src/plugin_mgr/instance_run_handler.cpp -index 8ba10db..9eed762 100644 ---- a/src/plugin_mgr/instance_run_handler.cpp -+++ b/src/plugin_mgr/instance_run_handler.cpp -@@ -13,104 +13,45 @@ - #include - #include - --static void* get_ring_buf(std::shared_ptr instance) { -+static const void* get_ring_buf(std::shared_ptr instance) { - if (instance == nullptr) { - return nullptr; - } -- switch (instance->get_type()) { -- case PluginType::COLLECTOR: { -- return (std::dynamic_pointer_cast(instance))->get_interface()->get_ring_buf(); -- } -- case PluginType::SCENARIO: { -- return (std::dynamic_pointer_cast(instance))->get_interface()->get_ring_buf(); -- } -- case PluginType::TUNE: { -- break; -- } -- default: { -- break; -- } -- } -- return nullptr; --} -- --static void reflash_ring_buf(std::shared_ptr instance) { -- (std::dynamic_pointer_cast(instance))->get_interface()->reflash_ring_buf(); --} -- --void InstanceRunHandler::run_aware(std::shared_ptr instance, std::vector &deps) { -- void *a[MAX_DEPENDENCIES_SIZE]; -- for (size_t i = 0; i < deps.size(); ++i) { -- std::shared_ptr ins = memory_store.get_instance(deps[i]); -- a[i] = get_ring_buf(ins); -- } -- (std::dynamic_pointer_cast(instance))->get_interface()->aware(a, (int)deps.size()); -+ return instance->get_interface()->get_ring_buf(); - } - --void InstanceRunHandler::run_tune(std::shared_ptr instance, std::vector &deps) { -- void *a[MAX_DEPENDENCIES_SIZE]; -+void InstanceRunHandler::run_instance(std::shared_ptr instance) { -+ std::vector input_data; -+ std::vector deps = instance->get_deps(); - for (size_t i = 0; i < deps.size(); ++i) { - std::shared_ptr ins = memory_store.get_instance(deps[i]); -- a[i] = get_ring_buf(ins); -+ input_data.emplace_back(get_ring_buf(ins)); - } -- (std::dynamic_pointer_cast(instance))->get_interface()->tune(a, (int)deps.size()); -+ Param param; -+ param.args = input_data.data(); -+ param.len = input_data.size(); -+ instance->get_interface()->run(¶m); - } - --void InstanceRunHandler::insert_instance(std::shared_ptr instance) { -- switch (instance->get_type()) { -- case PluginType::COLLECTOR: { -- collector[instance->get_name()] = instance; -- (std::dynamic_pointer_cast(instance))->get_interface()->enable(); -- break; -- } -- case PluginType::SCENARIO: { -- scenario[instance->get_name()] = instance; -- (std::dynamic_pointer_cast(instance))->get_interface()->enable(); -- break; -- } -- case PluginType::TUNE: { -- tune[instance->get_name()] = instance; -- (std::dynamic_pointer_cast(instance))->get_interface()->enable(); -- break; -- } -- default: { -- break; -- } -- } -+void InstanceRunHandler::insert_instance(std::shared_ptr instance, uint64_t time) { -+ instance->set_enabled(true); -+ schedule_queue.push(ScheduleInstance{instance, time}); - INFO("[PluginManager] " << instance->get_name() << " instance insert into running queue."); - } - - void InstanceRunHandler::delete_instance(std::shared_ptr instance) { -- switch (instance->get_type()) { -- case PluginType::COLLECTOR: { -- collector.erase(instance->get_name()); -- (std::dynamic_pointer_cast(instance))->get_interface()->disable(); -- break; -- } -- case PluginType::SCENARIO: { -- scenario.erase(instance->get_name()); -- (std::dynamic_pointer_cast(instance))->get_interface()->disable(); -- break; -- } -- case PluginType::TUNE: { -- tune.erase(instance->get_name()); -- (std::dynamic_pointer_cast(instance))->get_interface()->disable(); -- break; -- } -- default: { -- break; -- } -- } -+ instance->get_interface()->disable(); -+ instance->set_enabled(false); - INFO("[PluginManager] " << instance->get_name() << " instance delete from running queue."); - } - --void InstanceRunHandler::handle_instance() { -+void InstanceRunHandler::handle_instance(uint64_t time) { - InstanceRunMessage msg; - while(this->recv_queue_try_pop(msg)){ - std::shared_ptr instance = msg.get_instance(); - switch (msg.get_type()){ - case RunType::ENABLED: { -- insert_instance(std::move(instance)); -+ insert_instance(std::move(instance), time); - break; - } - case RunType::DISABLED: { -@@ -121,78 +62,19 @@ void InstanceRunHandler::handle_instance() { - } - } - --template --static std::vector get_deps(std::shared_ptr instance) { -- std::shared_ptr t_instance = std::dynamic_pointer_cast(instance); -- std::string deps = (t_instance)->get_interface()->get_dep(); -- std::string dep = ""; -- std::vector vec; -- for (size_t i = 0; i < deps.length(); ++i) { -- if (deps[i] != '-') { -- dep += deps[i]; -- }else { -- vec.emplace_back(dep); -- dep = ""; -- } -- } -- vec.emplace_back(dep); -- return vec; --} -- --void InstanceRunHandler::adjust_collector_queue(const std::vector &deps, const std::vector &m_deps, bool flag) { -- for (auto &m_dep : m_deps) { -- bool ok = false; -- for (auto &dep : deps) { -- if (m_dep == dep) { -- ok = true; -- } -+void InstanceRunHandler::schedule(uint64_t time) { -+ while (!schedule_queue.empty()) { -+ auto schedule_instance = schedule_queue.top(); -+ if (schedule_instance.time != time) { -+ break; - } -- if (ok) continue; -- if (flag) { -- if (is_instance_exist(m_dep) && !collector.count(m_dep)) { -- this->insert_instance(memory_store.get_instance(m_dep)); -- } -- } else { -- if (is_instance_exist(m_dep) && collector.count(m_dep)) { -- this->delete_instance(memory_store.get_instance(m_dep)); -- } -+ schedule_queue.pop(); -+ if (!schedule_instance.instance->get_enabled()) { -+ break; - } -- } --} -- --void InstanceRunHandler::check_scenario_dependency(const std::vector &origin_deps, const std::vector &cur_deps) { -- adjust_collector_queue(origin_deps, cur_deps, true); -- adjust_collector_queue(cur_deps, origin_deps, false); --} -- --void InstanceRunHandler::schedule_collector(uint64_t time) { -- for (auto &p : collector) { -- std::shared_ptr instance = p.second; -- int t = (std::dynamic_pointer_cast(instance))->get_interface()->get_cycle(); -- if (time % t != 0) return; -- reflash_ring_buf(instance); -- } --} -- --void InstanceRunHandler::schedule_scenario(uint64_t time) { -- for (auto &p : scenario) { -- std::shared_ptr instance = p.second; -- int t = (std::dynamic_pointer_cast(instance))->get_interface()->get_cycle(); -- if (time % t != 0) return; -- std::vector origin_deps = get_deps(instance); -- run_aware(instance, origin_deps); -- std::vector cur_deps = get_deps(instance); -- check_scenario_dependency(origin_deps, cur_deps); -- } --} -- --void InstanceRunHandler::schedule_tune(uint64_t time) { -- for (auto &p : tune) { -- std::shared_ptr instance = p.second; -- int t = (std::dynamic_pointer_cast(instance))->get_interface()->get_cycle(); -- if (time % t != 0) return; -- std::vector deps = get_deps(instance); -- run_tune(instance, deps); -+ run_instance(schedule_instance.instance); -+ schedule_instance.time += schedule_instance.instance->get_interface()->get_cycle(); -+ schedule_queue.push(schedule_instance); - } - } - -@@ -200,11 +82,8 @@ void start(InstanceRunHandler *instance_run_handler) { - unsigned long long time = 0; - INFO("[PluginManager] instance schedule started!"); - while(true) { -- instance_run_handler->handle_instance(); -- instance_run_handler->schedule_collector(time); -- instance_run_handler->schedule_scenario(time); -- instance_run_handler->schedule_tune(time); -- -+ instance_run_handler->handle_instance(time); -+ instance_run_handler->schedule(time); - usleep(instance_run_handler->get_cycle() * 1000); - time += instance_run_handler->get_cycle(); - } -diff --git a/src/plugin_mgr/instance_run_handler.h b/src/plugin_mgr/instance_run_handler.h -index 83f9f4a..4172e99 100644 ---- a/src/plugin_mgr/instance_run_handler.h -+++ b/src/plugin_mgr/instance_run_handler.h -@@ -20,6 +20,7 @@ - #include - #include - #include -+#include - #include - - enum class RunType { -@@ -43,15 +44,22 @@ private: - std::shared_ptr instance; - }; - -+class ScheduleInstance { -+public: -+ bool operator < (const ScheduleInstance &rhs) const { -+ return time > rhs.time || (time == rhs.time && instance->get_type() > rhs.instance->get_type()); -+ } -+ std::shared_ptr instance; -+ uint64_t time; -+}; -+ - // A handler to schedule plugin instance - class InstanceRunHandler { - public: - InstanceRunHandler(MemoryStore &memory_store) : memory_store(memory_store), cycle(DEFAULT_CYCLE_SIZE) {} - void run(); -- void schedule_collector(uint64_t time); -- void schedule_scenario(uint64_t time); -- void schedule_tune(uint64_t time); -- void handle_instance(); -+ void schedule(uint64_t time); -+ void handle_instance(uint64_t time); - void set_cycle(int cycle) { - this->cycle = cycle; - } -@@ -71,16 +79,13 @@ public: - return this->recv_queue.try_pop(msg); - } - private: -- void run_aware(std::shared_ptr instance, std::vector &deps); -- void run_tune(std::shared_ptr instance, std::vector &deps); -+ void run_instance(std::shared_ptr instance); - void delete_instance(std::shared_ptr instance); -- void insert_instance(std::shared_ptr instance); -+ void insert_instance(std::shared_ptr instance, uint64_t time); - void adjust_collector_queue(const std::vector &deps, const std::vector &m_deps, bool flag); - void check_scenario_dependency(const std::vector &deps, const std::vector &m_deps); - -- std::unordered_map> collector; -- std::unordered_map> scenario; -- std::unordered_map> tune; -+ std::priority_queue schedule_queue; - SafeQueue recv_queue; - MemoryStore &memory_store; - int cycle; -diff --git a/src/plugin_mgr/interface.h b/src/plugin_mgr/interface.h -index 075378a..2106698 100644 ---- a/src/plugin_mgr/interface.h -+++ b/src/plugin_mgr/interface.h -@@ -12,40 +12,28 @@ - #ifndef PLUGIN_MGR_INTERFACE_H - #define PLUGIN_MGR_INTERFACE_H - --struct CollectorInterface { -- char* (*get_version)(); -- char* (*get_name)(); -- char* (*get_description)(); -- char* (*get_type)(); -- int (*get_cycle)(); -- char* (*get_dep)(); -- void (*enable)(); -- void (*disable)(); -- void* (*get_ring_buf)(); -- void (*reflash_ring_buf)(); -+enum PluginType { -+ COLLECTOR, -+ SCENARIO, -+ TUNE, - }; - --struct ScenarioInterface { -- char* (*get_version)(); -- char* (*get_name)(); -- char* (*get_description)(); -- char* (*get_dep)(); -- int (*get_cycle)(); -- void (*enable)(); -- void (*disable)(); -- void (*aware)(void*[], int); -- void* (*get_ring_buf)(); -+struct Param { -+ void *args; -+ int len; - }; - --struct TuneInterface { -- char* (*get_version)(); -- char* (*get_name)(); -- char* (*get_description)(); -- char* (*get_dep)(); -+struct Interface { -+ const char* (*get_version)(); -+ const char* (*get_name)(); -+ const char* (*get_description)(); -+ const char* (*get_dep)(); -+ PluginType (*get_type)(); - int (*get_cycle)(); -- void (*enable)(); -+ bool (*enable)(); - void (*disable)(); -- void (*tune)(void*[], int); -+ const void* (*get_ring_buf)(); -+ void (*run)(const Param*); - }; - - #endif // !PLUGIN_MGR_INTERFACE_H -diff --git a/src/plugin_mgr/message_manager.h b/src/plugin_mgr/message_manager.h -index 416be48..00ea4c7 100644 ---- a/src/plugin_mgr/message_manager.h -+++ b/src/plugin_mgr/message_manager.h -@@ -31,7 +31,7 @@ public: - Message() : type(MessageType::EXTERNAL) {} - Message(Opt opt) : opt(opt) {} - Message(Opt opt, MessageType type) : opt(opt), type(type) {} -- Message(Opt opt, std::vector payload) : opt(opt), payload(payload) {} -+ Message(Opt opt, const std::vector &payload) : opt(opt), payload(payload) {} - Opt get_opt() { - return this->opt; - } -diff --git a/src/plugin_mgr/plugin.cpp b/src/plugin_mgr/plugin.cpp -index 1a2db0d..bdd8226 100644 ---- a/src/plugin_mgr/plugin.cpp -+++ b/src/plugin_mgr/plugin.cpp -@@ -16,7 +16,7 @@ const std::string Instance::PLUGIN_DISABLED = "close"; - const std::string Instance::PLUGIN_STATE_ON = "available"; - const std::string Instance::PLUGIN_STATE_OFF = "unavailable"; - --int Plugin::load(const std::string dl_path) { -+int Plugin::load(const std::string &dl_path) { - void *handler = dlopen(dl_path.c_str(), RTLD_LAZY); - if (handler == nullptr) { - return -1; -@@ -30,3 +30,24 @@ std::string Instance::get_info() const { - std::string run_text = this->enabled ? PLUGIN_ENABLED : PLUGIN_DISABLED; - return name + "(" + state_text + ", " + run_text + ")"; - } -+ -+std::vector Instance::get_deps() { -+ std::vector vec; -+ if (get_interface()->get_dep == nullptr) { -+ return vec; -+ } -+ std::string deps = get_interface()->get_dep(); -+ std::string dep = ""; -+ for (size_t i = 0; i < deps.length(); ++i) { -+ if (deps[i] != '-') { -+ dep += deps[i]; -+ } else { -+ vec.emplace_back(dep); -+ dep = ""; -+ } -+ } -+ if (!dep.empty()) { -+ vec.emplace_back(dep); -+ } -+ return vec; -+} -diff --git a/src/plugin_mgr/plugin.h b/src/plugin_mgr/plugin.h -index d59ab8a..ac0e0b5 100644 ---- a/src/plugin_mgr/plugin.h -+++ b/src/plugin_mgr/plugin.h -@@ -17,31 +17,21 @@ - #include - #include - --enum class PluginType { -- COLLECTOR, -- SCENARIO, -- TUNE, -- EMPTY, --}; -- --std::string plugin_type_to_string(PluginType type); -- - class Instance { - public: -- virtual ~Instance() = default; -- void set_name(std::string name) { -+ void set_name(const std::string &name) { - this->name = name; - } - std::string get_name() const { - return this->name; - } -- void set_type(PluginType type) { -- this->type = type; -- } - PluginType get_type() const { -- return type; -+ return interface->get_type(); -+ } -+ Interface* get_interface() const { -+ return this->interface; - } -- void set_plugin_name(std::string name) { -+ void set_plugin_name(const std::string &name) { - this->plugin_name = name; - } - std::string get_plugin_name() const { -@@ -59,82 +49,35 @@ public: - bool get_enabled() const { - return this->enabled; - } -+ void set_interface(Interface *interface) { -+ this->interface = interface; -+ } - std::string get_info() const; -+ std::vector get_deps(); - private: - std::string name; - std::string plugin_name; -- PluginType type; - bool state; - bool enabled; -+ Interface *interface; - const static std::string PLUGIN_ENABLED; - const static std::string PLUGIN_DISABLED; - const static std::string PLUGIN_STATE_ON; - const static std::string PLUGIN_STATE_OFF; - }; - --class CollectorInstance : public Instance { --public: -- CollectorInstance() : interface(nullptr) { } -- ~CollectorInstance() { -- interface = nullptr; -- } -- void set_interface(CollectorInterface *interface) { -- this->interface = interface; -- } -- CollectorInterface* get_interface() const { -- return this->interface; -- } --private: -- CollectorInterface* interface; --}; -- --class ScenarioInstance : public Instance { --public: -- ScenarioInstance() : interface(nullptr) { } -- ~ScenarioInstance() { -- interface = nullptr; -- } -- void set_interface(ScenarioInterface *interface) { -- this->interface = interface; -- } -- ScenarioInterface* get_interface() const { -- return this->interface; -- } --private: -- ScenarioInterface* interface; --}; -- --class TuneInstance : public Instance { --public: -- TuneInstance() : interface(nullptr) { } -- ~TuneInstance() { -- interface = nullptr; -- } -- void set_interface(TuneInterface *interface) { -- this->interface = interface; -- } -- TuneInterface* get_interface() const { -- return this->interface; -- } --private: -- TuneInterface *interface; --}; -- - class Plugin { - public: -- Plugin(std::string name, PluginType type) : name(name), type(type), handler(nullptr) { } -+ Plugin(const std::string &name) : name(name), handler(nullptr) { } - ~Plugin() { - if (handler != nullptr) { - dlclose(handler); - } - } -- int load(const std::string dl_path); -+ int load(const std::string &dl_path); - std::string get_name() const { - return this->name; - } -- PluginType get_type() const { -- return this->type; -- } - void add_instance(std::shared_ptr ins) { - instances.emplace_back(ins); - } -@@ -150,7 +93,6 @@ public: - private: - std::vector> instances; - std::string name; -- PluginType type; - void *handler; - }; - -diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp -index 5324512..1503fc1 100644 ---- a/src/plugin_mgr/plugin_manager.cpp -+++ b/src/plugin_mgr/plugin_manager.cpp -@@ -78,9 +78,8 @@ ErrorCode PluginManager::query_plugin(const std::string &name, std::string &res) - return ErrorCode::OK; - } - --template --int PluginManager::load_dl_instance(std::shared_ptr plugin, T **interface_list) { -- int (*get_instance)(T**) = (int(*)(T**))dlsym(plugin->get_handler(), "get_instance"); -+int PluginManager::load_dl_instance(std::shared_ptr plugin, Interface **interface_list) { -+ int (*get_instance)(Interface**) = (int(*)(Interface**))dlsym(plugin->get_handler(), "get_instance"); - if (get_instance == nullptr) { - ERROR("[PluginManager] dlsym error!\n"); - return -1; -@@ -90,78 +89,33 @@ int PluginManager::load_dl_instance(std::shared_ptr plugin, T **interfac - return len; - } - --template --std::vector get_dep(T *interface) { -- char *deps = interface->get_dep(); -- std::vector res; -- std::string dep; -- for (int i = 0; deps[i] != 0; ++i) { -- if (deps[i] != '-') { -- dep += deps[i]; -- } else { -- res.emplace_back(dep); -- dep = ""; -- } -- } -- if (!dep.empty()) res.emplace_back(dep); -- return res; --} -- --template --void PluginManager::save_instance(std::shared_ptr plugin, T *interface_list, int len) { -+void PluginManager::save_instance(std::shared_ptr plugin, Interface *interface_list, int len) { - if (interface_list == nullptr) return; - for (int i = 0; i < len; ++i) { -- T *interface = interface_list + i; -- std::shared_ptr instance = std::make_shared(); -+ Interface *interface = interface_list + i; -+ std::shared_ptr instance = std::make_shared(); - std::string name = interface->get_name(); -+ instance->set_interface(interface); - instance->set_name(name); - instance->set_plugin_name(plugin->get_name()); -- instance->set_type(plugin->get_type()); - instance->set_enabled(false); -- if (plugin->get_type() == PluginType::COLLECTOR) { -- DEBUG("[PluginManager] add node"); -- dep_handler.add_node(name); -- } else { -- dep_handler.add_node(name, get_dep(interface)); -- } -+ dep_handler.add_node(name, instance->get_deps()); - instance->set_state(dep_handler.get_node_state(name)); -- (std::dynamic_pointer_cast(instance))->set_interface(interface); - DEBUG("[PluginManager] Instance: " << name.c_str()); - memory_store.add_instance(name, instance); -- plugin->add_instance(instance); -+ plugin->add_instance(instance); - } - } - - bool PluginManager::load_instance(std::shared_ptr plugin) { - int len = 0; - DEBUG("plugin: " << plugin->get_name()); -- switch (plugin->get_type()) { -- case PluginType::COLLECTOR: { -- CollectorInterface *interface_list = nullptr; -- len = load_dl_instance(plugin, &interface_list); -- if (len == -1) return false; -- DEBUG("[PluginManager] save collect instance"); -- save_instance(plugin, interface_list, len); -- break; -- } -- case PluginType::SCENARIO: { -- ScenarioInterface *interface_list = nullptr; -- len = load_dl_instance(plugin, &interface_list); -- if (len == -1) return false; -- save_instance(plugin, interface_list, len); -- break; -- } -- case PluginType::TUNE: { -- TuneInterface *interface_list = nullptr; -- len = load_dl_instance(plugin, &interface_list); -- if (len == -1) return false; -- save_instance(plugin, interface_list, len); -- break; -- } -- default: { -- return false; -- } -+ Interface *interface_list = nullptr; -+ len = load_dl_instance(plugin, &interface_list); -+ if (len < 0) { -+ return false; - } -+ save_instance(plugin, interface_list, len); - update_instance_state(); - return true; - } -@@ -177,8 +131,8 @@ void PluginManager::update_instance_state() { - } - } - --ErrorCode PluginManager::load_plugin(const std::string &name, PluginType type) { -- std::string plugin_path = get_path(type) + "/" + name; -+ErrorCode PluginManager::load_plugin(const std::string &name) { -+ std::string plugin_path = get_path() + "/" + name; - if (!file_exist(plugin_path)) { - return ErrorCode::LOAD_PLUGIN_FILE_NOT_EXIST; - } -@@ -191,9 +145,8 @@ ErrorCode PluginManager::load_plugin(const std::string &name, PluginType type) { - if (memory_store.is_plugin_exist(name)) { - return ErrorCode::LOAD_PLUGIN_EXIST; - } -- const std::string dl_path = get_path(type) + '/' + name; -- std::shared_ptr plugin = std::make_shared(name, type); -- int error = plugin->load(dl_path); -+ std::shared_ptr plugin = std::make_shared(name); -+ int error = plugin->load(plugin_path); - if (error) { - return ErrorCode::LOAD_PLUGIN_DLOPEN_FAILED; - } -@@ -268,16 +221,35 @@ ErrorCode PluginManager::instance_enabled(std::string name) { - return ErrorCode::ENABLE_INSTANCE_ALREADY_ENABLED; - } - std::vector pre_dependencies = dep_handler.get_pre_dependencies(name); -+ std::vector> new_enabled; -+ bool enabled = true; - for (int i = pre_dependencies.size() - 1; i >= 0; --i) { - instance = memory_store.get_instance(pre_dependencies[i]); - if (instance->get_enabled()) { - continue; - } -- instance->set_enabled(true); -- instance_run_handler->recv_queue_push(InstanceRunMessage(RunType::ENABLED, instance)); -- DEBUG("[PluginManager] " << instance->get_name() << " instance enabled."); -+ new_enabled.emplace_back(instance); -+ if (!instance->get_interface()->enable()) { -+ enabled = false; -+ WARN("[PluginManager] " << instance->get_name() << " instance enabled failed, because instance init environment failed."); -+ break; -+ } -+ } -+ if (enabled) { -+ for (int i = pre_dependencies.size() - 1; i >= 0; --i) { -+ instance = memory_store.get_instance(pre_dependencies[i]); -+ if (instance->get_enabled()) { -+ continue; -+ } -+ instance_run_handler->recv_queue_push(InstanceRunMessage(RunType::ENABLED, instance)); -+ } -+ return ErrorCode::OK; -+ } else { -+ for (auto instance : new_enabled) { -+ instance->get_interface()->disable(); -+ } -+ return ErrorCode::ENABLE_INSTANCE_ENV; - } -- return ErrorCode::OK; - } - - ErrorCode PluginManager::instance_disabled(std::string name) { -@@ -291,7 +263,6 @@ ErrorCode PluginManager::instance_disabled(std::string name) { - if (!instance->get_enabled()) { - return ErrorCode::DISABLE_INSTANCE_ALREADY_DISABLED; - } -- instance->set_enabled(false); - instance_run_handler->recv_queue_push(InstanceRunMessage(RunType::DISABLED, instance)); - return ErrorCode::OK; - } -@@ -331,9 +302,7 @@ ErrorCode PluginManager::add_list(std::string &res) { - res += p.first + "\n"; - } - res += "Installed Plugins:\n"; -- res += get_plugin_in_dir(DEFAULT_COLLECTOR_PATH); -- res += get_plugin_in_dir(DEFAULT_SCENARIO_PATH); -- res += get_plugin_in_dir(DEFAULT_TUNE_PATH); -+ res += get_plugin_in_dir(DEFAULT_PLUGIN_PATH); - return ErrorCode::OK; - } - -@@ -371,15 +340,15 @@ void PluginManager::pre_enable() { - } - } - --void PluginManager::pre_load_plugin(PluginType type) { -- std::string path = get_path(type); -+void PluginManager::pre_load_plugin() { -+ std::string path = get_path(); - DIR *dir = opendir(path.c_str()); - if (dir == nullptr) return; - struct dirent *entry; - while ((entry = readdir(dir)) != nullptr) { - std::string name = entry->d_name; - if (end_with(name, ".so")) { -- auto ret = load_plugin(name, type); -+ auto ret = load_plugin(name); - if (ret != ErrorCode::OK) { - WARN("[PluginManager] " << name << " plugin preload failed, because " << ErrorText::get_error_text(ret) << "."); - } else { -@@ -391,27 +360,13 @@ void PluginManager::pre_load_plugin(PluginType type) { - } - - void PluginManager::pre_load() { -- pre_load_plugin(PluginType::COLLECTOR); -- pre_load_plugin(PluginType::SCENARIO); -- pre_load_plugin(PluginType::TUNE); -+ pre_load_plugin(); - pre_enable(); - } - --void* PluginManager::get_data_buffer(std::string name) { -+const void* PluginManager::get_data_buffer(std::string name) { - std::shared_ptr instance = memory_store.get_instance(name); -- switch (instance->get_type()) { -- case PluginType::COLLECTOR: { -- CollectorInterface *collector_interface = (std::dynamic_pointer_cast(instance))->get_interface(); -- return collector_interface->get_ring_buf(); -- } -- case PluginType::SCENARIO: { -- ScenarioInterface *scenario_interface = (std::dynamic_pointer_cast(instance))->get_interface(); -- return scenario_interface->get_ring_buf(); -- } -- default: -- return nullptr; -- } -- return nullptr; -+ return instance->get_interface()->get_ring_buf(); - } - - std::string PluginManager::instance_dep_check(const std::string &name) { -@@ -465,8 +420,7 @@ int PluginManager::run() { - switch (msg.get_opt()) { - case Opt::LOAD: { - std::string plugin_name = msg.get_payload(0); -- PluginType type = plugin_types[msg.get_payload(1)]; -- ErrorCode ret_code = load_plugin(plugin_name, type); -+ ErrorCode ret_code = load_plugin(plugin_name); - if(ret_code == ErrorCode::OK) { - INFO("[PluginManager] " << plugin_name << " plugin loaded."); - res.set_opt(Opt::RESPONSE_OK); -diff --git a/src/plugin_mgr/plugin_manager.h b/src/plugin_mgr/plugin_manager.h -index 709d42e..9339f0d 100644 ---- a/src/plugin_mgr/plugin_manager.h -+++ b/src/plugin_mgr/plugin_manager.h -@@ -33,10 +33,10 @@ public: - void pre_load(); - void pre_enable(); - void init(); -- void* get_data_buffer(std::string name); -+ const void* get_data_buffer(std::string name); - private: -- void pre_load_plugin(PluginType type); -- ErrorCode load_plugin(const std::string &path, PluginType type); -+ void pre_load_plugin(); -+ ErrorCode load_plugin(const std::string &path); - ErrorCode remove(const std::string &name); - ErrorCode query_all_plugins(std::string &res); - ErrorCode query_plugin(const std::string &name, std::string &res); -@@ -47,10 +47,8 @@ private: - ErrorCode add_list(std::string &res); - ErrorCode download(const std::string &name, std::string &res); - std::string instance_dep_check(const std::string &name); -- template -- int load_dl_instance(std::shared_ptr plugin, T **interface_list); -- template -- void save_instance(std::shared_ptr plugin, T *interface_list, int len); -+ int load_dl_instance(std::shared_ptr plugin, Interface **interface_list); -+ void save_instance(std::shared_ptr plugin, Interface *interface_list, int len); - bool load_instance(std::shared_ptr plugin); - void batch_load(); - void batch_remove(); --- -2.33.0 - diff --git a/0003-the-client-adapts-to-the-new-interface-and-refactor-.patch b/0003-the-client-adapts-to-the-new-interface-and-refactor-.patch deleted file mode 100644 index 1c7f8c2..0000000 --- a/0003-the-client-adapts-to-the-new-interface-and-refactor-.patch +++ /dev/null @@ -1,1080 +0,0 @@ -From 2f00d1f6c4a0dd199cdfb13e9a541c5f87f5cf4e Mon Sep 17 00:00:00 2001 -From: fly_1997 -Date: Tue, 28 May 2024 11:09:13 +0800 -Subject: [PATCH 2/4] the client adapts to the new interface and refactor - memory store - ---- - src/client/arg_parse.cpp | 18 +----- - src/client/arg_parse.h | 4 -- - src/client/client.cpp | 1 - - src/client/cmd_handler.cpp | 7 +-- - src/client/cmd_handler.h | 4 -- - src/common/message_protocol.cpp | 1 - - src/common/message_protocol.h | 4 +- - src/plugin_mgr/config.h | 7 +-- - src/plugin_mgr/dep_handler.cpp | 84 +++++++++++++------------ - src/plugin_mgr/dep_handler.h | 56 ++++++++--------- - src/plugin_mgr/instance_run_handler.cpp | 8 +-- - src/plugin_mgr/instance_run_handler.h | 11 +--- - src/plugin_mgr/interface.h | 33 ++++++++-- - src/plugin_mgr/logger.cpp | 1 - - src/plugin_mgr/main.cpp | 1 - - src/plugin_mgr/memory_store.h | 39 +++++++----- - src/plugin_mgr/message_manager.h | 3 +- - src/plugin_mgr/plugin.cpp | 2 +- - src/plugin_mgr/plugin.h | 2 +- - src/plugin_mgr/plugin_manager.cpp | 75 ++++++++-------------- - src/plugin_mgr/plugin_manager.h | 29 +++------ - 21 files changed, 174 insertions(+), 216 deletions(-) - -diff --git a/src/client/arg_parse.cpp b/src/client/arg_parse.cpp -index 947c4c4..75e9671 100644 ---- a/src/client/arg_parse.cpp -+++ b/src/client/arg_parse.cpp -@@ -13,11 +13,10 @@ - #include - #include - --const std::string ArgParse::OPT_STRING = "Qqd:t:l:r:e:i:"; -+const std::string ArgParse::OPT_STRING = "Qqd:l:r:e:i:"; - const struct option ArgParse::long_options[] = { - {"help", no_argument, NULL, 'h'}, - {"load", required_argument, NULL, 'l'}, -- {"type", required_argument, NULL, 't'}, - {"remove", required_argument, NULL, 'r'}, - {"query", required_argument, NULL, 'q'}, - {"query-dep", required_argument, NULL, 'Q'}, -@@ -34,10 +33,6 @@ void ArgParse::arg_error(const std::string &msg) { - exit(EXIT_FAILURE); - } - --void ArgParse::set_type(char *_type) { -- type = _type; --} -- - void ArgParse::set_arg(char *_arg) { - arg = std::string(_arg); - } -@@ -46,10 +41,6 @@ void ArgParse::print_help() { - std::cout << "usage: oeawarectl [options]...\n" - " options\n" - " -l|--load [plugin] load plugin and need plugin type.\n" -- " -t|--type [plugin_type] assign plugin type. there are three types:\n" -- " collector: collection plugin.\n" -- " scenario: awareness plugin.\n" -- " tune: tune plugin.\n" - " -r|--remove [plugin] remove plugin from system.\n" - " -e|--enable [instance] enable the plugin instance.\n" - " -d|--disable [instance] disable the plugin instance.\n" -@@ -70,7 +61,6 @@ void ArgParse::init_opts() { - opts.insert('e'); - opts.insert('d'); - opts.insert('i'); -- opts.insert('t'); - } - - int ArgParse::init(int argc, char *argv[]) { -@@ -82,9 +72,6 @@ int ArgParse::init(int argc, char *argv[]) { - while((opt = getopt_long(argc, argv, OPT_STRING.c_str(), long_options, nullptr)) != -1) { - std::string full_opt; - switch (opt) { -- case 't': -- set_type(optarg); -- break; - case 'h': - help = true; - break; -@@ -118,9 +105,6 @@ int ArgParse::init(int argc, char *argv[]) { - - } - } -- if (cmd == 'l' && type.empty()) { -- arg_error("missing arguments."); -- } - if (help) { - print_help(); - exit(EXIT_SUCCESS); -diff --git a/src/client/arg_parse.h b/src/client/arg_parse.h -index 6a0a25b..e3e55cd 100644 ---- a/src/client/arg_parse.h -+++ b/src/client/arg_parse.h -@@ -22,15 +22,11 @@ public: - static void init_opts(); - static void set_type(char* _type); - static void set_arg(char* _arg); -- static std::string get_type() { -- return type; -- } - static std::string get_arg() { - return arg; - } - private: - static std::string arg; -- static std::string type; - static std::unordered_set opts; - static const std::string OPT_STRING; - static const int MAX_OPT_SIZE = 20; -diff --git a/src/client/client.cpp b/src/client/client.cpp -index afaa189..6318d5d 100644 ---- a/src/client/client.cpp -+++ b/src/client/client.cpp -@@ -12,7 +12,6 @@ - #include "client.h" - - std::string ArgParse::arg; --std::string ArgParse::type; - std::unordered_set ArgParse::opts; - - void Client::cmd_groups_init() { -diff --git a/src/client/cmd_handler.cpp b/src/client/cmd_handler.cpp -index 6f3f760..009a9bc 100644 ---- a/src/client/cmd_handler.cpp -+++ b/src/client/cmd_handler.cpp -@@ -23,10 +23,7 @@ void LoadHandler::check(const std::string &type) { - - void LoadHandler::handler(Msg &msg) { - std::string arg = ArgParse::get_arg(); -- std::string type = ArgParse::get_type(); -- check(type); - msg.add_payload(arg); -- msg.add_payload(type); - msg.set_opt(Opt::LOAD); - } - -@@ -109,10 +106,10 @@ void write_to_file(const std::string &file_name, const std::string &text) { - void QueryTopHandler::handler(Msg &msg) { - std::string arg = ArgParse::get_arg(); - if (arg.empty()) { -- msg.set_opt(Opt::QUERY_ALL_TOP); -+ msg.set_opt(Opt::QUERY_ALL_DEPS); - } else { - msg.add_payload(arg); -- msg.set_opt(Opt::QUERY_TOP); -+ msg.set_opt(Opt::QUERY_DEP); - } - } - -diff --git a/src/client/cmd_handler.h b/src/client/cmd_handler.h -index 2e32098..53178fd 100644 ---- a/src/client/cmd_handler.h -+++ b/src/client/cmd_handler.h -@@ -13,9 +13,6 @@ - #define CLIENT_CMD_HANDLER_H - #include "message_protocol.h" - #include "arg_parse.h" --#include --#include --#include - - class CmdHandler { - public: -@@ -27,7 +24,6 @@ public: - - class LoadHandler : public CmdHandler { - public: -- // LoadHandler(const ArgParse &arg_parse) { } - void handler(Msg &msg) override; - void res_handler(Msg &msg) override; - private: -diff --git a/src/common/message_protocol.cpp b/src/common/message_protocol.cpp -index a813a6c..9cf9415 100644 ---- a/src/common/message_protocol.cpp -+++ b/src/common/message_protocol.cpp -@@ -10,7 +10,6 @@ - * See the Mulan PSL v2 for more details. - ******************************************************************************/ - #include "message_protocol.h" --#include - - template - inline ssize_t handle_error(T fn) { -diff --git a/src/common/message_protocol.h b/src/common/message_protocol.h -index b2c3c0d..d659f59 100644 ---- a/src/common/message_protocol.h -+++ b/src/common/message_protocol.h -@@ -34,8 +34,8 @@ enum class Opt { - REMOVE, - QUERY, - QUERY_ALL, -- QUERY_TOP, -- QUERY_ALL_TOP, -+ QUERY_DEP, -+ QUERY_ALL_DEPS, - LIST, - DOWNLOAD, - RESPONSE_OK, -diff --git a/src/plugin_mgr/config.h b/src/plugin_mgr/config.h -index 3844f71..9d097ab 100644 ---- a/src/plugin_mgr/config.h -+++ b/src/plugin_mgr/config.h -@@ -13,7 +13,6 @@ - #define PLUGIN_MGR_CONFIG_H - - #include "plugin.h" --#include - #include - #include - #include -@@ -52,7 +51,7 @@ namespace std { - - class EnableItem { - public: -- EnableItem(const std::string &name) : name(name), enabled(false) { } -+ explicit EnableItem(const std::string &name) : name(name), enabled(false) { } - void set_enabled(bool enabled) { - this->enabled = enabled; - } -@@ -86,9 +85,6 @@ public: - int get_log_level() const { - return this->log_level; - } -- int get_schedule_cycle() const { -- return this->schedule_cycle; -- } - std::string get_log_type() const { - return this->log_type; - } -@@ -115,7 +111,6 @@ public: - } - private: - int log_level; -- int schedule_cycle; - std::string log_path; - std::string log_type; - std::unordered_map plugin_list; -diff --git a/src/plugin_mgr/dep_handler.cpp b/src/plugin_mgr/dep_handler.cpp -index c6d0985..1006175 100644 ---- a/src/plugin_mgr/dep_handler.cpp -+++ b/src/plugin_mgr/dep_handler.cpp -@@ -11,39 +11,52 @@ - ******************************************************************************/ - #include "dep_handler.h" - #include --#include --#include - -+bool DepHandler::is_instance_exist(const std::string &name) { -+ return nodes.count(name); -+} -+ -+void DepHandler::add_instance(std::shared_ptr instance) { -+ add_node(instance); -+} -+ -+void DepHandler::delete_instance(const std::string &name) { -+ del_node(name); -+} -+ - void DepHandler::add_arc_node(std::shared_ptr node, const std::vector &dep_nodes) { - std::shared_ptr arc_head = node->head; - node->cnt = dep_nodes.size(); - int real_cnt = 0; -- bool state = true; - for (auto name : dep_nodes) { - std::shared_ptr tmp = std::make_shared(); - tmp->arc_name = name; -- tmp->node_name = node->name; -+ tmp->node_name = node->instance->get_name(); - tmp->next = arc_head->next; - arc_head->next = tmp; - - if (nodes.count(name)) { -- arc_nodes[name][tmp] = true; -+ tmp->is_exist = true; -+ arc_nodes[name].insert(tmp); - real_cnt++; - } else { -- arc_nodes[name][tmp] = false; -- state = false; -+ tmp->is_exist = false; -+ arc_nodes[name].insert(tmp); - } - } -- node->state = state; -+ if (real_cnt == node->cnt) { -+ node->instance->set_state(true); -+ } - node->real_cnt = real_cnt; - } - -- --void DepHandler::add_node(const std::string &name, const std::vector &dep_nodes) { -- std::shared_ptr cur_node = add_new_node(name); -+void DepHandler::add_node(std::shared_ptr instance) { -+ std::string name = instance->get_name(); -+ std::shared_ptr cur_node = add_new_node(instance); - this->nodes[name] = cur_node; -+ std::vector dep_nodes = instance->get_deps(); - add_arc_node(cur_node, dep_nodes); -- change_arc_nodes(name, true); -+ update_instance_state(name); - } - - void DepHandler::del_node(const std::string &name) { -@@ -56,16 +69,14 @@ std::shared_ptr DepHandler::get_node(const std::string &name) { - return this->nodes[name]; - } - --std::shared_ptr DepHandler::add_new_node(std::string name) { -- std::shared_ptr cur_node = std::make_shared(name); -+std::shared_ptr DepHandler::add_new_node(std::shared_ptr instance) { -+ std::shared_ptr cur_node = std::make_shared(); -+ cur_node->instance = instance; - cur_node->head = std::make_shared(); -- tail->next = cur_node; -- tail = cur_node; - return cur_node; - } - - void DepHandler::del_node_and_arc_nodes(std::shared_ptr node) { -- std::shared_ptr next = node->next; - std::shared_ptr arc = node->head; - while(arc) { - std::shared_ptr tmp = arc->next; -@@ -80,34 +91,28 @@ void DepHandler::del_node_and_arc_nodes(std::shared_ptr node) { - } - } - --void DepHandler::change_arc_nodes(std::string name, bool state) { -- if (!nodes[name]->state || !arc_nodes.count(name)) return; -- std::unordered_map, bool> &mp = arc_nodes[name]; -- for (auto &vec : mp) { -- vec.second = state; -- if (nodes.count(vec.first->node_name)) { -- std::shared_ptr tmp = nodes[vec.first->node_name]; -- if (state) { -- tmp->real_cnt++; -- if (tmp->real_cnt == tmp->cnt) { -- tmp->state = true; -- } -- } else { -- tmp->real_cnt--; -- tmp->state = false; -+void DepHandler::update_instance_state(const std::string &name) { -+ if (!nodes[name]->instance->get_state() || !arc_nodes.count(name)) return; -+ std::unordered_set> &arcs = arc_nodes[name]; -+ for (auto &arc_node : arcs) { -+ if (nodes.count(arc_node->node_name)) { -+ auto tmp = nodes[arc_node->node_name]; -+ tmp->real_cnt++; -+ if (tmp->real_cnt == tmp->cnt) { -+ tmp->instance->set_state(true); - } -- change_arc_nodes(vec.first->node_name, state); -+ update_instance_state(tmp->instance->get_name()); - } - } - } - --void DepHandler::query_all_top(std::vector> &query) { -+void DepHandler::query_all_dependencies(std::vector> &query) { - for (auto &p : nodes) { - query_node_top(p.first, query); - } - } - --void DepHandler::query_node_top(std::string name, std::vector> &query) { -+void DepHandler::query_node_top(const std::string &name, std::vector> &query) { - std::shared_ptr p = nodes[name]->head; - if (p->next == nullptr) { - query.emplace_back(std::vector{name}); -@@ -119,7 +124,7 @@ void DepHandler::query_node_top(std::string name, std::vector> &query) { -+void DepHandler::query_node_dependency(const std::string &name, std::vector> &query) { - if (!nodes.count(name)) return; - std::queue q; - std::unordered_set vis; -@@ -128,9 +133,10 @@ void DepHandler::query_node(const std::string &name, std::vector{node->name}); -+ std::string node_name = node->instance->get_name(); -+ query.emplace_back(std::vector{node_name}); - for (auto cur = node->head->next; cur != nullptr; cur = cur->next) { -- query.emplace_back(std::vector{node->name, cur->arc_name}); -+ query.emplace_back(std::vector{node_name, cur->arc_name}); - if (!vis.count(cur->arc_name) && nodes.count(cur->arc_name)) { - vis.insert(cur->arc_name); - q.push(cur->arc_name); -@@ -148,7 +154,7 @@ std::vector DepHandler::get_pre_dependencies(const std::string &nam - while (!q.empty()) { - auto &node = q.front(); - q.pop(); -- res.emplace_back(node->name); -+ res.emplace_back(node->instance->get_name()); - for (auto arc_node = node->head->next; arc_node != nullptr; arc_node = arc_node->next) { - if (!vis.count(arc_node->arc_name)) { - vis.insert(arc_node->arc_name); -diff --git a/src/plugin_mgr/dep_handler.h b/src/plugin_mgr/dep_handler.h -index 40b8748..a7a8ef6 100644 ---- a/src/plugin_mgr/dep_handler.h -+++ b/src/plugin_mgr/dep_handler.h -@@ -12,68 +12,62 @@ - #ifndef PLUGIN_MGR_DEP_HANDLER_H - #define PLUGIN_MGR_DEP_HANDLER_H - -+#include "plugin.h" - #include --#include --#include --#include --#include -+#include - - struct ArcNode { - std::shared_ptr next; - std::string arc_name; - std::string node_name; -- ArcNode() : next(nullptr) {} -+ bool is_exist; -+ ArcNode() : next(nullptr), is_exist(false) { } - }; - - // a instance node - struct Node { - std::shared_ptr next; - std::shared_ptr head; -- std::string name; -+ std::shared_ptr instance; - int cnt; - int real_cnt; -- bool state; // dependency closed-loop -- Node() : next(nullptr), head(nullptr), cnt(0), real_cnt(0), state(true) {} -- Node(const std::string &name): next(nullptr), head(nullptr), name(name), cnt(0), real_cnt(0), state(true) {} -+ Node(): next(nullptr), head(nullptr), cnt(0), real_cnt(0) { } - }; - - class DepHandler { - public: - DepHandler() { - this->head = std::make_shared(); -- this->tail = head; - } - std::shared_ptr get_node(const std::string &name); -- bool get_node_state(std::string name) { -- return this->nodes[name]->state; -+ bool get_node_state(const std::string &name) { -+ return this->nodes[name]->instance->get_state(); - } -- void add_node(const std::string &name, const std::vector &dep_nodes = {}); -- void del_node(const std::string &name); -- std::vector get_pre_dependencies(const std::string &name); -- // query instance dependency -- void query_node(const std::string &name, std::vector> &query); -- // query all instance dependencies -- void query_all_top(std::vector> &query); -+ void add_instance(std::shared_ptr instance); -+ void delete_instance(const std::string &name); -+ bool is_instance_exist(const std::string &name); -+ std::shared_ptr get_instance(const std::string &name) const { -+ return nodes.at(name)->instance; -+ } -+ void query_node_dependency(const std::string &name, std::vector> &query); -+ void query_all_dependencies(std::vector> &query); -+ /* check whether the instance has dependencies */ - bool have_dep(const std::string &name) { - return arc_nodes.count(name); - } -- bool is_empty() const { -- return nodes.empty(); -- } -- size_t get_node_nums() const { -- return nodes.size(); -- } -+ std::vector get_pre_dependencies(const std::string &name); - private: -- void query_node_top(std::string name, std::vector> &query); -+ void add_node(std::shared_ptr instance); -+ void del_node(const std::string &name); -+ void query_node_top(const std::string &name, std::vector> &query); - void add_arc_node(std::shared_ptr node, const std::vector &dep_nodes); -- void change_arc_nodes(std::string name, bool state); -+ void update_instance_state(const std::string &name); - void del_node_and_arc_nodes(std::shared_ptr node); -- std::shared_ptr add_new_node(std::string name); -- -- std::unordered_map, bool>> arc_nodes; -+ std::shared_ptr add_new_node(std::shared_ptr instance); -+ /* indegree edges */ -+ std::unordered_map>> arc_nodes; - std::unordered_map> nodes; - std::shared_ptr head; -- std::shared_ptr tail; - }; - - #endif // !PLUGIN_MGR_DEP_HANDLER_H -diff --git a/src/plugin_mgr/instance_run_handler.cpp b/src/plugin_mgr/instance_run_handler.cpp -index 9eed762..c60207b 100644 ---- a/src/plugin_mgr/instance_run_handler.cpp -+++ b/src/plugin_mgr/instance_run_handler.cpp -@@ -13,7 +13,7 @@ - #include - #include - --static const void* get_ring_buf(std::shared_ptr instance) { -+static const DataRingBuf* get_ring_buf(std::shared_ptr instance) { - if (instance == nullptr) { - return nullptr; - } -@@ -21,14 +21,14 @@ static const void* get_ring_buf(std::shared_ptr instance) { - } - - void InstanceRunHandler::run_instance(std::shared_ptr instance) { -- std::vector input_data; -+ std::vector input_data; - std::vector deps = instance->get_deps(); - for (size_t i = 0; i < deps.size(); ++i) { - std::shared_ptr ins = memory_store.get_instance(deps[i]); - input_data.emplace_back(get_ring_buf(ins)); - } - Param param; -- param.args = input_data.data(); -+ param.ring_bufs = input_data.data(); - param.len = input_data.size(); - instance->get_interface()->run(¶m); - } -@@ -73,7 +73,7 @@ void InstanceRunHandler::schedule(uint64_t time) { - break; - } - run_instance(schedule_instance.instance); -- schedule_instance.time += schedule_instance.instance->get_interface()->get_cycle(); -+ schedule_instance.time += schedule_instance.instance->get_interface()->get_period(); - schedule_queue.push(schedule_instance); - } - } -diff --git a/src/plugin_mgr/instance_run_handler.h b/src/plugin_mgr/instance_run_handler.h -index 4172e99..fc45874 100644 ---- a/src/plugin_mgr/instance_run_handler.h -+++ b/src/plugin_mgr/instance_run_handler.h -@@ -16,19 +16,14 @@ - #include "plugin.h" - #include "logger.h" - #include "memory_store.h" --#include --#include --#include --#include - #include --#include - - enum class RunType { - ENABLED, - DISABLED, - }; - --// Message for communication between plugin manager and instance scheduling -+/* Message for communication between plugin manager and instance scheduling */ - class InstanceRunMessage { - public: - InstanceRunMessage() {} -@@ -53,10 +48,10 @@ public: - uint64_t time; - }; - --// A handler to schedule plugin instance -+/* A handler to schedule instances. */ - class InstanceRunHandler { - public: -- InstanceRunHandler(MemoryStore &memory_store) : memory_store(memory_store), cycle(DEFAULT_CYCLE_SIZE) {} -+ explicit InstanceRunHandler(MemoryStore &memory_store) : memory_store(memory_store), cycle(DEFAULT_CYCLE_SIZE) {} - void run(); - void schedule(uint64_t time); - void handle_instance(uint64_t time); -diff --git a/src/plugin_mgr/interface.h b/src/plugin_mgr/interface.h -index 2106698..6495b92 100644 ---- a/src/plugin_mgr/interface.h -+++ b/src/plugin_mgr/interface.h -@@ -11,6 +11,8 @@ - ******************************************************************************/ - #ifndef PLUGIN_MGR_INTERFACE_H - #define PLUGIN_MGR_INTERFACE_H -+#include -+#include - - enum PluginType { - COLLECTOR, -@@ -18,8 +20,24 @@ enum PluginType { - TUNE, - }; - -+struct DataBuf { -+ int len; -+ void *data; -+}; -+ -+struct DataRingBuf { -+ /* instance name */ -+ const char *instance_name; -+ /* buf write index, initial value is -1 */ -+ int index; -+ /* instance run times */ -+ uint64_t count; -+ struct DataBuf *buf; -+ int buf_len; -+}; -+ - struct Param { -- void *args; -+ const struct DataRingBuf **ring_bufs; - int len; - }; - -@@ -28,12 +46,17 @@ struct Interface { - const char* (*get_name)(); - const char* (*get_description)(); - const char* (*get_dep)(); -- PluginType (*get_type)(); -- int (*get_cycle)(); -+ enum PluginType (*get_type)(); -+ int (*get_period)(); - bool (*enable)(); - void (*disable)(); -- const void* (*get_ring_buf)(); -- void (*run)(const Param*); -+ const struct DataRingBuf* (*get_ring_buf)(); -+ void (*run)(const struct Param*); - }; - -+/* Obtains the instances from the plugin. -+ * The return value is the number of instances. -+ */ -+int get_instance(struct Interface **interface); -+ - #endif // !PLUGIN_MGR_INTERFACE_H -diff --git a/src/plugin_mgr/logger.cpp b/src/plugin_mgr/logger.cpp -index 318eafb..7a924c2 100644 ---- a/src/plugin_mgr/logger.cpp -+++ b/src/plugin_mgr/logger.cpp -@@ -11,7 +11,6 @@ - ******************************************************************************/ - #include "logger.h" - #include --#include - - Logger::Logger() { - logger = log4cplus::Logger::getInstance("oeAware"); -diff --git a/src/plugin_mgr/main.cpp b/src/plugin_mgr/main.cpp -index 4e6acdc..698ba62 100644 ---- a/src/plugin_mgr/main.cpp -+++ b/src/plugin_mgr/main.cpp -@@ -53,7 +53,6 @@ int main(int argc, char **argv) { - INFO("[PluginManager] Start plugin manager!"); - PluginManager plugin_manager(config, handler_msg, res_msg); - plugin_manager.init(); -- plugin_manager.pre_load(); - plugin_manager.run(); - return 0; - } -\ No newline at end of file -diff --git a/src/plugin_mgr/memory_store.h b/src/plugin_mgr/memory_store.h -index ac3ff98..999795a 100644 ---- a/src/plugin_mgr/memory_store.h -+++ b/src/plugin_mgr/memory_store.h -@@ -11,37 +11,36 @@ - ******************************************************************************/ - #ifndef PLUGIN_MGR_MEMORY_STORE_H - #define PLUGIN_MGR_MEMORY_STORE_H --#include "plugin.h" - #include "logger.h" -+#include "dep_handler.h" - #include --#include - --//OeAware memory storage, which is used to store plugins and instances in the memory. -+/* OeAware memory storage, which is used to store plugins and instances in the memory. */ - class MemoryStore { - public: - void add_plugin(const std::string &name, std::shared_ptr plugin) { - this->plugins.insert(std::make_pair(name, plugin)); - } -- void add_instance(const std::string &name, std::shared_ptr instance) { -- this->instances.insert(std::make_pair(name, instance)); -+ void add_instance(std::shared_ptr instance) { -+ dep_handler.add_instance(instance); - } - std::shared_ptr get_plugin(const std::string &name) const { - return this->plugins.at(name); - } - std::shared_ptr get_instance(const std::string &name) const { -- return this->instances.at(name); -+ return dep_handler.get_instance(name); - } - void delete_plugin(const std::string &name) { - this->plugins.erase(name); - } - void delete_instance(const std::string &name) { -- this->instances.erase(name); -+ dep_handler.delete_instance(name); - } - bool is_plugin_exist(const std::string &name) const { - return this->plugins.count(name); - } -- bool is_instance_exist(const std::string &name) const { -- return this->instances.count(name); -+ bool is_instance_exist(const std::string &name) { -+ return dep_handler.is_instance_exist(name); - } - std::vector> get_all_plugins() { - std::vector> res; -@@ -50,16 +49,24 @@ public: - } - return res; - } -- std::vector> get_all_instances() { -- std::vector> res; -- for (auto &p : instances) { -- res.emplace_back(p.second); -- } -- return res; -+ void query_node_dependency(const std::string &name, std::vector> &query) { -+ return dep_handler.query_node_dependency(name, query); -+ } -+ void query_all_dependencies(std::vector> &query) { -+ return dep_handler.query_all_dependencies(query); -+ } -+ bool have_dep(const std::string &name) { -+ return dep_handler.have_dep(name); -+ } -+ std::vector get_pre_dependencies(const std::string &name) { -+ return dep_handler.get_pre_dependencies(name); - } - private: -+ /* instance are stored in the form of DAG. -+ * DepHandler stores instances and manages dependencies. -+ */ -+ DepHandler dep_handler; - std::unordered_map> plugins; -- std::unordered_map> instances; - }; - - #endif // !PLUGIN_MGR_MEMORY_STORE_H -diff --git a/src/plugin_mgr/message_manager.h b/src/plugin_mgr/message_manager.h -index 00ea4c7..95bbd1a 100644 ---- a/src/plugin_mgr/message_manager.h -+++ b/src/plugin_mgr/message_manager.h -@@ -29,7 +29,7 @@ enum class MessageType { - class Message { - public: - Message() : type(MessageType::EXTERNAL) {} -- Message(Opt opt) : opt(opt) {} -+ explicit Message(Opt opt) : opt(opt) {} - Message(Opt opt, MessageType type) : opt(opt), type(type) {} - Message(Opt opt, const std::vector &payload) : opt(opt), payload(payload) {} - Opt get_opt() { -@@ -79,6 +79,7 @@ public: - MessageManager(SafeQueue *handler_msg, SafeQueue *res_msg) { - this->handler_msg = handler_msg; - this->res_msg = res_msg; -+ this->tcp_socket = nullptr; - } - void init(){ - this->tcp_socket = new TcpSocket(); -diff --git a/src/plugin_mgr/plugin.cpp b/src/plugin_mgr/plugin.cpp -index bdd8226..4096fef 100644 ---- a/src/plugin_mgr/plugin.cpp -+++ b/src/plugin_mgr/plugin.cpp -@@ -33,7 +33,7 @@ std::string Instance::get_info() const { - - std::vector Instance::get_deps() { - std::vector vec; -- if (get_interface()->get_dep == nullptr) { -+ if (get_interface()->get_dep == nullptr || get_interface()->get_dep() == nullptr) { - return vec; - } - std::string deps = get_interface()->get_dep(); -diff --git a/src/plugin_mgr/plugin.h b/src/plugin_mgr/plugin.h -index ac0e0b5..f6b5029 100644 ---- a/src/plugin_mgr/plugin.h -+++ b/src/plugin_mgr/plugin.h -@@ -68,7 +68,7 @@ private: - - class Plugin { - public: -- Plugin(const std::string &name) : name(name), handler(nullptr) { } -+ explicit Plugin(const std::string &name) : name(name), handler(nullptr) { } - ~Plugin() { - if (handler != nullptr) { - dlclose(handler); -diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp -index 1503fc1..7900ecf 100644 ---- a/src/plugin_mgr/plugin_manager.cpp -+++ b/src/plugin_mgr/plugin_manager.cpp -@@ -11,21 +11,13 @@ - ******************************************************************************/ - #include "plugin_manager.h" - #include "default_path.h" --#include "utils.h" --#include --#include - #include --#include - --const std::string PluginManager::COLLECTOR_TEXT = "collector"; --const std::string PluginManager::SCENARIO_TEXT = "scenario"; --const std::string PluginManager::TUNE_TEXT = "tune"; - const static int ST_MODE_MASK = 0777; - - void PluginManager::init() { -- plugin_types[COLLECTOR_TEXT] = PluginType::COLLECTOR; -- plugin_types[SCENARIO_TEXT] = PluginType::SCENARIO; -- plugin_types[TUNE_TEXT] = PluginType::TUNE; -+ instance_run_handler.reset(new InstanceRunHandler(memory_store)); -+ pre_load(); - } - - ErrorCode PluginManager::remove(const std::string &name) { -@@ -40,19 +32,18 @@ ErrorCode PluginManager::remove(const std::string &name) { - if (instance->get_enabled()) { - return ErrorCode::REMOVE_INSTANCE_IS_RUNNING; - } -- if (dep_handler.have_dep(iname)) { -+ if (memory_store.have_dep(iname)) { - return ErrorCode::REMOVE_INSTANCE_HAVE_DEP; - } - instance_names.emplace_back(iname); - } - for(auto &iname : instance_names) { - memory_store.delete_instance(iname); -- dep_handler.del_node(iname); - } - memory_store.delete_plugin(name); -- update_instance_state(); - return ErrorCode::OK; - } -+ - ErrorCode PluginManager::query_all_plugins(std::string &res) { - std::vector> all_plugins = memory_store.get_all_plugins(); - for (auto &p : all_plugins) { -@@ -99,10 +90,8 @@ void PluginManager::save_instance(std::shared_ptr plugin, Interface *int - instance->set_name(name); - instance->set_plugin_name(plugin->get_name()); - instance->set_enabled(false); -- dep_handler.add_node(name, instance->get_deps()); -- instance->set_state(dep_handler.get_node_state(name)); - DEBUG("[PluginManager] Instance: " << name.c_str()); -- memory_store.add_instance(name, instance); -+ memory_store.add_instance(instance); - plugin->add_instance(instance); - } - } -@@ -116,21 +105,9 @@ bool PluginManager::load_instance(std::shared_ptr plugin) { - return false; - } - save_instance(plugin, interface_list, len); -- update_instance_state(); - return true; - } - --void PluginManager::update_instance_state() { -- std::vector> all_instances = memory_store.get_all_instances(); -- for (auto &instance : all_instances) { -- if (dep_handler.get_node_state(instance->get_name())) { -- instance->set_state(true); -- } else { -- instance->set_state(false); -- } -- } --} -- - ErrorCode PluginManager::load_plugin(const std::string &name) { - std::string plugin_path = get_path() + "/" + name; - if (!file_exist(plugin_path)) { -@@ -160,6 +137,8 @@ ErrorCode PluginManager::load_plugin(const std::string &name) { - std::string generate_dot(MemoryStore &memory_store, const std::vector> &query) { - std::string res; - res += "digraph G {\n"; -+ res += " rankdir = TB\n"; -+ res += " ranksep = 1\n"; - std::unordered_map> sub_graph; - for (auto &vec : query) { - std::shared_ptr instance = memory_store.get_instance(vec[0]); -@@ -171,45 +150,45 @@ std::string generate_dot(MemoryStore &memory_store, const std::vectorget_plugin_name()].insert(vec[1]); - } else { -- res += vec[1] + "[label=\"(missing)\\n" + vec[1] + "\", fontcolor=red];\n"; -+ res += " " + vec[1] + "[label=\"(missing)\\n" + vec[1] + "\", fontcolor=red];\n"; - } -- res += vec[0] + "->" + vec[1] + ";\n"; -+ res += " " + vec[0] + "->" + vec[1] + ";\n"; - } - int id = 0; - for (auto &p : sub_graph) { -- res += "subgraph cluster_" + std::to_string(id) + " {\n"; -- res += "node [style=filled];\n"; -- res += "label = \"" + p.first + "\";\n"; -+ res += " subgraph cluster_" + std::to_string(id) + " {\n"; -+ res += " node [style=filled];\n"; -+ res += " label = \"" + p.first + "\";\n"; - for (auto &i_name : p.second) { -- res += i_name + ";\n"; -+ res += " " + i_name + ";\n"; - } -- res += "}\n"; -+ res += " }\n"; - id++; - } - res += "}"; - return res; - } - --ErrorCode PluginManager::query_top(const std::string &name, std::string &res) { -+ErrorCode PluginManager::query_dependency(const std::string &name, std::string &res) { - if (!memory_store.is_instance_exist(name)) { - return ErrorCode::QUERY_DEP_NOT_EXIST; - } - DEBUG("[PluginManager] query top : " << name); - std::vector> query; -- dep_handler.query_node(name, query); -+ memory_store.query_node_dependency(name, query); - res = generate_dot(memory_store, query); - return ErrorCode::OK; - } - --ErrorCode PluginManager::query_all_tops(std::string &res) { -+ErrorCode PluginManager::query_all_dependencies(std::string &res) { - std::vector> query; -- dep_handler.query_all_top(query); -+ memory_store.query_all_dependencies(query); - DEBUG("[PluginManager] query size:" << query.size()); - res = generate_dot(memory_store, query); - return ErrorCode::OK; - } - --ErrorCode PluginManager::instance_enabled(std::string name) { -+ErrorCode PluginManager::instance_enabled(const std::string &name) { - if (!memory_store.is_instance_exist(name)) { - return ErrorCode::ENABLE_INSTANCE_NOT_LOAD; - } -@@ -220,7 +199,7 @@ ErrorCode PluginManager::instance_enabled(std::string name) { - if (instance->get_enabled()) { - return ErrorCode::ENABLE_INSTANCE_ALREADY_ENABLED; - } -- std::vector pre_dependencies = dep_handler.get_pre_dependencies(name); -+ std::vector pre_dependencies = memory_store.get_pre_dependencies(name); - std::vector> new_enabled; - bool enabled = true; - for (int i = pre_dependencies.size() - 1; i >= 0; --i) { -@@ -252,7 +231,7 @@ ErrorCode PluginManager::instance_enabled(std::string name) { - } - } - --ErrorCode PluginManager::instance_disabled(std::string name) { -+ErrorCode PluginManager::instance_disabled(const std::string &name) { - if (!memory_store.is_instance_exist(name)) { - return ErrorCode::DISABLE_INSTANCE_NOT_LOAD; - } -@@ -364,7 +343,7 @@ void PluginManager::pre_load() { - pre_enable(); - } - --const void* PluginManager::get_data_buffer(std::string name) { -+const void* PluginManager::get_data_buffer(const std::string &name) { - std::shared_ptr instance = memory_store.get_instance(name); - return instance->get_interface()->get_ring_buf(); - } -@@ -375,7 +354,7 @@ std::string PluginManager::instance_dep_check(const std::string &name) { - for (size_t i = 0; i < plugin->get_instance_len(); ++i) { - std::string instance_name = plugin->get_instance(i)->get_name(); - std::vector> query; -- dep_handler.query_node(instance_name, query); -+ memory_store.query_node_dependency(instance_name, query); - std::vector lack; - for (auto &item : query) { - if (item.size() < 2) continue; -@@ -478,10 +457,10 @@ int PluginManager::run() { - } - break; - } -- case Opt::QUERY_TOP: { -+ case Opt::QUERY_DEP: { - std::string res_text; - std::string name = msg.get_payload(0); -- ErrorCode ret_code = query_top(name , res_text); -+ ErrorCode ret_code = query_dependency(name , res_text); - if (ret_code == ErrorCode::OK) { - INFO("[PluginManager] query " << name << " instance dependencies."); - res.set_opt(Opt::RESPONSE_OK); -@@ -494,9 +473,9 @@ int PluginManager::run() { - } - break; - } -- case Opt::QUERY_ALL_TOP: { -+ case Opt::QUERY_ALL_DEPS: { - std::string res_text; -- ErrorCode ret_code = query_all_tops(res_text); -+ ErrorCode ret_code = query_all_dependencies(res_text); - if (ret_code == ErrorCode::OK) { - INFO("[PluginManager] query all instances dependencies."); - res.set_opt(Opt::RESPONSE_OK); -diff --git a/src/plugin_mgr/plugin_manager.h b/src/plugin_mgr/plugin_manager.h -index 9339f0d..18d3f35 100644 ---- a/src/plugin_mgr/plugin_manager.h -+++ b/src/plugin_mgr/plugin_manager.h -@@ -15,35 +15,28 @@ - #include "instance_run_handler.h" - #include "config.h" - #include "memory_store.h" --#include "dep_handler.h" - #include "message_manager.h" - #include "error_code.h" --#include --#include --#include --#include - - class PluginManager { - public: - PluginManager(Config &config, SafeQueue &handler_msg, SafeQueue &res_msg) : -- config(config), handler_msg(handler_msg), res_msg(res_msg) { -- instance_run_handler.reset(new InstanceRunHandler(memory_store)); -- } -+ config(config), handler_msg(handler_msg), res_msg(res_msg) { } - int run(); -- void pre_load(); -- void pre_enable(); - void init(); -- const void* get_data_buffer(std::string name); -+ const void* get_data_buffer(const std::string &name); - private: -+ void pre_load(); -+ void pre_enable(); - void pre_load_plugin(); - ErrorCode load_plugin(const std::string &path); - ErrorCode remove(const std::string &name); - ErrorCode query_all_plugins(std::string &res); - ErrorCode query_plugin(const std::string &name, std::string &res); -- ErrorCode query_top(const std::string &name, std::string &res); -- ErrorCode query_all_tops(std::string &res); -- ErrorCode instance_enabled(std::string name); -- ErrorCode instance_disabled(std::string name); -+ ErrorCode query_dependency(const std::string &name, std::string &res); -+ ErrorCode query_all_dependencies(std::string &res); -+ ErrorCode instance_enabled(const std::string &name); -+ ErrorCode instance_disabled(const std::string &name); - ErrorCode add_list(std::string &res); - ErrorCode download(const std::string &name, std::string &res); - std::string instance_dep_check(const std::string &name); -@@ -61,13 +54,9 @@ private: - SafeQueue &handler_msg; - SafeQueue &res_msg; - MemoryStore memory_store; -- DepHandler dep_handler; -- std::unordered_map plugin_types; -- static const std::string COLLECTOR_TEXT; -- static const std::string SCENARIO_TEXT; -- static const std::string TUNE_TEXT; - }; - - bool check_permission(std::string path, int mode); - bool file_exist(const std::string &file_name); -+ - #endif --- -2.33.0 - diff --git a/0004-modify-some-interfaces-and-add-interface-comments.patch b/0004-modify-some-interfaces-and-add-interface-comments.patch deleted file mode 100644 index ecb93dd..0000000 --- a/0004-modify-some-interfaces-and-add-interface-comments.patch +++ /dev/null @@ -1,121 +0,0 @@ -From 0758b61d2e9af546d3c55bc9cb3704cd7a4fe59a Mon Sep 17 00:00:00 2001 -From: fly_1997 -Date: Tue, 28 May 2024 20:00:07 +0800 -Subject: [PATCH 3/4] modify some interfaces and add interface comments - ---- - src/plugin_mgr/instance_run_handler.cpp | 1 + - src/plugin_mgr/instance_run_handler.h | 10 +++------- - src/plugin_mgr/interface.h | 17 ++++++++++------- - src/plugin_mgr/plugin.h | 4 ++-- - 4 files changed, 16 insertions(+), 16 deletions(-) - -diff --git a/src/plugin_mgr/instance_run_handler.cpp b/src/plugin_mgr/instance_run_handler.cpp -index c60207b..fc9dc04 100644 ---- a/src/plugin_mgr/instance_run_handler.cpp -+++ b/src/plugin_mgr/instance_run_handler.cpp -@@ -34,6 +34,7 @@ void InstanceRunHandler::run_instance(std::shared_ptr instance) { - } - - void InstanceRunHandler::insert_instance(std::shared_ptr instance, uint64_t time) { -+ /* To check if an instance is enabled, enable() is called in the PluginManager. */ - instance->set_enabled(true); - schedule_queue.push(ScheduleInstance{instance, time}); - INFO("[PluginManager] " << instance->get_name() << " instance insert into running queue."); -diff --git a/src/plugin_mgr/instance_run_handler.h b/src/plugin_mgr/instance_run_handler.h -index fc45874..f0bf263 100644 ---- a/src/plugin_mgr/instance_run_handler.h -+++ b/src/plugin_mgr/instance_run_handler.h -@@ -42,7 +42,7 @@ private: - class ScheduleInstance { - public: - bool operator < (const ScheduleInstance &rhs) const { -- return time > rhs.time || (time == rhs.time && instance->get_type() > rhs.instance->get_type()); -+ return time > rhs.time || (time == rhs.time && instance->get_priority() > rhs.instance->get_priority()); - } - std::shared_ptr instance; - uint64_t time; -@@ -61,9 +61,6 @@ public: - int get_cycle() { - return cycle; - } -- bool is_instance_exist(const std::string &name) { -- return memory_store.is_instance_exist(name); -- } - void recv_queue_push(InstanceRunMessage &msg) { - this->recv_queue.push(msg); - } -@@ -77,15 +74,14 @@ private: - void run_instance(std::shared_ptr instance); - void delete_instance(std::shared_ptr instance); - void insert_instance(std::shared_ptr instance, uint64_t time); -- void adjust_collector_queue(const std::vector &deps, const std::vector &m_deps, bool flag); -- void check_scenario_dependency(const std::vector &deps, const std::vector &m_deps); - -+ /* Instance execution queue. */ - std::priority_queue schedule_queue; -+ /*Receives messages from the PluginManager. */ - SafeQueue recv_queue; - MemoryStore &memory_store; - int cycle; - static const int DEFAULT_CYCLE_SIZE = 10; -- static const int MAX_DEPENDENCIES_SIZE = 20; - }; - - #endif // !PLUGIN_MGR_INSTANCE_RUN_HANDLER_H -diff --git a/src/plugin_mgr/interface.h b/src/plugin_mgr/interface.h -index 6495b92..8aa6933 100644 ---- a/src/plugin_mgr/interface.h -+++ b/src/plugin_mgr/interface.h -@@ -14,12 +14,6 @@ - #include - #include - --enum PluginType { -- COLLECTOR, -- SCENARIO, -- TUNE, --}; -- - struct DataBuf { - int len; - void *data; -@@ -43,10 +37,19 @@ struct Param { - - struct Interface { - const char* (*get_version)(); -+ /* The instance name is a unique identifier in the system. */ - const char* (*get_name)(); - const char* (*get_description)(); -+ /* Specifies the instance dependencies, which is used as the input information -+ * for instance execution. -+ */ - const char* (*get_dep)(); -- enum PluginType (*get_type)(); -+ /* Instance scheduling priority. In a uniform time period, a instance with a -+ * lower priority is scheduled first. -+ */ -+ int (*get_priority)(); -+ int (*get_type)(); -+ /* Instance execution period. */ - int (*get_period)(); - bool (*enable)(); - void (*disable)(); -diff --git a/src/plugin_mgr/plugin.h b/src/plugin_mgr/plugin.h -index f6b5029..7415b99 100644 ---- a/src/plugin_mgr/plugin.h -+++ b/src/plugin_mgr/plugin.h -@@ -25,8 +25,8 @@ public: - std::string get_name() const { - return this->name; - } -- PluginType get_type() const { -- return interface->get_type(); -+ int get_priority() const { -+ return interface->get_priority(); - } - Interface* get_interface() const { - return this->interface; --- -2.33.0 - diff --git a/0005-add-the-SIGINT-signal-processing-and-singleton-class.patch b/0005-add-the-SIGINT-signal-processing-and-singleton-class.patch deleted file mode 100644 index 551ba6f..0000000 --- a/0005-add-the-SIGINT-signal-processing-and-singleton-class.patch +++ /dev/null @@ -1,401 +0,0 @@ -From 6b8debf93307ee68f2ecd4b0bf5ac2d01ee278b8 Mon Sep 17 00:00:00 2001 -From: fly_1997 -Date: Wed, 29 May 2024 15:12:31 +0800 -Subject: [PATCH 4/4] add the SIGINT signal processing and singleton classes - ---- - src/plugin_mgr/instance_run_handler.cpp | 1 - - src/plugin_mgr/logger.cpp | 2 +- - src/plugin_mgr/logger.h | 3 +- - src/plugin_mgr/main.cpp | 37 +++++++++++++++++++------ - src/plugin_mgr/memory_store.h | 2 +- - src/plugin_mgr/message_manager.cpp | 22 ++++++++++----- - src/plugin_mgr/message_manager.h | 32 +++++++++++---------- - src/plugin_mgr/plugin.h | 2 +- - src/plugin_mgr/plugin_manager.cpp | 26 ++++++++++------- - src/plugin_mgr/plugin_manager.h | 21 ++++++++++---- - 10 files changed, 97 insertions(+), 51 deletions(-) - -diff --git a/src/plugin_mgr/instance_run_handler.cpp b/src/plugin_mgr/instance_run_handler.cpp -index fc9dc04..ecd7778 100644 ---- a/src/plugin_mgr/instance_run_handler.cpp -+++ b/src/plugin_mgr/instance_run_handler.cpp -@@ -35,7 +35,6 @@ void InstanceRunHandler::run_instance(std::shared_ptr instance) { - - void InstanceRunHandler::insert_instance(std::shared_ptr instance, uint64_t time) { - /* To check if an instance is enabled, enable() is called in the PluginManager. */ -- instance->set_enabled(true); - schedule_queue.push(ScheduleInstance{instance, time}); - INFO("[PluginManager] " << instance->get_name() << " instance insert into running queue."); - } -diff --git a/src/plugin_mgr/logger.cpp b/src/plugin_mgr/logger.cpp -index 7a924c2..af39583 100644 ---- a/src/plugin_mgr/logger.cpp -+++ b/src/plugin_mgr/logger.cpp -@@ -26,7 +26,7 @@ Logger::Logger() { - logger.addAppender(appender); - } - --void Logger::init(Config *config) { -+void Logger::init(std::shared_ptr config) { - log4cplus::SharedAppenderPtr appender(new log4cplus::FileAppender(config->get_log_path() + "/server.log")); - appender->setName("file"); - log4cplus::tstring pattern = LOG4CPLUS_TEXT("%D{%m/%d/%y %H:%M:%S} [%t] %-5p %c - %m" -diff --git a/src/plugin_mgr/logger.h b/src/plugin_mgr/logger.h -index e86dd72..a219c86 100644 ---- a/src/plugin_mgr/logger.h -+++ b/src/plugin_mgr/logger.h -@@ -13,6 +13,7 @@ - #define PLUGIN_MGR_LOGGER_H - - #include "config.h" -+#include - #include - - #define INFO(fmt) LOG4CPLUS_INFO(logger.get(), fmt) -@@ -24,7 +25,7 @@ - class Logger { - public: - Logger(); -- void init(Config *config); -+ void init(std::shared_ptr config); - log4cplus::Logger get() { - return logger; - } -diff --git a/src/plugin_mgr/main.cpp b/src/plugin_mgr/main.cpp -index 698ba62..5cfb020 100644 ---- a/src/plugin_mgr/main.cpp -+++ b/src/plugin_mgr/main.cpp -@@ -10,6 +10,7 @@ - * See the Mulan PSL v2 for more details. - ******************************************************************************/ - #include "plugin_manager.h" -+#include - - Logger logger; - -@@ -20,8 +21,26 @@ void print_help() { - " ./oeaware /etc/oeAware/config.yaml\n"); - } - -+void signal_handler(int signum) { -+ auto &plugin_manager = PluginManager::get_instance(); -+ auto memory_store = plugin_manager.get_memory_store(); -+ auto all_plugins = memory_store.get_all_plugins(); -+ for (auto plugin : all_plugins) { -+ for (size_t i = 0; i < plugin->get_instance_len(); ++i) { -+ auto instance = plugin->get_instance(i); -+ if (!instance->get_enabled()) { -+ continue; -+ } -+ instance->get_interface()->disable(); -+ INFO("[PluginManager] " << instance->get_name() << " instance disabled."); -+ } -+ } -+ exit(signum); -+} -+ - int main(int argc, char **argv) { -- Config config; -+ signal(SIGINT, signal_handler); -+ std::shared_ptr config = std::make_shared(); - if (argc < 2) { - ERROR("System need a argument!"); - exit(EXIT_FAILURE); -@@ -39,20 +58,20 @@ int main(int argc, char **argv) { - ERROR("Insufficient permission on " << config_path); - exit(EXIT_FAILURE); - } -- if (!config.load(config_path)) { -+ if (!config->load(config_path)) { - ERROR("Config load error!"); - exit(EXIT_FAILURE); - } -- logger.init(&config); -- SafeQueue handler_msg; -- SafeQueue res_msg; -+ logger.init(config); -+ std::shared_ptr> handler_msg = std::make_shared>(); -+ std::shared_ptr> res_msg = std::make_shared>(); - INFO("[MessageManager] Start message manager!"); -- MessageManager message_manager(&handler_msg, &res_msg); -- message_manager.init(); -+ MessageManager &message_manager = MessageManager::get_instance(); -+ message_manager.init(handler_msg, res_msg); - message_manager.run(); - INFO("[PluginManager] Start plugin manager!"); -- PluginManager plugin_manager(config, handler_msg, res_msg); -- plugin_manager.init(); -+ PluginManager& plugin_manager = PluginManager::get_instance(); -+ plugin_manager.init(config, handler_msg, res_msg); - plugin_manager.run(); - return 0; - } -\ No newline at end of file -diff --git a/src/plugin_mgr/memory_store.h b/src/plugin_mgr/memory_store.h -index 999795a..0e862db 100644 ---- a/src/plugin_mgr/memory_store.h -+++ b/src/plugin_mgr/memory_store.h -@@ -42,7 +42,7 @@ public: - bool is_instance_exist(const std::string &name) { - return dep_handler.is_instance_exist(name); - } -- std::vector> get_all_plugins() { -+ const std::vector> get_all_plugins() { - std::vector> res; - for (auto &p : plugins) { - res.emplace_back(p.second); -diff --git a/src/plugin_mgr/message_manager.cpp b/src/plugin_mgr/message_manager.cpp -index 815122c..a9f862d 100644 ---- a/src/plugin_mgr/message_manager.cpp -+++ b/src/plugin_mgr/message_manager.cpp -@@ -57,7 +57,7 @@ bool TcpSocket::init() { - return true; - - } --static void send_msg(Msg &msg, SafeQueue *handler_msg) { -+static void send_msg(Msg &msg, std::shared_ptr> handler_msg) { - Message message; - message.set_opt(msg.opt()); - message.set_type(MessageType::EXTERNAL); -@@ -66,7 +66,7 @@ static void send_msg(Msg &msg, SafeQueue *handler_msg) { - } - handler_msg->push(message); - } --static void recv_msg(Msg &msg, SafeQueue *res_msg) { -+static void recv_msg(Msg &msg, std::shared_ptr> res_msg) { - Message res; - res_msg->wait_and_pop(res); - msg.set_opt(res.get_opt()); -@@ -75,7 +75,7 @@ static void recv_msg(Msg &msg, SafeQueue *res_msg) { - } - } - --void TcpSocket::serve_accept(SafeQueue *handler_msg, SafeQueue *res_msg){ -+void TcpSocket::serve_accept(std::shared_ptr> handler_msg, std::shared_ptr> res_msg){ - struct epoll_event evs[MAX_EVENT_SIZE]; - int sz = sizeof(evs) / sizeof(struct epoll_event); - while (true) { -@@ -112,12 +112,20 @@ void TcpSocket::serve_accept(SafeQueue *handler_msg, SafeQueue - } - } - --void handler(MessageManager *mgr) { -- TcpSocket* tcp_socket = mgr->tcp_socket; -- if (!tcp_socket->init()) { -+void MessageManager::tcp_start() { -+ if (!tcp_socket.init()) { - return; - } -- tcp_socket->serve_accept(mgr->handler_msg, mgr->res_msg); -+ tcp_socket.serve_accept(handler_msg, res_msg); -+} -+ -+static void handler(MessageManager *mgr) { -+ mgr->tcp_start(); -+} -+ -+void MessageManager::init(std::shared_ptr> handler_msg, std::shared_ptr> res_msg) { -+ this->handler_msg = handler_msg; -+ this->res_msg = res_msg; - } - - void MessageManager::run() { -diff --git a/src/plugin_mgr/message_manager.h b/src/plugin_mgr/message_manager.h -index 95bbd1a..f5240aa 100644 ---- a/src/plugin_mgr/message_manager.h -+++ b/src/plugin_mgr/message_manager.h -@@ -61,34 +61,38 @@ private: - - class TcpSocket { - public: -- TcpSocket() {} -+ TcpSocket() : sock(-1), epfd(-1) { } - ~TcpSocket() { - close(sock); - } - bool init(); -- void serve_accept(SafeQueue *handler_msg, SafeQueue *res_msg); -+ void serve_accept(std::shared_ptr> handler_msg, std::shared_ptr> res_msg); - private: - int domain_listen(const char *name); -- -+private: - int sock; - int epfd; - }; - - class MessageManager { - public: -- MessageManager(SafeQueue *handler_msg, SafeQueue *res_msg) { -- this->handler_msg = handler_msg; -- this->res_msg = res_msg; -- this->tcp_socket = nullptr; -- } -- void init(){ -- this->tcp_socket = new TcpSocket(); -+ MessageManager(const MessageManager&) = delete; -+ MessageManager& operator=(const MessageManager&) = delete; -+ static MessageManager& get_instance() { -+ static MessageManager message_manager; -+ return message_manager; - } -+ void init(std::shared_ptr> handler_msg, std::shared_ptr> res_msg); -+ void tcp_start(); - void run(); -- -- SafeQueue *handler_msg; -- SafeQueue *res_msg; -- TcpSocket *tcp_socket; -+private: -+ MessageManager() { } -+private: -+ /* Message queue stores messages from the client and is consumed by PluginManager. */ -+ std::shared_ptr> handler_msg; -+ /* Message queue stores messages from PluginManager and is consumed by TcpSocket. */ -+ std::shared_ptr> res_msg; -+ TcpSocket tcp_socket; - }; - - #endif // !PLUGIN_MGR_MESSAGE_MANAGER_H -\ No newline at end of file -diff --git a/src/plugin_mgr/plugin.h b/src/plugin_mgr/plugin.h -index 7415b99..a011261 100644 ---- a/src/plugin_mgr/plugin.h -+++ b/src/plugin_mgr/plugin.h -@@ -81,7 +81,7 @@ public: - void add_instance(std::shared_ptr ins) { - instances.emplace_back(ins); - } -- std::shared_ptr get_instance(int i) const { -+ std::shared_ptr get_instance(size_t i) const { - return instances[i]; - } - size_t get_instance_len() const { -diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp -index 7900ecf..4c5f5fc 100644 ---- a/src/plugin_mgr/plugin_manager.cpp -+++ b/src/plugin_mgr/plugin_manager.cpp -@@ -15,7 +15,12 @@ - - const static int ST_MODE_MASK = 0777; - --void PluginManager::init() { -+ -+void PluginManager::init(std::shared_ptr config, std::shared_ptr> handler_msg, -+ std::shared_ptr> res_msg) { -+ this->config = config; -+ this->handler_msg = handler_msg; -+ this->res_msg = res_msg; - instance_run_handler.reset(new InstanceRunHandler(memory_store)); - pre_load(); - } -@@ -220,12 +225,13 @@ ErrorCode PluginManager::instance_enabled(const std::string &name) { - if (instance->get_enabled()) { - continue; - } -+ instance->set_enabled(true); - instance_run_handler->recv_queue_push(InstanceRunMessage(RunType::ENABLED, instance)); - } - return ErrorCode::OK; - } else { -- for (auto instance : new_enabled) { -- instance->get_interface()->disable(); -+ for (auto ins : new_enabled) { -+ ins->get_interface()->disable(); - } - return ErrorCode::ENABLE_INSTANCE_ENV; - } -@@ -275,7 +281,7 @@ std::string PluginManager::get_plugin_in_dir(const std::string &path) { - } - - ErrorCode PluginManager::add_list(std::string &res) { -- auto plugin_list = config.get_plugin_list(); -+ auto plugin_list = config->get_plugin_list(); - res += "Supported Packages:\n"; - for (auto &p : plugin_list) { - res += p.first + "\n"; -@@ -286,16 +292,16 @@ ErrorCode PluginManager::add_list(std::string &res) { - } - - ErrorCode PluginManager::download(const std::string &name, std::string &res) { -- if (!config.is_plugin_info_exist(name)) { -+ if (!config->is_plugin_info_exist(name)) { - return ErrorCode::DOWNLOAD_NOT_FOUND; - } -- res += config.get_plugin_info(name).get_url(); -+ res += config->get_plugin_info(name).get_url(); - return ErrorCode::OK; - } - - void PluginManager::pre_enable() { -- for (size_t i = 0; i < config.get_enable_list_size(); ++i) { -- EnableItem item = config.get_enable_list(i); -+ for (size_t i = 0; i < config->get_enable_list_size(); ++i) { -+ EnableItem item = config->get_enable_list(i); - if (item.get_enabled()) { - std::string name = item.get_name(); - if (!memory_store.is_plugin_exist(name)) { -@@ -394,7 +400,7 @@ int PluginManager::run() { - while (true) { - Message msg; - Message res; -- this->handler_msg.wait_and_pop(msg); -+ this->handler_msg->wait_and_pop(msg); - if (msg.get_opt() == Opt::SHUTDOWN) break; - switch (msg.get_opt()) { - case Opt::LOAD: { -@@ -557,7 +563,7 @@ int PluginManager::run() { - break; - } - if (msg.get_type() == MessageType::EXTERNAL) -- res_msg.push(res); -+ res_msg->push(res); - } - return 0; - } -diff --git a/src/plugin_mgr/plugin_manager.h b/src/plugin_mgr/plugin_manager.h -index 18d3f35..b7c04fe 100644 ---- a/src/plugin_mgr/plugin_manager.h -+++ b/src/plugin_mgr/plugin_manager.h -@@ -20,12 +20,21 @@ - - class PluginManager { - public: -- PluginManager(Config &config, SafeQueue &handler_msg, SafeQueue &res_msg) : -- config(config), handler_msg(handler_msg), res_msg(res_msg) { } -+ PluginManager(const PluginManager&) = delete; -+ PluginManager& operator=(const PluginManager&) = delete; -+ static PluginManager& get_instance() { -+ static PluginManager plugin_manager; -+ return plugin_manager; -+ } - int run(); -- void init(); -+ void init(std::shared_ptr config, std::shared_ptr> handler_msg, -+ std::shared_ptr> res_msg); -+ const MemoryStore& get_memory_store() { -+ return this->memory_store; -+ } - const void* get_data_buffer(const std::string &name); - private: -+ PluginManager() { } - void pre_load(); - void pre_enable(); - void pre_load_plugin(); -@@ -50,9 +59,9 @@ private: - std::string get_plugin_in_dir(const std::string &path); - private: - std::unique_ptr instance_run_handler; -- Config &config; -- SafeQueue &handler_msg; -- SafeQueue &res_msg; -+ std::shared_ptr config; -+ std::shared_ptr> handler_msg; -+ std::shared_ptr> res_msg; - MemoryStore memory_store; - }; - --- -2.33.0 - diff --git a/0006-add-dynamic-dependencncy-adjustment.patch b/0006-add-dynamic-dependencncy-adjustment.patch deleted file mode 100644 index df86a90..0000000 --- a/0006-add-dynamic-dependencncy-adjustment.patch +++ /dev/null @@ -1,682 +0,0 @@ -From 40bb095943d23c0bf271c633fc7ec6379925762a Mon Sep 17 00:00:00 2001 -From: fly_1997 -Date: Wed, 5 Jun 2024 11:08:32 +0800 -Subject: [PATCH] add dynamic dependencncy adjustment - ---- - src/plugin_mgr/dep_handler.cpp | 108 ++++++++-------- - src/plugin_mgr/dep_handler.h | 37 ++++-- - src/plugin_mgr/instance_run_handler.cpp | 156 ++++++++++++++++++++---- - src/plugin_mgr/instance_run_handler.h | 48 +++++--- - src/plugin_mgr/interface.h | 4 +- - src/plugin_mgr/memory_store.h | 10 +- - src/plugin_mgr/plugin_manager.cpp | 41 ++----- - 7 files changed, 270 insertions(+), 134 deletions(-) - -diff --git a/src/plugin_mgr/dep_handler.cpp b/src/plugin_mgr/dep_handler.cpp -index 1006175..227ee2f 100644 ---- a/src/plugin_mgr/dep_handler.cpp -+++ b/src/plugin_mgr/dep_handler.cpp -@@ -29,25 +29,47 @@ void DepHandler::add_arc_node(std::shared_ptr node, const std::vectorcnt = dep_nodes.size(); - int real_cnt = 0; - for (auto name : dep_nodes) { -- std::shared_ptr tmp = std::make_shared(); -- tmp->arc_name = name; -- tmp->node_name = node->instance->get_name(); -+ std::string from = node->instance->get_name(); -+ std::shared_ptr tmp = std::make_shared(from, name); - tmp->next = arc_head->next; - arc_head->next = tmp; - - if (nodes.count(name)) { - tmp->is_exist = true; -- arc_nodes[name].insert(tmp); -+ tmp->init = true; - real_cnt++; -- } else { -- tmp->is_exist = false; -- arc_nodes[name].insert(tmp); - } -+ in_edges[name].insert(from); -+ arc_nodes[std::make_pair(from, name)] = tmp; - } - if (real_cnt == node->cnt) { - node->instance->set_state(true); - } - node->real_cnt = real_cnt; -+} -+ -+void DepHandler::add_edge(const std::string &from, const std::string &to) { -+ if (in_edges[to].find(from) != in_edges[to].end()) { -+ auto arc_node = arc_nodes[std::make_pair(from, to)]; -+ arc_node->is_exist = true; -+ return; -+ } -+ -+ auto arc_node = std::make_shared(from, to); -+ auto node = nodes[from]; -+ arc_node->next = node->head->next; -+ node->head->next = arc_node; -+ arc_node->is_exist = true; -+ arc_nodes[std::make_pair(from, to)] = arc_node; -+ in_edges[to].insert(from); -+} -+ -+void DepHandler::delete_edge(const std::string &from, const std::string &to) { -+ if (in_edges[to].find(from) == in_edges[to].end()) { -+ return; -+ } -+ auto arc_node = arc_nodes[std::make_pair(from, to)]; -+ arc_node->is_exist = false; - } - - void DepHandler::add_node(std::shared_ptr instance) { -@@ -81,10 +103,11 @@ void DepHandler::del_node_and_arc_nodes(std::shared_ptr node) { - while(arc) { - std::shared_ptr tmp = arc->next; - if (arc != node->head){ -- std::string name = arc->arc_name; -- arc_nodes[name].erase(arc); -- if (arc_nodes[name].empty()) { -- arc_nodes.erase(name); -+ std::string name = arc->to; -+ in_edges[name].erase(arc->from); -+ arc_nodes.erase(std::make_pair(arc->from, arc->to)); -+ if (in_edges[name].empty()) { -+ in_edges.erase(name); - } - } - arc = tmp; -@@ -92,15 +115,18 @@ void DepHandler::del_node_and_arc_nodes(std::shared_ptr node) { - } - - void DepHandler::update_instance_state(const std::string &name) { -- if (!nodes[name]->instance->get_state() || !arc_nodes.count(name)) return; -- std::unordered_set> &arcs = arc_nodes[name]; -- for (auto &arc_node : arcs) { -- if (nodes.count(arc_node->node_name)) { -- auto tmp = nodes[arc_node->node_name]; -+ if (!nodes[name]->instance->get_state() || !in_edges.count(name)) return; -+ std::unordered_set &arcs = in_edges[name]; -+ for (auto &from : arcs) { -+ auto arc_node = arc_nodes[std::make_pair(from, name)]; -+ if (nodes.count(from)) { -+ auto tmp = nodes[from]; - tmp->real_cnt++; - if (tmp->real_cnt == tmp->cnt) { - tmp->instance->set_state(true); - } -+ arc_node->is_exist = true; -+ arc_node->init = true; - update_instance_state(tmp->instance->get_name()); - } - } -@@ -113,54 +139,38 @@ void DepHandler::query_all_dependencies(std::vector> &q - } - - void DepHandler::query_node_top(const std::string &name, std::vector> &query) { -- std::shared_ptr p = nodes[name]->head; -- if (p->next == nullptr) { -+ std::shared_ptr arc_node = nodes[name]->head; -+ if (arc_node->next == nullptr) { - query.emplace_back(std::vector{name}); - return; - } -- while (p->next != nullptr) { -- query.emplace_back(std::vector{name, p->next->arc_name}); -- p = p->next; -+ while (arc_node->next != nullptr) { -+ if (arc_node->next->is_exist) { -+ query.emplace_back(std::vector{name, arc_node->next->to}); -+ } -+ arc_node = arc_node->next; - } - } - - void DepHandler::query_node_dependency(const std::string &name, std::vector> &query) { - if (!nodes.count(name)) return; -- std::queue q; -+ std::queue instance_queue; - std::unordered_set vis; - vis.insert(name); -- q.push(name); -- while (!q.empty()) { -- auto node = nodes[q.front()]; -- q.pop(); -+ instance_queue.push(name); -+ while (!instance_queue.empty()) { -+ auto node = nodes[instance_queue.front()]; -+ instance_queue.pop(); - std::string node_name = node->instance->get_name(); - query.emplace_back(std::vector{node_name}); - for (auto cur = node->head->next; cur != nullptr; cur = cur->next) { -- query.emplace_back(std::vector{node_name, cur->arc_name}); -- if (!vis.count(cur->arc_name) && nodes.count(cur->arc_name)) { -- vis.insert(cur->arc_name); -- q.push(cur->arc_name); -+ if (cur->is_exist) { -+ query.emplace_back(std::vector{node_name, cur->to}); - } -- } -- } --} -- --std::vector DepHandler::get_pre_dependencies(const std::string &name) { -- std::vector res; -- std::queue> q; -- std::unordered_set vis; -- vis.insert(name); -- q.push(nodes[name]); -- while (!q.empty()) { -- auto &node = q.front(); -- q.pop(); -- res.emplace_back(node->instance->get_name()); -- for (auto arc_node = node->head->next; arc_node != nullptr; arc_node = arc_node->next) { -- if (!vis.count(arc_node->arc_name)) { -- vis.insert(arc_node->arc_name); -- q.push(nodes[arc_node->arc_name]); -+ if (!vis.count(cur->to) && nodes.count(cur->to)) { -+ vis.insert(cur->to); -+ instance_queue.push(cur->to); - } - } - } -- return res; - } -diff --git a/src/plugin_mgr/dep_handler.h b/src/plugin_mgr/dep_handler.h -index a7a8ef6..322e3b3 100644 ---- a/src/plugin_mgr/dep_handler.h -+++ b/src/plugin_mgr/dep_handler.h -@@ -18,10 +18,12 @@ - - struct ArcNode { - std::shared_ptr next; -- std::string arc_name; -- std::string node_name; -- bool is_exist; -- ArcNode() : next(nullptr), is_exist(false) { } -+ std::string from; -+ std::string to; -+ bool is_exist; /* Whether this edge exists. */ -+ bool init; /* The initial state of the edge. */ -+ ArcNode() { } -+ ArcNode(const std::string &from, const std::string &to) : next(nullptr), from(from), to(to), is_exist(false), init(false) { } - }; - - // a instance node -@@ -29,11 +31,19 @@ struct Node { - std::shared_ptr next; - std::shared_ptr head; - std::shared_ptr instance; -- int cnt; -- int real_cnt; -+ int cnt; /* Number of dependencies required for loading. */ -+ int real_cnt; /* Actual number of dependencies during loading. */ - Node(): next(nullptr), head(nullptr), cnt(0), real_cnt(0) { } - }; - -+struct pair_hash { -+ std::size_t operator() (const std::pair &pair) const { -+ auto h1 = std::hash{}(pair.first); -+ auto h2 = std::hash{}(pair.second); -+ return h1 ^ h2; -+ } -+}; -+ - class DepHandler { - public: - DepHandler() { -@@ -43,19 +53,23 @@ public: - bool get_node_state(const std::string &name) { - return this->nodes[name]->instance->get_state(); - } -+ void delete_edge(const std::string &from, const std::string &to); -+ void add_edge(const std::string &from, const std::string &to); - void add_instance(std::shared_ptr instance); - void delete_instance(const std::string &name); - bool is_instance_exist(const std::string &name); - std::shared_ptr get_instance(const std::string &name) const { -+ if (!nodes.count(name)) { -+ return nullptr; -+ } - return nodes.at(name)->instance; - } - void query_node_dependency(const std::string &name, std::vector> &query); - void query_all_dependencies(std::vector> &query); - /* check whether the instance has dependencies */ - bool have_dep(const std::string &name) { -- return arc_nodes.count(name); -+ return in_edges.count(name); - } -- std::vector get_pre_dependencies(const std::string &name); - private: - void add_node(std::shared_ptr instance); - void del_node(const std::string &name); -@@ -64,8 +78,11 @@ private: - void update_instance_state(const std::string &name); - void del_node_and_arc_nodes(std::shared_ptr node); - std::shared_ptr add_new_node(std::shared_ptr instance); -- /* indegree edges */ -- std::unordered_map>> arc_nodes; -+ /* Indegree edges. */ -+ std::unordered_map> in_edges; -+ /* Store all edges. */ -+ std::unordered_map, std::shared_ptr, pair_hash> arc_nodes; -+ /* Store all points. */ - std::unordered_map> nodes; - std::shared_ptr head; - }; -diff --git a/src/plugin_mgr/instance_run_handler.cpp b/src/plugin_mgr/instance_run_handler.cpp -index ecd7778..496166b 100644 ---- a/src/plugin_mgr/instance_run_handler.cpp -+++ b/src/plugin_mgr/instance_run_handler.cpp -@@ -20,9 +20,8 @@ static const DataRingBuf* get_ring_buf(std::shared_ptr instance) { - return instance->get_interface()->get_ring_buf(); - } - --void InstanceRunHandler::run_instance(std::shared_ptr instance) { -+void InstanceRunHandler::run_instance(std::vector &deps, InstanceRun run) { - std::vector input_data; -- std::vector deps = instance->get_deps(); - for (size_t i = 0; i < deps.size(); ++i) { - std::shared_ptr ins = memory_store.get_instance(deps[i]); - input_data.emplace_back(get_ring_buf(ins)); -@@ -30,62 +29,167 @@ void InstanceRunHandler::run_instance(std::shared_ptr instance) { - Param param; - param.ring_bufs = input_data.data(); - param.len = input_data.size(); -- instance->get_interface()->run(¶m); -+ run(¶m); - } - --void InstanceRunHandler::insert_instance(std::shared_ptr instance, uint64_t time) { -- /* To check if an instance is enabled, enable() is called in the PluginManager. */ -- schedule_queue.push(ScheduleInstance{instance, time}); -- INFO("[PluginManager] " << instance->get_name() << " instance insert into running queue."); -+void InstanceRunHandler::enable_instance(const std::string &name) { -+ std::queue> instance_node_queue; -+ auto dep_handler = memory_store.get_dep_handler(); -+ instance_node_queue.push(dep_handler.get_node(name)); -+ std::vector new_enabled; -+ bool enabled = true; -+ while (!instance_node_queue.empty()) { -+ auto node = instance_node_queue.front(); -+ instance_node_queue.pop(); -+ if (node->instance->get_enabled()) { -+ continue; -+ } -+ auto cur_name = node->instance->get_name(); -+ node->instance->set_enabled(true); -+ new_enabled.emplace_back(cur_name); -+ if (!node->instance->get_interface()->enable()) { -+ enabled = false; -+ break; -+ } -+ for (auto arc = node->head->next; arc != nullptr; arc = arc->next) { -+ if (!arc->is_exist) { -+ continue; -+ } -+ auto cur_node = dep_handler.get_node(arc->to); -+ in_degree[arc->to]++; -+ instance_node_queue.push(cur_node); -+ } -+ } -+ if (!enabled) { -+ for (auto &enabled_name : new_enabled) { -+ auto instance = dep_handler.get_instance(enabled_name); -+ instance->get_interface()->disable(); -+ instance->set_enabled(false); -+ if (enabled_name == name) { -+ continue; -+ } -+ in_degree[enabled_name]--; -+ } -+ } else { -+ for (auto &enabled_name : new_enabled) { -+ auto instance = dep_handler.get_instance(enabled_name); -+ schedule_queue.push(ScheduleInstance{instance, time}); -+ INFO("[InstanceRunHandler] " << enabled_name << " instance insert into schedule queue at time " << time); -+ } -+ } - } - --void InstanceRunHandler::delete_instance(std::shared_ptr instance) { -- instance->get_interface()->disable(); -- instance->set_enabled(false); -- INFO("[PluginManager] " << instance->get_name() << " instance delete from running queue."); -+void InstanceRunHandler::disable_instance(const std::string &name) { -+ if (in_degree[name] != 0) { -+ return; -+ } -+ std::queue> instance_node_queue; -+ auto dep_handler = memory_store.get_dep_handler(); -+ instance_node_queue.push(dep_handler.get_node(name)); -+ while (!instance_node_queue.empty()) { -+ auto node = instance_node_queue.front(); -+ auto &instance = node->instance; -+ instance_node_queue.pop(); -+ auto cur_name = instance->get_name(); -+ instance->set_enabled(false); -+ instance->get_interface()->disable(); -+ INFO("[InstanceRunHandler] " << cur_name << " instance disabled at time " << time); -+ for (auto arc = node->head->next; arc != nullptr; arc = arc->next) { -+ auto cur_node = dep_handler.get_node(arc->to); -+ arc->is_exist = arc->init; -+ /* The instance can be closed only when the indegree is 0. */ -+ if (in_degree[arc->to] <= 0 || --in_degree[arc->to] != 0) { -+ continue; -+ } -+ instance_node_queue.push(cur_node); -+ } -+ } - } - --void InstanceRunHandler::handle_instance(uint64_t time) { -- InstanceRunMessage msg; -+void InstanceRunHandler::handle_instance() { -+ std::shared_ptr msg; - while(this->recv_queue_try_pop(msg)){ -- std::shared_ptr instance = msg.get_instance(); -- switch (msg.get_type()){ -+ std::shared_ptr instance = msg->get_instance(); -+ switch (msg->get_type()){ - case RunType::ENABLED: { -- insert_instance(std::move(instance), time); -+ enable_instance(instance->get_name()); - break; - } - case RunType::DISABLED: { -- delete_instance(std::move(instance)); -+ disable_instance(instance->get_name()); - break; - } - } -+ msg->notify_one(); - } - } - --void InstanceRunHandler::schedule(uint64_t time) { -+void InstanceRunHandler::change_instance_state(const std::string &name, std::vector &deps, -+ std::vector &after_deps) { -+ for (auto &dep : deps) { -+ if (std::find(after_deps.begin(), after_deps.end(), dep) != after_deps.end()) { -+ continue; -+ } -+ auto instance = memory_store.get_instance(dep); -+ if (instance == nullptr) { -+ ERROR("[InstanceRunHandler] ilegal dependency: " << dep); -+ continue; -+ } -+ /* Disable the instance that is not required. */ -+ if (instance->get_enabled()) { -+ memory_store.delete_edge(name, instance->get_name()); -+ in_degree[instance->get_name()]--; -+ auto msg = std::make_shared(RunType::DISABLED, instance); -+ recv_queue_push(std::move(msg)); -+ } -+ } -+ for (auto &after_dep : after_deps) { -+ if (std::find(deps.begin(), deps.end(), after_dep) != deps.end()) { -+ continue; -+ } -+ auto instance = memory_store.get_instance(after_dep); -+ if (instance == nullptr) { -+ ERROR("[InstanceRunHandler] ilegal dependency: " << after_dep); -+ continue; -+ } -+ /* Enable the instance that is required. */ -+ if (!instance->get_enabled()) { -+ in_degree[instance->get_name()]++; -+ memory_store.add_edge(name, instance->get_name()); -+ auto msg = std::make_shared(RunType::ENABLED, instance); -+ recv_queue_push(std::move(msg)); -+ } -+ } -+} -+ -+void InstanceRunHandler::schedule() { - while (!schedule_queue.empty()) { - auto schedule_instance = schedule_queue.top(); -+ auto &instance = schedule_instance.instance; - if (schedule_instance.time != time) { - break; - } - schedule_queue.pop(); -- if (!schedule_instance.instance->get_enabled()) { -- break; -+ if (!instance->get_enabled()) { -+ continue; - } -- run_instance(schedule_instance.instance); -- schedule_instance.time += schedule_instance.instance->get_interface()->get_period(); -+ std::vector deps = instance->get_deps(); -+ run_instance(deps, instance->get_interface()->run); -+ schedule_instance.time += instance->get_interface()->get_period(); - schedule_queue.push(schedule_instance); -+ /* Dynamically change dependencies. */ -+ std::vector after_deps = instance->get_deps(); -+ change_instance_state(instance->get_name(), deps, after_deps); - } - } - - void start(InstanceRunHandler *instance_run_handler) { -- unsigned long long time = 0; - INFO("[PluginManager] instance schedule started!"); - while(true) { -- instance_run_handler->handle_instance(time); -- instance_run_handler->schedule(time); -+ instance_run_handler->handle_instance(); -+ instance_run_handler->schedule(); - usleep(instance_run_handler->get_cycle() * 1000); -- time += instance_run_handler->get_cycle(); -+ instance_run_handler->add_time(instance_run_handler->get_cycle()); - } - } - -diff --git a/src/plugin_mgr/instance_run_handler.h b/src/plugin_mgr/instance_run_handler.h -index f0bf263..980fd98 100644 ---- a/src/plugin_mgr/instance_run_handler.h -+++ b/src/plugin_mgr/instance_run_handler.h -@@ -27,16 +27,30 @@ enum class RunType { - class InstanceRunMessage { - public: - InstanceRunMessage() {} -- InstanceRunMessage(RunType type, std::shared_ptr instance) : type(type), instance(instance) {} -+ InstanceRunMessage(RunType type, std::shared_ptr instance) : type(type), instance(instance), finish(false) { } - RunType get_type() { - return type; - } - std::shared_ptr get_instance() { - return instance; - } -+ void wait() { -+ std::unique_lock lock(mutex); -+ cond.wait(lock, [this]() { -+ return finish; -+ }); -+ } -+ void notify_one() { -+ std::unique_lock lock(mutex); -+ finish = true; -+ cond.notify_one(); -+ } - private: - RunType type; - std::shared_ptr instance; -+ std::mutex mutex; -+ std::condition_variable cond; -+ bool finish; - }; - - class ScheduleInstance { -@@ -51,35 +65,39 @@ public: - /* A handler to schedule instances. */ - class InstanceRunHandler { - public: -- explicit InstanceRunHandler(MemoryStore &memory_store) : memory_store(memory_store), cycle(DEFAULT_CYCLE_SIZE) {} -+ using InstanceRun = void (*)(const struct Param*); -+ explicit InstanceRunHandler(MemoryStore &memory_store) : memory_store(memory_store), time(0), cycle(DEFAULT_CYCLE_SIZE) { } - void run(); -- void schedule(uint64_t time); -- void handle_instance(uint64_t time); -+ void schedule(); -+ void handle_instance(); - void set_cycle(int cycle) { - this->cycle = cycle; - } - int get_cycle() { - return cycle; - } -- void recv_queue_push(InstanceRunMessage &msg) { -- this->recv_queue.push(msg); -- } -- void recv_queue_push(InstanceRunMessage &&msg) { -+ void recv_queue_push(std::shared_ptr msg) { - this->recv_queue.push(msg); - } -- bool recv_queue_try_pop(InstanceRunMessage &msg) { -+ bool recv_queue_try_pop(std::shared_ptr &msg) { - return this->recv_queue.try_pop(msg); - } -+ void add_time(uint64_t period) { -+ time += period; -+ } -+private: -+ void run_instance(std::vector &deps, InstanceRun run); -+ void change_instance_state(const std::string &name, std::vector &deps, std::vector &after_deps); -+ void enable_instance(const std::string &name); -+ void disable_instance(const std::string &name); - private: -- void run_instance(std::shared_ptr instance); -- void delete_instance(std::shared_ptr instance); -- void insert_instance(std::shared_ptr instance, uint64_t time); -- - /* Instance execution queue. */ - std::priority_queue schedule_queue; -- /*Receives messages from the PluginManager. */ -- SafeQueue recv_queue; -+ /* Receives messages from the PluginManager. */ -+ SafeQueue> recv_queue; -+ std::unordered_map in_degree; - MemoryStore &memory_store; -+ uint64_t time; - int cycle; - static const int DEFAULT_CYCLE_SIZE = 10; - }; -diff --git a/src/plugin_mgr/interface.h b/src/plugin_mgr/interface.h -index 8aa6933..9dad5b8 100644 ---- a/src/plugin_mgr/interface.h -+++ b/src/plugin_mgr/interface.h -@@ -21,11 +21,11 @@ struct DataBuf { - - struct DataRingBuf { - /* instance name */ -- const char *instance_name; -+ const char *instance_name; - /* buf write index, initial value is -1 */ - int index; - /* instance run times */ -- uint64_t count; -+ uint64_t count; - struct DataBuf *buf; - int buf_len; - }; -diff --git a/src/plugin_mgr/memory_store.h b/src/plugin_mgr/memory_store.h -index 0e862db..a43c461 100644 ---- a/src/plugin_mgr/memory_store.h -+++ b/src/plugin_mgr/memory_store.h -@@ -58,8 +58,14 @@ public: - bool have_dep(const std::string &name) { - return dep_handler.have_dep(name); - } -- std::vector get_pre_dependencies(const std::string &name) { -- return dep_handler.get_pre_dependencies(name); -+ const DepHandler& get_dep_handler() const { -+ return dep_handler; -+ } -+ void add_edge(const std::string &from, const std::string &to) { -+ dep_handler.add_edge(from, to); -+ } -+ void delete_edge(const std::string &from, const std::string &to) { -+ dep_handler.delete_edge(from, to); - } - private: - /* instance are stored in the form of DAG. -diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp -index 4c5f5fc..9ecaa6d 100644 ---- a/src/plugin_mgr/plugin_manager.cpp -+++ b/src/plugin_mgr/plugin_manager.cpp -@@ -22,7 +22,6 @@ void PluginManager::init(std::shared_ptr config, std::shared_ptrhandler_msg = handler_msg; - this->res_msg = res_msg; - instance_run_handler.reset(new InstanceRunHandler(memory_store)); -- pre_load(); - } - - ErrorCode PluginManager::remove(const std::string &name) { -@@ -204,35 +203,14 @@ ErrorCode PluginManager::instance_enabled(const std::string &name) { - if (instance->get_enabled()) { - return ErrorCode::ENABLE_INSTANCE_ALREADY_ENABLED; - } -- std::vector pre_dependencies = memory_store.get_pre_dependencies(name); -- std::vector> new_enabled; -- bool enabled = true; -- for (int i = pre_dependencies.size() - 1; i >= 0; --i) { -- instance = memory_store.get_instance(pre_dependencies[i]); -- if (instance->get_enabled()) { -- continue; -- } -- new_enabled.emplace_back(instance); -- if (!instance->get_interface()->enable()) { -- enabled = false; -- WARN("[PluginManager] " << instance->get_name() << " instance enabled failed, because instance init environment failed."); -- break; -- } -- } -- if (enabled) { -- for (int i = pre_dependencies.size() - 1; i >= 0; --i) { -- instance = memory_store.get_instance(pre_dependencies[i]); -- if (instance->get_enabled()) { -- continue; -- } -- instance->set_enabled(true); -- instance_run_handler->recv_queue_push(InstanceRunMessage(RunType::ENABLED, instance)); -- } -- return ErrorCode::OK; -+ std::shared_ptr msg = std::make_shared(RunType::ENABLED, instance); -+ /* Send message to InstanceRunHandler. */ -+ instance_run_handler->recv_queue_push(msg); -+ /* Wait for InstanceRunHandler to finsh this task. */ -+ msg->wait(); -+ if (msg->get_instance()->get_enabled()) { -+ return ErrorCode::OK; - } else { -- for (auto ins : new_enabled) { -- ins->get_interface()->disable(); -- } - return ErrorCode::ENABLE_INSTANCE_ENV; - } - } -@@ -248,7 +226,9 @@ ErrorCode PluginManager::instance_disabled(const std::string &name) { - if (!instance->get_enabled()) { - return ErrorCode::DISABLE_INSTANCE_ALREADY_DISABLED; - } -- instance_run_handler->recv_queue_push(InstanceRunMessage(RunType::DISABLED, instance)); -+ auto msg = std::make_shared(RunType::DISABLED, instance); -+ instance_run_handler->recv_queue_push(msg); -+ msg->wait(); - return ErrorCode::OK; - } - -@@ -397,6 +377,7 @@ bool file_exist(const std::string &file_name) { - - int PluginManager::run() { - instance_run_handler->run(); -+ pre_load(); - while (true) { - Message msg; - Message res; --- -2.33.0 - diff --git a/0007-fix-dependency-disabled-failed-and-pre-enable-illega.patch b/0007-fix-dependency-disabled-failed-and-pre-enable-illega.patch deleted file mode 100644 index 2130329..0000000 --- a/0007-fix-dependency-disabled-failed-and-pre-enable-illega.patch +++ /dev/null @@ -1,115 +0,0 @@ -From 2a6837386db74d59e35f2ff54499d79904ae1501 Mon Sep 17 00:00:00 2001 -From: fly_1997 -Date: Thu, 13 Jun 2024 10:06:04 +0800 -Subject: [PATCH 1/2] fix dependency disabled failed and pre-enable illegal - plugin - ---- - src/plugin_mgr/instance_run_handler.cpp | 17 ++++++++++------- - src/plugin_mgr/instance_run_handler.h | 4 +++- - src/plugin_mgr/plugin_manager.cpp | 12 ++++++------ - 3 files changed, 19 insertions(+), 14 deletions(-) - -diff --git a/src/plugin_mgr/instance_run_handler.cpp b/src/plugin_mgr/instance_run_handler.cpp -index 496166b..928b555 100644 ---- a/src/plugin_mgr/instance_run_handler.cpp -+++ b/src/plugin_mgr/instance_run_handler.cpp -@@ -79,10 +79,11 @@ void InstanceRunHandler::enable_instance(const std::string &name) { - } - } - --void InstanceRunHandler::disable_instance(const std::string &name) { -- if (in_degree[name] != 0) { -+void InstanceRunHandler::disable_instance(const std::string &name, RunType type) { -+ if (type == RunType::INTERNAL_DISABLED && in_degree[name] != 0) { - return; - } -+ in_degree[name] = 0; - std::queue> instance_node_queue; - auto dep_handler = memory_store.get_dep_handler(); - instance_node_queue.push(dep_handler.get_node(name)); -@@ -111,12 +112,14 @@ void InstanceRunHandler::handle_instance() { - while(this->recv_queue_try_pop(msg)){ - std::shared_ptr instance = msg->get_instance(); - switch (msg->get_type()){ -- case RunType::ENABLED: { -+ case RunType::ENABLED: -+ case RunType::INTERNAL_ENABLED: { - enable_instance(instance->get_name()); - break; - } -- case RunType::DISABLED: { -- disable_instance(instance->get_name()); -+ case RunType::DISABLED: -+ case RunType::INTERNAL_DISABLED: { -+ disable_instance(instance->get_name(), msg->get_type()); - break; - } - } -@@ -139,7 +142,7 @@ void InstanceRunHandler::change_instance_state(const std::string &name, std::vec - if (instance->get_enabled()) { - memory_store.delete_edge(name, instance->get_name()); - in_degree[instance->get_name()]--; -- auto msg = std::make_shared(RunType::DISABLED, instance); -+ auto msg = std::make_shared(RunType::INTERNAL_DISABLED, instance); - recv_queue_push(std::move(msg)); - } - } -@@ -156,7 +159,7 @@ void InstanceRunHandler::change_instance_state(const std::string &name, std::vec - if (!instance->get_enabled()) { - in_degree[instance->get_name()]++; - memory_store.add_edge(name, instance->get_name()); -- auto msg = std::make_shared(RunType::ENABLED, instance); -+ auto msg = std::make_shared(RunType::INTERNAL_ENABLED, instance); - recv_queue_push(std::move(msg)); - } - } -diff --git a/src/plugin_mgr/instance_run_handler.h b/src/plugin_mgr/instance_run_handler.h -index 980fd98..682510b 100644 ---- a/src/plugin_mgr/instance_run_handler.h -+++ b/src/plugin_mgr/instance_run_handler.h -@@ -21,6 +21,8 @@ - enum class RunType { - ENABLED, - DISABLED, -+ INTERNAL_ENABLED, -+ INTERNAL_DISABLED, - }; - - /* Message for communication between plugin manager and instance scheduling */ -@@ -89,7 +91,7 @@ private: - void run_instance(std::vector &deps, InstanceRun run); - void change_instance_state(const std::string &name, std::vector &deps, std::vector &after_deps); - void enable_instance(const std::string &name); -- void disable_instance(const std::string &name); -+ void disable_instance(const std::string &name, RunType type); - private: - /* Instance execution queue. */ - std::priority_queue schedule_queue; -diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp -index 9ecaa6d..7220f48 100644 ---- a/src/plugin_mgr/plugin_manager.cpp -+++ b/src/plugin_mgr/plugin_manager.cpp -@@ -282,13 +282,13 @@ ErrorCode PluginManager::download(const std::string &name, std::string &res) { - void PluginManager::pre_enable() { - for (size_t i = 0; i < config->get_enable_list_size(); ++i) { - EnableItem item = config->get_enable_list(i); -+ std::string plugin_name = item.get_name(); -+ if (!memory_store.is_plugin_exist(plugin_name)) { -+ WARN("[PluginManager] plugin " << plugin_name << " cannot be enabled, because it does not exist."); -+ continue; -+ } - if (item.get_enabled()) { -- std::string name = item.get_name(); -- if (!memory_store.is_plugin_exist(name)) { -- WARN("[PluginManager] plugin " << name << " cannot be enabled, because it does not exist."); -- continue; -- } -- std::shared_ptr plugin = memory_store.get_plugin(name); -+ std::shared_ptr plugin = memory_store.get_plugin(plugin_name); - for (size_t j = 0; j < plugin->get_instance_len(); ++j) { - instance_enabled(plugin->get_instance(j)->get_name()); - } --- -2.33.0 - diff --git a/0008-fix-dependency-error-and-add-enable-failed-logs.patch b/0008-fix-dependency-error-and-add-enable-failed-logs.patch deleted file mode 100644 index 5104769..0000000 --- a/0008-fix-dependency-error-and-add-enable-failed-logs.patch +++ /dev/null @@ -1,138 +0,0 @@ -From 918ef95a2e5f9de71efa55beee35eaa083c31b7d Mon Sep 17 00:00:00 2001 -From: fly_1997 -Date: Thu, 13 Jun 2024 16:28:19 +0800 -Subject: [PATCH 2/2] fix dependency error and add enable failed logs - ---- - src/plugin_mgr/dep_handler.cpp | 22 +++++++++++++--------- - src/plugin_mgr/instance_run_handler.h | 2 ++ - src/plugin_mgr/plugin_manager.cpp | 17 ++++++++++++----- - 3 files changed, 27 insertions(+), 14 deletions(-) - -diff --git a/src/plugin_mgr/dep_handler.cpp b/src/plugin_mgr/dep_handler.cpp -index 227ee2f..2b20e7e 100644 ---- a/src/plugin_mgr/dep_handler.cpp -+++ b/src/plugin_mgr/dep_handler.cpp -@@ -28,22 +28,26 @@ void DepHandler::add_arc_node(std::shared_ptr node, const std::vector arc_head = node->head; - node->cnt = dep_nodes.size(); - int real_cnt = 0; -+ bool state = true; - for (auto name : dep_nodes) { - std::string from = node->instance->get_name(); - std::shared_ptr tmp = std::make_shared(from, name); - tmp->next = arc_head->next; - arc_head->next = tmp; -- -+ tmp->init = true; - if (nodes.count(name)) { - tmp->is_exist = true; -- tmp->init = true; - real_cnt++; -+ if (!nodes[name]->instance->get_state()) { -+ state = false; -+ } - } - in_edges[name].insert(from); - arc_nodes[std::make_pair(from, name)] = tmp; - } -+ /* node->instance->state = true, only all dependencies meet the conditions. */ - if (real_cnt == node->cnt) { -- node->instance->set_state(true); -+ node->instance->set_state(state); - } - node->real_cnt = real_cnt; - } -@@ -115,18 +119,17 @@ void DepHandler::del_node_and_arc_nodes(std::shared_ptr node) { - } - - void DepHandler::update_instance_state(const std::string &name) { -- if (!nodes[name]->instance->get_state() || !in_edges.count(name)) return; -+ if (!in_edges.count(name)) return; - std::unordered_set &arcs = in_edges[name]; - for (auto &from : arcs) { - auto arc_node = arc_nodes[std::make_pair(from, name)]; - if (nodes.count(from)) { - auto tmp = nodes[from]; - tmp->real_cnt++; -- if (tmp->real_cnt == tmp->cnt) { -+ if (tmp->real_cnt == tmp->cnt && nodes[name]->instance->get_state()) { - tmp->instance->set_state(true); - } - arc_node->is_exist = true; -- arc_node->init = true; - update_instance_state(tmp->instance->get_name()); - } - } -@@ -144,8 +147,9 @@ void DepHandler::query_node_top(const std::string &name, std::vector{name}); - return; - } -- while (arc_node->next != nullptr) { -- if (arc_node->next->is_exist) { -+ while (arc_node->next != nullptr) { -+ /* Display the edges that exist and the points that do not. */ -+ if (arc_node->next->is_exist || !nodes.count(arc_node->next->to)) { - query.emplace_back(std::vector{name, arc_node->next->to}); - } - arc_node = arc_node->next; -@@ -164,7 +168,7 @@ void DepHandler::query_node_dependency(const std::string &name, std::vectorinstance->get_name(); - query.emplace_back(std::vector{node_name}); - for (auto cur = node->head->next; cur != nullptr; cur = cur->next) { -- if (cur->is_exist) { -+ if (cur->is_exist || !nodes.count(cur->to)) { - query.emplace_back(std::vector{node_name, cur->to}); - } - if (!vis.count(cur->to) && nodes.count(cur->to)) { -diff --git a/src/plugin_mgr/instance_run_handler.h b/src/plugin_mgr/instance_run_handler.h -index 682510b..3804a49 100644 ---- a/src/plugin_mgr/instance_run_handler.h -+++ b/src/plugin_mgr/instance_run_handler.h -@@ -19,8 +19,10 @@ - #include - - enum class RunType { -+ /* Message from PluginManager. */ - ENABLED, - DISABLED, -+ /* Message from internal. */ - INTERNAL_ENABLED, - INTERNAL_DISABLED, - }; -diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp -index 7220f48..c3ff8bf 100644 ---- a/src/plugin_mgr/plugin_manager.cpp -+++ b/src/plugin_mgr/plugin_manager.cpp -@@ -290,16 +290,23 @@ void PluginManager::pre_enable() { - if (item.get_enabled()) { - std::shared_ptr plugin = memory_store.get_plugin(plugin_name); - for (size_t j = 0; j < plugin->get_instance_len(); ++j) { -- instance_enabled(plugin->get_instance(j)->get_name()); -+ std::string name = plugin->get_instance(j)->get_name(); -+ auto ret = instance_enabled(name); -+ if (ret != ErrorCode::OK) { -+ WARN("[PluginManager] " << name << " instance pre-enabled failed, because " << ErrorText::get_error_text(ret) << "."); -+ } else { -+ INFO("[PluginManager] " << name << " instance pre-enabled."); -+ } - } - } else { - for (size_t j = 0; j < item.get_instance_size(); ++j) { - std::string name = item.get_instance_name(j); -- if (!memory_store.is_instance_exist(name)) { -- WARN("[PluginManager] instance " << name << " cannot be enabled, because it does not exist."); -- continue; -+ auto ret = instance_enabled(name); -+ if (ret != ErrorCode::OK) { -+ WARN("[PluginManager] " << name << " instance pre-enabled failed, because " << ErrorText::get_error_text(ret) << "."); -+ } else { -+ INFO("[PluginManager] " << name << " instance pre-enabled."); - } -- instance_enabled(name); - } - } - } --- -2.33.0 - diff --git a/oeAware-manager-v1.0.1.tar.gz b/oeAware-manager-v1.0.1.tar.gz deleted file mode 100644 index f66e036..0000000 Binary files a/oeAware-manager-v1.0.1.tar.gz and /dev/null differ diff --git a/oeAware-manager-v1.0.2.tar.gz b/oeAware-manager-v1.0.2.tar.gz new file mode 100644 index 0000000..43ff4a4 Binary files /dev/null and b/oeAware-manager-v1.0.2.tar.gz differ diff --git a/oeAware-manager.spec b/oeAware-manager.spec index 1956a13..1f4eef7 100644 --- a/oeAware-manager.spec +++ b/oeAware-manager.spec @@ -1,18 +1,10 @@ Name: oeAware-manager -Version: v1.0.1 -Release: 6 +Version: v1.0.2 +Release: 1 Summary: OeAware server and client License: MulanPSL2 URL: https://gitee.com/openeuler/%{name} Source0: %{name}-%{version}.tar.gz -Patch1: 0001-fix-issues.patch -Patch2: 0002-refactor-plugin-interface.patch -Patch3: 0003-the-client-adapts-to-the-new-interface-and-refactor-.patch -Patch4: 0004-modify-some-interfaces-and-add-interface-comments.patch -Patch5: 0005-add-the-SIGINT-signal-processing-and-singleton-class.patch -Patch6: 0006-add-dynamic-dependencncy-adjustment.patch -Patch7: 0007-fix-dependency-disabled-failed-and-pre-enable-illega.patch -Patch8: 0008-fix-dependency-error-and-add-enable-failed-logs.patch BuildRequires: cmake make gcc-c++ BuildRequires: boost-devel @@ -48,7 +40,7 @@ install -D -p -m 0644 oeaware.service %{buildroot}%{_unitdir}/oeaware.service %systemd_preun oeaware.service %post -%systemd_post oeaware.service +systemctl start oeaware.service %files %attr(0750, root, root) %{_bindir}/oeaware @@ -57,6 +49,9 @@ install -D -p -m 0644 oeaware.service %{buildroot}%{_unitdir}/oeaware.service %attr(0644, root, root) %{_unitdir}/oeaware.service %changelog +* Thu Jun 20 2024 fly_1997 -v1.0.2-1 +- update version to v1.0.2-1 + * Fri Jun 14 2024 fly_1997 -v1.0.1-6 - fix dependency error and add enable failed logs - fix dependency disabled failed and pre-enable illegal plugin