You need to sign in or sign up before continuing.
typewrappers.c 5.7 KB
Newer Older
1 2 3 4
/*
 * types.c: converter functions between the internal representation
 *          and the Python objects
 *
5
 * Copyright (C) 2005, 2007 Red Hat, Inc.
6 7 8 9
 *
 * Daniel Veillard <veillard@redhat.com>
 */

10
#include <config.h>
11

D
Daniel P. Berrange 已提交
12 13 14 15 16
/* Horrible kludge to work around even more horrible name-space pollution
 *    via Python.h.  That file includes /usr/include/python2.5/pyconfig*.h,
 *       which has over 180 autoconf-style HAVE_* definitions.  Shame on them.  */
#undef HAVE_PTHREAD_H

17
#include "typewrappers.h"
18 19

PyObject *
20
libvirt_intWrap(int val)
21 22 23 24 25 26 27
{
    PyObject *ret;
    ret = PyInt_FromLong((long) val);
    return (ret);
}

PyObject *
28
libvirt_longWrap(long val)
29 30 31 32 33 34
{
    PyObject *ret;
    ret = PyInt_FromLong(val);
    return (ret);
}

35 36 37 38 39 40
PyObject *
libvirt_ulongWrap(unsigned long val)
{
    PyObject *ret;
    ret = PyLong_FromLong(val);
    return (ret);
41
}
42

43
PyObject *
44
libvirt_longlongWrap(long long val)
45 46 47 48 49 50
{
    PyObject *ret;
    ret = PyLong_FromUnsignedLongLong((unsigned long long) val);
    return (ret);
}

51
PyObject *
52
libvirt_charPtrWrap(char *str)
53 54 55 56 57 58 59 60 61 62 63 64 65
{
    PyObject *ret;

    if (str == NULL) {
        Py_INCREF(Py_None);
        return (Py_None);
    }
    ret = PyString_FromString(str);
    free(str);
    return (ret);
}

PyObject *
66
libvirt_constcharPtrWrap(const char *str)
67 68 69 70 71 72 73 74 75 76 77 78
{
    PyObject *ret;

    if (str == NULL) {
        Py_INCREF(Py_None);
        return (Py_None);
    }
    ret = PyString_FromString(str);
    return (ret);
}

PyObject *
79
libvirt_charPtrConstWrap(const char *str)
80 81 82 83 84 85 86 87 88 89 90 91
{
    PyObject *ret;

    if (str == NULL) {
        Py_INCREF(Py_None);
        return (Py_None);
    }
    ret = PyString_FromString(str);
    return (ret);
}

PyObject *
92
libvirt_virDomainPtrWrap(virDomainPtr node)
93 94 95 96 97 98 99 100 101 102 103 104 105
{
    PyObject *ret;

    if (node == NULL) {
        Py_INCREF(Py_None);
        return (Py_None);
    }
    ret =
        PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virDomainPtr",
                                     NULL);
    return (ret);
}

106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
PyObject *
libvirt_virNetworkPtrWrap(virNetworkPtr node)
{
    PyObject *ret;

    if (node == NULL) {
        Py_INCREF(Py_None);
        return (Py_None);
    }
    ret =
        PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virNetworkPtr",
                                     NULL);
    return (ret);
}

121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
PyObject *
libvirt_virInterfacePtrWrap(virInterfacePtr node)
{
    PyObject *ret;

    if (node == NULL) {
        Py_INCREF(Py_None);
        return (Py_None);
    }
    ret =
        PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virInterfacePtr",
                                     NULL);
    return (ret);
}

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
PyObject *
libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node)
{
    PyObject *ret;

    if (node == NULL) {
        Py_INCREF(Py_None);
        return (Py_None);
    }
    ret =
        PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virStoragePoolPtr",
                                     NULL);
    return (ret);
}

PyObject *
libvirt_virStorageVolPtrWrap(virStorageVolPtr node)
{
    PyObject *ret;

    if (node == NULL) {
        Py_INCREF(Py_None);
        return (Py_None);
    }
    ret =
        PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virStorageVolPtr",
                                     NULL);
    return (ret);
}

166
PyObject *
167
libvirt_virConnectPtrWrap(virConnectPtr node)
168 169 170 171 172 173 174 175 176 177 178 179
{
    PyObject *ret;

    if (node == NULL) {
        Py_INCREF(Py_None);
        return (Py_None);
    }
    ret =
        PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virConnectPtr",
                                     NULL);
    return (ret);
}
180

181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
PyObject *
libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node)
{
    PyObject *ret;

    if (node == NULL) {
        Py_INCREF(Py_None);
        return (Py_None);
    }
    ret =
        PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virNodeDevicePtr",
                                     NULL);
    return (ret);
}

196 197 198 199 200 201 202 203 204 205 206 207 208
PyObject *
libvirt_virSecretPtrWrap(virSecretPtr node)
{
    PyObject *ret;

    if (node == NULL) {
        Py_INCREF(Py_None);
        return Py_None;
    }
    ret = PyCObject_FromVoidPtrAndDesc(node, (char *) "virSecretPtr", NULL);
    return (ret);
}

209 210 211 212 213 214 215 216 217 218 219 220 221
PyObject *
libvirt_virStreamPtrWrap(virStreamPtr node)
{
    PyObject *ret;

    if (node == NULL) {
        Py_INCREF(Py_None);
        return Py_None;
    }
    ret = PyCObject_FromVoidPtrAndDesc(node, (char *) "virStreamPtr", NULL);
    return (ret);
}

222 223 224 225 226 227 228
PyObject *
libvirt_virEventHandleCallbackWrap(virEventHandleCallback node)
{
    PyObject *ret;

    if (node == NULL) {
        Py_INCREF(Py_None);
229
        printf("%s: WARNING - Wrapping None\n", __func__);
230 231 232 233 234 235 236 237 238 239 240 241 242 243
        return (Py_None);
    }
    ret =
        PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virEventHandleCallback",
                                     NULL);
    return (ret);
}

PyObject *
libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node)
{
    PyObject *ret;

    if (node == NULL) {
244
        printf("%s: WARNING - Wrapping None\n", __func__);
245 246 247 248 249 250 251 252 253
        Py_INCREF(Py_None);
        return (Py_None);
    }
    ret =
        PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virEventTimeoutCallback",
                                     NULL);
    return (ret);
}

254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
PyObject *
libvirt_virFreeCallbackWrap(virFreeCallback node)
{
    PyObject *ret;

    if (node == NULL) {
        Py_INCREF(Py_None);
        return (Py_None);
    }
    ret =
        PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virFreeCallback",
                                     NULL);
    return (ret);
}

269 270 271 272 273 274 275 276 277 278 279 280 281 282
PyObject *
libvirt_virVoidPtrWrap(void* node)
{
    PyObject *ret;

    if (node == NULL) {
        Py_INCREF(Py_None);
        return (Py_None);
    }
    ret =
        PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "void*",
                                     NULL);
    return (ret);
}