gui/API search directory for library mainWinAPI
[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>
ffd54a90 5#include <lttv/iattribute.h>
fcdf0ec2 6#include <lttv/attribute.h>
7#include <lttv/option.h>
dc877563 8#include <lttv/traceset.h>
9#include <ltt/trace.h>
eccb5352 10
dc877563 11void lttv_option_init(int argc, char **argv);
12void lttv_option_destroy();
13
14void lttv_module_init(int argc, char **argv);
15void lttv_module_destroy();
fcdf0ec2 16
ffd54a90 17void lttv_state_init(int argc, char **argv);
18void lttv_state_destroy();
19
eccb5352 20/* The main program maintains a few central data structures and relies
21 on modules for the rest. These data structures may be accessed by modules
22 through an exported API */
23
ffd54a90 24static LttvIAttribute *attributes;
eccb5352 25
dc877563 26static LttvHooks
27 *before_options,
28 *after_options,
29 *before_main,
30 *after_main;
eccb5352 31
dc877563 32static char
33 *a_module,
34 *a_module_path;
eccb5352 35
dc877563 36static int a_argc;
eccb5352 37
dc877563 38static char **a_argv;
eccb5352 39
40static void lttv_module_option(void *hook_data);
41
42static void lttv_module_path_option(void *hook_data);
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
ffd54a90 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
41f18f3e 58 g_type_init();
59 //g_type_init_with_debug_flags (G_TYPE_DEBUG_OBJECTS | G_TYPE_DEBUG_SIGNALS);
d83f6739 60
ffd54a90 61 attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
eccb5352 62
dc877563 63 before_options = lttv_hooks_new();
64 after_options = lttv_hooks_new();
65 before_main = lttv_hooks_new();
66 after_main = lttv_hooks_new();
eccb5352 67
dc877563 68 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/before",
69 LTTV_POINTER, &value));
ffd54a90 70 *(value.v_pointer) = before_options;
dc877563 71 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/after",
72 LTTV_POINTER, &value));
ffd54a90 73 *(value.v_pointer) = after_options;
dc877563 74 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
75 LTTV_POINTER, &value));
ffd54a90 76 *(value.v_pointer) = before_main;
dc877563 77 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/after",
78 LTTV_POINTER, &value));
ffd54a90 79 *(value.v_pointer) = after_main;
eccb5352 80
eccb5352 81
82 /* Initialize the command line options processing */
83
84 lttv_option_init(argc,argv);
85 lttv_module_init(argc,argv);
ffd54a90 86 lttv_state_init(argc,argv);
eccb5352 87
88 /* Initialize the module loading */
89
90 lttv_module_path_add("/usr/lib/lttv/plugins");
91
92 /* Add some built-in options */
93
94 lttv_option_add("module",'m', "load a module", "name of module to load",
ffd54a90 95 LTTV_OPT_STRING, &a_module, lttv_module_option, NULL);
eccb5352 96
97 lttv_option_add("modules-path", 'L',
98 "add a directory to the module search path",
ffd54a90 99 "directory to add to the path", LTTV_OPT_STRING, &a_module_path,
eccb5352 100 lttv_module_path_option, NULL);
101
dc877563 102 lttv_hooks_call(before_options, NULL);
c432246e 103 lttv_option_parse(argc, argv);
dc877563 104 lttv_hooks_call(after_options, NULL);
c432246e 105
dc877563 106 lttv_hooks_call(before_main, NULL);
107 lttv_hooks_call(after_main, NULL);
eccb5352 108
ffd54a90 109 lttv_state_destroy();
eccb5352 110 lttv_module_destroy();
111 lttv_option_destroy();
dc877563 112
113 lttv_hooks_destroy(before_options);
114 lttv_hooks_destroy(after_options);
115 lttv_hooks_destroy(before_main);
116 lttv_hooks_destroy(after_main);
117 g_object_unref(attributes);
eccb5352 118
119#ifdef MEMDEBUG
120 g_message("Memory summary after main");
121 g_mem_profile();
122#endif
eccb5352 123}
124
dc877563 125
ffd54a90 126LttvAttribute *lttv_global_attributes()
1cab0928 127{
cbe7c836 128 return (LttvAttribute*)attributes;
1cab0928 129}
130
131
eccb5352 132void lttv_module_option(void *hook_data)
133{
dc877563 134 lttv_module_load(a_module,a_argc,a_argv);
eccb5352 135}
136
137
138void lttv_module_path_option(void *hook_data)
139{
ffd54a90 140 lttv_module_path_add(a_module_path);
eccb5352 141}
This page took 0.029199 seconds and 4 git commands to generate.