--help argument -h added to main and option.c
[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/iattribute.h>
6 #include <lttv/attribute.h>
7 #include <lttv/option.h>
8 #include <lttv/traceset.h>
9 #include <ltt/trace.h>
10 #include <stdio.h>
11
12
13 void lttv_option_init(int argc, char **argv);
14 void lttv_option_destroy();
15
16 void lttv_module_init(int argc, char **argv);
17 void lttv_module_destroy();
18
19 void lttv_state_init(int argc, char **argv);
20 void lttv_state_destroy();
21
22 /* The main program maintains a few central data structures and relies
23 on modules for the rest. These data structures may be accessed by modules
24 through an exported API */
25
26 static LttvIAttribute *attributes;
27
28 static LttvHooks
29 *before_options,
30 *after_options,
31 *before_main,
32 *after_main;
33
34 static char
35 *a_module,
36 *a_module_path;
37
38 static int a_argc;
39
40 static char **a_argv;
41
42 static void lttv_module_option(void *hook_data);
43
44 static void lttv_module_path_option(void *hook_data);
45
46 static void lttv_help(void);
47
48 /* Since everything is done in modules, the main program only takes care
49 of the infrastructure. */
50
51 int main(int argc, char **argv) {
52
53 LttvAttributeValue value;
54
55 #ifdef MEMDEBUG
56 g_mem_set_vtable(glib_mem_profiler_table);
57 g_message("Memory summary before main");
58 g_mem_profile();
59 #endif
60
61 g_type_init();
62 //g_type_init_with_debug_flags (G_TYPE_DEBUG_OBJECTS | G_TYPE_DEBUG_SIGNALS);
63
64 attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
65
66 before_options = lttv_hooks_new();
67 after_options = lttv_hooks_new();
68 before_main = lttv_hooks_new();
69 after_main = lttv_hooks_new();
70
71 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/before",
72 LTTV_POINTER, &value));
73 *(value.v_pointer) = before_options;
74 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/after",
75 LTTV_POINTER, &value));
76 *(value.v_pointer) = after_options;
77 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
78 LTTV_POINTER, &value));
79 *(value.v_pointer) = before_main;
80 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/after",
81 LTTV_POINTER, &value));
82 *(value.v_pointer) = after_main;
83
84
85 /* Initialize the command line options processing */
86
87 lttv_option_init(argc,argv);
88 lttv_module_init(argc,argv);
89 lttv_state_init(argc,argv);
90
91 /* Initialize the module loading */
92
93 lttv_module_path_add("/usr/lib/lttv/plugins");
94
95 /* Add some built-in options */
96
97 lttv_option_add("module",'m', "load a module", "name of module to load",
98 LTTV_OPT_STRING, &a_module, lttv_module_option, NULL);
99
100 lttv_option_add("modules-path", 'L',
101 "add a directory to the module search path",
102 "directory to add to the path", LTTV_OPT_STRING, &a_module_path,
103 lttv_module_path_option, NULL);
104
105 lttv_option_add("help",'h', "basic help", "none",
106 LTTV_OPT_NONE, NULL, lttv_help, NULL);
107
108
109 lttv_hooks_call(before_options, NULL);
110 lttv_option_parse(argc, argv);
111 lttv_hooks_call(after_options, NULL);
112
113 lttv_hooks_call(before_main, NULL);
114 lttv_hooks_call(after_main, NULL);
115
116 lttv_state_destroy();
117 lttv_module_destroy();
118 lttv_option_destroy();
119
120 lttv_hooks_destroy(before_options);
121 lttv_hooks_destroy(after_options);
122 lttv_hooks_destroy(before_main);
123 lttv_hooks_destroy(after_main);
124 g_object_unref(attributes);
125
126 #ifdef MEMDEBUG
127 g_message("Memory summary after main");
128 g_mem_profile();
129 #endif
130 }
131
132
133 LttvAttribute *lttv_global_attributes()
134 {
135 return (LttvAttribute*)attributes;
136 }
137
138
139 void lttv_module_option(void *hook_data)
140 {
141 lttv_module_load(a_module,a_argc,a_argv);
142 }
143
144
145 void lttv_module_path_option(void *hook_data)
146 {
147 lttv_module_path_add(a_module_path);
148 }
149
150 void lttv_help()
151 {
152 printf("Linux Trace Toolkit Visualizer\n");
153 printf("\n");
154 lttv_option_show_help();
155 printf("\n");
156 }
This page took 0.031891 seconds and 4 git commands to generate.