Debian Codegraph @

device-src/property.h

raw
1 /*
2 * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
3 * Copyright (c) 2013-2016 Carbonite, Inc. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Contact information: Carbonite Inc., 756 N Pastoria Ave
20 * Sunnyvale, CA 94085, or: http://www.zmanda.com
21 */
22
23 #ifndef DEVICE_PROPERTY_H
24 #define DEVICE_PROPERTY_H
25
26 #include <glib.h>
27 #include <glib-object.h>
28
29 /* The properties interface defines define capabilities and other interesting
30 * properties. */
31
32 typedef enum {
33 PROPERTY_PHASE_BEFORE_START = (1 << 0),
34 PROPERTY_PHASE_BETWEEN_FILE_WRITE = (1 << 1),
35 PROPERTY_PHASE_INSIDE_FILE_WRITE = (1 << 2),
36 PROPERTY_PHASE_BETWEEN_FILE_READ = (1 << 3),
37 PROPERTY_PHASE_INSIDE_FILE_READ = (1 << 4),
38 PROPERTY_PHASE_MAX = (1 << 5)
39 } PropertyPhaseFlags;
40
41 #define PROPERTY_PHASE_MASK (PROPERTY_PHASE_MAX-1)
42 #define PROPERTY_PHASE_SHIFT 8
43
44 typedef enum {
45 PROPERTY_ACCESS_GET_BEFORE_START = (PROPERTY_PHASE_BEFORE_START),
46 PROPERTY_ACCESS_GET_BETWEEN_FILE_WRITE =
47 (PROPERTY_PHASE_BETWEEN_FILE_WRITE),
48 PROPERTY_ACCESS_GET_INSIDE_FILE_WRITE = (PROPERTY_PHASE_INSIDE_FILE_WRITE),
49 PROPERTY_ACCESS_GET_BETWEEN_FILE_READ =
50 (PROPERTY_PHASE_BETWEEN_FILE_READ),
51 PROPERTY_ACCESS_GET_INSIDE_FILE_READ = (PROPERTY_PHASE_INSIDE_FILE_READ),
52
53 PROPERTY_ACCESS_SET_BEFORE_START =
54 (PROPERTY_PHASE_BEFORE_START << PROPERTY_PHASE_SHIFT),
55 PROPERTY_ACCESS_SET_BETWEEN_FILE_WRITE =
56 (PROPERTY_PHASE_BETWEEN_FILE_WRITE << PROPERTY_PHASE_SHIFT),
57 PROPERTY_ACCESS_SET_INSIDE_FILE_WRITE =
58 (PROPERTY_PHASE_INSIDE_FILE_WRITE << PROPERTY_PHASE_SHIFT),
59 PROPERTY_ACCESS_SET_BETWEEN_FILE_READ =
60 (PROPERTY_PHASE_BETWEEN_FILE_READ << PROPERTY_PHASE_SHIFT),
61 PROPERTY_ACCESS_SET_INSIDE_FILE_READ =
62 (PROPERTY_PHASE_INSIDE_FILE_READ << PROPERTY_PHASE_SHIFT)
63 } PropertyAccessFlags;
64
65 #define PROPERTY_ACCESS_GET_MASK (PROPERTY_PHASE_MASK)
66 #define PROPERTY_ACCESS_SET_MASK (PROPERTY_PHASE_MASK << PROPERTY_PHASE_SHIFT)
67
68 /* Some properties can only be occasionally (or unreliably) detected, so
69 * this enum allows the user to override the detected or default
70 * setting. Surety indicates a level of confidence in the value, while
71 * source describes how we found out about it. */
72 typedef enum {
73 /* Support is not based on conclusive evidence. */
74 PROPERTY_SURETY_BAD,
75 /* Support is based on conclusive evidence. */
76 PROPERTY_SURETY_GOOD,
77 } PropertySurety;
78
79 typedef enum {
80 /* property is from default setting. */
81 PROPERTY_SOURCE_DEFAULT,
82 /* property is from device query. */
83 PROPERTY_SOURCE_DETECTED,
84 /* property is from user override (configuration). */
85 PROPERTY_SOURCE_USER,
86 } PropertySource;
87
88 /*****
89 * Initialization
90 */
91
92 /* This should be called exactly once from device_api_init(). */
93 extern void device_property_init(void);
94
95 /* This structure is usually statically allocated. It holds information about
96 * a property that is common across all devices.
97 */
98 typedef guint DevicePropertyId;
99 typedef struct {
100 DevicePropertyId ID; /* Set by device_property_register() */
101 GType type;
102 const char *name;
103 const char *description;
104 } DevicePropertyBase;
105
106 /* Registers a new property and returns its ID. This function takes ownership
107 * of its argument; it must not be freed later. It should be called from a
108 * device driver's registration function. */
109 extern DevicePropertyId device_property_register(DevicePropertyBase*);
110
111 /* Does the same thing, but fills in a new DevicePropertyBase with the given
112 * values first, and does not return the ID. This is more convenient for
113 * device-specific properties. */
114 extern void device_property_fill_and_register(
115 DevicePropertyBase * base,
116 GType type,
117 const char * name,
118 const char * desc);
119
120 /* Gets a DevicePropertyBase from its ID. */
121 DevicePropertyBase* device_property_get_by_id(DevicePropertyId);
122 DevicePropertyBase* device_property_get_by_name(const char*);
123
124 /*****
125 * Class-level Property Information
126 */
127
128 /* This structure is held inside a Device object. It holds information about a
129 * property that is specific to the device driver, but not to a specific
130 * instance of the driver. */
131 struct Device; /* forward declaration */
132 typedef gboolean (*PropertySetFn)(
133 struct Device *self,
134 DevicePropertyBase *base,
135 GValue *val,
136 PropertySurety surety,
137 PropertySource source);
138 typedef gboolean (*PropertyGetFn)(
139 struct Device *self,
140 DevicePropertyBase *base,
141 GValue *val,
142 PropertySurety *surety,
143 PropertySource *source);
144
145 typedef struct {
146 DevicePropertyBase *base;
147 PropertyAccessFlags access;
148 PropertySetFn setter;
149 PropertyGetFn getter;
150 } DeviceProperty;
151
152 /*****
153 * Property-specific Types, etc.
154 */
155
156 /* Standard property value types here.
157 * Important: see property.c for the other half of type declarations.*/
158 typedef enum {
159 CONCURRENCY_PARADIGM_EXCLUSIVE,
160 CONCURRENCY_PARADIGM_SHARED_READ,
161 CONCURRENCY_PARADIGM_RANDOM_ACCESS
162 } ConcurrencyParadigm;
163 #define CONCURRENCY_PARADIGM_TYPE concurrency_paradigm_get_type()
164 GType concurrency_paradigm_get_type (void);
165
166 #define STREAMING_REQUIREMENT_TYPE streaming_requirement_get_type()
167 GType streaming_requirement_get_type (void);
168
169 typedef enum {
170 MEDIA_ACCESS_MODE_READ_ONLY,
171 MEDIA_ACCESS_MODE_WORM,
172 MEDIA_ACCESS_MODE_READ_WRITE,
173 MEDIA_ACCESS_MODE_WRITE_ONLY
174 } MediaAccessMode;
175 #define MEDIA_ACCESS_MODE_TYPE media_access_mode_get_type()
176 GType media_access_mode_get_type (void);
177
178 /* Standard property definitions follow. See also property.c. */
179
180 /* Value is a ConcurrencyParadigm */
181 extern DevicePropertyBase device_property_concurrency;
182 #define PROPERTY_CONCURRENCY (device_property_concurrency.ID)
183
184 /* Value is a StreamingRequirement */
185 typedef enum {
186 STREAMING_REQUIREMENT_NONE,
187 STREAMING_REQUIREMENT_DESIRED,
188 STREAMING_REQUIREMENT_REQUIRED
189 } StreamingRequirement;
190 extern DevicePropertyBase device_property_streaming;
191 #define PROPERTY_STREAMING (device_property_streaming.ID)
192
193 /* Value is a gboolean. */
194 extern DevicePropertyBase device_property_compression;
195 #define PROPERTY_COMPRESSION (device_property_compression.ID)
196
197 /* Value is a gdouble, representing (compressed size)/(original
198 size). The period over which this value is measured is undefined. */
199 extern DevicePropertyBase device_property_compression_rate;
200 #define PROPERTY_COMPRESSION_RATE (device_property_compression_rate.ID)
201
202 /* Value is a gint; gives the write block size. */
203 extern DevicePropertyBase device_property_block_size;
204 #define PROPERTY_BLOCK_SIZE (device_property_block_size.ID)
205
206 /* Read-only. Value is a guint. */
207 extern DevicePropertyBase device_property_min_block_size;
208 extern DevicePropertyBase device_property_max_block_size;
209 #define PROPERTY_MIN_BLOCK_SIZE (device_property_min_block_size.ID)
210 #define PROPERTY_MAX_BLOCK_SIZE (device_property_max_block_size.ID)
211
212 /* Value is a guint; gives the minimum buffer size for reads. Only
213 * the tape device implements this, but it corresponds to the tapetype
214 * readblocksize parameter, so it's a global property*/
215 extern DevicePropertyBase device_property_read_block_size;
216 #define PROPERTY_READ_BLOCK_SIZE (device_property_read_block_size.ID)
217
218 /* Value is a gboolean. */
219 extern DevicePropertyBase device_property_appendable;
220 #define PROPERTY_APPENDABLE (device_property_appendable.ID)
221
222 /* Value is a string. */
223 extern DevicePropertyBase device_property_canonical_name;
224 #define PROPERTY_CANONICAL_NAME (device_property_canonical_name.ID)
225
226 /* Value is MediaAccessMode. */
227 extern DevicePropertyBase device_property_medium_access_type;
228 #define PROPERTY_MEDIUM_ACCESS_TYPE (device_property_medium_access_type.ID)
229
230 /* Value is a gboolean. */
231 extern DevicePropertyBase device_property_partial_deletion;
232 #define PROPERTY_PARTIAL_DELETION (device_property_partial_deletion.ID)
233
234 /* Value is a gboolean. */
235 extern DevicePropertyBase device_property_full_deletion;
236 #define PROPERTY_FULL_DELETION (device_property_full_deletion.ID)
237
238 /* Value is a guint64. On devices that support it, this property will
239 limit the total amount of data written to a volume; attempts to
240 write beyond this point will cause the device to simulate "out of
241 space". Zero means no limit. */
242 extern DevicePropertyBase device_property_max_volume_usage;
243 #define PROPERTY_MAX_VOLUME_USAGE (device_property_max_volume_usage.ID)
244
245 /* For devices supporting max_volume_usage this property will be used
246 disable/enable property max_volume_usage. If FALSE, max_volume_usage
247 will not be verified while writing to the device */
248 extern DevicePropertyBase device_property_enforce_max_volume_usage;
249 #define PROPERTY_ENFORCE_MAX_VOLUME_USAGE (device_property_enforce_max_volume_usage.ID)
250 /* Should the device produce verbose output? Value is a gboolean. Not
251 * present in all devices. */
252 extern DevicePropertyBase device_property_verbose;
253 #define PROPERTY_VERBOSE (device_property_verbose.ID)
254
255 /* A comment for the use of the user. */
256 extern DevicePropertyBase device_property_comment;
257 #define PROPERTY_COMMENT (device_property_comment.ID)
258
259 /* Does this device support LEOM? */
260 extern DevicePropertyBase device_property_leom;
261 #define PROPERTY_LEOM (device_property_leom.ID)
262
263 /* Whether to re-use connection. */
264 extern DevicePropertyBase device_property_reuse_connection;
265 #define PROPERTY_REUSE_CONNECTION (device_property_reuse_connection.ID)
266
267 /* Speed limits for sending and receiving */
268 extern DevicePropertyBase device_property_max_send_speed;
269 extern DevicePropertyBase device_property_max_recv_speed;
270 #define PROPERTY_MAX_SEND_SPEED (device_property_max_send_speed.ID)
271 #define PROPERTY_MAX_RECV_SPEED (device_property_max_recv_speed.ID)
272
273 /* Number of threads to use */
274 extern DevicePropertyBase device_property_nb_threads_backup;
275 #define PROPERTY_NB_THREADS_BACKUP (device_property_nb_threads_backup.ID)
276 extern DevicePropertyBase device_property_nb_threads_recovery;
277 #define PROPERTY_NB_THREADS_RECOVERY (device_property_nb_threads_recovery.ID)
278
279 /* use multi part upload must be used */
280 extern DevicePropertyBase device_property_multi_part_upload;
281 #define PROPERTY_MULTI_PART_UPLOAD (device_property_multi_part_upload.ID)
282
283 /* Path to certificate authority certificate */
284 extern DevicePropertyBase device_property_ssl_ca_info;
285 #define PROPERTY_SSL_CA_INFO (device_property_ssl_ca_info.ID)
286
287 /* proxy */
288 extern DevicePropertyBase device_property_proxy;
289 #define PROPERTY_PROXY (device_property_proxy.ID)
290 #endif