Re: Questions about tailoring libdmapsharing API to benefit GObject introspection
- From: Emmanuele Bassi <ebassi gmail com>
- To: "W. Michael Petullo" <mike flyn org>
- Cc: Philip Withnall <philip tecnocode co uk>, gir-devel-list gnome org
- Subject: Re: Questions about tailoring libdmapsharing API to benefit GObject introspection
- Date: Mon, 13 Nov 2017 15:59:52 +0000
Hi;
On 12 November 2017 at 23:06, W. Michael Petullo <mike flyn org> wrote:
I am the maintainer of libdmapsharing, a GObject-based library. I am
just now getting around to adjusting the library's API to better suit
GObject introspection. I am not sure how to process on two things
having
to do with object properties.
One of my interfaces, the DAAPRecord, has among its properties two
items: hash, a GLib2 ByteArray/g_param_spec_pointer and mediakind, a
g_param_spec_enum. I am trying to implement an object of this
interface in
Python, but I am not sure how to proceed with either of these
properties.
(As I mentioned, I am willing to modify the libdmapsharing interface
to
facilitate this if necessary.)
I am not sure how to best handle hash. Should I create a box type? It
seems like the should be a straightforward approach to handle a
ByteArray.
Can you provide a link to the code in question, and a copy of the
relevant bit of the generated GIR file?
My first guess would be that you are right, and it should be a boxed
type. See the GTlsCertificate:certificate property for an example.
https://git.gnome.org/browse/glib/tree/gio/gtlscertificate.c#n106
For mediakind, I get a warning if I try this:
class PyDAAPRecord((GObject.GObject, DAAP.Record, DMAP.Record):
# ...
mediakind = GObject.property(type=GObject.TYPE_INT, default=0)
That looks like more of a Python thing, which I can’t help with, sorry.
The code is available with:
git clone git://git.gnome.org/libdmapsharing
<property name="hash" writable="1" transfer-ownership="none">
<type name="gpointer" c:type="gpointer"/>
</property>
This is your problem:
https://git.gnome.org/browse/libdmapsharing/tree/libdmapsharing/dpap-record.c#n38
Use g_param_spec_boxed() with G_TYPE_HASH_TABLE.
You'll also need to annotate the property[0] with a gtk-doc stanza and
make the type of keys and values explicit:
https://wiki.gnome.org/Projects/GObjectIntrospection/Annotations#GObject-Introspection_annotations
Look for `element-type` in the context of hash tables.
"Pointers" do not make any sense for language bindings, because
there's no way for them to marshal a pointer to language native data
types.
Ciao,
Emmanuele.
[0] Actually, for good code hygiene, you should document all your
properties. Relying on GParamSpec fields is just not good enough.
--
https://www.bassi.io
[@] ebassi [@gmail.com]
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]