gvariant.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /*
  2. * Copyright © 2007, 2008 Ryan Lortie
  3. * Copyright © 2009, 2010 Codethink Limited
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the licence, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * Author: Ryan Lortie <[email protected]>
  19. */
  20. #ifndef __G_VARIANT_H__
  21. #define __G_VARIANT_H__
  22. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  23. #error "Only <glib.h> can be included directly."
  24. #endif
  25. #include <glib/gvarianttype.h>
  26. #include <glib/gstring.h>
  27. #include <glib/gbytes.h>
  28. G_BEGIN_DECLS
  29. typedef struct _GVariant GVariant;
  30. typedef enum
  31. {
  32. G_VARIANT_CLASS_BOOLEAN = 'b',
  33. G_VARIANT_CLASS_BYTE = 'y',
  34. G_VARIANT_CLASS_INT16 = 'n',
  35. G_VARIANT_CLASS_UINT16 = 'q',
  36. G_VARIANT_CLASS_INT32 = 'i',
  37. G_VARIANT_CLASS_UINT32 = 'u',
  38. G_VARIANT_CLASS_INT64 = 'x',
  39. G_VARIANT_CLASS_UINT64 = 't',
  40. G_VARIANT_CLASS_HANDLE = 'h',
  41. G_VARIANT_CLASS_DOUBLE = 'd',
  42. G_VARIANT_CLASS_STRING = 's',
  43. G_VARIANT_CLASS_OBJECT_PATH = 'o',
  44. G_VARIANT_CLASS_SIGNATURE = 'g',
  45. G_VARIANT_CLASS_VARIANT = 'v',
  46. G_VARIANT_CLASS_MAYBE = 'm',
  47. G_VARIANT_CLASS_ARRAY = 'a',
  48. G_VARIANT_CLASS_TUPLE = '(',
  49. G_VARIANT_CLASS_DICT_ENTRY = '{'
  50. } GVariantClass;
  51. GLIB_AVAILABLE_IN_ALL
  52. void g_variant_unref (GVariant *value);
  53. GLIB_AVAILABLE_IN_ALL
  54. GVariant * g_variant_ref (GVariant *value);
  55. GLIB_AVAILABLE_IN_ALL
  56. GVariant * g_variant_ref_sink (GVariant *value);
  57. GLIB_AVAILABLE_IN_ALL
  58. gboolean g_variant_is_floating (GVariant *value);
  59. GLIB_AVAILABLE_IN_ALL
  60. GVariant * g_variant_take_ref (GVariant *value);
  61. GLIB_AVAILABLE_IN_ALL
  62. const GVariantType * g_variant_get_type (GVariant *value);
  63. GLIB_AVAILABLE_IN_ALL
  64. const gchar * g_variant_get_type_string (GVariant *value);
  65. GLIB_AVAILABLE_IN_ALL
  66. gboolean g_variant_is_of_type (GVariant *value,
  67. const GVariantType *type);
  68. GLIB_AVAILABLE_IN_ALL
  69. gboolean g_variant_is_container (GVariant *value);
  70. GLIB_AVAILABLE_IN_ALL
  71. GVariantClass g_variant_classify (GVariant *value);
  72. GLIB_AVAILABLE_IN_ALL
  73. GVariant * g_variant_new_boolean (gboolean value);
  74. GLIB_AVAILABLE_IN_ALL
  75. GVariant * g_variant_new_byte (guchar value);
  76. GLIB_AVAILABLE_IN_ALL
  77. GVariant * g_variant_new_int16 (gint16 value);
  78. GLIB_AVAILABLE_IN_ALL
  79. GVariant * g_variant_new_uint16 (guint16 value);
  80. GLIB_AVAILABLE_IN_ALL
  81. GVariant * g_variant_new_int32 (gint32 value);
  82. GLIB_AVAILABLE_IN_ALL
  83. GVariant * g_variant_new_uint32 (guint32 value);
  84. GLIB_AVAILABLE_IN_ALL
  85. GVariant * g_variant_new_int64 (gint64 value);
  86. GLIB_AVAILABLE_IN_ALL
  87. GVariant * g_variant_new_uint64 (guint64 value);
  88. GLIB_AVAILABLE_IN_ALL
  89. GVariant * g_variant_new_handle (gint32 value);
  90. GLIB_AVAILABLE_IN_ALL
  91. GVariant * g_variant_new_double (gdouble value);
  92. GLIB_AVAILABLE_IN_ALL
  93. GVariant * g_variant_new_string (const gchar *string);
  94. GLIB_AVAILABLE_IN_2_38
  95. GVariant * g_variant_new_take_string (gchar *string);
  96. GLIB_AVAILABLE_IN_2_38
  97. GVariant * g_variant_new_printf (const gchar *format_string,
  98. ...) G_GNUC_PRINTF (1, 2);
  99. GLIB_AVAILABLE_IN_ALL
  100. GVariant * g_variant_new_object_path (const gchar *object_path);
  101. GLIB_AVAILABLE_IN_ALL
  102. gboolean g_variant_is_object_path (const gchar *string);
  103. GLIB_AVAILABLE_IN_ALL
  104. GVariant * g_variant_new_signature (const gchar *signature);
  105. GLIB_AVAILABLE_IN_ALL
  106. gboolean g_variant_is_signature (const gchar *string);
  107. GLIB_AVAILABLE_IN_ALL
  108. GVariant * g_variant_new_variant (GVariant *value);
  109. GLIB_AVAILABLE_IN_ALL
  110. GVariant * g_variant_new_strv (const gchar * const *strv,
  111. gssize length);
  112. GLIB_AVAILABLE_IN_2_30
  113. GVariant * g_variant_new_objv (const gchar * const *strv,
  114. gssize length);
  115. GLIB_AVAILABLE_IN_ALL
  116. GVariant * g_variant_new_bytestring (const gchar *string);
  117. GLIB_AVAILABLE_IN_ALL
  118. GVariant * g_variant_new_bytestring_array (const gchar * const *strv,
  119. gssize length);
  120. GLIB_AVAILABLE_IN_ALL
  121. GVariant * g_variant_new_fixed_array (const GVariantType *element_type,
  122. gconstpointer elements,
  123. gsize n_elements,
  124. gsize element_size);
  125. GLIB_AVAILABLE_IN_ALL
  126. gboolean g_variant_get_boolean (GVariant *value);
  127. GLIB_AVAILABLE_IN_ALL
  128. guchar g_variant_get_byte (GVariant *value);
  129. GLIB_AVAILABLE_IN_ALL
  130. gint16 g_variant_get_int16 (GVariant *value);
  131. GLIB_AVAILABLE_IN_ALL
  132. guint16 g_variant_get_uint16 (GVariant *value);
  133. GLIB_AVAILABLE_IN_ALL
  134. gint32 g_variant_get_int32 (GVariant *value);
  135. GLIB_AVAILABLE_IN_ALL
  136. guint32 g_variant_get_uint32 (GVariant *value);
  137. GLIB_AVAILABLE_IN_ALL
  138. gint64 g_variant_get_int64 (GVariant *value);
  139. GLIB_AVAILABLE_IN_ALL
  140. guint64 g_variant_get_uint64 (GVariant *value);
  141. GLIB_AVAILABLE_IN_ALL
  142. gint32 g_variant_get_handle (GVariant *value);
  143. GLIB_AVAILABLE_IN_ALL
  144. gdouble g_variant_get_double (GVariant *value);
  145. GLIB_AVAILABLE_IN_ALL
  146. GVariant * g_variant_get_variant (GVariant *value);
  147. GLIB_AVAILABLE_IN_ALL
  148. const gchar * g_variant_get_string (GVariant *value,
  149. gsize *length);
  150. GLIB_AVAILABLE_IN_ALL
  151. gchar * g_variant_dup_string (GVariant *value,
  152. gsize *length);
  153. GLIB_AVAILABLE_IN_ALL
  154. const gchar ** g_variant_get_strv (GVariant *value,
  155. gsize *length);
  156. GLIB_AVAILABLE_IN_ALL
  157. gchar ** g_variant_dup_strv (GVariant *value,
  158. gsize *length);
  159. GLIB_AVAILABLE_IN_2_30
  160. const gchar ** g_variant_get_objv (GVariant *value,
  161. gsize *length);
  162. GLIB_AVAILABLE_IN_ALL
  163. gchar ** g_variant_dup_objv (GVariant *value,
  164. gsize *length);
  165. GLIB_AVAILABLE_IN_ALL
  166. const gchar * g_variant_get_bytestring (GVariant *value);
  167. GLIB_AVAILABLE_IN_ALL
  168. gchar * g_variant_dup_bytestring (GVariant *value,
  169. gsize *length);
  170. GLIB_AVAILABLE_IN_ALL
  171. const gchar ** g_variant_get_bytestring_array (GVariant *value,
  172. gsize *length);
  173. GLIB_AVAILABLE_IN_ALL
  174. gchar ** g_variant_dup_bytestring_array (GVariant *value,
  175. gsize *length);
  176. GLIB_AVAILABLE_IN_ALL
  177. GVariant * g_variant_new_maybe (const GVariantType *child_type,
  178. GVariant *child);
  179. GLIB_AVAILABLE_IN_ALL
  180. GVariant * g_variant_new_array (const GVariantType *child_type,
  181. GVariant * const *children,
  182. gsize n_children);
  183. GLIB_AVAILABLE_IN_ALL
  184. GVariant * g_variant_new_tuple (GVariant * const *children,
  185. gsize n_children);
  186. GLIB_AVAILABLE_IN_ALL
  187. GVariant * g_variant_new_dict_entry (GVariant *key,
  188. GVariant *value);
  189. GLIB_AVAILABLE_IN_ALL
  190. GVariant * g_variant_get_maybe (GVariant *value);
  191. GLIB_AVAILABLE_IN_ALL
  192. gsize g_variant_n_children (GVariant *value);
  193. GLIB_AVAILABLE_IN_ALL
  194. void g_variant_get_child (GVariant *value,
  195. gsize index_,
  196. const gchar *format_string,
  197. ...);
  198. GLIB_AVAILABLE_IN_ALL
  199. GVariant * g_variant_get_child_value (GVariant *value,
  200. gsize index_);
  201. GLIB_AVAILABLE_IN_ALL
  202. gboolean g_variant_lookup (GVariant *dictionary,
  203. const gchar *key,
  204. const gchar *format_string,
  205. ...);
  206. GLIB_AVAILABLE_IN_ALL
  207. GVariant * g_variant_lookup_value (GVariant *dictionary,
  208. const gchar *key,
  209. const GVariantType *expected_type);
  210. GLIB_AVAILABLE_IN_ALL
  211. gconstpointer g_variant_get_fixed_array (GVariant *value,
  212. gsize *n_elements,
  213. gsize element_size);
  214. GLIB_AVAILABLE_IN_ALL
  215. gsize g_variant_get_size (GVariant *value);
  216. GLIB_AVAILABLE_IN_ALL
  217. gconstpointer g_variant_get_data (GVariant *value);
  218. GLIB_AVAILABLE_IN_2_36
  219. GBytes * g_variant_get_data_as_bytes (GVariant *value);
  220. GLIB_AVAILABLE_IN_ALL
  221. void g_variant_store (GVariant *value,
  222. gpointer data);
  223. GLIB_AVAILABLE_IN_ALL
  224. gchar * g_variant_print (GVariant *value,
  225. gboolean type_annotate);
  226. GLIB_AVAILABLE_IN_ALL
  227. GString * g_variant_print_string (GVariant *value,
  228. GString *string,
  229. gboolean type_annotate);
  230. GLIB_AVAILABLE_IN_ALL
  231. guint g_variant_hash (gconstpointer value);
  232. GLIB_AVAILABLE_IN_ALL
  233. gboolean g_variant_equal (gconstpointer one,
  234. gconstpointer two);
  235. GLIB_AVAILABLE_IN_ALL
  236. GVariant * g_variant_get_normal_form (GVariant *value);
  237. GLIB_AVAILABLE_IN_ALL
  238. gboolean g_variant_is_normal_form (GVariant *value);
  239. GLIB_AVAILABLE_IN_ALL
  240. GVariant * g_variant_byteswap (GVariant *value);
  241. GLIB_AVAILABLE_IN_2_36
  242. GVariant * g_variant_new_from_bytes (const GVariantType *type,
  243. GBytes *bytes,
  244. gboolean trusted);
  245. GLIB_AVAILABLE_IN_ALL
  246. GVariant * g_variant_new_from_data (const GVariantType *type,
  247. gconstpointer data,
  248. gsize size,
  249. gboolean trusted,
  250. GDestroyNotify notify,
  251. gpointer user_data);
  252. typedef struct _GVariantIter GVariantIter;
  253. struct _GVariantIter {
  254. /*< private >*/
  255. gsize x[16];
  256. };
  257. GLIB_AVAILABLE_IN_ALL
  258. GVariantIter * g_variant_iter_new (GVariant *value);
  259. GLIB_AVAILABLE_IN_ALL
  260. gsize g_variant_iter_init (GVariantIter *iter,
  261. GVariant *value);
  262. GLIB_AVAILABLE_IN_ALL
  263. GVariantIter * g_variant_iter_copy (GVariantIter *iter);
  264. GLIB_AVAILABLE_IN_ALL
  265. gsize g_variant_iter_n_children (GVariantIter *iter);
  266. GLIB_AVAILABLE_IN_ALL
  267. void g_variant_iter_free (GVariantIter *iter);
  268. GLIB_AVAILABLE_IN_ALL
  269. GVariant * g_variant_iter_next_value (GVariantIter *iter);
  270. GLIB_AVAILABLE_IN_ALL
  271. gboolean g_variant_iter_next (GVariantIter *iter,
  272. const gchar *format_string,
  273. ...);
  274. GLIB_AVAILABLE_IN_ALL
  275. gboolean g_variant_iter_loop (GVariantIter *iter,
  276. const gchar *format_string,
  277. ...);
  278. typedef struct _GVariantBuilder GVariantBuilder;
  279. struct _GVariantBuilder {
  280. /*< private >*/
  281. gsize x[16];
  282. };
  283. typedef enum
  284. {
  285. G_VARIANT_PARSE_ERROR_FAILED,
  286. G_VARIANT_PARSE_ERROR_BASIC_TYPE_EXPECTED,
  287. G_VARIANT_PARSE_ERROR_CANNOT_INFER_TYPE,
  288. G_VARIANT_PARSE_ERROR_DEFINITE_TYPE_EXPECTED,
  289. G_VARIANT_PARSE_ERROR_INPUT_NOT_AT_END,
  290. G_VARIANT_PARSE_ERROR_INVALID_CHARACTER,
  291. G_VARIANT_PARSE_ERROR_INVALID_FORMAT_STRING,
  292. G_VARIANT_PARSE_ERROR_INVALID_OBJECT_PATH,
  293. G_VARIANT_PARSE_ERROR_INVALID_SIGNATURE,
  294. G_VARIANT_PARSE_ERROR_INVALID_TYPE_STRING,
  295. G_VARIANT_PARSE_ERROR_NO_COMMON_TYPE,
  296. G_VARIANT_PARSE_ERROR_NUMBER_OUT_OF_RANGE,
  297. G_VARIANT_PARSE_ERROR_NUMBER_TOO_BIG,
  298. G_VARIANT_PARSE_ERROR_TYPE_ERROR,
  299. G_VARIANT_PARSE_ERROR_UNEXPECTED_TOKEN,
  300. G_VARIANT_PARSE_ERROR_UNKNOWN_KEYWORD,
  301. G_VARIANT_PARSE_ERROR_UNTERMINATED_STRING_CONSTANT,
  302. G_VARIANT_PARSE_ERROR_VALUE_EXPECTED
  303. } GVariantParseError;
  304. #define G_VARIANT_PARSE_ERROR (g_variant_parse_error_quark ())
  305. GLIB_DEPRECATED_IN_2_38_FOR(g_variant_parse_error_quark)
  306. GQuark g_variant_parser_get_error_quark (void);
  307. GLIB_AVAILABLE_IN_ALL
  308. GQuark g_variant_parse_error_quark (void);
  309. GLIB_AVAILABLE_IN_ALL
  310. GVariantBuilder * g_variant_builder_new (const GVariantType *type);
  311. GLIB_AVAILABLE_IN_ALL
  312. void g_variant_builder_unref (GVariantBuilder *builder);
  313. GLIB_AVAILABLE_IN_ALL
  314. GVariantBuilder * g_variant_builder_ref (GVariantBuilder *builder);
  315. GLIB_AVAILABLE_IN_ALL
  316. void g_variant_builder_init (GVariantBuilder *builder,
  317. const GVariantType *type);
  318. GLIB_AVAILABLE_IN_ALL
  319. GVariant * g_variant_builder_end (GVariantBuilder *builder);
  320. GLIB_AVAILABLE_IN_ALL
  321. void g_variant_builder_clear (GVariantBuilder *builder);
  322. GLIB_AVAILABLE_IN_ALL
  323. void g_variant_builder_open (GVariantBuilder *builder,
  324. const GVariantType *type);
  325. GLIB_AVAILABLE_IN_ALL
  326. void g_variant_builder_close (GVariantBuilder *builder);
  327. GLIB_AVAILABLE_IN_ALL
  328. void g_variant_builder_add_value (GVariantBuilder *builder,
  329. GVariant *value);
  330. GLIB_AVAILABLE_IN_ALL
  331. void g_variant_builder_add (GVariantBuilder *builder,
  332. const gchar *format_string,
  333. ...);
  334. GLIB_AVAILABLE_IN_ALL
  335. void g_variant_builder_add_parsed (GVariantBuilder *builder,
  336. const gchar *format,
  337. ...);
  338. GLIB_AVAILABLE_IN_ALL
  339. GVariant * g_variant_new (const gchar *format_string,
  340. ...);
  341. GLIB_AVAILABLE_IN_ALL
  342. void g_variant_get (GVariant *value,
  343. const gchar *format_string,
  344. ...);
  345. GLIB_AVAILABLE_IN_ALL
  346. GVariant * g_variant_new_va (const gchar *format_string,
  347. const gchar **endptr,
  348. va_list *app);
  349. GLIB_AVAILABLE_IN_ALL
  350. void g_variant_get_va (GVariant *value,
  351. const gchar *format_string,
  352. const gchar **endptr,
  353. va_list *app);
  354. GLIB_AVAILABLE_IN_2_34
  355. gboolean g_variant_check_format_string (GVariant *value,
  356. const gchar *format_string,
  357. gboolean copy_only);
  358. GLIB_AVAILABLE_IN_ALL
  359. GVariant * g_variant_parse (const GVariantType *type,
  360. const gchar *text,
  361. const gchar *limit,
  362. const gchar **endptr,
  363. GError **error);
  364. GLIB_AVAILABLE_IN_ALL
  365. GVariant * g_variant_new_parsed (const gchar *format,
  366. ...);
  367. GLIB_AVAILABLE_IN_ALL
  368. GVariant * g_variant_new_parsed_va (const gchar *format,
  369. va_list *app);
  370. GLIB_AVAILABLE_IN_2_40
  371. gchar * g_variant_parse_error_print_context (GError *error,
  372. const gchar *source_str);
  373. GLIB_AVAILABLE_IN_ALL
  374. gint g_variant_compare (gconstpointer one,
  375. gconstpointer two);
  376. typedef struct _GVariantDict GVariantDict;
  377. struct _GVariantDict {
  378. /*< private >*/
  379. gsize x[16];
  380. };
  381. GLIB_AVAILABLE_IN_2_40
  382. GVariantDict * g_variant_dict_new (GVariant *from_asv);
  383. GLIB_AVAILABLE_IN_2_40
  384. void g_variant_dict_init (GVariantDict *dict,
  385. GVariant *from_asv);
  386. GLIB_AVAILABLE_IN_2_40
  387. gboolean g_variant_dict_lookup (GVariantDict *dict,
  388. const gchar *key,
  389. const gchar *format_string,
  390. ...);
  391. GLIB_AVAILABLE_IN_2_40
  392. GVariant * g_variant_dict_lookup_value (GVariantDict *dict,
  393. const gchar *key,
  394. const GVariantType *expected_type);
  395. GLIB_AVAILABLE_IN_2_40
  396. gboolean g_variant_dict_contains (GVariantDict *dict,
  397. const gchar *key);
  398. GLIB_AVAILABLE_IN_2_40
  399. void g_variant_dict_insert (GVariantDict *dict,
  400. const gchar *key,
  401. const gchar *format_string,
  402. ...);
  403. GLIB_AVAILABLE_IN_2_40
  404. void g_variant_dict_insert_value (GVariantDict *dict,
  405. const gchar *key,
  406. GVariant *value);
  407. GLIB_AVAILABLE_IN_2_40
  408. gboolean g_variant_dict_remove (GVariantDict *dict,
  409. const gchar *key);
  410. GLIB_AVAILABLE_IN_2_40
  411. void g_variant_dict_clear (GVariantDict *dict);
  412. GLIB_AVAILABLE_IN_2_40
  413. GVariant * g_variant_dict_end (GVariantDict *dict);
  414. GLIB_AVAILABLE_IN_2_40
  415. GVariantDict * g_variant_dict_ref (GVariantDict *dict);
  416. GLIB_AVAILABLE_IN_2_40
  417. void g_variant_dict_unref (GVariantDict *dict);
  418. G_END_DECLS
  419. #endif /* __G_VARIANT_H__ */