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_python.c

    r1 r9  
    2525#include "service_internal_python.h"
    2626
    27 int python_support(maps* m,service* s,int argc,char** argv,map *inputs,map *outputs){
    28   Py_Initialize();
    29   PyObject *pName, *pModule, *pFunc;
    30   pName = PyString_FromString(argv[2]);
    31   pModule = PyImport_Import(pName);
    32   int i;
    33   if (pModule != NULL) {
    34     pFunc=PyObject_GetAttrString(pModule,argv[4]);
    35     if (pFunc && PyCallable_Check(pFunc)){
    36       PyDictObject* arg1=PyDict_FromMap(inputs);
    37       PyDictObject* arg2=PyDict_FromMap(outputs);
    38       PyObject *pArgs=PyTuple_New(2);
    39       PyObject *pValue;
    40       PyTuple_SetItem(pArgs, 0, (PyObject *)arg1);
    41       PyTuple_SetItem(pArgs, 1, (PyObject *)arg2);
    42       pValue = PyString_FromString(argv[argc-1]);
    43 #ifdef DEBUG
    44       fprintf(stderr,"Function successfully loaded\n");
    45 #endif 
    46       /**
    47        * Need to check if we need to fork to load a status enabled
    48        */
    49       if(strcmp(PyString_AsString(pValue),"bg")!=0){
    50 #ifdef DEBUG
    51         fprintf(stderr,"RUN IN NORMAL MODE \n");
    52 #endif
    53         pValue = PyObject_CallObject(pFunc, pArgs);
    54         if (pValue != NULL) {
    55           inputs=mapFromPyDict(arg1);
    56           outputs=mapFromPyDict(arg2);
    57 #ifdef DEBUG
    58           fprintf(stderr,"Result of call: %i\n", PyInt_AsLong(pValue));
    59           dumpMap(inputs);
    60           dumpMap(outputs);
    61 #ifndef WIN32
    62           fprintf(stderr,"printProcessResponse(%i,\"%s\",%i,inputs,outputs);",getpid(),argv[1],PyInt_AsLong(pValue));
    63 #endif
    64 #endif
    65           printProcessResponse(m,getpid(),s,argv[2],PyInt_AsLong(pValue),inputs,outputs);
    66         }
    67       }
    68       else{
    69         pid_t pid;
    70 #ifdef WIN32
    71         pid = 0;
    72 #else
    73         pid = fork ();
    74 #endif
    75         if (pid > 0) {
    76           /* dady */
    77           printProcessResponse(m,pid,s,argv[2],SERVICE_STARTED,inputs,outputs);
    78         }else if (pid == 0) {
    79           /* son */
    80 #ifdef DEBUG
    81           fprintf(stderr,"RUN IN BACKGROUND MODE \n");
    82 #endif
    83           char tmp1[256];
    84           sprintf(tmp1,"service/temp/%s_%d.xml",argv[2],getpid());
    85 #ifndef WIN32
    86           stdout =
    87 #endif
    88                   freopen(tmp1 , "w+" , stdout);
    89           printProcessResponse(m,getpid(),s,argv[2],SERVICE_STARTED,inputs,outputs);
    90           fflush(stdout);
    91           pValue = PyObject_CallObject(pFunc, pArgs);
    92           if (pValue != NULL) {
    93             rewind(stdout);
    94             inputs=mapFromPyDict(arg1);
    95             outputs=mapFromPyDict(arg2);
    96 #ifdef DEBUG
    97             fprintf(stderr,"Result of call: %ld\n", PyInt_AsLong(pValue));
    98             dumpMap(inputs);
    99             dumpMap(outputs);
    100             fprintf(stderr,"printProcessResponse(%i,%s,%i,inputs,outputs);",s,getpid(),argv[2],PyInt_AsLong(pValue));
    101 #endif
    102 //          sleep(6);
    103             printProcessResponse(m,getpid(),s,argv[2],PyInt_AsLong(pValue),inputs,outputs);
    104           }
    105           exit(1);
    106         } else {
    107           /* error */
    108         }
    109       }
    110       Py_DECREF(pArgs);
    111       Py_DECREF(pValue);
    112 #ifdef DEBUG
    113       fprintf(stderr,"Function ran successfully\n");
    114 #endif 
    115     }
    116     else{
    117       char tmpS[1024];
    118       sprintf(tmpS, "Cannot find function %s \n", argv[4]);
    119       map* tmps=createMap("text",tmpS);
    120       printExceptionReportResponse(m,tmps);
    121       //fprintf(stderr, "Cannot find function %s \n", argv[2]);
    122       exit(-1);
    123     }
    124   }else{
    125     char tmpS[1024];
    126     sprintf(tmpS, "Cannot find function %s \n", argv[4]);
    127     map* tmps=createMap("text",tmpS);
    128     printExceptionReportResponse(m,tmps);
    129     //fprintf(stderr, "Cannot find function %s \n", argv[4]);
    130     if (PyErr_Occurred())
    131       PyErr_Print();
    132 
    133   }
    134   Py_Finalize();
    135   return 2;
    136 }
    137 
    13827int zoo_python_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){
    13928  maps* m=*main_conf;
     
    14433  map* tmp=NULL;
    14534  tmp=getMapFromMaps(*main_conf,"env","PYTHONPATH");
    146   char *python_path=NULL;
     35  char *python_path;
     36  fprintf(stderr,"PYTHON SUPPORT \n");
     37  fflush(stderr);
    14738  if(tmp!=NULL){
    148           python_path=(char*)malloc((1+strlen(tmp->value))*sizeof(char));
    149           sprintf(python_path,"%s",tmp->value);
     39    fprintf(stderr,"PYTHON SUPPORT (%i)\n",strlen(tmp->value));
     40    python_path=(char*)malloc((strlen(tmp->value))*sizeof(char));
     41    sprintf(python_path,"%s",tmp->value);
    15042  }
    15143  else{
    152         python_path=(char*)malloc(2*sizeof(char));
    153         python_path=".";
     44    python_path=strdup(".");
    15445  }
    15546  tmp=NULL;
     
    15849  if(tmp!=NULL && strcmp(tmp->value,"")!=0)
    15950#ifdef WIN32
    160           sprintf(pythonpath,"%s/%s/;%s",ntmp,tmp->value,python_path);
     51    sprintf(pythonpath,"%s/%s/;%s",ntmp,tmp->value,python_path);
    16152#else
    162           sprintf(pythonpath,"%s/%s/:%s",ntmp,tmp->value,python_path);
     53  sprintf(pythonpath,"%s/%s/:%s",ntmp,tmp->value,python_path);
    16354#endif
    16455  else
     
    16657    sprintf(pythonpath,"%s;%s",ntmp,python_path);
    16758#else
    168     sprintf(pythonpath,"%s:%s",ntmp,python_path);
    169 #endif
    170 #ifdef DEBUG
    171   fprintf(stderr,"PYTHONPATH=%s\n",pythonpath);
    172 #endif
     59  sprintf(pythonpath,"%s:%s",ntmp,python_path);
     60#endif
     61  //#ifdef DEBUG
     62    fprintf(stderr,"PYTHONPATH=%s\n",pythonpath);
     63  //#endif
    17364#ifndef WIN32
    17465  setenv("PYTHONPATH",pythonpath,1);
     
    17869  free(python_path);
    17970  free(pythonpath);
    180   //
     71
    18172  Py_Initialize();
    18273  PyObject *pName, *pModule, *pFunc;
    18374  tmp=getMap(s->content,"serviceProvider");
    184   //if(tmp!=NULL)
    185   pName = PyString_FromString(tmp->value);
     75  if(tmp!=NULL)
     76    pName = PyString_FromString(tmp->value);
     77  else{
     78    map* err=createMap("text","Unable to parse serviceProvider please check your zcfg file.");
     79    addToMap(err,"code","NoApplicableCode");
     80    printExceptionReportResponse(m,err);
     81    exit(-1);
     82  }
    18683  pModule = PyImport_Import(pName);
    18784  int i;
     
    20299#ifdef DEBUG
    203100      fprintf(stderr,"RUN IN NORMAL MODE \n");
    204       //fflush(stderr);
     101      fflush(stderr);
    205102#endif
    206103      pValue = PyObject_CallObject(pFunc, pArgs);
    207104      if (pValue != NULL) {
    208105        res=PyInt_AsLong(pValue);
    209         /*inputs=mapsFromPyDict(arg2);
    210         dumpMaps(inputs);*/
    211         outputs=mapsFromPyDict(arg3);
    212         *real_outputs=outputs;
    213 
     106        freeMaps(real_outputs);
     107        free(*real_outputs);
     108        //*real_inputs=mapsFromPyDict(arg2);
     109        //createMapsFromPyDict(real_outputs,arg3);
     110        *real_outputs=mapsFromPyDict(arg3);
    214111#ifdef DEBUG
    215112        fprintf(stderr,"Result of call: %i\n", PyInt_AsLong(pValue));
    216113        dumpMaps(inputs);
    217114        dumpMaps(outputs);
    218         fprintf(stderr,"printProcessResponse(%i,\"%s\",%i,inputs,outputs);",
    219                 getpid(),tmp->value,PyInt_AsLong(pValue));
    220         dumpMaps(outputs);
    221 #endif
     115#endif
     116        Py_DECREF(arg1);
     117        Py_DECREF(arg2);
     118        Py_DECREF(arg3);
     119        Py_DECREF(pArgs);
    222120        Py_DECREF(pValue);
    223121        Py_XDECREF(pFunc);
    224         Py_DECREF(pArgs);
    225122        Py_DECREF(pModule);
    226       }else{
    227          
     123      }else{     
    228124        PyObject *ptype,*pvalue, *ptraceback;
    229125        PyErr_Fetch(&ptype, &pvalue, &ptraceback);
     
    268164      map* tmps=createMap("text",tmpS);
    269165      printExceptionReportResponse(m,tmps);
    270       //fprintf(stderr, "Cannot find function %s \n", argv[2]);
    271166      Py_XDECREF(pFunc);
    272167      Py_DECREF(pModule);
     
    275170  } else{
    276171    char tmpS[1024];
    277     sprintf(tmpS, "Cannot find function %s \n", tmp->value);
     172    sprintf(tmpS, "Python module %s cannot be loaded.\n", tmp->value);
    278173    map* tmps=createMap("text",tmpS);
    279174    printExceptionReportResponse(m,tmps);
    280     //fprintf(stderr, "Cannot find function %s \n", argv[4]);
    281175    if (PyErr_Occurred())
    282176      PyErr_Print();
    283177    exit(-1);
    284178  }
     179#ifndef DEBUG
     180  // Failed when DEBUG is defined
    285181  Py_Finalize();
     182#endif
    286183  return res;
    287184}
     
    329226            PyString_AsString(key),PyString_AsString(value));
    330227#endif
    331     if(cursor!=NULL){
     228    while(cursor!=NULL){
    332229      cursor=cursor->next;
    333230    }
    334     cursor=(maps*)malloc(sizeof(maps*));
     231    cursor=(maps*)malloc(MAPS_SIZE);
    335232    cursor->name=PyString_AsString(key);
    336233#ifdef DEBUG
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