From 3cad531cca70e05ea4df01d155e588899b734e6f Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Sun, 2 May 2010 12:32:07 +0200 Subject: [PATCH] add azimuth.[ch] --- src/Makefile.am | 2 ++ src/azimuth.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/azimuth.h | 61 ++++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 src/azimuth.c create mode 100644 src/azimuth.h diff --git a/src/Makefile.am b/src/Makefile.am index f00246d..41bf042 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,6 +24,8 @@ bin_PROGRAMS = \ azimuth azimuth_SOURCES = \ + azimuth.c \ + azimuth.h \ main.c \ connection-watcher.c \ position-publisher.c diff --git a/src/azimuth.c b/src/azimuth.c new file mode 100644 index 0000000..4176c5d --- /dev/null +++ b/src/azimuth.c @@ -0,0 +1,99 @@ +/* + * azimuth.c - Source for Azimith + * Copyright (C) 2010 Guillaume Desmottes + * @author Guillaume Desmottes + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#include +#include + +#include "azimuth.h" +#include "position-publisher.h" + +G_DEFINE_TYPE(Azimuth, azimuth, G_TYPE_OBJECT) + +/* private structure */ +typedef struct _AzimuthPrivate AzimuthPrivate; + +struct _AzimuthPrivate +{ + GMainLoop *loop; + PositionPublisher *publisher; +}; + +#define AZIMUTH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), AZIMUTH_TYPE, AzimuthPrivate)) + +static void +azimuth_init (Azimuth *obj) +{ + AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (obj); + + priv->loop = g_main_loop_new (NULL, FALSE); + priv->publisher = NULL; +} + +static void +azimuth_dispose (GObject *object) +{ + Azimuth *self = AZIMUTH (object); + AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self); + + if (priv->publisher != NULL) + { + g_object_unref (priv->publisher); + priv->publisher = NULL; + } + + if (priv->loop != NULL) + { + g_main_loop_unref (priv->loop); + priv->loop = NULL; + } + + if (G_OBJECT_CLASS (azimuth_parent_class)->dispose) + G_OBJECT_CLASS (azimuth_parent_class)->dispose (object); +} + +static void +azimuth_class_init (AzimuthClass *azimuth_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (azimuth_class); + + g_type_class_add_private (azimuth_class, sizeof (AzimuthPrivate)); + + object_class->dispose = azimuth_dispose; +} + +Azimuth * +azimuth_new (void) +{ + return g_object_new (AZIMUTH_TYPE, + NULL); +} + +void +azimuth_run (Azimuth *self) +{ + AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self); + + g_assert (priv->publisher == NULL); + priv->publisher = position_publisher_new (); + + g_print ("azimuth running\n"); + g_main_loop_run (priv->loop); +} diff --git a/src/azimuth.h b/src/azimuth.h new file mode 100644 index 0000000..5d96828 --- /dev/null +++ b/src/azimuth.h @@ -0,0 +1,61 @@ +/* + * azimuth.h - Header for Azimith + * Copyright (C) 2010 Guillaume Desmottes + * @author Guillaume Desmottes + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __AZIMUTH_H__ +#define __AZIMUTH_H__ + +#include + +G_BEGIN_DECLS + +typedef struct _Azimuth Azimuth; +typedef struct _AzimuthClass AzimuthClass; + +struct _AzimuthClass { + GObjectClass parent_class; +}; + +struct _Azimuth { + GObject parent; +}; + +GType azimuth_get_type (void); + +/* TYPE MACROS */ +#define AZIMUTH_TYPE \ + (azimuth_get_type()) +#define AZIMUTH(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), AZIMUTH_TYPE, Azimuth)) +#define AZIMUTH_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), AZIMUTH_TYPE, AzimuthClass)) +#define IS_AZIMUTH(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), AZIMUTH_TYPE)) +#define IS_AZIMUTH_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), AZIMUTH_TYPE)) +#define AZIMUTH_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), AZIMUTH_TYPE, AzimuthClass)) + +Azimuth * azimuth_new (void); + +void azimuth_run (Azimuth *self); + +G_END_DECLS + +#endif /* #ifndef __AZIMUTH_H__*/ -- 1.7.9.5