"Fossies" - the Fresh Open Source Software Archive

Member "navit-0.5.6/navit/traffic/dummy/traffic_dummy.c" (6 Mar 2021, 8689 Bytes) of package /linux/privat/navit-0.5.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "traffic_dummy.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.5.5_vs_0.5.6.

    1 /**
    2  * Navit, a modular navigation system.
    3  * Copyright (C) 2005-2017 Navit Team
    4  *
    5  * This program is free software; you can redistribute it and/or
    6  * modify it under the terms of the GNU General Public License
    7  * version 2 as published by the Free Software Foundation.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the
   16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   17  * Boston, MA  02110-1301, USA.
   18  */
   19 
   20 /**
   21  * @file traffic_dummy.c
   22  *
   23  * @brief A dummy traffic plugin.
   24  *
   25  * This is a dummy plugin to test the traffic framework.
   26  */
   27 
   28 #include <string.h>
   29 #include <time.h>
   30 
   31 #ifdef _POSIX_C_SOURCE
   32 #include <sys/types.h>
   33 #endif
   34 #include "glib_slice.h"
   35 #include "config.h"
   36 #include "coord.h"
   37 #include "item.h"
   38 #include "xmlconfig.h"
   39 #include "traffic.h"
   40 #include "plugin.h"
   41 #include "debug.h"
   42 
   43 /**
   44  * @brief Stores information about the plugin instance.
   45  */
   46 struct traffic_priv {
   47     struct navit * nav;         /*!< The navit instance */
   48     int reports_requested;      /*!< How many reports have been requested */
   49 };
   50 
   51 struct traffic_message ** traffic_dummy_get_messages(struct traffic_priv * this_);
   52 
   53 /**
   54  * @brief Returns a dummy traffic report.
   55  *
   56  * This method will report two messages when first called: The messages indicate queuing traffic on the
   57  * A9 Munich–Nuremberg between Neufahrn and Allershausen, and slow traffic on the A96 Lindau–Munich
   58  * between Gräfelfing and München-Laim.
   59  *
   60  * The 10th call will report an update message for the A9 (with a recent timestamp but otherwise the same
   61  * data) and a cancellation message for the A96.
   62  *
   63  * They mimic TMC messages in that coordinates are approximate, TMC identifiers are supplied for the
   64  * locations and extra data fields which can be inferred from the TMC location table are filled. The
   65  * timestamps indicate a message that has just been received for the first time, i.e. its “first
   66  * received” and “last updated” timestamps match and are recent. Expiration is after 20 seconds for
   67  * messages in the first feed and 10 seconds for messages in the first feed (far below the lowest
   68  * expiration timespan permitted in TMC).
   69  *
   70  * All other calls to this method will return `NULL`, indicating that there are no messages to report.
   71  *
   72  * @return A `NULL`-terminated pointer array. Each element points to one `struct traffic_message`.
   73  * `NULL` is returned (rather than an empty pointer array) if there are no messages to report.
   74  */
   75 struct traffic_message ** traffic_dummy_get_messages(struct traffic_priv * this_) {
   76     struct traffic_message ** messages;
   77     struct traffic_point * from;
   78     struct traffic_point * to;
   79     struct traffic_point * at;
   80     struct traffic_point * via;
   81     struct traffic_location * location;
   82 
   83     this_->reports_requested++;
   84 
   85     switch (this_->reports_requested) {
   86     case 10:
   87         messages = g_new0(struct traffic_message *, 6);
   88 
   89         from = traffic_point_new(11.6208, 48.3164, "Neufahrn", "68", "12732-4");
   90         to = traffic_point_new(11.5893, 48.429, "Allershausen", "67", "12732");
   91         location = traffic_location_new(NULL, from, to, NULL, NULL, "Nürnberg", NULL, location_dir_one,
   92                                         location_fuzziness_low_res, location_ramps_none, type_highway_land, NULL, "A9", "58:1", -1);
   93         messages[0] = traffic_message_new_single_event("dummy:A9-68-67", time(NULL), time(NULL),
   94                       time(NULL) + 86400, 0, location, event_class_congestion, event_congestion_queue);
   95 
   96         from = traffic_point_new(11.4481, 48.1266, "Gräfelfing", "36b", "12961-2");
   97         to = traffic_point_new(11.5028, 48.1258, "München-Laim", "38", "12961");
   98         location = traffic_location_new(NULL, from, to, NULL, NULL, "München", NULL, location_dir_one,
   99                                         location_fuzziness_low_res, location_ramps_none, type_highway_land, NULL, "A96", "58:1", -1);
  100         messages[1] = traffic_message_new_single_event("dummy:A96-36b-38", time(NULL), time(NULL),
  101                       time(NULL) + 86400, 0, location, event_class_congestion, event_congestion_slow_traffic);
  102 
  103         from = traffic_point_new(11.6143, 48.15255, "Effnertunnel", NULL, "60922");
  104         to = traffic_point_new(11.53225, 48.13255, "Trappentreutunnel", NULL, "35333");
  105         via = traffic_point_new(11.5728, 48.178, "Petueltunnel", NULL, "29829");
  106         location = traffic_location_new(NULL, from, to, via, NULL, NULL, NULL, location_dir_one,
  107                                         location_fuzziness_low_res, location_ramps_none, type_line_unspecified, NULL, "B2R", "58:1", 1);
  108         messages[2] = traffic_message_new_single_event("dummy:B2R-N", time(NULL), time(NULL),
  109                       time(NULL) + 86400, 0, location, event_class_congestion, event_congestion_slow_traffic);
  110 
  111         from = traffic_point_new(11.6143, 48.15255, "Effnertunnel", NULL, "60922");
  112         to = traffic_point_new(11.53225, 48.13255, "Trappentreutunnel", NULL, "35333");
  113         via = traffic_point_new(11.55085, 48.11225, "Brudermühltunnel", NULL, "35329");
  114         location = traffic_location_new(NULL, from, to, via, NULL, NULL, NULL, location_dir_one,
  115                                         location_fuzziness_low_res, location_ramps_none, type_line_unspecified, NULL, "B2R", "58:1", -1);
  116         messages[3] = traffic_message_new_single_event("dummy:B2R-S", time(NULL), time(NULL),
  117                       time(NULL) + 86400, 0, location, event_class_congestion, event_congestion_slow_traffic);
  118 
  119         from = traffic_point_new(11.6208, 48.3164, "Neufahrn", "68", "12727+5");
  120         at = traffic_point_new(11.6405, 48.2435, "Garching-Süd", "71", "12727");
  121         location = traffic_location_new(at, from, NULL, NULL, NULL, NULL, NULL, location_dir_one,
  122                                         location_fuzziness_low_res, location_ramps_none, type_highway_land, NULL, "A9", "58:1", 1);
  123         messages[4] = traffic_message_new_single_event("dummy:A9-71-S", time(NULL), time(NULL),
  124                       time(NULL) + 86400, 0, location, event_class_congestion, event_congestion_slow_traffic);
  125         break;
  126 
  127     case 20:
  128         messages = g_new0(struct traffic_message *, 4);
  129 
  130         from = traffic_point_new(11.6208, 48.3164, "Neufahrn", "68", "12732-4");
  131         to = traffic_point_new(11.5893, 48.429, "Allershausen", "67", "12732");
  132         location = traffic_location_new(NULL, from, to, NULL, NULL, "Nürnberg", NULL, location_dir_one,
  133                                         location_fuzziness_low_res, location_ramps_none, type_highway_land, NULL, "A9", "58:1", -1);
  134         messages[0] = traffic_message_new_single_event("dummy:A9-68-67", time(NULL) - 10, time(NULL),
  135                       time(NULL) + 10, 0, location, event_class_congestion, event_congestion_queue);
  136 
  137         from = traffic_point_new(11.4481, 48.1266, "Gräfelfing", "36b", "12961-2");
  138         to = traffic_point_new(11.5028, 48.1258, "München-Laim", "38", "12961");
  139         location = traffic_location_new(NULL, from, to, NULL, NULL, "München", NULL, location_dir_one,
  140                                         location_fuzziness_low_res, location_ramps_none, type_highway_land, NULL, "A96", "58:1", -1);
  141         messages[1] = traffic_message_new_cancellation("dummy:A96-36b-38", time(NULL) - 10, time(NULL),
  142                       time(NULL) + 10, location);
  143         break;
  144 
  145     default:
  146         return NULL;
  147     }
  148 
  149     return messages;
  150 }
  151 
  152 /**
  153  * @brief The methods implemented by this plugin
  154  */
  155 static struct traffic_methods traffic_dummy_meth = {
  156     traffic_dummy_get_messages,
  157     NULL,
  158 };
  159 
  160 /**
  161  * @brief Registers a new dummy traffic plugin
  162  *
  163  * @param nav The navit instance
  164  * @param meth Receives the traffic methods
  165  * @param attrs The attributes for the map
  166  * @param cbl
  167  *
  168  * @return A pointer to a `traffic_priv` structure for the plugin instance
  169  */
  170 static struct traffic_priv * traffic_dummy_new(struct navit *nav, struct traffic_methods *meth,
  171         struct attr **attrs, struct callback_list *cbl) {
  172     struct traffic_priv *ret;
  173 
  174     dbg(lvl_debug, "enter");
  175 
  176     ret = g_new0(struct traffic_priv, 1);
  177     *meth = traffic_dummy_meth;
  178 
  179     return ret;
  180 }
  181 
  182 /**
  183  * @brief Initializes the traffic plugin.
  184  *
  185  * This function is called once on startup.
  186  */
  187 void plugin_init(void) {
  188     dbg(lvl_debug, "enter");
  189 
  190     plugin_register_category_traffic("dummy", traffic_dummy_new);
  191 }