/[zanavi_public1]/navit/navit/vehicle/android/vehicle_android.c
ZANavi

Diff of /navit/navit/vehicle/android/vehicle_android.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 29 Revision 30
76 jmethodID Location_getLatitude, Location_getLongitude, Location_getSpeed, Location_getBearing, Location_getAltitude, Location_getTime, Location_getAccuracy; 76 jmethodID Location_getLatitude, Location_getLongitude, Location_getSpeed, Location_getBearing, Location_getAltitude, Location_getTime, Location_getAccuracy;
77}; 77};
78 78
79// global vars 79// global vars
80struct vehicle_priv *priv_global_android = NULL; 80struct vehicle_priv *priv_global_android = NULL;
81
82jclass NavitClass3 = NULL;
83jmethodID Navit_get_vehicle;
81// global vars 84// global vars
85
86
87
88
89static int find_static_method(jclass class, char *name, char *args, jmethodID *ret)
90{
91 JNIEnv *jnienv2;
92 jnienv2 = jni_getenv();
93
94 //DBG dbg(0,"EEnter\n");
95 *ret = (*jnienv2)->GetStaticMethodID(jnienv2, class, name, args);
96 if (*ret == NULL)
97 {
98 //DBG dbg(0, "Failed to get static Method %s with signature %s\n", name, args);
99 return 0;
100 }
101 return 1;
102}
82 103
83 104
84/** 105/**
85 * @brief Free the android_vehicle 106 * @brief Free the android_vehicle
86 * 107 *
173 time_t tnow; 194 time_t tnow;
174 struct tm *tm; 195 struct tm *tm;
175 196
176 struct vehicle_priv *v = priv_global_android; 197 struct vehicle_priv *v = priv_global_android;
177 198
199 JNIEnv *jnienv2;
200 jnienv2 = jni_getenv();
201
178 //dbg(0,"jnienv=%p\n", jnienv); 202 //dbg(0,"jnienv=%p\n", jnienv);
179 //dbg(0,"priv_global_android=%p\n", priv_global_android); 203 //dbg(0,"priv_global_android=%p\n", priv_global_android);
180 //dbg(0,"v=%p\n", v); 204 //dbg(0,"v=%p\n", v);
181 //dbg(0,"location=%p\n", location); 205 //dbg(0,"location=%p\n", location);
182 206
183 // this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!) 207 // this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!)
184 // this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!) 208 // this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!)
185 // this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!) 209 // this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!)
186 v->geo.lat = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getLatitude); 210 v->geo.lat = (*jnienv2)->CallDoubleMethod(jnienv2, location, v->Location_getLatitude);
187 v->geo.lng = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getLongitude); 211 v->geo.lng = (*jnienv2)->CallDoubleMethod(jnienv2, location, v->Location_getLongitude);
188 v->speed = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getSpeed) * 3.6; // convert from m/s -> km/h 212 v->speed = (*jnienv2)->CallFloatMethod(jnienv2, location, v->Location_getSpeed) * 3.6; // convert from m/s -> km/h
189 v->direction = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getBearing); 213 v->direction = (*jnienv2)->CallFloatMethod(jnienv2, location, v->Location_getBearing);
190 v->height = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getAltitude); 214 v->height = (*jnienv2)->CallDoubleMethod(jnienv2, location, v->Location_getAltitude);
191 v->radius = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getAccuracy); 215 v->radius = (*jnienv2)->CallFloatMethod(jnienv2, location, v->Location_getAccuracy);
192 tnow = (*jnienv)->CallLongMethod(jnienv, location, v->Location_getTime) / 1000; 216 tnow = (*jnienv2)->CallLongMethod(jnienv2, location, v->Location_getTime) / 1000;
193 // this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!) 217 // this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!)
194 // this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!) 218 // this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!)
195 // this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!) 219 // this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!)
196 220
197 221
199 strftime(v->fixiso8601, sizeof(v->fixiso8601), "%Y-%m-%dT%TZ", tm); 223 strftime(v->fixiso8601, sizeof(v->fixiso8601), "%Y-%m-%dT%TZ", tm);
200 // //DBG dbg(0,"lat %f lon %f\n",v->geo.lat,v->geo.lng); 224 // //DBG dbg(0,"lat %f lon %f\n",v->geo.lat,v->geo.lng);
201 v->have_coords = 1; 225 v->have_coords = 1;
202 226
203 // remove globalref again 227 // remove globalref again
204 (*jnienv)->DeleteGlobalRef(jnienv, location); 228 (*jnienv2)->DeleteGlobalRef(jnienv2, location);
205 229
206 // ***** calls: navit.c -> navit_vehicle_update 230 // ***** calls: navit.c -> navit_vehicle_update
207 // xxx stupid callback stuff -> remove me!! xxx 231 // xxx stupid callback stuff -> remove me!! xxx
208 callback_list_call_attr_0(v->cbl, attr_position_coord_geo); 232 callback_list_call_attr_0(v->cbl, attr_position_coord_geo);
209 233
223static int vehicle_android_init(struct vehicle_priv *ret) 247static int vehicle_android_init(struct vehicle_priv *ret)
224{ 248{
225#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT 249#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
226 dbg(0,"+#+:enter\n"); 250 dbg(0,"+#+:enter\n");
227#endif 251#endif
252
253 int thread_id = gettid();
254 dbg(0, "THREAD ID=%d\n", thread_id);
255
256 JNIEnv *jnienv2;
257 jnienv2 = jni_getenv();
258
228 jmethodID cid; 259 jmethodID cid;
229 260
230 //dbg(0,"priv_global_android=%p\n", priv_global_android); 261 //dbg(0,"priv_global_android=%p\n", priv_global_android);
231 262
232 if (!android_find_class_global("android/location/Location", &ret->LocationClass)) 263 if (!android_find_class_global("android/location/Location", &ret->LocationClass))
248 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitVehicle", &ret->NavitVehicleClass)) 279 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitVehicle", &ret->NavitVehicleClass))
249 { 280 {
250 return 0; 281 return 0;
251 } 282 }
252 283
253 //dbg(0,"jnienv=%p\n", jnienv); 284 //dbg(0,"jnienv2=%p\n", jnienv2);
254 285
255 //DBG dbg(0,"at 3\n"); 286 //DBG dbg(0,"at 3\n");
256 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitVehicleClass, "<init>", "(Landroid/content/Context;I)V"); 287 //cid = (*jnienv2)->GetMethodID(jnienv2, ret->NavitVehicleClass, "<init>", "(Landroid/content/Context;I)V");
257 if (cid == NULL) 288 //if (cid == NULL)
258 { 289 //{
259 //DBG dbg(0,"no method found\n"); 290 // //DBG dbg(0,"no method found\n");
291 // return 0;
292 //}
293
294 // --------------- Init the new Vehicle Object here -----------------
295 // --------------- Init the new Vehicle Object here -----------------
296 // --------------- Init the new Vehicle Object here -----------------
297 dbg(0,"Init the new Vehicle Object here\n");
298
299 if (NavitClass3 == NULL)
300 {
301 if (!android_find_class_global("com/zoffcc/applications/zanavi/Navit", &NavitClass3))
302 {
303 NavitClass3 = NULL;
260 return 0; 304 return 0;
261 } 305 }
262 //DBG dbg(0,"at 4 android_activity=%p\n",android_activity); 306 }
307
308 if (!find_static_method(NavitClass3, "get_vehicle_object", "()Lcom/zoffcc/applications/zanavi/NavitVehicle;", &Navit_get_vehicle))
309 {
310 return 0;
311 }
312
263 ret->NavitVehicle = (*jnienv)->NewObject(jnienv, ret->NavitVehicleClass, cid, android_activity, (int) ret->cb); 313 /// --old-- ret->NavitVehicle = (*jnienv2)->NewObject(jnienv2, ret->NavitVehicleClass, cid, android_activity, (int) ret->cb);
264 //DBG dbg(0,"result=%p\n",ret->NavitVehicle); 314 /// --new--
315 ret->NavitVehicle = (*jnienv2)->CallStaticObjectMethod(jnienv2, NavitClass3, Navit_get_vehicle);
316 /// --new--
317 // --------------- Init the new Vehicle Object here -----------------
318 // --------------- Init the new Vehicle Object here -----------------
319 // --------------- Init the new Vehicle Object here -----------------
320
265 if (!ret->NavitVehicle) 321 if (!ret->NavitVehicle)
266 { 322 {
267 return 0; 323 return 0;
268 } 324 }
269 325
270 if (ret->NavitVehicle) 326 if (ret->NavitVehicle)
271 { 327 {
272 ret->NavitVehicle = (*jnienv)->NewGlobalRef(jnienv, ret->NavitVehicle); 328 ret->NavitVehicle = (*jnienv2)->NewGlobalRef(jnienv2, ret->NavitVehicle);
273 } 329 }
330
331 dbg(0,"leave\n");
274 332
275#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT 333#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
276 dbg(0,"+#+:leave\n"); 334 dbg(0,"+#+:leave\n");
277#endif 335#endif
278 336

Legend:
Removed from v.29  
changed lines
  Added in v.30

   
Visit the ZANavi Wiki