navit  0.5.3-trunk
traffic_traff_android.c File Reference

The TraFF plugin for Android. More...

#include <string.h>
#include <time.h>
#include "glib_slice.h"
#include "config.h"
#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"

Data Structures

struct  traffic_priv
 Stores information about the plugin instance. More...
 

Macros

#define POSITION_RECT_SIZE   100000
 Minimum area around the current position for which to retrieve traffic updates. More...
 

Functions

void traffic_traff_android_destroy (struct traffic_priv *this_)
 Destructor. More...
 
struct traffic_message ** traffic_traff_android_get_messages (struct traffic_priv *this_)
 Returns an empty traffic report. More...
 
static void traffic_traff_android_on_feed_received (struct traffic_priv *this_, char *feed)
 Called when a new TraFF feed is received. More...
 
static void traffic_traff_android_set_selection (struct traffic_priv *this_)
 Sets the route map selection. More...
 
static void traffic_traff_android_destination_callback (struct traffic_priv *this_)
 Callback for destination changes. More...
 
static void traffic_traff_android_status_callback (struct traffic_priv *this_, int status)
 Callback for navigation status changes. More...
 
static void traffic_traff_android_position_callback (struct traffic_priv *this_, struct navit *navit, struct vehicle *vehicle)
 Callback for position changes. More...
 
static int traffic_traff_android_init (struct traffic_priv *this_)
 Initializes a traff_android plugin. More...
 
static struct traffic_privtraffic_traff_android_new (struct navit *nav, struct traffic_methods *meth, struct attr **attrs, struct callback_list *cbl)
 Registers a new traff_android traffic plugin. More...
 
void plugin_init (void)
 Initializes the traffic plugin. More...
 

Variables

static struct traffic_methods traffic_traff_android_meth
 The methods implemented by this plugin. More...
 

Detailed Description

The TraFF plugin for Android.

Navit, a modular navigation system. Copyright (C) 2005-2018 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 receives TraFF feeds via Android broadcasts and content providers.

Macro Definition Documentation

◆ POSITION_RECT_SIZE

#define POSITION_RECT_SIZE   100000

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 traffic_priv::position_rect and updated in traffic_traff_android_position_callback(struct traffic_priv *, struct navit *, struct vehicle *).

Function Documentation

◆ plugin_init()

void plugin_init ( void  )

Initializes the traffic plugin.

The plugin entry point.

This function is called once on startup.

References dbg, lvl_debug, and traffic_traff_android_new().

◆ traffic_traff_android_destination_callback()

static void traffic_traff_android_destination_callback ( struct traffic_priv this_)
static

Callback for destination changes.

Parameters
this_The instance which will handle the destination update

References traffic_traff_android_set_selection().

Referenced by traffic_traff_android_init().

◆ traffic_traff_android_destroy()

◆ traffic_traff_android_get_messages()

struct traffic_message ** traffic_traff_android_get_messages ( struct traffic_priv this_)

Returns an empty traffic report.

Returns
Always NULL

◆ traffic_traff_android_init()

◆ traffic_traff_android_new()

static struct traffic_priv* traffic_traff_android_new ( struct navit nav,
struct traffic_methods meth,
struct attr **  attrs,
struct callback_list cbl 
)
static

Registers a new traff_android traffic plugin.

Parameters
navThe navit instance
methReceives the traffic methods
attrsThe attributes for the map
cbl
Returns
A pointer to a traffic_priv structure for the plugin instance

References callback_cast, callback_new_1, traffic_priv::cbid, dbg, lvl_debug, traffic_priv::nav, traffic_priv::position_rect, traffic_priv::position_valid, traffic_priv::route_map_sel, traffic_traff_android_init(), traffic_traff_android_meth, and traffic_traff_android_on_feed_received().

Referenced by plugin_init().

◆ traffic_traff_android_on_feed_received()

static void traffic_traff_android_on_feed_received ( struct traffic_priv this_,
char *  feed 
)
static

Called when a new TraFF feed is received.

Parameters
this_Private data for the module instance
feedFeed data in string form

References dbg, lvl_debug, lvl_error, traffic_priv::nav, navit_attr_iter_destroy(), navit_attr_iter_new(), navit_get_attr(), attr::navit_object, traffic_get_messages_from_xml_string(), traffic_process_messages(), and attr::u.

Referenced by traffic_traff_android_new().

◆ traffic_traff_android_position_callback()

static void traffic_traff_android_position_callback ( struct traffic_priv this_,
struct navit navit,
struct vehicle vehicle 
)
static

Callback for position changes.

This updates traffic_priv::position_rect if the vehicle has moved far enough from its center to be within 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.

Parameters
this_The instance which will handle the position update
navitThe Navit instance
vehicleThe vehicle which delivered the position update and from which the position can be queried

References c, attr::coord_geo, coord_rect_contains(), coord_rect::lu, traffic_priv::position_rect, POSITION_RECT_SIZE, projection_mg, coord_rect::rl, traffic_traff_android_set_selection(), transform_from_geo(), attr::u, vehicle_get_attr(), coord::x, and coord::y.

Referenced by traffic_traff_android_init().

◆ traffic_traff_android_set_selection()

◆ traffic_traff_android_status_callback()

static void traffic_traff_android_status_callback ( struct traffic_priv this_,
int  status 
)
static

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.

Parameters
this_The instance which will handle the navigation status update
statusThe status of the navigation engine (the value of the
nav_status
Definition: navigation.h:45
attribute)

References traffic_priv::position_valid, and traffic_traff_android_set_selection().

Referenced by traffic_traff_android_init().

Variable Documentation

◆ traffic_traff_android_meth

struct traffic_methods traffic_traff_android_meth
static
Initial value:
= {
}
void traffic_traff_android_destroy(struct traffic_priv *this_)
Destructor.
Definition: traffic_traff_android.c:84
struct traffic_message ** traffic_traff_android_get_messages(struct traffic_priv *this_)
Returns an empty traffic report.
Definition: traffic_traff_android.c:107

The methods implemented by this plugin.

Referenced by traffic_traff_android_new().