]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/plugins/fd/example-plugin-fd.c
More plugin implementation
[bacula/bacula] / bacula / src / plugins / fd / example-plugin-fd.c
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2008 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation, which is 
11    listed in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of John Walker.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  * Sample Plugin program
30  *
31  *  Kern Sibbald, October 2007
32  *
33  */
34 #include <stdio.h>
35 #include "fd-plugins.h"
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 #define PLUGIN_LICENSE      "GPL"
42 #define PLUGIN_AUTHOR       "Kern Sibbald"
43 #define PLUGIN_DATE         "January 2008"
44 #define PLUGIN_VERSION      "1"
45 #define PLUGIN_DESCRIPTION  "Test File Daemon Plugin"
46
47 /* Forward referenced functions */
48 static bpError newPlugin(bpContext *ctx);
49 static bpError freePlugin(bpContext *ctx);
50 static bpError getPluginValue(bpContext *ctx, pVariable var, void *value);
51 static bpError setPluginValue(bpContext *ctx, pVariable var, void *value);
52 static bpError handlePluginEvent(bpContext *ctx, bEvent *event, void *value);
53
54
55 /* Pointers to Bacula functions */
56 static bFuncs *bfuncs = NULL;
57 static bInfo  *binfo = NULL;
58
59 static pInfo pluginInfo = {
60    sizeof(pluginInfo),
61    PLUGIN_INTERFACE_VERSION,
62    PLUGIN_MAGIC,
63    PLUGIN_LICENSE,
64    PLUGIN_AUTHOR,
65    PLUGIN_DATE,
66    PLUGIN_VERSION,
67    PLUGIN_DESCRIPTION,
68 };
69
70 static pFuncs pluginFuncs = {
71    sizeof(pluginFuncs),
72    PLUGIN_INTERFACE_VERSION,
73
74    /* Entry points into plugin */
75    newPlugin,                         /* new plugin instance */
76    freePlugin,                        /* free plugin instance */
77    getPluginValue,
78    setPluginValue,
79    handlePluginEvent
80 };
81
82 bpError loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs)
83 {
84    bfuncs = lbfuncs;                  /* set Bacula funct pointers */
85    binfo  = lbinfo;
86    printf("plugin: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version);
87
88    *pinfo  = &pluginInfo;             /* return pointer to our info */
89    *pfuncs = &pluginFuncs;            /* return pointer to our functions */
90
91    return 0;
92 }
93
94 bpError unloadPlugin() 
95 {
96    printf("plugin: Unloaded\n");
97    return 0;
98 }
99
100 static bpError newPlugin(bpContext *ctx)
101 {
102    int JobId = 0;
103    bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
104 // printf("plugin: newPlugin JobId=%d\n", JobId);
105    bfuncs->registerBaculaEvents(ctx, 1, 2, 0);
106    return 0;
107 }
108
109 static bpError freePlugin(bpContext *ctx)
110 {
111    int JobId = 0;
112    bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
113 // printf("plugin: freePlugin JobId=%d\n", JobId);
114    return 0;
115 }
116
117 static bpError getPluginValue(bpContext *ctx, pVariable var, void *value) 
118 {
119 // printf("plugin: getPluginValue var=%d\n", var);
120    return 0;
121 }
122
123 static bpError setPluginValue(bpContext *ctx, pVariable var, void *value) 
124 {
125 // printf("plugin: setPluginValue var=%d\n", var);
126    return 0;
127 }
128
129 static bpError handlePluginEvent(bpContext *ctx, bEvent *event, void *value)
130 {
131    char *name;
132    switch (event->eventType) {
133    case bEventJobStart:
134       printf("plugin: JobStart=%s\n", (char *)value);
135       break;
136    case bEventJobEnd:
137       printf("plugin: JobEnd\n");
138       break;
139    case bEventBackupStart:
140       printf("plugin: BackupStart\n");
141       break;
142    case bEventBackupEnd:
143       printf("plugin: BackupEnd\n");
144       break;
145    case bEventPluginCommand:
146       printf("plugin: command=%s\n", (char *)value);
147       break;
148    case bEventLevel:
149       printf("plugin: JobLevel=%c %d\n", (int)value, (int)value);
150       break;
151    case bEventSince:
152       printf("plugin: since=%d\n", (int)value);
153       break;
154    default:
155       printf("plugin: unknown event=%d\n", event->eventType);
156    }
157    bfuncs->getBaculaValue(ctx, bVarFDName, (void *)&name);
158 // printf("FD Name=%s\n", name);
159 // bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message");
160 // bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");
161    return 0;
162 }
163
164 #ifdef __cplusplus
165 }
166 #endif