|
|
1 | /** |
|
|
2 | * ZANavi, Zoff Android Navigation system. |
|
|
3 | * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc> |
|
|
4 | * |
|
|
5 | * This program is free software; you can redistribute it and/or |
|
|
6 | * modify it under the terms of the GNU General Public License |
|
|
7 | * version 2 as published by the Free Software Foundation. |
|
|
8 | * |
|
|
9 | * This program is distributed in the hope that it will be useful, |
|
|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
12 | * GNU General Public License for more details. |
|
|
13 | * |
|
|
14 | * You should have received a copy of the GNU General Public License |
|
|
15 | * along with this program; if not, write to the |
|
|
16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
|
17 | * Boston, MA 02110-1301, USA. |
|
|
18 | */ |
|
|
19 | |
1 | /** @file vehicle_android.c |
20 | /** @file vehicle_android.c |
2 | * @brief android uses dbus signals |
21 | * @brief android uses dbus signals |
3 | * |
22 | * |
4 | * Navit, a modular navigation system. |
23 | * Navit, a modular navigation system. |
5 | * Copyright (C) 2005-2008 Navit Team |
24 | * Copyright (C) 2005-2008 Navit Team |
… | |
… | |
63 | * @returns nothing |
82 | * @returns nothing |
64 | */ |
83 | */ |
65 | static void |
84 | static void |
66 | vehicle_android_destroy(struct vehicle_priv *priv) |
85 | vehicle_android_destroy(struct vehicle_priv *priv) |
67 | { |
86 | { |
68 | // dbg(0,"enter\n"); |
87 | // //DBG dbg(0,"enter\n"); |
69 | g_free(priv); |
88 | g_free(priv); |
70 | } |
89 | } |
71 | |
90 | |
72 | /** |
91 | /** |
73 | * @brief Provide the outside with information |
92 | * @brief Provide the outside with information |
… | |
… | |
79 | */ |
98 | */ |
80 | static int |
99 | static int |
81 | vehicle_android_position_attr_get(struct vehicle_priv *priv, |
100 | vehicle_android_position_attr_get(struct vehicle_priv *priv, |
82 | enum attr_type type, struct attr *attr) |
101 | enum attr_type type, struct attr *attr) |
83 | { |
102 | { |
84 | dbg(1,"enter %s\n",attr_to_name(type)); |
103 | //dbg(1,"enter %s\n",attr_to_name(type)); |
85 | switch (type) { |
104 | switch (type) |
|
|
105 | { |
86 | #if 0 |
106 | #if 0 |
87 | case attr_position_fix_type: |
107 | case attr_position_fix_type: |
88 | attr->u.num = priv->fix_type; |
108 | attr->u.num = priv->fix_type; |
89 | break; |
109 | break; |
90 | #endif |
110 | #endif |
… | |
… | |
118 | attr->u.str=priv->fixiso8601; |
138 | attr->u.str=priv->fixiso8601; |
119 | break; |
139 | break; |
120 | default: |
140 | default: |
121 | return 0; |
141 | return 0; |
122 | } |
142 | } |
123 | dbg(1,"ok\n"); |
143 | //dbg(1,"ok\n"); |
124 | attr->type = type; |
144 | attr->type = type; |
125 | return 1; |
145 | return 1; |
126 | } |
146 | } |
127 | |
147 | |
128 | struct vehicle_methods vehicle_android_methods = { |
148 | struct vehicle_methods vehicle_android_methods = { |
… | |
… | |
143 | v->height = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getAltitude); |
163 | v->height = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getAltitude); |
144 | v->radius = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getAccuracy); |
164 | v->radius = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getAccuracy); |
145 | tnow=(*jnienv)->CallLongMethod(jnienv, location, v->Location_getTime)/1000; |
165 | tnow=(*jnienv)->CallLongMethod(jnienv, location, v->Location_getTime)/1000; |
146 | tm = gmtime(&tnow); |
166 | tm = gmtime(&tnow); |
147 | strftime(v->fixiso8601, sizeof(v->fixiso8601), "%Y-%m-%dT%TZ", tm); |
167 | strftime(v->fixiso8601, sizeof(v->fixiso8601), "%Y-%m-%dT%TZ", tm); |
148 | // dbg(0,"lat %f lon %f\n",v->geo.lat,v->geo.lng); |
168 | // //DBG dbg(0,"lat %f lon %f\n",v->geo.lat,v->geo.lng); |
149 | v->have_coords=1; |
169 | v->have_coords=1; |
150 | |
170 | |
151 | // ***** calls: navit.c -> navit_vehicle_update |
171 | // ***** calls: navit.c -> navit_vehicle_update |
152 | callback_list_call_attr_0(v->cbl, attr_position_coord_geo); |
172 | callback_list_call_attr_0(v->cbl, attr_position_coord_geo); |
153 | } |
173 | } |
… | |
… | |
172 | if (!android_find_method(ret->LocationClass, "getTime", "()J", &ret->Location_getTime)) |
192 | if (!android_find_method(ret->LocationClass, "getTime", "()J", &ret->Location_getTime)) |
173 | return 0; |
193 | return 0; |
174 | if (!android_find_method(ret->LocationClass, "getAccuracy", "()F", &ret->Location_getAccuracy)) |
194 | if (!android_find_method(ret->LocationClass, "getAccuracy", "()F", &ret->Location_getAccuracy)) |
175 | return 0; |
195 | return 0; |
176 | if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitVehicle", &ret->NavitVehicleClass)) |
196 | if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitVehicle", &ret->NavitVehicleClass)) |
|
|
197 | { |
177 | return 0; |
198 | return 0; |
|
|
199 | } |
178 | dbg(0,"at 3\n"); |
200 | //DBG dbg(0,"at 3\n"); |
179 | cid = (*jnienv)->GetMethodID(jnienv, ret->NavitVehicleClass, "<init>", "(Landroid/content/Context;I)V"); |
201 | cid = (*jnienv)->GetMethodID(jnienv, ret->NavitVehicleClass, "<init>", "(Landroid/content/Context;I)V"); |
180 | if (cid == NULL) { |
202 | if (cid == NULL) |
|
|
203 | { |
181 | dbg(0,"no method found\n"); |
204 | //DBG dbg(0,"no method found\n"); |
182 | return 0; /* exception thrown */ |
205 | return 0; /* exception thrown */ |
183 | } |
206 | } |
184 | dbg(0,"at 4 android_activity=%p\n",android_activity); |
207 | //DBG dbg(0,"at 4 android_activity=%p\n",android_activity); |
185 | ret->NavitVehicle=(*jnienv)->NewObject(jnienv, ret->NavitVehicleClass, cid, android_activity, (int) ret->cb); |
208 | ret->NavitVehicle=(*jnienv)->NewObject(jnienv, ret->NavitVehicleClass, cid, android_activity, (int) ret->cb); |
186 | dbg(0,"result=%p\n",ret->NavitVehicle); |
209 | //DBG dbg(0,"result=%p\n",ret->NavitVehicle); |
187 | if (!ret->NavitVehicle) |
210 | if (!ret->NavitVehicle) |
|
|
211 | { |
188 | return 0; |
212 | return 0; |
|
|
213 | } |
|
|
214 | |
189 | if (ret->NavitVehicle) |
215 | if (ret->NavitVehicle) |
|
|
216 | { |
190 | (*jnienv)->NewGlobalRef(jnienv, ret->NavitVehicle); |
217 | ret->NavitVehicle = (*jnienv)->NewGlobalRef(jnienv, ret->NavitVehicle); |
|
|
218 | } |
191 | |
219 | |
192 | return 1; |
220 | return 1; |
193 | } |
221 | } |
194 | |
222 | |
195 | /** |
223 | /** |
… | |
… | |
205 | struct callback_list *cbl, |
233 | struct callback_list *cbl, |
206 | struct attr **attrs) |
234 | struct attr **attrs) |
207 | { |
235 | { |
208 | struct vehicle_priv *ret; |
236 | struct vehicle_priv *ret; |
209 | |
237 | |
210 | dbg(0, "enter\n"); |
238 | //DBG dbg(0, "enter\n"); |
211 | ret = g_new0(struct vehicle_priv, 1); |
239 | ret = g_new0(struct vehicle_priv, 1); |
212 | ret->cbl = cbl; |
240 | ret->cbl = cbl; |
213 | ret->cb=callback_new_1(callback_cast(vehicle_android_callback), ret); |
241 | ret->cb=callback_new_1(callback_cast(vehicle_android_callback), ret); |
214 | *meth = vehicle_android_methods; |
242 | *meth = vehicle_android_methods; |
215 | vehicle_android_init(ret); |
243 | vehicle_android_init(ret); |
216 | dbg(0, "return\n"); |
244 | //DBG dbg(0, "return\n"); |
217 | return ret; |
245 | return ret; |
218 | } |
246 | } |
219 | |
247 | |
220 | /** |
248 | /** |
221 | * @brief register vehicle_android |
249 | * @brief register vehicle_android |
… | |
… | |
223 | * @returns nothing |
251 | * @returns nothing |
224 | */ |
252 | */ |
225 | void |
253 | void |
226 | plugin_init(void) |
254 | plugin_init(void) |
227 | { |
255 | { |
228 | // dbg(0, "enter\n"); |
256 | //DBG dbg(0, "enter\n"); |
229 | plugin_register_vehicle_type("android", vehicle_android_new_android); |
257 | plugin_register_vehicle_type("android", vehicle_android_new_android); |
230 | } |
258 | } |