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

Aleksander Morgado aleksander at aleksander.es
Thu May 7 15:49:47 UTC 2020


On Thu, May 7, 2020 at 4:23 PM Enrico Mioso <mrkiko.rs at gmail.com> wrote:
>
> Oh, sorry. It makes sense due to the way C structs work, so i may use
> struct _AvModem {

You still need to define the parent GObject here.


>    MMObject mmobject;
>    /* other members */
> };
>
> Still, if all is OK I should be able to do something like:
> mm_object_get_modem(MM_OBJECT(m));
>
> or am I mistaken?
> currently, this fails...
>
> thanks again,
> Enrico
>
>
> On Thu, 7 May 2020, Enrico Mioso wrote:
>
> > Date: Thu, 7 May 2020 15:59:44
> > From: Enrico Mioso <mrkiko.rs at gmail.com>
> > To: Aleksander Morgado <aleksander at aleksander.es>
> > Cc: "ModemManager (development)" <modemmanager-devel at lists.freedesktop.org>,
> >     marco.perini1993 at gmail.com
> > Subject: Re: Correct connection sequence to maximize chances of e.g.: getting
> >     connected :)
> >
> > 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.
> >



-- 
Aleksander
https://aleksander.es


More information about the ModemManager-devel mailing list