source: trunk/zoo-kernel/service_internal_perl.c @ 22

Last change on this file since 22 was 22, checked in by david, 10 years ago

ajout support perl (attention encore en dev)

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
30EXTERN_C
31
32void xs_init(pTHX)
33{
34        char *file = __FILE__;
35        dXSUB_SYS;
36       
37        /* DynaLoader is a special case */
38        newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
39}
40
41
42
43int map_to_hash(map * m, HV ** hash_map) {
44        HV * tmp = *hash_map;
45        map * tmp_m = m;
46        do {
47                printf("map name %s  value %s \n",m->name,m->value);
48
49                if ( NULL == hv_store( tmp, tmp_m->name, strlen(tmp_m->name), sv_2mortal(newSVpv(tmp_m->value, strlen(tmp_m->value))), 0) ) {
50                        return 1;
51                        }
52                tmp_m = tmp_m->next;
53                }
54        while (tmp_m != NULL);
55        return 0;
56}
57
58int maps_to_hash( maps* m, HV ** hash_maps){
59        HV * tmp = *hash_maps;
60        if (m != NULL) {
61                printf("maps name %s \n",m->name);
62                HV* hash_m = (HV *)sv_2mortal((SV *)newHV());
63                if (map_to_hash(m->content,&hash_m) != 0){
64                        return 1;
65                }
66               
67                if ( NULL == hv_store( tmp, m->name, strlen(m->name),sv_2mortal(newRV_inc((SV *)hash_m)), 0) ) {
68                        return 1;
69                }       
70                return maps_to_hash(m->next,hash_maps);
71        }
72        return 0;
73}
74
75int hash_to_map(HV * hh,map ** m){
76        hv_iterinit(hh);
77        *m = (map *)malloc(MAP_SIZE);
78        if (*m == NULL){
79                // erreur d'allocation memoire
80                return 1;
81        }
82        map * tmp = *m;
83        HE * he = hv_iternext(hh);
84        while (he != NULL){
85                printf("key : %s  value : %s \n",HeKEY(he),(char *)SvRV(HeVAL(he)));
86                tmp->name = HeKEY(he);
87                tmp->value = (char *)SvRV(HeVAL(he));
88                he = hv_iternext(hh);
89                if(he != NULL){
90                        tmp->next = (map *)malloc(MAP_SIZE);
91                        if (tmp->next == NULL){
92                                //erreur allocation memoire
93                                return 1;
94                        }
95                        tmp=tmp->next;
96                }
97                else {
98                        tmp->next = NULL;
99                }
100
101        }
102
103        return 1;
104}
105       
106int hash_to_maps(HV * hh,maps** m){
107        hv_iterinit(hh);
108        *m = (maps *)malloc(MAPS_SIZE);
109        maps * tmp = *m;
110        HE * he = hv_iternext(hh);
111        map *mm;
112        while (he != NULL) {
113                printf("key ===> %s \n",HeKEY(he));
114                tmp->name = HeKEY(he);
115                hash_to_map((HV *) SvRV(HeVAL(he)),&mm);
116                tmp->content = mm;
117                he = hv_iternext(hh);
118                if (he != NULL){
119                        tmp->next = (maps *)malloc(MAPS_SIZE);
120                        tmp= tmp->next;
121                }
122                else {
123                        tmp->next = NULL;
124                }               
125        }
126        return 1;
127}
128       
129int zoo_perl_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){
130        maps* m=*main_conf;
131        maps* inputs=*real_inputs;
132        maps* outputs=*real_outputs;
133        int res=SERVICE_FAILED;
134        map * tmp=getMap(s->content,"serviceProvide");
135
136        char *my_argv[] = { "", tmp->value };
137        if ((my_perl = perl_alloc()) == NULL){
138                fprintf(stderr,"no memmory");
139                exit(1);
140        }
141        perl_construct( my_perl );
142        perl_parse(my_perl, xs_init, 2, my_argv, (char **)NULL);
143        perl_run(my_perl);
144       
145
146        HV* h_main_conf = (HV *)sv_2mortal((SV *)newHV());
147        HV* h_real_inputs = (HV *)sv_2mortal((SV *)newHV());
148        HV* h_real_outputs = (HV *)sv_2mortal((SV *)newHV());
149        maps_to_hash(m,&h_main_conf);
150        maps_to_hash(inputs,&h_real_inputs);
151        maps_to_hash(outputs,&h_real_outputs);
152        dSP;
153        ENTER;
154        SAVETMPS;
155        PUSHMARK(SP);
156        XPUSHs(sv_2mortal(newRV_inc((SV *)h_main_conf)));
157        XPUSHs(sv_2mortal(newRV_inc((SV *)h_real_inputs)));
158        XPUSHs(sv_2mortal(newRV_inc((SV *)h_real_outputs)));
159        PUTBACK;
160        call_pv(s->name, G_SCALAR);
161        SPAGAIN;
162        res = POPi;
163        hash_to_maps(h_real_outputs,real_outputs);
164        PUTBACK;
165        FREETMPS;
166        LEAVE;
167        return res;
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