Lumiera  0.pre.03
»edit your freedom«
plugin-dynlib.c
Go to the documentation of this file.
1 /*
2  PluginDynlib - Lumiera Plugin loader for dynamic libraries
3 
4  Copyright (C) Lumiera.org
5  2008, Christian Thaeter <ct@pipapo.org>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
28 #include "include/logging.h"
29 #include "lib/tmpbuf.h"
30 #include "common/plugin.h"
31 
32 #include <dlfcn.h>
33 #include <nobug.h>
34 
35 
36 LumieraPlugin
37 lumiera_plugin_load_DYNLIB (const char* name)
38 {
39  TRACE (pluginloader_dbg, "load DYNLIB: %s", name);
40  REQUIRE (name);
41  LumieraPlugin self = lumiera_plugin_new (name);
42  LumieraInterface plugin = NULL;
43 
44  void* handle = dlopen (name, RTLD_LAZY|RTLD_LOCAL);
45  if (handle)
46  {
47  plugin = (LumieraInterface) dlsym (handle, LUMIERA_INTERFACE_DSTRING (lumieraorg__plugin, 0, lumieraorg_plugin));
48 
49  if (!plugin)
50  LUMIERA_ERROR_SET (pluginloader, PLUGIN_WTF, name);
51  }
52  else
53  LUMIERA_ERROR_SET (pluginloader_dbg, PLUGIN_OPEN, lumiera_tmpbuf_snprintf (4096, "%s: %s", name, dlerror()));
54 
55  return lumiera_plugin_init (self, handle, plugin);
56 }
57 
58 
59 void
60 lumiera_plugin_unload_DYNLIB (LumieraPlugin self)
61 {
62  TRACE (pluginloader_dbg);
63  void* handle = lumiera_plugin_handle (self);
64  if (handle)
65  dlclose (handle);
67 }
#define LUMIERA_ERROR_SET(flag, err, extra)
Helper macro to raise an error for the current thread.
Definition: error.h:91
LumieraPlugin lumiera_plugin_new(const char *name)
Allocates an preinitialises a plugin structure.
Definition: plugin.c:132
Lumiera plugins define &#39;interfaces&#39; as shown in interface.h, the plugin system handles the loading of...
This header is for including and configuring NoBug.
Round robin temporary buffers.
LumieraPlugin lumiera_plugin_init(LumieraPlugin self, void *handle, LumieraInterface plugin)
Definition: plugin.c:148
#define LUMIERA_INTERFACE_DSTRING(iname, version, dname)
Construct a definition string for an interface.
Definition: interface.h:120
void * lumiera_plugin_handle(LumieraPlugin self)
Query the plugin handle.
Definition: plugin.c:166
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption
char * lumiera_tmpbuf_snprintf(size_t size, const char *fmt,...)
Construct a string in a tmpbuf.
Definition: tmpbuf.c:125