Annotation of gpl/axl/py-axl/py_axl_stream.c, revision 1.1.1.1

1.1       misho       1: /** 
                      2:  *  PyAxl: Axl Library python bindings
                      3:  *  Copyright (C) 2009 Advanced Software Production Line, S.L.
                      4:  *
                      5:  *  This program is free software; you can redistribute it and/or
                      6:  *  modify it under the terms of the GNU Lesser General Public License
                      7:  *  as published by the Free Software Foundation; either version 2.1
                      8:  *  of the License, or (at your option) any later version.
                      9:  *
                     10:  *  This program is distributed in the hope that it will be useful,
                     11:  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
                     12:  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                     13:  *  Lesser General Public License for more details.
                     14:  *
                     15:  *  You should have received a copy of the GNU Lesser General Public
                     16:  *  License along with this program; if not, write to the Free
                     17:  *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
                     18:  *  02111-1307 USA
                     19:  *  
                     20:  *  You may find a copy of the license under this software is released
                     21:  *  at COPYING file. This is LGPL software: you are welcome to develop
                     22:  *  proprietary applications using this library without any royalty or
                     23:  *  fee but returning back any change, improvement or addition in the
                     24:  *  form of source code, project image, documentation patches, etc.
                     25:  *
                     26:  *  For commercial support for XML enabled solutions contact us:
                     27:  *          
                     28:  *      Postal address:
                     29:  *         Advanced Software Production Line, S.L.
                     30:  *         C/ Antonio Suarez Nº 10, 
                     31:  *         Edificio Alius A, Despacho 102
                     32:  *         Alcalá de Henares 28802 (Madrid)
                     33:  *         Spain
                     34:  *
                     35:  *      Email address:
                     36:  *         info@aspl.es - http://www.aspl.es/axl
                     37:  */
                     38: #include <py_axl_stream.h>
                     39: 
                     40: #define LOG_DOMAIN "py-axl-stream"
                     41: 
                     42: struct _PyAxlStream {
                     43:        /* header required to initialize python required bits for
                     44:           every python object */
                     45:        PyObject_HEAD
                     46: 
                     47:        /* pointer to the axl stream */
                     48:        axlStream * stream;
                     49: };
                     50: 
                     51: static int py_axl_stream_init_type (PyAxlStream *self, PyObject *args, PyObject *kwds)
                     52: {
                     53:     return 0;
                     54: }
                     55: 
                     56: /** 
                     57:  * @brief Function used to allocate memory required by the object
                     58:  * axl.Stream
                     59:  */
                     60: static PyObject * py_axl_stream_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
                     61: {
                     62:        PyAxlStream *self;
                     63: 
                     64:        /* create the object */
                     65:        self = (PyAxlStream *)type->tp_alloc(type, 0);
                     66: 
                     67:        return (PyObject *)self;
                     68: }
                     69: 
                     70: /** 
                     71:  * @brief Function used to finish and dealloc memory used by the
                     72:  * object axl.Stream
                     73:  */
                     74: static void py_axl_stream_dealloc (PyAxlStream* self)
                     75: {
                     76:        /* free the stream it self */
                     77:        self->ob_type->tp_free ((PyObject*)self);
                     78: 
                     79:        return;
                     80: }
                     81: 
                     82: /** 
                     83:  * @brief This function implements the generic attribute getting that
                     84:  * allows to perform complex member resolution (not merely direct
                     85:  * member access).
                     86:  */
                     87: PyObject * py_axl_stream_get_attr (PyObject *o, PyObject *attr_name) {
                     88:        const char      * attr = NULL;
                     89:        PyObject        * result;
                     90: /*     PyAxlStream        * self = (PyAxlStream *) o; */
                     91: 
                     92:        /* now implement other attributes */
                     93:        if (! PyArg_Parse (attr_name, "s", &attr))
                     94:                return NULL;
                     95: 
                     96:        __axl_log (LOG_DOMAIN, AXL_LEVEL_DEBUG, "received request to report stream attr name %s (self: %p)",
                     97:                   attr, o);
                     98: 
                     99:        /* first implement generic attr already defined */
                    100:        result = PyObject_GenericGetAttr (o, attr_name);
                    101:        if (result)
                    102:                return result;
                    103:        
                    104:        return NULL;
                    105: }
                    106: 
                    107: /** 
                    108:  * @brief Implements attribute set operation.
                    109:  */
                    110: int py_axl_stream_set_attr (PyObject *o, PyObject *attr_name, PyObject *v)
                    111: {
                    112:        const char      * attr = NULL;
                    113: /*     PyAxlStream        * self = (PyAxlStream *) o; */
                    114: /*     axl_bool          boolean_value = axl_false; */
                    115: 
                    116:        /* now implement other attributes */
                    117:        if (! PyArg_Parse (attr_name, "s", &attr))
                    118:                return -1;
                    119: 
                    120:        /* now implement generic setter */
                    121:        return PyObject_GenericSetAttr (o, attr_name, v);
                    122: }
                    123: 
                    124: static PyMethodDef py_axl_stream_methods[] = { 
                    125:        {NULL}  
                    126: }; 
                    127: 
                    128: static PyTypeObject PyAxlStreamType = {
                    129:     PyObject_HEAD_INIT(NULL)
                    130:     0,                         /* ob_size*/
                    131:     "axl.Stream",                 /* tp_name*/
                    132:     sizeof(PyAxlStream),       /* tp_basicsize*/
                    133:     0,                         /* tp_itemsize*/
                    134:     (destructor)py_axl_stream_dealloc, /* tp_dealloc*/
                    135:     0,                         /* tp_print*/
                    136:     0,                         /* tp_getattr*/
                    137:     0,                         /* tp_setattr*/
                    138:     0,                         /* tp_compare*/
                    139:     0,                         /* tp_repr*/
                    140:     0,                         /* tp_as_number*/
                    141:     0,                         /* tp_as_sequence*/
                    142:     0,                         /* tp_as_mapping*/
                    143:     0,                         /* tp_hash */
                    144:     0,                         /* tp_call*/
                    145:     0,                         /* tp_str*/
                    146:     py_axl_stream_get_attr,    /* tp_getattro*/
                    147:     py_axl_stream_set_attr,    /* tp_setattro*/
                    148:     0,                         /* tp_as_buffer*/
                    149:     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,  /* tp_flags*/
                    150:     "Stream object; wrapper of axlStream API type",           /* tp_doc */
                    151:     0,                        /* tp_traverse */
                    152:     0,                        /* tp_clear */
                    153:     0,                        /* tp_richcompare */
                    154:     0,                        /* tp_weakstreamoffset */
                    155:     0,                        /* tp_iter */
                    156:     0,                        /* tp_iternext */
                    157:     py_axl_stream_methods,     /* tp_methods */
                    158:     0, /* py_axl_stream_members, */     /* tp_members */
                    159:     0,                         /* tp_getset */
                    160:     0,                         /* tp_base */
                    161:     0,                         /* tp_dict */
                    162:     0,                         /* tp_descr_get */
                    163:     0,                         /* tp_descr_set */
                    164:     0,                         /* tp_dictoffset */
                    165:     (initproc)py_axl_stream_init_type,      /* tp_init */
                    166:     0,                         /* tp_alloc */
                    167:     py_axl_stream_new,         /* tp_new */
                    168: 
                    169: };
                    170: 
                    171: 
                    172: /** 
                    173:  * @brief Allows to check if the PyObject received represents a
                    174:  * PyAxlStream reference.
                    175:  */
                    176: axl_bool             py_axl_stream_check    (PyObject          * obj)
                    177: {
                    178:        /* check null references */
                    179:        if (obj == NULL)
                    180:                return axl_false;
                    181: 
                    182:        /* return check result */
                    183:        return PyObject_TypeCheck (obj, &PyAxlStreamType);
                    184: }
                    185: 
                    186: void        init_axl_stream      (PyObject * module)
                    187: {
                    188:        /* register type */
                    189:        if (PyType_Ready(&PyAxlStreamType) < 0)
                    190:                return;
                    191:        
                    192:        Py_INCREF (&PyAxlStreamType);
                    193:        PyModule_AddObject(module, "Stream", (PyObject *)&PyAxlStreamType);
                    194: 
                    195: }
                    196: 
                    197: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>