Ignore:
Timestamp:
Sep 14, 2010, 2:04:55 PM (14 years ago)
Author:
djay
Message:

Update of both ZOO Kernel and ZOO Services (ogr base-vect-ops ServicesProvider?).
All the ZCFG files have been corrected to remove all references to wrong metadata (Test = Demo) to avoid validation issues.
Main Memory leaks has been removed from this version.
Addition of the Simplify Service in the C ogr base-vect-ops ServicesProvider? and addition of the Python version (without Simplify).
Update of the configure.ac and Makefile.in to follow dicussions on the mailing list and ensure to use our cgic206 and not another one, path to our cgic library is now directly in the Makefile.in file.
Accept the "-" character to name inputs, to solve issue on GRASS 7 integration.
Addition of the extension keyword for ZCFG file to be able to store resulting outputs in a file name using the extension suffix.
This version after a testing period shall be considerate as 1.0.1 version of the ZOO Project.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-kernel/service_internal_js.c

    r1 r9  
    3030                   maps **inputs,maps **outputs)
    3131{
     32  maps* main=*main_conf;
     33  maps* _inputs=*inputs;
     34  maps* _outputs=*outputs;
     35
    3236  /* The class of the global object. */
    3337  JSClass global_class = {
     
    4751  if (rt == NULL)
    4852    return 1;
    49 
     53 
    5054  /* Create a context. */
    51   cx = JS_NewContext(rt, 8192);
     55  cx = JS_NewContext(rt,8192);
    5256  if (cx == NULL){
    5357    return 1;
     
    7882  map* tmpm1=getMap(request,"metapath");
    7983  map* tmpm2=getMap(s->content,"serviceProvider");
    80   char *filename[strlen(tmpm1->value)+strlen(tmpm2->value)+6];
     84  char filename[strlen(tmpm1->value)+strlen(tmpm2->value)+6];
    8185  char ntmp[1024];
    8286  getcwd(ntmp,1024);
     
    8791  uint16 lineno;
    8892  jsval rval;
    89   FILE *jsfile=fopen(filename,"rb");
     93  FILE *jsfile=fopen(filename,"r");
    9094  JSBool ok ;
    91   JSScript *script = JS_CompileFileHandle(cx, global, filename, jsfile);
    92   if(script){
     95  JSScript *script = JS_CompileFileHandle(cx, global, filename,jsfile);
     96  if(script!=NULL){
    9397    (void)JS_ExecuteScript(cx, global, script, &rval);
    9498  }
     
    102106    JS_DestroyRuntime(rt);
    103107    JS_ShutDown();
     108    fclose(jsfile);
    104109    exit(-1);
    105110  }
    106111  /* Call a function in obj's scope. */
    107112  jsval argv[3];
    108   argv[0] = OBJECT_TO_JSVAL(JSObject_FromMaps(cx,*main_conf));
    109   argv[1] = OBJECT_TO_JSVAL(JSObject_FromMaps(cx,*inputs));
    110   argv[2] = OBJECT_TO_JSVAL(JSObject_FromMaps(cx,*outputs));
    111   jsval rval1;
     113  JSObject *jsargv1=JSObject_FromMaps(cx,*main_conf);
     114  argv[0] = OBJECT_TO_JSVAL(jsargv1);
     115  JSObject *jsargv2=JSObject_FromMaps(cx,*inputs);
     116  argv[1] = OBJECT_TO_JSVAL(jsargv2);
     117  JSObject *jsargv3=JSObject_FromMaps(cx,*outputs);
     118  argv[2] = OBJECT_TO_JSVAL(jsargv3);
     119  jsval rval1=JSVAL_NULL;
    112120#ifdef JS_DEBUG
    113121  fprintf(stderr, "object %p\n", (void *) argv[2]);
     
    121129
    122130  JSObject *d;
    123   if (ok==JS_TRUE) {
     131  if (ok==JS_TRUE && JSVAL_IS_OBJECT(rval1)==JS_TRUE) {
    124132#ifdef JS_DEBUG
    125133    fprintf(stderr,"Function run sucessfully !\n");
     
    127135    /* Should get a number back from the service function call. */
    128136    ok = JS_ValueToObject(cx, rval1, &d);
    129     if (ok==JS_TRUE) {
    130 #ifdef JS_DEBUG
    131       fprintf(stderr,"Function run sucessfully !\n");
    132 #endif
    133       /*char tmpres[10];
    134       sprintf(tmpres,"%p",(void *)d);
    135       res=atoi(tmpres);*/
    136     }
    137137  }else{
    138138    /* Unable to run JS function */
    139139    char tmp1[1024];
    140     //sprintf(tmp1,"Unable to run %s from the JavScript file %s",s->name,filename);
     140    if(strlen(dbg)==0)
     141      sprintf(dbg,"No result was found after the function call");
    141142    sprintf(tmp1,"Unable to run %s from the JavScript file %s : \n %s",s->name,filename,dbg);
    142143    fprintf(stderr,"%s",tmp1);
    143144    map* err=createMap("text",tmp1);
    144     addMapToMap(err,createMap("code","NoApplicableCode"));
     145    addToMap(err,"code","NoApplicableCode");
    145146    printExceptionReportResponse(*main_conf,err);
     147    freeMap(&err);
     148    free(err);
    146149    JS_DestroyContext(cx);
    147150    JS_DestroyRuntime(rt);
    148151    JS_ShutDown();
     152    // Should return -1 here but the unallocation won't work from zoo_service_loader.c line 1847
    149153    exit(-1);
    150154  }
    151155
    152156  jsval t=OBJECT_TO_JSVAL(d);
    153   //JSVAL_TO_OBJECT(t);
    154   if(JS_IsArrayObject(cx,t)){
     157  if(JS_IsArrayObject(cx,d)){
    155158#ifdef JS_DEBUG
    156159    fprintf(stderr,"An array was returned !\n");
    157160#endif
    158     jsdouble len;
    159     if((JS_GetArrayLength(cx, t, &len)==JS_FALSE)){
     161    jsint len;
     162    if((JS_GetArrayLength(cx, d, &len)==JS_FALSE)){
    160163#ifdef JS_DEBUG
    161164      fprintf(stderr,"outputs array is empty\n");
     
    163166    }
    164167    jsval tmp1;
    165     JSBool hasResult=JS_GetElement(cx,t,0,&tmp1);
     168    JSBool hasResult=JS_GetElement(cx,d,0,&tmp1);
    166169    res=JSVAL_TO_INT(tmp1);
    167170#ifdef JS_DEBUG
     
    169172#endif
    170173    jsval tmp2;
    171     JSBool hasElement=JS_GetElement(cx,t,1,&tmp2);
    172     out=mapsFromJSObject(cx,tmp2);
    173     *outputs=out;
     174    JSBool hasElement=JS_GetElement(cx,d,1,&tmp2);
     175    if(hasElement==JS_TRUE){
     176      *outputs=mapsFromJSObject(cx,tmp2);
     177    }
    174178  }
    175179  else{
    176     //#ifdef JS_DEBUG
    177     fprintf(stderr,"The service didn't return an array !\n");
    178     //#endif
     180#ifdef JS_DEBUG
     181    fprintf(stderr,"The serice didn't return an array !\n");
     182#endif
    179183    jsval tmp1;
    180     JSBool hasResult=JS_GetProperty(cx,t,"result",&tmp1);
     184    JSBool hasResult=JS_GetProperty(cx,d,"result",&tmp1);
    181185    res=JSVAL_TO_INT(tmp1);
    182186
    183     //#ifdef JS_DEBUG
     187#ifdef JS_DEBUG
    184188    fprintf(stderr," * %d * \n",res);
    185     //#endif
     189#endif
    186190    jsval tmp2;
    187     JSBool hasElement=JS_GetProperty(cx,t,"outputs",&tmp2);
     191    JSBool hasElement=JS_GetProperty(cx,d,"outputs",&tmp2);
    188192    if(!hasElement)
    189193      fprintf(stderr,"No outputs property returned\n");
    190     if(JS_IsArrayObject(cx,tmp2))
     194    if(JS_IsArrayObject(cx,JSVAL_TO_OBJECT(tmp2)))
    191195      fprintf(stderr,"outputs is array an as expected\n");
    192196    else
    193197      fprintf(stderr,"outputs is not an array as expected\n");
    194     out=mapsFromJSObject(cx,tmp2);
     198    *outputs=mapsFromJSObject(cx,tmp2);
    195199#ifdef JS_DEBUG
    196200    dumpMaps(out);
    197201#endif
    198     *outputs=out;
    199   }
    200 
    201   *inputs=mapsFromJSObject(cx,argv[1]);
    202   *main_conf=mapsFromJSObject(cx,argv[0]);
    203 
    204  
    205   //}
    206   //else
    207   // ERROR
    208   //;
     202  }
    209203
    210204  /* Cleanup. */
    211   JS_MaybeGC(cx);
     205  // The JS_MaybeGC call imply segmentation fault
     206  //JS_MaybeGC(cx);
    212207  JS_DestroyScript(cx, script);
    213   JS_DestroyContext(cx);
     208  // If we use the DestroyContext as requested to release memory then we get
     209  // issue getting back the main configuration maps after coming back to the
     210  // runRequest function ...
     211  //JS_DestroyContext(cx);
    214212  JS_DestroyRuntime(rt);
    215213  JS_ShutDown();
    216   fflush(stderr);
    217214#ifdef JS_DEBUG
    218215  fprintf(stderr,"Returned value %d\n",res);
     
    223220JSObject* JSObject_FromMaps(JSContext *cx,maps* t){
    224221  JSObject *res = JS_NewArrayObject(cx, 0, NULL);
     222  if(res==NULL)
     223    fprintf(stderr,"Array Object is NULL!\n");
    225224  maps* tmp=t;
    226225  while(tmp!=NULL){
     
    247246  while(tmpm!=NULL){
    248247    jsval jsstr = STRING_TO_JSVAL(JS_NewString(cx,tmpm->value,strlen(tmpm->value)));
    249     JS_SetProperty(cx, resf, tmpm->name,&jsstr);
     248    JS_SetProperty(cx, res, tmpm->name,&jsstr);
    250249#ifdef JS_DEBUG
    251250    fprintf(stderr,"%s => %s\n",tmpm->name,tmpm->value);
     
    259258  maps *res=NULL;
    260259  maps *tres=NULL;
    261   JSVAL_TO_OBJECT(t);
     260  jsint oi=0;
     261  JSObject* tt=JSVAL_TO_OBJECT(t);
    262262#ifdef JS_DEBUG
    263263  fprintf(stderr,"Is finally an array ?\n");
    264 #endif
    265   if(JS_IsArrayObject(cx,t)){
    266 #ifdef JS_DEBUG
     264  if(JS_IsArrayObject(cx,tt)){
    267265    fprintf(stderr,"Is finally an array !\n");
    268 #endif
    269   }
    270 #ifdef JS_DEBUG
     266  }
    271267  else
    272268    fprintf(stderr,"Is not an array !\n");
    273269#endif
    274   jsdouble len;
    275   if((JS_GetArrayLength(cx, t, &len)==JS_FALSE)){
     270  jsint len;
     271  JSBool hasLen=JS_GetArrayLength(cx, tt, &len);
     272  if(hasLen==JS_FALSE){
    276273#ifdef JS_DEBUG
    277274    fprintf(stderr,"outputs array is empty\n");
    278275#endif
    279276  }
    280   int i=0;
    281   char tmp[10];
    282   sprintf(tmp,"%d",len);
    283   int clen=atoi(tmp);
    284277#ifdef JS_DEBUG
    285278  fprintf(stderr,"outputs array length : %d\n",len);
    286279#endif
    287   for(i=0;i<len;i++){
    288 #ifdef JS_DEBUG
    289     fprintf(stderr,"outputs array length : %d step %d\n",len,i);
     280  for(oi=0;oi < len;oi++){
     281#ifdef JS_DEBUG
     282    fprintf(stderr,"outputs array length : %d step %d \n",len,oi);
    290283#endif
    291284    jsval tmp1;
    292     JSBool hasElement=JS_GetElement(cx,t,i,&tmp1);
    293     JSVAL_TO_OBJECT(tmp1);
    294     JSIdArray *idp=JS_Enumerate(cx,tmp1);
     285    JSBool hasElement=JS_GetElement(cx,tt,oi,&tmp1);
     286    JSObject *otmp1=JSVAL_TO_OBJECT(tmp1);
     287    JSIdArray *idp=JS_Enumerate(cx,otmp1);
    295288    if(idp!=NULL) {
    296289      int index;
     
    300293#endif
    301294      for (index=0,argNum=idp->length;index<argNum;index++) {
    302         jsid* id = idp->vector[index];
     295        jsval id = idp->vector[index];
    303296        jsval vp;
    304297        JSString* str;
     
    310303        len1 = JS_GetStringLength(jsmsg);
    311304#ifdef JS_DEBUG
    312         fprintf(stderr,"Enumerate id : %d => %s\n",i,JS_GetStringBytes(jsmsg));
    313 #endif
    314         jsval nvp;
    315         if((JS_GetProperty(cx, tmp1, JS_GetStringBytes(jsmsg), &nvp)==JS_FALSE))
    316 #ifdef JS_DEBUG
    317         fprintf(stderr,"Enumerate id : %d => %s => No more value\n",i,JS_GetStringBytes(jsmsg));
     305        fprintf(stderr,"Enumerate id : %d => %s\n",oi,JS_GetStringBytes(jsmsg));
     306#endif
     307        jsval nvp=JSVAL_NULL;
     308        if((JS_GetProperty(cx, JSVAL_TO_OBJECT(tmp1), JS_GetStringBytes(jsmsg), &nvp)==JS_FALSE))
     309#ifdef JS_DEBUG
     310        fprintf(stderr,"Enumerate id : %d => %s => No more value\n",oi,JS_GetStringBytes(jsmsg));
    318311#endif
    319312        if(JSVAL_IS_OBJECT(nvp)){
     
    333326          fprintf(stderr,"JSVAL NVP1J IS OBJECT\n");
    334327#endif
    335           tres=(maps*)malloc(sizeof(maps*));
     328          tres=(maps*)malloc(MAPS_SIZE);
    336329          tres->name=strdup(JS_GetStringBytes(jsmsg));
    337330          tres->content=mapFromJSObject(cx,nvp1j);
     
    341334#endif
    342335          if(res==NULL)
    343             res=tres;
     336            res=dupMaps(&tres);
    344337          else
    345338            addMapsToMaps(&res,tres);
     339          freeMaps(&tres);
     340          free(tres);
     341          tres=NULL;
    346342#ifdef JS_DEBUG
    347343          dumpMaps(res);
     
    363359map* mapFromJSObject(JSContext *cx,jsval t){
    364360  map *res=NULL;
    365   JSIdArray *idp=JS_Enumerate(cx,t);
     361  JSIdArray *idp=JS_Enumerate(cx,JSVAL_TO_OBJECT(t));
    366362#ifdef JS_DEBUG
    367363  fprintf(stderr,"Properties %p\n",(void*)t);
     
    374370#endif
    375371    for (index=0,argNum=idp->length;index<argNum;index++) {
    376       jsid* id = idp->vector[index];
     372      jsval id = idp->vector[index];
    377373      jsval vp;
    378374      JSString* str;
     
    384380      len = JS_GetStringLength(jsmsg);
    385381      jsval nvp;
    386       JS_GetProperty(cx, t, JS_GetStringBytes(jsmsg), &nvp);
     382      JS_GetProperty(cx, JSVAL_TO_OBJECT(t), JS_GetStringBytes(jsmsg), &nvp);
    387383      jsmsg1 = JS_ValueToString(cx,nvp);
    388384      len1 = JS_GetStringLength(jsmsg1);
     
    390386      fprintf(stderr,"Enumerate id : %d [ %s => %s ]\n",index,JS_GetStringBytes(jsmsg),JS_GetStringBytes(jsmsg1));
    391387#endif
    392       if(res!=NULL)
    393         addMapToMap(&res,createMap(JS_GetStringBytes(jsmsg),JS_GetStringBytes(jsmsg1)));
    394       else
     388      if(res!=NULL){
     389        fprintf(stderr,"%s - %s\n",JS_GetStringBytes(jsmsg),JS_GetStringBytes(jsmsg1));
     390        addToMap(res,JS_GetStringBytes(jsmsg),JS_GetStringBytes(jsmsg1));
     391      }
     392      else{
    395393        res=createMap(JS_GetStringBytes(jsmsg),JS_GetStringBytes(jsmsg1));
     394        res->next=NULL;
     395      }
     396      dumpMap(res);
    396397    }
    397398  }
     
    401402  return res;
    402403}
    403 
    404404
    405405/* The error reporter callback. */
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