Ignore:
Timestamp:
Oct 4, 2012, 5:04:31 PM (12 years ago)
Author:
djay
Message:

Many thanks to Trevor Clarke for providing patch for Python ZOO-API. This rev. shall fix ticket #74.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/service_internal_python.c

    r364 r368  
    2525#include "service_internal_python.h"
    2626
     27static PyObject* ZooError;
     28
     29PyMethodDef zooMethods[] = {
     30  {"update_status", PythonUpdateStatus, METH_VARARGS, "Update status percentage of a running process."},
     31  {NULL, NULL, 0, NULL} /* tempt not the blade, all fear the sentinel */
     32};
     33
     34PyMODINIT_FUNC init_zoo(){
     35  PyObject *tmp,*d;
     36  PyObject* module = Py_InitModule("zoo", zooMethods);
     37  if (module == NULL)
     38    return;
     39 
     40  d = PyModule_GetDict(module);
     41  tmp = PyInt_FromLong(3);
     42  PyDict_SetItemString(d, "SERVICE_SUCCEEDED", tmp);
     43  Py_DECREF(tmp);
     44
     45  tmp = PyInt_FromLong(4);
     46  PyDict_SetItemString(d, "SERVICE_FAILED", tmp);
     47  Py_DECREF(tmp);
     48
     49  ZooError = PyErr_NewException("zoo.error", NULL, NULL);
     50  Py_INCREF(ZooError);
     51  PyModule_AddObject(module, "error", ZooError);
     52}
     53
    2754int zoo_python_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){
    2855  maps* m=*main_conf;
     
    80107  PyEval_InitThreads();
    81108  Py_Initialize();
     109  init_zoo();
    82110  mainstate = PyThreadState_Swap(NULL);
    83111  PyEval_ReleaseLock();
     
    388416  return res;
    389417}
     418
     419PyObject*
     420PythonUpdateStatus(PyObject* self, PyObject* args)
     421{
     422  maps* conf;
     423  PyObject* confdict;
     424  int istatus;
     425  char* status;
     426  if (!PyArg_ParseTuple(args, "O!i", &PyDict_Type, &confdict, &istatus)){
     427#ifdef DEBUG
     428    fprintf(stderr,"Incorrect arguments to update status function");
     429#endif
     430    return NULL;
     431  }
     432  if (istatus < 0 || istatus > 100){
     433     PyErr_SetString(ZooError, "Status must be a percentage.");
     434     return NULL;
     435  }else{
     436     char tmpStatus[4];
     437     snprintf(tmpStatus, 4, "%i", istatus);
     438     status = strdup(tmpStatus);
     439  }
     440  /* now update the map */
     441  {
     442    PyObject* lenv = PyMapping_GetItemString(confdict, "lenv");
     443    if (lenv && PyMapping_Check(lenv)){
     444      PyObject* valobj = PyString_FromString(status);
     445      PyMapping_SetItemString(lenv, "status", valobj);
     446      Py_DECREF(valobj);
     447    }
     448    Py_DECREF(lenv);
     449  }
     450  conf = mapsFromPyDict((PyDictObject*)confdict);
     451  if (getMapFromMaps(conf,"lenv","status") != NULL){
     452    fprintf(stderr,"STATUS RETURNED : %s\n",status);
     453    if(status!=NULL){
     454      setMapInMaps(conf,"lenv","status",status);
     455      free(status);
     456    }
     457    else
     458      setMapInMaps(conf,"lenv","status","15");
     459    updateStatus(conf);
     460  }
     461  freeMaps(&conf);
     462  free(conf);
     463  Py_RETURN_NONE;
     464}
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