]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/plugins/sd/main.c
4be52758c643259b996a876a2073a68830ab2c10
[bacula/bacula] / bacula / src / plugins / sd / main.c
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2007-2014 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20 /*
21  * Main program to test loading and running Bacula plugins.
22  *   Destined to become Bacula pluginloader, ...
23  *
24  * Kern Sibbald, October 2007
25  */
26 #include "bacula.h"
27 #include <dlfcn.h>
28 #include "lib/plugin.h"
29 #include "plugin-sd.h"
30
31 const char *plugin_type = "-sd.so";
32
33
34 /* Forward referenced functions */
35 static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value);
36 static bpError baculaSetValue(bpContext *ctx, bVariable var, void *value);
37
38
39 /* Bacula entry points */
40 static bFuncs bfuncs = {
41    sizeof(bFuncs),
42    PLUGIN_INTERFACE,
43    baculaGetValue,
44    baculaSetValue,
45    NULL,
46    NULL
47 };
48     
49
50
51
52 int main(int argc, char *argv[])
53 {
54    char plugin_dir[1000];
55    bpContext ctx;
56    bEvent event;
57    Plugin *plugin;
58     
59    b_plugin_list = New(alist(10, not_owned_by_alist));
60
61    ctx.bContext = NULL;
62    ctx.pContext = NULL;
63    getcwd(plugin_dir, sizeof(plugin_dir)-1);
64
65    load_plugins((void *)&bfuncs, plugin_dir, plugin_type);
66
67    foreach_alist(plugin, b_plugin_list) {
68       printf("bacula: plugin_size=%d plugin_version=%d\n", 
69               pref(plugin)->size, pref(plugin)->interface);
70       printf("License: %s\nAuthor: %s\nDate: %s\nVersion: %s\nDescription: %s\n",
71          pref(plugin)->plugin_license, pref(plugin)->plugin_author, 
72          pref(plugin)->plugin_date, pref(plugin)->plugin_version, 
73          pref(plugin)->plugin_description);
74
75       /* Start a new instance of the plugin */
76       pref(plugin)->newPlugin(&ctx);
77       event.eventType = bEventNewVolume;   
78       pref(plugin)->handlePluginEvent(&ctx, &event);
79       /* Free the plugin instance */
80       pref(plugin)->freePlugin(&ctx);
81
82       /* Start a new instance of the plugin */
83       pref(plugin)->newPlugin(&ctx);
84       event.eventType = bEventNewVolume;   
85       pref(plugin)->handlePluginEvent(&ctx, &event);
86       /* Free the plugin instance */
87       pref(plugin)->freePlugin(&ctx);
88    }
89
90    unload_plugins();
91
92    printf("bacula: OK ...\n");
93    close_memory_pool();
94    sm_dump(false);
95    return 0;
96 }
97
98 static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value)
99 {
100    printf("bacula: baculaGetValue var=%d\n", var);
101    if (value) {
102       *((int *)value) = 100;
103    }
104    return 0;
105 }
106
107 static bpError baculaSetValue(bpContext *ctx, bVariable var, void *value)
108 {
109    printf("bacula: baculaSetValue var=%d\n", var);
110    return 0;
111 }