Add copyright notices and some comments about status and TODO
[lttv.git] / ltt / branches / poly / lttv / main / traceset.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19
20 #include <lttv/traceset.h>
21 #include <stdio.h>
22
23 /* A trace is a sequence of events gathered in the same tracing session. The
24 events may be stored in several tracefiles in the same directory.
25 A trace set is defined when several traces are to be analyzed together,
26 possibly to study the interactions between events in the different traces.
27 */
28
29 struct _LttvTraceset {
30 char * filename;
31 GPtrArray *traces;
32 LttvAttribute *a;
33 };
34
35
36 struct _LttvTrace {
37 LttTrace *t;
38 LttvAttribute *a;
39 guint ref_count;
40 };
41
42
43 LttvTraceset *lttv_traceset_new()
44 {
45 LttvTraceset *s;
46
47 s = g_new(LttvTraceset, 1);
48 s->filename = NULL;
49 s->traces = g_ptr_array_new();
50 s->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
51 return s;
52 }
53
54 char * lttv_traceset_name(LttvTraceset * s)
55 {
56 return s->filename;
57 }
58
59 LttvTrace *lttv_trace_new(LttTrace *t)
60 {
61 LttvTrace *new_trace;
62
63 new_trace = g_new(LttvTrace, 1);
64 new_trace->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
65 new_trace->t = t;
66 new_trace->ref_count = 0;
67 return new_trace;
68 }
69
70
71 LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig)
72 {
73 int i;
74 LttvTraceset *s;
75 LttvTrace * trace;
76
77 s = g_new(LttvTraceset, 1);
78 s->filename = NULL;
79 s->traces = g_ptr_array_new();
80 for(i=0;i<s_orig->traces->len;i++)
81 {
82 trace = g_ptr_array_index(s_orig->traces, i);
83 trace->ref_count++;
84
85 /*CHECK this used ltt_trace_copy while it may not be needed. Need to
86 define how traces and tracesets are shared */
87 g_ptr_array_add(
88 s->traces,
89 g_ptr_array_index(s_orig->traces, i));
90 }
91 s->a = LTTV_ATTRIBUTE(lttv_iattribute_deep_copy(LTTV_IATTRIBUTE(s_orig->a)));
92 return s;
93 }
94
95
96 LttvTraceset *lttv_traceset_load(const gchar *filename)
97 {
98 LttvTraceset *s = g_new(LttvTraceset,1);
99 FILE *tf;
100
101 s->filename = g_strdup(filename);
102 tf = fopen(filename,"r");
103
104 g_critical("NOT IMPLEMENTED : load traceset data from a XML file");
105
106 fclose(tf);
107 return s;
108 }
109
110 gint lttv_traceset_save(LttvTraceset *s)
111 {
112 FILE *tf;
113
114 tf = fopen(s->filename, "w");
115
116 g_critical("NOT IMPLEMENTED : save traceset data in a XML file");
117
118 fclose(tf);
119 return 0;
120 }
121
122 void lttv_traceset_destroy(LttvTraceset *s)
123 {
124 g_ptr_array_free(s->traces, TRUE);
125 g_object_unref(s->a);
126 g_free(s);
127 }
128
129 void lttv_trace_destroy(LttvTrace *t)
130 {
131 g_object_unref(t->a);
132 g_free(t);
133 }
134
135
136 void lttv_traceset_add(LttvTraceset *s, LttvTrace *t)
137 {
138 t->ref_count++;
139 g_ptr_array_add(s->traces, t);
140 }
141
142
143 unsigned lttv_traceset_number(LttvTraceset *s)
144 {
145 return s->traces->len;
146 }
147
148
149 LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i)
150 {
151 g_assert(s->traces->len > i);
152 return ((LttvTrace *)s->traces->pdata[i]);
153 }
154
155
156 void lttv_traceset_remove(LttvTraceset *s, unsigned i)
157 {
158 LttvTrace * t;
159 g_assert(s->traces->len > i);
160 t = (LttvTrace *)s->traces->pdata[i];
161 t->ref_count--;
162 g_ptr_array_remove_index(s->traces, i);
163 }
164
165
166 /* A set of attributes is attached to each trace set, trace and tracefile
167 to store user defined data as needed. */
168
169 LttvAttribute *lttv_traceset_attribute(LttvTraceset *s)
170 {
171 return s->a;
172 }
173
174
175 LttvAttribute *lttv_trace_attribute(LttvTrace *t)
176 {
177 return t->a;
178 }
179
180
181 LttTrace *lttv_trace(LttvTrace *t)
182 {
183 return t->t;
184 }
185
186 guint lttv_trace_get_ref_number(LttvTrace * t)
187 {
188 return t->ref_count;
189 }
This page took 0.032726 seconds and 4 git commands to generate.