Changeset 368 for trunk/zoo-project/zoo-kernel/service_internal_python.c
- Timestamp:
- Oct 4, 2012, 5:04:31 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service_internal_python.c
r364 r368 25 25 #include "service_internal_python.h" 26 26 27 static PyObject* ZooError; 28 29 PyMethodDef 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 34 PyMODINIT_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 27 54 int zoo_python_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){ 28 55 maps* m=*main_conf; … … 80 107 PyEval_InitThreads(); 81 108 Py_Initialize(); 109 init_zoo(); 82 110 mainstate = PyThreadState_Swap(NULL); 83 111 PyEval_ReleaseLock(); … … 388 416 return res; 389 417 } 418 419 PyObject* 420 PythonUpdateStatus(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.