aboutsummaryrefslogtreecommitdiff
path: root/libplanfahr/lpf-provider.c
blob: fc2acc4f8438972730748690f21452fcf651c7d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * Copyright (C) 2014 Guido Guenther <agx@sigxcpu.org>
 *
 * 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.
 */

#include "config.h"

#include "lpf-provider.h"

G_DEFINE_INTERFACE (LpfProvider, lpf_provider, G_TYPE_OBJECT)

/**
 * SECTION:lpf-provider
 * @short_description: Public transport information provider interface
 * @see_also: #LpfProvider
 *
 * A #LpfProvider represents a provider of public transport
 * information such as timetables or location information
 */
/**
 * LpfProviderGotLocsNotify:
 * @locs: (element-type Lpf.Loc): List of found locations
 * @user_data: userdata
 * @err: (transfer full): #GError
 *
 * Callback invoked after the locations matching the query were
 * received. In case of an error @locs is #NULL.
 */
/**
 * LpfProviderGotTripsNotify:
 * @trips: (element-type Lpf.Loc): List of found trips
 * @user_data: userdata
 * @err: (transfer full): #GError
 *
 * Callback invoked after the trips matching the query were
 * received. In case of an error @trips is #NULL.
 */


GQuark
lpf_provider_error_quark (void)
{
  return g_quark_from_static_string ("lpf-provider-error-quark");
}

/**
 * lpf_provider_name:
 * @LpfProvider: a #LpfProvider
 *
 * Returns: transfer-none: the providers name
 */
const char*
lpf_provider_get_name (LpfProvider *self)
{
    g_return_val_if_fail (LPF_IS_PROVIDER (self), NULL);

    return LPF_PROVIDER_GET_INTERFACE (self)->get_name (self);
}


/* invoked by LprManager to activate the provider */
void
lpf_provider_activate (LpfProvider *self, GObject *obj)
{
    LPF_PROVIDER_GET_INTERFACE (self)->activate (self, obj);
}

/* invoked by LpfManager to activate the provider */
void
lpf_provider_deactivate (LpfProvider *self, GObject *obj)
{
    g_return_if_fail (LPF_IS_PROVIDER (self));

    LPF_PROVIDER_GET_INTERFACE (self)->deactivate (self, obj);
}

/**
 * lpf_provider_get_locs:
 * @self: a #LpfProvider
 * @match: locations to match
 * @flags: #LpfProviderGetLocsFlags for loation lookup
 * @callback: (scope async): #LpfProviderGotLocsNotify to invoke
 *   once locations are available
 * @user_data: (allow-none): User data for the callback
 *
 * Initiate a lookup for locations that match @match. Once complete
 *  @callback is invoked with a #GSList of matched #LpfLocation s.  The
 *  caller is responsible for freeing the locations list via
 *  #lpf_provider_free_locs.
 *
 * Returns: 0 on success, -1 on error
 */
gint
lpf_provider_get_locs (LpfProvider *self, const char* match, LpfProviderGetLocsFlags flags, LpfProviderGotLocsNotify callback, gpointer user_data)
{
    g_return_val_if_fail (LPF_IS_PROVIDER (self), -1);
    g_return_val_if_fail (match, -1);
    g_return_val_if_fail (callback, -1);

    return LPF_PROVIDER_GET_INTERFACE (self)->get_locs (self, match, flags, callback, user_data);
}

/**
 * lpf_provider_free_locs:
 * @self: a #LpfProvider
 * @locs: (element-type LpfLoc): A linked list of location
 *
 * Free the location list
 */
void
lpf_provider_free_locs(LpfProvider *self, GSList *locs)
{
    g_slist_free_full (locs, g_object_unref);
}

/**
 * lpf_provider_get_trips:
 * @self: a #LpfProvider
 * @start: start of trip location
 * @end: end of trip location
 * @date: Date and time the trip starts as #GDateTime
 * @flags: #LpfProviderGetTripsFlags for trip lookups
 * @callback: (scope async): #LpfProviderGotTripsNotify to invoke
 *   once trips are available
 * @user_data: (allow-none): User data for the callback
 *
 * Initiate a lookup for trips starting at the location @start, ending
 * at @end and starting (or depending on @flags) ending at @date.
 * Once completed @callback is invoked with a #GSList of matched
 * trips. The caller is responsible for freeing the locations list via
 * #lpf_provider_free_trips.
 *
 * Returns: 0 on success, -1 on error
 */

gint
lpf_provider_get_trips (LpfProvider *self, LpfLoc *start, LpfLoc *end, GDateTime *date, LpfProviderGetTripsFlags flags, LpfProviderGotLocsNotify callback, gpointer user_data)
{
    g_return_val_if_fail (LPF_IS_PROVIDER (self), -1);
    g_return_val_if_fail (start, -1);
    g_return_val_if_fail (end, -1);
    g_return_val_if_fail (date, -1);
    g_return_val_if_fail (callback, -1);

    return LPF_PROVIDER_GET_INTERFACE (self)->get_trips (self, start, end, date, flags, callback, user_data);
}

static void
lpf_provider_default_init (LpfProviderInterface *iface)
{
    g_object_interface_install_property
        (iface, g_param_spec_string (LPF_PROVIDER_PROP_NAME,
                                     "Name",
                                     "Provider Name",
                                     NULL,
                                     G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}

/**
 * lpf_provider_free_trips:
 * @self: a #LpfProvider
 * @trips: (element-type LpfTrip): A linked list of trips
 *
 * Free the trips list
 */
void
lpf_provider_free_trips(LpfProvider *self, GSList *trips)
{
    g_slist_free_full (trips, g_object_unref);
}


/**
 * lpf_provider_create: (skip)
 *
 * Create the provider
 */