Correct connection sequence to maximize chances of e.g.: getting connected :)

Enrico Mioso mrkiko.rs at gmail.com
Thu May 7 13:59:44 UTC 2020


Ok, now things are a little bit clearer. However, when running my test code I face the issue:
Creating object:

(process:45799): GLib-GObject-WARNING **: 15:52:57.565: specified instance size for type 'AvModem' is smaller than the parent type's 'GObject' instance size

(process:45799): GLib-CRITICAL **: 15:52:57.565: g_once_init_leave: assertion 'result != 0' failed

(process:45799): GLib-GObject-CRITICAL **: 15:52:57.565: g_object_new_with_properties: assertion 'G_TYPE_IS_OBJECT (object_type)' failed

(process:45799): GLib-GObject-CRITICAL **: 15:52:57.565: g_object_unref: assertion 'G_IS_OBJECT (object)' failed

I guess I am missing some details about declaring MMObjectclass is my parent class.
I can't understand them from the GObjects doc, even tough they seem pretty well written, once you grasp the context.

With final type I was able to drop some code. Now my objecct skel looks as follows:

/* header */
#ifndef __main_h__
#define __main_h__

#include <glib-object.h>
#include <libmm-glib.h>

G_BEGIN_DECLS
#define AV_TYPE_MODEM av_modem_get_type()
G_DECLARE_FINAL_TYPE(AvModem, av_modem, AV, MODEM, GObject)

AvModem *av_modem_new(void);

G_END_DECLS

#endif

/* source */

#include <glib.h>
#include <main.h>
#include <libmm-glib.h>

struct _AvModem {
 	MMObject *mmobject;
 	/* other members */
};

G_DEFINE_TYPE(AvModem, av_modem, G_TYPE_OBJECT)

static void av_modem_init(AvModem *self) {
 	g_print("%s invoked\n",__FUNCTION__);
 	/* here we would g_object_new and things */
 	/* initialize all public and private members to reasonable default values.
 	 * They are all automatically initialized to 0 to begin with. */
}

static void av_modem_dispose(GObject *gobject) {
 	g_print("%s invoked\n",__FUNCTION__);
 	/* In dispose(), you are supposed to free all types referenced from this
 	 * object which might themselves hold a reference to self. Generally,
 	 * the most simple solution is to unref all members on which you own a
 	 * reference.
 	 */

 	/* time to g_object_clear things */
 	G_OBJECT_CLASS (av_modem_parent_class)->dispose (gobject);
}

static void av_modem_finalize(GObject *gobject) {
 	g_print("%s invoked\n",__FUNCTION__);
 	/* e.g.: g_free for filename */
 	G_OBJECT_CLASS (av_modem_parent_class)->finalize (gobject);
}

static void av_modem_class_init(AvModemClass *klass) {
 	g_print("%s invoked\n",__FUNCTION__);
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 	object_class->dispose = av_modem_dispose;
 	object_class->finalize = av_modem_finalize;
}

AvModem *av_modem_new(void) {
 	AvModem *m;
 	m = g_object_new(AV_TYPE_MODEM, NULL);
 	return m;
}

gint main(void) {
 	AvModem *m;
 	g_print("Creating object:\n");
 	m = av_modem_new();
 	g_object_unref(m);
 	return 0;
}

It works if I use
MMObject m;
instead of *m as my _AvModem struct member, which is not the right solution I know...
Second, the final objective is to have

AvModem *av_modem_new(MMObject *m);

And I guess inside the function I can use a simple assignment due to the fact the compiler still knows the structure in the C file.


More information about the ModemManager-devel mailing list