Yattm - unified GTK instant-messaging client logo
   [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003]

Home - Main Page - Data Structures - File List - Data Fields - Globals

plugin.h File Reference

#include <ltdl.h>
#include "plugin_api.h"

Include dependency graph for plugin.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  callback_data
struct  eb_PLUGIN_INFO
struct  menu_data
struct  menu_item_data

Defines

#define EB_PLUGIN_LIST   "PLUGIN::LIST"

Typedefs

typedef void(* menu_func )()

Enumerations

enum  PLUGIN_STATUS { PLUGIN_NOT_LOADED, PLUGIN_LOADED, PLUGIN_CANNOT_LOAD, PLUGIN_NO_STATUS }

Functions

eb_PLUGIN_INFOFindPluginByName (char *name)
eb_PLUGIN_INFOFindPluginByService (char *service)
int unload_module (eb_PLUGIN_INFO *epi)
void unload_modules ()
int load_module (char *path, char *name)
void load_modules ()
int load_service_plugin (lt_dlhandle Module, PLUGIN_INFO *info, char *name)
int load_utility_plugin (lt_dlhandle Module, PLUGIN_INFO *info, char *name)
int load_log_plugin (lt_dlhandle Module, PLUGIN_INFO *info, char *name)
int load_sound_plugin (lt_dlhandle Module, PLUGIN_INFO *info, char *name)
int load_gui_plugin (lt_dlhandle Module, PLUGIN_INFO *info, char *name)
int init_menus ()

Variables

char * PLUGIN_TYPE_TXT []
char * PLUGIN_STATUS_TXT []


Define Documentation

#define EB_PLUGIN_LIST   "PLUGIN::LIST"
 

Definition at line 28 of file plugin.h.

Referenced by build_modules_list(), FindLoadedPluginByService(), FindPluginByHandle(), FindPluginByName(), SetPluginInfo(), unload_modules(), and write_module_prefs().


Typedef Documentation

typedef void(* menu_func)()
 

Definition at line 64 of file plugin.h.

Referenced by init_menu().


Enumeration Type Documentation

enum PLUGIN_STATUS
 

Enumeration values:
PLUGIN_NOT_LOADED 
PLUGIN_LOADED 
PLUGIN_CANNOT_LOAD 
PLUGIN_NO_STATUS 

Definition at line 33 of file plugin.h.

Referenced by SetPluginInfo().


Function Documentation

eb_PLUGIN_INFO* FindPluginByName char *    name
 

Definition at line 83 of file plugin.c.

References compare_plugin_name(), EB_PLUGIN_LIST, and GetPref().

Referenced by load_module(), plugin_selected(), and SetPluginInfo().

00084 {
00085     GList *plugins=GetPref(EB_PLUGIN_LIST);
00086     GList *PluginData = g_list_find_custom(plugins, name, compare_plugin_name);
00087     if(PluginData)
00088         return(PluginData->data);
00089     return(NULL);
00090 }

eb_PLUGIN_INFO* FindPluginByService char *    service
 

int init_menus  
 

Definition at line 430 of file plugin.c.

References EB_CHAT_WINDOW_MENU, EB_CONTACT_MENU, EB_IMPORT_MENU, EB_PROFILE_MENU, ebmCONTACTDATA, ebmIMPORTDATA, ebmPROFILEDATA, and init_menu().

Referenced by main().

00431 {
00432     init_menu(EB_PROFILE_MENU, rebuild_profile_menu, ebmPROFILEDATA);
00433     init_menu(EB_IMPORT_MENU, rebuild_import_menu, ebmIMPORTDATA);
00434     /* The chat window menu is dynamically redrawn */
00435     init_menu(EB_CHAT_WINDOW_MENU, NULL, ebmCONTACTDATA);
00436     init_menu(EB_CONTACT_MENU, NULL, ebmCONTACTDATA);
00437     return(0);
00438 }

int load_gui_plugin lt_dlhandle    Module,
PLUGIN_INFO   info,
char *    name
 

Definition at line 411 of file plugin.c.

Referenced by load_module().

00412 {
00413     return(1);
00414 }

int load_log_plugin lt_dlhandle    Module,
PLUGIN_INFO   info,
char *    name
 

Definition at line 401 of file plugin.c.

Referenced by load_module().

00402 {
00403     return(1);
00404 }

int load_module char *    path,
char *    name
 

Definition at line 200 of file plugin.c.

References _, DBG_CORE, eb_debug, FindPluginByName(), load_gui_plugin(), load_log_plugin(), load_service_plugin(), load_sound_plugin(), load_utility_plugin(), PLUGIN_CANNOT_LOAD, PLUGIN_GUI, PLUGIN_LOADED, PLUGIN_LOG, PLUGIN_SERVICE, PLUGIN_SOUND, PLUGIN_UTILITY, SetPluginInfo(), eb_PLUGIN_INFO::status, and PLUGIN_INFO::type.

Referenced by load_modules(), and reload_plugin_callback().

00201 {
00202     char full_path[1024];
00203     lt_dlhandle Module;
00204     PLUGIN_INFO *plugin_info=NULL;
00205     eb_PLUGIN_INFO *epi=NULL;
00206 
00207     sprintf(full_path, "%s/%s", path, name);
00208     eb_debug(DBG_CORE, "Opening module: %s\n", full_path);
00209     Module = lt_dlopen(full_path);
00210     eb_debug(DBG_CORE, "Module: %p\n", Module);
00211 
00212     /* Find out if this plugin is already loaded */
00213     if(!Module) {
00214         /* Only update status on a plugin that is not already loaded */
00215         SetPluginInfo(NULL, full_path, NULL, PLUGIN_CANNOT_LOAD, lt_dlerror(), NULL, FALSE);
00216         return(-1);
00217     }
00218     plugin_info = (PLUGIN_INFO *)lt_dlsym(Module, "plugin_info");
00219     if(!plugin_info) {
00220         lt_dlclose(Module);
00221         /* Only update status on a plugin that is not already loaded */
00222         SetPluginInfo(NULL, full_path, NULL, PLUGIN_CANNOT_LOAD, _("Cannot resolve symbol plugin_info"), NULL, FALSE);
00223         return(-1);
00224     }
00225     epi=FindPluginByName(full_path);
00226     if(epi && epi->status==PLUGIN_LOADED) {
00227         lt_dlclose(Module);
00228         eb_debug(DBG_CORE, "Not loading already loaded module %s\n", name);
00229         return(-1);
00230     }
00231     switch(plugin_info->type) {
00232     case PLUGIN_SERVICE:
00233         load_service_plugin(Module, plugin_info, full_path);
00234         break;
00235     case PLUGIN_UTILITY:
00236         load_utility_plugin(Module, plugin_info, full_path);
00237         break;
00238     case PLUGIN_SOUND:
00239         load_sound_plugin(Module, plugin_info, full_path);
00240         break;
00241     case PLUGIN_LOG:
00242         load_log_plugin(Module, plugin_info, full_path);
00243         break;
00244     case PLUGIN_GUI:
00245         load_gui_plugin(Module, plugin_info, full_path);
00246         break;
00247     default:
00248         break;
00249     }
00250     return(0);
00251 }

void load_modules  
 

Definition at line 254 of file plugin.c.

00255 {
00256     /* UNUSED struct dirent **namelist=NULL; */
00257     char buf[1024], *modules_path=NULL, *cur_path=NULL;
00258     char *tok_buf=NULL, *tok_buf_old=NULL;
00259     int n=0, success=0;
00260     struct dirent *dp;
00261     DIR *dirp;
00262 
00263     eb_debug(DBG_CORE, ">Entering\n");
00264     modules_path=g_strdup(cGetLocalPref("modules_path"));
00265     tok_buf = g_new0(char, strlen(modules_path)+1);
00266     /* Save the old pointer, because strtok_r will change it */
00267     tok_buf_old=tok_buf;
00268     lt_dlinit();
00269     lt_dlsetsearchpath(modules_path);
00270 
00271     /* Use a thread-safe strtok */
00272 #ifdef HAVE_STRTOK_R
00273     cur_path=strtok_r(modules_path, ":", &tok_buf);
00274 #else
00275     cur_path=strtok(modules_path, ":");
00276 #endif
00277     if(!cur_path)
00278         cur_path=MODULE_DIR;
00279     do {
00280         if((dirp = opendir(cur_path)) == NULL)
00281         {
00282             sprintf(buf, _("Cannot open module directory \"%s\""), cur_path);
00283             do_error_dialog(buf, _("Warning"));
00284             buf[0] = '\0';
00285             break;
00286         }
00287         n = 0;
00288         while((dp = readdir(dirp)) != NULL)
00289         {
00290             if( dp == NULL )
00291             {
00292                 sprintf(buf, _("Looking for modules in %s"), cur_path);
00293                 perror(buf);
00294                 continue;
00295             }
00296             else if( select_module_entry( dp ) )
00297             {
00298                 n++;
00299                 success = load_module(cur_path, dp->d_name);
00300             }
00301         }
00302         if( n == 0 )
00303         {
00304             eb_debug(DBG_CORE, "<No modules found in %s, returning.\n", cur_path);
00305         }
00306         else
00307         {
00308             eb_debug(DBG_CORE, "Loaded %d modules from %s.\n", n, cur_path);
00309         }
00310         closedir(dirp);
00311 #ifdef HAVE_STRTOK_R
00312     } while((cur_path=strtok_r(NULL, ":", &tok_buf)));
00313 #else
00314     } while((cur_path=strtok(NULL, ":")));
00315 #endif
00316 
00317     g_free(modules_path);
00318     g_free(tok_buf_old);
00319     eb_debug(DBG_CORE, "Adding idle_check\n");
00320     add_idle_check();
00321     eb_debug(DBG_CORE, "<End services_init\n");
00322 }

int load_service_plugin lt_dlhandle    Module,
PLUGIN_INFO   info,
char *    name
 

Definition at line 324 of file plugin.c.

References _, add_service(), PLUGIN_INFO::brief_desc, DBG_CORE, DBG_MOD, eb_debug, eb_update_from_value_pair(), FindLoadedPluginByService(), GetPref(), PLUGIN_INFO::init, service::name, PLUGIN_CANNOT_LOAD, PLUGIN_LOADED, PLUGIN_INFO::prefs, service::sc, SetPluginInfo(), eb_PLUGIN_INFO::status, and _input_list::widget.

Referenced by load_module().

00325 {
00326     struct service *Service_Info=NULL;
00327     struct service_callbacks *(*query_callbacks)();
00328     int service_id=-1;
00329     eb_PLUGIN_INFO *epi=NULL;
00330     GList *user_prefs=NULL;
00331 
00332     Service_Info = lt_dlsym(Module, "SERVICE_INFO");
00333     eb_debug(DBG_CORE, "SERVICE_INFO: %p\n", Service_Info);
00334     if(!Service_Info) {
00335         SetPluginInfo(info, name, NULL, PLUGIN_CANNOT_LOAD, _("Unable to resolve symbol SERVICE_INFO"), NULL, FALSE);
00336         lt_dlclose(Module);
00337         return(-1);
00338     }
00339     /* Don't load this module if there's a service of this type already loaded */
00340     epi=FindLoadedPluginByService(Service_Info->name);
00341     if(epi && epi->status==PLUGIN_LOADED) {
00342         fprintf(stderr, _("Not loading module %s, a module for that service is already loaded!\n"), name);
00343         SetPluginInfo(info, name, NULL, PLUGIN_CANNOT_LOAD, _("Service provided by an already loaded plugin"), Service_Info->name, FALSE);
00344         lt_dlclose(Module);
00345         return(-1);
00346     }
00347     /* No more hard-coded service_id numbers */
00348     query_callbacks = lt_dlsym(Module, "query_callbacks");
00349     if(!query_callbacks) {
00350         SetPluginInfo(info, name, NULL, PLUGIN_CANNOT_LOAD, "Unable to resolve symbol query_callbacks", Service_Info->name, FALSE);
00351         lt_dlclose(Module);
00352         return(-1);
00353     }
00354     if(info->init) {
00355         eb_debug(DBG_CORE, "Executing init for %s\n", info->brief_desc);
00356         info->init();
00357     }
00358     if(info->prefs) {
00359         user_prefs=GetPref(name);
00360         if(user_prefs) {
00361             eb_update_from_value_pair(info->prefs, user_prefs);
00362         }
00363         eb_debug(DBG_MOD, "prefs name: %s\n", info->prefs->widget.entry.name);
00364     }
00365     Service_Info->sc=query_callbacks();
00366     /* The callbacks are defined by the SERVICE_INFO struct in each module */
00367     service_id = add_service(Service_Info);
00368     SetPluginInfo(info, name, Module, PLUGIN_LOADED, "", Service_Info->name, TRUE);
00369     eb_debug(DBG_CORE, "Added module:%s, service: %s\n", name, eb_services[service_id].name);
00370     eb_debug(DBG_CORE, "eb_services[%i].sc->read_local_account_config: %p\n", service_id, eb_services[service_id].sc->read_local_account_config);
00371     return(0);
00372 }

int load_sound_plugin lt_dlhandle    Module,
PLUGIN_INFO   info,
char *    name
 

Definition at line 406 of file plugin.c.

Referenced by load_module().

00407 {
00408     return(1);
00409 }

int load_utility_plugin lt_dlhandle    Module,
PLUGIN_INFO   info,
char *    name
 

Definition at line 374 of file plugin.c.

References _, PLUGIN_INFO::brief_desc, DBG_CORE, DBG_MOD, do_error_dialog(), eb_debug, eb_update_from_value_pair(), GetPref(), PLUGIN_INFO::init, PLUGIN_CANNOT_LOAD, PLUGIN_LOADED, PLUGIN_INFO::prefs, SetPluginInfo(), and _input_list::widget.

Referenced by load_module().

00375 {
00376     char buf[1024];
00377     GList *user_prefs=NULL;
00378 
00379     eb_debug(DBG_CORE, ">\n");
00380     if(!info->init) {
00381         SetPluginInfo(info, name, NULL, PLUGIN_CANNOT_LOAD, _("No init function defined"), NULL, FALSE);
00382         lt_dlclose(Module);
00383         sprintf(buf, _("init function not defined for utility module %s, unloading module\n"), name);
00384         do_error_dialog(buf, _("Warning"));
00385         return(-1);
00386     }
00387     eb_debug(DBG_CORE, "Executing init for %s\n", info->brief_desc);
00388     info->init();
00389     if(info->prefs) {
00390         user_prefs=GetPref(name);
00391         if(user_prefs) {
00392             eb_update_from_value_pair(info->prefs, user_prefs);
00393         }
00394         eb_debug(DBG_MOD, "prefs name: %s\n", info->prefs->widget.entry.name);
00395     }
00396     SetPluginInfo(info, name, Module, PLUGIN_LOADED, "", NULL, TRUE);
00397     eb_debug(DBG_CORE, "<\n");
00398     return(0);
00399 }

int unload_module eb_PLUGIN_INFO   epi
 

Definition at line 159 of file plugin.c.

References _, add_service(), DBG_CORE, do_error_dialog(), eb_debug, eb_nomodule_query_callbacks(), PLUGIN_INFO::finish, eb_PLUGIN_INFO::Module, eb_PLUGIN_INFO::name, eb_PLUGIN_INFO::pi, PLUGIN_NOT_LOADED, PLUGIN_INFO::prefs, service::sc, eb_PLUGIN_INFO::service, and eb_PLUGIN_INFO::status.

Referenced by reload_plugin_callback(), unload_modules(), and unload_plugin_callback().

00160 {
00161     int error=0;
00162     char buf[1024];
00163 
00164     eb_debug(DBG_CORE, ">Unloading plugin %s\n", epi->name);
00165     /* This is a service plugin, special handling required */
00166     if(epi->pi.finish) {
00167         eb_debug(DBG_CORE, "Calling plugins finish function\n");
00168         error=epi->pi.finish();
00169         if(error) {
00170             sprintf(buf, _("Unable to unload plugin %s, still in use?\n"), epi->name);
00171             do_error_dialog(buf, _("Error"));
00172             eb_debug(DBG_CORE, "<Plugin failed to unload\n");
00173             return(-1);
00174         }
00175     }
00176     if(epi->service) {
00177         struct service SERVICE_INFO = { strdup(epi->service), -1, FALSE, FALSE, FALSE, FALSE, NULL };
00178 
00179         SERVICE_INFO.sc=eb_nomodule_query_callbacks();
00180         add_service(&SERVICE_INFO);
00181     }
00182     epi->status=PLUGIN_NOT_LOADED;
00183     epi->pi.prefs=NULL;
00184     eb_debug(DBG_CORE, "Closing plugin\n");
00185     if(lt_dlclose(epi->Module)) {
00186         fprintf(stderr, "Error closing plugin: %s\n", lt_dlerror());
00187     }
00188     eb_debug(DBG_CORE, "<Plugin unloaded\n");
00189     return(0);
00190 
00191 }

void unload_modules  
 

Definition at line 193 of file plugin.c.

References EB_PLUGIN_LIST, GetPref(), and unload_module().

Referenced by main().

00193                           {
00194     GList *plugins=GetPref(EB_PLUGIN_LIST);
00195     for(plugins=GetPref(EB_PLUGIN_LIST); plugins; plugins=plugins->next) {
00196         unload_module(plugins->data);
00197     }
00198 }


Variable Documentation

char* PLUGIN_STATUS_TXT[]
 

Definition at line 31 of file plugin.h.

char* PLUGIN_TYPE_TXT[]
 

Definition at line 30 of file plugin.h.


Contact: Andy Maloney     [Documentation generated by doxygen]