File: sfile.h

package info (click to toggle)
sysprof 1.0.7-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 664 kB
  • ctags: 518
  • sloc: ansic: 5,033; sh: 852; makefile: 196
file content (143 lines) | stat: -rw-r--r-- 4,798 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* Sysprof -- Sampling, systemwide CPU profiler
 * Copyright 2004, Red Hat, Inc.
 * Copyright 2004, 2005, Soeren Sandmann
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

typedef struct SFormat SFormat;
typedef struct SFileInput SFileInput;
typedef struct SFileOutput SFileOutput;
typedef guint SType;


/* A possibly better API/naming scheme
 *
 * Serializer *serializer_new (SerializerFormat *format);
 *
 * SerializerReadContext *serializer_begin_read_filename (serializer *serialize,
 *						          const char *filename,
 *                                                        GError *err);
 * serializer_get_blah (SerializerReadContext *);
 * void serialzier_end_read (...);
 *
 * SerializerWritecontext *...;
 * serializer_begin_write (context);
 * serializer_write_int ();
 * serializer_end_write (..., GError **err);
 *
 *
 *  For formats consider:
 *
 *   Format *format_new (void);
 *   void format_set_record (Format *f, Content *r);
 *   Content *new_record (Content *c1, ...);
 *
 *   List *format_new_list (Format *f
 *   
 *
 * Consider adding optional elements:
 *
 *         sformat_new_optional (gpointer content)
 *
 * enums, optionals, selections, empties
 *
 *
 *==============================================
 * Also think about versioning - apps will want to be able to read and write
 * different versions of the format, and they want to be able to sniff the
 * format + version
 *
 */

/* - Describing Types - */
SFormat *sformat_new         (gpointer    f);
gpointer sformat_new_record  (const char *name,
			      SType      *type,
			      gpointer    content,
			      ...);
gpointer sformat_new_list    (const char *name,
			      SType      *type,
			      gpointer    content);
gpointer sformat_new_pointer (const char *name,
			      SType      *target_type);
gpointer sformat_new_integer (const char *name);
gpointer sformat_new_string  (const char *name);
void     sformat_free        (SFormat    *format);


/* - Reading - */
SFileInput *  sfile_load        (const char  *filename,
				 SFormat       *format,
				 GError     **err);
void     sfile_begin_get_record (SFileInput  *file,
				 const char *name);
int      sfile_begin_get_list   (SFileInput  *file,
				 const char *name);
void     sfile_get_pointer      (SFileInput  *file,
				 const char *name,
				 gpointer    *pointer);
void	 sfile_get_integer      (SFileInput  *file,
				 const char *name,
				 gint32     *integer);
void     sfile_get_string       (SFileInput  *file,
				 const char *name,
				 char       **string);
void     sfile_end_get          (SFileInput  *file,
				 const char *name,
				 gpointer     object);
void	 sfile_input_free	(SFileInput  *file);

#if 0
/* incremental loading (worth considering at least) */
SFileLoader *sfile_loader_new      (SFormat        *format);
void         sfile_loader_add_text (SFileLoader  *loader,
				    const char   *text,
				    int           len);
SFile *      sfile_loader_finish   (SFileLoader  *loader,
				    GError      **err);
void         sfile_loader_free     (SFileLoader  *loader);
#endif

/* - Writing - */

/* FIXME - not10: see if we can't get rid of the names. It
 * should be possible to pass NULL to state_transition_check()
 * and have it interprete that as "whatever". We would need
 * a way to get the name back then, though.
 */

SFileOutput *  sfile_output_new (SFormat       *format);
void     sfile_begin_add_record (SFileOutput       *file,
				 const char *name);
void     sfile_begin_add_list   (SFileOutput       *file,
				 const char *name);
void     sfile_end_add          (SFileOutput       *file,
				 const char *name,
				 gpointer object);
void     sfile_add_string       (SFileOutput       *file,
				 const char *name,
				 const char  *string);
void     sfile_add_integer      (SFileOutput       *file,
				 const char *name,
				 int          integer);
void     sfile_add_pointer      (SFileOutput       *file,
				 const char *name,
				 gpointer     pointer);
gboolean sfile_output_save      (SFileOutput       *sfile,
				 const char  *filename,
				 GError     **err);

void sfile_output_free (SFileOutput *sfile);