Constructor Properties in GObject

I have a GObject question that I hope someone can help me with.  I
imagine this has been asked before, but a quick search of the
mailing-list archives didn't turn up any answers.

Regarding a GObject's constructor properties, is there a mechanism in
GObject or a generally accepted idiom for *requiring* certain properties
to be supplied at object construction?

I'm aware of the G_PARAM_CONSTRUCT and G_PARAM_CONSTRUCT_ONLY flags, but
as far as I can tell these flags only indicate that a property *may* be
passed to a constructor.  They don't guarantee that the property *will*
be present when the constructor() method is called.

At the moment I'm working around this by overriding the constructor()
method, chaining up, and then checking that certain private fields
corresponding to the required constructor properties have been set
correctly.  (In my case the properties are other GObjects, so I check
for NULL pointers.)  If I detect a missing constructor property, I use
g_error() to produce a fatal error message.  I'd prefer that this error
be recoverable, such that g_object_new() returns NULL to the caller, but
I don't know how to properly abort the GObject construction phase.

It would be ideal if GObject did these checks for me, so that all I'd
have to do is specify which "G_PARAM_CONSTRUCT" properties I want to be

Any advice?

Matthew Barnes
matthew barnes net

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]