Skip to content

Latest commit

 

History

History
187 lines (136 loc) · 5.59 KB

mce-io.h

File metadata and controls

187 lines (136 loc) · 5.59 KB
 
Dec 16, 2010
Dec 16, 2010
1
2
3
4
/**
* @file mce-io.h
* Headers for the generic I/O functionality for the Mode Control Entity
* <p>
May 12, 2011
May 12, 2011
5
* Copyright © 2007, 2009-2011 Nokia Corporation and/or its subsidiary(-ies).
May 17, 2019
May 17, 2019
6
* Copyright (C) 2012-2019 Jolla Ltd.
Dec 16, 2010
Dec 16, 2010
7
8
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
May 17, 2019
May 17, 2019
9
10
11
* @author Santtu Lakkala <ext-santtu.1.lakkala@nokia.com>
* @author Jukka Turunen <ext-jukka.t.turunen@nokia.com>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
Dec 16, 2010
Dec 16, 2010
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
*
* mce is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* mce 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with mce. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _MCE_IO_H_
#define _MCE_IO_H_
Jan 10, 2013
Jan 10, 2013
28
29
#include <sys/stat.h>
May 26, 2014
May 26, 2014
30
#include <stdio.h>
Oct 26, 2018
Oct 26, 2018
31
#include <stdbool.h>
Dec 16, 2010
Dec 16, 2010
32
May 27, 2014
May 27, 2014
33
34
#include <glib.h>
Dec 16, 2010
Dec 16, 2010
35
36
37
38
39
40
41
42
43
44
/** Error policies for mce-io */
typedef enum {
/** Exit on error */
MCE_IO_ERROR_POLICY_EXIT,
/** Warn about errors */
MCE_IO_ERROR_POLICY_WARN,
/** Silently ignore errors */
MCE_IO_ERROR_POLICY_IGNORE
} error_policy_t;
Nov 15, 2012
Nov 15, 2012
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
/** Control structure for updating output files */
typedef struct {
/* static configuration */
/** descriptive context information used for identifying the
* purpose of the output file even if no valid output path
* is available */
const gchar *context;
/** TRUE to truncate the file before writing,
* FALSE to append to the end of the file */
gboolean truncate_file;
/** TRUE to close the file on exit
* [from mce_write_number_string_to_file() function],
* FALSE to leave the file open */
gboolean close_on_exit;
/* runtime configuration */
/** Path to the file, or NULL (in which case one misconfiguration
* error message will be logged if write helpers are called) */
const char *path;
/* dynamic state */
/** Cached output stream, use mce_close_output() to close */
FILE *file;
/** TRUE if missing path configuration error has already been
* written for this file */
gboolean invalid_config_reported;
Oct 16, 2019
Oct 16, 2019
77
78
79
/** For suppressing reporting of repeated errors */
int reported_errno;
Nov 15, 2012
Nov 15, 2012
80
81
} output_state_t;
Dec 23, 2014
Dec 23, 2014
82
typedef struct mce_io_mon_t mce_io_mon_t;
Mar 14, 2014
Mar 14, 2014
83
Dec 23, 2014
Dec 23, 2014
84
/** Callback function type for I/O monitor input notifications */
Jan 7, 2016
Jan 7, 2016
85
typedef gboolean (*mce_io_mon_notify_cb)(mce_io_mon_t *iomon, gpointer data, gsize bytes_read);
Dec 16, 2010
Dec 16, 2010
86
Dec 23, 2014
Dec 23, 2014
87
/** Callback function type for I/O monitor delete notifications */
Dec 23, 2014
Dec 23, 2014
88
typedef void (*mce_io_mon_delete_cb)(mce_io_mon_t *iomon);
Mar 14, 2014
Mar 14, 2014
89
Dec 23, 2014
Dec 23, 2014
90
91
92
/** Callback function type for releasing I/O monitor user data block */
typedef void (*mce_io_mon_free_cb)(void *user_data);
Mar 14, 2014
Mar 14, 2014
93
94
/* iomon functions */
Dec 23, 2014
Dec 23, 2014
95
96
97
98
99
100
mce_io_mon_t *mce_io_mon_register_string(const gint fd,
const gchar *const file,
error_policy_t error_policy,
gboolean rewind_policy,
mce_io_mon_notify_cb callback,
mce_io_mon_delete_cb delete_cb);
Mar 14, 2014
Mar 14, 2014
101
Dec 23, 2014
Dec 23, 2014
102
103
104
105
106
107
108
mce_io_mon_t *mce_io_mon_register_chunk(const gint fd,
const gchar *const file,
error_policy_t error_policy,
gboolean rewind_policy,
mce_io_mon_notify_cb callback,
mce_io_mon_delete_cb delete_cb,
gulong chunk_size);
Mar 14, 2014
Mar 14, 2014
109
Dec 23, 2014
Dec 23, 2014
110
void mce_io_mon_unregister(mce_io_mon_t *iomon);
Mar 14, 2014
Mar 14, 2014
111
Dec 23, 2014
Dec 23, 2014
112
void mce_io_mon_unregister_list(GSList *list);
Mar 14, 2014
Mar 14, 2014
113
Dec 23, 2014
Dec 23, 2014
114
void mce_io_mon_unregister_at_path(const char *path);
Mar 14, 2014
Mar 14, 2014
115
Dec 23, 2014
Dec 23, 2014
116
void mce_io_mon_suspend(mce_io_mon_t *iomon);
Mar 14, 2014
Mar 14, 2014
117
Dec 23, 2014
Dec 23, 2014
118
void mce_io_mon_resume(mce_io_mon_t *iomon);
Mar 14, 2014
Mar 14, 2014
119
Dec 23, 2014
Dec 23, 2014
120
const gchar *mce_io_mon_get_path(const mce_io_mon_t *iomon);
Mar 14, 2014
Mar 14, 2014
121
Dec 23, 2014
Dec 23, 2014
122
int mce_io_mon_get_fd(const mce_io_mon_t *iomon);
Dec 16, 2010
Dec 16, 2010
123
Dec 23, 2014
Dec 23, 2014
124
125
126
127
128
129
void mce_io_mon_set_user_data(mce_io_mon_t *iomon,
void *user_data,
mce_io_mon_free_cb free_cb);
void *mce_io_mon_get_user_data(const mce_io_mon_t *iomon);
Mar 14, 2014
Mar 14, 2014
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* output_state_t funtions */
void mce_close_output(output_state_t *output);
gboolean mce_write_number_string_to_file(output_state_t *output, const gulong number);
/* misc utils */
gboolean mce_close_file(const gchar *const file, FILE **fp);
gboolean mce_read_chunk_from_file(const gchar *const file, void **data,
gssize *len, int flags);
gboolean mce_read_string_from_file(const gchar *const file, gchar **string);
gboolean mce_read_number_string_from_file(const gchar *const file,
gulong *number, FILE **fp,
gboolean rewind,
gboolean close_on_exit);
gboolean mce_write_string_to_file(const gchar *const file,
const gchar *const string);
gboolean mce_write_number_string_to_file_atomic(const gchar *const file,
const gulong number);
May 12, 2011
May 12, 2011
156
gboolean mce_are_settings_locked(void);
Mar 14, 2014
Mar 14, 2014
157
May 12, 2011
May 12, 2011
158
gboolean mce_unlock_settings(void);
Dec 16, 2010
Dec 16, 2010
159
Jan 10, 2013
Jan 10, 2013
160
void *mce_io_load_file(const char *path, size_t *psize);
Mar 14, 2014
Mar 14, 2014
161
Nov 5, 2013
Nov 5, 2013
162
void *mce_io_load_file_until_eof(const char *path, size_t *psize);
Mar 14, 2014
Mar 14, 2014
163
Jan 10, 2013
Jan 10, 2013
164
165
166
gboolean mce_io_save_file(const char *path,
const void *data, size_t size,
mode_t mode);
Mar 14, 2014
Mar 14, 2014
167
Nov 5, 2013
Nov 5, 2013
168
169
gboolean mce_io_save_to_existing_file(const char *path,
const void *data, size_t size);
Mar 14, 2014
Mar 14, 2014
170
Jan 10, 2013
Jan 10, 2013
171
172
173
gboolean mce_io_save_file_atomic(const char *path,
const void *data, size_t size,
mode_t mode, gboolean keep_backup);
Mar 14, 2014
Mar 14, 2014
174
Jan 10, 2013
Jan 10, 2013
175
176
177
178
gboolean mce_io_update_file_atomic(const char *path,
const void *data, size_t size,
mode_t mode, gboolean keep_backup);
Oct 17, 2018
Oct 17, 2018
179
180
181
182
/* Resume from suspend detection */
void mce_io_init_resume_timer(void);
void mce_io_quit_resume_timer(void);
Oct 26, 2018
Oct 26, 2018
183
184
185
186
guint mce_io_add_watch(int fd, bool close_on_unref, GIOCondition cnd, GIOFunc io_cb, gpointer aptr);
const char *mce_io_condition_repr (GIOCondition cond);
const char *mce_io_status_name (GIOStatus io_status);
Dec 16, 2010
Dec 16, 2010
187
#endif /* _MCE_IO_H_ */