gobject.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. /* GObject - GLib Type, Object, Parameter and Signal Library
  2. * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General
  15. * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __G_OBJECT_H__
  18. #define __G_OBJECT_H__
  19. #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
  20. #error "Only <glib-object.h> can be included directly."
  21. #endif
  22. #include <gobject/gtype.h>
  23. #include <gobject/gvalue.h>
  24. #include <gobject/gparam.h>
  25. #include <gobject/gclosure.h>
  26. #include <gobject/gsignal.h>
  27. #include <gobject/gboxed.h>
  28. G_BEGIN_DECLS
  29. /* --- type macros --- */
  30. /**
  31. * G_TYPE_IS_OBJECT:
  32. * @type: Type id to check
  33. *
  34. * Check if the passed in type id is a %G_TYPE_OBJECT or derived from it.
  35. *
  36. * Returns: %FALSE or %TRUE, indicating whether @type is a %G_TYPE_OBJECT.
  37. */
  38. #define G_TYPE_IS_OBJECT(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT)
  39. /**
  40. * G_OBJECT:
  41. * @object: Object which is subject to casting.
  42. *
  43. * Casts a #GObject or derived pointer into a (GObject*) pointer.
  44. * Depending on the current debugging level, this function may invoke
  45. * certain runtime checks to identify invalid casts.
  46. */
  47. #define G_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject))
  48. /**
  49. * G_OBJECT_CLASS:
  50. * @class: a valid #GObjectClass
  51. *
  52. * Casts a derived #GObjectClass structure into a #GObjectClass structure.
  53. */
  54. #define G_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass))
  55. /**
  56. * G_IS_OBJECT:
  57. * @object: Instance to check for being a %G_TYPE_OBJECT.
  58. *
  59. * Checks whether a valid #GTypeInstance pointer is of type %G_TYPE_OBJECT.
  60. */
  61. #if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_42
  62. #define G_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE ((object), G_TYPE_OBJECT))
  63. #else
  64. #define G_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_OBJECT))
  65. #endif
  66. /**
  67. * G_IS_OBJECT_CLASS:
  68. * @class: a #GObjectClass
  69. *
  70. * Checks whether @class "is a" valid #GObjectClass structure of type
  71. * %G_TYPE_OBJECT or derived.
  72. */
  73. #define G_IS_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_OBJECT))
  74. /**
  75. * G_OBJECT_GET_CLASS:
  76. * @object: a #GObject instance.
  77. *
  78. * Get the class structure associated to a #GObject instance.
  79. *
  80. * Returns: pointer to object class structure.
  81. */
  82. #define G_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass))
  83. /**
  84. * G_OBJECT_TYPE:
  85. * @object: Object to return the type id for.
  86. *
  87. * Get the type id of an object.
  88. *
  89. * Returns: Type id of @object.
  90. */
  91. #define G_OBJECT_TYPE(object) (G_TYPE_FROM_INSTANCE (object))
  92. /**
  93. * G_OBJECT_TYPE_NAME:
  94. * @object: Object to return the type name for.
  95. *
  96. * Get the name of an object's type.
  97. *
  98. * Returns: Type name of @object. The string is owned by the type system and
  99. * should not be freed.
  100. */
  101. #define G_OBJECT_TYPE_NAME(object) (g_type_name (G_OBJECT_TYPE (object)))
  102. /**
  103. * G_OBJECT_CLASS_TYPE:
  104. * @class: a valid #GObjectClass
  105. *
  106. * Get the type id of a class structure.
  107. *
  108. * Returns: Type id of @class.
  109. */
  110. #define G_OBJECT_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class))
  111. /**
  112. * G_OBJECT_CLASS_NAME:
  113. * @class: a valid #GObjectClass
  114. *
  115. * Return the name of a class structure's type.
  116. *
  117. * Returns: Type name of @class. The string is owned by the type system and
  118. * should not be freed.
  119. */
  120. #define G_OBJECT_CLASS_NAME(class) (g_type_name (G_OBJECT_CLASS_TYPE (class)))
  121. /**
  122. * G_VALUE_HOLDS_OBJECT:
  123. * @value: a valid #GValue structure
  124. *
  125. * Checks whether the given #GValue can hold values derived from type %G_TYPE_OBJECT.
  126. *
  127. * Returns: %TRUE on success.
  128. */
  129. #define G_VALUE_HOLDS_OBJECT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_OBJECT))
  130. /* --- type macros --- */
  131. /**
  132. * G_TYPE_INITIALLY_UNOWNED:
  133. *
  134. * The type for #GInitiallyUnowned.
  135. */
  136. #define G_TYPE_INITIALLY_UNOWNED (g_initially_unowned_get_type())
  137. /**
  138. * G_INITIALLY_UNOWNED:
  139. * @object: Object which is subject to casting.
  140. *
  141. * Casts a #GInitiallyUnowned or derived pointer into a (GInitiallyUnowned*)
  142. * pointer. Depending on the current debugging level, this function may invoke
  143. * certain runtime checks to identify invalid casts.
  144. */
  145. #define G_INITIALLY_UNOWNED(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnowned))
  146. /**
  147. * G_INITIALLY_UNOWNED_CLASS:
  148. * @class: a valid #GInitiallyUnownedClass
  149. *
  150. * Casts a derived #GInitiallyUnownedClass structure into a
  151. * #GInitiallyUnownedClass structure.
  152. */
  153. #define G_INITIALLY_UNOWNED_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnownedClass))
  154. /**
  155. * G_IS_INITIALLY_UNOWNED:
  156. * @object: Instance to check for being a %G_TYPE_INITIALLY_UNOWNED.
  157. *
  158. * Checks whether a valid #GTypeInstance pointer is of type %G_TYPE_INITIALLY_UNOWNED.
  159. */
  160. #define G_IS_INITIALLY_UNOWNED(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_INITIALLY_UNOWNED))
  161. /**
  162. * G_IS_INITIALLY_UNOWNED_CLASS:
  163. * @class: a #GInitiallyUnownedClass
  164. *
  165. * Checks whether @class "is a" valid #GInitiallyUnownedClass structure of type
  166. * %G_TYPE_INITIALLY_UNOWNED or derived.
  167. */
  168. #define G_IS_INITIALLY_UNOWNED_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_INITIALLY_UNOWNED))
  169. /**
  170. * G_INITIALLY_UNOWNED_GET_CLASS:
  171. * @object: a #GInitiallyUnowned instance.
  172. *
  173. * Get the class structure associated to a #GInitiallyUnowned instance.
  174. *
  175. * Returns: pointer to object class structure.
  176. */
  177. #define G_INITIALLY_UNOWNED_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnownedClass))
  178. /* GInitiallyUnowned ia a GObject with initially floating reference count */
  179. /* --- typedefs & structures --- */
  180. typedef struct _GObject GObject;
  181. typedef struct _GObjectClass GObjectClass;
  182. typedef struct _GObject GInitiallyUnowned;
  183. typedef struct _GObjectClass GInitiallyUnownedClass;
  184. typedef struct _GObjectConstructParam GObjectConstructParam;
  185. /**
  186. * GObjectGetPropertyFunc:
  187. * @object: a #GObject
  188. * @property_id: the numeric id under which the property was registered with
  189. * g_object_class_install_property().
  190. * @value: a #GValue to return the property value in
  191. * @pspec: the #GParamSpec describing the property
  192. *
  193. * The type of the @get_property function of #GObjectClass.
  194. */
  195. typedef void (*GObjectGetPropertyFunc) (GObject *object,
  196. guint property_id,
  197. GValue *value,
  198. GParamSpec *pspec);
  199. /**
  200. * GObjectSetPropertyFunc:
  201. * @object: a #GObject
  202. * @property_id: the numeric id under which the property was registered with
  203. * g_object_class_install_property().
  204. * @value: the new value for the property
  205. * @pspec: the #GParamSpec describing the property
  206. *
  207. * The type of the @set_property function of #GObjectClass.
  208. */
  209. typedef void (*GObjectSetPropertyFunc) (GObject *object,
  210. guint property_id,
  211. const GValue *value,
  212. GParamSpec *pspec);
  213. /**
  214. * GObjectFinalizeFunc:
  215. * @object: the #GObject being finalized
  216. *
  217. * The type of the @finalize function of #GObjectClass.
  218. */
  219. typedef void (*GObjectFinalizeFunc) (GObject *object);
  220. /**
  221. * GWeakNotify:
  222. * @data: data that was provided when the weak reference was established
  223. * @where_the_object_was: the object being finalized
  224. *
  225. * A #GWeakNotify function can be added to an object as a callback that gets
  226. * triggered when the object is finalized. Since the object is already being
  227. * finalized when the #GWeakNotify is called, there's not much you could do
  228. * with the object, apart from e.g. using its address as hash-index or the like.
  229. */
  230. typedef void (*GWeakNotify) (gpointer data,
  231. GObject *where_the_object_was);
  232. /**
  233. * GObject:
  234. *
  235. * All the fields in the GObject structure are private
  236. * to the #GObject implementation and should never be accessed directly.
  237. */
  238. struct _GObject
  239. {
  240. GTypeInstance g_type_instance;
  241. /*< private >*/
  242. volatile guint ref_count;
  243. GData *qdata;
  244. };
  245. /**
  246. * GObjectClass:
  247. * @g_type_class: the parent class
  248. * @constructor: the @constructor function is called by g_object_new () to
  249. * complete the object initialization after all the construction properties are
  250. * set. The first thing a @constructor implementation must do is chain up to the
  251. * @constructor of the parent class. Overriding @constructor should be rarely
  252. * needed, e.g. to handle construct properties, or to implement singletons.
  253. * @set_property: the generic setter for all properties of this type. Should be
  254. * overridden for every type with properties. If implementations of
  255. * @set_property don't emit property change notification explicitly, this will
  256. * be done implicitly by the type system. However, if the notify signal is
  257. * emitted explicitly, the type system will not emit it a second time.
  258. * @get_property: the generic getter for all properties of this type. Should be
  259. * overridden for every type with properties.
  260. * @dispose: the @dispose function is supposed to drop all references to other
  261. * objects, but keep the instance otherwise intact, so that client method
  262. * invocations still work. It may be run multiple times (due to reference
  263. * loops). Before returning, @dispose should chain up to the @dispose method
  264. * of the parent class.
  265. * @finalize: instance finalization function, should finish the finalization of
  266. * the instance begun in @dispose and chain up to the @finalize method of the
  267. * parent class.
  268. * @dispatch_properties_changed: emits property change notification for a bunch
  269. * of properties. Overriding @dispatch_properties_changed should be rarely
  270. * needed.
  271. * @notify: the class closure for the notify signal
  272. * @constructed: the @constructed function is called by g_object_new() as the
  273. * final step of the object creation process. At the point of the call, all
  274. * construction properties have been set on the object. The purpose of this
  275. * call is to allow for object initialisation steps that can only be performed
  276. * after construction properties have been set. @constructed implementors
  277. * should chain up to the @constructed call of their parent class to allow it
  278. * to complete its initialisation.
  279. *
  280. * The class structure for the GObject type.
  281. *
  282. * <example>
  283. * <title>Implementing singletons using a constructor</title>
  284. * <programlisting>
  285. * static MySingleton *the_singleton = NULL;
  286. *
  287. * static GObject*
  288. * my_singleton_constructor (GType type,
  289. * guint n_construct_params,
  290. * GObjectConstructParam *construct_params)
  291. * {
  292. * GObject *object;
  293. *
  294. * if (!the_singleton)
  295. * {
  296. * object = G_OBJECT_CLASS (parent_class)->constructor (type,
  297. * n_construct_params,
  298. * construct_params);
  299. * the_singleton = MY_SINGLETON (object);
  300. * }
  301. * else
  302. * object = g_object_ref (G_OBJECT (the_singleton));
  303. *
  304. * return object;
  305. * }
  306. * </programlisting></example>
  307. */
  308. struct _GObjectClass
  309. {
  310. GTypeClass g_type_class;
  311. /*< private >*/
  312. GSList *construct_properties;
  313. /*< public >*/
  314. /* seldom overidden */
  315. GObject* (*constructor) (GType type,
  316. guint n_construct_properties,
  317. GObjectConstructParam *construct_properties);
  318. /* overridable methods */
  319. void (*set_property) (GObject *object,
  320. guint property_id,
  321. const GValue *value,
  322. GParamSpec *pspec);
  323. void (*get_property) (GObject *object,
  324. guint property_id,
  325. GValue *value,
  326. GParamSpec *pspec);
  327. void (*dispose) (GObject *object);
  328. void (*finalize) (GObject *object);
  329. /* seldom overidden */
  330. void (*dispatch_properties_changed) (GObject *object,
  331. guint n_pspecs,
  332. GParamSpec **pspecs);
  333. /* signals */
  334. void (*notify) (GObject *object,
  335. GParamSpec *pspec);
  336. /* called when done constructing */
  337. void (*constructed) (GObject *object);
  338. /*< private >*/
  339. gsize flags;
  340. /* padding */
  341. gpointer pdummy[6];
  342. };
  343. /**
  344. * GObjectConstructParam:
  345. * @pspec: the #GParamSpec of the construct parameter
  346. * @value: the value to set the parameter to
  347. *
  348. * The GObjectConstructParam struct is an auxiliary
  349. * structure used to hand #GParamSpec/#GValue pairs to the @constructor of
  350. * a #GObjectClass.
  351. */
  352. struct _GObjectConstructParam
  353. {
  354. GParamSpec *pspec;
  355. GValue *value;
  356. };
  357. /**
  358. * GInitiallyUnowned:
  359. *
  360. * All the fields in the GInitiallyUnowned structure
  361. * are private to the #GInitiallyUnowned implementation and should never be
  362. * accessed directly.
  363. */
  364. /**
  365. * GInitiallyUnownedClass:
  366. *
  367. * The class structure for the GInitiallyUnowned type.
  368. */
  369. /* --- prototypes --- */
  370. GLIB_AVAILABLE_IN_ALL
  371. GType g_initially_unowned_get_type (void);
  372. GLIB_AVAILABLE_IN_ALL
  373. void g_object_class_install_property (GObjectClass *oclass,
  374. guint property_id,
  375. GParamSpec *pspec);
  376. GLIB_AVAILABLE_IN_ALL
  377. GParamSpec* g_object_class_find_property (GObjectClass *oclass,
  378. const gchar *property_name);
  379. GLIB_AVAILABLE_IN_ALL
  380. GParamSpec**g_object_class_list_properties (GObjectClass *oclass,
  381. guint *n_properties);
  382. GLIB_AVAILABLE_IN_ALL
  383. void g_object_class_override_property (GObjectClass *oclass,
  384. guint property_id,
  385. const gchar *name);
  386. GLIB_AVAILABLE_IN_ALL
  387. void g_object_class_install_properties (GObjectClass *oclass,
  388. guint n_pspecs,
  389. GParamSpec **pspecs);
  390. GLIB_AVAILABLE_IN_ALL
  391. void g_object_interface_install_property (gpointer g_iface,
  392. GParamSpec *pspec);
  393. GLIB_AVAILABLE_IN_ALL
  394. GParamSpec* g_object_interface_find_property (gpointer g_iface,
  395. const gchar *property_name);
  396. GLIB_AVAILABLE_IN_ALL
  397. GParamSpec**g_object_interface_list_properties (gpointer g_iface,
  398. guint *n_properties_p);
  399. GLIB_AVAILABLE_IN_ALL
  400. GType g_object_get_type (void) G_GNUC_CONST;
  401. GLIB_AVAILABLE_IN_ALL
  402. gpointer g_object_new (GType object_type,
  403. const gchar *first_property_name,
  404. ...);
  405. GLIB_AVAILABLE_IN_ALL
  406. gpointer g_object_newv (GType object_type,
  407. guint n_parameters,
  408. GParameter *parameters);
  409. GLIB_AVAILABLE_IN_ALL
  410. GObject* g_object_new_valist (GType object_type,
  411. const gchar *first_property_name,
  412. va_list var_args);
  413. GLIB_AVAILABLE_IN_ALL
  414. void g_object_set (gpointer object,
  415. const gchar *first_property_name,
  416. ...) G_GNUC_NULL_TERMINATED;
  417. GLIB_AVAILABLE_IN_ALL
  418. void g_object_get (gpointer object,
  419. const gchar *first_property_name,
  420. ...) G_GNUC_NULL_TERMINATED;
  421. GLIB_AVAILABLE_IN_ALL
  422. gpointer g_object_connect (gpointer object,
  423. const gchar *signal_spec,
  424. ...) G_GNUC_NULL_TERMINATED;
  425. GLIB_AVAILABLE_IN_ALL
  426. void g_object_disconnect (gpointer object,
  427. const gchar *signal_spec,
  428. ...) G_GNUC_NULL_TERMINATED;
  429. GLIB_AVAILABLE_IN_ALL
  430. void g_object_set_valist (GObject *object,
  431. const gchar *first_property_name,
  432. va_list var_args);
  433. GLIB_AVAILABLE_IN_ALL
  434. void g_object_get_valist (GObject *object,
  435. const gchar *first_property_name,
  436. va_list var_args);
  437. GLIB_AVAILABLE_IN_ALL
  438. void g_object_set_property (GObject *object,
  439. const gchar *property_name,
  440. const GValue *value);
  441. GLIB_AVAILABLE_IN_ALL
  442. void g_object_get_property (GObject *object,
  443. const gchar *property_name,
  444. GValue *value);
  445. GLIB_AVAILABLE_IN_ALL
  446. void g_object_freeze_notify (GObject *object);
  447. GLIB_AVAILABLE_IN_ALL
  448. void g_object_notify (GObject *object,
  449. const gchar *property_name);
  450. GLIB_AVAILABLE_IN_ALL
  451. void g_object_notify_by_pspec (GObject *object,
  452. GParamSpec *pspec);
  453. GLIB_AVAILABLE_IN_ALL
  454. void g_object_thaw_notify (GObject *object);
  455. GLIB_AVAILABLE_IN_ALL
  456. gboolean g_object_is_floating (gpointer object);
  457. GLIB_AVAILABLE_IN_ALL
  458. gpointer g_object_ref_sink (gpointer object);
  459. GLIB_AVAILABLE_IN_ALL
  460. gpointer g_object_ref (gpointer object);
  461. GLIB_AVAILABLE_IN_ALL
  462. void g_object_unref (gpointer object);
  463. GLIB_AVAILABLE_IN_ALL
  464. void g_object_weak_ref (GObject *object,
  465. GWeakNotify notify,
  466. gpointer data);
  467. GLIB_AVAILABLE_IN_ALL
  468. void g_object_weak_unref (GObject *object,
  469. GWeakNotify notify,
  470. gpointer data);
  471. GLIB_AVAILABLE_IN_ALL
  472. void g_object_add_weak_pointer (GObject *object,
  473. gpointer *weak_pointer_location);
  474. GLIB_AVAILABLE_IN_ALL
  475. void g_object_remove_weak_pointer (GObject *object,
  476. gpointer *weak_pointer_location);
  477. /**
  478. * GToggleNotify:
  479. * @data: Callback data passed to g_object_add_toggle_ref()
  480. * @object: The object on which g_object_add_toggle_ref() was called.
  481. * @is_last_ref: %TRUE if the toggle reference is now the
  482. * last reference to the object. %FALSE if the toggle
  483. * reference was the last reference and there are now other
  484. * references.
  485. *
  486. * A callback function used for notification when the state
  487. * of a toggle reference changes. See g_object_add_toggle_ref().
  488. */
  489. typedef void (*GToggleNotify) (gpointer data,
  490. GObject *object,
  491. gboolean is_last_ref);
  492. GLIB_AVAILABLE_IN_ALL
  493. void g_object_add_toggle_ref (GObject *object,
  494. GToggleNotify notify,
  495. gpointer data);
  496. GLIB_AVAILABLE_IN_ALL
  497. void g_object_remove_toggle_ref (GObject *object,
  498. GToggleNotify notify,
  499. gpointer data);
  500. GLIB_AVAILABLE_IN_ALL
  501. gpointer g_object_get_qdata (GObject *object,
  502. GQuark quark);
  503. GLIB_AVAILABLE_IN_ALL
  504. void g_object_set_qdata (GObject *object,
  505. GQuark quark,
  506. gpointer data);
  507. GLIB_AVAILABLE_IN_ALL
  508. void g_object_set_qdata_full (GObject *object,
  509. GQuark quark,
  510. gpointer data,
  511. GDestroyNotify destroy);
  512. GLIB_AVAILABLE_IN_ALL
  513. gpointer g_object_steal_qdata (GObject *object,
  514. GQuark quark);
  515. GLIB_AVAILABLE_IN_2_34
  516. gpointer g_object_dup_qdata (GObject *object,
  517. GQuark quark,
  518. GDuplicateFunc dup_func,
  519. gpointer user_data);
  520. GLIB_AVAILABLE_IN_2_34
  521. gboolean g_object_replace_qdata (GObject *object,
  522. GQuark quark,
  523. gpointer oldval,
  524. gpointer newval,
  525. GDestroyNotify destroy,
  526. GDestroyNotify *old_destroy);
  527. GLIB_AVAILABLE_IN_ALL
  528. gpointer g_object_get_data (GObject *object,
  529. const gchar *key);
  530. GLIB_AVAILABLE_IN_ALL
  531. void g_object_set_data (GObject *object,
  532. const gchar *key,
  533. gpointer data);
  534. GLIB_AVAILABLE_IN_ALL
  535. void g_object_set_data_full (GObject *object,
  536. const gchar *key,
  537. gpointer data,
  538. GDestroyNotify destroy);
  539. GLIB_AVAILABLE_IN_ALL
  540. gpointer g_object_steal_data (GObject *object,
  541. const gchar *key);
  542. GLIB_AVAILABLE_IN_2_34
  543. gpointer g_object_dup_data (GObject *object,
  544. const gchar *key,
  545. GDuplicateFunc dup_func,
  546. gpointer user_data);
  547. GLIB_AVAILABLE_IN_2_34
  548. gboolean g_object_replace_data (GObject *object,
  549. const gchar *key,
  550. gpointer oldval,
  551. gpointer newval,
  552. GDestroyNotify destroy,
  553. GDestroyNotify *old_destroy);
  554. GLIB_AVAILABLE_IN_ALL
  555. void g_object_watch_closure (GObject *object,
  556. GClosure *closure);
  557. GLIB_AVAILABLE_IN_ALL
  558. GClosure* g_cclosure_new_object (GCallback callback_func,
  559. GObject *object);
  560. GLIB_AVAILABLE_IN_ALL
  561. GClosure* g_cclosure_new_object_swap (GCallback callback_func,
  562. GObject *object);
  563. GLIB_AVAILABLE_IN_ALL
  564. GClosure* g_closure_new_object (guint sizeof_closure,
  565. GObject *object);
  566. GLIB_AVAILABLE_IN_ALL
  567. void g_value_set_object (GValue *value,
  568. gpointer v_object);
  569. GLIB_AVAILABLE_IN_ALL
  570. gpointer g_value_get_object (const GValue *value);
  571. GLIB_AVAILABLE_IN_ALL
  572. gpointer g_value_dup_object (const GValue *value);
  573. GLIB_AVAILABLE_IN_ALL
  574. gulong g_signal_connect_object (gpointer instance,
  575. const gchar *detailed_signal,
  576. GCallback c_handler,
  577. gpointer gobject,
  578. GConnectFlags connect_flags);
  579. /*< protected >*/
  580. GLIB_AVAILABLE_IN_ALL
  581. void g_object_force_floating (GObject *object);
  582. GLIB_AVAILABLE_IN_ALL
  583. void g_object_run_dispose (GObject *object);
  584. GLIB_AVAILABLE_IN_ALL
  585. void g_value_take_object (GValue *value,
  586. gpointer v_object);
  587. GLIB_DEPRECATED_FOR(g_value_take_object)
  588. void g_value_set_object_take_ownership (GValue *value,
  589. gpointer v_object);
  590. GLIB_DEPRECATED
  591. gsize g_object_compat_control (gsize what,
  592. gpointer data);
  593. /* --- implementation macros --- */
  594. #define G_OBJECT_WARN_INVALID_PSPEC(object, pname, property_id, pspec) \
  595. G_STMT_START { \
  596. GObject *_glib__object = (GObject*) (object); \
  597. GParamSpec *_glib__pspec = (GParamSpec*) (pspec); \
  598. guint _glib__property_id = (property_id); \
  599. g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'", \
  600. __FILE__, __LINE__, \
  601. (pname), \
  602. _glib__property_id, \
  603. _glib__pspec->name, \
  604. g_type_name (G_PARAM_SPEC_TYPE (_glib__pspec)), \
  605. G_OBJECT_TYPE_NAME (_glib__object)); \
  606. } G_STMT_END
  607. /**
  608. * G_OBJECT_WARN_INVALID_PROPERTY_ID:
  609. * @object: the #GObject on which set_property() or get_property() was called
  610. * @property_id: the numeric id of the property
  611. * @pspec: the #GParamSpec of the property
  612. *
  613. * This macro should be used to emit a standard warning about unexpected
  614. * properties in set_property() and get_property() implementations.
  615. */
  616. #define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \
  617. G_OBJECT_WARN_INVALID_PSPEC ((object), "property", (property_id), (pspec))
  618. GLIB_AVAILABLE_IN_ALL
  619. void g_clear_object (volatile GObject **object_ptr);
  620. #define g_clear_object(object_ptr) g_clear_pointer ((object_ptr), g_object_unref)
  621. /**
  622. * g_set_object: (skip)
  623. * @object_ptr: a pointer to a #GObject reference
  624. * @new_object: (nullable) (transfer none): a pointer to the new #GObject to
  625. * assign to it, or %NULL to clear the pointer
  626. *
  627. * Updates a #GObject pointer to refer to @new_object. It increments the
  628. * reference count of @new_object (if non-%NULL), decrements the reference
  629. * count of the current value of @object_ptr (if non-%NULL), and assigns
  630. * @new_object to @object_ptr. The assignment is not atomic.
  631. *
  632. * @object_ptr must not be %NULL.
  633. *
  634. * A macro is also included that allows this function to be used without
  635. * pointer casts. The function itself is static inline, so its address may vary
  636. * between compilation units.
  637. *
  638. * One convenient usage of this function is in implementing property setters:
  639. * |[
  640. * void
  641. * foo_set_bar (Foo *foo,
  642. * Bar *new_bar)
  643. * {
  644. * g_return_if_fail (IS_FOO (foo));
  645. * g_return_if_fail (new_bar == NULL || IS_BAR (new_bar));
  646. *
  647. * if (g_set_object (&foo->bar, new_bar))
  648. * g_object_notify (foo, "bar");
  649. * }
  650. * ]|
  651. *
  652. * Returns: %TRUE if the value of @object_ptr changed, %FALSE otherwise
  653. *
  654. * Since: 2.44
  655. */
  656. static inline gboolean
  657. (g_set_object) (GObject **object_ptr,
  658. GObject *new_object)
  659. {
  660. GObject *old_object = *object_ptr;
  661. /* rely on g_object_[un]ref() to check the pointers are actually GObjects;
  662. * elide a (object_ptr != NULL) check because most of the time we will be
  663. * operating on struct members with a constant offset, so a NULL check would
  664. * not catch bugs
  665. */
  666. if (old_object == new_object)
  667. return FALSE;
  668. if (new_object != NULL)
  669. g_object_ref (new_object);
  670. *object_ptr = new_object;
  671. if (old_object != NULL)
  672. g_object_unref (old_object);
  673. return TRUE;
  674. }
  675. #define g_set_object(object_ptr, new_object) \
  676. (/* Check types match. */ \
  677. 0 ? *(object_ptr) = (new_object), FALSE : \
  678. (g_set_object) ((GObject **) (object_ptr), (GObject *) (new_object)) \
  679. )
  680. typedef struct {
  681. /*<private>*/
  682. union { gpointer p; } priv;
  683. } GWeakRef;
  684. GLIB_AVAILABLE_IN_ALL
  685. void g_weak_ref_init (GWeakRef *weak_ref,
  686. gpointer object);
  687. GLIB_AVAILABLE_IN_ALL
  688. void g_weak_ref_clear (GWeakRef *weak_ref);
  689. GLIB_AVAILABLE_IN_ALL
  690. gpointer g_weak_ref_get (GWeakRef *weak_ref);
  691. GLIB_AVAILABLE_IN_ALL
  692. void g_weak_ref_set (GWeakRef *weak_ref,
  693. gpointer object);
  694. G_END_DECLS
  695. #endif /* __G_OBJECT_H__ */