Changeset 217 for branches/branch-1.2/zoo-services
- Timestamp:
- May 31, 2011, 3:30:49 AM (13 years ago)
- Location:
- branches/branch-1.2
- Files:
-
- 9 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/branch-1.2
-
branches/branch-1.2/zoo-services/arithmetics/cgi-env/Multiply.zcfg
r106 r217 5 5 storeSupported = true 6 6 statusSupported = true 7 serviceProvider = demo_service.zo7 serviceProvider = test_service.zo 8 8 serviceType = C 9 9 <MetaData> -
branches/branch-1.2/zoo-services/arithmetics/makefile.vc
r1 r217 1 1 GEODIR=c:/OSGeo4W/ 2 2 TOOLS=c:/Users/djay/GeoLabs/tools/ 3 CFLAGS=-I$(GEODIR)/include -I$(TOOLS)/include -I../../ ../zoo-kernel/ -I./ -DLINUX_FREE_ISSUE -DDEBUG3 CFLAGS=-I$(GEODIR)/include -I$(TOOLS)/include -I../../zoo-kernel/ -I./ -DLINUX_FREE_ISSUE -DDEBUG -DWIN32 4 4 CPP=cl /TP 5 5 6 cgi-env/ service.zo:service.c7 $(CPP) $(CFLAGS) /c service.c8 link /dll /out:cgi-env/ ogr_service.zso ../../../zoo-kernel/service_internal.obj ./service.obj -L$(TOOLS)/lib/libssl32.dll.a $(GEODIR)/lib/libxml2.lib $(GEODIR)/lib/gdal_i.lib $(TOOLS)/lib/libeay32.dll.a $(TOOLS)/lib/libcrypto.a $(TOOLS)/lib/libssl32.dll.a6 cgi-env/test_service.zo: test_service.c 7 $(CPP) $(CFLAGS) /c test_service.c 8 link /dll /out:cgi-env/test_service.zo ../../zoo-kernel/service_internal.obj ./test_service.obj -L$(TOOLS)/lib/libssl32.dll.a $(GEODIR)/lib/libxml2.lib $(GEODIR)/lib/gdal_i.lib $(TOOLS)/lib/libeay32.dll.a $(TOOLS)/lib/libcrypto.a $(TOOLS)/lib/libssl32.dll.a $(TOOLS)/lib/libintl.lib 9 9 10 10 clean: 11 rm -f cgi-env/ogr_service.zso11 erase cgi-env\demo_service.* -
branches/branch-1.2/zoo-services/arithmetics/test_service.c
r1 r217 3 3 extern "C" { 4 4 5 #ifdef WIN32 6 __declspec(dllexport) 7 #endif 5 8 int Multiply(maps*& conf,maps*& inputs,maps*& outputs){ 6 9 fprintf(stderr,"\nService internal print\n"); -
branches/branch-1.2/zoo-services/cgal/Makefile
r1 r217 1 CFLAGS=-I../../zoo-kernel -svn/ -I./ `xml2-config --cflags` `python-config --cflags` -DLINUX_FREE_ISSUE #-DDEBUG1 CFLAGS=-I../../zoo-kernel/ -I./ `xml2-config --cflags` `python-config --cflags` -DLINUX_FREE_ISSUE #-DDEBUG 2 2 CC=gcc 3 3 4 cgi-env/ service.zo: service.c5 g++ ${CFLAGS} -shared -fpic -o cgi-env/ service.zo ./service.c -lgdal4 cgi-env/cgal_service.zo: service.c 5 g++ ${CFLAGS} -shared -fpic -o cgi-env/cgal_service.zo ./service.c -lgdal -lCGAL 6 6 7 7 clean: 8 rm -f *.zo *.o *.tab.c *.tab.h *.sr.c* service_loader lex.* *.lreg *.sibling8 rm -f cgi-env/*.zo *.o *.tab.c *.tab.h *.sr.c* service_loader lex.* *.lreg *.sibling 9 9 rm -rf service_loader.dSYM -
branches/branch-1.2/zoo-services/cgal/service.c
r1 r217 46 46 void printExceptionReportResponse(maps*,map*); 47 47 48 char *base64(const unsigned char *input, int length){ 49 BIO *bmem, *b64; 50 BUF_MEM *bptr; 51 52 b64 = BIO_new(BIO_f_base64()); 53 bmem = BIO_new(BIO_s_mem()); 54 b64 = BIO_push(b64, bmem); 55 BIO_write(b64, input, length); 56 BIO_flush(b64); 57 BIO_get_mem_ptr(b64, &bptr); 58 59 char *buff = (char *)malloc(bptr->length+1); 60 memcpy(buff, bptr->data, bptr->length); 61 buff[bptr->length] = 0; 62 63 BIO_free_all(b64); 64 65 return buff; 66 } 67 68 OGRGeometryH createGeometryFromGML(maps* conf,char* inputStr){ 69 xmlInitParser(); 70 xmlDocPtr doc = xmlParseMemory(inputStr,strlen(inputStr)); 71 xmlChar *xmlbuff; 72 int buffersize; 73 xmlXPathContextPtr xpathCtx; 74 xmlXPathObjectPtr xpathObj; 75 char * xpathExpr="/*/*/*/*/*[local-name()='Polygon' or local-name()='MultiPolygon']"; 76 xpathCtx = xmlXPathNewContext(doc); 77 xpathObj = xmlXPathEvalExpression(BAD_CAST xpathExpr,xpathCtx); 78 if(!xpathObj->nodesetval){ 79 map* tmp=createMap("text","Unable to parse Input Polygon"); 80 addToMap(tmp,"code","InvalidParameterValue"); 81 printExceptionReportResponse(conf,tmp); 82 exit(0); 83 } 84 int size = (xpathObj->nodesetval) ? xpathObj->nodesetval->nodeNr : 0; 85 /** 86 * Create a temporary XML document 87 */ 88 xmlDocPtr ndoc = xmlNewDoc(BAD_CAST "1.0"); 89 /** 90 * Only one polygon should be provided so we use it as the root node. 91 */ 92 for(int k=size-1;k>=0;k--){ 93 xmlDocSetRootElement(ndoc, xpathObj->nodesetval->nodeTab[k]); 94 } 95 xmlDocDumpFormatMemory(ndoc, &xmlbuff, &buffersize, 1); 96 char *tmp=strdup(strstr((char*)xmlbuff,"?>")+2); 97 xmlXPathFreeObject(xpathObj); 98 xmlXPathFreeContext(xpathCtx); 99 xmlFree(xmlbuff); 100 xmlFreeDoc(doc); 101 xmlCleanupParser(); 102 fprintf(stderr,"\nService internal print\n Loading the geometry from GML string ..."); 103 OGRGeometryH res=OGR_G_CreateFromGML(tmp); 104 if(res==NULL){ 105 map* tmp=createMap("text","Unable to call OGR_G_CreatFromGML"); 106 addToMap(tmp,"code","NoApplicableCode"); 107 printExceptionReportResponse(conf,tmp); 108 exit(0); 109 } 110 else 111 return OGR_G_CreateFromGML(tmp); 112 } 113 114 115 int Delaunay(maps*& conf,maps*& inputs,maps*& outputs){ 48 int Voronoi(maps*& conf,maps*& inputs,maps*& outputs){ 49 #ifdef DEBUG 116 50 fprintf(stderr,"\nService internal print\nStarting\n"); 51 #endif 117 52 maps* cursor=inputs; 118 53 OGRGeometryH geometry,res; … … 121 56 map* tmpm=NULL; 122 57 tmpm=getMapFromMaps(inputs,"InputPoints","value"); 123 58 124 59 xmlInitParser(); 125 60 xmlDocPtr doc = … … 135 70 xpathObj = xmlXPathEvalExpression(BAD_CAST "/*/*[local-name()='featureMember']/*/*/*[local-name()='Point']/*[local-name()='coordinates']",xpathCtx); 136 71 xmlXPathFreeContext(xpathCtx); 137 xmlNodeSet* toto=xpathObj->nodesetval; 138 139 if(toto==NULL) 140 fprintf(stderr,"IMPOSSIBLE DE CONTINUER !!!!\n"); 72 xmlNodeSet* nSet=xpathObj->nodesetval; 73 74 if(nSet==NULL){ 75 setMapInMaps(conf,"lenv","message","Unable to continue !!!"); 76 return SERVICE_FAILED; 77 } 141 78 char filepath[2048]; 142 79 map* tmpMap=getMapFromMaps(conf,"main","tmpPath"); … … 145 82 } 146 83 FILE *fo=fopen(filepath,"w"); 147 fprintf(stderr,"File Creation (%s) OK\nPrinting %d Points.\n",filepath,toto->nodeNr); 148 for(int k=0;k<toto->nodeNr;k++){ 149 xmlNodePtr cur=toto->nodeTab[k]; 84 #ifdef DEBUG 85 fprintf(stderr,"File Creation (%s) OK\nPrinting %d Points.\n",filepath,nSet->nodeNr); 86 #endif 87 for(int k=0;k<nSet->nodeNr;k++){ 88 xmlNodePtr cur=nSet->nodeTab[k]; 150 89 char *val= 151 90 (char*)xmlNodeListGetString(doc,cur->xmlChildrenNode,1); … … 159 98 } 160 99 fclose(fo); 100 #ifdef DEBUG 161 101 fprintf(stderr,"File Close (%s) OK\n",filepath); 102 #endif 162 103 163 104 std::ifstream in(filepath); 164 165 std::istream_iterator<Point1> begin(in); 166 std::istream_iterator<Point1> end; 167 168 DelaunayTriangulation dt1; 169 dt1.insert(begin, end); 105 std::istream_iterator<Point> begin(in); 106 std::istream_iterator<Point> end; 107 Triangulation T; 108 T.insert(begin, end); 170 109 171 110 OGRRegisterAll(); … … 180 119 181 120 tmpMap=getMapFromMaps(outputs,"Result","mimeType"); 182 c har *oDriver=(char*)malloc(7*sizeof(char));121 const char *oDriver; 183 122 oDriver="GeoJSON"; 184 123 if(tmpMap!=NULL){ 185 124 if(strcmp(tmpMap->value,"text/xml")==0){ 186 fprintf(stderr,"USEING GML \n");187 125 oDriver="GML"; 188 126 } … … 212 150 sprintf( emessage, "%s -> `%s'\n", emessage, poR->GetDriver(iDriver)->GetName() ); 213 151 } 214 215 fprintf(stderr,"{\"type\": \"error\", \"%s\"}",emessage); 216 exit( 1 ); 152 153 setMapInMaps(conf,"lenv","message",emessage); 154 return SERVICE_FAILED; 155 217 156 } 218 157 … … 221 160 sprintf( emessage, "%s driver does not support data source creation.\n", 222 161 "json" ); 223 fprintf(stderr,"{\"type\": \"error\", \"%s\"}",emessage); 224 exit( 1 ); 225 } 226 227 /* -------------------------------------------------------------------- */ 228 /* Create the output data source. */ 229 /* -------------------------------------------------------------------- */ 230 map* tpath=getMapFromMaps(conf,"main","tmpPath"); 231 char *pszDestDataSource=(char*)malloc(strlen(tpath->value)+20); 232 char **papszDSCO=NULL; 233 sprintf(pszDestDataSource,"%s/result_%d.json",tpath->value,getpid()); 234 fprintf(stderr,"\n *%s* \n",pszDestDataSource); 235 poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO ); 236 if( poODS == NULL ){ 237 char emessage[1024]; 238 sprintf( emessage, "%s driver failed to create %s\n", 239 "json", pszDestDataSource ); 240 fprintf(stderr,"{\"type\": \"error\", \"%s\"}",emessage); 241 exit( 1 ); 242 } 243 244 /* -------------------------------------------------------------------- */ 245 /* Create the layer. */ 246 /* -------------------------------------------------------------------- */ 247 if( !poODS->TestCapability( ODsCCreateLayer ) ) 248 { 249 char emessage[1024]; 250 sprintf( emessage, 251 "Layer %s not found, and CreateLayer not supported by driver.", 252 "Result" ); 253 fprintf(stderr,"{\"type\": \"error\",\"message\": \"%s\"}",emessage); 254 return FALSE; 255 } 256 257 CPLErrorReset(); 258 259 OGRLayer *poDstLayer = poODS->CreateLayer( "Result", NULL,wkbLineString,NULL); 260 if( poDstLayer == NULL ){ 261 fprintf( stderr,"Layer creation failed.\n" ); 262 exit( 1 ); 263 } 264 265 Vertex_circulator vc = dt1.incident_vertices(dt1.infinite_vertex()), 266 done(vc); 267 if (vc != 0) { 268 do {std::cout << vc->point() << std::endl;}while(++vc != done); 269 } 270 271 DelaunayTriangulation::Edge_iterator eit=dt1.edges_begin(); 272 int i=0; 273 for ( ; eit !=dt1.edges_end(); ++eit) { 274 fprintf(stderr,"Edge %d\n",i); 275 i++; 276 /*CGAL::Object o = dt1.dual(eit); 277 if (const K::Segment_2 *tmp=CGAL::object_cast<K::Segment_2>(&o)) { 278 const K::Point_2 p1=tmp->source(); 279 const K::Point_2 p2=tmp->target(); 280 //#ifdef DEBUG 281 fprintf(stderr,"P1 %d %d | P2 %d %d\n",p1.x(),p1.y(),p2.x(),p2.y()); 282 //#endif 283 }*/ 284 /*if (const K::Segment_3 *tmp=CGAL::object_cast<K::Segment_3>(eit)) { 285 const K::Point_3 p1=tmp->source(); 286 const K::Point_3 p2=tmp->target(); 287 #ifdef DEBUG 288 fprintf(stderr,"P1 %d %d | P2 %d %d\n",p1.x(),p1.y(),p2.x(),p2.y()); 289 #endif 290 OGRFeatureH hFeature = OGR_F_Create( OGR_L_GetLayerDefn( poDstLayer ) ); 291 OGRGeometryH currLine=OGR_G_CreateGeometry(wkbLineString); 292 OGR_G_AddPoint_2D(currLine,p1.x(),p1.y()); 293 OGR_G_AddPoint_2D(currLine,p2.x(),p2.y()); 294 OGR_F_SetGeometry( hFeature, currLine ); 295 OGR_G_DestroyGeometry(currLine); 296 if( OGR_L_CreateFeature( poDstLayer, hFeature ) != OGRERR_NONE ){ 297 fprintf( stderr,"Failed to create feature in file.\n" ); 298 exit( 1 ); 299 } 300 OGR_F_Destroy( hFeature );*/ 301 } 302 303 int idg=0; 304 for (DelaunayTriangulation::Face_iterator fit = dt1.faces_begin(); fit!= 305 dt1.faces_end(); ++fit) { 306 int idx = 0; 307 int i0, i1, i2; 308 309 OGRFeatureH hFeature = OGR_F_Create( OGR_L_GetLayerDefn( poDstLayer ) ); 310 OGRGeometryH currLine=OGR_G_CreateGeometry(wkbLineString); 311 312 for(i0=0;i0<3;i0++){ 313 if(!dt1.is_infinite((*fit).vertex(i0))) 314 OGR_G_AddPoint_2D(currLine,(*fit).vertex(i0)->point().x(), 315 (*fit).vertex(i0)->point().y()); 316 if(i0==2 && !dt1.is_infinite((*fit).vertex(0))) 317 OGR_G_AddPoint_2D(currLine,(*fit).vertex(0)->point().x(), 318 (*fit).vertex(0)->point().y()); 319 } 320 OGR_F_SetGeometry( hFeature, currLine ); 321 OGR_G_DestroyGeometry(currLine); 322 if( OGR_L_CreateFeature( poDstLayer, hFeature ) != OGRERR_NONE ){ 323 fprintf( stderr,"Failed to create feature in file.\n" ); 324 exit( 1 ); 325 } 326 OGR_F_Destroy( hFeature ); 327 328 /*OGRFeatureH hFeature=NULL; 329 OGRGeometryH currLine=NULL; 330 if(idg==0) { 331 hFeature = OGR_F_Create( OGR_L_GetLayerDefn( poDstLayer ) ); 332 currLine=OGR_G_CreateGeometry(wkbLineString); 333 }*/ 334 335 for (DelaunayTriangulation::Vertex_iterator vit = dt1.vertices_begin(); vit!= 336 dt1.vertices_end(); ++vit) { 337 idx++; 338 /*if(idg==0) 339 OGR_G_AddPoint_2D(currLine,(*vit).point().x(), 340 (*vit).point().y());*/ 341 342 343 if ((*vit).point() == (*fit).vertex(0)->point()){ 344 i0 = idx; 345 /*OGR_G_AddPoint_2D(currLine,(*fit).vertex(i0)->point().x(), 346 (*fit).vertex(i0)->point().y());**/ 347 } 348 if ((*vit).point() == (*fit).vertex(1)->point()){ 349 i1 = idx; 350 /*OGR_G_AddPoint_2D(currLine,(*fit).vertex(i1)->point().x(), 351 (*fit).vertex(i1)->point().y());*/ 352 } 353 if ((*vit).point() == (*fit).vertex(2)->point()){ 354 i2 = idx; 355 /*OGR_G_AddPoint_2D(currLine,(*fit).vertex(i2)->point().x(), 356 (*fit).vertex(i2)->point().y());*/ 357 } 358 } 359 /*if(idg==0){ 360 OGR_F_SetGeometry( hFeature, currLine ); 361 OGR_G_DestroyGeometry(currLine); 362 if( OGR_L_CreateFeature( poDstLayer, hFeature ) != OGRERR_NONE ){ 363 fprintf( stderr,"Failed to create feature in file.\n" ); 364 exit( 1 ); 365 } 366 OGR_F_Destroy( hFeature ); 367 idg++; 368 }*/ 369 370 std::cerr << "f " << i0 << " " << dt1.triangle(fit) << std::endl; 371 372 } 373 OGR_DS_Destroy( poODS ); 374 OGRCleanupAll(); 375 376 377 char tmp1[1024]; 378 outputs=(maps*)malloc(sizeof(maps*)); 379 outputs->name="Result"; 380 381 FILE * fichier=fopen(pszDestDataSource,"r"); 382 struct stat file_status; 383 stat(pszDestDataSource, &file_status); 384 fprintf(stderr,"%s (%d)",pszDestDataSource,file_status.st_size); 385 char *res1=(char *)malloc(file_status.st_size*sizeof(char)); 386 if(fichier==NULL) 387 fprintf(stderr,"Failed to open file %s for reading purpose.\n",pszDestDataSource); 388 fread(res1,1,(file_status.st_size)*sizeof(char),fichier); 389 res1[strlen(res1)]=0; 390 fclose(fichier); 391 //unlink(pszDestDataSource); 392 //fprintf(stderr,"Read (%s).\n",res1); 393 394 outputs->content=createMap("value",res1); 395 396 if(strcmp(oDriver,"GML")==0) 397 addMapToMap(&outputs->content,createMap("mimeType","text/xml")); 398 else 399 addMapToMap(&outputs->content,createMap("mimeType","text/plain")); 400 401 addMapToMap(&outputs->content,createMap("encoding","UTF-8")); 402 outputs->next=NULL; 403 fprintf(stderr,"\nService internal print\n===\n"); 404 xmlCleanupParser(); 405 406 return SERVICE_SUCCEEDED; 407 } 408 409 410 int Voronoi(maps*& conf,maps*& inputs,maps*& outputs){ 411 fprintf(stderr,"\nService internal print\nStarting\n"); 412 maps* cursor=inputs; 413 OGRGeometryH geometry,res; 414 int bufferDistance; 415 xmlInitParser(); 416 map* tmpm=NULL; 417 tmpm=getMapFromMaps(inputs,"InputPoints","value"); 418 419 xmlInitParser(); 420 xmlDocPtr doc = 421 xmlParseMemory(tmpm->value,strlen(tmpm->value)); 422 xmlNodePtr cur = xmlDocGetRootElement(doc); 423 /** 424 * Parse every Input in DataInputs node. 425 */ 426 maps* tempMaps=NULL; 427 xmlXPathContextPtr xpathCtx; 428 xmlXPathObjectPtr xpathObj; 429 xpathCtx = xmlXPathNewContext(doc); 430 xpathObj = xmlXPathEvalExpression(BAD_CAST "/*/*[local-name()='featureMember']/*/*/*[local-name()='Point']/*[local-name()='coordinates']",xpathCtx); 431 xmlXPathFreeContext(xpathCtx); 432 xmlNodeSet* toto=xpathObj->nodesetval; 433 434 if(toto==NULL) 435 fprintf(stderr,"IMPOSSIBLE DE CONTINUER !!!!\n"); 436 char filepath[2048]; 437 map* tmpMap=getMapFromMaps(conf,"main","tmpPath"); 438 if(tmpMap!=NULL){ 439 sprintf(filepath,"%s/varonoi_%d.tmp",tmpMap->value,getpid()); 440 } 441 FILE *fo=fopen(filepath,"w"); 442 fprintf(stderr,"File Creation (%s) OK\nPrinting %d Points.\n",filepath,toto->nodeNr); 443 for(int k=0;k<toto->nodeNr;k++){ 444 xmlNodePtr cur=toto->nodeTab[k]; 445 char *val= 446 (char*)xmlNodeListGetString(doc,cur->xmlChildrenNode,1); 447 char *tmp=strstr(val,","); 448 char tmp1[1024]; 449 strncpy(tmp1,val,strlen(val)-strlen(tmp)); 450 tmp1[strlen(val)-strlen(tmp)]=0; 451 char buff[1024]; 452 sprintf(buff,"%s %s\n",tmp1,tmp+1); 453 fwrite(buff,1,strlen(buff)*sizeof(char),fo); 454 } 455 fclose(fo); 456 fprintf(stderr,"File Close (%s) OK\n",filepath); 457 458 std::ifstream in(filepath); 459 std::istream_iterator<Point> begin(in); 460 std::istream_iterator<Point> end; 461 Triangulation T; 462 T.insert(begin, end); 463 464 OGRRegisterAll(); 465 /* -------------------------------------------------------------------- */ 466 /* Try opening the output datasource as an existing, writable */ 467 /* -------------------------------------------------------------------- */ 468 OGRDataSource *poODS; 469 470 OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar(); 471 OGRSFDriver *poDriver = NULL; 472 int iDriver; 473 474 tmpMap=getMapFromMaps(outputs,"Result","mimeType"); 475 char *oDriver=(char*)malloc(7*sizeof(char)); 476 oDriver="GeoJSON"; 477 if(tmpMap!=NULL){ 478 if(strcmp(tmpMap->value,"text/xml")==0){ 479 fprintf(stderr,"USEING GML \n"); 480 oDriver="GML"; 481 } 482 } 483 484 for( iDriver = 0; 485 iDriver < poR->GetDriverCount() && poDriver == NULL; 486 iDriver++ ) 487 { 488 #ifdef DEBUG 489 fprintf(stderr,"D:%s\n",poR->GetDriver(iDriver)->GetName()); 490 #endif 491 if( EQUAL(poR->GetDriver(iDriver)->GetName(),oDriver) ) 492 { 493 poDriver = poR->GetDriver(iDriver); 494 } 495 } 496 497 if( poDriver == NULL ) 498 { 499 char emessage[8192]; 500 sprintf( emessage, "Unable to find driver `%s'.\n", oDriver ); 501 sprintf( emessage, "%sThe following drivers are available:\n",emessage ); 502 503 for( iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ ) 504 { 505 sprintf( emessage, "%s -> `%s'\n", emessage, poR->GetDriver(iDriver)->GetName() ); 506 } 507 508 fprintf(stderr,"{\"type\": \"error\", \"%s\"}",emessage); 509 exit( 1 ); 510 } 511 512 if( !poDriver->TestCapability( ODrCCreateDataSource ) ){ 513 char emessage[1024]; 514 sprintf( emessage, "%s driver does not support data source creation.\n", 515 "json" ); 516 fprintf(stderr,"{\"type\": \"error\", \"%s\"}",emessage); 517 exit( 1 ); 162 setMapInMaps(conf,"lenv","message",emessage); 163 return SERVICE_FAILED; 518 164 } 519 165 … … 530 176 sprintf( emessage, "%s driver failed to create %s\n", 531 177 "json", pszDestDataSource ); 532 fprintf(stderr,"{\"type\": \"error\", \"%s\"}",emessage);533 exit( 1 );178 setMapInMaps(conf,"lenv","message",emessage); 179 return SERVICE_FAILED; 534 180 } 535 181 … … 543 189 "Layer %s not found, and CreateLayer not supported by driver.", 544 190 "Result" ); 545 fprintf(stderr,"{\"type\": \"error\",\"message\": \"%s\"}",emessage);546 return FALSE;191 setMapInMaps(conf,"lenv","message",emessage); 192 return SERVICE_FAILED; 547 193 } 548 194 … … 551 197 OGRLayer *poDstLayer = poODS->CreateLayer( "Result", NULL,wkbLineString,NULL); 552 198 if( poDstLayer == NULL ){ 553 fprintf( stderr,"Layer creation failed.\n");554 exit( 1 );199 setMapInMaps(conf,"lenv","message","Layer creation failed.\n"); 200 return SERVICE_FAILED; 555 201 } 556 202 … … 574 220 OGR_G_DestroyGeometry(currLine); 575 221 if( OGR_L_CreateFeature( poDstLayer, hFeature ) != OGRERR_NONE ){ 576 fprintf( stderr,"Failed to create feature in file.\n");577 exit( 1 );222 setMapInMaps(conf,"lenv","message","Failed to create feature in file.\n"); 223 return SERVICE_FAILED; 578 224 } 579 225 OGR_F_Destroy( hFeature ); … … 592 238 593 239 char tmp1[1024]; 594 outputs=(maps*)malloc(sizeof(maps*));595 outputs->name="Result";596 240 597 241 FILE * fichier=fopen(pszDestDataSource,"r"); 598 242 struct stat file_status; 599 243 stat(pszDestDataSource, &file_status); 600 //fprintf(stderr,"%s (%d)",pszDestDataSource,file_status.st_size);601 244 char *res1=(char *)malloc(file_status.st_size*sizeof(char)); 602 if(fichier==NULL) 603 fprintf(stderr,"Failed to open file %s for reading purpose.\n",pszDestDataSource); 245 if(fichier==NULL){ 246 char tmp[1024]; 247 sprintf(tmp,"Failed to open file %s for reading purpose.\n", 248 pszDestDataSource); 249 setMapInMaps(conf,"lenv","message",tmp); 250 return SERVICE_FAILED; 251 } 604 252 fread(res1,1,(file_status.st_size)*sizeof(char),fichier); 605 253 res1[strlen(res1)]=0; 606 254 fclose(fichier); 607 255 unlink(pszDestDataSource); 608 //fprintf(stderr,"Read (%s).\n",res1); 609 610 outputs->content=createMap("value",res1); 256 257 setMapInMaps(outputs,"Result","value",res1); 611 258 612 259 if(strcmp(oDriver,"GML")==0) 613 addMapToMap(&outputs->content,createMap("mimeType","text/xml"));260 setMapInMaps(outputs,"Result","mimeType","text/xml"); 614 261 else 615 addMapToMap(&outputs->content,createMap("mimeType","text/plain"));616 617 addMapToMap(&outputs->content,createMap("encoding","UTF-8"));618 outputs->next=NULL; 262 setMapInMaps(outputs,"Result","mimeType","text/plain"); 263 264 setMapInMaps(outputs,"Result","encoding","UTF-8"); 265 #ifdef DEBUG 619 266 fprintf(stderr,"\nService internal print\n===\n"); 267 #endif 620 268 xmlCleanupParser(); 621 269 return SERVICE_SUCCEEDED; -
branches/branch-1.2/zoo-services/ogr/base-vect-ops/makefile.vc
r1 r217 1 GEODIR=c:/OSGeo4W/ 2 TOOLS=c:/Users/djay/GeoLabs/tools/ 3 CFLAGS=-I$(GEODIR)/include -I$(TOOLS)/include -I../../../zoo-kernel/ -I./ -DLINUX_FREE_ISSUE -DDEBUG 1 ZOODIR=../../../zoo-kernel 2 THIRDSDIR=../../../thirds 3 !INCLUDE $(ZOODIR)/nmake.opt 4 CFLAGS=-I$(GEODIR)/include -I$(TPATH)/include -I$(ZOODIR) -I./ -DLINUX_FREE_ISSUE -DWIN32 #-DDEBUG 4 5 CPP=cl /TP 5 6 6 cgi-env/ service.zo: service.c7 cgi-env/ogr_service.zo: service.c 7 8 $(CPP) $(CFLAGS) /c service.c 8 link /dll /out:cgi-env/ogr_service.z so ../../../zoo-kernel/service_internal.obj ./service.obj -L$(TOOLS)/lib/libssl32.dll.a $(GEODIR)/lib/libxml2.lib $(GEODIR)/lib/gdal_i.lib $(TOOLS)/lib/libeay32.dll.a $(TOOLS)/lib/libcrypto.a $(TOOLS)/lib/libssl32.dll.a9 link /dll /out:cgi-env/ogr_service.zo ../../../zoo-kernel/service_internal.obj ./service.obj -L$(TOOLS)/lib/libssl32.dll.a $(GEODIR)/lib/libxml2.lib $(GEODIR)/lib/gdal_i.lib $(GEODIR)/lib/geos_c_i.lib $(TPATH)/lib/libeay32.dll.a $(TPATH)/lib/libcrypto.a $(TPATH)/lib/libssl32.dll.a $(LIBINTL_CPATH)/lib/libintl.lib 9 10 10 11 clean: 11 rm -f cgi-env/ogr_service.zso12 erase cgi-env\ogr_service.* -
branches/branch-1.2/zoo-services/ogr/base-vect-ops/service.c
r55 r217 43 43 44 44 void printExceptionReportResponse(maps*,map*); 45 char *base64(const unsignedchar *input, int length);45 char *base64(const char *input, int length); 46 46 47 47 OGRGeometryH createGeometryFromGML(maps* conf,char* inputStr){ … … 56 56 xpathObj = xmlXPathEvalExpression(BAD_CAST xpathExpr,xpathCtx); 57 57 if(!xpathObj->nodesetval){ 58 map* tmp=createMap("text","Unable to parse Input Polygon"); 59 addToMap(tmp,"code","InvalidParameterValue"); 60 printExceptionReportResponse(conf,tmp); 61 exit(0); 58 setMapInMaps(conf,"lenv","message",_ss("Unable to parse Input Polygon")); 59 setMapInMaps(conf,"lenv","code","InvalidParameterValue"); 60 return NULL; 62 61 } 63 62 int size = (xpathObj->nodesetval) ? xpathObj->nodesetval->nodeNr : 0; … … 80 79 xmlFreeDoc(doc); 81 80 xmlFreeDoc(ndoc); 81 #ifndef WIN32 82 82 xmlCleanupParser(); 83 #endif 83 84 #ifdef DEBUG 84 85 fprintf(stderr,"\nService internal print\n Loading the geometry from GML string ..."); … … 94 95 } 95 96 97 #ifdef WIN32 98 __declspec(dllexport) 99 #endif 96 100 int Simplify(maps*& conf,maps*& inputs,maps*& outputs){ 97 101 maps* cursor=inputs; … … 104 108 else 105 109 tolerance=atof(tmp0->value); 110 #ifdef DEBUG 106 111 fprintf(stderr,"Tolerance for Simplify %f",tolerance); 112 #endif 107 113 map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); 108 114 if(!tmp){ … … 126 132 return SERVICE_FAILED; 127 133 } 134 #ifdef DEBUG 128 135 fprintf(stderr,"Create GEOSGeometry object"); 136 #endif 129 137 GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS(); 130 138 GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance); 131 res= OGRGeometryFactory::createFromGEOS(gres);139 res=(OGRGeometryH)OGRGeometryFactory::createFromGEOS(gres); 132 140 tmp1=getMapFromMaps(outputs,"Result","mimeType"); 133 141 if(tmp1!=NULL){ … … 136 144 char *tmpS=OGR_G_ExportToJson(res); 137 145 setMapInMaps(outputs,"Result","value",tmpS); 146 #ifndef WIN32 138 147 setMapInMaps(outputs,"Result","mimeType","text/plain"); 139 148 setMapInMaps(outputs,"Result","encoding","UTF-8"); 140 149 free(tmpS); 150 #endif 141 151 } 142 152 else{ 143 153 char *tmpS=OGR_G_ExportToGML(res); 144 154 setMapInMaps(outputs,"Result","value",tmpS); 155 #ifndef WIN32 145 156 setMapInMaps(outputs,"Result","mimeType","text/xml"); 146 157 setMapInMaps(outputs,"Result","encoding","UTF-8"); 147 158 setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd"); 148 159 free(tmpS); 160 #endif 149 161 } 150 162 }else{ 151 char *tmpS=OGR_G_ExportToJson( tmp->value);163 char *tmpS=OGR_G_ExportToJson(res); 152 164 setMapInMaps(outputs,"Result","value",tmpS); 165 #ifndef WIN32 153 166 setMapInMaps(outputs,"Result","mimeType","text/plain"); 154 167 setMapInMaps(outputs,"Result","encoding","UTF-8"); 155 168 free(tmpS); 169 #endif 156 170 } 157 171 outputs->next=NULL; … … 178 192 return SERVICE_FAILED; 179 193 } 194 #ifdef DEBUG 180 195 fprintf(stderr,"Service internal print \n"); 181 196 dumpMaps(inputs); 182 197 fprintf(stderr,"/Service internal print \n"); 198 #endif 183 199 map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); 200 #ifdef DEBUG 184 201 fprintf(stderr,"Service internal print \n"); 185 202 dumpMap(tmp1); 186 203 fprintf(stderr,"/Service internal print \n"); 204 #endif 187 205 if(tmp1!=NULL){ 188 206 if(strncmp(tmp1->value,"text/js",7)==0 || … … 199 217 } 200 218 res=(*myFunc)(geometry); 219 #ifdef DEBUG 201 220 fprintf(stderr,"Service internal print \n"); 202 221 dumpMaps(outputs); 203 222 fprintf(stderr,"/Service internal print \n"); 223 #endif 204 224 map *tmp_2=getMapFromMaps(outputs,"Result","mimeType"); 225 #ifdef DEBUG 205 226 fprintf(stderr,"Service internal print \n"); 206 227 dumpMap(tmp_2); 207 228 fprintf(stderr,"/Service internal print \n"); 229 #endif 208 230 if(tmp_2!=NULL){ 209 231 if(strncmp(tmp_2->value,"text/js",7)==0 || … … 211 233 char *tmpS=OGR_G_ExportToJson(res); 212 234 setMapInMaps(outputs,"Result","value",tmpS); 235 #ifndef WIN32 213 236 setMapInMaps(outputs,"Result","mimeType","text/plain"); 214 237 setMapInMaps(outputs,"Result","encoding","UTF-8"); 215 238 free(tmpS); 239 #endif 216 240 } 217 241 else{ 218 242 char *tmpS=OGR_G_ExportToGML(res); 219 243 setMapInMaps(outputs,"Result","value",tmpS); 244 #ifndef WIN32 220 245 setMapInMaps(outputs,"Result","mimeType","text/xml"); 221 246 setMapInMaps(outputs,"Result","encoding","UTF-8"); 222 247 setMapInMaps(outputs,"Result","schema",schema); 223 248 free(tmpS); 249 #endif 224 250 } 225 251 }else{ 226 252 char *tmpS=OGR_G_ExportToJson(res); 227 253 setMapInMaps(outputs,"Result","value",tmpS); 254 #ifndef WIN32 228 255 setMapInMaps(outputs,"Result","mimeType","text/plain"); 229 256 setMapInMaps(outputs,"Result","encoding","UTF-8"); 230 257 free(tmpS); 231 } 232 outputs->next=NULL; 258 #endif 259 } 260 //outputs->next=NULL; 233 261 #ifdef DEBUG 234 262 dumpMaps(outputs); … … 239 267 //CPLFree(res); 240 268 //CPLFree(geometry); 269 #ifdef DEBUG 241 270 fprintf(stderr,"Service internal print \n"); 242 271 dumpMaps(outputs); 243 272 fprintf(stderr,"/Service internal print \n"); 273 #endif 244 274 return SERVICE_SUCCEEDED; 245 275 } … … 276 306 bufferDistance=atof(tmp->value); 277 307 res=OGR_G_Buffer(geometry,bufferDistance,30); 308 dumpMap(tmp); 278 309 tmp1=getMapFromMaps(outputs,"Result","mimeType"); 310 dumpMap(tmp); 279 311 if(strncmp(tmp1->value,"application/json",16)==0){ 280 312 char *tmpS=OGR_G_ExportToJson(res); 281 313 setMapInMaps(outputs,"Result","value",tmpS); 314 dumpMap(tmp); 315 #ifndef WIN32 282 316 setMapInMaps(outputs,"Result","mimeType","text/plain"); 283 317 setMapInMaps(outputs,"Result","encoding","UTF-8"); 284 318 free(tmpS); 319 #endif 285 320 } 286 321 else{ 287 322 char *tmpS=OGR_G_ExportToGML(res); 288 323 setMapInMaps(outputs,"Result","value",tmpS); 324 dumpMap(tmp); 325 #ifndef WIN32 289 326 free(tmpS); 290 327 setMapInMaps(outputs,"Result","mimeType","text/xml"); 291 328 setMapInMaps(outputs,"Result","encoding","UTF-8"); 292 329 setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd"); 330 #endif 293 331 } 294 outputs->next=NULL;332 //outputs->next=NULL; 295 333 OGR_G_DestroyGeometry(geometry); 296 334 OGR_G_DestroyGeometry(res); … … 335 373 fprintf(stderr,"\nService internal print1\n"); 336 374 fflush(stderr); 337 #endif338 375 fprintf(stderr,"\nService internal print1\n"); 339 376 dumpMaps(inputs); 340 377 fprintf(stderr,"\nService internal print1\n"); 378 #endif 341 379 342 380 maps* cursor=inputs; … … 357 395 if(geometry1==NULL){ 358 396 setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1.")); 397 #ifdef DEBUG 359 398 fprintf(stderr,"SERVICE FAILED !\n"); 360 return SERVICE_FAILED; 361 } 399 #endif 400 return SERVICE_FAILED; 401 } 402 #ifdef DEBUG 362 403 fprintf(stderr,"\nService internal print1 InputEntity1\n"); 404 #endif 363 405 { 364 406 map* tmp=getMapFromMaps(inputs,"InputEntity2","value"); 365 407 map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType"); 366 //#ifdef DEBUG408 #ifdef DEBUG 367 409 fprintf(stderr,"MY MAP \n[%s] - %i\n",tmp1->value,strncmp(tmp1->value,"application/json",16)); 368 410 //dumpMap(tmp); 369 411 fprintf(stderr,"MY MAP\n"); 370 ///#endif371 412 fprintf(stderr,"\nService internal print1 InputEntity2\n"); 413 #endif 372 414 if(tmp1!=NULL){ 373 415 if(strncmp(tmp1->value,"application/json",16)==0){ 416 #ifdef DEBUG 374 417 fprintf(stderr,"\nService internal print1 InputEntity2 as JSON\n"); 418 #endif 375 419 geometry2=OGR_G_CreateGeometryFromJson(tmp->value); 376 420 } 377 421 else{ 422 #ifdef DEBUG 378 423 fprintf(stderr,"\nService internal print1 InputEntity2 as GML\n"); 424 #endif 379 425 geometry2=createGeometryFromGML(conf,tmp->value); 380 426 } … … 382 428 else 383 429 geometry2=createGeometryFromGML(conf,tmp->value); 430 #ifdef DEBUG 384 431 fprintf(stderr,"\nService internal print1 InputEntity2 PreFinal\n"); 385 } 432 #endif 433 } 434 #ifdef DEBUG 386 435 fprintf(stderr,"\nService internal print1 InputEntity2 Final\n"); 436 #endif 387 437 if(geometry2==NULL){ 388 438 setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2.")); 439 #ifdef DEBUG 389 440 fprintf(stderr,"SERVICE FAILED !\n"); 390 return SERVICE_FAILED; 391 } 441 #endif 442 return SERVICE_FAILED; 443 } 444 #ifdef DEBUG 392 445 fprintf(stderr,"\nService internal print1\n"); 446 #endif 393 447 res=(*myFunc)(geometry1,geometry2); 448 #ifdef DEBUG 394 449 fprintf(stderr,"\nService internal print1\n"); 395 450 #endif 396 451 /* nuova parte */ 397 452 map* tmp2=getMapFromMaps(outputs,"Result","mimeType"); … … 399 454 char *tmpS=OGR_G_ExportToJson(res); 400 455 setMapInMaps(outputs,"Result","value",tmpS); 456 #ifndef WIN32 401 457 setMapInMaps(outputs,"Result","mimeType","text/plain"); 402 458 setMapInMaps(outputs,"Result","encoding","UTF-8"); 403 459 free(tmpS); 460 #endif 404 461 } 405 462 else{ 406 463 char *tmpS=OGR_G_ExportToGML(res); 407 464 setMapInMaps(outputs,"Result","value",tmpS); 465 #ifndef WIN32 408 466 setMapInMaps(outputs,"Result","mimeType","text/xml"); 409 467 setMapInMaps(outputs,"Result","encoding","UTF-8"); 410 468 setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd"); 411 469 free(tmpS); 470 #endif 412 471 } 413 472 -
branches/branch-1.2/zoo-services/utils/status/service.c
r34 r217 24 24 25 25 #include "service.h" 26 #ifdef WIN32 27 #include <windows.h> 28 #endif 26 29 27 30 extern "C" { … … 135 138 setMapInMaps(conf,"lenv","status",tmp); 136 139 updateStatus(conf); 140 #ifndef WIN32 137 141 sleep(1); 142 #else 143 Sleep(1000); 144 #endif 138 145 i+=5; 139 146 }
Note: See TracChangeset
for help on using the changeset viewer.