root / trunk / nntpgrab_core / nntpgrab_plugin.h
History | View | Annotate | Download (13.4 KB)
| 1 |
/*
|
|---|---|
| 2 |
Copyright (C) 2005-2012 Erik van Pienbroek |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License as published by |
| 6 |
the Free Software Foundation; either version 2 of the License, or |
| 7 |
(at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program; if not, write to the Free Software |
| 16 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef _NNTPGRAB_PLUGIN_H_
|
| 20 |
#define _NNTPGRAB_PLUGIN_H_
|
| 21 |
|
| 22 |
#include |
| 23 |
#include |
| 24 |
|
| 25 |
#include |
| 26 |
|
| 27 |
G_BEGIN_DECLS |
| 28 |
|
| 29 |
#define NNTPGRAB_PLUGIN_API_VERSION 20111201 |
| 30 |
|
| 31 |
typedef enum { |
| 32 |
NNTP_ERROR_NONE, |
| 33 |
NNTP_ERROR_HOST_NOT_FOUND, |
| 34 |
NNTP_ERROR_SSL_INITIALISE, |
| 35 |
NNTP_ERROR_CONNECTION_REFUSED, |
| 36 |
NNTP_ERROR_CONNECTION_TIMEOUT, |
| 37 |
NNTP_ERROR_READ, |
| 38 |
NNTP_ERROR_WRITE, |
| 39 |
NNTP_ERROR_INVALID_MSG, |
| 40 |
NNTP_ERROR_LOGIN_FAILURE, |
| 41 |
NNTP_ERROR_TOO_MANY_CONNECTIONS, |
| 42 |
NNTP_ERROR_PART_NOT_AVAILABLE, |
| 43 |
NNTP_ERROR_NO_SUCH_GROUP, |
| 44 |
NNTP_ERROR_UNABLE_TO_SAVE_PART |
| 45 |
} NNTPGrabErrCode; |
| 46 |
|
| 47 |
typedef enum { |
| 48 |
DECODER_RESULT_COMPLETE, |
| 49 |
DECODER_RESULT_INCOMPLETE, |
| 50 |
DECODER_RESULT_NO_PARTS_AVAIL, |
| 51 |
DECODER_RESULT_ERROR |
| 52 |
} NNTPGrabDecoderRes; |
| 53 |
|
| 54 |
typedef struct _ng_plugin_core_data NGPluginCoreData; |
| 55 |
|
| 56 |
/**
|
| 57 |
* NGPluginCoreFuncs: |
| 58 |
* @config_get_avail_servers: Get a list of all the available usenet servers. Needs to be free'd using config_free_avail_servers |
| 59 |
* @config_free_avail_servers: Free a list of usenet servers returned by config_get_avail_servers |
| 60 |
* @config_get_server_info: Retrieve information from a configured usenet server |
| 61 |
* @config_add_server: Add a new usenet server to the configuration |
| 62 |
* @config_del_server: Delete a usenet server from the configuration |
| 63 |
* @config_edit_server: Change an already configured usenet server |
| 64 |
* @config_get_opts: Retrieve general configuration parameters |
| 65 |
* @config_set_opts: Change general configuration parameters |
| 66 |
* @config_save: Save the configuration to disk |
| 67 |
* @config_get_folder_listing: Retrieve a list containing all the sub-folders which are in the given folder. Needs to be free'd using config_free_folder_listing |
| 68 |
* @config_free_folder_listing: Free a list of sub-folders |
| 69 |
* @config_get_config_folder: Retrieve the folder where all configuration files can be stored. Needs to be free'd using ng_free |
| 70 |
* @schedular_start: Start the schedular |
| 71 |
* @schedular_stop: Stop the schedular |
| 72 |
* @schedular_get_state: Retrieve the current state of the schedular |
| 73 |
* @schedular_add_file_to_queue: Add a file to the download queue |
| 74 |
* @schedular_del_file_from_queue: Remove a file from the download queue |
| 75 |
* @schedular_restart_file: Restart a file in the download queue |
| 76 |
* @schedular_save_queue: Force any changes in the download queue to be saved to disk |
| 77 |
* @schedular_foreach_file: Retrieve a list of all the items in the download queue (by using callback functions) |
| 78 |
* @schedular_move_file: Change the position of a file in the download queue |
| 79 |
* @schedular_move_collection: Change the position of a collection in the download queue |
| 80 |
* @schedular_mark_task_optional: Mark a task optional or non-optional |
| 81 |
* @plugins_get_avail_plugins: Retrieve a list of all the available plugins |
| 82 |
* @plugins_free_avail_plugins: Free a list as returned by the function plugins_get_avail_plugins |
| 83 |
* @plugins_get_plugin_info: Retrieve information about a specific plugin |
| 84 |
* @plugins_load_plugin: Load a plugin |
| 85 |
* @plugins_unload_plugin: Unload a plugin |
| 86 |
* @plugins_set_persistent: Indicate whether a plugin needs to be automatically loaded on startup |
| 87 |
* @plugins_call_plugin_method: Call a method of a plugin |
| 88 |
* @server_request_quit: Give a signal to the frontend that it must quit the program |
| 89 |
* @set_emit_log_messages: Indicate whether log messages should be emit |
| 90 |
* |
| 91 |
* Structure containing all the exported functions from the NNTPGrab Core |
| 92 |
* |
| 93 |
*/ |
| 94 |
typedef struct _ng_plugin_core_funcs { |
| 95 |
NGList *(*config_get_avail_servers) (void);
|
| 96 |
void (*config_free_avail_servers) (NGList *servers);
|
| 97 |
ngboolean (*config_get_server_info) (const char *servername, NGConfigServer *server); |
| 98 |
ngboolean (*config_add_server) (NGConfigServer new_server, char **errmsg);
|
| 99 |
ngboolean (*config_del_server) (const char *servername, char **errmsg); |
| 100 |
ngboolean (*config_edit_server) (const char *servername, NGConfigServer server, char **errmsg); |
| 101 |
NGConfigOpts (*config_get_opts) (void);
|
| 102 |
void (*config_set_opts) (NGConfigOpts opts);
|
| 103 |
ngboolean (*config_save) (char **errmsg);
|
| 104 |
char *(*config_get_config_folder) (void); |
| 105 |
ngboolean (*schedular_start) (void);
|
| 106 |
ngboolean (*schedular_stop) (const char *reason, ngboolean wait); |
| 107 |
NGSchedularState (*schedular_get_state) (void);
|
| 108 |
ngboolean (*schedular_add_file_to_queue) (const char *collection_name, const char *subject, const char *poster, time_t stamp, nguint64 file_size, NGList *groups, NGList *parts, char **errmsg); |
| 109 |
ngboolean (*schedular_del_file_from_queue) (const char *collection_name, const char *subject, char **errmsg); |
| 110 |
ngboolean (*schedular_restart_file) (const char *collection_name, const char *subject, char **errmsg); |
| 111 |
ngboolean (*schedular_save_queue) (char **errmsg);
|
| 112 |
void (*schedular_foreach_file) (ForeachCollectionFunc collection_func, ForeachFileFunc file_func, ForeachGroupFunc group_func, void *data); |
| 113 |
ngboolean (*schedular_move_file) (const char *collection_name_src, const char *subject_src, const char *collection_name_dest, int position_dest); |
| 114 |
ngboolean (*schedular_move_collection) (const char *collection_name, int new_position); |
| 115 |
ngboolean (*schedular_mark_task_optional) (const char *collection_name, const char *subject, ngboolean is_optional); |
| 116 |
NGList *(*plugins_get_avail_plugins) (void);
|
| 117 |
void (*plugins_free_avail_plugins) (NGList *plugins);
|
| 118 |
ngboolean (*plugins_get_plugin_info) (const char *plugin_name, NNTPGrabPluginInfo *plugin_info); |
| 119 |
ngboolean (*plugins_load_plugin) (const char *plugin_name, char **errmsg); |
| 120 |
ngboolean (*plugins_unload_plugin) (const char *plugin_name, char **errmsg); |
| 121 |
ngboolean (*plugins_set_persistent) (const char *plugin_name, ngboolean persistent); |
| 122 |
NGVariant *(*plugins_call_plugin_method) (const char *plugin_name, const char *method, NGVariant *parameters, char **errmsg); |
| 123 |
void (*server_request_quit) (void); |
| 124 |
void (*set_emit_log_messages) (ngboolean val);
|
| 125 |
} NGPluginCoreFuncs; |
| 126 |
|
| 127 |
/**
|
| 128 |
* NGPlugin: |
| 129 |
* @core_data: Internal information for the NNTPGrab Core. Must remain untouched |
| 130 |
* @core_funcs: Structure containing all the exported functions from the NNTPGrab Core |
| 131 |
* @priv: Plugin-specific data can be saved in this field |
| 132 |
* |
| 133 |
* Structure containing plugin information |
| 134 |
*/ |
| 135 |
typedef struct _ng_plugin { |
| 136 |
GObject parent; |
| 137 |
|
| 138 |
NGPluginCoreData *core_data; |
| 139 |
NGPluginCoreFuncs core_funcs; |
| 140 |
gpointer priv; |
| 141 |
} NGPlugin; |
| 142 |
|
| 143 |
#define NG_PLUGIN_FUNCTION(f) ((NGPluginFunction) (f))
|
| 144 |
typedef void (*NGPluginFunction) (void); |
| 145 |
|
| 146 |
/**
|
| 147 |
* ng_plugin_set_name: |
| 148 |
* @plugin_data: Structure containing plugin information |
| 149 |
* @name: Name of the plugin. Will be used to identify plugins. Must be unique |
| 150 |
* |
| 151 |
* Set the name of the plugin |
| 152 |
*/ |
| 153 |
void ng_plugin_set_name(NGPlugin *plugin_data, const char *name); |
| 154 |
|
| 155 |
/**
|
| 156 |
* ng_plugin_set_version: |
| 157 |
* @plugin_data: Structure containing plugin information |
| 158 |
* @version: Version of the plugin |
| 159 |
* |
| 160 |
* Set the version of the plugin |
| 161 |
*/ |
| 162 |
void ng_plugin_set_version(NGPlugin *plugin_data, const char *version); |
| 163 |
|
| 164 |
/**
|
| 165 |
* ng_plugin_set_author: |
| 166 |
* @plugin_data: Structure containing plugin information |
| 167 |
* @author: The name of the author(s) of this plugin |
| 168 |
* |
| 169 |
* Set the author of the plugin |
| 170 |
*/ |
| 171 |
void ng_plugin_set_author(NGPlugin *plugin_data, const char *author); |
| 172 |
|
| 173 |
/**
|
| 174 |
* ng_plugin_set_url: |
| 175 |
* @plugin_data: Structure containing plugin information |
| 176 |
* @url: Location where users can find out more information about this plugin |
| 177 |
* |
| 178 |
* Set the URL of the plugin |
| 179 |
*/ |
| 180 |
void ng_plugin_set_url(NGPlugin *plugin_data, const char *url); |
| 181 |
|
| 182 |
/**
|
| 183 |
* ng_plugin_set_description: |
| 184 |
* @plugin_data: Structure containing plugin information |
| 185 |
* @description: Description containing the functionality of this plugin |
| 186 |
* |
| 187 |
* Set the description of the plugin |
| 188 |
*/ |
| 189 |
void ng_plugin_set_description(NGPlugin *plugin_data, const char *description); |
| 190 |
|
| 191 |
/**
|
| 192 |
* ng_plugin_get_is_loaded: |
| 193 |
* @plugin_data: Structure containing plugin information |
| 194 |
* |
| 195 |
* Find out if the plugin is fully loaded at the moment |
| 196 |
* |
| 197 |
* Returns: TRUE when the plugin is fully loaded |
| 198 |
*/ |
| 199 |
ngboolean ng_plugin_get_is_loaded(NGPlugin *plugin_data); |
| 200 |
|
| 201 |
/**
|
| 202 |
* ng_plugin_register_function: |
| 203 |
* @plugin_data: Structure containing plugin information |
| 204 |
* @function_name: The name of the function. Must be unique |
| 205 |
* @impl: Pointer to the implementation of this function |
| 206 |
* @marshaller: The function to translate arrays of parameter values to proper parameters |
| 207 |
* @return_type: The return type of the function |
| 208 |
* @num_params: The number of arguments which this function expects |
| 209 |
* @...: A list of parameter types |
| 210 |
* |
| 211 |
* Create a new function which can be called from other plugins |
| 212 |
* |
| 213 |
* Returns: TRUE if the function was successfully registered, FALSE if it was already registered |
| 214 |
*/ |
| 215 |
ngboolean ng_plugin_register_function(NGPlugin *plugin_data, const char *function_name, NGPluginFunction impl, GSignalCMarshaller marshaller, GType return_type, int num_params, ...); |
| 216 |
|
| 217 |
/**
|
| 218 |
* ng_plugin_set_required_function: |
| 219 |
* @plugin_data: Structure containing plugin information |
| 220 |
* @function_name: The name of the function which this plugin requires for proper operation |
| 221 |
* |
| 222 |
* Indicate that the plugin requires a function from another plugin to function properly |
| 223 |
*/ |
| 224 |
void ng_plugin_set_required_function(NGPlugin *plugin_data, const char *function_name); |
| 225 |
|
| 226 |
/**
|
| 227 |
* ng_plugin_call: |
| 228 |
* @plugin_data: Structure containing plugin information |
| 229 |
* @function_name: The name of the function which needs to be called |
| 230 |
* @...: Variable number of arguments to pass on to the function. If a return value is expected, it must be the last argument |
| 231 |
* |
| 232 |
* Call a function from another plugin |
| 233 |
* |
| 234 |
* Returns: TRUE is the function has been called, FALSE if the function isn't registered |
| 235 |
*/ |
| 236 |
ngboolean ng_plugin_call(NGPlugin *plugin_data, const char *function_name, ...); |
| 237 |
|
| 238 |
/**
|
| 239 |
* ng_plugin_create_event: |
| 240 |
* @plugin_data: Structure containing plugin information |
| 241 |
* @event_name: The name of the event. Must be unique |
| 242 |
* @num_params: The number of arguments which this event expects |
| 243 |
* |
| 244 |
* Create a new event on which other plugins can register to |
| 245 |
* |
| 246 |
* Returns: TRUE if the event was successfully created, FALSE if it was already registered |
| 247 |
*/ |
| 248 |
ngboolean ng_plugin_create_event(NGPlugin *plugin_data, const char *event_name, int num_params); |
| 249 |
|
| 250 |
/**
|
| 251 |
* ng_plugin_set_required_event: |
| 252 |
* @plugin_data: Structure containing plugin information |
| 253 |
* @event_name: The name of the event which this plugin requires for proper operation |
| 254 |
* |
| 255 |
* Indicate that the plugin requires a event from another plugin to function properly |
| 256 |
*/ |
| 257 |
void ng_plugin_set_required_event(NGPlugin *plugin_data, const char *event_name); |
| 258 |
|
| 259 |
/**
|
| 260 |
* ng_plugin_connect_event: |
| 261 |
* @plugin_data: Structure containing plugin information |
| 262 |
* @event_name: The name of the event |
| 263 |
* @impl: The callback function which needs to be called when the event is emit |
| 264 |
* @user_data: Optional callback data |
| 265 |
* |
| 266 |
* Connect to an event exported from another plugin |
| 267 |
* |
| 268 |
* Returns: TRUE if the event was successfully connection. FALSE if the event_name isn't known |
| 269 |
*/ |
| 270 |
ngboolean ng_plugin_connect_event(NGPlugin *plugin_data, const char *event_name, NGPluginFunction impl, void *user_data); |
| 271 |
|
| 272 |
/**
|
| 273 |
* ng_plugin_disconnect_event_by_func: |
| 274 |
* @plugin_data: Structure containing plugin information |
| 275 |
* @impl: The callback function |
| 276 |
* @user_data: Optional callback data |
| 277 |
* |
| 278 |
* Disconnect an event handler |
| 279 |
* Most plugins don't need to use this function as it will be done automatically on unload |
| 280 |
* |
| 281 |
* Returns: TRUE if the event handler was successfully disconnected. FALSE if no connection exists |
| 282 |
*/ |
| 283 |
ngboolean ng_plugin_disconnect_event_by_func(NGPlugin *plugin_data, NGPluginFunction impl, void *user_data);
|
| 284 |
|
| 285 |
/**
|
| 286 |
* ng_plugin_emit_event: |
| 287 |
* @plugin_data: Structure containing plugin information |
| 288 |
* @event_name: The name of the event which needs to be emit |
| 289 |
* @params: NULL-terminated array of arguments to pass on to the event handlers |
| 290 |
* |
| 291 |
* Emit an event |
| 292 |
* |
| 293 |
* Returns: TRUE if the event was successfully emit. FALSE if the event_name isn't registered yet |
| 294 |
*/ |
| 295 |
ngboolean ng_plugin_emit_event(NGPlugin *plugin_data, const char *event_name, const char *params[]); |
| 296 |
|
| 297 |
/**
|
| 298 |
* ng_plugin_emit_log_msg: |
| 299 |
* @plugin_data: Structure containing plugin information |
| 300 |
* @log_level: The log level |
| 301 |
* @format: The format string |
| 302 |
* @...: Variable number of arguments containing data for the given format |
| 303 |
* |
| 304 |
* Emit a message for logging |
| 305 |
*/ |
| 306 |
void ng_plugin_emit_log_msg(NGPlugin *plugin_data, NGLogLevel log_level, const char *format, ...) G_GNUC_PRINTF(3, 4); |
| 307 |
|
| 308 |
G_END_DECLS |
| 309 |
|
| 310 |
#endif /* _NNTPGRAB_PLUGIN_H_ */ |
NNTPGrab

