Add wrapper for DBusServer.
[dbus-python-phuang.git] / _dbus_bindings / float.c
blob5826ec376a1431a4aa22f87ba766f9f778f9ce30
1 /* Simple D-Bus types: Double and (with appropriate #defines) Float
3 * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 #include <Python.h>
27 #include <structmember.h>
29 #include <stdint.h>
31 #include "dbus_bindings-internal.h"
32 #include "types-internal.h"
34 PyDoc_STRVAR(Double_tp_doc,
35 "A double-precision floating point number (a subtype of float).");
37 #ifdef WITH_DBUS_FLOAT32
38 PyDoc_STRVAR(Float_tp_doc,
39 "A single-precision floating point number (a subtype of float).");
40 #endif
42 PyTypeObject DBusPyDouble_Type = {
43 PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
45 "dbus.Double",
48 0, /* tp_dealloc */
49 0, /* tp_print */
50 0, /* tp_getattr */
51 0, /* tp_setattr */
52 0, /* tp_compare */
53 0, /* tp_repr */
54 0, /* tp_as_number */
55 0, /* tp_as_sequence */
56 0, /* tp_as_mapping */
57 0, /* tp_hash */
58 0, /* tp_call */
59 0, /* tp_str */
60 0, /* tp_getattro */
61 0, /* tp_setattro */
62 0, /* tp_as_buffer */
63 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
64 Double_tp_doc, /* tp_doc */
65 0, /* tp_traverse */
66 0, /* tp_clear */
67 0, /* tp_richcompare */
68 0, /* tp_weaklistoffset */
69 0, /* tp_iter */
70 0, /* tp_iternext */
71 0, /* tp_methods */
72 0, /* tp_members */
73 0, /* tp_getset */
74 DEFERRED_ADDRESS(&DBusPythonFloatType), /* tp_base */
75 0, /* tp_dict */
76 0, /* tp_descr_get */
77 0, /* tp_descr_set */
78 0, /* tp_dictoffset */
79 0, /* tp_init */
80 0, /* tp_alloc */
81 0, /* tp_new */
84 #ifdef WITH_DBUS_FLOAT32
86 PyTypeObject DBusPyFloat_Type = {
87 PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
89 "dbus.Float",
92 0, /* tp_dealloc */
93 0, /* tp_print */
94 0, /* tp_getattr */
95 0, /* tp_setattr */
96 0, /* tp_compare */
97 0, /* tp_repr */
98 0, /* tp_as_number */
99 0, /* tp_as_sequence */
100 0, /* tp_as_mapping */
101 0, /* tp_hash */
102 0, /* tp_call */
103 0, /* tp_str */
104 0, /* tp_getattro */
105 0, /* tp_setattro */
106 0, /* tp_as_buffer */
107 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
108 Float_tp_doc, /* tp_doc */
109 0, /* tp_traverse */
110 0, /* tp_clear */
111 0, /* tp_richcompare */
112 0, /* tp_weaklistoffset */
113 0, /* tp_iter */
114 0, /* tp_iternext */
115 0, /* tp_methods */
116 0, /* tp_members */
117 0, /* tp_getset */
118 DEFERRED_ADDRESS(&DBusPythonFloatType), /* tp_base */
119 0, /* tp_dict */
120 0, /* tp_descr_get */
121 0, /* tp_descr_set */
122 0, /* tp_dictoffset */
123 0, /* tp_init */
124 0, /* tp_alloc */
125 0, /* tp_new */
127 #endif /* defined(WITH_DBUS_FLOAT32) */
129 dbus_bool_t
130 dbus_py_init_float_types(void)
132 DBusPyDouble_Type.tp_base = &DBusPyFloatBase_Type;
133 if (PyType_Ready(&DBusPyDouble_Type) < 0) return 0;
134 DBusPyDouble_Type.tp_print = NULL;
136 #ifdef WITH_DBUS_FLOAT32
137 DBusPyFloat_Type.tp_base = &DBusPyFloatBase_Type;
138 if (PyType_Ready(&DBusPyFloat_Type) < 0) return 0;
139 DBusPyFloat_Type.tp_print = NULL;
140 #endif
142 return 1;
145 dbus_bool_t
146 dbus_py_insert_float_types(PyObject *this_module)
148 Py_INCREF(&DBusPyDouble_Type);
149 if (PyModule_AddObject(this_module, "Double",
150 (PyObject *)&DBusPyDouble_Type) < 0) return 0;
151 #ifdef WITH_DBUS_FLOAT32
152 Py_INCREF(&DBusPyFloat_Type);
153 if (PyModule_AddObject(this_module, "Float",
154 (PyObject *)&DBusPyFloat_Type) < 0) return 0;
155 #endif
157 return 1;