Changeset 26 for trunk/zoo-services


Ignore:
Timestamp:
Sep 24, 2010, 5:11:43 AM (14 years ago)
Author:
djay
Message:

ZOO-Kernel updates and bug fixes :

  • Fixing gestion of RawDataOutput? when the Service return SERVICE_FAILED an ExceptionReport? was returned to the client.
  • Use gcc when compiling service_internal.c to avoid strange error messages about switch ....
  • Function setMapInMaps was added in service.h to let users set the value of a specific map in a maps.
  • Fixing JavaScript? issue during the context destruction process.
  • Use the GetStatus? ZOO Service when it is available on the local installation for statusLocation.
  • Add some comments for ServiceStarted?, ServiceSucceeded?, ServiceFailed? and ServiceAccepted?.
  • Dynamic creation of a lenv maps in the main configuration file maps, containing the current status and a sid (Service ID). Those informations can be used later by the GetStatus? Service to let user check the on-going status during the Service runs.
  • Function updateStatus was added to service_internal.h which let the Services developers set the current percentCompleted value.

ZOO-Service updates and bug fixes :

  • Add GetStatus? Service and its demo longProcess Service. All are in the wps_status.zo Services Provider.
  • Use the setMapInMaps in the base-vect-ops code to enhance readibility.

ZOO-API updates :

  • Add the function ZOO.UpdateStatus? to the ZOO JavaScript? API which simply point on ZOOUpdateStatus which can be called as-is from JavaScript?. Use : ZOOUpdateStatus(conf,value) where conf is the main configuration file maps and value the the value of the current status.
Location:
trunk/zoo-services
Files:
7 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-services/ogr/base-vect-ops/Makefile

    r9 r26  
    1 CFLAGS=-I../../../zoo-kernel/ -I./ `xml2-config --cflags` `python-config --cflags`  `gdal-config --cflags`   -DLINUX_FREE_ISSUE #-DDEBUG
    2 CC=gcc
     1CFLAGS=-I../../../zoo-kernel/ -I./ `xsl-config --cflags`  `gdal-config --cflags`  -DLINUX_FREE_ISSUE #-DDEBUG
     2# if JS_ENABLED flag is set to true in your ZOO-Kernel Makefile then you'll have
     3# uncomment the following line
     4# JS_LDFLAGS=../../../zoo-kernel/ulinet.o ../../../zoo-kernel/service_internal_js.o
    35
    4 cgi-env/service.zo: service.c
    5         g++ ${CFLAGS} -shared -fpic -o cgi-env/ogr_service.zo ./service.c ../../../zoo-kernel/service_internal.o `gdal-config --libs`
     6cgi-env/ogr_service.zo: service.c
     7        g++ ${CFLAGS} -shared -fpic -o cgi-env/ogr_service.zo ./service.c ../../../zoo-kernel/service_internal.o ${JS_LDFLAGS} `xsl-config --libs` `gdal-config --libs` `geos-config --libs`
    68
    79clean:
  • trunk/zoo-services/ogr/base-vect-ops/service.c

    r9 r26  
    7474    char *tmp=(char*)calloc((xmlStrlen(xmlStrstr(xmlbuff,BAD_CAST "?>"))-1),sizeof(char));
    7575    sprintf(tmp,"%s",xmlStrstr(xmlbuff,BAD_CAST "?>")+2);
    76     //strdup(strstr((char*)xmlbuff,"?>")+2);
    7776    xmlXPathFreeObject(xpathObj);
    7877    xmlXPathFreeContext(xpathCtx);
     
    8786    free(tmp);
    8887    if(res==NULL){
    89       map* tmp=createMap("text","Unable to call OGR_G_CreatFromGML");
    90       addToMap(tmp,"code","NoApplicableCode");
    91       printExceptionReportResponse(conf,tmp);
    92       exit(0);
     88      setMapInMaps(conf,"lenv","message","Unable to call OGR_G_CreatFromGML");
     89      return NULL;
    9390    }
    9491    else
    95       return res;//OGR_G_CreateFromGML(tmp);
     92      return res;
    9693  }
    9794
     
    108105    fprintf(stderr,"Tolerance for Simplify %f",tolerance);
    109106    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
    110     if(!tmp)
    111       return SERVICE_FAILED;
    112     map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeTime");
     107    if(!tmp){
     108      setMapInMaps(conf,"lenv","message","Unagle to parse the input geometry from InputPolygon");
     109      return SERVICE_FAILED;
     110    }
     111    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
    113112    if(tmp1!=NULL){
    114113      if(strncmp(tmp1->value,"text/js",7)==0 ||
    115          strncmp(tmp1->value,"application/json",7)==0)
     114         strncmp(tmp1->value,"application/json",16)==0)
    116115        geometry=OGR_G_CreateGeometryFromJson(tmp->value);
    117116      else
    118117        geometry=createGeometryFromGML(conf,tmp->value);
    119118    }
    120     else
    121       geometry=createGeometryFromGML(conf,tmp->value);
     119    else{
     120      setMapInMaps(conf,"lenv","message","Unable to find any geometry for InputPolygon");
     121      return SERVICE_FAILED;
     122    }
     123    if(geometry==NULL){
     124      setMapInMaps(conf,"lenv","message","Unagle to parse the input geometry from InputPolygon");
     125      return SERVICE_FAILED;
     126    }
     127    fprintf(stderr,"Create GEOSGeometry object");
    122128    GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS();
    123129    GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance);
    124130    res=OGRGeometryFactory::createFromGEOS(gres);
     131    tmp1=getMapFromMaps(outputs,"Result","mimeType");
    125132    if(tmp1!=NULL){
    126133      if(strncmp(tmp1->value,"text/js",7)==0 ||
    127134         strncmp(tmp1->value,"application/json",16)==0){
    128         outputs->content=createMap("value",OGR_G_ExportToJson(tmp->value));
    129         addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    130         addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
     135        char *tmpS=OGR_G_ExportToJson(res);
     136        setMapInMaps(outputs,"Result","value",tmpS);
     137        setMapInMaps(outputs,"Result","mimeType","text/plain");
     138        setMapInMaps(outputs,"Result","encoding","UTF-8");
     139        free(tmpS);
    131140      }
    132141      else{
    133         outputs->content=createMap("value",OGR_G_ExportToGML(res));
    134         addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
    135         addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    136         addMapToMap(&outputs->content,createMap("schema","http://fooa/gml/3.1.0/polygon.xsd"));
     142        char *tmpS=OGR_G_ExportToGML(res);
     143        setMapInMaps(outputs,"Result","value",tmpS);
     144        setMapInMaps(outputs,"Result","mimeType","text/xml");
     145        setMapInMaps(outputs,"Result","encoding","UTF-8");
     146        setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
     147        free(tmpS);
    137148      }
    138149    }else{
    139       outputs->content=createMap("value",OGR_G_ExportToJson(res));
    140       addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    141       addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
     150      char *tmpS=OGR_G_ExportToJson(tmp->value);
     151      setMapInMaps(outputs,"Result","value",tmpS);
     152      setMapInMaps(outputs,"Result","mimeType","text/plain");
     153      setMapInMaps(outputs,"Result","encoding","UTF-8");
     154      free(tmpS);
    142155    }
    143156    outputs->next=NULL;
     
    178191    else
    179192      geometry=createGeometryFromGML(conf,tmp->value);
     193    if(geometry==NULL)
     194      return SERVICE_FAILED;
    180195    res=(*myFunc)(geometry);
    181196    fprintf(stderr,"Service internal print \n");
     
    189204      if(strncmp(tmp_2->value,"text/js",7)==0 ||
    190205         strncmp(tmp_2->value,"application/json",16)==0){
    191         char *tres=OGR_G_ExportToJson(res);
    192         addToMap(outputs->content,"value",tres);
    193         free(tres);
    194         addToMap(outputs->content,"mimeType","text/plain");
    195         addToMap(outputs->content,"encoding","UTF-8");
     206        char *tmpS=OGR_G_ExportToJson(res);
     207        setMapInMaps(outputs,"Result","value",tmpS);
     208        setMapInMaps(outputs,"Result","mimeType","text/plain");
     209        setMapInMaps(outputs,"Result","encoding","UTF-8");
     210        free(tmpS);
    196211      }
    197212      else{
    198         char *tres=OGR_G_ExportToGML(res);
    199         addToMap(outputs->content,"value",tres);
    200         free(tres);
     213        char *tmpS=OGR_G_ExportToGML(res);
     214        setMapInMaps(outputs,"Result","value",tmpS);
     215        setMapInMaps(outputs,"Result","mimeType","text/plain");
     216        setMapInMaps(outputs,"Result","encoding","UTF-8");
     217        free(tmpS);
     218
    201219      }
    202220    }else{
    203       char *tres=OGR_G_ExportToJson(res);
    204       addToMap(outputs->content,"value",tres);
    205       free(tres);
    206       addToMap(outputs->content,"mimeType","text/plain");
    207       addToMap(outputs->content,"encoding","UTF-8");
     221      char *tmpS=OGR_G_ExportToJson(res);
     222      setMapInMaps(outputs,"Result","value",tmpS);
     223      setMapInMaps(outputs,"Result","mimeType","text/plain");
     224      setMapInMaps(outputs,"Result","encoding","UTF-8");
     225      free(tmpS);
    208226    }
    209227    outputs->next=NULL;
     
    235253   else
    236254     geometry=createGeometryFromGML(conf,tmp->value);
    237    int bufferDistance=1;
     255   if(geometry==NULL){
     256     setMapInMaps(conf,"lenv","message","Unable to parse input geometry");
     257     return SERVICE_FAILED;
     258   }
     259   double bufferDistance;
    238260   tmp=getMapFromMaps(inputs,"BufferDistance","value");
    239    if(tmp!=NULL)
    240                 bufferDistance=atoi(tmp->value);
     261   if(tmp==NULL){
     262     bufferDistance=atof("10.0");
     263   }
     264   else
     265     bufferDistance=atof(tmp->value);
    241266   res=OGR_G_Buffer(geometry,bufferDistance,30);
    242267   tmp1=getMapFromMaps(outputs,"Result","mimeType");
    243268   if(strncmp(tmp1->value,"application/json",16)==0){
    244                 addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
    245                 addToMap(outputs->content,"mimeType","text/plain");
     269     char *tmpS=OGR_G_ExportToJson(res);
     270     setMapInMaps(outputs,"Result","value",tmpS);
     271     setMapInMaps(outputs,"Result","mimeType","text/plain");
     272     setMapInMaps(outputs,"Result","encoding","UTF-8");
     273     free(tmpS);
    246274   }
    247275   else{
    248                 addToMap(outputs->content,"value",OGR_G_ExportToGML(res));
     276     char *tmpS=OGR_G_ExportToGML(res);
     277     setMapInMaps(outputs,"Result","value",tmpS);
     278     setMapInMaps(outputs,"Result","mimeType","text/xml");
     279     setMapInMaps(outputs,"Result","encoding","UTF-8");
     280     setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
    249281   }
    250282   outputs->next=NULL;
     
    254286}
    255287
    256 /*  int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
    257 #ifdef DEBUG
    258     fprintf(stderr,"\nService internal print\n");
    259 #endif
    260     maps* cursor=inputs;
    261     OGRGeometryH geometry,res;
    262     int bufferDistance;   
    263     if(cursor!=NULL){
    264 #ifdef DEBUG
    265       fprintf(stderr,"\nService internal print\n");
    266       dumpMaps(cursor);
    267       fprintf(stderr,"\nService internal print\n");
    268       dumpMaps(inputs);
    269       fprintf(stderr,"\nService internal print\n");
    270 #endif
    271       map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
    272       map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
    273       if(tmp1!=NULL){
    274         if(strncmp(tmp1->value,"application/json",16)==0 ||
    275            strncmp(tmp1->value,"text/js",7)==0)
    276           geometry=OGR_G_CreateGeometryFromJson(tmp->value);
    277         else
    278           geometry=createGeometryFromGML(conf,tmp->value);
    279       }
    280       else
    281         geometry=createGeometryFromGML(conf,tmp->value);
    282     }
    283     if(cursor!=NULL){
    284       map* tmp=getMapFromMaps(cursor,"BufferDistance","value");
    285       if(tmp==NULL){
    286         bufferDistance=10;
    287       }
    288       else
    289         bufferDistance=atoi(tmp->value);
    290 #ifdef DEBUG
    291       fprintf(stderr,"\nService internal print (BufferDistance value: %i)\n",bufferDistance);
    292 #endif
    293     }
    294 #ifdef DEBUG
    295     dumpMaps(outputs);
    296 #endif
    297     map* tmp=getMapFromMaps(outputs,"Result","mimeType");
    298     res=OGR_G_Buffer(geometry,bufferDistance,30);
    299 #ifdef DEBUG
    300     dumpMap(tmp);
    301 #endif
    302     if(tmp!=NULL){
    303 #ifdef DEBUG
    304       dumpMap(tmp);
    305 #endif
    306       if(strncmp(tmp->value,"application/json",16)==0){
    307         addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
    308         addToMap(outputs->content,"mimeType","text/plain");
    309         addToMap(outputs->content,"encoding","UTF-8");
    310       }
    311       else if(strcmp(tmp->value,"text/xml")==0){
    312         xmlInitParser();
    313         xmlDocPtr doc = xmlParseMemory(tmp->value,strlen(tmp->value));
    314         xmlChar *xmlbuff;
    315         int buffersize;
    316         char *buff=OGR_G_ExportToGML(res);
    317         addToMap(outputs->content,"value",buff);
    318         map* tmp1=getMapFromMaps(outputs,"Result","encoding");
    319         if(tmp1!=NULL)
    320           addToMap(outputs->content,"encoding",tmp1->value);
    321         else
    322           addToMap(outputs->content,"encoding","UTF-8");
    323         xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
    324         xmlFree(xmlbuff);
    325         xmlFreeDoc(doc);
    326         xmlCleanupParser();
    327       }
    328       else{
    329         addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
    330         addToMap(outputs->content,"mimeType","text/plain");
    331         addToMap(outputs->content,"encoding","UTF-8");
    332         outputs->next=NULL;
    333       }
    334       outputs->next=NULL;
    335     }
    336     else{
    337       addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
    338       addToMap(outputs->content,"mimeType","text/plain");
    339       addToMap(outputs->content,"encoding","UTF-8");
    340       outputs->next=NULL;
    341     }
    342     outputs->next=NULL;
    343 #ifdef DEBUG
    344     dumpMaps(outputs);
    345     fprintf(stderr,"\nService internal print\n===\n");
    346 #endif
    347     OGR_G_DestroyGeometry(geometry);
    348     OGR_G_DestroyGeometry(res);
    349     return SERVICE_SUCCEEDED;
    350   }
    351 */
    352 
    353288#ifdef WIN32
    354289  __declspec(dllexport)
     
    387322#ifdef DEBUG
    388323    fprintf(stderr,"\nService internal print1\n");
    389 #endif
    390324    fflush(stderr);
     325#endif
     326    fprintf(stderr,"\nService internal print1\n");
     327    dumpMaps(inputs);
     328    fprintf(stderr,"\nService internal print1\n");
    391329
    392330    maps* cursor=inputs;
     
    405343        geometry1=createGeometryFromGML(conf,tmp->value);
    406344    }
     345    if(geometry1==NULL){
     346      setMapInMaps(conf,"lenv","message","Unable to parse input geometry for InputEntity1.");
     347      fprintf(stderr,"SERVICE FAILED !\n");
     348      return SERVICE_FAILED;
     349    }
     350    fprintf(stderr,"\nService internal print1 InputEntity1\n");
    407351    {
    408352      map* tmp=getMapFromMaps(inputs,"InputEntity2","value");
    409353      map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType");
    410 #ifdef DEBUG
     354      //#ifdef DEBUG
     355      fprintf(stderr,"MY MAP \n[%s] - %i\n",tmp1->value,strncmp(tmp1->value,"application/json",16));
     356      //dumpMap(tmp);
    411357      fprintf(stderr,"MY MAP\n");
    412       dumpMap(tmp1);
    413       fprintf(stderr,"MY MAP\n");
    414 #endif
     358      ///#endif
     359      fprintf(stderr,"\nService internal print1 InputEntity2\n");
    415360      if(tmp1!=NULL){
    416         if(strncmp(tmp1->value,"application/json",16)==0)
     361        if(strncmp(tmp1->value,"application/json",16)==0){
     362          fprintf(stderr,"\nService internal print1 InputEntity2 as JSON\n");
    417363          geometry2=OGR_G_CreateGeometryFromJson(tmp->value);
    418         else
     364        }
     365        else{
     366          fprintf(stderr,"\nService internal print1 InputEntity2 as GML\n");
    419367          geometry2=createGeometryFromGML(conf,tmp->value);
     368        }
    420369      }
    421370      else
    422371        geometry2=createGeometryFromGML(conf,tmp->value);
    423     }
     372      fprintf(stderr,"\nService internal print1 InputEntity2 PreFinal\n");
     373    }
     374    fprintf(stderr,"\nService internal print1 InputEntity2 Final\n");
     375    if(geometry2==NULL){
     376      setMapInMaps(conf,"lenv","message","Unable to parse input geometry for InputEntity2.");
     377      fprintf(stderr,"SERVICE FAILED !\n");
     378      return SERVICE_FAILED;
     379    }
     380    fprintf(stderr,"\nService internal print1\n");
    424381    res=(*myFunc)(geometry1,geometry2);
    425     addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
    426     addToMap(outputs->content,"mimeType","text/plain");
    427     addToMap(outputs->content,"encoding","UTF-8");
    428     outputs->next=NULL;
     382    fprintf(stderr,"\nService internal print1\n");
     383    char *tmpS=OGR_G_ExportToJson(res);
     384    setMapInMaps(outputs,"Result","value",tmpS);
     385    setMapInMaps(outputs,"Result","mimeType","text/plain");
     386    setMapInMaps(outputs,"Result","encoding","UTF-8");
     387    free(tmpS);
    429388    OGR_G_DestroyGeometry(geometry1);
    430389    OGR_G_DestroyGeometry(geometry2);
     
    469428#endif
    470429    fflush(stderr);
    471 
    472430    maps* cursor=inputs;
    473431    OGRGeometryH geometry1,geometry2;
     
    491449        geometry1=createGeometryFromGML(conf,tmp->value);
    492450    }
     451    if(geometry1==NULL){
     452      setMapInMaps(conf,"lenv","message","Unable to parse input geometry for InputEntity1.");
     453      fprintf(stderr,"SERVICE FAILED !\n");
     454      return SERVICE_FAILED;
     455    }
    493456    {
    494457      map* tmp=getMapFromMaps(inputs,"InputEntity2","value");
     
    509472        geometry2=createGeometryFromGML(conf,tmp->value);
    510473    }
    511     res=OGR_G_Distance(geometry1,geometry2);
    512     outputs=(maps*)malloc(sizeof(maps*));
    513     outputs->name="Distance";
     474    if(geometry2==NULL){
     475      setMapInMaps(conf,"lenv","message","Unable to parse input geometry for InputEntity2.");
     476      fprintf(stderr,"SERVICE FAILED !\n");
     477      return SERVICE_FAILED;
     478    }
     479    res=OGR_G_Distance(geometry1,geometry2);   
    514480    char tmpres[100];
    515481    sprintf(tmpres,"%d",res);
    516     outputs->content=createMap("value",tmpres);
    517     addMapToMap(&outputs->content,createMap("datatype","float"));
    518     outputs->next=NULL;
     482    setMapInMaps(outputs,"Distance","value",tmpres);
     483    setMapInMaps(outputs,"Distance","dataType","float");
    519484#ifdef DEBUG
    520485    dumpMaps(outputs);
     
    531496    double res;
    532497    /**
    533      * Extract Geometry from the InputEntity1 value
     498     * Extract Geometry from the InputPolygon value
    534499     */
    535     OGRGeometryH geometry1;
    536     map* tmp=getMapFromMaps(inputs,"InputEntity1","value");
     500    OGRGeometryH geometry;
     501    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
     502    if(tmp==NULL){
     503      setMapInMaps(conf,"lenv","message","Unable to parse input geometry from InputPolygon");
     504      return SERVICE_FAILED;
     505    }
    537506    fprintf(stderr,"geometry creation %s \n",tmp->value);
    538     geometry1=createGeometryFromGML(conf,tmp->value);
     507    geometry=createGeometryFromGML(conf,tmp->value);
     508    if(geometry==NULL){
     509      setMapInMaps(conf,"lenv","message","Unable to parse input geometry from InputPolygon");
     510      return SERVICE_FAILED;
     511    }
    539512    fprintf(stderr,"geometry created %s \n",tmp->value);
    540     res=OGR_G_GetArea(geometry1);
     513    res=OGR_G_GetArea(geometry);
    541514    fprintf(stderr,"area %d \n",res);
    542515    /**
    543      * Creating the outputs
     516     * Filling the outputs
    544517     */
    545     outputs=(maps*)malloc(sizeof(maps*));
    546     outputs->name="Area";
    547518    char tmp1[100];
    548519    sprintf(tmp1,"%d",res);
    549     outputs->content=createMap("value",tmp1);
    550     addMapToMap(&outputs->content,createMap("datatype","float"));
    551     outputs->next=NULL;
     520    setMapInMaps(outputs,"Area","value",tmp1);
     521    setMapInMaps(outputs,"Area","dataType","float");
    552522#ifdef DEBUG
    553523    dumpMaps(outputs);
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

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