traces now identified by device:inode in attributes
[lttv.git] / ltt / branches / poly / lttv / lttv / iattribute.h
CommitLineData
9c312311 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
dc877563 19#ifndef IATTRIBUTE_H
20#define IATTRIBUTE_H
21
22
23#include <glib-object.h>
308711e5 24#include <ltt/time.h>
dc877563 25
26/* The content of a data structure may be seen as an array of pairs of
27 attribute name and value. This simple model allows generic navigation
28 and access functions over a wide range of structures. The names are
29 represented by unique integer identifiers, GQuarks. */
30
31typedef GQuark LttvAttributeName;
32
dc877563 33typedef enum _LttvAttributeType {
34 LTTV_INT, LTTV_UINT, LTTV_LONG, LTTV_ULONG, LTTV_FLOAT, LTTV_DOUBLE,
35 LTTV_TIME, LTTV_POINTER, LTTV_STRING, LTTV_GOBJECT, LTTV_NONE
36} LttvAttributeType;
37
38typedef union LttvAttributeValue {
39 int *v_int;
40 unsigned *v_uint;
41 long *v_long;
42 unsigned long *v_ulong;
43 float *v_float;
44 double *v_double;
308711e5 45 LttTime *v_time;
dc877563 46 gpointer *v_pointer;
47 char **v_string;
996acd92 48 GObject **v_gobject;
dc877563 49} LttvAttributeValue;
50
51
52/* GObject interface type macros */
53
54#define LTTV_IATTRIBUTE_TYPE (lttv_iattribute_get_type ())
55#define LTTV_IATTRIBUTE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_IATTRIBUTE_TYPE, LttvIAttribute))
56#define LTTV_IATTRIBUTE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_IATTRIBUTE_TYPE, LttvIAttributeClass))
57#define LTTV_IS_IATTRIBUTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_IATTRIBUTE_TYPE))
58#define LTTV_IS_IATTRIBUTE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_IATTRIBUTE_TYPE))
59#define LTTV_IATTRIBUTE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), LTTV_IATTRIBUTE_TYPE, LttvIAttributeClass))
60
61
62typedef struct _LttvIattribute LttvIAttribute; /* dummy object */
63typedef struct _LttvIAttributeClass LttvIAttributeClass;
64
65
66struct _LttvIAttributeClass {
67 GTypeInterface parent;
68
3e67c985 69 LttvIAttribute* (*new_attribute) (LttvIAttribute *self);
70
dc877563 71 unsigned int (*get_number) (LttvIAttribute *self);
72
73 gboolean (*named) (LttvIAttribute *self, gboolean *homogeneous);
74
75 LttvAttributeType (*get) (LttvIAttribute *self, unsigned i,
76 LttvAttributeName *name, LttvAttributeValue *v);
77
78 LttvAttributeType (*get_by_name) (LttvIAttribute *self,
79 LttvAttributeName name, LttvAttributeValue *v);
80
81 LttvAttributeValue (*add) (LttvIAttribute *self, LttvAttributeName name,
82 LttvAttributeType t);
83
84 void (*remove) (LttvIAttribute *self, unsigned i);
85
86 void (*remove_by_name) (LttvIAttribute *self,
87 LttvAttributeName name);
88
b445142a 89 LttvIAttribute* (*find_subdir) (LttvIAttribute *self,
dc877563 90 LttvAttributeName name);
91};
92
93
94GType lttv_iattribute_get_type(void);
95
96
97/* Total number of attributes */
98
99unsigned int lttv_iattribute_get_number(LttvIAttribute *self);
100
101
102/* Container type. Named (fields in struct or elements in a hash table)
103 or unnamed (elements in an array) attributes, homogeneous type or not. */
104
105gboolean lttv_iattribute_named(LttvIAttribute *self, gboolean *homogeneous);
106
107
108/* Get the i th attribute along with its type and a pointer to its value. */
109
110LttvAttributeType lttv_iattribute_get(LttvIAttribute *self, unsigned i,
111 LttvAttributeName *name, LttvAttributeValue *v);
112
113
114/* Get the named attribute in the table along with its type and a pointer to
115 its value. If the named attribute does not exist, the type is LTTV_NONE. */
116
117LttvAttributeType lttv_iattribute_get_by_name(LttvIAttribute *self,
118 LttvAttributeName name, LttvAttributeValue *v);
119
120
121/* Add an attribute, which must not exist. The name is an empty string for
122 containers with unnamed attributes. Its value is initialized to 0 or NULL
123 and its pointer returned. */
124
125LttvAttributeValue lttv_iattribute_add(LttvIAttribute *self,
126 LttvAttributeName name, LttvAttributeType t);
127
128
129/* Remove an attribute */
130
131void lttv_iattribute_remove(LttvIAttribute *self, unsigned i);
132
133void lttv_iattribute_remove_by_name(LttvIAttribute *self,
134 LttvAttributeName name);
135
136
137/* Create an empty iattribute object and add it as an attribute under the
138 specified name, or return an existing iattribute attribute. If an
139 attribute of that name already exists but is not a GObject supporting the
140 iattribute interface, return NULL. */
141
b445142a 142LttvIAttribute* lttv_iattribute_find_subdir(LttvIAttribute *self,
dc877563 143 LttvAttributeName name);
144
145
146/* The remaining utility functions are not part of the LttvIAttribute
147 interface but operate on objects implementing it. */
148
149/* Find the named attribute in the table, which must be of the specified type.
150 If it does not exist, it is created with a default value of 0 (NULL for
151 pointer types). Since the address of the value is obtained, it may be
152 changed easily afterwards. The function returns false when the attribute
153 exists but is of incorrect type. */
154
155gboolean lttv_iattribute_find(LttvIAttribute *self, LttvAttributeName name,
156 LttvAttributeType t, LttvAttributeValue *v);
157
158
159/* Trees of attribute tables may be accessed using a hierarchical path with
160 components separated by /, like in filesystems */
161
162gboolean lttv_iattribute_find_by_path(LttvIAttribute *self, char *path,
163 LttvAttributeType t, LttvAttributeValue *v);
164
165
166/* Shallow and deep copies */
167
168void lttv_iattribute_copy_value(LttvAttributeType t, LttvAttributeValue dest,
169 LttvAttributeValue src);
170
171LttvIAttribute *lttv_iattribute_shallow_copy(LttvIAttribute *self);
172
173LttvIAttribute *lttv_iattribute_deep_copy(LttvIAttribute *self);
174
175#endif // IATTRIBUTE_H
This page took 0.032939 seconds and 4 git commands to generate.