GInterface and function, which returns pointer do data



Hi!

I'm trying to implement an interface in my code. I don't know how to
implement function which returns pointer to data. here's small part of code:

#define GOOFY_TYPE_FILE            (goofy_file_get_type ())
#define GOOFY_FILE(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),
GOOFY_TYPE_FILE, GoofyFile)
#define GOOFY_IS_FILE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GOOFY_TYPE_FILE))
#define GOOFY_FILE_GET_IFACE(obj)  (G_TYPE_INSTANCE_GET_INTERFACE ((obj),
GOOFY_TYPE_FILE, GoofyFileIface))

typedef struct _GoofyFile GoofyFile;
typedef struct _GoofyFileIface GoofyFileIface;

struct _GoofyFileIface {
   GTypeInterface parent_iface;

   gchar   (*get_file_name)    (GoofyFile  *file);  /*  <<< Shouldn't it
be:      gchar   (**get_file_name)    (GoofyFile  *file);     */
};

GType   goofy_file_get_type     (void);

gchar   *goofy_file_get_name    (GoofyFile  *file);

And now source:

GType   goofy_file_get_type ()
{
   static GType object_type = 0;

   if (!object_type) {
       static const GTypeInfo object_info = {
           sizeof(GoofyFileIface),
           NULL,    /* base init */
           NULL,    /* base finalize */
       };
       object_type =
           g_type_register_static(G_TYPE_INTERFACE,
                      "GoofyFile",
                      &object_info, 0);
   }
   return object_type;
}

gchar   *goofy_file_get_name    (GoofyFile  *file)  {
   return GOOFY_FILE_GET_IFACE (file)->get_file_name (file);  /* Hot to
properly write this line?!  */
}

If you have any idea, please let me know! ;)

--
Cya!
Tom



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