diff options
author | mvglasow <michael -at- vonglasow.com> | 2015-10-31 19:52:49 +0100 |
---|---|---|
committer | mvglasow <michael -at- vonglasow.com> | 2015-10-31 19:52:49 +0100 |
commit | 271fe67afa751b7a793027052262e8d2044f10e1 (patch) | |
tree | 5b4536c9230ca6c35dbbeb7c55c1e13a012a67ab /navit/navigation.c | |
parent | 6d94fdea12a166d4d7832d0c3df0df474b276d24 (diff) | |
download | navit-271fe67afa751b7a793027052262e8d2044f10e1.tar.gz |
Add:osd:new navigation_status OSD
Signed-off-by: mvglasow <michael -at- vonglasow.com>
Diffstat (limited to 'navit/navigation.c')
-rw-r--r-- | navit/navigation.c | 103 |
1 files changed, 90 insertions, 13 deletions
diff --git a/navit/navigation.c b/navit/navigation.c index a78ce1e1a..ba9b5aaeb 100644 --- a/navit/navigation.c +++ b/navit/navigation.c @@ -146,15 +146,6 @@ struct suffix { }; -enum nav_status { - status_no_route = -1, - status_no_destination = 0, - status_position_wait = 1, - status_calculating = 2, - status_recalculating = 3, - status_routing = 4, -}; - enum nav_status_int { status_none = 0, status_busy = 1, @@ -681,6 +672,46 @@ select_announced_destinations(struct navigation_command *current_command) } +/** + * @brief Converts navigation status to human-readable text. + * + * @param The status. This must be one of the values for {@code enum nav_status}. + * + * @return A string which corresponds to the constant value. The caller is responsible for calling + * {@code g_free()} when the result is no longer needed. + */ +char *nav_status_to_text(int status) { + char *ret; + + switch (status) { + case status_invalid: + ret = g_strdup("status_invalid"); + break; + case status_no_route: + ret = g_strdup("status_no_route"); + break; + case status_no_destination: + ret = g_strdup("status_no_destination"); + break; + case status_position_wait: + ret = g_strdup("status_position_wait"); + break; + case status_calculating: + ret = g_strdup("status_calculating"); + break; + case status_recalculating: + ret = g_strdup("status_recalculating"); + break; + case status_routing: + ret = g_strdup("status_routing"); + break; + default: + ret = g_strdup_printf("status_unknown_%d)", status); + } + return ret; +} + + int navigation_get_attr(struct navigation *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) { @@ -740,13 +771,11 @@ navigation_set_turnaround(struct navigation *this_, int val) int navigation_set_attr(struct navigation *this_, struct attr *attr) { - int attr_updated=0; switch (attr->type) { case attr_speech: this_->speech=attr->u.speech; break; case attr_nav_status: - attr_updated = (this_->nav_status != attr->u.num); this_->nav_status = attr->u.num; break; default: @@ -3860,23 +3889,71 @@ navigation_destroy(struct navigation *this_) g_free(this_); } +/** + * @brief Registers a new callback function. + * + * Callback functions are called whenever the attribute for which they are registered changes. + * It is possible to register callbacks for {@code attr_any}, which will fire on any change. + * + * The {@code navigation} object has three callback lists. They differ by the arguments which are + * passed to the callback function and are selected based on the attribute type: + * <ul> + * <li>Callbacks for the {@code navigation_speech} attribute are added to the + * {@code callback_speech} list.</li> + * <li>Callbacks for the {@code navigation_long} attribute are added to the {@code callback} list. + * </li> + * <li>Callbacks for any other attribute, including {@code attr_any}, are added to the list stored + * in the {@code callback_list} attribute. This functionality is inherited from + * {@code navit_object}.</li> + * </ul> + * + * @param this_ The navigation object. + * @param type The attribute type + * @param cb The callback function + * + * @return true on success, false on failure + */ int navigation_register_callback(struct navigation *this_, enum attr_type type, struct callback *cb) { + struct attr attr_cbl; + if (type == attr_navigation_speech) callback_list_add(this_->callback_speech, cb); - else + else if (type == attr_navigation_long) callback_list_add(this_->callback, cb); + else { + if (navigation_get_attr(this_, attr_callback_list, &attr_cbl, NULL)) + callback_list_add(attr_cbl.u.callback_list, cb); + else + return 0; + } return 1; } +/** + * @brief Unregisters a callback function. + * + * This function removes a previously registered callback function from the callback list to which + * it was added. See the documentation on + * {@link navigation_register_callback(struct navigation *, enum attr_type, struct callback *)} for + * details on callback lists. + * + * @param this_ The navigation object. + * @param type The attribute type + * @param cb The callback function + */ void navigation_unregister_callback(struct navigation *this_, enum attr_type type, struct callback *cb) { + struct attr attr_cbl; + if (type == attr_navigation_speech) callback_list_remove(this_->callback_speech, cb); - else + else if (type == attr_navigation_long) callback_list_remove(this_->callback, cb); + else if (navigation_get_attr(this_, attr_callback_list, &attr_cbl, NULL)) + callback_list_remove(attr_cbl.u.callback_list, cb); } struct map * |