1 /* 2 * libInstPatch 3 * Copyright (C) 1999-2014 Element Green <element@elementsofsound.org> 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public License 7 * as published by the Free Software Foundation; version 2.1 8 * of the License only. 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 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 18 * 02110-1301, USA or on the web at http://www.gnu.org. 19 */ 20 #ifndef __IPATCH_XML_OBJECT_H__ 21 #define __IPATCH_XML_OBJECT_H__ 22 23 #include <glib.h> 24 #include <glib-object.h> 25 26 /** 27 * IpatchXmlEncodeFunc: 28 * @node: XML node to encode XML to 29 * @object: Object being encoded (object and property encoders) 30 * @pspec: Spec of property being encoded (property encoders only) 31 * @value: Value to encode (property and GValue encoders only) 32 * @err: Location to store error value (or %NULL if ignoring) 33 * 34 * Function type for encoding objects, properties or GValue types to XML trees. 35 * Forms the basis of serializing GObject and GValues to XML. The caller 36 * handles creating an XML node element to contain the given object, property or 37 * value XML encoding. 38 * 39 * Returns: Should return %TRUE on success and %FALSE on error (in which 40 * case @err should be set). 41 */ 42 typedef gboolean(*IpatchXmlEncodeFunc)(GNode *node, GObject *object, 43 GParamSpec *pspec, GValue *value, 44 GError **err); 45 /** 46 * IpatchXmlDecodeFunc: 47 * @node: XML node to be decoded 48 * @object: Object being decoded to (object and property decoders, %NULL otherwise) 49 * @pspec: Spec of property being decoded (property decoders only, %NULL otherwise) 50 * @value: Value to decode to (property and GValue decoders only, %NULL otherwise) 51 * @err: Location to store error value (or %NULL if ignoring) 52 * 53 * Function type for decoding objects, properties or GValue types from XML trees to 54 * their original instance values in memory. For object decoders, only @object 55 * will be set and the decoded XML content should be assigned to the object; 56 * for property decoders @object, @pspec and @value will be set, @value is 57 * initialized to the property value type and the decoded value should be 58 * assigned to it; for GValue decoders, only the @value will be initialized 59 * which the decoded value should be assigned to. 60 * 61 * Returns: Should return TRUE on success, FALSE otherwise (in which case @err 62 * should be set) 63 */ 64 typedef gboolean(*IpatchXmlDecodeFunc)(GNode *node, GObject *object, 65 GParamSpec *pspec, GValue *value, 66 GError **err); 67 68 void ipatch_xml_register_handler(GType type, const char *prop_name, 69 IpatchXmlEncodeFunc encode_func, 70 IpatchXmlDecodeFunc decode_func); 71 void 72 ipatch_xml_register_handler_full(GType type, const char *prop_name, 73 IpatchXmlEncodeFunc encode_func, 74 IpatchXmlDecodeFunc decode_func, 75 GDestroyNotify notify_func, gpointer user_data); 76 gboolean ipatch_xml_lookup_handler(GType type, GParamSpec *pspec, 77 IpatchXmlEncodeFunc *encode_func, 78 IpatchXmlDecodeFunc *decode_func); 79 gboolean ipatch_xml_lookup_handler_by_prop_name(GType type, const char *prop_name, 80 IpatchXmlEncodeFunc *encode_func, 81 IpatchXmlDecodeFunc *decode_func); 82 83 gboolean ipatch_xml_encode_object(GNode *node, GObject *object, 84 gboolean create_element, GError **err); 85 gboolean ipatch_xml_encode_property(GNode *node, GObject *object, GParamSpec *pspec, 86 gboolean create_element, GError **err); 87 gboolean ipatch_xml_encode_property_by_name(GNode *node, GObject *object, 88 const char *propname, 89 gboolean create_element, GError **err); 90 gboolean ipatch_xml_encode_value(GNode *node, GValue *value, GError **err); 91 92 gboolean ipatch_xml_decode_object(GNode *node, GObject *object, GError **err); 93 gboolean ipatch_xml_decode_property(GNode *node, GObject *object, GParamSpec *pspec, 94 GError **err); 95 gboolean ipatch_xml_decode_property_by_name(GNode *node, GObject *object, 96 const char *propname, GError **err); 97 gboolean ipatch_xml_decode_value(GNode *node, GValue *value, GError **err); 98 99 gboolean ipatch_xml_default_encode_object_func(GNode *node, GObject *object, 100 GParamSpec *pspec, GValue *value, 101 GError **err); 102 gboolean ipatch_xml_default_encode_property_func(GNode *node, GObject *object, 103 GParamSpec *pspec, GValue *value, 104 GError **err); 105 gboolean ipatch_xml_default_encode_value_func(GNode *node, GObject *object, 106 GParamSpec *pspec, GValue *value, 107 GError **err); 108 gboolean ipatch_xml_default_decode_object_func(GNode *node, GObject *object, 109 GParamSpec *pspec, GValue *value, 110 GError **err); 111 gboolean ipatch_xml_default_decode_property_func(GNode *node, GObject *object, 112 GParamSpec *pspec, GValue *value, 113 GError **err); 114 gboolean ipatch_xml_default_decode_value_func(GNode *node, GObject *object, 115 GParamSpec *pspec, GValue *value, 116 GError **err); 117 #endif 118