parent
03c685b9e4
commit
0c853a7038
4 changed files with 157 additions and 0 deletions
@ -0,0 +1,94 @@ |
||||
#include <stdio.h> |
||||
#include "golib.h" |
||||
|
||||
G_DEFINE_TYPE (MesonSample, meson_sample, G_TYPE_OBJECT) |
||||
|
||||
#define MESON_SAMPLE_GET_PRIVATE(o) \ |
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((o), MESON_SAMPLE_TYPE, MesonSamplePrivate)) |
||||
|
||||
struct _MesonSamplePrivate { |
||||
gchar *msg; |
||||
}; |
||||
|
||||
enum { |
||||
PROP_0, |
||||
PROP_MSG, |
||||
N_PROPERTIES |
||||
}; |
||||
|
||||
static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, }; |
||||
|
||||
static void meson_sample_init (MesonSample *object) |
||||
{ |
||||
MesonSamplePrivate *priv = MESON_SAMPLE_GET_PRIVATE (object); |
||||
priv->msg = NULL; |
||||
} |
||||
static void meson_sample_finalize (GObject *object) |
||||
{ |
||||
MesonSamplePrivate *priv = MESON_SAMPLE_GET_PRIVATE (object); |
||||
g_free (priv->msg); |
||||
G_OBJECT_CLASS (meson_sample_parent_class)->finalize (object); |
||||
} |
||||
|
||||
static void meson_sample_set_property (GObject *object, |
||||
guint property_id, |
||||
const GValue *value, |
||||
GParamSpec *pspec) { |
||||
MesonSamplePrivate *priv = MESON_SAMPLE_GET_PRIVATE (object); |
||||
switch (property_id) { |
||||
case PROP_MSG: |
||||
g_free (priv->msg); |
||||
priv->msg = g_value_dup_string (value); |
||||
break; |
||||
default: |
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
static void meson_sample_get_property (GObject *object, |
||||
guint property_id, |
||||
GValue *value, |
||||
GParamSpec *pspec) { |
||||
MesonSamplePrivate *priv = MESON_SAMPLE_GET_PRIVATE (object); |
||||
switch (property_id) { |
||||
case PROP_MSG: |
||||
g_value_set_string (value, priv->msg); |
||||
break; |
||||
default: |
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
static void meson_sample_class_init (MesonSampleClass *klass) { |
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
||||
object_class->set_property = meson_sample_set_property; |
||||
object_class->get_property = meson_sample_get_property; |
||||
object_class->finalize = meson_sample_finalize; |
||||
|
||||
obj_properties[PROP_MSG] = |
||||
g_param_spec_string ("msg", |
||||
"Msg", |
||||
"The message to print.", |
||||
"propertytext", |
||||
G_PARAM_READWRITE | |
||||
G_PARAM_CONSTRUCT); |
||||
g_object_class_install_properties (object_class, |
||||
N_PROPERTIES, |
||||
obj_properties); |
||||
g_type_class_add_private (object_class, sizeof (MesonSamplePrivate)); |
||||
} |
||||
|
||||
MesonSample* meson_sample_new () { |
||||
MesonSample *sample; |
||||
sample = g_object_new(MESON_SAMPLE_TYPE, NULL); |
||||
return sample; |
||||
} |
||||
|
||||
void meson_sample_func (MesonSample *sample) { |
||||
MesonSamplePrivate *priv; |
||||
g_return_if_fail (sample != NULL); |
||||
priv = MESON_SAMPLE_GET_PRIVATE(sample); |
||||
printf("GObject introspection is working, %s!\n", priv->msg); |
||||
} |
@ -0,0 +1,37 @@ |
||||
#ifndef GOLIB_H |
||||
#define GOLIB_H |
||||
|
||||
#include <glib.h> |
||||
#include <glib-object.h> |
||||
|
||||
#define MESON_SAMPLE_TYPE \ |
||||
(meson_sample_get_type()) |
||||
#define MESON_SAMPLE(o) \ |
||||
(G_TYPE_CHECK_INSTANCE_CAST ((o), MESON_SAMPLE_TYPE, MesonSample)) |
||||
#define MESON_SAMPLE_CLASS(c) \ |
||||
(G_TYPE_CHECK_CLASS_CAST ((c), MESON_SAMPLE_TYPE, MesonSampleClass)) |
||||
#define MESON_IS_SAMPLE(o) \ |
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((o), MESON_SAMPLE_TYPE)) |
||||
#define MESON_IS_SAMPLE_CLASS(c) \ |
||||
(G_TYPE_CHECK_CLASS_TYPE ((c), MESON_SAMPLE_TYPE)) |
||||
#define MESON_SAMPLE_GET_CLASS(o) \ |
||||
(G_TYPE_INSTANCE_GET_CLASS ((o), MESON_SAMPLE_TYPE, MesonSampleClass)) |
||||
|
||||
typedef struct _MesonSample MesonSample; |
||||
typedef struct _MesonSamplePrivate MesonSamplePrivate; |
||||
typedef struct _MesonSampleClass MesonSampleClass; |
||||
|
||||
struct _MesonSample { |
||||
GObject parent; |
||||
}; |
||||
|
||||
struct _MesonSampleClass { |
||||
GObjectClass parent; |
||||
}; |
||||
|
||||
GType meson_sample_get_type () G_GNUC_CONST; |
||||
MesonSample* meson_sample_new (void); |
||||
|
||||
void meson_sample_func (MesonSample *sample); |
||||
|
||||
#endif |
@ -0,0 +1,11 @@ |
||||
project('gobject-introspection', 'c') |
||||
|
||||
glib = dependency('glib-2.0') |
||||
gobj = dependency('gobject-2.0') |
||||
|
||||
libsources = ['golib.c', 'golib.h'] |
||||
|
||||
exe = executable('goprog', libsources, 'prog.c', |
||||
deps : [glib, gobj]) |
||||
|
||||
test('gobjtest', exe) |
@ -0,0 +1,15 @@ |
||||
#include<glib.h> |
||||
#include<glib-object.h> |
||||
#include"golib.h" |
||||
|
||||
int main (int argc, char *argv[]) |
||||
{ |
||||
MesonSample *i; |
||||
|
||||
i = meson_sample_new(); |
||||
meson_sample_func(i); |
||||
g_object_unref(G_OBJECT(i)); |
||||
|
||||
return 0; |
||||
} |
||||
|
Loading…
Reference in new issue