Commit 258fb3d6 authored by Mieszko Mazurek's avatar Mieszko Mazurek

an issue example

parents
foo.gir
foo.vapi
libfoo.so
tags
#include "foo-bar.h"
struct _FooBar
{
GObject parent_instance;
gint number;
};
G_DEFINE_TYPE (FooBar, foo_bar, G_TYPE_OBJECT);
enum
{
_UNUSED,
PROP_NUMBER,
N_PROPS,
};
static GParamSpec *props[N_PROPS];
static void
set_property (GObject *gobj,
guint prop_id,
const GValue *value,
GParamSpec *spec)
{
FooBar *self;
self = FOO_BAR (gobj);
switch (prop_id)
{
case PROP_NUMBER:
foo_bar_set_number (self, g_value_get_int (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobj, prop_id, spec);
}
}
static void
get_property (GObject *gobj,
guint prop_id,
GValue *value,
GParamSpec *spec)
{
FooBar *self;
self = FOO_BAR (gobj);
switch (prop_id)
{
case PROP_NUMBER:
g_value_set_int (value, self->number);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobj, prop_id, spec);
}
}
static void
foo_bar_init (FooBar *self)
{
}
static void
foo_bar_class_init (FooBarClass *cls)
{
GObjectClass *gcls;
gcls = G_OBJECT_CLASS (cls);
gcls->set_property = set_property;
gcls->get_property = get_property;
props[PROP_NUMBER] =
g_param_spec_int ("number",
"number",
"An example property",
G_MININT32, G_MAXINT32, 42,
G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
g_object_class_install_properties (gcls, N_PROPS, props);
}
void
foo_bar_set_number (FooBar *self,
gint value)
{
if (value != self->number)
{
self->number = value;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_NUMBER]);
}
}
gint
foo_bar_get_number (FooBar *self)
{
return self->number;
}
#pragma once
#include <glib-object.h>
G_BEGIN_DECLS
#define FOO_TYPE_BAR (foo_bar_get_type ())
G_DECLARE_FINAL_TYPE (FooBar, foo_bar, FOO, BAR, GObject);
/**
* foo_bar_new
*
* returns: (transfer full)
*/
FooBar *foo_bar_new ();
void foo_bar_set_number (FooBar *self,
gint value);
gint foo_bar_get_number (FooBar *self);
G_END_DECLS
all: foo.vapi
clean:
rm -f libfoo.so foo.gir foo.vapi
ARGS=`pkg-config --libs --cflags gobject-2.0`
libfoo.so: foo-bar.c foo-bar.h
gcc ${ARGS} -fPIC -shared $< -o $@
foo.gir: libfoo.so
g-ir-scanner foo-bar.h foo-bar.c --namespace=Foo --library=foo ${ARGS} -L. --output foo.gir
foo.vapi: foo.gir
vapigen --library=foo foo.gir
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment