diff options
author | Christopher Davis <loafier@gmail.com> | 2006-06-19 12:25:06 +0000 |
---|---|---|
committer | Christopher Davis <loafier@gmail.com> | 2006-06-19 12:25:06 +0000 |
commit | bb48c914c6239ed1dbcb29eb62d33d3ab91e7215 (patch) | |
tree | 0b6910959f96f683f3aa11a8e2f53572e42b3305 /objects/irc-connect-object.c | |
parent | efef73ae301947875602d67d0979a8ce3bd57dd0 (diff) | |
download | irssi-python-bb48c914c6239ed1dbcb29eb62d33d3ab91e7215.tar.gz irssi-python-bb48c914c6239ed1dbcb29eb62d33d3ab91e7215.tar.xz irssi-python-bb48c914c6239ed1dbcb29eb62d33d3ab91e7215.zip |
initial import
git-svn-id: http://svn.irssi.org/repos/irssi-python@4282 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'objects/irc-connect-object.c')
-rw-r--r-- | objects/irc-connect-object.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/objects/irc-connect-object.c b/objects/irc-connect-object.c new file mode 100644 index 0000000..6e2d3a7 --- /dev/null +++ b/objects/irc-connect-object.c @@ -0,0 +1,99 @@ +#include <Python.h> +#include "pymodule.h" +#include "base-objects.h" +#include "irc-connect-object.h" +#include "pyirssi_irc.h" +#include "pycore.h" +#include "pyutils.h" + +/* member IDs */ +enum +{ + M_IRC_CONNECT_ALTERNATE_NICK, +}; + +/* cleanup and deallocation handled by Connect base */ + +static PyObject *PyIrcConnect_get(PyIrcConnect *self, void *closure) +{ + int member = GPOINTER_TO_INT(closure); + + RET_NULL_IF_INVALID(self->data); + + switch (member) + { + case M_IRC_CONNECT_ALTERNATE_NICK: + RET_AS_STRING_OR_NONE(self->data->alternate_nick); + } + + /* This shouldn't be reached... but... */ + return PyErr_Format(PyExc_RuntimeError, "invalid member id, %d", member); +} + +static PyGetSetDef PyIrcConnect_getseters[] = { + {"alternate_nick", (getter)PyIrcConnect_get, NULL, + "Alternate nick to use if default nick is taken", + GINT_TO_POINTER(M_IRC_CONNECT_ALTERNATE_NICK)}, + + {NULL} +}; + +PyTypeObject PyIrcConnectType = { + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "IrcConnect", /*tp_name*/ + sizeof(PyIrcConnect), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + 0, /*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*/ + "PyIrcConnect objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + PyIrcConnect_getseters, /* tp_getset */ + &PyConnectType, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +PyObject *pyirc_connect_new(void *connect, int managed) +{ + return pyconnect_sub_new(connect, &PyIrcConnectType, managed); +} + +int irc_connect_object_init(void) +{ + g_return_val_if_fail(py_module != NULL, 0); + + if (PyType_Ready(&PyIrcConnectType) < 0) + return 0; + + Py_INCREF(&PyIrcConnectType); + PyModule_AddObject(py_module, "IrcConnect", (PyObject *)&PyIrcConnectType); + + return 1; +} |