diff --git a/src/dummytrackerplugin/dummytrackerplugin.cc b/src/dummytrackerplugin/dummytrackerplugin.cc index 857a8be..29bc54b 100644 --- a/src/dummytrackerplugin/dummytrackerplugin.cc +++ b/src/dummytrackerplugin/dummytrackerplugin.cc @@ -40,10 +40,9 @@ static void load_config(WT_IDataControlPlugin* obj, const char ***config, int si } } -static int plugin_process(WT_IDataControlPlugin* obj, - char[WT_MAX_APP_NAME_LEN], - char[WT_MAX_WIN_TITLE_LEN], - int*) +static int plugin_suspend(WT_IDataControlPlugin* obj, + const char[WT_MAX_APP_NAME_LEN], + const char[WT_MAX_WIN_TITLE_LEN]) { if (!obj->silent) { @@ -60,4 +59,5 @@ WT_PLUGIN_DEFINE( create_plugin, destroy_plugin, load_config, - plugin_process) + nullptr, + plugin_suspend) diff --git a/src/gnomescreensaverplugin/gnomescreensaver.cc b/src/gnomescreensaverplugin/gnomescreensaver.cc index e5207d5..27f9cd8 100644 --- a/src/gnomescreensaverplugin/gnomescreensaver.cc +++ b/src/gnomescreensaverplugin/gnomescreensaver.cc @@ -134,10 +134,9 @@ static void load_config(WT_IDataControlPlugin*, const char ***, int) } -static int plugin_process(WT_IDataControlPlugin* plugin, - char[WT_MAX_APP_NAME_LEN], - char[WT_MAX_WIN_TITLE_LEN], - int*) +static int plugin_suspend(WT_IDataControlPlugin* plugin, + const char[WT_MAX_APP_NAME_LEN], + const char[WT_MAX_WIN_TITLE_LEN]) { return plugin->suspend_tracking(); } @@ -149,4 +148,5 @@ WT_PLUGIN_DEFINE( create_plugin, destroy_plugin, load_config, - plugin_process) + nullptr, + plugin_suspend) diff --git a/src/tracker/plugincontainer.cc b/src/tracker/plugincontainer.cc index baaa136..32f87a1 100644 --- a/src/tracker/plugincontainer.cc +++ b/src/tracker/plugincontainer.cc @@ -38,35 +38,37 @@ bool PluginContainer::process_controllers(DataEntry &entry) { WT_LOG_D << "Updating data..."; - int force_break = 0; - char in_out_app_name[WT_MAX_APP_NAME_LEN] = {0}; - char in_out_window_title[WT_MAX_WIN_TITLE_LEN] = {0}; + char app_name[WT_MAX_APP_NAME_LEN] = {0}; + char window_title[WT_MAX_WIN_TITLE_LEN] = {0}; - strncpy(in_out_app_name, entry.proc_name.c_str(), WT_MAX_APP_NAME_LEN-1); - strncpy(in_out_window_title, entry.description.c_str(), WT_MAX_WIN_TITLE_LEN-1); + strncpy(app_name, entry.proc_name.c_str(), WT_MAX_APP_NAME_LEN-1); + strncpy(window_title, entry.description.c_str(), WT_MAX_WIN_TITLE_LEN-1); for (const auto &plugin : plugins) { - if (plugin->process_data_entry(in_out_app_name, in_out_window_title, &force_break)) + if (plugin->suspend_logging(app_name, window_title)) { return true; } + } - if (force_break) + for (const auto &plugin : plugins) + { + if (plugin->update_data_entry(app_name, window_title)) { WT_LOG_D << "Force break from plugin " << plugin->get_name(); break; } } - if (strcmp(in_out_app_name, entry.proc_name.c_str())) + if (strcmp(app_name, entry.proc_name.c_str())) { - entry.proc_name = in_out_app_name; + entry.proc_name = app_name; } - if (strcmp(in_out_window_title, entry.description.c_str())) + if (strcmp(window_title, entry.description.c_str())) { - entry.description = in_out_window_title; + entry.description = window_title; } return false; diff --git a/src/tracker/pluginloader.cc b/src/tracker/pluginloader.cc index c04bd20..22a49a7 100644 --- a/src/tracker/pluginloader.cc +++ b/src/tracker/pluginloader.cc @@ -75,11 +75,24 @@ void PluginLoader::try_load_plugin(const std::string &path) } } -bool PluginWrapper::process_data_entry(char in_out_app_name[WT_MAX_APP_NAME_LEN], - char in_out_window_title[WT_MAX_WIN_TITLE_LEN], - int* out_force_break) +bool PluginWrapper::update_data_entry(char in_out_app_name[WT_MAX_APP_NAME_LEN], + char in_out_window_title[WT_MAX_WIN_TITLE_LEN]) { - return plugin_info.control_data_func(plugin, in_out_app_name, in_out_window_title, out_force_break); + if (plugin_info.update_data_func) + { + return plugin_info.update_data_func(plugin, in_out_app_name, in_out_window_title); + } + return false; +} + +bool PluginWrapper::suspend_logging(char in_out_app_name[WT_MAX_APP_NAME_LEN], + char in_out_window_title[WT_MAX_WIN_TITLE_LEN]) +{ + if (plugin_info.suspend_tracking_func) + { + return plugin_info.suspend_tracking_func(plugin, in_out_app_name, in_out_window_title); + } + return false; } } diff --git a/src/tracker/pluginloader.h b/src/tracker/pluginloader.h index 9a8dfe0..3da889f 100644 --- a/src/tracker/pluginloader.h +++ b/src/tracker/pluginloader.h @@ -53,13 +53,18 @@ class PluginWrapper return plugin_info.version; } - bool process_data_entry(char in_out_app_name[WT_MAX_APP_NAME_LEN], - char in_out_window_title[WT_MAX_WIN_TITLE_LEN], - int* out_force_break); + bool update_data_entry(char in_out_app_name[WT_MAX_APP_NAME_LEN], + char in_out_window_title[WT_MAX_WIN_TITLE_LEN]); + + bool suspend_logging(char in_out_app_name[WT_MAX_APP_NAME_LEN], + char in_out_window_title[WT_MAX_WIN_TITLE_LEN]); void load_configuration(const char*** config, int size) { - plugin_info.load_config_func(plugin, config, size); + if (plugin_info.load_config_func) + { + plugin_info.load_config_func(plugin, config, size); + } } }; diff --git a/src/wtcommon/idatacontrolplugin.h b/src/wtcommon/idatacontrolplugin.h index ee5e01a..cf012c8 100644 --- a/src/wtcommon/idatacontrolplugin.h +++ b/src/wtcommon/idatacontrolplugin.h @@ -23,17 +23,52 @@ extern "C" { #endif +/** + * A struct that represents a plugin. + */ struct WT_IDataControlPlugin; +/** + * Creates an instance of the plugin. + * @return The instance of the WT_IDataControlPlugin struct. + */ typedef WT_IDataControlPlugin*(*WT_CreateFunc)(); -typedef void (*WT_DestroyFunc)(WT_IDataControlPlugin *); -typedef void (*WT_LoadConfigFunc)(WT_IDataControlPlugin*, const char **config[2], int size); -typedef int (*WT_ControlDataFunc)( +/** + * Destroys instance of the plugin. + * @param plugin The instance of the WT_IDataControlPlugin struct. + */ +typedef void (*WT_DestroyFunc)(WT_IDataControlPlugin *plugin); + +/** + * Loads configuration to a plugin. + * @param plugin The plugin. + * @param config An array of key-value string pair that contains configuration for the plugin. + * @param size A number of configuration entries. + */ +typedef void (*WT_LoadConfigFunc)(WT_IDataControlPlugin *plugin, const char **config[2], int size); + +/** + * Updates data entiers that will be stored in a database. + * @param in_out_app_name An application name of the data entry. + * @param in_out_window_title A window title of the data entry. + * @return Zero, if other plugins should be processed; otherwise, non-zero value. + */ +typedef int (*WT_UpdateDataFunc)( WT_IDataControlPlugin*, char in_out_app_name[WT_MAX_APP_NAME_LEN], - char in_out_window_title[WT_MAX_WIN_TITLE_LEN], - int* out_force_break); + char in_out_window_title[WT_MAX_WIN_TITLE_LEN]); + +/** + * Returns information whether a tracking should be suspended. + * @param app_name An application name of the data entry. + * @param window_title A window title of the data entry. + * @return Non-zero value, if the tracking should be suspended; otherwise, zero. +*/ +typedef int (*WT_SuspendTrackingFunc)( + WT_IDataControlPlugin*, + const char app_name[WT_MAX_APP_NAME_LEN], + const char window_title[WT_MAX_WIN_TITLE_LEN]); typedef struct { int version; @@ -42,15 +77,26 @@ typedef struct { WT_CreateFunc create_func; WT_DestroyFunc destroy_func; WT_LoadConfigFunc load_config_func; - WT_ControlDataFunc control_data_func; + WT_UpdateDataFunc update_data_func; + WT_SuspendTrackingFunc suspend_tracking_func; } WT_PluginInfo; #ifdef __cplusplus } #endif - -#define WT_PLUGIN_DEFINE(version, rank, name, create_func, destroy_func, load_config_func, control_data_func) \ +/** Defines a plugin + * + * @param version A version of the workertracker that the plugin was compiled for. + * @param rank A plugin priority rank - higher value, more important plugin. + * @param name A name of the plugin. + * @param create_func A pointer to the construction function of the WT_CreateFunc signature. + * @param destroy_func A pointer to the destroy function of the WT_DestroyFunc signature. + * @param load_config_func A pointer to the function that loads the configuration, of the WT_LoadConfigFunc signature, optional. + * @param update_data_func A pointer to the function that might update a data, of the WT_UpdateDataFunc signature, optional. + * @param suspend_tracking_func A pointer to the function that might suspend a tracking, of the WT_SuspendTrackingFunc signature, optional. + */ +#define WT_PLUGIN_DEFINE(version, rank, name, create_func, destroy_func, load_config_func, update_data_func, suspend_tracking_func) \ WT_PLUGIN_EXPORT WT_PluginInfo wt_plugin_info = { \ version, \ rank, \ @@ -58,7 +104,8 @@ typedef struct { create_func, \ destroy_func, \ load_config_func, \ - control_data_func \ + update_data_func, \ + suspend_tracking_func \ };