Refine the interactions between the hooks provided by the different modules.
[lttv.git] / ltt / branches / poly / lttv / main.c
1
2 #include <lttv/hook.h>
3 #include <lttv/module.h>
4 #include <lttv/lttv.h>
5 #include <lttv/attribute.h>
6 #include <lttv/option.h>
7 #include <lttv/traceset.h>
8 #include <ltt/trace.h>
9
10 void lttv_option_init(int argc, char **argv);
11 void lttv_option_destroy();
12
13 void lttv_module_init(int argc, char **argv);
14 void lttv_module_destroy();
15
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
20 static LttvIAttributes *attributes;
21
22 static LttvHooks
23 *before_options,
24 *after_options,
25 *before_main,
26 *after_main;
27
28 static char
29 *a_module,
30 *a_module_path;
31
32 static int a_argc;
33
34 static char **a_argv;
35
36 static void lttv_module_option(void *hook_data);
37
38 static void lttv_module_path_option(void *hook_data);
39
40 #ifdef MEMDEBUG
41 extern struct GMemVTable *glib_mem_profiler_table;
42 #endif
43
44
45 /* Since everything is done in modules, the main program only takes care
46 of the infrastructure. */
47
48 int main(int argc, char **argv) {
49
50 LttvAttributeValue *value;
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
58 attributes = LTTV_IATTRIBUTES(g_object_new(LTTV_ATTRIBUTES_TYPE));
59
60 before_options = lttv_hooks_new();
61 after_options = lttv_hooks_new();
62 before_main = lttv_hooks_new();
63 after_main = lttv_hooks_new();
64
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;
77
78
79 /* Initialize the command line options processing */
80
81 lttv_option_init(argc,argv);
82 lttv_module_init(argc,argv);
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",
95 "directory to add to the path", LTTV_OPT_STRING, &aModulePath,
96 lttv_module_path_option, NULL);
97
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);
102
103 lttv_module_destroy();
104 lttv_option_destroy();
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);
111
112 #ifdef MEMDEBUG
113 g_message("Memory summary after main");
114 g_mem_profile();
115 #endif
116 }
117
118
119 lttv_attributes *lttv_global_attributes()
120 {
121 return attributes;
122 }
123
124
125 void lttv_module_option(void *hook_data)
126 {
127 lttv_module_load(a_module,a_argc,a_argv);
128 }
129
130
131 void lttv_module_path_option(void *hook_data)
132 {
133 lttv_module_path_add(a_path);
134 }
This page took 0.032626 seconds and 4 git commands to generate.