122 lines
4.4 KiB
Diff
122 lines
4.4 KiB
Diff
From 0758b61d2e9af546d3c55bc9cb3704cd7a4fe59a Mon Sep 17 00:00:00 2001
|
|
From: fly_1997 <flylove7@outlook.com>
|
|
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> instance) {
|
|
}
|
|
|
|
void InstanceRunHandler::insert_instance(std::shared_ptr<Instance> 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> 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> instance);
|
|
void delete_instance(std::shared_ptr<Instance> instance);
|
|
void insert_instance(std::shared_ptr<Instance> instance, uint64_t time);
|
|
- void adjust_collector_queue(const std::vector<std::string> &deps, const std::vector<std::string> &m_deps, bool flag);
|
|
- void check_scenario_dependency(const std::vector<std::string> &deps, const std::vector<std::string> &m_deps);
|
|
|
|
+ /* Instance execution queue. */
|
|
std::priority_queue<ScheduleInstance> schedule_queue;
|
|
+ /*Receives messages from the PluginManager. */
|
|
SafeQueue<InstanceRunMessage> 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 <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
-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
|
|
|