Branch data Line data Source code
1 : : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- 2 : : * GObject introspection: Property implementation 3 : : * 4 : : * Copyright (C) 2005 Matthias Clasen 5 : : * Copyright (C) 2008,2009 Red Hat, Inc. 6 : : * 7 : : * SPDX-License-Identifier: LGPL-2.1-or-later 8 : : * 9 : : * This library is free software; you can redistribute it and/or 10 : : * modify it under the terms of the GNU Lesser General Public 11 : : * License as published by the Free Software Foundation; either 12 : : * version 2 of the License, or (at your option) any later version. 13 : : * 14 : : * This library is distributed in the hope that it will be useful, 15 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 : : * Lesser General Public License for more details. 18 : : * 19 : : * You should have received a copy of the GNU Lesser General Public 20 : : * License along with this library; if not, write to the 21 : : * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 22 : : * Boston, MA 02111-1307, USA. 23 : : */ 24 : : 25 : : #include "config.h" 26 : : 27 : : #include <glib.h> 28 : : 29 : : #include <girepository/girepository.h> 30 : : #include "gibaseinfo-private.h" 31 : : #include "girepository-private.h" 32 : : #include "gitypelib-internal.h" 33 : : #include "gipropertyinfo.h" 34 : : 35 : : /** 36 : : * GIPropertyInfo: 37 : : * 38 : : * `GIPropertyInfo` represents a property in a [class@GObject.Object]. 39 : : * 40 : : * A property belongs to either a [class@GIRepository.ObjectInfo] or a 41 : : * [class@GIRepository.InterfaceInfo]. 42 : : * 43 : : * Since: 2.80 44 : : */ 45 : : 46 : : /** 47 : : * gi_property_info_get_flags: 48 : : * @info: a #GIPropertyInfo 49 : : * 50 : : * Obtain the flags for this property info. 51 : : * 52 : : * See [type@GObject.ParamFlags] for more information about possible flag 53 : : * values. 54 : : * 55 : : * Returns: the flags 56 : : * Since: 2.80 57 : : */ 58 : : GParamFlags 59 : 0 : gi_property_info_get_flags (GIPropertyInfo *info) 60 : : { 61 : : GParamFlags flags; 62 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info; 63 : : PropertyBlob *blob; 64 : : 65 : 0 : g_return_val_if_fail (info != NULL, 0); 66 : 0 : g_return_val_if_fail (GI_IS_PROPERTY_INFO (info), 0); 67 : : 68 : 0 : blob = (PropertyBlob *)&rinfo->typelib->data[rinfo->offset]; 69 : : 70 : 0 : flags = 0; 71 : : 72 [ # # ]: 0 : if (blob->readable) 73 : 0 : flags = flags | G_PARAM_READABLE; 74 : : 75 [ # # ]: 0 : if (blob->writable) 76 : 0 : flags = flags | G_PARAM_WRITABLE; 77 : : 78 [ # # ]: 0 : if (blob->construct) 79 : 0 : flags = flags | G_PARAM_CONSTRUCT; 80 : : 81 [ # # ]: 0 : if (blob->construct_only) 82 : 0 : flags = flags | G_PARAM_CONSTRUCT_ONLY; 83 : : 84 : 0 : return flags; 85 : : } 86 : : 87 : : /** 88 : : * gi_property_info_get_type_info: 89 : : * @info: a #GIPropertyInfo 90 : : * 91 : : * Obtain the type information for the property @info. 92 : : * 93 : : * Returns: (transfer full): The [class@GIRepository.TypeInfo]. Free it with 94 : : * [method@GIRepository.BaseInfo.unref] when done. 95 : : * Since: 2.80 96 : : */ 97 : : GITypeInfo * 98 : 0 : gi_property_info_get_type_info (GIPropertyInfo *info) 99 : : { 100 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info; 101 : : 102 : 0 : g_return_val_if_fail (info != NULL, NULL); 103 : 0 : g_return_val_if_fail (GI_IS_PROPERTY_INFO (info), NULL); 104 : : 105 : 0 : return gi_type_info_new ((GIBaseInfo*)info, 106 : : rinfo->typelib, 107 : 0 : rinfo->offset + G_STRUCT_OFFSET (PropertyBlob, type)); 108 : : } 109 : : 110 : : /** 111 : : * gi_property_info_get_ownership_transfer: 112 : : * @info: a #GIPropertyInfo 113 : : * 114 : : * Obtain the ownership transfer for this property. 115 : : * 116 : : * See [type@GIRepository.Transfer] for more information about transfer values. 117 : : * 118 : : * Returns: the transfer 119 : : * Since: 2.80 120 : : */ 121 : : GITransfer 122 : 0 : gi_property_info_get_ownership_transfer (GIPropertyInfo *info) 123 : : { 124 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info; 125 : : PropertyBlob *blob; 126 : : 127 : 0 : g_return_val_if_fail (info != NULL, -1); 128 : 0 : g_return_val_if_fail (GI_IS_PROPERTY_INFO (info), -1); 129 : : 130 : 0 : blob = (PropertyBlob *)&rinfo->typelib->data[rinfo->offset]; 131 : : 132 [ # # ]: 0 : if (blob->transfer_ownership) 133 : 0 : return GI_TRANSFER_EVERYTHING; 134 [ # # ]: 0 : else if (blob->transfer_container_ownership) 135 : 0 : return GI_TRANSFER_CONTAINER; 136 : : else 137 : 0 : return GI_TRANSFER_NOTHING; 138 : : } 139 : : 140 : : /** 141 : : * gi_property_info_get_setter: 142 : : * @info: a #GIPropertyInfo 143 : : * 144 : : * Obtains the setter function associated with this `GIPropertyInfo`. 145 : : * 146 : : * The setter is only available for `G_PARAM_WRITABLE` properties that 147 : : * are also not `G_PARAM_CONSTRUCT_ONLY`. 148 : : * 149 : : * Returns: (transfer full) (nullable): The function info, or `NULL` if not set. 150 : : * Free it with [method@GIRepository.BaseInfo.unref] when done. 151 : : * Since: 2.80 152 : : */ 153 : : GIFunctionInfo * 154 : 0 : gi_property_info_get_setter (GIPropertyInfo *info) 155 : : { 156 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info; 157 : : PropertyBlob *blob; 158 : : GIBaseInfo *container; 159 : : GIInfoType parent_type; 160 : : 161 : 0 : g_return_val_if_fail (info != NULL, NULL); 162 : 0 : g_return_val_if_fail (GI_IS_PROPERTY_INFO (info), NULL); 163 : : 164 : 0 : blob = (PropertyBlob *)&rinfo->typelib->data[rinfo->offset]; 165 [ # # # # ]: 0 : if (!blob->writable || blob->construct_only) 166 : 0 : return NULL; 167 : : 168 [ # # ]: 0 : if (blob->setter == ACCESSOR_SENTINEL) 169 : 0 : return NULL; 170 : : 171 : 0 : container = rinfo->container; 172 : 0 : parent_type = gi_base_info_get_info_type (container); 173 [ # # ]: 0 : if (parent_type == GI_INFO_TYPE_OBJECT) 174 : 0 : return gi_object_info_get_method ((GIObjectInfo *) container, blob->setter); 175 [ # # ]: 0 : else if (parent_type == GI_INFO_TYPE_INTERFACE) 176 : 0 : return gi_interface_info_get_method ((GIInterfaceInfo *) container, blob->setter); 177 : : else 178 : 0 : return NULL; 179 : : } 180 : : 181 : : /** 182 : : * gi_property_info_get_getter: 183 : : * @info: a #GIPropertyInfo 184 : : * 185 : : * Obtains the getter function associated with this `GIPropertyInfo`. 186 : : * 187 : : * The setter is only available for `G_PARAM_READABLE` properties. 188 : : * 189 : : * Returns: (transfer full) (nullable): The function info, or `NULL` if not set. 190 : : * Free it with [method@GIRepository.BaseInfo.unref] when done. 191 : : * Since: 2.80 192 : : */ 193 : : GIFunctionInfo * 194 : 0 : gi_property_info_get_getter (GIPropertyInfo *info) 195 : : { 196 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info; 197 : : PropertyBlob *blob; 198 : : GIBaseInfo *container; 199 : : GIInfoType parent_type; 200 : : 201 : 0 : g_return_val_if_fail (info != NULL, NULL); 202 : 0 : g_return_val_if_fail (GI_IS_PROPERTY_INFO (info), NULL); 203 : : 204 : 0 : blob = (PropertyBlob *)&rinfo->typelib->data[rinfo->offset]; 205 [ # # ]: 0 : if (!blob->readable) 206 : 0 : return NULL; 207 : : 208 [ # # ]: 0 : if (blob->getter == ACCESSOR_SENTINEL) 209 : 0 : return NULL; 210 : : 211 : 0 : container = rinfo->container; 212 : 0 : parent_type = gi_base_info_get_info_type (container); 213 [ # # ]: 0 : if (parent_type == GI_INFO_TYPE_OBJECT) 214 : 0 : return gi_object_info_get_method ((GIObjectInfo *) container, blob->getter); 215 [ # # ]: 0 : else if (parent_type == GI_INFO_TYPE_INTERFACE) 216 : 0 : return gi_interface_info_get_method ((GIInterfaceInfo *) container, blob->getter); 217 : : else 218 : 0 : return NULL; 219 : : } 220 : : 221 : : void 222 : 1 : gi_property_info_class_init (gpointer g_class, 223 : : gpointer class_data) 224 : : { 225 : 1 : GIBaseInfoClass *info_class = g_class; 226 : : 227 : 1 : info_class->info_type = GI_INFO_TYPE_PROPERTY; 228 : 1 : }