Changed automake files to reflect the new header files.
[lttv.git] / ltt / branches / poly / lttv / main.c
CommitLineData
eccb5352 1
3d218f2a 2#include <lttv/hook.h>
3#include <lttv/module.h>
fcdf0ec2 4#include <lttv/lttv.h>
5#include <lttv/attribute.h>
6#include <lttv/option.h>
dc877563 7#include <lttv/traceset.h>
8#include <ltt/trace.h>
eccb5352 9
dc877563 10void lttv_option_init(int argc, char **argv);
11void lttv_option_destroy();
12
13void lttv_module_init(int argc, char **argv);
14void lttv_module_destroy();
fcdf0ec2 15
eccb5352 16/* The main program maintains a few central data structures and relies
17 on modules for the rest. These data structures may be accessed by modules
18 through an exported API */
19
dc877563 20static LttvIAttributes *attributes;
eccb5352 21
dc877563 22static LttvHooks
23 *before_options,
24 *after_options,
25 *before_main,
26 *after_main;
eccb5352 27
dc877563 28static char
29 *a_module,
30 *a_module_path;
eccb5352 31
dc877563 32static int a_argc;
eccb5352 33
dc877563 34static char **a_argv;
eccb5352 35
36static void lttv_module_option(void *hook_data);
37
38static void lttv_module_path_option(void *hook_data);
39
eccb5352 40#ifdef MEMDEBUG
41extern struct GMemVTable *glib_mem_profiler_table;
42#endif
43
dc877563 44
eccb5352 45/* Since everything is done in modules, the main program only takes care
46 of the infrastructure. */
47
48int main(int argc, char **argv) {
49
dc877563 50 LttvAttributeValue *value;
eccb5352 51
52#ifdef MEMDEBUG
53 g_mem_set_vtable(glib_mem_profiler_table);
54 g_message("Memory summary before main");
55 g_mem_profile();
56#endif
57
dc877563 58 attributes = LTTV_IATTRIBUTES(g_object_new(LTTV_ATTRIBUTES_TYPE));
eccb5352 59
dc877563 60 before_options = lttv_hooks_new();
61 after_options = lttv_hooks_new();
62 before_main = lttv_hooks_new();
63 after_main = lttv_hooks_new();
eccb5352 64
dc877563 65 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/before",
66 LTTV_POINTER, &value));
67 *(value->v_pointer) = before_options;
68 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/after",
69 LTTV_POINTER, &value));
70 *(value->v_pointer) = after_options;
71 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
72 LTTV_POINTER, &value));
73 *(value->v_pointer) = before_main;
74 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/after",
75 LTTV_POINTER, &value));
76 *(value->v_pointer) = after_main;
eccb5352 77
eccb5352 78
79 /* Initialize the command line options processing */
80
81 lttv_option_init(argc,argv);
82 lttv_module_init(argc,argv);
eccb5352 83
84 /* Initialize the module loading */
85
86 lttv_module_path_add("/usr/lib/lttv/plugins");
87
88 /* Add some built-in options */
89
90 lttv_option_add("module",'m', "load a module", "name of module to load",
91 LTTV_OPT_STRING, &aModule, lttv_module_option, NULL);
92
93 lttv_option_add("modules-path", 'L',
94 "add a directory to the module search path",
dc877563 95 "directory to add to the path", LTTV_OPT_STRING, &aModulePath,
eccb5352 96 lttv_module_path_option, NULL);
97
dc877563 98 lttv_hooks_call(before_options, NULL);
99 lttv_hooks_call(after_options, NULL);
100 lttv_hooks_call(before_main, NULL);
101 lttv_hooks_call(after_main, NULL);
eccb5352 102
eccb5352 103 lttv_module_destroy();
104 lttv_option_destroy();
dc877563 105
106 lttv_hooks_destroy(before_options);
107 lttv_hooks_destroy(after_options);
108 lttv_hooks_destroy(before_main);
109 lttv_hooks_destroy(after_main);
110 g_object_unref(attributes);
eccb5352 111
112#ifdef MEMDEBUG
113 g_message("Memory summary after main");
114 g_mem_profile();
115#endif
eccb5352 116}
117
dc877563 118
1cab0928 119lttv_attributes *lttv_global_attributes()
120{
dc877563 121 return attributes;
1cab0928 122}
123
124
eccb5352 125void lttv_module_option(void *hook_data)
126{
dc877563 127 lttv_module_load(a_module,a_argc,a_argv);
eccb5352 128}
129
130
131void lttv_module_path_option(void *hook_data)
132{
dc877563 133 lttv_module_path_add(a_path);
eccb5352 134}
This page took 0.028147 seconds and 4 git commands to generate.