Finishing the total time counters
[lwes-journaller.git] / src / journal_factory.c
blob9eb5fa2af048ba993ed391b8294745e407a11254
1 /*======================================================================*
2 * Copyright (C) 2008 Light Weight Event System *
3 * All rights reserved. *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
18 * Boston, MA 02110-1301 USA. *
19 *======================================================================*/
20 #include "config.h"
22 #include "journal.h"
23 #include "journal_gz.h"
24 #include "journal_file.h"
26 #include "log.h"
27 #include "opt.h"
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <dlfcn.h> /* see http://www.tldp.org/HOWTO/C++-dlopen/index.html */
34 int journal_factory(struct journal* jrn, const char* name)
36 if ( strcmp(arg_journ_type, ARG_FILE) == 0 )
38 if ( journal_file_ctor(jrn, name) < 0 )
40 LOG_ER("Failed to create a plain file journal.\n");
41 return -1;
44 else if ( strcmp(arg_journ_type, ARG_GZ) == 0 )
46 if ( journal_gz_ctor(jrn, name) < 0 )
48 LOG_ER("Failed to create a GZ compressed journal.\n");
49 return -1;
52 else
54 char pathname[256] ;
55 char *err = NULL ;
56 void* module = NULL ;
57 /* TODO: Change /home/y/lib */
58 strcpy(pathname, "/home/y/lib/liblwes-journaller-journal-") ;
59 strcat(pathname, arg_journ_type) ;
60 strcat(pathname, ".so") ;
61 module = dlopen(pathname, RTLD_NOW) ;
63 if ( module )
65 char symname[100] ;
66 strcpy(symname, "lwes_journaller_journal_") ;
67 strcat(symname, arg_journ_type) ;
68 strcat(symname, "_LTX_init") ;
69 lwes_journaller_journal_init_t init =
70 (lwes_journaller_journal_init_t) dlsym(module, symname) ;
71 if ( !dlerror() )
73 if ( (*init)(jrn, name) < 0 )
75 LOG_ER("Failed to create a dynamic journal method.\n") ;
76 return -1 ;
78 else
80 return 0 ;
83 else
85 err = dlerror() ;
88 else
90 err = dlerror() ;
93 LOG_ER("Unrecognized journal type \"%s\", try \"" ARG_FILE "\" or \"" ARG_GZ "\".\n%s\n",
94 arg_journ_type, err);
95 return -1;
98 return 0;