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

Enrico Mioso mrkiko.rs at gmail.com
Wed May 6 15:26:57 UTC 2020


Hello Aleksander, helo all!!

So my journey continues. :)
Sorry for deleting the quoted text every time, but without doing so, answers may result complicated to read confortably for me.

So, in the end I came to the conclusion that using GObjects is probably the best course of cation :)

So I am studying the GLib GObjects page for details, and started writing some code to try to understand things better.

Goal: implement a GObject who can act as a container for:
- MMObjects, MMModem objects, MMModemVoice objects
- (long) integers for GSignals handlers and other data.
I managed to get my code to compile, but would like some hints / recommendations on how I may proceed.

My 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_DERIVABLE_TYPE(AvModem, av_modem, AV, MODEM, GObject)

struct _AvModemClass {
 	MMObjectClass parent_class;

 	/* functions ... */
 	/* padding with things like
 	gpointer padding[12];
 	*/
};

AvModem *av_modem_new(void);

G_END_DECLS

#endif


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

typedef struct {
 	gchar *filename;
} AvModemPrivate;

G_DEFINE_TYPE_WITH_PRIVATE (AvModem, av_modem, G_TYPE_OBJECT)

static void av_modem_init(AvModem *self) {
 	g_print("__FUNCTION__ invoked\n");
 	AvModemPrivate *priv = av_modem_get_instance_private(self);

 	/* 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("__FUNCTION__ invoked\n");
 	AvModemPrivate *priv = av_modem_get_instance_private(AV_MODEM(gobject));

 	/* 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("__FUNCTION__ invoked\n");
 	AvModemPrivate *priv = av_modem_get_instance_private(AV_MODEM(gobject));

 	/* 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("__FUNCTION__ invoked\n");
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 	object_class->dispose = av_modem_dispose;
 	object_class->finalize = av_modem_finalize;
}



gint main(void) {
 	return 0;
}

I see you use various convenience macros in libmm-glib headers, but I am trying to do things step by step to understand them.
I may have used GBoxed to wrap my own structs instead, but I am trying to do what's better.
I absoulutely need refcounting in this scenario. :)

Thanks again!!!!

Enrico


More information about the ModemManager-devel mailing list