update for beta universally
[framework/location/libslp-location.git] / location / location-ips.c
1 /*
2  * libslp-location
3  *
4  * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
7  *          Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "location/location-setting.h"
27 #include "location/location-log.h"
28
29 #include "location/location-module-internal.h"
30
31 #include "location/location-ips.h"
32 #include "location/location-marshal.h"
33 #include "location/location-ielement.h"
34
35 typedef struct _LocationIpsPrivate {
36         LocationIpsMod *mod;
37         LocationPosition *pos;
38         LocationAccuracy *acc;
39 } LocationIpsPrivate;
40
41 enum {
42         PROP_0,
43         PROP_METHOD_TYPE,
44         PROP_LAST_POSITION
45 };
46
47 #define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_IPS, LocationIpsPrivate))
48
49 static void location_ielement_interface_init (LocationIElementInterface *iface);
50
51 G_DEFINE_TYPE_WITH_CODE (LocationIps, location_ips, G_TYPE_OBJECT,
52                          G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT,
53                          location_ielement_interface_init));
54
55 static void
56 location_ips_dispose (GObject *gobject)
57 {
58         LOCATION_LOGD("location_ips_dispose");
59         G_OBJECT_CLASS (location_ips_parent_class)->dispose (gobject);
60 }
61
62 static void
63 location_ips_finalize (GObject *gobject)
64 {
65         LOCATION_LOGD("location_ips_finalize");
66         LocationIpsPrivate* priv = GET_PRIVATE(gobject);
67         module_free(priv->mod, "ips");
68         priv->mod = NULL;
69
70         G_OBJECT_CLASS (location_ips_parent_class)->finalize (gobject);
71 }
72
73 static void
74 location_ips_get_property (GObject *object,
75         guint property_id,
76         GValue *value,
77         GParamSpec *pspec)
78 {
79         LocationIpsPrivate *priv = GET_PRIVATE (object);
80
81         switch (property_id){
82                 case PROP_METHOD_TYPE:
83                         g_value_set_int(value, LOCATION_METHOD_IPS);
84                         break;
85                 case PROP_LAST_POSITION:{
86                         g_value_set_boxed (value, priv->pos);
87                         break;
88                 }
89                 default:
90                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
91                         break;
92         }
93 }
94
95 static int
96 location_ips_get_position (LocationIps *self,
97         LocationPosition **position,
98         LocationAccuracy **accuracy)
99 {
100         LOCATION_LOGD("location_ips_get_position");
101
102         LocationIpsPrivate *priv = GET_PRIVATE (self);
103         g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
104         setting_retval_if_fail(GPS_ENABLED);
105         setting_retval_if_fail(NETWORK_ENABLED);
106
107         LocModIpsOps ops = priv->mod->ops;
108         g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
109         g_return_val_if_fail (ops.get_position, LOCATION_ERROR_NOT_AVAILABLE);
110         int ret = ops.get_position(priv->mod->handler, position, accuracy);
111         if (priv->pos) location_position_free(priv->pos);
112         if (priv->acc) location_accuracy_free(priv->acc);
113         priv->pos = location_position_copy(*position);
114         priv->acc = location_accuracy_copy(*accuracy);
115         return ret;
116 }
117
118 static void
119 location_ielement_interface_init (LocationIElementInterface *iface)
120 {
121         iface->get_position = (TYPE_GET_POSITION)location_ips_get_position;
122 }
123
124 static void
125 location_ips_init (LocationIps *self)
126 {
127         LOCATION_LOGD("location_ips_init");
128         LocationIpsPrivate* priv = GET_PRIVATE(self);
129
130         priv->mod = (LocationIpsMod*)module_new("ips");
131         if(!priv->mod) LOCATION_LOGW("module loading failed");
132
133         priv->pos = NULL;
134         priv->acc = NULL;
135 }
136
137 static void
138 location_ips_class_init (LocationIpsClass *klass)
139 {
140         LOCATION_LOGD("location_ips_class_init");
141         GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
142         GParamSpec *pspec;
143
144         gobject_class->get_property = location_ips_get_property;
145
146         gobject_class->dispose = location_ips_dispose;
147         gobject_class->finalize = location_ips_finalize;
148
149         g_type_class_add_private (klass, sizeof (LocationIpsPrivate));
150
151         pspec = g_param_spec_int ("method",
152                                 "method type",
153                                 "location method type name",
154                                 LOCATION_METHOD_IPS,
155                                 LOCATION_METHOD_IPS,
156                                 LOCATION_METHOD_IPS,
157                                 G_PARAM_READABLE);
158         g_object_class_install_property (gobject_class,
159                                    PROP_METHOD_TYPE,
160                                    pspec);
161
162         pspec = g_param_spec_boxed ("last-position",
163                                 "ips last position prop",
164                                 "ips last position data",
165                                 LOCATION_TYPE_POSITION,
166                                 G_PARAM_READABLE);
167         g_object_class_install_property (gobject_class,
168                                    PROP_LAST_POSITION,
169                                    pspec);
170 }
171