tizen 2.3.1 release
[framework/telephony/libtcore.git] / src / co_gps.c
1 /*
2  * libtcore
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Ja-young Gu <jygu@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include <glib.h>
26
27 #include "tcore.h"
28 #include "plugin.h"
29 #include "user_request.h"
30 #include "co_gps.h"
31
32 struct private_object_data {
33         struct tcore_gps_operations *ops;
34 };
35
36 static void _free_hook(CoreObject *o)
37 {
38         struct private_object_data *po = NULL;
39
40         po = tcore_object_ref_object(o);
41         if (po) {
42                 free(po);
43                 tcore_object_link_object(o, NULL);
44         }
45 }
46
47 static void _clone_hook(CoreObject *src, CoreObject *dest)
48 {
49         struct private_object_data *src_po = NULL;
50         struct private_object_data *dest_po = NULL;
51
52         if (!src || !dest)
53                 return;
54
55         dest_po = calloc(1, sizeof(struct private_object_data));
56         if (!dest_po) {
57                 tcore_object_link_object(dest, NULL);
58                 return;
59         }
60
61         src_po = tcore_object_ref_object(src);
62         dest_po->ops = src_po->ops;
63
64         tcore_object_link_object(dest, dest_po);
65 }
66
67 static TReturn _dispatcher(CoreObject *o, UserRequest *ur)
68 {
69         enum tcore_request_command command;
70         struct private_object_data *po = NULL;
71
72         if (!o || !ur)
73                 return TCORE_RETURN_EINVAL;
74
75         po = tcore_object_ref_object(o);
76         if (!po || !po->ops)
77                 return TCORE_RETURN_ENOSYS;
78
79         command = tcore_user_request_get_command(ur);
80         switch (command) {
81                 case TREQ_GPS_CONFIRM_MEASURE_POS:
82                         dbg("TREQ_GPS_CONFIRM_MEASURE_POS");
83                         if (!po->ops->confirm_measure_pos)
84                                 return TCORE_RETURN_ENOSYS;
85
86                         return po->ops->confirm_measure_pos(o, ur);
87
88                 case TREQ_GPS_SET_FREQUENCY_AIDING:
89                         dbg("TREQ_GPS_SET_FREQUENCY_AIDING");
90                         if (!po->ops->set_frequency_aiding)
91                                 return TCORE_RETURN_ENOSYS;
92
93                         return po->ops->set_frequency_aiding(o, ur);
94
95                 case TREQ_ENABLE_SMART_ASSISTANT:
96                         dbg("TREQ_ENABLE_SMART_ASSISTANT");
97                         if (!po->ops->enable_smart_assistant)
98                                 return TCORE_RETURN_ENOSYS;
99
100                         return po->ops->enable_smart_assistant(o, ur);
101
102                 case TREQ_DISABLE_SMART_ASSISTANT:
103                         dbg("TREQ_DISABLE_SMART_ASSISTANT");
104                         if (!po->ops->disable_smart_assistant)
105                                 return TCORE_RETURN_ENOSYS;
106
107                         return po->ops->disable_smart_assistant(o, ur);
108
109                 case TREQ_SYNC_SMART_ASSISTANT_AREA_LIST:
110                         dbg("TREQ_SYNC_SMART_ASSISTANT_AREA_LIST");
111                         if (!po->ops->sync_smart_assistant_area_list)
112                                 return TCORE_RETURN_ENOSYS;
113
114                         return po->ops->sync_smart_assistant_area_list(o, ur);
115
116                 case TREQ_DEL_SMART_ASSISTANT_AREA_LIST:
117                         dbg("TREQ_DEL_SMART_ASSISTANT_AREA_LIST");
118                         if (!po->ops->del_smart_assistant_area_list)
119                                 return TCORE_RETURN_ENOSYS;
120
121                         return po->ops->del_smart_assistant_area_list(o, ur);
122
123                 case TREQ_ADD_SMART_ASSISTANT_AREA:
124                         dbg("TREQ_ADD_SMART_ASSISTANT_AREA");
125                         if (!po->ops->add_smart_assistant_area)
126                                 return TCORE_RETURN_ENOSYS;
127
128                         return po->ops->add_smart_assistant_area(o, ur);
129
130                 case TREQ_MODIFY_SMART_ASSISTANT_AREA:
131                         dbg("TREQ_MODIFY_SMART_ASSISTANT_AREA");
132                         if (!po->ops->modify_smart_assistant_area)
133                                 return TCORE_RETURN_ENOSYS;
134
135                         return po->ops->modify_smart_assistant_area(o, ur);
136
137                 case TREQ_SET_SMART_ASSISTANT_INFO:
138                         dbg("TREQ_SET_SMART_ASSISTANT_INFO");
139                         if (!po->ops->set_smart_assistant_info)
140                                 return TCORE_RETURN_ENOSYS;
141
142                         return po->ops->set_smart_assistant_info(o, ur);
143
144                 default:
145                         dbg("not supported cmd");
146                         break;
147         }
148         return TCORE_RETURN_SUCCESS;
149 }
150
151 CoreObject *tcore_gps_new(TcorePlugin *p, const char *name,
152                 struct tcore_gps_operations *ops, TcoreHal *hal)
153 {
154         CoreObject *o = NULL;
155         struct private_object_data *po = NULL;
156
157         if (!p)
158                 return NULL;
159
160         o = tcore_object_new(p, name, hal);
161         if (!o)
162                 return NULL;
163
164         po = calloc(1, sizeof(struct private_object_data));
165         if (!po) {
166                 tcore_object_free(o);
167                 return NULL;
168         }
169
170         po->ops = ops;
171
172         tcore_object_set_type(o, CORE_OBJECT_TYPE_GPS);
173         tcore_object_link_object(o, po);
174         tcore_object_set_dispatcher(o, _dispatcher);
175         tcore_object_set_free_hook(o, _free_hook);
176         tcore_object_set_clone_hook(o, _clone_hook);
177
178         return o;
179 }
180
181 void tcore_gps_free(CoreObject *o)
182 {
183         CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_GPS);
184
185         tcore_object_free(o);
186 }
187
188 void tcore_gps_set_ops(CoreObject *o, struct tcore_gps_operations *ops)
189 {
190         struct private_object_data *po = NULL;
191
192         CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_GPS);
193
194         po = (struct private_object_data *)tcore_object_ref_object(o);
195         if (!po) {
196                 return;
197         }
198
199         po->ops = ops;
200 }