From 643ec4a83a2480aaf33c3581ff90b073cd0ce06a Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 2 Jan 2008 14:34:52 +0000 Subject: [PATCH] A little work on FD plugin git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6179 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/plugins/fd/Makefile | 14 ++--- .../fd/{plugin-fd.c => example-plugin-fd.c} | 7 ++- bacula/src/plugins/fd/main.c | 51 ++++++++++++++++--- bacula/src/plugins/fd/plugin-fd.h | 22 ++++---- 4 files changed, 68 insertions(+), 26 deletions(-) rename bacula/src/plugins/fd/{plugin-fd.c => example-plugin-fd.c} (94%) diff --git a/bacula/src/plugins/fd/Makefile b/bacula/src/plugins/fd/Makefile index 96776447bf..6d6e68830a 100644 --- a/bacula/src/plugins/fd/Makefile +++ b/bacula/src/plugins/fd/Makefile @@ -9,20 +9,16 @@ CC = g++ -g -O0 -Wall .c.o: $(CC) -I../.. -DTEST_PROGRAM -c $< -all: main plugin-fd.so +all: main example-plugin-fd.so main: main.o plugin-fd.h $(CC) -L../../lib main.o -o main -lbac -lpthread -lssl -l crypto -ldl -plugin-fd.o: plugin-fd.c plugin-fd.h - $(CC) -fPIC -I../.. -c plugin-fd.c +example-plugin-fd.o: example-plugin-fd.c plugin-fd.h + $(CC) -fPIC -I../.. -c example-plugin-fd.c -plugin.o: plugin.c plugin.h - $(CC) -fPIC -I../.. -c plugin.c - - -plugin-fd.so: plugin-fd.o - $(CC) -shared plugin-fd.o -o plugin-fd.so +example-plugin-fd.so: example-plugin-fd.o + $(CC) -shared example-plugin-fd.o -o example-plugin-fd.so clean: diff --git a/bacula/src/plugins/fd/plugin-fd.c b/bacula/src/plugins/fd/example-plugin-fd.c similarity index 94% rename from bacula/src/plugins/fd/plugin-fd.c rename to bacula/src/plugins/fd/example-plugin-fd.c index a00d384b1c..fd5e6326c0 100644 --- a/bacula/src/plugins/fd/plugin-fd.c +++ b/bacula/src/plugins/fd/example-plugin-fd.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + Copyright (C) 2007-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -40,7 +40,7 @@ extern "C" { #define PLUGIN_LICENSE "GPL" #define PLUGIN_AUTHOR "Kern Sibbald" -#define PLUGIN_DATE "November 2007" +#define PLUGIN_DATE "January 2008" #define PLUGIN_VERSION "1" #define PLUGIN_DESCRIPTION "Test File Daemon Plugin" @@ -128,7 +128,10 @@ static bpError setPluginValue(bpContext *ctx, pVariable var, void *value) static bpError handlePluginEvent(bpContext *ctx, bEvent *event) { + char *name; printf("plugin: HandleEvent Event=%d\n", event->eventType); + bfuncs->getBaculaValue(ctx, bVarFDName, (void *)&name); + printf("FD Name=%s\n", name); return 0; } diff --git a/bacula/src/plugins/fd/main.c b/bacula/src/plugins/fd/main.c index 3333a912aa..98c8ef7898 100644 --- a/bacula/src/plugins/fd/main.c +++ b/bacula/src/plugins/fd/main.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + Copyright (C) 2007-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -43,6 +43,10 @@ const char *plugin_type = "-fd.so"; static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value); static bpError baculaSetValue(bpContext *ctx, bVariable var, void *value); static bpError baculaRegisterEvents(bpContext *ctx, ...); +static bpError baculaJobMsg(bpContext *ctx, const char *file, int line, + int type, time_t mtime, const char *msg); +static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line, + int level, const char *msg); /* Bacula info */ static bInfo binfo = { @@ -57,8 +61,8 @@ static bFuncs bfuncs = { baculaRegisterEvents, baculaGetValue, baculaSetValue, - NULL, - NULL, + baculaJobMsg, + baculaDebugMsg }; @@ -89,14 +93,18 @@ int main(int argc, char *argv[]) /* Start a new instance of the plugin */ plug_func(plugin)->newPlugin(&ctx); - event.eventType = bEventNewVolume; + event.eventType = bEventJobStart; + plug_func(plugin)->handlePluginEvent(&ctx, &event); + event.eventType = bEventJobEnd; plug_func(plugin)->handlePluginEvent(&ctx, &event); /* Free the plugin instance */ plug_func(plugin)->freePlugin(&ctx); /* Start a new instance of the plugin */ plug_func(plugin)->newPlugin(&ctx); - event.eventType = bEventNewVolume; + event.eventType = bEventJobStart; + plug_func(plugin)->handlePluginEvent(&ctx, &event); + event.eventType = bEventJobEnd; plug_func(plugin)->handlePluginEvent(&ctx, &event); /* Free the plugin instance */ plug_func(plugin)->freePlugin(&ctx); @@ -113,8 +121,23 @@ int main(int argc, char *argv[]) static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value) { printf("bacula: baculaGetValue var=%d\n", var); - if (value) { + if (!value) { + return 1; + } + switch (var) { + case bVarJobId: *((int *)value) = 100; + break; + case bVarFDName: + *((char **)value) = "FD Name"; + break; + case bVarLevel: + case bVarType: + case bVarClient: + case bVarJobName: + case bVarJobStatus: + case bVarSinceTime: + break; } return 0; } @@ -137,3 +160,19 @@ static bpError baculaRegisterEvents(bpContext *ctx, ...) va_end(args); return 0; } + +static bpError baculaJobMsg(bpContext *ctx, const char *file, int line, + int type, time_t mtime, const char *msg) +{ + printf("Job message: %s:%d type=%d time=%ld msg=%s\n", + file, line, type, mtime, msg); + return 0; +} + +static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line, + int level, const char *msg) +{ + printf("Debug message: %s:%d level=%d msg=%s\n", + file, line, level, msg); + return 0; +} diff --git a/bacula/src/plugins/fd/plugin-fd.h b/bacula/src/plugins/fd/plugin-fd.h index 2f1010bae5..21167c2eb3 100644 --- a/bacula/src/plugins/fd/plugin-fd.h +++ b/bacula/src/plugins/fd/plugin-fd.h @@ -56,17 +56,19 @@ extern "C" { /* Bacula Variable Ids */ typedef enum { - bVarJobId = 1 + bVarJobId = 1, + bVarFDName = 2, + bVarLevel = 3, + bVarType = 4, + bVarClient = 5, + bVarJobName = 6, + bVarJobStatus = 7, + bVarSinceTime = 8 } bVariable; typedef enum { bEventJobStart = 1, - bEventJobInit = 2, - bEventJobRun = 3, - bEventJobEnd = 4, - bEventNewVolume = 5, - bEventVolumePurged = 6, - bEventReload = 7 + bEventJobEnd = 2, } bEventType; typedef struct s_bEvent { @@ -85,8 +87,10 @@ typedef struct s_baculaFuncs { bpError (*registerBaculaEvents)(bpContext *ctx, ...); bpError (*getBaculaValue)(bpContext *ctx, bVariable var, void *value); bpError (*setBaculaValue)(bpContext *ctx, bVariable var, void *value); - bpError (*allocBaculaMem)(bpContext *ctx, uint32_t size, char *addr); - bpError (*freeBaculaMem)(bpContext *ctx, char *addr); + bpError (*JobMessage)(bpContext *ctx, const char *file, int line, + int type, time_t mtime, const char *msg); + bpError (*DebugMessage)(bpContext *ctx, const char *file, int line, + int level, const char *msg); } bFuncs; -- 2.39.5