TIVI-320: Add dbus-python to repos to support connman-test
[profile/ivi/dbus-python.git] / _dbus_bindings / float.c
1 /* Simple D-Bus types: Double and (with appropriate #defines) Float
2  *
3  * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
4  *
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:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
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.
24  */
25
26 #include <Python.h>
27 #include <structmember.h>
28
29 #include <stdint.h>
30
31 #include "dbus_bindings-internal.h"
32 #include "types-internal.h"
33
34 PyDoc_STRVAR(Double_tp_doc,
35 "A double-precision floating point number (a subtype of float).");
36
37 #ifdef WITH_DBUS_FLOAT32
38 PyDoc_STRVAR(Float_tp_doc,
39 "A single-precision floating point number (a subtype of float).");
40 #endif
41
42 PyTypeObject DBusPyDouble_Type = {
43     PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
44     0,
45     "dbus.Double",
46     0,
47     0,
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 */
82 };
83
84 #ifdef WITH_DBUS_FLOAT32
85
86 PyTypeObject DBusPyFloat_Type = {
87     PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
88     0,
89     "dbus.Float",
90     0,
91     0,
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 */
126 };
127 #endif /* defined(WITH_DBUS_FLOAT32) */
128
129 dbus_bool_t
130 dbus_py_init_float_types(void)
131 {
132     DBusPyDouble_Type.tp_base = &DBusPyFloatBase_Type;
133     if (PyType_Ready(&DBusPyDouble_Type) < 0) return 0;
134     DBusPyDouble_Type.tp_print = NULL;
135
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
141
142     return 1;
143 }
144
145 dbus_bool_t
146 dbus_py_insert_float_types(PyObject *this_module)
147 {
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
156
157     return 1;
158 }