From e38d453bcf0c8a99b7f9fcee9dcfae8f3fa39054 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Mon, 3 Aug 2020 19:53:27 +0200 Subject: Fix:build:Prevent try_compile() from choking on CXX Signed-off-by: mvglasow --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b1717d1a5..362937200 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.2) set(MACOSX_BUNDLE_GUI_IDENTIFIER "org.navitproject.navit") set(MACOSX_BUNDLE_BUNDLE_NAME "Navit") message(STATUS "Building with CMake V${CMAKE_VERSION}") -project(navit C) +project(navit C CXX) # Workaround for CMake issue 8345 / 9220, see http://trac.navit-project.org/ticket/1041 if(DEFINED CMAKE_CXX_COMPILER AND CMAKE_CXX_COMPILER MATCHES "^$") -- cgit v1.2.1 From e72acd6493f5d074223372b8deebe67816725c56 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Thu, 6 Aug 2020 22:32:19 +0200 Subject: Add:traffic:Add basic TraFF 0.8 support Signed-off-by: mvglasow --- .../src/org/navitproject/navit/NavitTraff.java | 238 +++++++++++++++++++-- navit/navit.c | 29 +++ navit/traffic.c | 11 +- navit/traffic.h | 6 + navit/traffic/dummy/traffic_dummy.c | 1 + navit/traffic/null/traffic_null.c | 1 + .../traffic/traff_android/traffic_traff_android.c | 16 ++ navit/xmlconfig.h | 2 +- 8 files changed, 283 insertions(+), 21 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index c82d7d293..8ef738724 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -25,11 +25,18 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.IntentFilter.MalformedMimeTypeException; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.database.Cursor; +import android.net.Uri; +import android.os.Bundle; import android.util.Log; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; /** * The TraFF receiver implementation. @@ -39,11 +46,35 @@ import java.util.List; */ public class NavitTraff extends BroadcastReceiver { + private static final String ACTION_TRAFF_GET_CAPABILITIES = "org.traffxml.traff.GET_CAPABILITIES"; private static final String ACTION_TRAFF_FEED = "org.traffxml.traff.FEED"; private static final String ACTION_TRAFF_POLL = "org.traffxml.traff.POLL"; + private static final String ACTION_TRAFF_SUBSCRIBE = "org.traffxml.traff.SUBSCRIBE"; + private static final String ACTION_TRAFF_SUBSCRIPTION_CHANGE = "org.traffxml.traff.SUBSCRIPTION_CHANGE"; + private static final String ACTION_TRAFF_UNSUBSCRIBE = "org.traffxml.traff.UNSUBSCRIBE"; + private static final String COLUMN_DATA = "data"; + private static final String CONTENT_SCHEMA = "content"; + private static final String EXTRA_CAPABILITIES = "capabilities"; private static final String EXTRA_FEED = "feed"; + private static final String EXTRA_FILTER_LIST = "filter_list"; + private static final String EXTRA_PACKAGE = "package"; + private static final String EXTRA_SUBSCRIPTION_ID = "subscription_id"; + private static final String MIME_TYPE_TRAFF = "vnd.android.cursor.dir/org.traffxml.message"; + private static final int RESULT_OK = -1; + private static final int RESULT_INTERNAL_ERROR = 7; + private static final int RESULT_INVALID = 1; + private static final int RESULT_SUBSCRIPTION_REJECTED = 2; + private static final int RESULT_NOT_COVERED = 3; + private static final int RESULT_PARTIALLY_COVERED = 4; + private static final int RESULT_SUBSCRIPTION_UNKNOWN = 5; + private static final String TAG = "NavitTraff"; private final long mCbid; + private final Context context; + + /** Active subscriptions (key is the subscription ID, value is the package ID) */ + private Map subscriptions = new HashMap(); + /** * Forwards a newly received TraFF feed to the traffic module for processing. * @@ -65,39 +96,212 @@ public class NavitTraff extends BroadcastReceiver { */ NavitTraff(Context context, long cbid) { this.mCbid = cbid; + this.context = context.getApplicationContext(); - /* An intent filter for TraFF events. */ - IntentFilter traffFilter = new IntentFilter(); - traffFilter.addAction(ACTION_TRAFF_FEED); - traffFilter.addAction(ACTION_TRAFF_POLL); + /* An intent filter for TraFF 0.7 events. */ + IntentFilter traffFilter07 = new IntentFilter(); + traffFilter07.addAction(ACTION_TRAFF_FEED); + + /* An intent filter for TraFF 0.8 events. */ + IntentFilter traffFilter08 = new IntentFilter(); + traffFilter08.addAction(ACTION_TRAFF_FEED); + traffFilter08.addDataScheme(CONTENT_SCHEMA); + try { + traffFilter08.addDataType(MIME_TYPE_TRAFF); + } catch (MalformedMimeTypeException e) { + // as long as the constant is a well-formed MIME type, this exception never gets thrown + e.printStackTrace(); + } - context.registerReceiver(this, traffFilter); - /* TODO unregister receiver on exit */ + this.context.registerReceiver(this, traffFilter07); + this.context.registerReceiver(this, traffFilter08); /* Broadcast a poll intent */ Intent outIntent = new Intent(ACTION_TRAFF_POLL); - PackageManager pm = context.getPackageManager(); - List receivers = pm.queryBroadcastReceivers(outIntent, 0); - if (receivers != null) { - for (ResolveInfo receiver : receivers) { + PackageManager pm = this.context.getPackageManager(); + List receivers07 = pm.queryBroadcastReceivers(outIntent, 0); + /* receivers with TraFF 0.8 support */ + List receivers08 = pm.queryBroadcastReceivers(new Intent(ACTION_TRAFF_GET_CAPABILITIES), 0); + if (receivers07 != null) { + /* get receivers which support only TraFF 0.7 */ + if (receivers08 != null) + receivers07.removeAll(receivers08); + for (ResolveInfo receiver : receivers07) { ComponentName cn = new ComponentName(receiver.activityInfo.applicationInfo.packageName, receiver.activityInfo.name); outIntent = new Intent(ACTION_TRAFF_POLL); outIntent.setComponent(cn); - context.sendBroadcast(outIntent, Manifest.permission.ACCESS_COARSE_LOCATION); + this.context.sendBroadcast(outIntent, Manifest.permission.ACCESS_COARSE_LOCATION); + } + } + if (receivers08 != null) { + for (ResolveInfo receiver : receivers08) { + Bundle extras = new Bundle(); + extras.putString(EXTRA_PACKAGE, context.getPackageName()); + extras.putString(EXTRA_FILTER_LIST, ""); + sendTraffIntent(context, ACTION_TRAFF_SUBSCRIBE, null, extras, + receiver.activityInfo.applicationInfo.packageName, + Manifest.permission.ACCESS_COARSE_LOCATION, this); } } } + void close() { + for (Map.Entry subscription : subscriptions.entrySet()) { + Bundle extras = new Bundle(); + extras.putString(EXTRA_SUBSCRIPTION_ID, subscription.getKey()); + sendTraffIntent(this.context, ACTION_TRAFF_UNSUBSCRIBE, null, extras, subscription.getValue(), + Manifest.permission.ACCESS_COARSE_LOCATION, this); + } + this.context.unregisterReceiver(this); + } + @Override public void onReceive(Context context, Intent intent) { - if ((intent != null) && (intent.getAction().equals(ACTION_TRAFF_FEED))) { - String feed = intent.getStringExtra(EXTRA_FEED); - if (feed == null) { - Log.w(this.getClass().getSimpleName(), "empty feed, ignoring"); - } else { - onFeedReceived(mCbid, feed); + if (intent != null) { + if (intent.getAction().equals(ACTION_TRAFF_FEED)) { + Uri uri = intent.getData(); + if (uri != null) { + /* 0.8 feed */ + String subscriptionId = intent.getStringExtra(EXTRA_SUBSCRIPTION_ID); + if (subscriptions.containsValue(subscriptionId)) + fetchMessages(context, uri); + else { + /* + * If we don’t recognize the subscription, skip processing and unsubscribe. + * Note: if EXTRA_PACKAGE is not set, sendTraffIntent() sends the request to every + * manifest-declared receiver which handles the request. + */ + Bundle extras = new Bundle(); + extras.putString(EXTRA_SUBSCRIPTION_ID, subscriptionId); + sendTraffIntent(context, ACTION_TRAFF_UNSUBSCRIBE, null, extras, + intent.getStringExtra(EXTRA_PACKAGE), + Manifest.permission.ACCESS_COARSE_LOCATION, this); + } + } else { + /* 0.7 feed */ + String packageName = intent.getStringExtra(EXTRA_PACKAGE); + /* if the feed comes from a TraFF 0.8+ source and we are subscribed, skip it */ + // TODO what if we don’t have a subscription yet? First subscribe, then poll (still no guarantee) + if ((packageName != null) && subscriptions.containsValue(packageName)) + return; + String feed = intent.getStringExtra(EXTRA_FEED); + if (feed == null) { + Log.w(this.getClass().getSimpleName(), "empty feed, ignoring"); + } else { + onFeedReceived(mCbid, feed); + } + } // uri != null + } else if (intent.getAction().equals(ACTION_TRAFF_SUBSCRIBE)) { + if (this.getResultCode() != RESULT_OK) + return; + Bundle extras = this.getResultExtras(true); + String data = this.getResultData(); + String packageName = extras.getString(EXTRA_PACKAGE); + String subscriptionId = extras.getString(EXTRA_SUBSCRIPTION_ID); + if ((data == null) || (packageName == null) || (subscriptionId == null)) + return; + subscriptions.put(subscriptionId, packageName); + fetchMessages(context, Uri.parse(data)); + } else if (intent.getAction().equals(ACTION_TRAFF_SUBSCRIPTION_CHANGE)) { + if (this.getResultCode() != RESULT_OK) + return; + Bundle extras = this.getResultExtras(true); + String data = this.getResultData(); + String subscriptionId = extras.getString(EXTRA_SUBSCRIPTION_ID); + if ((data == null) || (subscriptionId == null) || (!subscriptions.containsKey(subscriptionId))) + return; + fetchMessages(context, Uri.parse(data)); + } else if (intent.getAction().equals(ACTION_TRAFF_UNSUBSCRIBE)) { + /* + * If we ever unsubscribe for reasons other than that we are shutting down or got a feed for + * a subscription we don’t recognize, or if we start keeping a persistent list of + * subscriptions, we need to delete the subscription from our list. Until then, there is + * nothing to do here: either the subscription isn’t in the list, or we are about to shut + * down and the whole list is about to get discarded. + */ + } // intent.getAction() + } // intent != null + } + + /** + * @brief Fetches messages from a content provider. + * + * @param context + * @param uri The content provider URI + */ + private void fetchMessages(Context context, Uri uri) { + try { + Cursor cursor = context.getContentResolver().query(uri, new String[] {COLUMN_DATA}, null, null, null); + if (cursor == null) + return; + if (cursor.getCount() < 1) { + cursor.close(); + return; } + StringBuilder builder = new StringBuilder("\n"); + while (cursor.moveToNext()) + builder.append(cursor.getString(cursor.getColumnIndex(COLUMN_DATA))).append("\n"); + builder.append(""); + cursor.close(); + onFeedReceived(mCbid, builder.toString()); + } catch (Exception e) { + Log.w(TAG, String.format("Unable to fetch messages from %s", uri.toString()), e); + e.printStackTrace(); } } + + /** + * @brief Sends a TraFF intent to a source. + * + * This encapsulates most of the low-level Android handling. + * + * If the recipient specified in {@code packageName} declares multiple receivers for the intent in its + * manifest, a separate intent will be delivered to each of them. The intent will not be delivered to + * receivers registered at runtime. + * + * All intents are sent as explicit ordered broadcasts. This means two things: + * + * Any app which declares a matching receiver in its manifest will be woken up to process the intent. + * This works even with certain Android 7 builds which restrict intent delivery to apps which are not + * currently running. + * + * It is safe for the recipient to unconditionally set result data. If the recipient does not set result + * data, the result will have a result code of {@link #RESULT_INTERNAL_ERROR}, no data and no extras. + * + * @param context The context + * @param action The intent action. + * @param data The intent data (for TraFF, this is the content provider URI), or null + * @param extras The extras for the intent + * @param packageName The package name for the intent recipient, or null to deliver the intent to all matching receivers + * @param receiverPermission A permission which the recipient must hold, or null if not required + * @param resultReceiver A BroadcastReceiver which will receive the result for the intent + */ + /* From traff-consumer-android, by the same author and re-licensed under GPL2 for Navit */ + public static void sendTraffIntent(Context context, String action, Uri data, Bundle extras, String packageName, + String receiverPermission, BroadcastReceiver resultReceiver) { + Intent outIntent = new Intent(action); + PackageManager pm = context.getPackageManager(); + List receivers = pm.queryBroadcastReceivers(outIntent, 0); + if (receivers != null) + for (ResolveInfo receiver : receivers) { + if ((packageName != null) && !packageName.equals(receiver.activityInfo.applicationInfo.packageName)) + continue; + ComponentName cn = new ComponentName(receiver.activityInfo.applicationInfo.packageName, + receiver.activityInfo.name); + outIntent = new Intent(action); + if (data != null) + outIntent.setData(data); + if (extras != null) + outIntent.putExtras(extras); + outIntent.setComponent(cn); + context.sendOrderedBroadcast (outIntent, + receiverPermission, + resultReceiver, + null, // scheduler, + RESULT_INTERNAL_ERROR, // initialCode, + null, // initialData, + null); + } + } } diff --git a/navit/navit.c b/navit/navit.c index 50d639896..d87f1c2ae 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -3685,7 +3685,36 @@ int navit_get_blocked(struct navit *this_) { void navit_destroy(struct navit *this_) { dbg(lvl_debug,"enter %p",this_); + GList *mapsets; + struct map * map; + struct attr attr; graphics_draw_cancel(this_->gra, this_->displaylist); + + mapsets = this_->mapsets; + while (mapsets) { + GList *maps = NULL; + struct mapset_handle *msh; + msh = mapset_open(mapsets->data); + while (msh && (map = mapset_next(msh, 0))) { + /* Add traffic map (identified by the `attr_traffic` attribute) to list of maps to remove */ + if (map_get_attr(map, attr_traffic, &attr, NULL)) + maps = g_list_append(maps, map); + } + mapset_close(msh); + + /* Remove traffic maps, if any */ + while (maps) { + attr.type = attr_map; + attr.u.map = maps->data; + mapset_remove_attr(this_->mapsets, &attr); + attr_free_content(&attr); + maps = g_list_next(maps); + } + if (maps) + g_list_free(maps); + mapsets = g_list_next(mapsets); + } + callback_list_call_attr_1(this_->attr_cbl, attr_destroy, this_); attr_list_free(this_->attrs); diff --git a/navit/traffic.c b/navit/traffic.c index 9705abbdd..9cf22a371 100644 --- a/navit/traffic.c +++ b/navit/traffic.c @@ -4626,7 +4626,6 @@ static struct traffic * traffic_new(struct attr *parent, struct attr **attrs) { navit_object_destroy((struct navit_object *) this_); return NULL; } - navit_object_ref((struct navit_object *) this_); dbg(lvl_debug,"return %p", this_); // TODO do this once and cycle through all plugins @@ -5800,7 +5799,6 @@ struct map * traffic_get_map(struct traffic *this_) { attrs[4] = NULL; this_->shared->map = map_new(NULL, attrs); - navit_object_ref((struct navit_object *) this_->shared->map); /* populate map with previously stored messages */ filename = g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/traffic.xml", NULL); @@ -5938,6 +5936,13 @@ void traffic_set_route(struct traffic *this_, struct route *rt) { this_->shared->rt = rt; } +void traffic_destroy(struct traffic *this_) { + if (this_->meth.destroy) + this_->meth.destroy(this_->priv); + attr_list_free(this_->attrs); + g_free(this_); +} + struct object_func traffic_func = { attr_traffic, (object_func_new)traffic_new, @@ -5948,7 +5953,7 @@ struct object_func traffic_func = { (object_func_add_attr)navit_object_add_attr, (object_func_remove_attr)navit_object_remove_attr, (object_func_init)NULL, - (object_func_destroy)navit_object_destroy, + (object_func_destroy)traffic_destroy, (object_func_dup)NULL, (object_func_ref)navit_object_ref, (object_func_unref)navit_object_unref, diff --git a/navit/traffic.h b/navit/traffic.h index bf0ca907e..126cbb164 100644 --- a/navit/traffic.h +++ b/navit/traffic.h @@ -239,6 +239,7 @@ struct traffic_message_priv; */ struct traffic_methods { struct traffic_message **(* get_messages)(struct traffic_priv * this_); /**< Retrieves new messages from the traffic plugin */ + void (*destroy)(struct traffic_priv * this_); /**< Destructor for the traffic plugin */ }; /** @@ -989,6 +990,11 @@ void traffic_set_mapset(struct traffic *this_, struct mapset *ms); */ void traffic_set_route(struct traffic *this_, struct route *rt); +/** + * @brief Destructor. + */ +void traffic_destroy(struct traffic *this_); + /* end of prototypes */ #ifdef __cplusplus } diff --git a/navit/traffic/dummy/traffic_dummy.c b/navit/traffic/dummy/traffic_dummy.c index b838752dc..2ab4073d4 100644 --- a/navit/traffic/dummy/traffic_dummy.c +++ b/navit/traffic/dummy/traffic_dummy.c @@ -154,6 +154,7 @@ struct traffic_message ** traffic_dummy_get_messages(struct traffic_priv * this_ */ static struct traffic_methods traffic_dummy_meth = { traffic_dummy_get_messages, + NULL, }; /** diff --git a/navit/traffic/null/traffic_null.c b/navit/traffic/null/traffic_null.c index 94546a666..02fc461c6 100644 --- a/navit/traffic/null/traffic_null.c +++ b/navit/traffic/null/traffic_null.c @@ -65,6 +65,7 @@ struct traffic_message ** traffic_null_get_messages(struct traffic_priv * this_) */ static struct traffic_methods traffic_null_meth = { traffic_null_get_messages, + NULL, }; /** diff --git a/navit/traffic/traff_android/traffic_traff_android.c b/navit/traffic/traff_android/traffic_traff_android.c index 266f51a0c..788dd3708 100644 --- a/navit/traffic/traff_android/traffic_traff_android.c +++ b/navit/traffic/traff_android/traffic_traff_android.c @@ -54,8 +54,23 @@ struct traffic_priv { jobject NavitTraff; /**< An instance of `NavitTraff` */ }; +void traffic_traff_android_destroy(struct traffic_priv * this_); struct traffic_message ** traffic_traff_android_get_messages(struct traffic_priv * this_); +/** + * @brief Destructor. + */ +void traffic_traff_android_destroy(struct traffic_priv * this_) { + jmethodID cid; + + cid = (*jnienv)->GetMethodID(jnienv, this_->NavitTraffClass, "close", "()V"); + if (cid == NULL) { + dbg(lvl_error,"no method found"); + return; /* exception thrown */ + } + (*jnienv)->CallVoidMethod(jnienv, this_->NavitTraff, cid); +} + /** * @brief Returns an empty traffic report. * @@ -70,6 +85,7 @@ struct traffic_message ** traffic_traff_android_get_messages(struct traffic_priv */ static struct traffic_methods traffic_traff_android_meth = { traffic_traff_android_get_messages, + traffic_traff_android_destroy, }; diff --git a/navit/xmlconfig.h b/navit/xmlconfig.h index d5697d53c..bcd0ceec9 100644 --- a/navit/xmlconfig.h +++ b/navit/xmlconfig.h @@ -116,7 +116,7 @@ extern struct object_func map_func, mapset_func, navit_func, osd_func, tracking_ layout_func, roadprofile_func, vehicleprofile_func, layer_func, config_func, profile_option_func, script_func, log_func, speech_func, navigation_func, route_func, traffic_func; -#define HAS_OBJECT_FUNC(x) ((x) == attr_map || (x) == attr_mapset || (x) == attr_navit || (x) == attr_osd || (x) == attr_trackingo || (x) == attr_vehicle || (x) == attr_maps || (x) == attr_layout || (x) == attr_roadprofile || (x) == attr_vehicleprofile || (x) == attr_layer || (x) == attr_config || (x) == attr_profile_option || (x) == attr_script || (x) == attr_log || (x) == attr_speech || (x) == attr_navigation || (x) == attr_route) +#define HAS_OBJECT_FUNC(x) ((x) == attr_map || (x) == attr_mapset || (x) == attr_navit || (x) == attr_osd || (x) == attr_trackingo || (x) == attr_vehicle || (x) == attr_maps || (x) == attr_layout || (x) == attr_roadprofile || (x) == attr_vehicleprofile || (x) == attr_layer || (x) == attr_config || (x) == attr_profile_option || (x) == attr_script || (x) == attr_log || (x) == attr_speech || (x) == attr_navigation || (x) == attr_route || (x) == attr_traffic) #define NAVIT_OBJECT struct object_func *func; int refcount; struct attr **attrs; struct navit_object { -- cgit v1.2.1 From b942644f19e06a92e955c59206937ae5d541f1d0 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Fri, 7 Aug 2020 22:21:39 +0200 Subject: Fix:core:set destination before firing callbacks Signed-off-by: mvglasow --- navit/navit.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/navit/navit.c b/navit/navit.c index d87f1c2ae..9cc265b94 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -1613,8 +1613,6 @@ void navit_set_destination(struct navit *this_, struct pcoord *c, const char *de } g_free(destination_file); - callback_list_call_attr_0(this_->attr_cbl, attr_destination); - if (this_->route) { struct attr attr; int dstcount; @@ -1637,10 +1635,12 @@ void navit_set_destination(struct navit *this_, struct pcoord *c, const char *de g_free(pc); g_free(destination_file); } - - if (this_->ready == 3 && !(this_->flags & 4)) - navit_draw(this_); } + + callback_list_call_attr_0(this_->attr_cbl, attr_destination); + + if (this_->route && this_->ready == 3 && !(this_->flags & 4)) + navit_draw(this_); } /** @@ -1683,13 +1683,12 @@ void navit_set_destinations(struct navit *this_, struct pcoord *c, int count, co g_free(destination_file); } else this_->destination_valid=0; - callback_list_call_attr_0(this_->attr_cbl, attr_destination); - if (this_->route) { + if (this_->route) route_set_destinations(this_->route, c, count, async); - if (this_->ready == 3) - navit_draw(this_); - } + callback_list_call_attr_0(this_->attr_cbl, attr_destination); + if (this_->route && this_->ready == 3) + navit_draw(this_); } int navit_get_destinations(struct navit *this_, struct pcoord *pc, int count) { -- cgit v1.2.1 From 4a14ba5320f3d13abdb29d7b4402bb4af1635a49 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Fri, 7 Aug 2020 22:35:57 +0200 Subject: Refactor:core:Add documentation Signed-off-by: mvglasow --- navit/attr.c | 4 ++++ navit/navit.c | 22 ++++++++++++++++++++++ navit/route.c | 14 ++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/navit/attr.c b/navit/attr.c index 7eff92fb8..ea907b411 100644 --- a/navit/attr.c +++ b/navit/attr.c @@ -681,6 +681,10 @@ attr_generic_prepend_attr(struct attr **attrs, struct attr *attr) { * * If `attrs` does not contain `attr`, this function is a no-op. * + * Attributes are matched based on their `type` and `u.data` members, thus `attr` can be a shallow copy + * of the attribute, and can match multiple attributes in the list. The `attr` argument itself is not + * changed. + * * @param attrs The attribute list * @param attr The attribute to remove from the list * diff --git a/navit/navit.c b/navit/navit.c index 9cc265b94..709bcb58a 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -1691,6 +1691,22 @@ void navit_set_destinations(struct navit *this_, struct pcoord *c, int count, co navit_draw(this_); } +/** + * @brief Retrieves destinations from the route + * + * Prior to calling this method, you may want to retrieve the number of destinations by calling + * {@link navit_get_destination_count(struct navit *)} and assigning a buffer of sufficient capacity. + * + * If the return value equals `count`, the buffer was either just large enough or too small to hold the + * entire list of destinations; there is no way to tell from the result which is the case. + * + * If the Navit instance does not have a route, the result is 0. + * + * @param this_ The Navit instance + * @param pc Pointer to an array of projected coordinates which will receive the destination coordinates + * @param count Capacity of `pc` + * @return The number of destinations stored in `pc`, never greater than `count` + */ int navit_get_destinations(struct navit *this_, struct pcoord *pc, int count) { if(!this_->route) return 0; @@ -1698,6 +1714,12 @@ int navit_get_destinations(struct navit *this_, struct pcoord *pc, int count) { } +/** + * @brief Get the destinations count for the route + * + * @param this The Navit instance + * @return destination count for the route, or 0 if the Navit instance has no route + */ int navit_get_destination_count(struct navit *this_) { if(!this_->route) return 0; diff --git a/navit/route.c b/navit/route.c index 652ae6d54..e0358db66 100644 --- a/navit/route.c +++ b/navit/route.c @@ -1129,6 +1129,20 @@ void route_set_destinations(struct route *this, struct pcoord *dst, int count, i profile(0,"end"); } +/** + * @brief Retrieves destinations from the route + * + * Prior to calling this method, you may want to retrieve the number of destinations by calling + * {@link route_get_destination_count(struct route *)} and assigning a buffer of sufficient capacity. + * + * If the return value equals `count`, the buffer was either just large enough or too small to hold the + * entire list of destinations; there is no way to tell from the result which is the case. + * + * @param this The route instance + * @param pc Pointer to an array of projected coordinates which will receive the destination coordinates + * @param count Capacity of `pc` + * @return The number of destinations stored in `pc`, never greater than `count` + */ int route_get_destinations(struct route *this, struct pcoord *pc, int count) { int ret=0; GList *l=this->destinations; -- cgit v1.2.1 From 131acbffd9025c8579e12b2a46d9467a15ee1e0b Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 11 Aug 2020 19:30:55 +0200 Subject: Add:traffic:Complete TraFF 0.8 subscription suport Signed-off-by: mvglasow --- .../src/org/navitproject/navit/NavitTraff.java | 49 +++++-- navit/route.c | 2 +- navit/route_protected.h | 1 + navit/traffic.h | 18 +++ .../traffic/traff_android/traffic_traff_android.c | 162 ++++++++++++++++++++- 5 files changed, 217 insertions(+), 15 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 8ef738724..7ce8d51f4 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -116,14 +116,13 @@ public class NavitTraff extends BroadcastReceiver { this.context.registerReceiver(this, traffFilter07); this.context.registerReceiver(this, traffFilter08); - /* Broadcast a poll intent */ + /* Broadcast a poll intent to all TraFF 0.7-only receivers */ Intent outIntent = new Intent(ACTION_TRAFF_POLL); PackageManager pm = this.context.getPackageManager(); List receivers07 = pm.queryBroadcastReceivers(outIntent, 0); - /* receivers with TraFF 0.8 support */ List receivers08 = pm.queryBroadcastReceivers(new Intent(ACTION_TRAFF_GET_CAPABILITIES), 0); if (receivers07 != null) { - /* get receivers which support only TraFF 0.7 */ + /* get receivers which support only TraFF 0.7 and poll them */ if (receivers08 != null) receivers07.removeAll(receivers08); for (ResolveInfo receiver : receivers07) { @@ -134,16 +133,6 @@ public class NavitTraff extends BroadcastReceiver { this.context.sendBroadcast(outIntent, Manifest.permission.ACCESS_COARSE_LOCATION); } } - if (receivers08 != null) { - for (ResolveInfo receiver : receivers08) { - Bundle extras = new Bundle(); - extras.putString(EXTRA_PACKAGE, context.getPackageName()); - extras.putString(EXTRA_FILTER_LIST, ""); - sendTraffIntent(context, ACTION_TRAFF_SUBSCRIBE, null, extras, - receiver.activityInfo.applicationInfo.packageName, - Manifest.permission.ACCESS_COARSE_LOCATION, this); - } - } } void close() { @@ -156,6 +145,40 @@ public class NavitTraff extends BroadcastReceiver { this.context.unregisterReceiver(this); } + void onFilterUpdate(String filterList) { + /* change existing subscriptions */ + for (Map.Entry entry : subscriptions.entrySet()) { + Bundle extras = new Bundle(); + extras.putString(EXTRA_SUBSCRIPTION_ID, entry.getKey()); + extras.putString(EXTRA_FILTER_LIST, filterList); + sendTraffIntent(context, ACTION_TRAFF_SUBSCRIPTION_CHANGE, null, extras, + entry.getValue(), + Manifest.permission.ACCESS_COARSE_LOCATION, this); + } + + /* set up missing subscriptions */ + PackageManager pm = this.context.getPackageManager(); + List receivers = pm.queryBroadcastReceivers(new Intent(ACTION_TRAFF_GET_CAPABILITIES), 0); + if (receivers != null) { + /* filter out receivers to which we are already subscribed */ + Iterator iter = receivers.iterator(); + while (iter.hasNext()) { + ResolveInfo receiver = iter.next(); + if (subscriptions.containsValue(receiver.activityInfo.applicationInfo.packageName)) + iter.remove(); + } + + for (ResolveInfo receiver : receivers) { + Bundle extras = new Bundle(); + extras.putString(EXTRA_PACKAGE, context.getPackageName()); + extras.putString(EXTRA_FILTER_LIST, filterList); + sendTraffIntent(context, ACTION_TRAFF_SUBSCRIBE, null, extras, + receiver.activityInfo.applicationInfo.packageName, + Manifest.permission.ACCESS_COARSE_LOCATION, this); + } + } + } + @Override public void onReceive(Context context, Intent intent) { if (intent != null) { diff --git a/navit/route.c b/navit/route.c index e0358db66..5162c08be 100644 --- a/navit/route.c +++ b/navit/route.c @@ -1062,7 +1062,7 @@ struct map_selection * route_get_selection(struct route * this_) { * * @param sel Start of the list to be destroyed */ -static void route_free_selection(struct map_selection *sel) { +void route_free_selection(struct map_selection *sel) { struct map_selection *next; while (sel) { next=sel->next; diff --git a/navit/route_protected.h b/navit/route_protected.h index 586fde91d..3ce6c4663 100644 --- a/navit/route_protected.h +++ b/navit/route_protected.h @@ -160,6 +160,7 @@ struct route_graph { /* prototypes */ struct route_graph * route_get_graph(struct route *this_); struct map_selection * route_get_selection(struct route * this_); +void route_free_selection(struct map_selection *sel); void route_add_traffic_distortion(struct route *this_, struct item *item); void route_remove_traffic_distortion(struct route *this_, struct item *item); void route_change_traffic_distortion(struct route *this_, struct item *item); diff --git a/navit/traffic.h b/navit/traffic.h index 126cbb164..f695ad156 100644 --- a/navit/traffic.h +++ b/navit/traffic.h @@ -57,6 +57,24 @@ extern "C" { #endif +/** + * @brief Translates a Navit tile order to a minimum road class as used in TraFF. + * + * This can be used to translate a map selection into a TraFF filter. + * + * The tile order is the lowest tile level in which an object of a certain type can be placed (higher numbers + * correspond to lower levels). Currently, 8 is the maximum order for `highway_city`, `highway_land` and + * `street_n_lanes`, equivalent to `MOTORWAY` and `TRUNK`. 10 is the maximum order for `street_4_city` and + * `street_4_land` (`SECONDARY`), 12 for `street_3_city` and `street_3_land` (`TERTIARY`). All others can + * be placed in any tile level. + * + * This macro returns `PRIMARY`, `SECONDARY` and `TERTIARY` for the three bins above these cut-off orders, + * corresponding to one level below the lowest road class we expect to find there. (Not considering that + * low-level roads can be placed into higher-level tiles if they cross a tile boundary of the next lower + * level.) Below the lowest cut-off order, the macro returns NULL. + */ +#define order_to_min_road_class(x) (x <= 8 ? "PRIMARY" : x <= 10 ? "SECONDARY" : x <= 12 ? "TERTIARY" : NULL) + /** * @brief Classes for events. */ diff --git a/navit/traffic/traff_android/traffic_traff_android.c b/navit/traffic/traff_android/traffic_traff_android.c index 788dd3708..991cb36a5 100644 --- a/navit/traffic/traff_android/traffic_traff_android.c +++ b/navit/traffic/traff_android/traffic_traff_android.c @@ -22,7 +22,7 @@ * * @brief The TraFF plugin for Android * - * This plugin receives TraFF feeds via Android broadcasts. + * This plugin receives TraFF feeds via Android broadcasts and content providers. */ #include @@ -36,13 +36,31 @@ #include "item.h" #include "attr.h" #include "coord.h" +#include "map.h" +#include "route_protected.h" +#include "route.h" +#include "transform.h" #include "xmlconfig.h" #include "android.h" #include "traffic.h" #include "plugin.h" #include "callback.h" +#include "vehicle.h" #include "debug.h" #include "navit.h" +#include "util.h" + +/** + * @brief Minimum area around the current position for which to retrieve traffic updates. + * + * 100000 is equivalent to around 50 km on each side of the current position. The actual subscription area + * can be larger, allowing for a subscription area to be kept over multiple position updates. + * + * The actual subscription area around the current location is stored in + * {@link struct traffic_priv::position_rect} and updated in + * {@link traffic_traff_android_position_callback(struct traffic_priv *, struct navit *, struct vehicle *)}. + */ +#define POSITION_RECT_SIZE 100000 /** * @brief Stores information about the plugin instance. @@ -50,6 +68,9 @@ struct traffic_priv { struct navit * nav; /**< The navit instance */ struct callback * cbid; /**< The callback function for TraFF feeds **/ + int position_valid; /**< Whether Navit currently has a valid position */ + struct coord_rect * position_rect; /**< Rectangle around last known vehicle position (in `projection_mg`) */ + struct map_selection * route_map_sel; /**< Map selection for the current route */ jclass NavitTraffClass; /**< The `NavitTraff` class */ jobject NavitTraff; /**< An instance of `NavitTraff` */ }; @@ -69,6 +90,13 @@ void traffic_traff_android_destroy(struct traffic_priv * this_) { return; /* exception thrown */ } (*jnienv)->CallVoidMethod(jnienv, this_->NavitTraff, cid); + + if (this_->position_rect) + g_free(this_->position_rect); + this_->position_rect = NULL; + if (this_->route_map_sel) + route_free_selection(this_->route_map_sel); + this_->route_map_sel = NULL; } /** @@ -124,6 +152,123 @@ static void traffic_traff_android_on_feed_received(struct traffic_priv * this_, } +/** + * @brief Sets the route map selection + * + * @param this_ The instance which will handle the selection update + */ +static void traffic_traff_android_set_selection(struct traffic_priv * this_) { + struct route * route; + struct coord_geo lu, rl; + gchar *filter_list; + jstring j_filter_list; + gchar *min_road_class; + jmethodID cid; + + if (this_->route_map_sel) + route_free_selection(this_->route_map_sel); + this_->route_map_sel = NULL; + if (navit_get_destination_count(this_->nav) && (route = (navit_get_route(this_->nav)))) + this_->route_map_sel = route_get_selection(route); + + /* start building the filter list */ + filter_list = g_strconcat_printf(NULL, "\n"); + if (this_->position_rect) { + transform_to_geo(projection_mg, &this_->position_rect->lu, &lu); + transform_to_geo(projection_mg, &this_->position_rect->rl, &rl); + filter_list = g_strconcat_printf(filter_list, " \n", + rl.lat, lu.lng, lu.lat, rl.lng); + } + for (struct map_selection * sel = this_->route_map_sel; sel; sel = sel->next) { + transform_to_geo(projection_mg, &sel->u.c_rect.lu, &lu); + transform_to_geo(projection_mg, &sel->u.c_rect.rl, &rl); + min_road_class = order_to_min_road_class(sel->order); + if (!min_road_class) + filter_list = g_strconcat_printf(filter_list, " \n", + rl.lat, lu.lng, lu.lat, rl.lng); + else + filter_list = g_strconcat_printf(filter_list, " \n", + min_road_class, rl.lat, lu.lng, lu.lat, rl.lng); + } + /* the trailing \0 is required for NewStringUTF */ + filter_list = g_strconcat_printf(filter_list, "\0"); + j_filter_list = (*jnienv)->NewStringUTF(jnienv, filter_list); + cid = (*jnienv)->GetMethodID(jnienv, this_->NavitTraffClass, "onFilterUpdate", "(Ljava/lang/String;)V"); + if (cid) + (*jnienv)->CallVoidMethod(jnienv, this_->NavitTraff, cid, j_filter_list); + g_free(filter_list); +} + + +/** + * @brief Callback for destination changes + * + * @param this_ The instance which will handle the destination update + */ +static void traffic_traff_android_destination_callback(struct traffic_priv * this_) { + traffic_traff_android_set_selection(this_); +} + + +/** + * @brief Callback for navigation status changes + * + * This callback is necessary to force an update of existing subscriptions when Navit acquires a new + * position (after not having had valid position information), as the map selection will change when + * the current position becomes known for the first time. + * + * @param this_ The instance which will handle the navigation status update + * @param status The status of the navigation engine (the value of the {@code nav_status} attribute) + */ +static void traffic_traff_android_status_callback(struct traffic_priv * this_, int status) { + int new_position_valid = (status != 1); + if (new_position_valid && !this_->position_valid) { + this_->position_valid = new_position_valid; + traffic_traff_android_set_selection(this_); + } else if (new_position_valid != this_->position_valid) + this_->position_valid = new_position_valid; +} + + +/** + * @brief Callback for position changes + * + * This updates {@link struct traffic_priv::position_rect} if the vehicle has moved far enough from its + * center to be within {@link POSITION_RECT_SIZE} of one of its boundaries. The new rectangle is created + * with twice that amount of padding, allowing the vehicle to move for at least that distance before the + * subscription needs to be updated again. + * + * @param this_ The instance which will handle the position update + * @param navit The Navit instance + * @param vehicle The vehicle which delivered the position update and from which the position can be queried + */ +static void traffic_traff_android_position_callback(struct traffic_priv * this_, struct navit *navit, struct vehicle *vehicle) { + struct attr attr; + struct coord c; + struct coord_rect cr; + jmethodID cid; + if (!vehicle_get_attr(vehicle, attr_position_coord_geo, &attr, NULL)) + return; + transform_from_geo(projection_mg, attr.u.coord_geo, &c); + cr.lu = c; + cr.rl = c; + cr.lu.x -= POSITION_RECT_SIZE; + cr.rl.x += POSITION_RECT_SIZE; + cr.lu.y += POSITION_RECT_SIZE; + cr.rl.y -= POSITION_RECT_SIZE; + if (!this_->position_rect) + this_->position_rect = g_new0(struct coord_rect, 1); + if (!coord_rect_contains(this_->position_rect, &cr.lu) || !coord_rect_contains(this_->position_rect, &cr.rl)) { + cr.lu.x -= POSITION_RECT_SIZE; + cr.rl.x += POSITION_RECT_SIZE; + cr.lu.y += POSITION_RECT_SIZE; + cr.rl.y -= POSITION_RECT_SIZE; + *(this_->position_rect) = cr; + traffic_traff_android_set_selection(this_); + } +} + + /** * @brief Initializes a traff_android plugin * @@ -131,6 +276,9 @@ static void traffic_traff_android_on_feed_received(struct traffic_priv * this_, */ static int traffic_traff_android_init(struct traffic_priv * this_) { jmethodID cid; + struct route * route; + struct attr attr; + struct navigation * navigation; if (!android_find_class_global("org/navitproject/navit/NavitTraff", &this_->NavitTraffClass)) return 0; @@ -147,6 +295,15 @@ static int traffic_traff_android_init(struct traffic_priv * this_) { if (this_->NavitTraff) this_->NavitTraff = (*jnienv)->NewGlobalRef(jnienv, this_->NavitTraff); + /* register callbacks for position and destination changes */ + navit_add_callback(this_->nav, callback_new_attr_1(callback_cast(traffic_traff_android_position_callback), + attr_position_coord_geo, this_)); + navit_add_callback(this_->nav, callback_new_attr_1(callback_cast(traffic_traff_android_destination_callback), + attr_destination, this_)); + if ((navigation = navit_get_navigation(this_->nav))) + navigation_register_callback(navigation, attr_nav_status, + callback_new_attr_1(callback_cast(traffic_traff_android_status_callback), attr_nav_status, this_)); + return 1; } @@ -170,6 +327,9 @@ static struct traffic_priv * traffic_traff_android_new(struct navit *nav, struct ret = g_new0(struct traffic_priv, 1); ret->nav = nav; ret->cbid = callback_new_1(callback_cast(traffic_traff_android_on_feed_received), ret); + ret->position_valid = 0; + ret->position_rect = NULL; + ret->route_map_sel = NULL; /* TODO populate members, if any */ *meth = traffic_traff_android_meth; -- cgit v1.2.1 From 0a17ef1898eb7cd865350c9986661cc194237a6c Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 11 Aug 2020 19:32:32 +0200 Subject: Refactor:core:Add documentation Signed-off-by: mvglasow --- navit/route.c | 11 +++++++++++ navit/util.c | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/navit/route.c b/navit/route.c index 5162c08be..fa62ce2d7 100644 --- a/navit/route.c +++ b/navit/route.c @@ -939,6 +939,17 @@ struct map_selection *route_selection; /** * @brief Returns a single map selection + * + * The boundaries of the selection are determined as follows: First a rectangle spanning `c1` and `c2` is + * built (the two coordinates can be any two opposite corners of the rectangle). Then its maximum extension + * (height or width) is determined and multiplied with the percentage specified by `rel`. The resulting + * amount of padding is added to each edge. After that, the amount specified by `abs` is added to each edge. + * + * @param order Map order (deepest tile level) to select + * @param c1 First coordinate + * @param c2 Second coordinate + * @param rel Relative padding to add to the selection rectangle, in percent + * @param abs Absolute padding to add to the selection rectangle */ struct map_selection * route_rect(int order, struct coord *c1, struct coord *c2, int rel, int abs) { diff --git a/navit/util.c b/navit/util.c index cf4412938..0dfdab20e 100644 --- a/navit/util.c +++ b/navit/util.c @@ -479,6 +479,19 @@ GList *g_hash_to_list_keys(GHashTable *h) { return ret; } +/** + * @brief Appends a formatted string and appends it to an existing one. + * + * Usage is similar to the familiar C functions that take a format string and a variable argument list. + * + * Return value is a concatenation of `buffer` (unless it is NULL) and `fmt`, with the remaining arguments + * inserted into `fmt`. + * + * @param buffer An existing string, can be null and will be freed by this function + * @param fmt A format string (will not be altered) + * + * @return A newly allocated string, see description. The caller is responsible for freeing the returned string. + */ gchar *g_strconcat_printf(gchar *buffer, gchar *fmt, ...) { gchar *str,*ret; va_list ap; -- cgit v1.2.1 From 7d0ecff1676788d7e30875f0f8936b95eeb470a8 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 11 Aug 2020 21:34:16 +0200 Subject: Refactor:traffic:Make sanity check happy Signed-off-by: mvglasow --- navit/android/src/org/navitproject/navit/NavitTraff.java | 14 +++++++------- navit/traffic/traff_android/traffic_traff_android.c | 15 ++++++++------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 7ce8d51f4..4591f3a62 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -249,7 +249,7 @@ public class NavitTraff extends BroadcastReceiver { /** * @brief Fetches messages from a content provider. - * + * * @param context * @param uri The content provider URI */ @@ -276,22 +276,22 @@ public class NavitTraff extends BroadcastReceiver { /** * @brief Sends a TraFF intent to a source. - * + * * This encapsulates most of the low-level Android handling. - * + * * If the recipient specified in {@code packageName} declares multiple receivers for the intent in its * manifest, a separate intent will be delivered to each of them. The intent will not be delivered to * receivers registered at runtime. - * + * * All intents are sent as explicit ordered broadcasts. This means two things: - * + * * Any app which declares a matching receiver in its manifest will be woken up to process the intent. * This works even with certain Android 7 builds which restrict intent delivery to apps which are not * currently running. - * + * * It is safe for the recipient to unconditionally set result data. If the recipient does not set result * data, the result will have a result code of {@link #RESULT_INTERNAL_ERROR}, no data and no extras. - * + * * @param context The context * @param action The intent action. * @param data The intent data (for TraFF, this is the content provider URI), or null diff --git a/navit/traffic/traff_android/traffic_traff_android.c b/navit/traffic/traff_android/traffic_traff_android.c index 991cb36a5..e0862ec5c 100644 --- a/navit/traffic/traff_android/traffic_traff_android.c +++ b/navit/traffic/traff_android/traffic_traff_android.c @@ -177,7 +177,7 @@ static void traffic_traff_android_set_selection(struct traffic_priv * this_) { transform_to_geo(projection_mg, &this_->position_rect->lu, &lu); transform_to_geo(projection_mg, &this_->position_rect->rl, &rl); filter_list = g_strconcat_printf(filter_list, " \n", - rl.lat, lu.lng, lu.lat, rl.lng); + rl.lat, lu.lng, lu.lat, rl.lng); } for (struct map_selection * sel = this_->route_map_sel; sel; sel = sel->next) { transform_to_geo(projection_mg, &sel->u.c_rect.lu, &lu); @@ -185,10 +185,10 @@ static void traffic_traff_android_set_selection(struct traffic_priv * this_) { min_road_class = order_to_min_road_class(sel->order); if (!min_road_class) filter_list = g_strconcat_printf(filter_list, " \n", - rl.lat, lu.lng, lu.lat, rl.lng); + rl.lat, lu.lng, lu.lat, rl.lng); else filter_list = g_strconcat_printf(filter_list, " \n", - min_road_class, rl.lat, lu.lng, lu.lat, rl.lng); + min_road_class, rl.lat, lu.lng, lu.lat, rl.lng); } /* the trailing \0 is required for NewStringUTF */ filter_list = g_strconcat_printf(filter_list, "\0"); @@ -242,7 +242,8 @@ static void traffic_traff_android_status_callback(struct traffic_priv * this_, i * @param navit The Navit instance * @param vehicle The vehicle which delivered the position update and from which the position can be queried */ -static void traffic_traff_android_position_callback(struct traffic_priv * this_, struct navit *navit, struct vehicle *vehicle) { +static void traffic_traff_android_position_callback(struct traffic_priv * this_, struct navit *navit, + struct vehicle *vehicle) { struct attr attr; struct coord c; struct coord_rect cr; @@ -297,12 +298,12 @@ static int traffic_traff_android_init(struct traffic_priv * this_) { /* register callbacks for position and destination changes */ navit_add_callback(this_->nav, callback_new_attr_1(callback_cast(traffic_traff_android_position_callback), - attr_position_coord_geo, this_)); + attr_position_coord_geo, this_)); navit_add_callback(this_->nav, callback_new_attr_1(callback_cast(traffic_traff_android_destination_callback), - attr_destination, this_)); + attr_destination, this_)); if ((navigation = navit_get_navigation(this_->nav))) navigation_register_callback(navigation, attr_nav_status, - callback_new_attr_1(callback_cast(traffic_traff_android_status_callback), attr_nav_status, this_)); + callback_new_attr_1(callback_cast(traffic_traff_android_status_callback), attr_nav_status, this_)); return 1; } -- cgit v1.2.1 From 2a86c6e1115490dac5a5235946fd16f385600126 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 11 Aug 2020 22:43:24 +0200 Subject: Refactor:traffic/traff_android:More sanity check fixes Signed-off-by: mvglasow --- navit/android/src/org/navitproject/navit/NavitTraff.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 4591f3a62..495209bec 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -72,7 +72,7 @@ public class NavitTraff extends BroadcastReceiver { private final Context context; - /** Active subscriptions (key is the subscription ID, value is the package ID) */ + /** Active subscriptions (key is the subscription ID, value is the package ID). */ private Map subscriptions = new HashMap(); /** @@ -250,7 +250,7 @@ public class NavitTraff extends BroadcastReceiver { /** * @brief Fetches messages from a content provider. * - * @param context + * @param context The context to use for the content resolver * @param uri The content provider URI */ private void fetchMessages(Context context, Uri uri) { @@ -296,7 +296,7 @@ public class NavitTraff extends BroadcastReceiver { * @param action The intent action. * @param data The intent data (for TraFF, this is the content provider URI), or null * @param extras The extras for the intent - * @param packageName The package name for the intent recipient, or null to deliver the intent to all matching receivers + * @param packageName The package name for the recipient, or null to deliver the intent to all matching receivers * @param receiverPermission A permission which the recipient must hold, or null if not required * @param resultReceiver A BroadcastReceiver which will receive the result for the intent */ @@ -318,7 +318,7 @@ public class NavitTraff extends BroadcastReceiver { if (extras != null) outIntent.putExtras(extras); outIntent.setComponent(cn); - context.sendOrderedBroadcast (outIntent, + context.sendOrderedBroadcast(outIntent, receiverPermission, resultReceiver, null, // scheduler, -- cgit v1.2.1 From 507944a6f1aae92ce9ad697cc3949cfeb468b5f9 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 11 Aug 2020 23:18:51 +0200 Subject: Refactor:traffic/traff_android:Fix Javadoc formatting Signed-off-by: mvglasow --- navit/android/src/org/navitproject/navit/NavitTraff.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 495209bec..9292cd408 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -248,7 +248,7 @@ public class NavitTraff extends BroadcastReceiver { } /** - * @brief Fetches messages from a content provider. + * Fetches messages from a content provider. * * @param context The context to use for the content resolver * @param uri The content provider URI @@ -275,20 +275,18 @@ public class NavitTraff extends BroadcastReceiver { } /** - * @brief Sends a TraFF intent to a source. - * - * This encapsulates most of the low-level Android handling. - * + * Sends a TraFF intent to a source. This encapsulates most of the low-level Android handling. + *

* If the recipient specified in {@code packageName} declares multiple receivers for the intent in its * manifest, a separate intent will be delivered to each of them. The intent will not be delivered to * receivers registered at runtime. - * + *

* All intents are sent as explicit ordered broadcasts. This means two things: - * + *

* Any app which declares a matching receiver in its manifest will be woken up to process the intent. * This works even with certain Android 7 builds which restrict intent delivery to apps which are not * currently running. - * + *

* It is safe for the recipient to unconditionally set result data. If the recipient does not set result * data, the result will have a result code of {@link #RESULT_INTERNAL_ERROR}, no data and no extras. * -- cgit v1.2.1 From 55e029700cf7860e8a1f4cfed894f096b9ba9c38 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 11 Aug 2020 23:22:08 +0200 Subject: Refactor:traffic/traff_android:Fix checkstyle issues Signed-off-by: mvglasow --- navit/android/src/org/navitproject/navit/NavitTraff.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 9292cd408..23c07354d 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -276,18 +276,18 @@ public class NavitTraff extends BroadcastReceiver { /** * Sends a TraFF intent to a source. This encapsulates most of the low-level Android handling. - *

- * If the recipient specified in {@code packageName} declares multiple receivers for the intent in its + * + *

If the recipient specified in {@code packageName} declares multiple receivers for the intent in its * manifest, a separate intent will be delivered to each of them. The intent will not be delivered to * receivers registered at runtime. - *

- * All intents are sent as explicit ordered broadcasts. This means two things: - *

- * Any app which declares a matching receiver in its manifest will be woken up to process the intent. + * + *

All intents are sent as explicit ordered broadcasts. This means two things: + * + *

Any app which declares a matching receiver in its manifest will be woken up to process the intent. * This works even with certain Android 7 builds which restrict intent delivery to apps which are not * currently running. - *

- * It is safe for the recipient to unconditionally set result data. If the recipient does not set result + * + *

It is safe for the recipient to unconditionally set result data. If the recipient does not set result * data, the result will have a result code of {@link #RESULT_INTERNAL_ERROR}, no data and no extras. * * @param context The context -- cgit v1.2.1 From 27d48440d0ee90356759f07cf4205fef0a4c7553 Mon Sep 17 00:00:00 2001 From: jkoan Date: Mon, 10 Aug 2020 10:23:28 +0200 Subject: fix:core:Optimize log message for required vehicle attributes --- navit/track.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/navit/track.c b/navit/track.c index 0bc702b7e..70b89c6fc 100644 --- a/navit/track.c +++ b/navit/track.c @@ -637,10 +637,11 @@ void tracking_update(struct tracking *tr, struct vehicle *v, struct vehicleprofi !vehicle_get_attr(tr->vehicle, attr_position_direction, &direction_attr, NULL) || !vehicle_get_attr(tr->vehicle, attr_position_coord_geo, &coord_geo, NULL) || !vehicle_get_attr(tr->vehicle, attr_position_time_iso8601, &time_attr, NULL)) { - dbg(lvl_error,"failed to get position data %d %d %d", + dbg(lvl_error,"failed to get position data speed:%d direction:%d coord:%d time:%d", vehicle_get_attr(tr->vehicle, attr_position_speed, &speed_attr, NULL), vehicle_get_attr(tr->vehicle, attr_position_direction, &direction_attr, NULL), - vehicle_get_attr(tr->vehicle, attr_position_coord_geo, &coord_geo, NULL)); + vehicle_get_attr(tr->vehicle, attr_position_coord_geo, &coord_geo, NULL), + vehicle_get_attr(tr->vehicle, attr_position_time_iso8601, &time_attr, NULL)); return; } if (tr->tunnel_extrapolation) { -- cgit v1.2.1 From 26594f97de07b91ca9e462262e00485bc0bc6b09 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Thu, 13 Aug 2020 19:09:39 +0200 Subject: Fix:core:Fix invalid pointer which would cause unpredictable crashes Signed-off-by: mvglasow --- navit/navit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/navit/navit.c b/navit/navit.c index 709bcb58a..dc5fb8fdb 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -3727,7 +3727,7 @@ void navit_destroy(struct navit *this_) { while (maps) { attr.type = attr_map; attr.u.map = maps->data; - mapset_remove_attr(this_->mapsets, &attr); + mapset_remove_attr(mapsets->data, &attr); attr_free_content(&attr); maps = g_list_next(maps); } -- cgit v1.2.1 From 5c3a9e19ff12f2a40d27d693de6e7e9b682b61ad Mon Sep 17 00:00:00 2001 From: jkoan Date: Mon, 10 Aug 2020 09:55:52 +0200 Subject: fix:vehicle:gpsd:Add Support for Gpsd 3.21 --- navit/vehicle/gpsd/vehicle_gpsd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/navit/vehicle/gpsd/vehicle_gpsd.c b/navit/vehicle/gpsd/vehicle_gpsd.c index ea3aaf1f8..1670812fa 100644 --- a/navit/vehicle/gpsd/vehicle_gpsd.c +++ b/navit/vehicle/gpsd/vehicle_gpsd.c @@ -17,7 +17,6 @@ * Boston, MA 02110-1301, USA. */ -#include #include #include #include @@ -166,7 +165,12 @@ vehicle_gpsd_callback(struct gps_data_t *data, const char *buf, size_t len, data->set &= ~SATELLITE_SET; } if (data->set & STATUS_SET) { +#if GPSD_API_MAJOR_VERSION >= 10 + priv->status = data->fix.status; +#else priv->status = data->status; +#endif // GPSD_API_MAJOR_VERSION >= 9 + data->set &= ~STATUS_SET; } if (data->set & MODE_SET) { -- cgit v1.2.1 From 1079d4a6d94b5237d35be2dff1107656bc47046a Mon Sep 17 00:00:00 2001 From: barbeque-squared Date: Fri, 21 Aug 2020 16:25:45 +0200 Subject: fix:graphics/qt5:Add missing include --- navit/graphics/qt5/graphics_qt5.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp index 11f480c0a..e2747ff78 100644 --- a/navit/graphics/qt5/graphics_qt5.cpp +++ b/navit/graphics/qt5/graphics_qt5.cpp @@ -45,6 +45,7 @@ extern "C" { #include #include #include +#include #include #include #include -- cgit v1.2.1 From 21fe6b836e3f2e644103cd97a7a389600958af9b Mon Sep 17 00:00:00 2001 From: barbeque-squared Date: Fri, 21 Aug 2020 16:43:25 +0200 Subject: fix:maptool:Add missing external, fixes #1045 --- navit/maptool/maptool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/navit/maptool/maptool.h b/navit/maptool/maptool.h index 37590e30b..49b13fd92 100644 --- a/navit/maptool/maptool.h +++ b/navit/maptool/maptool.h @@ -406,7 +406,7 @@ int write_aux_tiles(struct zip_info *zip_info); int create_tile_hash(void); void write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out); void merge_tiles(struct tile_info *info); -struct attr map_information_attrs[32]; +extern struct attr map_information_attrs[32]; void index_init(struct zip_info *info, int version); void index_submap_add(struct tile_info *info, struct tile_head *th); -- cgit v1.2.1 From 6e256078cae4073f107d88baf617e1672727f5d5 Mon Sep 17 00:00:00 2001 From: jkoan Date: Sun, 6 Sep 2020 16:43:11 +0000 Subject: fix:build:Fix Codesigning with newer ndk image versions --- navit/android/build.gradle | 2 +- scripts/setup_publish_keys.sh | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/navit/android/build.gradle b/navit/android/build.gradle index dc19f4f5d..0d5ef7a70 100644 --- a/navit/android/build.gradle +++ b/navit/android/build.gradle @@ -11,7 +11,7 @@ android { storeFile file(System.getenv("KEYSTORE") ?: "/store") keyAlias System.getenv("KEY_ALIAS") storePassword System.getenv("STORE_PASS") - keyPassword System.getenv("KEY_PASS") + keyPassword System.getenv("STORE_PASS") } } defaultConfig { diff --git a/scripts/setup_publish_keys.sh b/scripts/setup_publish_keys.sh index 2b1331d8e..b363d9d32 100755 --- a/scripts/setup_publish_keys.sh +++ b/scripts/setup_publish_keys.sh @@ -7,8 +7,7 @@ if [[ -n $GOOGLE_KEY ]]; then fi if [[ -n $KEY ]]; then wget "https://github.com/navit-gps/infrastructure-blackbox/raw/master/keyrings/keystore.gpg" - openssl aes-256-cbc -d -in keystore.gpg -md md5 -k $KEY > ~/.keystore - keytool -importkeystore -srcstorepass "$STORE_PASS" -deststorepass "$STORE_PASS" -srckeystore ~/.keystore -destkeystore ~/.keystore -deststoretype pkcs12 - keytool -keypasswd -alias $KEY_ALIAS -storepass $STORE_PASS -new $KEY_PASS -keystore ~/.keystore - rm keystore.gpg + openssl aes-256-cbc -d -in keystore.gpg -md md5 -k $KEY > keystore + keytool -importkeystore -srcstorepass "$STORE_PASS" -deststorepass "$STORE_PASS" -srckeystore keystore -destkeystore ~/.keystore -deststoretype pkcs12 + rm keystore.gpg keystore fi -- cgit v1.2.1 From 427fd1b0d2a02bca8f3966d896bc9ab0e3f64f5e Mon Sep 17 00:00:00 2001 From: jkoan Date: Sun, 6 Sep 2020 18:50:47 +0200 Subject: fix:build:Fix usage of inkscape 1.0 commandline usage --- navit/icons/CMakeLists.txt | 2 +- navit/icons/navit_svg2png | 2 +- navit/textures/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/navit/icons/CMakeLists.txt b/navit/icons/CMakeLists.txt index 9817aa25e..548bef441 100644 --- a/navit/icons/CMakeLists.txt +++ b/navit/icons/CMakeLists.txt @@ -30,7 +30,7 @@ macro(convert_to_png IMAGE_INPUT IMAGE_OUTPUT SCALE) else() set(SCALE_ARGS) endif() - set(COMMAND_ARGS --without-gui --export-background-opacity=0 --export-png ${IMAGE_OUTPUT} ${SCALE_ARGS} ${IMAGE_INPUT}) + set(COMMAND_ARGS --export-type=png --export-background-opacity=0 ${SCALE_ARGS} --export-filename=${IMAGE_OUTPUT} ${IMAGE_INPUT}) else() message(FATAL_ERROR "no svg2png converter defined here.") endif() diff --git a/navit/icons/navit_svg2png b/navit/icons/navit_svg2png index 668613a61..32939c7f6 100755 --- a/navit/icons/navit_svg2png +++ b/navit/icons/navit_svg2png @@ -19,7 +19,7 @@ svgtopng() $svgtopng --width=$1 --height=$2 --output $4 $3 ;; *inkscape) - $svgtopng --without-gui --export-width=$1 --export-height=$2 --export-png=$BUILDDIR/$4 $3 + $svgtopng --export-width=$1 --export-height=$2 --export-type=png --export-filename=$4 $3 ;; *convert) $svgtopng -alpha on -background none $3 -resize $1x$2 $4 diff --git a/navit/textures/CMakeLists.txt b/navit/textures/CMakeLists.txt index 5eb1fcf7e..5cd70205f 100644 --- a/navit/textures/CMakeLists.txt +++ b/navit/textures/CMakeLists.txt @@ -30,7 +30,7 @@ macro(convert_to_png TEXTURE_INPUT TEXTURE_OUTPUT SCALE) else() set(SCALE_ARGS) endif() - set(COMMAND_ARGS --without-gui --export-background-opacity=0 --export-png ${TEXTURE_OUTPUT} ${SCALE_ARGS} ${TEXTURE_INPUT}) + set(COMMAND_ARGS --export-type=png --export-background-opacity=0 ${SCALE_ARGS} --export-filename=${TEXTURE_OUTPUT} ${TEXTURE_INPUT}) else() message(FATAL_ERROR "no svg2png converter defined here.") endif() -- cgit v1.2.1 From 903a7e589243d6ce3b920cc7ad9398a5c41d5726 Mon Sep 17 00:00:00 2001 From: jkoan Date: Thu, 20 Aug 2020 15:18:59 +0200 Subject: fix:graphics:win32:Fix build with newer libpng versions. Thx @bignaux fixes #984 --- navit/graphics/win32/graphics_win32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/navit/graphics/win32/graphics_win32.c b/navit/graphics/win32/graphics_win32.c index f4eda15f4..3f20daf2b 100644 --- a/navit/graphics/win32/graphics_win32.c +++ b/navit/graphics/win32/graphics_win32.c @@ -1337,7 +1337,7 @@ static int pngdecode(struct graphics_priv *gr, char *name, struct graphics_image /* expand images to bit-depth 8 (only applicable for grayscale images) */ if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8) - png_set_gray_1_2_4_to_8(png_ptr); + png_set_expand_gray_1_2_4_to_8(png_ptr); /* Expand grayscale to rgb */ if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) -- cgit v1.2.1 From 5b06924daa775955dc3175838ceee52d614d9777 Mon Sep 17 00:00:00 2001 From: jkoan Date: Tue, 13 Oct 2020 15:29:33 +0200 Subject: fix:vehicle:gpsd:minor comment fix --- navit/vehicle/gpsd/vehicle_gpsd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/navit/vehicle/gpsd/vehicle_gpsd.c b/navit/vehicle/gpsd/vehicle_gpsd.c index 1670812fa..f7324d24c 100644 --- a/navit/vehicle/gpsd/vehicle_gpsd.c +++ b/navit/vehicle/gpsd/vehicle_gpsd.c @@ -169,7 +169,7 @@ vehicle_gpsd_callback(struct gps_data_t *data, const char *buf, size_t len, priv->status = data->fix.status; #else priv->status = data->status; -#endif // GPSD_API_MAJOR_VERSION >= 9 +#endif // GPSD_API_MAJOR_VERSION >= 10 data->set &= ~STATUS_SET; } -- cgit v1.2.1 From 2ae30ae50b87bfbd6c84dbded007a613ae332e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20H=C3=B6hn?= Date: Tue, 13 Oct 2020 21:55:58 +0200 Subject: added license information to fix #1048 (#1060) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ändrad: navit/icons/archaeological_site.svg ändrad: navit/icons/cave.svg ändrad: navit/textures/cemetery.svg ändrad: navit/textures/diagonal-stripes-gray.svg ändrad: navit/textures/diagonal-stripes.svg ändrad: navit/textures/quarry.svg ändrad: navit/textures/scrub.svg ändrad: navit/textures/wetland.svg ändrad: navit/textures/wood.svg Co-authored-by: Stefan Wildemann --- navit/icons/archaeological_site.svg | 11 +++++++++++ navit/icons/cave.svg | 11 +++++++++++ navit/textures/cemetery.svg | 11 +++++++++++ navit/textures/diagonal-stripes-gray.svg | 11 +++++++++++ navit/textures/diagonal-stripes.svg | 11 +++++++++++ navit/textures/quarry.svg | 11 +++++++++++ navit/textures/scrub.svg | 11 +++++++++++ navit/textures/wetland.svg | 11 +++++++++++ navit/textures/wood.svg | 11 +++++++++++ 9 files changed, 99 insertions(+) diff --git a/navit/icons/archaeological_site.svg b/navit/icons/archaeological_site.svg index 19fc27283..31cf5c25a 100644 --- a/navit/icons/archaeological_site.svg +++ b/navit/icons/archaeological_site.svg @@ -5,7 +5,18 @@ image/svg+xml + + + + + + diff --git a/navit/icons/cave.svg b/navit/icons/cave.svg index c1a900573..575d38a92 100644 --- a/navit/icons/cave.svg +++ b/navit/icons/cave.svg @@ -22,7 +22,18 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Date: Wed, 14 Oct 2020 12:29:35 +0200 Subject: fix:android:Add possibility to use background position usage --- navit/android/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/navit/android/AndroidManifest.xml b/navit/android/AndroidManifest.xml index 27c7c3359..004ccb707 100644 --- a/navit/android/AndroidManifest.xml +++ b/navit/android/AndroidManifest.xml @@ -8,6 +8,7 @@ + -- cgit v1.2.1 From 3c99117dbbff7929c19232f01a51f80826a03cd2 Mon Sep 17 00:00:00 2001 From: jkoan Date: Fri, 30 Oct 2020 08:40:13 +0100 Subject: fix:build:android:Add extra security check for gradle. Just add the security check as mentioned in https://gitlab.com/fdroid/fdroiddata/-/issues/1843 --- gradle/wrapper/gradle-wrapper.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 25f587d12..7292aa85e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,3 +3,4 @@ distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-all.zip +distributionSha256Sum=33214524e686838c88a88e14e8b30e2323589cc9698186bc8e0594758b132b31 -- cgit v1.2.1 From 6819fe255df971f78e8a011b6374f1e9c7740d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20H=C3=B6hn?= Date: Sat, 31 Oct 2020 13:41:52 +0100 Subject: fix:core:osd:Altitude in metric with imperial defined * cleaned version of the patch by 1096 * fix issue of sanity check --- navit/osd/core/osd_core.c | 57 +++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/navit/osd/core/osd_core.c b/navit/osd/core/osd_core.c index cfbb0655c..40ea4350d 100644 --- a/navit/osd/core/osd_core.c +++ b/navit/osd/core/osd_core.c @@ -8,13 +8,13 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Boston, MA 02110-1301, USA. */ #include "config.h" @@ -450,7 +450,7 @@ static void osd_route_guard_init(struct osd_priv_common *opc, struct navit *nav) while ((map=mapset_next(msh, 1))) { struct attr attr; if(map_get_attr(map, attr_name, &attr, NULL)) { - if( ! strcmp(this->map_name, attr.u.str) ) { + if(!strcmp(this->map_name, attr.u.str) ) { mr=map_rect_new(map, NULL); if (mr) { while ((item=map_rect_get_item(mr))) { @@ -740,7 +740,7 @@ static void draw_aligned_osd_text(char *buffer, int align, struct osd_item *osd_ } while (*last) { - if (! g_ascii_isspace(*last)) { + if (!g_ascii_isspace(*last)) { lines++; break; } @@ -830,7 +830,7 @@ static void osd_odometer_draw(struct osd_priv_common *opc, struct navit *nav, st int secs; int imperial=0; - char buffer [256+1]=""; + char buffer[256+1]=""; char buffer2[256+1]=""; if(nav) { @@ -903,7 +903,7 @@ static void osd_odometer_draw(struct osd_priv_common *opc, struct navit *nav, st time_buffer = g_strdup_printf("%02d:%02d:%02d",hours,mins,secs); } - buffer [0] = 0; + buffer[0] = 0; buffer2[0] = 0; if(this->text) { str_replace(buffer,this->text,"${avg_spd}",spd_buffer); @@ -2473,11 +2473,11 @@ static void osd_speed_cam_draw(struct osd_priv_common *opc, struct navit *navit, } if(this_->text) { - char buffer [256]=""; + char buffer[256]=""; char buffer2[256]=""; char dir_str[16]; char spd_str[16]; - buffer [0] = 0; + buffer[0] = 0; buffer2[0] = 0; osd_fill_with_bgcolor(&opc->osd_item); @@ -2692,7 +2692,7 @@ static void osd_speed_warner_draw(struct osd_priv_common *opc, struct navit *nav img = this->img_active; } } else { - osd_color = this-> grey; + osd_color = this->grey; img = this->img_off; this->announce_state = eNoWarn; } @@ -2898,6 +2898,19 @@ static char *osd_text_format_attr(struct attr *attr, char *format, int imperial) case attr_position_speed: return format_speed(*attr->u.numd,"",format,imperial); case attr_position_height: + /** + * johnk 8/13/2020 + * if format is "feet" then return feet + * else + * if format is "imperial" + * return meters or feet as controlled by "imperial" + * return meters + */ + if (format && + (!strcmp(format, "feet") || (!strcmp(format, "imperial") && imperial == 1))) { + return (format_float_0(*attr->u.numd * FEET_PER_METER) ); + } + return (format_float_0(*attr->u.numd) ); case attr_position_direction: return format_float_0(*attr->u.numd); case attr_position_magnetic_direction: @@ -2966,7 +2979,7 @@ static char *osd_text_format_attr(struct attr *attr, char *format, int imperial) if (!strcmp(format,"value") || !strcmp(format,"unit")) { char *ret,*tmp=format_distance(attr->u.num," ",imperial); char *pos=strchr(tmp,' '); - if (! pos) + if (!pos) return tmp; *pos++='\0'; if (!strcmp(format,"value")) @@ -2982,7 +2995,7 @@ static char *osd_text_format_attr(struct attr *attr, char *format, int imperial) } else { if (strstr(format, "local;") == format) { textt = iso8601_to_secs(attr->u.str); - memcpy ((void *) &tm, (void *) localtime(&textt), sizeof(tm)); + memcpy((void *) &tm, (void *) localtime(&textt), sizeof(tm)); strftime(buffer, sizeof(buffer), (char *)(format + 6), &tm); } else if ((sscanf(format, "%*c%2d:%2d;", &(text_tm.tm_hour), &(text_tm.tm_min)) == 2) && (strchr("+-", format[0]))) { if (strchr("-", format[0])) { @@ -2990,7 +3003,7 @@ static char *osd_text_format_attr(struct attr *attr, char *format, int imperial) } else { textt = iso8601_to_secs(attr->u.str) + text_tm.tm_hour * 3600 + text_tm.tm_min * 60; } - memcpy ((void *) &tm, (void *) gmtime(&textt), sizeof(tm)); + memcpy((void *) &tm, (void *) gmtime(&textt), sizeof(tm)); strftime(buffer, sizeof(buffer), &format[strcspn(format, ";") + 1], &tm); } else { sscanf(attr->u.str, "%4d-%2d-%2dT%2d:%2d:%2d", &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday), &(tm.tm_hour), &(tm.tm_min), @@ -3214,7 +3227,7 @@ static void osd_text_draw(struct osd_priv_common *opc, struct navit *navit, stru } while (*last) { - if (! g_ascii_isspace(*last)) { + if (!g_ascii_isspace(*last)) { lines++; break; } @@ -3336,7 +3349,7 @@ static void osd_text_prepare(struct osd_priv_common *opc, struct navit *nav) { } end=strstr(start,"}"); - if (! end) + if (!end) break; *end++='\0'; @@ -3525,7 +3538,7 @@ static void osd_gps_status_draw(struct osd_priv_common *opc, struct navit *navit if (gr_image) { p.x = (opc->osd_item.w - gr_image->width) / 2; p.y = (opc->osd_item.h - gr_image->height) / 2; - graphics_draw_image(opc->osd_item.gr, opc->osd_item. graphic_fg, &p, gr_image); + graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_fg, &p, gr_image); graphics_image_free(opc->osd_item.gr, gr_image); } g_free(image); @@ -3611,7 +3624,7 @@ static void osd_volume_draw(struct osd_priv_common *opc, struct navit *navit, st if (gr_image) { p.x = (opc->osd_item.w - gr_image->width) / 2; p.y = (opc->osd_item.h - gr_image->height) / 2; - graphics_draw_image(opc->osd_item.gr, opc->osd_item. graphic_fg, &p, gr_image); + graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_fg, &p, gr_image); graphics_image_free(opc->osd_item.gr, gr_image); } g_free(image); @@ -3643,7 +3656,7 @@ static void osd_volume_init(struct osd_priv_common *opc, struct navit *nav) { struct volume *this = (struct volume *)opc->data; osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc); - navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_volume_click), attr_button, opc)); + navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast(osd_volume_click), attr_button, opc)); osd_volume_draw(opc, nav, NULL); } @@ -3827,7 +3840,7 @@ static struct osd_priv *osd_scale_new(struct navit *nav, struct osd_methods *met osd_set_std_attr(attrs, &opc->osd_item, TRANSPARENT_BG | ITEM_HAS_TEXT); - navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_scale_init), attr_graphics_ready, + navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast(osd_scale_init), attr_graphics_ready, opc)); return (struct osd_priv *) opc; @@ -3891,17 +3904,17 @@ static void osd_auxmap_init(struct osd_priv_common *opc, struct navit *nav) { struct color red= {0xffff,0x0,0x0,0xffff}; this->nav=nav; - if (! navit_get_attr(nav, attr_graphics, &attr, NULL)) + if (!navit_get_attr(nav, attr_graphics, &attr, NULL)) return; gra=attr.u.graphics; graphics_add_callback(gra, callback_new_attr_1(callback_cast(osd_auxmap_draw), attr_postdraw, opc)); - if (! navit_get_attr(nav, attr_transformation, &attr, NULL)) + if (!navit_get_attr(nav, attr_transformation, &attr, NULL)) return; this->ntrans=attr.u.transformation; - if (! navit_get_attr(nav, attr_displaylist, &attr, NULL)) + if (!navit_get_attr(nav, attr_displaylist, &attr, NULL) ) return; this->displaylist=attr.u.displaylist; - if (! navit_get_attr(nav, attr_layout, &attr, NULL)) + if (!navit_get_attr(nav, attr_layout, &attr, NULL)) return; this->layout=attr.u.layout; osd_set_std_graphic(nav, &opc->osd_item, NULL); -- cgit v1.2.1 From 12478f599efa93ae70deeedf0049e261d5d766ec Mon Sep 17 00:00:00 2001 From: jkoan Date: Sun, 25 Oct 2020 17:13:06 +0100 Subject: fix:build:core:Fix two issues where the wrong enum type is used, but both have the same value of 0 --- navit/command.c | 2 +- navit/map/binfile/binfile.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/navit/command.c b/navit/command.c index cc498b1a7..f2c6c0bb0 100644 --- a/navit/command.c +++ b/navit/command.c @@ -158,7 +158,7 @@ static void result_free(struct result *res) { attr_free_content(&res->attr); res->allocated=0; } else { - res->attr.type=type_none; + res->attr.type=attr_none; res->attr.u.data=NULL; } } diff --git a/navit/map/binfile/binfile.c b/navit/map/binfile/binfile.c index 6108154b6..ab65dcaf5 100644 --- a/navit/map/binfile/binfile.c +++ b/navit/map/binfile/binfile.c @@ -565,7 +565,7 @@ static int binfile_attr_get(void *priv_data, enum attr_type attr_type, struct at size_rem-=subsize+1; i++; } - mr->attrs[i].type=type_none; + mr->attrs[i].type=attr_none; mr->attrs[i].u.data=NULL; attr->u.attrs=mr->attrs; } else { -- cgit v1.2.1 From 3ab88d4794003dfce1f340b83e4ccf9f50ba4ef7 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Tue, 3 Nov 2020 14:04:38 -0700 Subject: Fix:plugin/j1850: Replace graphic_fg_white with graphic_fg. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Looks like this was missed in: 46f67d8937cfef6158eeee6e5ed039d29fc1b8f7 Fixes: j1850.c:319:46: error: ‘struct osd_item’ has no member named ‘graphic_fg_white’ Signed-off-by: James Hilliard --- navit/plugin/j1850/j1850.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/navit/plugin/j1850/j1850.c b/navit/plugin/j1850/j1850.c index 69a9b8fa5..bdef8a4fa 100644 --- a/navit/plugin/j1850/j1850.c +++ b/navit/plugin/j1850/j1850.c @@ -316,7 +316,7 @@ static void osd_j1850_init(struct j1850 *this, struct navit *nav) { graphics_gc_set_linewidth(this->white, this->width); - graphics_gc_set_linewidth(this->osd_item.graphic_fg_white, this->width); + graphics_gc_set_linewidth(this->osd_item.graphic_fg, this->width); event_add_timeout(500, 1, callback_new_1(callback_cast(osd_j1850_draw), this)); -- cgit v1.2.1 From b70baf2cb77bb17e7646fb8ad85d25ecc31e427d Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sun, 8 Nov 2020 17:20:15 +0200 Subject: Add:port/android:Adaptive app icon Signed-off-by: mvglasow --- navit/android/AndroidManifest.xml | 2 +- navit/android/AndroidManifest.xml.cmake | 2 +- .../res/drawable-hdpi/ic_launcher_background.png | Bin 0 -> 613 bytes .../res/drawable-hdpi/ic_launcher_foreground.png | Bin 0 -> 3358 bytes .../res/drawable-ldpi/ic_launcher_background.png | Bin 0 -> 377 bytes .../res/drawable-ldpi/ic_launcher_foreground.png | Bin 0 -> 1558 bytes .../res/drawable-mdpi/ic_launcher_background.png | Bin 0 -> 443 bytes .../res/drawable-mdpi/ic_launcher_foreground.png | Bin 0 -> 1976 bytes .../res/drawable-xhdpi/ic_launcher_background.png | Bin 0 -> 771 bytes .../res/drawable-xhdpi/ic_launcher_foreground.png | Bin 0 -> 4582 bytes .../res/drawable-xxhdpi/ic_launcher_background.png | Bin 0 -> 1242 bytes .../res/drawable-xxhdpi/ic_launcher_foreground.png | Bin 0 -> 7210 bytes .../android/res/mipmap-anydpi-v26/ic_launcher.xml | 5 + navit/android/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 4562 bytes navit/android/res/mipmap-ldpi/ic_launcher.png | Bin 0 -> 2092 bytes navit/android/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2868 bytes navit/android/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 6201 bytes navit/android/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 9396 bytes navit/icons/ic_launcher_background.svg | 140 +++++++++++++++++++++ navit/icons/ic_launcher_foreground.svg | 140 +++++++++++++++++++++ 20 files changed, 287 insertions(+), 2 deletions(-) create mode 100644 navit/android/res/drawable-hdpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-hdpi/ic_launcher_foreground.png create mode 100644 navit/android/res/drawable-ldpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-ldpi/ic_launcher_foreground.png create mode 100644 navit/android/res/drawable-mdpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-mdpi/ic_launcher_foreground.png create mode 100644 navit/android/res/drawable-xhdpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-xhdpi/ic_launcher_foreground.png create mode 100644 navit/android/res/drawable-xxhdpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-xxhdpi/ic_launcher_foreground.png create mode 100644 navit/android/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 navit/android/res/mipmap-hdpi/ic_launcher.png create mode 100644 navit/android/res/mipmap-ldpi/ic_launcher.png create mode 100644 navit/android/res/mipmap-mdpi/ic_launcher.png create mode 100644 navit/android/res/mipmap-xhdpi/ic_launcher.png create mode 100644 navit/android/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 navit/icons/ic_launcher_background.svg create mode 100644 navit/icons/ic_launcher_foreground.svg diff --git a/navit/android/AndroidManifest.xml b/navit/android/AndroidManifest.xml index 5978512ed..019b22fa3 100644 --- a/navit/android/AndroidManifest.xml +++ b/navit/android/AndroidManifest.xml @@ -15,7 +15,7 @@ android:usesCleartextTraffic="true" android:allowBackup="true" android:fullBackupContent="@xml/navit_backup_rules" - android:icon="@drawable/icon" + android:icon="@mipmap/ic_launcher" android:name=".NavitAppConfig"> + + + + diff --git a/navit/android/res/mipmap-hdpi/ic_launcher.png b/navit/android/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 000000000..ce18b5780 Binary files /dev/null and b/navit/android/res/mipmap-hdpi/ic_launcher.png differ diff --git a/navit/android/res/mipmap-ldpi/ic_launcher.png b/navit/android/res/mipmap-ldpi/ic_launcher.png new file mode 100644 index 000000000..183e2f829 Binary files /dev/null and b/navit/android/res/mipmap-ldpi/ic_launcher.png differ diff --git a/navit/android/res/mipmap-mdpi/ic_launcher.png b/navit/android/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 000000000..1bde1888e Binary files /dev/null and b/navit/android/res/mipmap-mdpi/ic_launcher.png differ diff --git a/navit/android/res/mipmap-xhdpi/ic_launcher.png b/navit/android/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 000000000..041c61c03 Binary files /dev/null and b/navit/android/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/navit/android/res/mipmap-xxhdpi/ic_launcher.png b/navit/android/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..ad89bd0b5 Binary files /dev/null and b/navit/android/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/navit/icons/ic_launcher_background.svg b/navit/icons/ic_launcher_background.svg new file mode 100644 index 000000000..ab3fe6bd9 --- /dev/null +++ b/navit/icons/ic_launcher_background.svg @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/navit/icons/ic_launcher_foreground.svg b/navit/icons/ic_launcher_foreground.svg new file mode 100644 index 000000000..ef4b12452 --- /dev/null +++ b/navit/icons/ic_launcher_foreground.svg @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + -- cgit v1.2.1 From bd72e1d06c27c2627ae48ce9777bf7aadd42f320 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Mon, 3 Aug 2020 19:53:27 +0200 Subject: Fix:build:Prevent try_compile() from choking on CXX Signed-off-by: mvglasow --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f392e1f92..24be236e4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.2) set(MACOSX_BUNDLE_GUI_IDENTIFIER "org.navitproject.navit") set(MACOSX_BUNDLE_BUNDLE_NAME "Navit") message(STATUS "Building with CMake V${CMAKE_VERSION}") -project(navit C) +project(navit C CXX) # Workaround for CMake issue 8345 / 9220, see http://trac.navit-project.org/ticket/1041 if(DEFINED CMAKE_CXX_COMPILER AND CMAKE_CXX_COMPILER MATCHES "^$") -- cgit v1.2.1 From 805a55515d53aac767b4665c985eb01a4117400b Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sun, 8 Nov 2020 19:42:18 +0200 Subject: Add:port/android:Adaptive app icon Signed-off-by: mvglasow --- navit/android/AndroidManifest.xml | 2 +- .../res/drawable-hdpi/ic_launcher_background.png | Bin 0 -> 613 bytes .../res/drawable-hdpi/ic_launcher_foreground.png | Bin 0 -> 3358 bytes .../res/drawable-ldpi/ic_launcher_background.png | Bin 0 -> 377 bytes .../res/drawable-ldpi/ic_launcher_foreground.png | Bin 0 -> 1558 bytes .../res/drawable-mdpi/ic_launcher_background.png | Bin 0 -> 443 bytes .../res/drawable-mdpi/ic_launcher_foreground.png | Bin 0 -> 1976 bytes .../res/drawable-xhdpi/ic_launcher_background.png | Bin 0 -> 771 bytes .../res/drawable-xhdpi/ic_launcher_foreground.png | Bin 0 -> 4582 bytes .../res/drawable-xxhdpi/ic_launcher_background.png | Bin 0 -> 1242 bytes .../res/drawable-xxhdpi/ic_launcher_foreground.png | Bin 0 -> 7210 bytes .../android/res/mipmap-anydpi-v26/ic_launcher.xml | 5 + navit/android/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 4562 bytes navit/android/res/mipmap-ldpi/ic_launcher.png | Bin 0 -> 2092 bytes navit/android/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2868 bytes navit/android/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 6201 bytes navit/android/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 9396 bytes navit/icons/ic_launcher_background.svg | 140 +++++++++++++++++++++ navit/icons/ic_launcher_foreground.svg | 140 +++++++++++++++++++++ 19 files changed, 286 insertions(+), 1 deletion(-) create mode 100644 navit/android/res/drawable-hdpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-hdpi/ic_launcher_foreground.png create mode 100644 navit/android/res/drawable-ldpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-ldpi/ic_launcher_foreground.png create mode 100644 navit/android/res/drawable-mdpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-mdpi/ic_launcher_foreground.png create mode 100644 navit/android/res/drawable-xhdpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-xhdpi/ic_launcher_foreground.png create mode 100644 navit/android/res/drawable-xxhdpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-xxhdpi/ic_launcher_foreground.png create mode 100644 navit/android/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 navit/android/res/mipmap-hdpi/ic_launcher.png create mode 100644 navit/android/res/mipmap-ldpi/ic_launcher.png create mode 100644 navit/android/res/mipmap-mdpi/ic_launcher.png create mode 100644 navit/android/res/mipmap-xhdpi/ic_launcher.png create mode 100644 navit/android/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 navit/icons/ic_launcher_background.svg create mode 100644 navit/icons/ic_launcher_foreground.svg diff --git a/navit/android/AndroidManifest.xml b/navit/android/AndroidManifest.xml index 004ccb707..b9e646097 100644 --- a/navit/android/AndroidManifest.xml +++ b/navit/android/AndroidManifest.xml @@ -17,7 +17,7 @@ android:usesCleartextTraffic="true" android:allowBackup="true" android:fullBackupContent="@xml/navit_backup_rules" - android:icon="@drawable/icon" + android:icon="@mipmap/ic_launcher" android:name=".NavitAppConfig"> + + + + diff --git a/navit/android/res/mipmap-hdpi/ic_launcher.png b/navit/android/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 000000000..ce18b5780 Binary files /dev/null and b/navit/android/res/mipmap-hdpi/ic_launcher.png differ diff --git a/navit/android/res/mipmap-ldpi/ic_launcher.png b/navit/android/res/mipmap-ldpi/ic_launcher.png new file mode 100644 index 000000000..183e2f829 Binary files /dev/null and b/navit/android/res/mipmap-ldpi/ic_launcher.png differ diff --git a/navit/android/res/mipmap-mdpi/ic_launcher.png b/navit/android/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 000000000..1bde1888e Binary files /dev/null and b/navit/android/res/mipmap-mdpi/ic_launcher.png differ diff --git a/navit/android/res/mipmap-xhdpi/ic_launcher.png b/navit/android/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 000000000..041c61c03 Binary files /dev/null and b/navit/android/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/navit/android/res/mipmap-xxhdpi/ic_launcher.png b/navit/android/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..ad89bd0b5 Binary files /dev/null and b/navit/android/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/navit/icons/ic_launcher_background.svg b/navit/icons/ic_launcher_background.svg new file mode 100644 index 000000000..ab3fe6bd9 --- /dev/null +++ b/navit/icons/ic_launcher_background.svg @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/navit/icons/ic_launcher_foreground.svg b/navit/icons/ic_launcher_foreground.svg new file mode 100644 index 000000000..ef4b12452 --- /dev/null +++ b/navit/icons/ic_launcher_foreground.svg @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + -- cgit v1.2.1 From 310570bacdd06319f6a38246902aedd986ecc8ce Mon Sep 17 00:00:00 2001 From: jkoan Date: Wed, 14 Oct 2020 12:29:35 +0200 Subject: fix:android:Add possibility to use background position usage --- navit/android/src/org/navitproject/navit/Navit.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/Navit.java b/navit/android/src/org/navitproject/navit/Navit.java index bacc15213..a9cad9be5 100644 --- a/navit/android/src/org/navitproject/navit/Navit.java +++ b/navit/android/src/org/navitproject/navit/Navit.java @@ -248,10 +248,15 @@ public class Navit extends Activity { private void verifyPermissions() { if (ContextCompat.checkSelfPermission(this, - Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { + return; + } else if (ContextCompat.checkSelfPermission(this, + Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED) { + return; + } else { Log.d(TAG,"ask for permission(s)"); ActivityCompat.requestPermissions(this, new String[] { - Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQ_FINE_LOC); + Manifest.permission.ACCESS_BACKGROUND_LOCATION}, MY_PERMISSIONS_REQ_FINE_LOC); } } -- cgit v1.2.1 From 6a3c215157ae1fb1ba05744cbf97ac6f0fab3c5c Mon Sep 17 00:00:00 2001 From: jkoan Date: Fri, 14 Aug 2020 21:01:14 +0200 Subject: add:vehicle:Add first Prototype of the geoclue Plugin --- CMakeLists.txt | 8 + navit/vehicle/geoclue/CMakeLists.txt | 2 + navit/vehicle/geoclue/vehicle_geoclue.c | 250 ++++++++++++++++++++++++++++++++ 3 files changed, 260 insertions(+) create mode 100644 navit/vehicle/geoclue/CMakeLists.txt create mode 100644 navit/vehicle/geoclue/vehicle_geoclue.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 24be236e4..fcf82f978 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,7 @@ add_module(graphics/qt5 "Qt5 libraries not found" FALSE) add_module(gui/qml "Qt Declarative not found" FALSE) add_module(gui/qt5_qml "Qt5 Declarative not found" FALSE) add_module(gui/gtk "GTK libs not found" FALSE) +add_module(vehicle/geoclue "geoclue lib not found" FALSE) add_module(vehicle/gpsd "gpsd lib not found" FALSE) add_module(vehicle/gypsy "gypsy lib not found" FALSE) add_module(vehicle/maemo "Default" FALSE) @@ -197,6 +198,13 @@ if(PKG_CONFIG_FOUND) if(IMLIB2_FOUND) set(HAVE_IMLIB2 1) endif(IMLIB2_FOUND) + + # Geoclue + pkg_check_modules ( GeoClue libgeoclue-2.0 ) + if(GeoClue_FOUND) + include_directories(${GeoClue_INCLUDE_DIRS}) + set_with_reason(vehicle/geoclue "libgeoclue found" TRUE ${GeoClue_INCLUDE_DIRS}) + endif(GeoClue_FOUND) else(PKG_CONFIG_FOUND) set_with_reason(support/glib "Glib not found" TRUE ${INTL_LIBS}) endif(PKG_CONFIG_FOUND) diff --git a/navit/vehicle/geoclue/CMakeLists.txt b/navit/vehicle/geoclue/CMakeLists.txt new file mode 100644 index 000000000..2a447ab02 --- /dev/null +++ b/navit/vehicle/geoclue/CMakeLists.txt @@ -0,0 +1,2 @@ +module_add_library(vehicle_geoclue vehicle_geoclue.c) +target_link_libraries(vehicle_geoclue ${GeoClue_LIBRARIES}) diff --git a/navit/vehicle/geoclue/vehicle_geoclue.c b/navit/vehicle/geoclue/vehicle_geoclue.c new file mode 100644 index 000000000..aca3d5a11 --- /dev/null +++ b/navit/vehicle/geoclue/vehicle_geoclue.c @@ -0,0 +1,250 @@ +/* + * Navit, a modular navigation system. + * Copyright 2020 Navit Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include +#include +#include +#include +#include "debug.h" +#include "callback.h" +#include "coord.h" +#include "item.h" +#include "vehicle.h" +#include "plugin.h" + +/** + * @defgroup vehicle-gypsy Vehicle GeoClue + * @ingroup vehicle-plugins + * @brief The Vehicle to gain position data from GeoClue. + * @Author jkoan + * @date 2020 + * + * @{ + */ + + +struct vehicle_priv { + GClueLocation *location; + char *bla; + struct callback_list *cbl; + double speed; + double direction; + double height; + struct coord_geo geo; + int accuracy; + struct tm time; + char* time_str; + char *timep; + GClueSimple *simple; +}; +GClueClient *client = NULL; + +/** + * @brief Free the geoclue_vehicle + * + * @param priv + * @returns nothing + */ +static void vehicle_geoclue_destroy(struct vehicle_priv *priv) { + g_clear_object(&client); + g_clear_object(&priv->simple); +} + +static void +print_location(GClueSimple *simple, + GParamSpec *pspec, + gpointer user_data) +{ + GClueLocation *location; + gdouble altitude; + gdouble speed; + gdouble direction; + GVariant *timestamp; + struct vehicle_priv *priv = user_data; + + location = gclue_simple_get_location(simple); + + priv->geo.lat = gclue_location_get_latitude(location); + priv->geo.lng = gclue_location_get_longitude(location); + priv->accuracy = gclue_location_get_accuracy(location); + altitude = gclue_location_get_altitude(location); + if(altitude != -G_MAXDOUBLE){ + priv->height=altitude; + } + speed = gclue_location_get_altitude(location); + if(speed != -G_MAXDOUBLE){ + priv->speed=speed; + } + direction = gclue_location_get_altitude(location); + if(direction != -G_MAXDOUBLE){ + priv->direction=direction; + } + + timestamp= gclue_location_get_timestamp(location); + if(timestamp) { + GDateTime *date_time; + glong second_since_epoch; + + + g_variant_get (timestamp, "(tt)", &second_since_epoch, NULL); + + date_time = g_date_time_new_from_unix_local (second_since_epoch); + + priv->time_str = g_date_time_format_iso8601(g_date_time_to_utc(date_time)); + + } + callback_list_call_attr_0(priv->cbl, attr_position_coord_geo); +} + +static void +on_client_active_notify(GClueClient *client, + GParamSpec *pspec, + gpointer user_data) +{ + if(gclue_client_get_active(client)) + return; + + g_print("Geolocation disabled. Quitting..\n"); + //vehicle_geoclue_destroy(&user_data); +} + +static void +on_simple_ready(GObject *source_object, + GAsyncResult *res, + gpointer user_data){ + GError *error = NULL; + + struct vehicle_priv* priv = user_data; + + priv->simple = gclue_simple_new_finish(res, &error); + if(error != NULL) { + dbg(lvl_error,"Failed to connect to GeoClue2 service: %s", error->message); + + exit(-1); + } + client = gclue_simple_get_client(priv->simple); + if(client) { + g_object_ref(client); + dbg(lvl_debug,"Client object: %s\n", + g_dbus_proxy_get_object_path(G_DBUS_PROXY(client))); + + g_signal_connect(client, + "notify::active", + G_CALLBACK(on_client_active_notify), + NULL); + } + print_location(priv->simple,NULL,priv); + + g_signal_connect(priv->simple, + "notify::location", + G_CALLBACK(print_location), + priv); +} + +/** + * @brief Provide the outside with information + * + * @param priv + * @param type TODO: What can this be? + * @param attr + * @returns true/false + */ +static int vehicle_geoclue_position_attr_get(struct vehicle_priv *priv, + enum attr_type type, struct attr *attr) { + switch(type) { + case attr_position_height: + attr->u.numd = &priv->height; + break; + case attr_position_speed: + attr->u.numd = &priv->speed; + break; + case attr_position_direction: + attr->u.numd = &priv->direction; + break; + case attr_position_qual: + attr->u.num = priv->accuracy; + break; + /*case attr_position_sats_used: + attr->u.num = priv->sats_used; + break;*/ + case attr_position_coord_geo: + attr->u.coord_geo = &priv->geo; + break; + case attr_position_time_iso8601: + if(!priv->time_str){ + return 0; + } + attr->u.str=priv->time_str; + break; + /* + attr->u.str=priv->time_str; + break;*/ + case attr_active: + return 1; + default: + return 0; + } + attr->type = type; + return 1; +} + +struct vehicle_methods vehicle_geoclue_methods = { + .destroy = vehicle_geoclue_destroy, + .position_attr_get = vehicle_geoclue_position_attr_get, +}; + +/** + * @brief Create geoclue_vehicle + * + * @param meth[out] Methodes supported by geoclue Plugin + * @param cbl[in] Callback List reference + * @param attrs Configuration attributes + * @returns vehicle_priv The newly created Vehicle priv + */ +static struct vehicle_priv *vehicle_geoclue_new(struct vehicle_methods *meth, + struct callback_list *cbl, + struct attr **attrs) { + struct vehicle_priv *ret; + dbg(lvl_debug, "enter"); + + *meth = vehicle_geoclue_methods; + + ret = (struct vehicle_priv*)g_new0(struct vehicle_priv, 1); + ret->cbl = cbl; + ret->time.tm_year=0; + gclue_simple_new("navit", + GCLUE_ACCURACY_LEVEL_EXACT, + NULL, + on_simple_ready, + ret + ); + return ret; +}; + +/** + * @brief register vehicle_geoclue + * + * @returns nothing + */ +void plugin_init(void){ + dbg(lvl_error, "enter"); + plugin_register_category_vehicle("geoclue", vehicle_geoclue_new); +}; + -- cgit v1.2.1 From c5e8008919743d18a595b0a99d3751d376990283 Mon Sep 17 00:00:00 2001 From: jkoan Date: Fri, 14 Aug 2020 21:33:24 +0200 Subject: fix:vehicle:Fix codestyle --- navit/vehicle/geoclue/vehicle_geoclue.c | 187 +++++++++++++++----------------- 1 file changed, 88 insertions(+), 99 deletions(-) diff --git a/navit/vehicle/geoclue/vehicle_geoclue.c b/navit/vehicle/geoclue/vehicle_geoclue.c index aca3d5a11..2220b24bb 100644 --- a/navit/vehicle/geoclue/vehicle_geoclue.c +++ b/navit/vehicle/geoclue/vehicle_geoclue.c @@ -67,95 +67,90 @@ static void vehicle_geoclue_destroy(struct vehicle_priv *priv) { g_clear_object(&priv->simple); } -static void -print_location(GClueSimple *simple, - GParamSpec *pspec, - gpointer user_data) -{ - GClueLocation *location; - gdouble altitude; - gdouble speed; - gdouble direction; - GVariant *timestamp; - struct vehicle_priv *priv = user_data; - - location = gclue_simple_get_location(simple); - - priv->geo.lat = gclue_location_get_latitude(location); - priv->geo.lng = gclue_location_get_longitude(location); - priv->accuracy = gclue_location_get_accuracy(location); - altitude = gclue_location_get_altitude(location); - if(altitude != -G_MAXDOUBLE){ - priv->height=altitude; - } - speed = gclue_location_get_altitude(location); - if(speed != -G_MAXDOUBLE){ - priv->speed=speed; - } - direction = gclue_location_get_altitude(location); - if(direction != -G_MAXDOUBLE){ - priv->direction=direction; - } +static void print_location(GClueSimple *simple, + GParamSpec *pspec, + gpointer user_data) { + GClueLocation *location; + gdouble altitude; + gdouble speed; + gdouble direction; + GVariant *timestamp; + struct vehicle_priv *priv = user_data; + + location = gclue_simple_get_location(simple); + + priv->geo.lat = gclue_location_get_latitude(location); + priv->geo.lng = gclue_location_get_longitude(location); + priv->accuracy = gclue_location_get_accuracy(location); + altitude = gclue_location_get_altitude(location); + if(altitude != -G_MAXDOUBLE) { + priv->height=altitude; + } + speed = gclue_location_get_altitude(location); + if(speed != -G_MAXDOUBLE) { + priv->speed=speed; + } + direction = gclue_location_get_altitude(location); + if(direction != -G_MAXDOUBLE) { + priv->direction=direction; + } - timestamp= gclue_location_get_timestamp(location); - if(timestamp) { - GDateTime *date_time; - glong second_since_epoch; + timestamp= gclue_location_get_timestamp(location); + if(timestamp) { + GDateTime *date_time; + glong second_since_epoch; - g_variant_get (timestamp, "(tt)", &second_since_epoch, NULL); + g_variant_get (timestamp, "(tt)", &second_since_epoch, NULL); - date_time = g_date_time_new_from_unix_local (second_since_epoch); + date_time = g_date_time_new_from_unix_local (second_since_epoch); - priv->time_str = g_date_time_format_iso8601(g_date_time_to_utc(date_time)); + priv->time_str = g_date_time_format_iso8601(g_date_time_to_utc(date_time)); - } - callback_list_call_attr_0(priv->cbl, attr_position_coord_geo); + } + callback_list_call_attr_0(priv->cbl, attr_position_coord_geo); } -static void -on_client_active_notify(GClueClient *client, - GParamSpec *pspec, - gpointer user_data) -{ - if(gclue_client_get_active(client)) - return; +static void on_client_active_notify(GClueClient *client, + GParamSpec *pspec, + gpointer user_data) { + if(gclue_client_get_active(client)) + return; - g_print("Geolocation disabled. Quitting..\n"); - //vehicle_geoclue_destroy(&user_data); + g_print("Geolocation disabled. Quitting..\n"); + //vehicle_geoclue_destroy(&user_data); } -static void -on_simple_ready(GObject *source_object, - GAsyncResult *res, - gpointer user_data){ - GError *error = NULL; +static void on_simple_ready(GObject *source_object, + GAsyncResult *res, + gpointer user_data) { + GError *error = NULL; - struct vehicle_priv* priv = user_data; + struct vehicle_priv* priv = user_data; - priv->simple = gclue_simple_new_finish(res, &error); - if(error != NULL) { - dbg(lvl_error,"Failed to connect to GeoClue2 service: %s", error->message); + priv->simple = gclue_simple_new_finish(res, &error); + if(error != NULL) { + dbg(lvl_error,"Failed to connect to GeoClue2 service: %s", error->message); - exit(-1); - } - client = gclue_simple_get_client(priv->simple); - if(client) { - g_object_ref(client); - dbg(lvl_debug,"Client object: %s\n", - g_dbus_proxy_get_object_path(G_DBUS_PROXY(client))); - - g_signal_connect(client, - "notify::active", - G_CALLBACK(on_client_active_notify), - NULL); - } - print_location(priv->simple,NULL,priv); + exit(-1); + } + client = gclue_simple_get_client(priv->simple); + if(client) { + g_object_ref(client); + dbg(lvl_debug,"Client object: %s\n", + g_dbus_proxy_get_object_path(G_DBUS_PROXY(client))); + + g_signal_connect(client, + "notify::active", + G_CALLBACK(on_client_active_notify), + NULL); + } + print_location(priv->simple,NULL,priv); - g_signal_connect(priv->simple, - "notify::location", - G_CALLBACK(print_location), - priv); + g_signal_connect(priv->simple, + "notify::location", + G_CALLBACK(print_location), + priv); } /** @@ -181,21 +176,15 @@ static int vehicle_geoclue_position_attr_get(struct vehicle_priv *priv, case attr_position_qual: attr->u.num = priv->accuracy; break; - /*case attr_position_sats_used: - attr->u.num = priv->sats_used; - break;*/ case attr_position_coord_geo: attr->u.coord_geo = &priv->geo; break; case attr_position_time_iso8601: - if(!priv->time_str){ + if(!priv->time_str) { return 0; } attr->u.str=priv->time_str; break; - /* - attr->u.str=priv->time_str; - break;*/ case attr_active: return 1; default: @@ -219,23 +208,23 @@ struct vehicle_methods vehicle_geoclue_methods = { * @returns vehicle_priv The newly created Vehicle priv */ static struct vehicle_priv *vehicle_geoclue_new(struct vehicle_methods *meth, - struct callback_list *cbl, - struct attr **attrs) { - struct vehicle_priv *ret; - dbg(lvl_debug, "enter"); - - *meth = vehicle_geoclue_methods; - - ret = (struct vehicle_priv*)g_new0(struct vehicle_priv, 1); - ret->cbl = cbl; - ret->time.tm_year=0; - gclue_simple_new("navit", - GCLUE_ACCURACY_LEVEL_EXACT, - NULL, - on_simple_ready, - ret - ); - return ret; + struct callback_list *cbl, + struct attr **attrs) { + struct vehicle_priv *ret; + dbg(lvl_debug, "enter"); + + *meth = vehicle_geoclue_methods; + + ret = (struct vehicle_priv*)g_new0(struct vehicle_priv, 1); + ret->cbl = cbl; + ret->time.tm_year=0; + gclue_simple_new("navit", + GCLUE_ACCURACY_LEVEL_EXACT, + NULL, + on_simple_ready, + ret + ); + return ret; }; /** @@ -243,7 +232,7 @@ static struct vehicle_priv *vehicle_geoclue_new(struct vehicle_methods *meth, * * @returns nothing */ -void plugin_init(void){ +void plugin_init(void) { dbg(lvl_error, "enter"); plugin_register_category_vehicle("geoclue", vehicle_geoclue_new); }; -- cgit v1.2.1 From bab784a39a5d26827fcc76661eee3738e4b46c0e Mon Sep 17 00:00:00 2001 From: jkoan Date: Sat, 15 Aug 2020 07:15:22 +0200 Subject: fix:vehicle_geoclue:Fix speed and direction and do some cleanup --- navit/vehicle/geoclue/vehicle_geoclue.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/navit/vehicle/geoclue/vehicle_geoclue.c b/navit/vehicle/geoclue/vehicle_geoclue.c index 2220b24bb..6384a1cc3 100644 --- a/navit/vehicle/geoclue/vehicle_geoclue.c +++ b/navit/vehicle/geoclue/vehicle_geoclue.c @@ -49,9 +49,7 @@ struct vehicle_priv { double height; struct coord_geo geo; int accuracy; - struct tm time; char* time_str; - char *timep; GClueSimple *simple; }; GClueClient *client = NULL; @@ -86,11 +84,11 @@ static void print_location(GClueSimple *simple, if(altitude != -G_MAXDOUBLE) { priv->height=altitude; } - speed = gclue_location_get_altitude(location); + speed = gclue_location_get_speed(location); if(speed != -G_MAXDOUBLE) { priv->speed=speed; } - direction = gclue_location_get_altitude(location); + direction = gclue_location_get_heading(location); if(direction != -G_MAXDOUBLE) { priv->direction=direction; } @@ -217,7 +215,6 @@ static struct vehicle_priv *vehicle_geoclue_new(struct vehicle_methods *meth, ret = (struct vehicle_priv*)g_new0(struct vehicle_priv, 1); ret->cbl = cbl; - ret->time.tm_year=0; gclue_simple_new("navit", GCLUE_ACCURACY_LEVEL_EXACT, NULL, -- cgit v1.2.1 From 764c7b920fd38c0261a4fe336175db2c3c2ef750 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sat, 19 Dec 2020 14:49:58 +0200 Subject: Fix:core:Prevent crash if destination is set before acquiring a location Signed-off-by: mvglasow --- navit/route.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/navit/route.c b/navit/route.c index fa62ce2d7..bc6e6815b 100644 --- a/navit/route.c +++ b/navit/route.c @@ -1058,7 +1058,8 @@ struct map_selection * route_get_selection(struct route * this_) { int i = 0; GList *tmp; - c[i++] = this_->pos->c; + if (this_->pos) + c[i++] = this_->pos->c; tmp = this_->destinations; while (tmp) { struct route_info *dst = tmp->data; -- cgit v1.2.1 From 1e5009785d32487d459540f8b8a403bc4e51d261 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sat, 19 Dec 2020 14:50:34 +0200 Subject: Refactor:core:Fix documentation for route_graph_build() Signed-off-by: mvglasow --- navit/route.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/navit/route.c b/navit/route.c index bc6e6815b..e15d0fcf9 100644 --- a/navit/route.c +++ b/navit/route.c @@ -3183,17 +3183,12 @@ static void route_graph_build_idle(struct route_graph *rg, struct vehicleprofile * add any routing information to the route graph - this has to be done via the route_graph_flood() * function. * - * The function does not create a graph covering the whole map, but only covering the rectangle - * between c1 and c2. - * * @param ms The mapset to build the route graph from - * @param c The coordinates of the destination or next waypoint - * @param c1 Corner 1 of the rectangle to use from the map - * @param c2 Corner 2 of the rectangle to use from the map + * @param c An array of coordinates for the current position, waypoints (if any) and destination + * @param count Number of coordinates in `c` * @param done_cb The callback which will be called when graph is complete * @return The new route graph. */ -// FIXME documentation does not match argument list static struct route_graph *route_graph_build(struct mapset *ms, struct coord *c, int count, struct callback *done_cb, int async, struct vehicleprofile *profile) { -- cgit v1.2.1 From d235b2374756a3f34c067b3a1deb564511638052 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sat, 19 Dec 2020 14:49:58 +0200 Subject: Fix:core:Prevent crash if destination is set before acquiring a location Signed-off-by: mvglasow --- navit/route.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/navit/route.c b/navit/route.c index 858e51406..273e50aeb 100644 --- a/navit/route.c +++ b/navit/route.c @@ -1047,7 +1047,8 @@ struct map_selection * route_get_selection(struct route * this_) { int i = 0; GList *tmp; - c[i++] = this_->pos->c; + if (this_->pos) + c[i++] = this_->pos->c; tmp = this_->destinations; while (tmp) { struct route_info *dst = tmp->data; -- cgit v1.2.1 From a1d4b2d311c01d6594a871ede13943da6293fac2 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sat, 19 Dec 2020 14:50:34 +0200 Subject: Refactor:core:Fix documentation for route_graph_build() Signed-off-by: mvglasow --- navit/route.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/navit/route.c b/navit/route.c index 273e50aeb..8e2ef91ec 100644 --- a/navit/route.c +++ b/navit/route.c @@ -3158,17 +3158,12 @@ static void route_graph_build_idle(struct route_graph *rg, struct vehicleprofile * add any routing information to the route graph - this has to be done via the route_graph_flood() * function. * - * The function does not create a graph covering the whole map, but only covering the rectangle - * between c1 and c2. - * * @param ms The mapset to build the route graph from - * @param c The coordinates of the destination or next waypoint - * @param c1 Corner 1 of the rectangle to use from the map - * @param c2 Corner 2 of the rectangle to use from the map + * @param c An array of coordinates for the current position, waypoints (if any) and destination + * @param count Number of coordinates in `c` * @param done_cb The callback which will be called when graph is complete * @return The new route graph. */ -// FIXME documentation does not match argument list static struct route_graph *route_graph_build(struct mapset *ms, struct coord *c, int count, struct callback *done_cb, int async, struct vehicleprofile *profile) { -- cgit v1.2.1 From 38a057375c6842caf7b84715ac0010eacbeb9a0c Mon Sep 17 00:00:00 2001 From: jkoan Date: Sat, 19 Dec 2020 20:28:08 +0100 Subject: add:graphics:svg_debug:Add svg_debugging plugin (#1061) * graphics:svg_debug:Add initial version of svg_debug Some TODOs still remaining, but its working good so far * fiexed:svg_debug:Fixed memory leeks on exit of plugin * fix:graphics:Some final touches for svg_debug * fix:graphics:svg_debug:Reformat to match navit style * fix:graphics:svg_debug:Reformat again to match navit style (Eclipse brakes things... now astyle) * fix:grpahics:svg_debug:Fix C99 for-loop --- CMakeLists.txt | 6 +- navit/attr_def.h | 1 + navit/graphics/svg_debug/CMakeLists.txt | 2 + navit/graphics/svg_debug/graphics_svg_debug.c | 782 ++++++++++++++++++++++++++ navit/navit_shipped.xml | 15 + 5 files changed, 805 insertions(+), 1 deletion(-) create mode 100644 navit/graphics/svg_debug/CMakeLists.txt create mode 100644 navit/graphics/svg_debug/graphics_svg_debug.c diff --git a/CMakeLists.txt b/CMakeLists.txt index fcf82f978..305229c30 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,7 @@ add_module(graphics/sdl "Required library not found" FALSE) add_module(graphics/egl "Required library not found" FALSE) add_module(graphics/qt_qpainter "Qt libraries not found" FALSE) add_module(graphics/qt5 "Qt5 libraries not found" FALSE) +add_module(graphics/svg_debug "native Glib not found" FALSE) add_module(gui/qml "Qt Declarative not found" FALSE) add_module(gui/qt5_qml "Qt5 Declarative not found" FALSE) add_module(gui/gtk "GTK libs not found" FALSE) @@ -325,7 +326,10 @@ if (NOT HAVE_WORDEXP) endif() if (NOT GLIB2_FOUND) set_with_reason(support/ezxml "Glib not found" TRUE) -endif() +else(NOT GLIB2_FOUND) + set_with_reason(graphics/svg_debug "Glib found" TRUE) +endif(NOT GLIB2_FOUND) + if(FREETYPE_FOUND) pkg_check_modules(FRIBIDI fribidi) diff --git a/navit/attr_def.h b/navit/attr_def.h index 45764ebb2..e498a40a8 100644 --- a/navit/attr_def.h +++ b/navit/attr_def.h @@ -404,6 +404,7 @@ ATTR(street_destination) ATTR(exit_to) ATTR(street_destination_forward) ATTR(street_destination_backward) +ATTR(outputdir) ATTR2(0x0003ffff,type_string_end) ATTR2(0x00040000,type_special_begin) ATTR(order) diff --git a/navit/graphics/svg_debug/CMakeLists.txt b/navit/graphics/svg_debug/CMakeLists.txt new file mode 100644 index 000000000..2bc202c1e --- /dev/null +++ b/navit/graphics/svg_debug/CMakeLists.txt @@ -0,0 +1,2 @@ +module_add_library(graphics_svg_debug graphics_svg_debug.c) + diff --git a/navit/graphics/svg_debug/graphics_svg_debug.c b/navit/graphics/svg_debug/graphics_svg_debug.c new file mode 100644 index 000000000..348906ad8 --- /dev/null +++ b/navit/graphics/svg_debug/graphics_svg_debug.c @@ -0,0 +1,782 @@ +/* + * Navit, a modular navigation system. + * Copyright (C) 2020 Navit Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +/** + * This Plugin can act as a Plugin + * + */ +#include "color.h" +#include +#include "config.h" +#ifdef HAVE_UNISTD_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "config.h" +#include "debug.h" +#include "point.h" +#include "graphics.h" + +#include "plugin.h" +#include "window.h" +#include "navit.h" +#include "keys.h" +#include "item.h" +#include "attr.h" +#include "item.h" +#include "attr.h" +#include "point.h" +#include "graphics.h" +#include "color.h" +#include "navit.h" +#include "event.h" +#include "debug.h" +#include "callback.h" +#include "util.h" + +struct graphics_priv { + + unsigned int frame; + int width; + int height; + int fullscreen; + struct color bg_color; + FILE *outfile; + const char *outputdir; + void *proxy_priv; + struct graphics_methods *proxy_graphics_methods; + struct navit *nav; + struct callback_list *cbl; +}; + +struct graphics_font_priv { + int size; + char *font; + struct graphics_font graphics_font_proxy; +}; + +struct graphics_gc_priv { + struct graphics_priv *gr; + unsigned int *dashed; + int is_dashed; + struct color fg; + struct color bg; + int linewidth; + struct graphics_image_priv *img; + struct graphics_gc_priv *graphics_gc_priv_proxy; + struct graphics_gc_methods *graphics_gc_methods_proxy; +}; + +struct graphics_image_priv { + int w, h; + char *data; + struct graphics_image_priv *graphics_image_priv_proxy; + struct graphics_image_methods *graphics_image_methods_proxy; +}; + +static void svg_debug_graphics_destroy(struct graphics_priv *gr) { + // TODO +} + +static void svg_debug_font_destroy(struct graphics_font_priv *this); +void svg_debug_get_text_bbox(struct graphics_priv *gr, + struct graphics_font_priv *font, char *text, int dx, int dy, + struct point *ret, int estimate); + +static struct graphics_font_methods font_methods = { .font_destroy = + svg_debug_font_destroy, +}; + +static void resize_callback_do(struct graphics_priv *gr, int w, int h) { + dbg(lvl_debug, "resize_callback w:%i h:%i", w, h) + gr->width = w; + gr->height = h; +} + +static void svg_debug_font_destroy(struct graphics_font_priv *this) { + dbg(lvl_debug, "enter font_destroy"); + if (this->graphics_font_proxy.meth.font_destroy) { + this->graphics_font_proxy.meth.font_destroy( + this->graphics_font_proxy.priv); + } + g_free(this); +} + +static struct graphics_font_priv* svg_debug_font_new(struct graphics_priv *gr, + struct graphics_font_methods *meth, char *font, int size, int flags) { + struct graphics_font_priv *priv = g_new(struct graphics_font_priv, 1); + + *meth = font_methods; + + priv->size = size / 10; + if (gr->proxy_graphics_methods->font_new) { + priv->graphics_font_proxy.priv = gr->proxy_graphics_methods->font_new( + gr->proxy_priv, &priv->graphics_font_proxy.meth, font, size, + flags); + } else { + return priv; + } + if (priv->graphics_font_proxy.priv) { + return priv; + } + return NULL; +} +void svg_debug_get_text_bbox(struct graphics_priv *gr, + struct graphics_font_priv *font, char *text, int dx, int dy, + struct point *ret, int estimate) { + if (gr->proxy_graphics_methods->get_text_bbox) { + gr->proxy_graphics_methods->get_text_bbox(gr->proxy_priv, + font->graphics_font_proxy.priv, text, dx, dy, ret, estimate); + } +} + +static void svg_debug_gc_destroy(struct graphics_gc_priv *gc) { + if (gc->graphics_gc_methods_proxy->gc_destroy) { + gc->graphics_gc_methods_proxy->gc_destroy(gc->graphics_gc_priv_proxy); + } + g_free(gc->graphics_gc_methods_proxy); + g_free(gc); +} + +static void svg_debug_gc_set_linewidth(struct graphics_gc_priv *gc, int w) { + gc->linewidth = w; + if (gc->graphics_gc_methods_proxy->gc_set_linewidth) { + gc->graphics_gc_methods_proxy->gc_set_linewidth( + gc->graphics_gc_priv_proxy, w); + } + +} + +static void svg_debug_gc_set_dashes(struct graphics_gc_priv *gc, int w, + int offset, unsigned char *dash_list, int n) { + gc->dashed = dash_list; + gc->is_dashed = TRUE; + if (gc->graphics_gc_methods_proxy->gc_set_dashes) { + gc->graphics_gc_methods_proxy->gc_set_dashes(gc->graphics_gc_priv_proxy, + w, offset, dash_list, n); + } +} + +static void svg_debug_gc_set_foreground(struct graphics_gc_priv *gc, + struct color *c) { + gc->fg.r = c->r / 256; + gc->fg.g = c->g / 256; + gc->fg.b = c->b / 256; + gc->fg.a = c->a / 256; + if (gc->graphics_gc_methods_proxy->gc_set_foreground) { + gc->graphics_gc_methods_proxy->gc_set_foreground( + gc->graphics_gc_priv_proxy, c); + } +} + +static void svg_debug_gc_set_background(struct graphics_gc_priv *gc, + struct color *c) { + gc->bg.r = c->r / 256; + gc->bg.g = c->g / 256; + gc->bg.b = c->b / 256; + gc->bg.a = c->a / 256; + if (gc->graphics_gc_methods_proxy->gc_set_foreground) { + gc->graphics_gc_methods_proxy->gc_set_foreground( + gc->graphics_gc_priv_proxy, c); + } +} + +static void svg_debug_gc_set_texture(struct graphics_gc_priv *gc, + struct graphics_image_priv *img) { + gc->img = img; +} + +static struct graphics_gc_methods gc_methods = { .gc_destroy = + svg_debug_gc_destroy, .gc_set_linewidth = svg_debug_gc_set_linewidth, + .gc_set_dashes = svg_debug_gc_set_dashes, .gc_set_foreground = + svg_debug_gc_set_foreground, .gc_set_background = + svg_debug_gc_set_background, .gc_set_texture = + svg_debug_gc_set_texture, +}; + +static struct graphics_gc_priv* svg_debug_gc_new(struct graphics_priv *gr, + struct graphics_gc_methods *meth) { + struct graphics_gc_priv *gc = g_new0(struct graphics_gc_priv, 1); + struct graphics_gc_priv *graphics_gc_priv_proxy = g_new0( + struct graphics_gc_priv, 1); + struct graphics_gc_methods *graphics_gc_methods_proxy = g_new0( + struct graphics_gc_methods, 1); + *meth = gc_methods; + gc->gr = gr; + gc->is_dashed = FALSE; + gc->linewidth = 1; + + if (gr->proxy_graphics_methods->gc_new) { + gr->proxy_graphics_methods->gc_new(gr->proxy_priv, + graphics_gc_methods_proxy); + } + gc->graphics_gc_methods_proxy = graphics_gc_methods_proxy; + gc->graphics_gc_priv_proxy = graphics_gc_priv_proxy; + return gc; +} + +void svg_debug_image_destroy(struct graphics_image_priv *img); +void svg_debug_image_destroy(struct graphics_image_priv *img) { + dbg(lvl_debug, "enter image_destroy"); + g_free(img->data); + if (img->graphics_image_methods_proxy->image_destroy) { + img->graphics_image_methods_proxy->image_destroy( + img->graphics_image_priv_proxy); + } + g_free(img->data); + g_free(img->graphics_image_methods_proxy); + g_free(img->graphics_image_priv_proxy); + g_free(img); +} + +static struct graphics_image_methods image_methods = { .image_destroy = + svg_debug_image_destroy, +}; + +static struct graphics_image_priv* svg_debug_image_new(struct graphics_priv *gr, + struct graphics_image_methods *meth, char *path, int *w, int *h, + struct point *hot, int rotation) { + struct graphics_image_priv *image_priv; + struct graphics_image_methods *graphics_image_methods; + char *base64_data_url = NULL; + char *base64_encoded_image = NULL; + char *image_mime_type = NULL; + char *contents = NULL; + char fileext[3] = ""; + gsize img_size; + + image_priv = g_new0(struct graphics_image_priv, 1); + graphics_image_methods = g_new0(struct graphics_image_methods, 1); + *meth = image_methods; + const char *data_url_template = "data:%s;base64,%s"; + + if (g_file_get_contents(path, &contents, &img_size, NULL)) { + dbg(lvl_debug, "image_new loaded %s", path); + + strtolower(fileext, &path[(strlen(path) - 3)]); + if (strcmp(fileext, "png")) { + image_mime_type = "image/png"; + } else if (strcmp(fileext, "jpg")) { + image_mime_type = "image/jpeg"; + } else if (strcmp(fileext, "gif")) { + image_mime_type = "image/gif"; + } else { + image_mime_type = "application/octet-stream"; + } + base64_encoded_image = g_base64_encode((guchar*) contents, img_size); + + base64_data_url = g_malloc0( + strlen(base64_encoded_image) + strlen(data_url_template) + + strlen(image_mime_type) + 1); + sprintf(base64_data_url, data_url_template, image_mime_type, + base64_encoded_image); + g_free(base64_encoded_image); + + image_priv->data = base64_data_url; + g_free(contents); + image_priv->h = *h; + image_priv->w = *w; + } else { + dbg(lvl_error, "image_new failed to load %s", path); + image_priv->data = + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="; + image_priv->h = 1; + image_priv->w = 1; + } + if (gr->proxy_graphics_methods->image_new) { + image_priv->graphics_image_priv_proxy = + gr->proxy_graphics_methods->image_new(gr->proxy_priv, + graphics_image_methods, path, w, h, hot, rotation); + image_priv->graphics_image_methods_proxy = graphics_image_methods; + } + if (image_priv->graphics_image_priv_proxy) { + return image_priv; + } + if (base64_data_url != NULL) { + g_free(base64_data_url); + } + g_free(graphics_image_methods); + g_free(image_priv); + return NULL; +} + +static void svg_debug_draw_lines(struct graphics_priv *gr, + struct graphics_gc_priv *gc, struct point *p, int count) { + const char *line_template_start = "\n"; + + fprintf(gr->outfile, line_template_start, ""); + int i; + for (i = 0; i < count; i++) { + fprintf(gr->outfile, coord_template, p[i].x, p[i].y); + } + + if (gc->is_dashed) { + fprintf(gr->outfile, dashed_template_start, ""); + int i; + for (i = 0; i < 4; i++) { + fprintf(gr->outfile, dashed_dasharray, gc->dashed[i]); + } + fprintf(gr->outfile, dashed_template_end, ""); + } + + fprintf(gr->outfile, line_template_end, gc->fg.r, gc->fg.g, gc->fg.b, + gc->linewidth); + + if (gr->proxy_graphics_methods->draw_lines) { + gr->proxy_graphics_methods->draw_lines(gr->proxy_priv, + gc->graphics_gc_priv_proxy, p, count); + } + +} + +static void svg_debug_draw_polygon(struct graphics_priv *gr, + struct graphics_gc_priv *gc, struct point *p, int count) { + const char *coord_template = "%i,%i "; + const char *polygon_template_start = "\n"; + fprintf(gr->outfile, polygon_template_start, ""); + int i; + for (i = 0; i < count; i++) { + fprintf(gr->outfile, coord_template, p[i].x, p[i].y); + } + fprintf(gr->outfile, polygon_template_end, gc->fg.r, gc->fg.g, gc->fg.b); + + if (gr->proxy_graphics_methods->draw_polygon) { + gr->proxy_graphics_methods->draw_polygon(gr->proxy_priv, + gc->graphics_gc_priv_proxy, p, count); + } + +} + +static void svg_debug_draw_rectangle(struct graphics_priv *gr, + struct graphics_gc_priv *gc, struct point *p, int w, int h) { + const char *rectangle_template = + "\n"; + fprintf(gr->outfile, rectangle_template, p->x, p->y, w, h, gc->fg.r, + gc->fg.g, gc->fg.b); + + if (gr->proxy_graphics_methods->draw_rectangle) { + gr->proxy_graphics_methods->draw_rectangle(gr->proxy_priv, + gc->graphics_gc_priv_proxy, p, w, h); + } +} + +static void svg_debug_draw_circle(struct graphics_priv *gr, + struct graphics_gc_priv *gc, struct point *p, int r) { + const char *circle_template = + "\n"; + fprintf(gr->outfile, circle_template, p->x, p->y, r / 2, gc->fg.r, gc->fg.g, + gc->fg.b); + + if (gr->proxy_graphics_methods->draw_circle) { + gr->proxy_graphics_methods->draw_circle(gr->proxy_priv, + gc->graphics_gc_priv_proxy, p, r); + } + +} + +static void svg_debug_draw_text(struct graphics_priv *gr, + struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, + struct graphics_font_priv *font, char *text, struct point *p, int dx, + int dy) { + const char *image_template = + "%s\n"; + if (dx == 0x10000 || dy == 0) { + fprintf(gr->outfile, image_template, p->x, p->y, fg->fg.r, fg->fg.g, + fg->fg.b, font ? font->size : 0, text); + } + if (gr->proxy_graphics_methods->draw_text && font) { + gr->proxy_graphics_methods->draw_text(gr->proxy_priv, + fg->graphics_gc_priv_proxy, bg->graphics_gc_priv_proxy, + font->graphics_font_proxy.priv, text, p, dx, dy); + } +} + +static void svg_debug_draw_image(struct graphics_priv *gr, + struct graphics_gc_priv *fg, struct point *p, + struct graphics_image_priv *img) { + // Write already encoded image to file + const char *image_template = + "\n"; + fprintf(gr->outfile, image_template, p->x, p->y, img->w, img->h, img->data); + if (gr->proxy_graphics_methods->draw_image) { + gr->proxy_graphics_methods->draw_image(gr->proxy_priv, fg, p, + img->graphics_image_priv_proxy); + } +} + +static void svg_debug_draw_drag(struct graphics_priv *gr, struct point *p) { + if (gr->proxy_graphics_methods->draw_drag) { + gr->proxy_graphics_methods->draw_drag(gr->proxy_priv, p); + } +} + +static void svg_debug_background_gc(struct graphics_priv *gr, + struct graphics_gc_priv *gc) { + if (gr->proxy_graphics_methods->background_gc) { + gr->proxy_graphics_methods->background_gc(gr->proxy_priv, + gc->graphics_gc_priv_proxy); + } +} + +static void svg_debug_draw_mode(struct graphics_priv *gr, + enum draw_mode_num mode) { + const char *svg_start_template = + "\n"; + const char *svg_end_template = "\n"; + char filename[255]; + switch (mode) { + case draw_mode_begin: + if (gr->outfile) { + dbg(lvl_debug, "Finished drawing %s/svg_debug_after_frame_%u.svg", + gr->outputdir, gr->frame) + fprintf(gr->outfile, svg_end_template, ""); + fclose(gr->outfile); + gr->frame += 1; + } + sprintf(filename, "%s/svg_debug_frame_%u.svg", gr->outputdir, + gr->frame); + gr->outfile = fopen(filename, "w"); + fprintf(gr->outfile, svg_start_template, gr->height, gr->width); + break; + case draw_mode_end: + dbg(lvl_debug, "Finished drawing %s/svg_debug_after_frame_%u.svg", + gr->outputdir, gr->frame) + fprintf(gr->outfile, svg_end_template, ""); + fclose(gr->outfile); + gr->frame += 1; + sprintf(filename, "%s/svg_debug_after_frame_%u.svg", gr->outputdir, + gr->frame); + gr->outfile = fopen(filename, "w"); + fprintf(gr->outfile, svg_start_template, gr->height, gr->width); + break; + default: + break; + } + if (gr->proxy_graphics_methods->draw_mode) { + gr->proxy_graphics_methods->draw_mode(gr->proxy_priv, mode); + } +} + +static void graphics_svg_debug_overlay_draw_mode(struct graphics_priv *gr, + enum draw_mode_num mode) { + // TODO + // https://stackoverflow.com/questions/5451135/embed-svg-in-svg + // more or less like in draw_mode but with different format string + // probably overlay_num so main svg can import it +} + +static struct graphics_priv* graphics_svg_debug_overlay_new( + struct graphics_priv *gr, struct graphics_methods *meth, + struct point *p, int w, int h, int wraparound); + +static int graphics_svg_debug_fullscreen(struct window *win, int on) { + struct graphics_priv *graphics_priv = (struct graphics_priv*) win->priv; + struct window *proxy_win; + if (!graphics_priv->proxy_graphics_methods->get_data) { + return 0; + } + proxy_win = graphics_priv->proxy_graphics_methods->get_data( + graphics_priv->proxy_priv, "window"); + if (proxy_win) { + return proxy_win->fullscreen(proxy_win, on); + } + return 0; +} + +static gboolean graphics_svg_debug_idle(void *data) { + struct graphics_priv *gr = (struct graphics_priv*) data; + static int first_run = TRUE; + if (first_run) { + callback_list_call_attr_2(gr->cbl, attr_resize, + GINT_TO_POINTER(gr->width), GINT_TO_POINTER(gr->height)); + first_run = FALSE; + } + return TRUE; +} + +static void graphics_svg_debug_disable_suspend(struct window *w) { + struct graphics_priv *graphics_priv = (struct graphics_priv*) w->priv; + struct window *proxy_win; + if (!graphics_priv->proxy_graphics_methods->get_data) { + return; + } + proxy_win = graphics_priv->proxy_graphics_methods->get_data( + graphics_priv->proxy_priv, "window"); + if (proxy_win) { + proxy_win->disable_suspend(proxy_win); + } + return; +} + +static void* svg_debug_get_data(struct graphics_priv *this, char const *type) { + if (strcmp(type, "window") == 0) { + struct window *win; + win = g_new0(struct window, 1); + win->priv = this; + win->fullscreen = graphics_svg_debug_fullscreen; + win->disable_suspend = graphics_svg_debug_disable_suspend; + return win; + } + if (this->proxy_graphics_methods->get_data) { + // FIXME: This will leak the proxied graphics_priv... But it works for now + return this->proxy_graphics_methods->get_data(this->proxy_priv, type); + } + return NULL; +} + +static void svg_debug_image_free(struct graphics_priv *gr, + struct graphics_image_priv *img) { + dbg(lvl_debug, "enter image_free"); + if (img->graphics_image_methods_proxy->image_destroy) { + img->graphics_image_methods_proxy->image_destroy( + img->graphics_image_priv_proxy); + } + if (gr->proxy_graphics_methods->image_free) { + gr->proxy_graphics_methods->image_free(gr->proxy_priv, + img->graphics_image_priv_proxy); + } + g_free(img->graphics_image_methods_proxy); + g_free(img->data); + g_free(img); +} + +static void graphics_svg_debug_overlay_disable(struct graphics_priv *gr, + int disable) { + // TODO +} + +static void graphics_svg_debug_overlay_resize(struct graphics_priv *gr, + struct point *p, int w, int h, int wraparound) { + // TODO +} + +static struct graphics_methods graphics_methods = { + .graphics_destroy = svg_debug_graphics_destroy, + .draw_mode = svg_debug_draw_mode, + .draw_lines = svg_debug_draw_lines, + .draw_polygon = svg_debug_draw_polygon, + .draw_rectangle = svg_debug_draw_rectangle, + .draw_circle = svg_debug_draw_circle, + .draw_text = svg_debug_draw_text, + // FIXME: Text size calculation is hard, because the svg is + // interpreted by the viewer, so we don't know its size + + .draw_image = svg_debug_draw_image, + .draw_image_warp = NULL, + .draw_drag = svg_debug_draw_drag, + .font_new = svg_debug_font_new, + .gc_new = svg_debug_gc_new, + .background_gc = svg_debug_background_gc, + .overlay_new = NULL, //graphics_svg_debug_overlay_new, // TODO + .image_new = svg_debug_image_new, + .get_data = svg_debug_get_data, + .image_free = svg_debug_image_free, + .get_text_bbox = svg_debug_get_text_bbox, + .overlay_disable = NULL, // graphics_svg_debug_overlay_disable, // TODO + .overlay_resize = NULL, // graphics_svg_debug_overlay_resize, // TODO + .set_attr = NULL, // TODO add proxy + .show_native_keyboard = NULL, // TODO add proxy + .hide_native_keyboard = NULL, // TODO add proxy + .get_dpi = NULL, // TODO add proxy + .draw_polygon_with_holes = NULL, // TODO add proxy + +}; + +static struct graphics_priv* graphics_svg_debug_overlay_new( + struct graphics_priv *gr, struct graphics_methods *meth, + struct point *p, int w, int h, int wraparound) { + struct graphics_priv *this = g_new0(struct graphics_priv, 1); + *meth = graphics_methods; + meth->draw_mode = graphics_svg_debug_overlay_draw_mode; + + // TODO + + return this; +} + +static struct graphics_priv* graphics_svg_debug_new(struct navit *nav, + struct graphics_methods *meth, struct attr **attrs, + struct callback_list *cbl) { + struct graphics_priv *this = g_new0(struct graphics_priv, 1); + struct graphics_methods *proxy_graphics_methods = g_new0( + struct graphics_methods, 1); + struct attr *attr; + void *proxy_priv = NULL; + struct graphics_priv* (*proxy_gra)(struct navit *nav, + struct graphics_methods *meth, struct attr **attrs, + struct callback_list *cbl); + + *meth = graphics_methods; + + // Save Parameters for later + this->nav = nav; + this->cbl = cbl; + + // Read configuration + this->width = 32; + if ((attr = attr_search(attrs, attr_w))) + this->width = attr->u.num; + this->height = 32; + if ((attr = attr_search(attrs, attr_h))) + this->height = attr->u.num; + + this->outputdir = g_get_tmp_dir(); + if ((attr = attr_search(attrs, attr_outputdir))) + this->outputdir = attr->u.str; + + // Get plugin to proxy + proxy_gra = NULL; + if ((attr = attr_search(attrs, attr_name))) { + if (attr->u.str[0] != '\0') { + proxy_gra = plugin_get_category_graphics(attr->u.str); + } + if (proxy_gra) { + // Call proxy plugin + proxy_priv = (*proxy_gra)(nav, proxy_graphics_methods, attrs, cbl); + } else { + dbg(lvl_error, "Failed to load graphics plugin %s.", attr->u.str); + return NULL; + } + } else { + if (!event_request_system("glib", "graphics_sdl_new")) { + dbg(lvl_error, "event_request_system failed"); + g_free(this); + return NULL; + } + } + + // Save proxy to call it later + this->proxy_priv = proxy_priv; + this->proxy_graphics_methods = proxy_graphics_methods; + this->frame = 0; + + // If something tries to write before calling draw_mode with start for the first time + this->outfile = fopen("/dev/null", "w"); + + //callbacks = cbl; + g_timeout_add(G_PRIORITY_DEFAULT + 10, graphics_svg_debug_idle, this); + + if (!proxy_gra) { + dbg(lvl_debug, "No Proxied plugin, so do not set functions to NULL") + // see comment below + callback_list_call_attr_2(cbl, attr_resize, + GINT_TO_POINTER(this->width), GINT_TO_POINTER(this->height)); + return this; + } + + // The rest of this function makes sure that svg_debug only supports what the + // proxied graphics plugin supports as well + // for example some graphics plugins don't support circles, but svg_debug does. + // if navit core sees that we support circles we would see it inside the svg, but not + // in the proxied graphics + // + // get_data and draw_mode may not been set to null because they need to exist + if (!this->proxy_graphics_methods->graphics_destroy) { + meth->graphics_destroy = NULL; + } + if (!this->proxy_graphics_methods->draw_lines) { + meth->draw_lines = NULL; + } + if (!this->proxy_graphics_methods->draw_polygon) { + meth->draw_polygon = NULL; + } + if (!this->proxy_graphics_methods->draw_rectangle) { + meth->draw_rectangle = NULL; + } + if (!this->proxy_graphics_methods->draw_circle) { + meth->draw_circle = NULL; + } + if (!this->proxy_graphics_methods->draw_text) { + meth->draw_text = NULL; + } + if (!this->proxy_graphics_methods->draw_image) { + meth->draw_image = NULL; + } + if (!this->proxy_graphics_methods->draw_image_warp) { + meth->draw_image_warp = NULL; + } + if (!this->proxy_graphics_methods->draw_drag) { + meth->draw_drag = NULL; + } + if (!this->proxy_graphics_methods->font_new) { + meth->font_new = NULL; + } + if (!this->proxy_graphics_methods->gc_new) { + meth->gc_new = NULL; + } + if (!this->proxy_graphics_methods->background_gc) { + meth->background_gc = NULL; + } + if (!this->proxy_graphics_methods->overlay_new) { + meth->overlay_new = NULL; + } + if (!this->proxy_graphics_methods->image_new) { + meth->image_new = NULL; + } + if (!this->proxy_graphics_methods->image_free) { + meth->image_free = NULL; + } + if (!this->proxy_graphics_methods->get_text_bbox) { + meth->get_text_bbox = NULL; + } + if (!this->proxy_graphics_methods->overlay_disable) { + meth->overlay_disable = NULL; + } + if (!this->proxy_graphics_methods->overlay_resize) { + meth->overlay_resize = NULL; + } + if (!this->proxy_graphics_methods->set_attr) { + meth->set_attr = NULL; + } + if (!this->proxy_graphics_methods->show_native_keyboard) { + meth->show_native_keyboard = NULL; + } + if (!this->proxy_graphics_methods->hide_native_keyboard) { + meth->hide_native_keyboard = NULL; + } + if (!this->proxy_graphics_methods->get_dpi) { + meth->get_dpi = NULL; + } + if (!this->proxy_graphics_methods->draw_polygon_with_holes) { + meth->draw_polygon_with_holes = NULL; + } + + // Add resize callback so we get called when window is resized so we can adjust the svg size + struct callback *callback = callback_new_attr_1(callback_cast(resize_callback_do), attr_resize, this); + callback_list_add(cbl, callback); + return this; +} + +void plugin_init(void) { + dbg(lvl_error, "enter svg_debug plugin_init") + plugin_register_category_graphics("svg_debug", graphics_svg_debug_new); + //plugin_register_category_event("svg_debug", event_svg_debug_new); +} diff --git a/navit/navit_shipped.xml b/navit/navit_shipped.xml index 5473349c7..5c2c404dc 100644 --- a/navit/navit_shipped.xml +++ b/navit/navit_shipped.xml @@ -37,6 +37,21 @@ + + + +