1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
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;
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.
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,
23 #include <glib-object.h>
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. */
31 typedef GQuark LttvAttributeName
;
33 typedef 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
38 typedef union LttvAttributeValue
{
42 unsigned long *v_ulong
;
52 /* GObject interface type macros */
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))
62 typedef struct _LttvIattribute LttvIAttribute
; /* dummy object */
63 typedef struct _LttvIAttributeClass LttvIAttributeClass
;
66 struct _LttvIAttributeClass
{
67 GTypeInterface parent
;
69 unsigned int (*get_number
) (LttvIAttribute
*self
);
71 gboolean (*named
) (LttvIAttribute
*self
, gboolean
*homogeneous
);
73 LttvAttributeType (*get
) (LttvIAttribute
*self
, unsigned i
,
74 LttvAttributeName
*name
, LttvAttributeValue
*v
);
76 LttvAttributeType (*get_by_name
) (LttvIAttribute
*self
,
77 LttvAttributeName name
, LttvAttributeValue
*v
);
79 LttvAttributeValue (*add
) (LttvIAttribute
*self
, LttvAttributeName name
,
82 void (*remove
) (LttvIAttribute
*self
, unsigned i
);
84 void (*remove_by_name
) (LttvIAttribute
*self
,
85 LttvAttributeName name
);
87 LttvIAttribute
* (*find_subdir
) (LttvIAttribute
*self
,
88 LttvAttributeName name
);
92 GType
lttv_iattribute_get_type(void);
95 /* Total number of attributes */
97 unsigned int lttv_iattribute_get_number(LttvIAttribute
*self
);
100 /* Container type. Named (fields in struct or elements in a hash table)
101 or unnamed (elements in an array) attributes, homogeneous type or not. */
103 gboolean
lttv_iattribute_named(LttvIAttribute
*self
, gboolean
*homogeneous
);
106 /* Get the i th attribute along with its type and a pointer to its value. */
108 LttvAttributeType
lttv_iattribute_get(LttvIAttribute
*self
, unsigned i
,
109 LttvAttributeName
*name
, LttvAttributeValue
*v
);
112 /* Get the named attribute in the table along with its type and a pointer to
113 its value. If the named attribute does not exist, the type is LTTV_NONE. */
115 LttvAttributeType
lttv_iattribute_get_by_name(LttvIAttribute
*self
,
116 LttvAttributeName name
, LttvAttributeValue
*v
);
119 /* Add an attribute, which must not exist. The name is an empty string for
120 containers with unnamed attributes. Its value is initialized to 0 or NULL
121 and its pointer returned. */
123 LttvAttributeValue
lttv_iattribute_add(LttvIAttribute
*self
,
124 LttvAttributeName name
, LttvAttributeType t
);
127 /* Remove an attribute */
129 void lttv_iattribute_remove(LttvIAttribute
*self
, unsigned i
);
131 void lttv_iattribute_remove_by_name(LttvIAttribute
*self
,
132 LttvAttributeName name
);
135 /* Create an empty iattribute object and add it as an attribute under the
136 specified name, or return an existing iattribute attribute. If an
137 attribute of that name already exists but is not a GObject supporting the
138 iattribute interface, return NULL. */
140 LttvIAttribute
* lttv_iattribute_find_subdir(LttvIAttribute
*self
,
141 LttvAttributeName name
);
144 /* The remaining utility functions are not part of the LttvIAttribute
145 interface but operate on objects implementing it. */
147 /* Find the named attribute in the table, which must be of the specified type.
148 If it does not exist, it is created with a default value of 0 (NULL for
149 pointer types). Since the address of the value is obtained, it may be
150 changed easily afterwards. The function returns false when the attribute
151 exists but is of incorrect type. */
153 gboolean
lttv_iattribute_find(LttvIAttribute
*self
, LttvAttributeName name
,
154 LttvAttributeType t
, LttvAttributeValue
*v
);
157 /* Trees of attribute tables may be accessed using a hierarchical path with
158 components separated by /, like in filesystems */
160 gboolean
lttv_iattribute_find_by_path(LttvIAttribute
*self
, char *path
,
161 LttvAttributeType t
, LttvAttributeValue
*v
);
164 /* Shallow and deep copies */
166 void lttv_iattribute_copy_value(LttvAttributeType t
, LttvAttributeValue dest
,
167 LttvAttributeValue src
);
169 LttvIAttribute
*lttv_iattribute_shallow_copy(LttvIAttribute
*self
);
171 LttvIAttribute
*lttv_iattribute_deep_copy(LttvIAttribute
*self
);
173 #endif // IATTRIBUTE_H