Projekt

Allgemein

Profil

Herunterladen (5,68 KB) Statistiken
| Zweig: | Markierung: | Revision:
/****************************************************************************
* This file is part of the project AqFinance.
* AqFinance (c) by 2007 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif


#include "ae_p.h"

#include "plugins/db/dir/dbdir_l.h"


#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/pathmanager.h>
#include <gwenhywfar/plugin.h>
#include <gwenhywfar/misc.h>
#include <gwenhywfar/i18n.h>
#include <gwenhywfar/debug.h>


#ifdef OS_WIN32
# define DIRSEP "\\"
#else
# define DIRSEP "/"
#endif



static uint32_t ae_plugin_init_count=0;

static GWEN_PLUGIN_MANAGER *ae_pluginManagerImExporter=NULL;





int AE_DbFactory(const char *s, AEDB_DB **pDb) {
if (s && *s) {
GWEN_URL *url;
const char *p;
AEDB_DB *db=NULL;

url=GWEN_Url_fromString(s);
if (url==NULL) {
DBG_ERROR(AE_LOGDOMAIN, "Invalid URL");
return GWEN_ERROR_INVALID;
}

p=GWEN_Url_GetProtocol(url);
if (!p || *p==0) {
DBG_ERROR(AE_LOGDOMAIN, "No protocol in URL");
GWEN_Url_free(url);
return GWEN_ERROR_INVALID;
}

if (strcasecmp(p, "dir")==0)
db=AEDB_DbDir_new(s);
else {
DBG_ERROR(AE_LOGDOMAIN, "Module [%s] not found", p);
GWEN_Url_free(url);
return GWEN_ERROR_NOT_FOUND;
}
*pDb=db;
return 0;
}
else {
DBG_ERROR(AE_LOGDOMAIN, "Empty URL");
return GWEN_ERROR_INVALID;
}
}



static int initPlugins() {
if (ae_plugin_init_count==0) {
GWEN_PLUGIN_MANAGER *pm;

/* create bankinfo plugin manager */
DBG_INFO(AE_LOGDOMAIN, "Registering imexporter plugin manager");
pm=GWEN_PluginManager_new("ae_imexporter", AE_PM_LIBNAME);
if (GWEN_PluginManager_Register(pm)) {
DBG_ERROR(AE_LOGDOMAIN,
"Could not register imexporter plugin manager");
return GWEN_ERROR_GENERIC;
}

#if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
/* add folder relative to EXE */
GWEN_PluginManager_AddRelPath(pm,
AE_PM_LIBNAME,
AQFINANCE_PLUGINS
DIRSEP
AE_IMEXPORTER_PLUGIN_FOLDER,
GWEN_PathManager_RelModeExe);
#else
/* add absolute folder */
GWEN_PluginManager_AddPath(pm,
AE_PM_LIBNAME,
AQFINANCE_PLUGINS
DIRSEP
AE_IMEXPORTER_PLUGIN_FOLDER);
#endif
ae_pluginManagerImExporter=pm;
}
ae_plugin_init_count++;
return 0;
}



static int finiPlugins() {
if (ae_plugin_init_count==0) {
DBG_ERROR(AE_LOGDOMAIN, "Plugins not initialized");
return GWEN_ERROR_INVALID;
}

if (ae_plugin_init_count==1) {
/* unregister and unload imexporter plugin manager */
if (ae_pluginManagerImExporter) {
if (GWEN_PluginManager_Unregister(ae_pluginManagerImExporter)) {
DBG_ERROR(AE_LOGDOMAIN,
"Could not unregister imexporter plugin manager");
}
GWEN_PluginManager_free(ae_pluginManagerImExporter);
ae_pluginManagerImExporter=NULL;
}
}
ae_plugin_init_count--;

return 0;
}



int AE_Init() {
int rv;
const char *s;

rv=GWEN_Init();
if (rv) {
DBG_ERROR_ERR(AE_LOGDOMAIN, rv);
return rv;
}
if (!GWEN_Logger_IsOpen(AE_LOGDOMAIN)) {
GWEN_Logger_Open(AE_LOGDOMAIN,
"aqfinance", 0,
GWEN_LoggerType_Console,
GWEN_LoggerFacility_User);
}

s=getenv("AE_LOGLEVEL");
if (s && *s) {
GWEN_LOGGER_LEVEL ll;

ll=GWEN_Logger_Name2Level(s);
GWEN_Logger_SetLevel(AE_LOGDOMAIN, ll);
}
else
GWEN_Logger_SetLevel(AE_LOGDOMAIN, GWEN_LoggerLevel_Notice);

DBG_INFO(AE_LOGDOMAIN,
"AqFinance v"
AF_VERSION_FULL_STRING
" (compiled at "
COMPILE_DATETIME
"): initialising");

/* define locale paths */
GWEN_PathManager_DefinePath(AE_PM_LIBNAME, AE_PM_LOCALEDIR);
#if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
/* add folder relative to EXE */
GWEN_PathManager_AddRelPath(AE_PM_LIBNAME,
AE_PM_LIBNAME,
AE_PM_LOCALEDIR,
LOCALEDIR,
GWEN_PathManager_RelModeExe);
#else
/* add absolute folder */
GWEN_PathManager_AddPath(AE_PM_LIBNAME,
AE_PM_LIBNAME,
AE_PM_LOCALEDIR,
LOCALEDIR);
#endif

/* define data paths */
GWEN_PathManager_DefinePath(AE_PM_LIBNAME, AE_PM_DATADIR);
#if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
/* add folder relative to EXE */
GWEN_PathManager_AddRelPath(AE_PM_LIBNAME,
AE_PM_LIBNAME,
AE_PM_DATADIR,
AQFINANCE_DATA_DIR,
GWEN_PathManager_RelModeExe);
#else
/* add absolute folder */
GWEN_PathManager_AddPath(AE_PM_LIBNAME,
AE_PM_LIBNAME,
AE_PM_DATADIR,
AQFINANCE_DATA_DIR);
#endif

if (1) {
GWEN_STRINGLIST *sl=GWEN_PathManager_GetPaths(AE_PM_LIBNAME,
AE_PM_LOCALEDIR);
const char *localedir=GWEN_StringList_FirstString(sl);

rv=GWEN_I18N_BindTextDomain_Dir(PACKAGE, localedir);
if (rv) {
DBG_ERROR(AE_LOGDOMAIN, "Could not bind textdomain (%d)", rv);
}
else {
rv=GWEN_I18N_BindTextDomain_Codeset(PACKAGE, "UTF-8");
if (rv) {
DBG_ERROR(AE_LOGDOMAIN, "Could not set codeset (%d)", rv);
}
}

GWEN_StringList_free(sl);
}

rv=initPlugins();
if (rv<0) {
DBG_INFO(AE_LOGDOMAIN, "here (%d)", rv);
AE_Fini();
return rv;
}

return 0;
}



int AE_Fini() {
finiPlugins();
/* undefine our own paths */
GWEN_PathManager_UndefinePath(AE_PM_LIBNAME, AE_PM_LOCALEDIR);
GWEN_PathManager_UndefinePath(AE_PM_LIBNAME, AE_PM_DATADIR);
/* remove AqBanking additions to all pathmanagers */
GWEN_PathManager_RemovePaths(AE_PM_LIBNAME);
GWEN_Logger_Close(AE_LOGDOMAIN);
GWEN_Fini();
return 0;
}


(2-2/6)