source: trunk/zoo-project/zoo-kernel/service_internal_perl.c @ 649

Last change on this file since 649 was 348, checked in by neteler, 13 years ago

set correctly svn propset

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 4.3 KB
Line 
1/**
2 * Author : David SAGGIORATO
3 *
4 * Copyright (c) 2009-2010 GeoLabs SARL
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25#include "service_internal_perl.h"
26
27
28static PerlInterpreter *my_perl;
29
30
31void xs_init(pTHX)
32{
33        char *file = __FILE__;
34        dXSUB_SYS;
35       
36        /* DynaLoader is a special case */
37        newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
38}
39
40
41
42int map_to_hash(map * m, HV ** hash_map) {
43        HV * tmp = *hash_map;
44        map * tmp_m = m;
45        do {
46                //printf("map name %s  value %s \n",m->name,m->value);
47
48                if ( NULL == hv_store( tmp, tmp_m->name, strlen(tmp_m->name), sv_2mortal(newSVpv(tmp_m->value, strlen(tmp_m->value))), 0) ) {
49                        return 1;
50                        }
51                tmp_m = tmp_m->next;
52                }
53        while (tmp_m != NULL);
54        return 0;
55}
56
57int maps_to_hash( maps* m, HV ** hash_maps){
58        HV * tmp = *hash_maps;
59        if (m != NULL) {
60                //printf("maps name %s \n",m->name);
61                HV* hash_m = (HV *)sv_2mortal((SV *)newHV());
62                if (map_to_hash(m->content,&hash_m) != 0){
63                        return 1;
64                }
65               
66                if ( NULL == hv_store( tmp, m->name, strlen(m->name),sv_2mortal(newRV_inc((SV *)hash_m)), 0) ) {
67                        return 1;
68                }       
69                return maps_to_hash(m->next,hash_maps);
70        }
71        return 0;
72}
73
74int hash_to_map(HV * hh,map ** m){
75        hv_iterinit(hh);
76        *m = (map *)malloc(MAP_SIZE);
77        if (*m == NULL){
78                // erreur d'allocation memoire
79                return 1;
80        }
81        map * tmp = *m;
82        HE * he = hv_iternext(hh);
83        while (he != NULL){
84                //fprintf(stderr,"key : %s  value : %s \n",HeKEY(he),(char *)SvRV(HeVAL(he)));
85                tmp->name = HeKEY(he);
86                tmp->value = (char *)SvRV(HeVAL(he));
87                he = hv_iternext(hh);
88                if(he != NULL){
89                        tmp->next = (map *)malloc(MAP_SIZE);
90                        if (tmp->next == NULL){
91                                //erreur allocation memoire
92                                return 1;
93                        }
94                        tmp=tmp->next;
95                }
96                else {
97                        tmp->next = NULL;
98                }
99
100        }
101
102        return 1;
103}
104       
105int hash_to_maps(HV * hh,maps** m){
106        hv_iterinit(hh);
107        *m = (maps *)malloc(MAPS_SIZE);
108        maps * tmp = *m;
109        HE * he = hv_iternext(hh);
110        map *mm;
111        while (he != NULL) {
112                //fprintf(stderr,"key ===> %s \n",HeKEY(he));
113                tmp->name = HeKEY(he);
114                hash_to_map((HV *) SvRV(HeVAL(he)),&mm);
115                tmp->content = mm;
116                he = hv_iternext(hh);
117                if (he != NULL){
118                        tmp->next = (maps *)malloc(MAPS_SIZE);
119                        tmp= tmp->next;
120                }
121                else {
122                        tmp->next = NULL;
123                }               
124        }
125        return 1;
126}
127       
128int zoo_perl_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){
129        maps* m=*main_conf;
130        maps* inputs=*real_inputs;
131        maps* outputs=*real_outputs;
132        int res=SERVICE_FAILED;
133        map * tmp=getMap(s->content,"serviceProvide");
134
135        char *my_argv[] = { "", tmp->value };
136        if ((my_perl = perl_alloc()) == NULL){
137                fprintf(stderr,"no memmory");
138                exit(1);
139        }
140        perl_construct( my_perl );
141        perl_parse(my_perl, xs_init, 2, my_argv, (char **)NULL);
142        perl_run(my_perl);
143       
144
145        HV* h_main_conf = (HV *)sv_2mortal((SV *)newHV());
146        HV* h_real_inputs = (HV *)sv_2mortal((SV *)newHV());
147        HV* h_real_outputs = (HV *)sv_2mortal((SV *)newHV());
148        maps_to_hash(m,&h_main_conf);
149        maps_to_hash(inputs,&h_real_inputs);
150        maps_to_hash(outputs,&h_real_outputs);
151        dSP;
152        ENTER;
153        SAVETMPS;
154        PUSHMARK(SP);
155        XPUSHs(sv_2mortal(newRV_inc((SV *)h_main_conf)));
156        XPUSHs(sv_2mortal(newRV_inc((SV *)h_real_inputs)));
157        XPUSHs(sv_2mortal(newRV_inc((SV *)h_real_outputs)));
158        PUTBACK;
159        call_pv(s->name, G_SCALAR);
160        SPAGAIN;
161        res = POPi;
162        hash_to_maps(h_real_outputs,real_outputs);
163        //dumpMaps(*real_outputs);
164        PUTBACK;
165        FREETMPS;
166        LEAVE;
167        return SERVICE_SUCCEEDED;
168}
169
170       
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
Note: See TracBrowser for help on using the repository browser.

Search

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png