Back to index

gcompris  8.2.2
py-mod-admin.c
Go to the documentation of this file.
00001 
00002 #include <Python.h>
00003 #include <pygobject.h>
00004 #include "gcompris/gcompris.h"
00005 #include "py-mod-admin.h"
00006 #include "py-gcompris-board.h"
00007 #include "py-gcompris-profile.h"
00008 
00009 /* All functions provided by this python module
00010  * wraps a gcompris function. Each "py_*" function wraps the
00011  * "*" C function.
00012  */
00013 
00014 static PyObject*
00015 py_board_run_next (PyObject* self, PyObject* args)
00016 {
00017   PyObject* pyObject;
00018   pyGcomprisBoardObject* pyGcomprisBoard;
00019   GcomprisBoard* cGcomprisBoard;
00020 
00021   /* Parse arguments */
00022   if(!PyArg_ParseTuple(args, "O:board_run_next", &pyObject))
00023     return NULL;
00024   pyGcomprisBoard = (pyGcomprisBoardObject*) pyObject;
00025   cGcomprisBoard = pyGcomprisBoard->cdata;
00026 
00027   /* Call the corresponding C function */
00028   gc_board_run_next(cGcomprisBoard);
00029 
00030   /* Create and return the result */
00031   Py_INCREF(Py_None);
00032   return Py_None;
00033 }
00034 
00035 static PyObject*
00036 py_gc_board_config_start (PyObject* self, PyObject* args)
00037 {
00038   PyObject* pyBoard;
00039   PyObject* pyProfile;
00040   pyGcomprisBoardObject* pyGcomprisBoard;
00041   pyGcomprisProfileObject* pyGcomprisProfile;
00042   GcomprisBoard* cGcomprisBoard;
00043   GcomprisProfile* cGcomprisProfile;
00044 
00045   /* Parse arguments */
00046   if(!PyArg_ParseTuple(args,
00047                      "OO:gc_board_config_start",
00048                      &pyBoard,
00049                      &pyProfile))
00050     return NULL;
00051 
00052   pyGcomprisBoard = (pyGcomprisBoardObject*) pyBoard;
00053   pyGcomprisProfile = (pyGcomprisProfileObject*) pyProfile;
00054   cGcomprisBoard = pyGcomprisBoard->cdata;
00055   cGcomprisProfile = pyGcomprisProfile->cdata;
00056 
00057   /* Call the corresponding C function */
00058   gc_board_config_start(cGcomprisBoard, cGcomprisProfile);
00059 
00060   /* Create and return the result */
00061   Py_INCREF(Py_None);
00062   return Py_None;
00063 }
00064 
00065 static PyObject*
00066 py_gc_board_config_stop (PyObject* self, PyObject* args)
00067 {
00068   /* Parse arguments */
00069   if(!PyArg_ParseTuple(args, ":gcompris.gc_board_config_stop"))
00070     return NULL;
00071 
00072   /* Call the corresponding C function */
00073   gc_board_config_stop();
00074 
00075   /* Create and return the result */
00076   Py_INCREF(Py_None);
00077   return Py_None;
00078 }
00079 
00080 static PyObject*
00081 py_gc_menu_get_boards (PyObject* self, PyObject* args)
00082 {
00083   GList *boards_list;
00084   GList *list;
00085   PyObject *pylist;
00086 
00087   /* Parse arguments */
00088   if(!PyArg_ParseTuple(args, ":gcompris.get_boards_list"))
00089     return NULL;
00090 
00091   /* Call the corresponding C function */
00092   boards_list = gc_menu_get_boards();
00093 
00094   pylist = PyList_New(0);
00095   for (list = boards_list; list != NULL; list = list->next){
00096     PyList_Append(pylist, gcompris_new_pyGcomprisBoardObject((GcomprisBoard*) list->data));
00097   }
00098   /* Create and return the result */
00099   return pylist;
00100 }
00101 
00102 static PyObject*
00103 py_gc_db_get_profile_from_id (PyObject* self, PyObject* args)
00104 {
00105   GcomprisProfile *profile;
00106   int profile_id;
00107 
00108   /* Parse arguments */
00109   if(!PyArg_ParseTuple(args, "i:gcompris.get_profile_from_id", &profile_id))
00110     return NULL;
00111 
00112   /* Call the corresponding C function */
00113   profile = gc_db_get_profile_from_id (profile_id);
00114 
00115   /* Create and return the result */
00116   return gcompris_new_pyGcomprisProfileObject(profile) ;
00117 }
00118 
00119 static PyObject*
00120 py_gc_db_get_board_from_id (PyObject* self, PyObject* args)
00121 {
00122   GcomprisBoard *board;
00123   int board_id;
00124 
00125   /* Parse arguments */
00126   if(!PyArg_ParseTuple(args, "i:gcompris.get_board_from_id", &board_id))
00127     return NULL;
00128 
00129   /* Call the corresponding C function */
00130   board = gc_db_get_board_from_id (board_id);
00131 
00132   /* Create and return the result */
00133   return gcompris_new_pyGcomprisBoardObject(board) ;
00134 }
00135 
00136 static PyObject*
00137 py_gc_db_get_group_from_id (PyObject* self, PyObject* args)
00138 {
00139   GcomprisGroup *group;
00140   int group_id;
00141 
00142   /* Parse arguments */
00143   if(!PyArg_ParseTuple(args, "i:gcompris.get_group_from_id", &group_id))
00144     return NULL;
00145 
00146   /* Call the corresponding C function */
00147   group = gc_db_get_group_from_id (group_id);
00148 
00149   /* Create and return the result */
00150   return gcompris_new_pyGcomprisGroupObject(group) ;
00151 }
00152 
00153 static PyObject*
00154 py_gc_db_get_user_from_id (PyObject* self, PyObject* args)
00155 {
00156   GcomprisUser *user;
00157   int user_id;
00158 
00159   /* Parse arguments */
00160   if(!PyArg_ParseTuple(args, "i:gcompris.get_user_from_id", &user_id))
00161     return NULL;
00162 
00163   /* Call the corresponding C function */
00164   user = gc_db_get_user_from_id (user_id);
00165 
00166   /* Create and return the result */
00167   return gcompris_new_pyGcomprisUserObject(user) ;
00168 }
00169 
00170 static PyObject*
00171 py_gc_db_get_class_from_id (PyObject* self, PyObject* args)
00172 {
00173   GcomprisClass *class;
00174   int class_id;
00175 
00176   /* Parse arguments */
00177   if(!PyArg_ParseTuple(args, "i:gcompris.get_class_from_id", &class_id))
00178     return NULL;
00179 
00180   /* Call the corresponding C function */
00181   class = gc_db_get_class_from_id (class_id);
00182 
00183   /* Create and return the result */
00184   return gcompris_new_pyGcomprisClassObject(class) ;
00185 }
00186 
00187 static PyObject*
00188 py_gc_db_profiles_list_get (PyObject* self, PyObject* args)
00189 {
00190   GList *profiles_list;
00191   GList *list;
00192   PyObject *pylist;
00193 
00194   /* Parse arguments */
00195   if(!PyArg_ParseTuple(args, ":gcompris.get_profiles_list"))
00196     return NULL;
00197 
00198   /* Call the corresponding C function */
00199   profiles_list = gc_db_profiles_list_get();
00200 
00201   pylist = PyList_New(0);
00202   for (list = profiles_list; list != NULL; list = list->next){
00203     PyList_Append(pylist, gcompris_new_pyGcomprisProfileObject((GcomprisProfile*) list->data));
00204   }
00205   /* Create and return the result */
00206   return pylist;
00207 }
00208 
00209 static PyObject*
00210 py_gc_db_get_users_list (PyObject* self, PyObject* args)
00211 {
00212   GList *users_list;
00213   GList *list;
00214   PyObject *pylist;
00215 
00216   /* Parse arguments */
00217   if(!PyArg_ParseTuple(args, ":gcompris.get_users_list"))
00218     return NULL;
00219 
00220   /* Call the corresponding C function */
00221   users_list = gc_db_get_users_list();
00222 
00223   pylist = PyList_New(0);
00224   for (list = users_list; list != NULL; list = list->next){
00225     PyList_Append(pylist, gcompris_new_pyGcomprisUserObject((GcomprisUser*) list->data));
00226   }
00227   /* Create and return the result */
00228   return pylist;
00229 }
00230 
00231 static PyObject*
00232 py_gc_db_get_groups_list (PyObject* self, PyObject* args)
00233 {
00234   GList *groups_list;
00235   GList *list;
00236   PyObject *pylist;
00237 
00238   /* Parse arguments */
00239   if(!PyArg_ParseTuple(args, ":gcompris.get_groups_list"))
00240     return NULL;
00241 
00242   /* Call the corresponding C function */
00243   groups_list = gc_db_get_groups_list();
00244 
00245   pylist = PyList_New(0);
00246   for (list = groups_list; list != NULL; list = list->next){
00247     PyList_Append(pylist, gcompris_new_pyGcomprisGroupObject((GcomprisGroup*) list->data));
00248   }
00249   /* Create and return the result */
00250   return pylist;
00251 }
00252 
00253 static PyObject*
00254 py_gc_db_get_classes_list (PyObject* self, PyObject* args)
00255 {
00256   GList *classes_list;
00257   GList *list;
00258   PyObject *pylist;
00259 
00260   /* Parse arguments */
00261   if(!PyArg_ParseTuple(args, ":gcompris.get_classes_list"))
00262     return NULL;
00263 
00264   /* Call the corresponding C function */
00265   classes_list = gc_db_get_classes_list();
00266 
00267   pylist = PyList_New(0);
00268   for (list = classes_list; list != NULL; list = list->next){
00269     PyList_Append(pylist, gcompris_new_pyGcomprisClassObject((GcomprisClass*) list->data));
00270   }
00271   /* Create and return the result */
00272   return pylist;
00273 }
00274 
00275 static PyObject*
00276 py_gc_db_users_from_group_get (PyObject* self, PyObject* args)
00277 {
00278   GList *users_list;
00279   GList *list;
00280   PyObject *pylist;
00281   int group_id;
00282 
00283   /* Parse arguments */
00284   if(!PyArg_ParseTuple(args, "i:gc_db_users_from_group_get", &group_id))
00285     return NULL;
00286 
00287   /* Call the corresponding C function */
00288   users_list = gc_db_users_from_group_get(group_id);
00289 
00290   pylist = PyList_New(0);
00291   for (list = users_list; list != NULL; list = list->next){
00292     PyList_Append(pylist, gcompris_new_pyGcomprisUserObject((GcomprisUser*) list->data));
00293   }
00294   /* Create and return the result */
00295   return pylist;
00296 }
00297 
00298 /* void                *gc_profile_set_current_user(GcomprisUser *user); */
00299 static PyObject*
00300 py_gc_profile_set_current_user (PyObject* self, PyObject* args)
00301 {
00302   PyObject *pyObject_user;
00303   pyGcomprisUserObject *pyUser;
00304   GcomprisUser *user;
00305 
00306   /* Parse arguments */
00307   if(!PyArg_ParseTuple(args, "O:gcompris.set_current_user", &pyObject_user))
00308     return NULL;
00309 
00310   pyUser = (pyGcomprisUserObject *) pyObject_user;
00311 
00312   user = (GcomprisUser *) pyUser->cdata;
00313   /* Call the corresponding C function */
00314   gc_profile_set_current_user(user);
00315 
00316   /* Create and return the result */
00317   Py_INCREF(Py_None);
00318   return Py_None;
00319 }
00320 
00321 
00322 
00323 /* GcomprisUser        *gc_profile_get_current_user(); */
00324 static PyObject*
00325 py_gc_profile_get_current_user (PyObject* self, PyObject* args)
00326 {
00327   GcomprisUser *user;
00328 
00329   /* Parse arguments */
00330   if(!PyArg_ParseTuple(args, ":gcompris.get_current_user"))
00331     return NULL;
00332 
00333   /* Call the corresponding C function */
00334   user = gc_profile_get_current_user ();
00335 
00336   /* Create and return the result */
00337   if (!user) {
00338   Py_INCREF(Py_None);
00339   return Py_None;
00340   }
00341   else
00342     return gcompris_new_pyGcomprisUserObject((GcomprisUser*) user);
00343 }
00344 
00345 static PyMethodDef PythonGcomprisAdminModule[] = {
00346   { "board_run_next",  py_board_run_next, METH_VARARGS, "board_run_next" },
00347   { "board_config_start",  py_gc_board_config_start, METH_VARARGS, "gc_board_config_start" },
00348   { "board_config_stop",  py_gc_board_config_stop, METH_VARARGS, "gc_board_config_stop" },
00349   { "get_profile_from_id",  py_gc_db_get_profile_from_id, METH_VARARGS, "gc_db_get_profile_from_id" },
00350   { "get_profiles_list",  py_gc_db_profiles_list_get, METH_VARARGS, "gc_db_profiles_list_get" },
00351   { "get_user_from_id",  py_gc_db_get_user_from_id, METH_VARARGS, "gc_db_get_user_from_id" },
00352   { "get_users_list",  py_gc_db_get_users_list, METH_VARARGS, "gc_db_get_users_list" },
00353   { "get_group_from_id",  py_gc_db_get_group_from_id, METH_VARARGS, "gc_db_get_group_from_id" },
00354   { "get_groups_list",  py_gc_db_get_groups_list, METH_VARARGS, "gc_db_get_groups_list" },
00355   { "get_class_from_id",  py_gc_db_get_class_from_id, METH_VARARGS, "gc_db_get_class_from_id" },
00356   { "get_classes_list",  py_gc_db_get_classes_list, METH_VARARGS, "gc_db_get_classes_list" },
00357   { "get_board_from_id",  py_gc_db_get_board_from_id, METH_VARARGS, "gc_db_get_board_from_id" },
00358   { "get_boards_list",  py_gc_menu_get_boards, METH_VARARGS, "gc_menu_get_boards" },
00359   { "get_users_from_group",  py_gc_db_users_from_group_get, METH_VARARGS, "gc_db_users_from_group_get" },
00360   { "get_users_from_group",  py_gc_db_users_from_group_get, METH_VARARGS, "gc_db_users_from_group_get" },
00361   { "get_current_user",  py_gc_profile_get_current_user, METH_VARARGS, "gc_profile_get_current_user" },
00362   { "set_current_user",  py_gc_profile_set_current_user, METH_VARARGS, "gc_profile_set_current_user" },
00363   { NULL, NULL, 0, NULL}
00364 };
00365 
00366 
00367 void python_gcompris_admin_module_init(void)
00368 {
00369   PyObject* module;
00370   module = Py_InitModule("_gcompris_admin", PythonGcomprisAdminModule);
00371 }
00372 
00373 /* Some usefull code parts ... */
00374 /*
00375 static PyObject*
00376 py_gcompris_(PyObject* self, PyObject* args)
00377 {
00378 */  /* Parse arguments */
00379 /*  if(!PyArg_ParseTuple(args, ":gcompris_"))
00380     return NULL;
00381 */
00382   /* Call the corresponding C function */
00383 /*  gcompris_();
00384 */
00385   /* Create and return the result */
00386 /*  Py_INCREF(Py_None);
00387   return Py_None;
00388 }
00389 */
00390 /*
00391   { "",  py_gcompris_, METH_VARARGS, "gcompris_" },
00392 */