git-svn-id: http://ltt.polymtl.ca/svn@289 04897980-b3bd-0310-b5e0-8ef037075253
[lttv.git] / ltt / branches / poly / lttv / main.c
... / ...
CommitLineData
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
13void lttv_option_init(int argc, char **argv);
14void lttv_option_destroy();
15
16void lttv_module_init(int argc, char **argv);
17void lttv_module_destroy();
18
19void lttv_state_init(int argc, char **argv);
20void 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
26static LttvIAttribute *attributes;
27
28static LttvHooks
29 *before_options,
30 *after_options,
31 *before_main,
32 *after_main;
33
34static char
35 *a_module,
36 *a_module_path;
37
38static int a_argc;
39
40static char **a_argv;
41
42static void lttv_module_option(void *hook_data);
43
44static void lttv_module_path_option(void *hook_data);
45
46static void lttv_help(void);
47
48/* Since everything is done in modules, the main program only takes care
49 of the infrastructure. */
50
51int 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
133LttvAttribute *lttv_global_attributes()
134{
135 return (LttvAttribute*)attributes;
136}
137
138
139void lttv_module_option(void *hook_data)
140{
141 lttv_module_load(a_module,a_argc,a_argv);
142}
143
144
145void lttv_module_path_option(void *hook_data)
146{
147 lttv_module_path_add(a_module_path);
148}
149
150void 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.023263 seconds and 4 git commands to generate.