From 734335998b3443ea86e3f565cc12295b12b6106d Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Mon, 3 Mar 2014 21:57:56 +0100 Subject: Add BVG provider This is our second hafas based provider to check the the interface actually works. --- docs/reference/Makefile.am | 1 + src/libplanfahr.sym | 1 + src/providers/Makefile.am | 24 +++++++ src/providers/de-bvg.c | 175 +++++++++++++++++++++++++++++++++++++++++++++ src/providers/de-bvg.h | 50 +++++++++++++ 5 files changed, 251 insertions(+) create mode 100644 src/providers/de-bvg.c create mode 100644 src/providers/de-bvg.h diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am index 0f77dbb..9ed93a8 100644 --- a/docs/reference/Makefile.am +++ b/docs/reference/Makefile.am @@ -31,6 +31,7 @@ CFILE_GLOB= # Header files to ignore when scanning. IGNORE_HFILES = \ planfahr.h \ + de-bvg.h \ de-db.h \ hafas-bin6.h \ $(NULL) diff --git a/src/libplanfahr.sym b/src/libplanfahr.sym index def0344..1fc8515 100644 --- a/src/libplanfahr.sym +++ b/src/libplanfahr.sym @@ -30,6 +30,7 @@ LIBPLANFAHR_PRIVATE_0.0.0 { global: lpf_loc_get_opaque; lpf_loc_set_opaque; + lpf_provider_de_bvg_get_type; lpf_provider_de_db_get_type; local: *; diff --git a/src/providers/Makefile.am b/src/providers/Makefile.am index 5bc3a84..164ec06 100644 --- a/src/providers/Makefile.am +++ b/src/providers/Makefile.am @@ -6,6 +6,7 @@ pkglibdir = $(LPF_PROVIDERS_DIR) pkglib_LTLIBRARIES = \ libplanfahr-provider-de-db.la \ + libplanfahr-provider-de-bvg.la \ $(NULL) libplanfahr_provider_de_db_la_SOURCES = \ @@ -30,3 +31,26 @@ libplanfahr_provider_de_db_la_LDFLAGS = \ -avoid-version \ $(LIBSOUP_LIBS) \ $(NULL) + +libplanfahr_provider_de_bvg_la_SOURCES = \ + de-bvg.h \ + de-bvg.c \ + hafas-bin6.h \ + hafas-bin6.c \ + $(NULL) + +libplanfahr_provider_de_bvg_la_CFLAGS = \ + $(GIO2_CFLAGS) \ + $(GOBJECT2_CFLAGS) \ + $(GTHREAD2_CFLAGS) \ + $(LIBXML2_CFLAGS) \ + $(LIBSOUP_CFLAGS) \ + $(WARN_CFLAGS) \ + -I$(top_srcdir)/src \ + $(NULL) + +libplanfahr_provider_de_bvg_la_LDFLAGS = \ + -module \ + -avoid-version \ + $(LIBSOUP_LIBS) \ + $(NULL) diff --git a/src/providers/de-bvg.c b/src/providers/de-bvg.c new file mode 100644 index 0000000..8094044 --- /dev/null +++ b/src/providers/de-bvg.c @@ -0,0 +1,175 @@ +/* + * de-bvg.c: BVG provider for libplanfahr + * + * Copyright (C) 2014 Guido Günther + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Author: Guido Günther +n */ + +#include + +#include +#include + +#include + +#include "de-bvg.h" +#include "hafas-bin6.h" +#include "lpf-provider.h" + +#define LOC_URL "http://www.fahrinfo-berlin.de/Fahrinfo/bin/query.bin/d" +#define TRIPS_URL "http://www.fahrinfo-berlin.de/Fahrinfo/bin/query.bin/d" + +#define PROVIDER_NAME "de_bvg" + +enum { + PROP_0, + PROP_NAME, + LAST_PROP +}; + +static void lpf_provider_de_bvg_interface_init (LpfProviderInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (LpfProviderDeBvg, lpf_provider_de_bvg, LPF_TYPE_PROVIDER_HAFAS_BIN6, + G_IMPLEMENT_INTERFACE (LPF_TYPE_PROVIDER, lpf_provider_de_bvg_interface_init)); + +#define GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), LPF_TYPE_PROVIDER_DE_BVG, LpfProviderDeBvgPrivate)) + +int lpf_provider_major_version = LPF_PROVIDER_MAJOR_VERSION; +int lpf_provider_minor_version = LPF_PROVIDER_MINOR_VERSION; + +typedef struct _LpfProviderDeBvgPrivate LpfProviderDeBvgPrivate; +struct _LpfProviderDeBvgPrivate { + gchar *name; +}; + + +static const char* +lpf_provider_de_bvg_get_name (LpfProvider *self) +{ + LpfProviderDeBvgPrivate *priv = GET_PRIVATE (self); + + return priv->name; +} + + +static const char* +lpf_provider_de_bvg_locs_url(LpfProviderHafasBin6 *self) +{ + return LOC_URL; +} + + +static const char* +lpf_provider_de_bvg_trips_url(LpfProviderHafasBin6 *self) +{ + return TRIPS_URL; +} + + +G_MODULE_EXPORT LpfProvider * +lpf_provider_create (void) +{ + return LPF_PROVIDER (lpf_provider_de_bvg_new ()); +} + + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + LpfProviderDeBvgPrivate *priv = GET_PRIVATE (object); + + switch (prop_id) { + case PROP_NAME: + /* construct only */ + priv->name = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + LpfProviderDeBvgPrivate *priv = GET_PRIVATE (object); + + switch (prop_id) { + case PROP_NAME: + g_value_set_string (value, priv->name); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + + +static void +lpf_provider_de_bvg_finalize (GObject *self) +{ + LpfProviderDeBvgPrivate *priv = GET_PRIVATE(self); + + g_free (priv->name); + G_OBJECT_CLASS (lpf_provider_de_bvg_parent_class)->finalize (self); +} + + +static void +lpf_provider_de_bvg_class_init (LpfProviderDeBvgClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + LpfProviderHafasBin6Class *hafas_class = LPF_PROVIDER_HAFAS_BIN6_CLASS (klass); + + g_type_class_add_private (klass, sizeof (LpfProviderDeBvgPrivate)); + + object_class->get_property = get_property; + object_class->set_property = set_property; + object_class->finalize = lpf_provider_de_bvg_finalize; + + /* LpfProvider */ + g_object_class_override_property (object_class, + PROP_NAME, + "name"); + + /* LpfProviderHafasBin6 */ + hafas_class->locs_url = lpf_provider_de_bvg_locs_url; + hafas_class->trips_url = lpf_provider_de_bvg_trips_url; +} + +static void +lpf_provider_de_bvg_interface_init (LpfProviderInterface *iface) +{ + iface->get_name = lpf_provider_de_bvg_get_name; +} + +static void +lpf_provider_de_bvg_init (LpfProviderDeBvg *self) +{ +} + +LpfProviderDeBvg * +lpf_provider_de_bvg_new (void) +{ + return g_object_new (LPF_TYPE_PROVIDER_DE_BVG, LPF_PROVIDER_PROP_NAME, + PROVIDER_NAME, NULL); +} diff --git a/src/providers/de-bvg.h b/src/providers/de-bvg.h new file mode 100644 index 0000000..9ef055c --- /dev/null +++ b/src/providers/de-bvg.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2014 Guido Guenther + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef _LPF_PROVIDER_DE_BVG_H +#define _LPF_PROVIDER_DE_BVG_H + +#include "hafas-bin6.h" + +G_BEGIN_DECLS +#define LPF_TYPE_PROVIDER_DE_BVG lpf_provider_de_bvg_get_type() +#define LPF_PROVIDER_DE_BVG(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), LPF_TYPE_PROVIDER_DE_BVG, LpfProviderDeBvg)) +#define LPF_PROVIDER_DE_BVG_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), LPF_TYPE_PROVIDER_DE_BVG, LpfProviderDeBvgClass)) +#define LPF_IS_PROVIDER_DE_BVG(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LPF_TYPE_PROVIDER_DE_BVG)) +#define LPF_IS_PROVIDER_DE_BVG_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), LPF_TYPE_PROVIDER_DE_BVG)) +#define LPF_PROVIDER_DE_BVG_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), LPF_TYPE_PROVIDER_DE_BVG, LpfProviderDeBvgClass)) + +typedef struct { + LpfProviderHafasBin6 parent; +} LpfProviderDeBvg; + +typedef struct { + LpfProviderHafasBin6Class parent_class; +} LpfProviderDeBvgClass; + +GType lpf_provider_de_bvg_get_type (void); + +LpfProviderDeBvg *lpf_provider_de_bvg_new (void); + +G_END_DECLS +#endif /* _LPF_PROVIDER_DB */ -- cgit v1.2.3