~ubuntu-branches/ubuntu/natty/libchamplain/natty

« back to all changes in this revision

Viewing changes to bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs

  • Committer: Bazaar Package Importer
  • Author(s): Sjoerd Simons, Laurent Bigonville, Sjoerd Simons
  • Date: 2009-09-15 00:01:41 UTC
  • mfrom: (1.1.3 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090915000141-i8fg5n1t02zxo79m
Tags: 0.4.0-1
[ Laurent Bigonville ]
* debian/control: Add libchamplain-0.3-dev dependency to
  libchamplain-gtk-0.3-dev

[ Sjoerd Simons ]
* New upstream release (0.4.0)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "champlain-perl.h"
 
2
 
 
3
static GPerlCallback*
 
4
champlainperl_constructor_create (SV *func, SV *data) {
 
5
        GType param_types [] = {
 
6
                CHAMPLAIN_TYPE_MAP_SOURCE_DESC,
 
7
        };
 
8
        return gperl_callback_new(
 
9
                func, data,
 
10
                G_N_ELEMENTS(param_types), param_types,
 
11
                CHAMPLAIN_TYPE_MAP_SOURCE
 
12
        );
 
13
}
 
14
 
 
15
 
 
16
static ChamplainMapSource*
 
17
champlainperl_constructor (ChamplainMapSourceDesc *desc, gpointer data) {
 
18
        GPerlCallback *callback = (GPerlCallback *) data;
 
19
        GValue return_value = { 0, };
 
20
        ChamplainMapSource *retval;
 
21
        
 
22
        if (callback == NULL) {
 
23
                croak("Chammplain::MapSourceFactory constructor callback is missing the data parameter");
 
24
        }
 
25
        
 
26
        g_value_init(&return_value, callback->return_type);
 
27
        /* FIXME desc is not passed as a Champlain::MapSourceDesc to the perl callback */
 
28
        gperl_callback_invoke(callback, &return_value, desc, callback->data);
 
29
        
 
30
        retval = g_value_get_object(&return_value);
 
31
        g_value_unset(&return_value);
 
32
        
 
33
        return retval;
 
34
}
 
35
 
 
36
 
 
37
/**
 
38
 * Returns the value of the given key or croaks if there's no such key.
 
39
 */
 
40
static SV*
 
41
champlainperl_fetch_or_croak (HV* hash , const char* key , I32 klen) {
 
42
 
 
43
        SV **s = hv_fetch(hash, key, klen, 0);
 
44
        if (s != NULL && SvOK(*s)) {
 
45
                return *s;
 
46
        }
 
47
        
 
48
        croak("Hashref requires the key: '%s'", key);
 
49
}
 
50
 
 
51
 
 
52
static ChamplainMapSourceDesc*
 
53
champlainperl_SvChamplainMapSourceDesc (SV *data) {
 
54
        HV *hash;
 
55
        SV *value;
 
56
        ChamplainMapSourceDesc desc = {0,};
 
57
 
 
58
        if ((!data) || (!SvOK(data)) || (!SvRV(data)) || (SvTYPE(SvRV(data)) != SVt_PVHV)) {
 
59
                croak("SvChamplainMapSourceDesc: value must be an hashref");
 
60
        }
 
61
 
 
62
        hash = (HV *) SvRV(data);
 
63
        
 
64
        /* All keys are mandatory */
 
65
        if (value = champlainperl_fetch_or_croak(hash, "id", 2)) {
 
66
                desc.id = g_strdup(SvGChar(value));
 
67
        }
 
68
        
 
69
        if (value = champlainperl_fetch_or_croak(hash, "name", 4)) {
 
70
                desc.name = g_strdup(SvGChar(value));
 
71
        }
 
72
        
 
73
        if (value = champlainperl_fetch_or_croak(hash, "license", 7)) {
 
74
                desc.license = g_strdup(SvGChar(value));
 
75
        }
 
76
        
 
77
        if (value = champlainperl_fetch_or_croak(hash, "license_uri", 11)) {
 
78
                desc.license_uri = g_strdup(SvGChar(value));
 
79
        }
 
80
        
 
81
        if (value = champlainperl_fetch_or_croak(hash, "min_zoom_level", 14)) {
 
82
                desc.min_zoom_level = (gint) SvIV(value);
 
83
        }
 
84
        
 
85
        if (value = champlainperl_fetch_or_croak(hash, "max_zoom_level", 14)) {
 
86
                desc.max_zoom_level = (gint) SvIV(value);
 
87
        }
 
88
        
 
89
        if (value = champlainperl_fetch_or_croak(hash, "projection", 10)) {
 
90
                desc.projection = SvChamplainMapProjection(value);
 
91
        }
 
92
        
 
93
        if (value = champlainperl_fetch_or_croak(hash, "uri_format", 10)) {
 
94
                desc.uri_format = g_strdup(SvGChar(value));
 
95
        }
 
96
 
 
97
        return g_memdup(&desc, sizeof(desc));
 
98
}
 
99
 
 
100
 
 
101
MODULE = Champlain::MapSourceFactory  PACKAGE = Champlain::MapSourceFactory  PREFIX = champlain_map_source_factory_
 
102
 
 
103
 
 
104
ChamplainMapSourceFactory*
 
105
champlain_map_source_factory_dup_default (class)
 
106
        C_ARGS: /* No args */
 
107
 
 
108
 
 
109
void
 
110
champlain_map_source_factory_dup_list (ChamplainMapSourceFactory *factory)
 
111
        PREINIT:
 
112
                GSList *list = NULL;
 
113
                GSList *item = NULL;
 
114
        
 
115
        PPCODE:
 
116
                list = champlain_map_source_factory_dup_list(factory);
 
117
                
 
118
                for (item = list; item != NULL; item = item->next) {
 
119
                        ChamplainMapSourceDesc *desc = CHAMPLAIN_MAP_SOURCE_DESC(item->data);
 
120
                        XPUSHs(sv_2mortal(newSVChamplainMapSourceDesc(desc)));
 
121
                }
 
122
                
 
123
                g_slist_free(list);
 
124
 
 
125
 
 
126
ChamplainMapSource*
 
127
champlain_map_source_factory_create (ChamplainMapSourceFactory *factory, const gchar *id)
 
128
 
 
129
 
 
130
gboolean
 
131
champlain_map_source_factory_register (ChamplainMapSourceFactory *factory, SV *sv_desc, SV* sv_constructor, SV *sv_data=NULL)
 
132
        PREINIT:
 
133
                ChamplainMapSourceDesc *desc = NULL;
 
134
                SV *sv = NULL;
 
135
                GPerlCallback *callback = NULL;
 
136
        
 
137
        CODE:
 
138
                desc = champlainperl_SvChamplainMapSourceDesc(sv_desc);
 
139
                callback = champlainperl_constructor_create(sv_constructor, sv_data);
 
140
                RETVAL = champlain_map_source_factory_register(factory, desc, champlainperl_constructor, callback);
 
141
 
 
142
        OUTPUT:
 
143
                RETVAL
 
144
 
 
145
 
 
146
const gchar*
 
147
OSM_MAPNIK (class)
 
148
        CODE:
 
149
                RETVAL = CHAMPLAIN_MAP_SOURCE_OSM_MAPNIK;
 
150
 
 
151
        OUTPUT:
 
152
                RETVAL
 
153
 
 
154
 
 
155
const gchar*
 
156
OSM_OSMARENDER (class)
 
157
        CODE:
 
158
                RETVAL = CHAMPLAIN_MAP_SOURCE_OSM_OSMARENDER;
 
159
 
 
160
        OUTPUT:
 
161
                RETVAL
 
162
 
 
163
 
 
164
const gchar*
 
165
OSM_CYCLE_MAP (class)
 
166
        CODE:
 
167
                RETVAL = CHAMPLAIN_MAP_SOURCE_OSM_CYCLE_MAP;
 
168
 
 
169
        OUTPUT:
 
170
                RETVAL
 
171
 
 
172
 
 
173
const gchar*
 
174
OAM (class)
 
175
        CODE:
 
176
                RETVAL = CHAMPLAIN_MAP_SOURCE_OAM;
 
177
 
 
178
        OUTPUT:
 
179
                RETVAL
 
180
 
 
181
 
 
182
const gchar*
 
183
MFF_RELIEF (class)
 
184
        CODE:
 
185
                RETVAL = CHAMPLAIN_MAP_SOURCE_MFF_RELIEF;
 
186
 
 
187
        OUTPUT:
 
188
                RETVAL