add azimuth.[ch]
[azimuth] / src / azimuth.c
1 /*
2  * azimuth.c - Source for Azimith
3  * Copyright (C) 2010 Guillaume Desmottes
4  * @author Guillaume Desmottes <gdesmott@gnome.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include "azimuth.h"
26 #include "position-publisher.h"
27
28 G_DEFINE_TYPE(Azimuth, azimuth, G_TYPE_OBJECT)
29
30 /* private structure */
31 typedef struct _AzimuthPrivate AzimuthPrivate;
32
33 struct _AzimuthPrivate
34 {
35   GMainLoop *loop;
36   PositionPublisher *publisher;
37 };
38
39 #define AZIMUTH_GET_PRIVATE(o)     (G_TYPE_INSTANCE_GET_PRIVATE ((o), AZIMUTH_TYPE, AzimuthPrivate))
40
41 static void
42 azimuth_init (Azimuth *obj)
43 {
44   AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (obj);
45
46   priv->loop = g_main_loop_new (NULL, FALSE);
47   priv->publisher = NULL;
48 }
49
50 static void
51 azimuth_dispose (GObject *object)
52 {
53   Azimuth *self = AZIMUTH (object);
54   AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
55
56   if (priv->publisher != NULL)
57     {
58       g_object_unref (priv->publisher);
59       priv->publisher = NULL;
60     }
61
62   if (priv->loop != NULL)
63     {
64       g_main_loop_unref (priv->loop);
65       priv->loop = NULL;
66     }
67
68   if (G_OBJECT_CLASS (azimuth_parent_class)->dispose)
69     G_OBJECT_CLASS (azimuth_parent_class)->dispose (object);
70 }
71
72 static void
73 azimuth_class_init (AzimuthClass *azimuth_class)
74 {
75   GObjectClass *object_class = G_OBJECT_CLASS (azimuth_class);
76
77   g_type_class_add_private (azimuth_class, sizeof (AzimuthPrivate));
78
79   object_class->dispose = azimuth_dispose;
80 }
81
82 Azimuth *
83 azimuth_new (void)
84 {
85   return g_object_new (AZIMUTH_TYPE,
86       NULL);
87 }
88
89 void
90 azimuth_run (Azimuth *self)
91 {
92   AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
93
94   g_assert (priv->publisher == NULL);
95   priv->publisher = position_publisher_new ();
96
97   g_print ("azimuth running\n");
98   g_main_loop_run (priv->loop);
99 }