1 /* testgmodule.c - test program for GMODULE
2 * Copyright (C) 1998 Tim Janik
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 g_print ("GModule: Hello global clash\n");
29 typedef void (*SimpleFunc) (void);
30 typedef void (*GModuleFunc) (GModule *);
32 SimpleFunc gplugin_clash_func;
38 GModule *module_self, *module_a, *module_b;
40 gchar *plugin_a, *plugin_b;
41 SimpleFunc f_a, f_b, f_self;
44 string = g_get_current_dir ();
45 g_print ("testgmodule (%s):\n", string);
47 plugin_a = g_strconcat (string, "/.libs/", "libgplugin_a.so", NULL);
48 plugin_b = g_strconcat (string, "/.libs/", "libgplugin_b.so", NULL);
53 g_print ("get main module handle\n");
54 module_self = g_module_open (NULL, G_MODULE_BIND_LAZY);
57 g_print ("error: %s\n", g_module_error ());
60 g_print ("load plugin from \"%s\"\n", plugin_a);
61 module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY);
64 g_print ("error: %s\n", g_module_error ());
67 g_print ("load plugin from \"%s\"\n", plugin_b);
68 module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY);
71 g_print ("error: %s\n", g_module_error ());
75 /* get plugin specific symbols and call them
77 string = "gplugin_a_func";
78 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
79 if (!g_module_symbol (module_a, string, (gpointer) &f_a))
81 g_print ("error: %s\n", g_module_error ());
84 string = "gplugin_b_func";
85 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
86 if (!g_module_symbol (module_b, string, (gpointer) &f_b))
88 g_print ("error: %s\n", g_module_error ());
91 g_print ("call plugin function(%p) A: ", f_a);
93 g_print ("call plugin function(%p) B: ", f_b);
96 /* get and call globally clashing functions
98 string = "g_clash_func";
99 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_self)));
100 if (!g_module_symbol (module_self, string, (gpointer) &f_self))
102 g_print ("error: %s\n", g_module_error ());
105 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
106 if (!g_module_symbol (module_a, string, (gpointer) &f_a))
108 g_print ("error: %s\n", g_module_error ());
111 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
112 if (!g_module_symbol (module_b, string, (gpointer) &f_b))
114 g_print ("error: %s\n", g_module_error ());
117 g_print ("call plugin function(%p) self: ", f_self);
119 g_print ("call plugin function(%p) A: ", f_a);
121 g_print ("call plugin function(%p) B: ", f_b);
124 /* get and call clashing plugin functions
126 string = "gplugin_clash_func";
127 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
128 if (!g_module_symbol (module_a, string, (gpointer) &f_a))
130 g_print ("error: %s\n", g_module_error ());
133 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
134 if (!g_module_symbol (module_b, string, (gpointer) &f_b))
136 g_print ("error: %s\n", g_module_error ());
139 g_print ("call plugin function(%p) A: ", f_a);
140 gplugin_clash_func = f_a;
141 gplugin_clash_func ();
142 g_print ("call plugin function(%p) B: ", f_b);
143 gplugin_clash_func = f_b;
144 gplugin_clash_func ();
146 /* call gmodule function form A
148 string = "gplugin_a_module_func";
149 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
150 if (!g_module_symbol (module_a, string, (gpointer) &gmod_f))
152 g_print ("error: %s\n", g_module_error ());
155 g_print ("call plugin A's module function(%p):\n{\n", gmod_f);
162 g_print ("unload plugin A:\n");
163 if (!g_module_close (module_a))
164 g_print ("error: %s\n", g_module_error ());
165 g_print ("unload plugin B:\n");
166 if (!g_module_close (module_b))
167 g_print ("error: %s\n", g_module_error ());
170 g_log_set_fatal_mask ("GModule", G_LOG_FATAL_MASK|G_LOG_LEVEL_WARNING);
171 g_module_symbol (0, 0, 0);
173 g_on_error_query (".libs/testgmodule");