Back to index

gcompris  8.2.2
py-gcompris-user.c
Go to the documentation of this file.
00001 #include "py-gcompris-profile.h"
00002 #include <pygobject.h>
00003 
00004 staticforward PyTypeObject pyGcomprisUserType;
00005 
00006 //static char pyGcomprisUserType_doc[]= "Python GcomprisBoars structure binding";
00007 
00008 
00009 /* Special function created for the python plugin to be able to create
00010  * a pyGcomprisBoardObject form the existing GcomprisBoard structure
00011  */
00012 PyObject*
00013 gcompris_new_pyGcomprisUserObject(GcomprisUser* user)
00014 {
00015   pyGcomprisUserObject* theuser = NULL;
00016 
00017   theuser = PyObject_New(pyGcomprisUserObject, &pyGcomprisUserType);
00018   if (theuser!=NULL)
00019     theuser->cdata = user;
00020 
00021   return (PyObject*)theuser;
00022 }
00023 
00024 
00025 /* Free the python gcompris user */
00026 static void
00027 pyGcomprisUserType_dealloc(pyGcomprisUserObject *self)
00028 {
00029   self->cdata = NULL;
00030   PyObject_DEL(self);
00031 }
00032 
00033 
00034 /* Methods defined in the pyGcomprisUser class */
00035 static PyMethodDef pyGcomprisUserType_methods[] = {
00036         {NULL,          NULL}           /* sentinel */
00037 };
00038 
00039 
00040 /* Return the value of the members contained in the GcomprisUser structure */
00041 static PyObject *
00042 pyGcomprisUserType_getattr(pyGcomprisUserObject *self, char *name)
00043 {
00044     /* int */
00045     if(strcmp(name,"user_id")==0) return Py_BuildValue("i", self->cdata->user_id);
00046     /* int */
00047     if(strcmp(name,"class_id")==0) return Py_BuildValue("i", self->cdata->class_id);
00048     /* str */
00049     if(strcmp(name,"login")==0) return Py_BuildValue("s", self->cdata->login);
00050     /* str */
00051     if(strcmp(name,"lastname")==0) return Py_BuildValue("s", self->cdata->lastname);
00052     /* str */
00053     if(strcmp(name,"firstname")==0) return Py_BuildValue("s", self->cdata->firstname);
00054     /* str */
00055     if(strcmp(name,"birthdate")==0) return Py_BuildValue("s", self->cdata->birthdate);
00056     /* u int */
00057     if(strcmp(name,"session_id")==0) return Py_BuildValue("i", self->cdata->session_id);
00058 
00059   return Py_FindMethod(pyGcomprisUserType_methods, (PyObject *)self, name);
00060 }
00061 
00062 /* Set the value of a GcomprisUser structure member */
00063 static int
00064 pyGcomprisUserType_setattr(pyGcomprisUserObject *self, char *name, PyObject *v)
00065 {
00066   if (self->cdata==NULL) return -1;
00067   if (v==NULL) return -1;
00068 
00069   /*  if (strcmp(name,"level")==0){
00070     value = (int) PyInt_AsLong(v);
00071     if ( value < 0 ) return -1;
00072     self->cdata->level=value;
00073     return 0;
00074     } */
00075   /* members are supposed to be read only */
00076 
00077   return -1;
00078 }
00079 
00080 static PyTypeObject pyGcomprisUserType = {
00081 #if defined(WIN32)
00082   PyObject_HEAD_INIT(NULL)
00083 #else /* ! WIN32 */
00084   PyObject_HEAD_INIT(&PyType_Type)
00085 #endif
00086   0,                                        /*ob_size*/
00087   "pyGcomprisUser",                        /*tp_name*/
00088   sizeof(pyGcomprisUserObject),            /*tp_basicsize*/
00089   0,                                        /*tp_itemsize*/
00090   /* methods */
00091   (destructor)pyGcomprisUserType_dealloc,  /*tp_dealloc*/
00092   0,                                        /*tp_print*/
00093   (getattrfunc)pyGcomprisUserType_getattr, /*tp_getattr*/
00094   (setattrfunc)pyGcomprisUserType_setattr, /*tp_setattr*/
00095   0,                                        /*tp_compare*/
00096   0,                                        /*tp_repr*/
00097   0,                                        /*tp_as_number*/
00098   0,                                        /*tp_as_sequence*/
00099   0,                                        /*tp_as_mapping*/
00100   0,                                        /*tp_hash*/
00101 };