summaryrefslogtreecommitdiff
path: root/navit/traffic
diff options
context:
space:
mode:
authormvglasow <michael -at- vonglasow.com>2017-11-27 23:19:05 +0100
committermvglasow <michael -at- vonglasow.com>2017-11-27 23:19:05 +0100
commit480614fbf784371f07589b935090989cbfd437a7 (patch)
tree627c03b07e80661b9e2fb48b130d37fe5e458f04 /navit/traffic
parenta9fa1310cc95e61ed2ebfee4564d432fb64ee1c1 (diff)
downloadnavit-480614fbf784371f07589b935090989cbfd437a7.tar.gz
Add:traffic/dummy:Implement traffic plugin API
Signed-off-by: mvglasow <michael -at- vonglasow.com>
Diffstat (limited to 'navit/traffic')
-rw-r--r--navit/traffic/dummy/traffic_dummy.c71
1 files changed, 39 insertions, 32 deletions
diff --git a/navit/traffic/dummy/traffic_dummy.c b/navit/traffic/dummy/traffic_dummy.c
index c0f74199b..9abaf1368 100644
--- a/navit/traffic/dummy/traffic_dummy.c
+++ b/navit/traffic/dummy/traffic_dummy.c
@@ -35,43 +35,30 @@
#include "config.h"
#include "coord.h"
#include "item.h"
+#include "xmlconfig.h"
#include "traffic.h"
-#include "event.h"
-#include "callback.h"
#include "debug.h"
/**
* @brief Stores information about the plugin instance.
*/
-struct traffic {
- struct navit * nav; /*!< The navit instance */
- struct callback * callback; /*!< The callback function for the idle loop */
- struct event_idle * idle; /*!< The idle event that triggers the idle function */
+struct traffic_priv {
+ struct navit * nav; /*!< The navit instance */
};
/**
- * @brief The idle function for the traffic plugin.
- *
- * This function polls backends for new messages and processes them by inserting, removing or modifying
- * traffic distortions and triggering route recalculations as needed.
- */
-void traffic_idle(struct traffic * this_) {
- // TODO poll backends and process any new messages
- dbg(lvl_error, "THIS IS THE DUMMY TRAFFIC PLUGIN. Got nothing to do yet...\n");
- traffic_report_messages(0, NULL);
-}
-
-/**
- * @brief Inserts a dummy traffic report.
+ * @brief Returns a dummy traffic report.
*
* This will report one single message, indicating queuing traffic on the A9 Munich–Nuremberg between
* Neufahrn and Allershausen. This mimics a TMC message in that coordinates are approximate, TMC
* identifiers are supplied for the location and extra data fields which can be inferred from the TMC
* location table are filled. The message purports to just have been received for the first time, and
* expire in 24 hours.
+ *
+ * @return A `NULL`-terminated pointer array. Each element points to one `struct traffic_message`.
*/
-void traffic_dummy_report(void) {
- struct traffic_message ** messages = g_new0(struct traffic_message *, 1);
+struct traffic_message ** traffic_dummy_get_messages(void) {
+ struct traffic_message ** messages = g_new0(struct traffic_message *, 2);
struct traffic_point * from = traffic_point_new(11.6208, 48.3164, "Neufahrn", "68", "12732-4");
struct traffic_point * to = traffic_point_new(11.5893, 48.429, "Allershausen", "67", "12732");
struct trafic_location * location = traffic_location_new(NULL, from, to, "Nürnberg", NULL,
@@ -80,24 +67,44 @@ void traffic_dummy_report(void) {
messages[0] = traffic_message_new_single_event("dummy:A9-68-67", time(NULL), time(NULL),
time(NULL) + 86400, 0, 0, location, event_class_congestion, event_congestion_queue);
- traffic_report_messages(1, messages);
}
/**
- * @brief Initializes the traffic plugin.
+ * @brief The methods implemented by this plugin
+ */
+static struct traffic_methods traffic_dummy_meth = {
+ traffic_dummy_get_messages,
+};
+
+/**
+ * @brief Registers a new dummy traffic plugin
*
- * This function is called once on startup.
+ * @param meth Receives the traffic methods
+ * @param attrs The attributes for the map
+ * @param cbl
+ * @param parent The parent of the plugin, must be the navit instance
+ *
+ * @return A pointer to a `traffic_priv` structure for the plugin instance
*/
-void plugin_init(void) {
- struct traffic * this_;
+static struct traffic_priv * traffic_dummy_new(struct traffic_methods *meth, struct attr **attrs,
+ struct callback_list *cbl, struct attr *parent) {
+ struct traffic_priv *ret;
- dbg(lvl_error, "THIS IS THE DUMMY TRAFFIC PLUGIN. Startup successful, more to come soon...\n");
+ dbg(lvl_error, "enter\n");
- this_ = g_new0(struct traffic, 1);
+ ret = g_new0(struct traffic_priv, 1);
+ *meth = traffic_dummy_meth;
- // TODO register ourselves as a map plugin (once we have a map provider)
+ return ret;
+}
+
+/**
+ * @brief Initializes the traffic plugin.
+ *
+ * This function is called once on startup.
+ */
+void plugin_init(void) {
+ dbg(lvl_error, "enter\n");
- // FIXME error:navit:event_add_idle:Can't find event system method add_idle. Event system is not set.
- this_->callback = callback_new_1(callback_cast(traffic_idle), this_);
- this_->idle = event_add_idle(200, this_->callback); // TODO store return value with plugin instance
+ plugin_register_category_traffic("dummy", traffic_dummy_new);
}