summaryrefslogtreecommitdiffstats
path: root/objects/netsplit-channel-object.c
blob: 3e2639bf1282c5060ca9700e71b9a9e013aeeb4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <Python.h>
#include "pyirssi_irc.h"
#include "pymodule.h"
#include "netsplit-channel-object.h"
#include "factory.h"
#include "pycore.h"

/* value copied -- no special cleanup */

static void PyNetsplitChannel_dealloc(PyNetsplitChannel *self)
{
    Py_XDECREF(self->name);

    self->ob_type->tp_free((PyObject*)self);
}

static PyObject *PyNetsplitChannel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    PyNetsplitChannel *self;

    self = (PyNetsplitChannel *)type->tp_alloc(type, 0);
    if (!self)
        return NULL;

    return (PyObject *)self;
}

/* Getters */
PyDoc_STRVAR(PyNetsplitChannel_name_doc,
    "Channel name"
);
static PyObject *PyNetsplitChannel_name_get(PyNetsplitChannel *self, void *closure)
{
    RET_AS_OBJ_OR_NONE(self->name);
}

PyDoc_STRVAR(PyNetsplitChannel_op_doc,
    "is op"
);
static PyObject *PyNetsplitChannel_op_get(PyNetsplitChannel *self, void *closure)
{
    return PyBool_FromLong(self->op);
}

PyDoc_STRVAR(PyNetsplitChannel_halfop_doc,
    "is halfop"
);
static PyObject *PyNetsplitChannel_halfop_get(PyNetsplitChannel *self, void *closure)
{
    return PyBool_FromLong(self->halfop);
}

PyDoc_STRVAR(PyNetsplitChannel_voice_doc,
    "is voice"
);
static PyObject *PyNetsplitChannel_voice_get(PyNetsplitChannel *self, void *closure)
{
    return PyBool_FromLong(self->voice);
}

PyDoc_STRVAR(PyNetsplitChannel_other_doc,
    "?"
);
static PyObject *PyNetsplitChannel_other_get(PyNetsplitChannel *self, void *closure)
{
    return PyInt_FromLong(self->other);
}

/* specialized getters/setters */
static PyGetSetDef PyNetsplitChannel_getseters[] = {
    {"name", (getter)PyNetsplitChannel_name_get, NULL,
        PyNetsplitChannel_name_doc, NULL},
    {"op", (getter)PyNetsplitChannel_op_get, NULL,
        PyNetsplitChannel_op_doc, NULL},
    {"halfop", (getter)PyNetsplitChannel_halfop_get, NULL,
        PyNetsplitChannel_halfop_doc, NULL},
    {"voice", (getter)PyNetsplitChannel_voice_get, NULL,
        PyNetsplitChannel_voice_doc, NULL},
    {"other", (getter)PyNetsplitChannel_other_get, NULL,
        PyNetsplitChannel_other_doc, NULL},
    {NULL}
};

/* Methods */
/* Methods for object */
static PyMethodDef PyNetsplitChannel_methods[] = {
    {NULL}  /* Sentinel */
};

PyTypeObject PyNetsplitChannelType = {
    PyObject_HEAD_INIT(NULL)
    0,                         /*ob_size*/
    "NetsplitChannel",            /*tp_name*/
    sizeof(PyNetsplitChannel),             /*tp_basicsize*/
    0,                         /*tp_itemsize*/
    (destructor)PyNetsplitChannel_dealloc, /*tp_dealloc*/
    0,                         /*tp_print*/
    0,                         /*tp_getattr*/
    0,                         /*tp_setattr*/
    0,                         /*tp_compare*/
    0,                         /*tp_repr*/
    0,                         /*tp_as_number*/
    0,                         /*tp_as_sequence*/
    0,                         /*tp_as_mapping*/
    0,                         /*tp_hash */
    0,                         /*tp_call*/
    0,                         /*tp_str*/
    0,                         /*tp_getattro*/
    0,                         /*tp_setattro*/
    0,                         /*tp_as_buffer*/
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
    "PyNetsplitChannel objects",           /* tp_doc */
    0,		               /* tp_traverse */
    0,		               /* tp_clear */
    0,		               /* tp_richcompare */
    0,		               /* tp_weaklistoffset */
    0,		               /* tp_iter */
    0,		               /* tp_iternext */
    PyNetsplitChannel_methods,             /* tp_methods */
    0,                      /* tp_members */
    PyNetsplitChannel_getseters,        /* tp_getset */
    0,          /* tp_base */
    0,                         /* tp_dict */
    0,                         /* tp_descr_get */
    0,                         /* tp_descr_set */
    0,                         /* tp_dictoffset */
    0,      /* tp_init */
    0,                         /* tp_alloc */
    PyNetsplitChannel_new,                 /* tp_new */
};


/* window item wrapper factory function */
PyObject *pynetsplit_channel_new(void *netsplit)
{
    NETSPLIT_CHAN_REC *rec = netsplit;
    PyNetsplitChannel *pynetsplit;
    PyObject *name; 

    name = PyString_FromString(rec->name);
    if (!name)
        return NULL;

    pynetsplit = py_inst(PyNetsplitChannel, PyNetsplitChannelType);
    if (!pynetsplit)
    {
        Py_DECREF(name);
        return NULL;
    }

    pynetsplit->name = name;
    pynetsplit->op = rec->op;
    pynetsplit->halfop = rec->halfop;
    pynetsplit->other = rec->other;
    
    return (PyObject *)pynetsplit;
}

int netsplit_channel_object_init(void) 
{
    g_return_val_if_fail(py_module != NULL, 0);

    if (PyType_Ready(&PyNetsplitChannelType) < 0)
        return 0;
    
    Py_INCREF(&PyNetsplitChannelType);
    PyModule_AddObject(py_module, "NetsplitChannel", (PyObject *)&PyNetsplitChannelType);

    return 1;
}