PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/GStreamer/Source/gst-python/gst/pygstexception.c

http://ossbuild.googlecode.com/
C | 269 lines | 172 code | 63 blank | 34 comment | 46 complexity | dabfa9e00ac88d6bee0296546a96c275 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-2.0, AGPL-1.0, LGPL-2.1, LGPL-2.0, GPL-3.0, LGPL-3.0, CC-BY-SA-3.0
  1. /*
  2. * pygstexception.c - gst-python exceptions
  3. * Copyright (C) 2005 Alessandro Decina
  4. *
  5. * Authors:
  6. * Alessandro Decina <alessandro@nnva.org>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Library General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Library General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public
  19. * License along with this library; if not, write to the
  20. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. * Boston, MA 02111-1307, USA.
  22. */
  23. #include <Python.h>
  24. #include "structmember.h"
  25. PyObject *PyGstExc_LinkError = NULL;
  26. PyObject *PyGstExc_AddError = NULL;
  27. PyObject *PyGstExc_QueryError = NULL;
  28. PyObject *PyGstExc_RemoveError = NULL;
  29. PyObject *PyGstExc_PluginNotFoundError = NULL;
  30. PyObject *PyGstExc_ElementNotFoundError = NULL;
  31. static PyObject *
  32. call_exception_init (PyObject * args)
  33. {
  34. PyObject *parent_init = NULL;
  35. PyObject *res = NULL;
  36. /* get Exception.__init__ */
  37. parent_init = PyObject_GetAttrString (PyExc_Exception, "__init__");
  38. if (parent_init == NULL)
  39. goto exception;
  40. /* call Exception.__init__. This will set self.args */
  41. res = PyObject_CallObject (parent_init, args);
  42. if (res == NULL)
  43. goto exception;
  44. Py_DECREF (parent_init);
  45. return res;
  46. exception:
  47. Py_XDECREF (parent_init);
  48. Py_XDECREF (res);
  49. return NULL;
  50. }
  51. static int
  52. add_method (PyObject * klass, PyObject * dict, PyMethodDef * method)
  53. {
  54. PyObject *module = NULL;
  55. PyObject *func = NULL;
  56. PyObject *meth = NULL;
  57. module = PyString_FromString ("gst");
  58. if (module == NULL)
  59. goto exception;
  60. func = PyCFunction_NewEx (method, NULL, module);
  61. if (func == NULL)
  62. goto exception;
  63. Py_DECREF (module);
  64. meth = PyMethod_New (func, NULL, klass);
  65. if (meth == NULL)
  66. goto exception;
  67. Py_DECREF (func);
  68. if (PyDict_SetItemString (dict, method->ml_name, meth) < 0)
  69. goto exception;
  70. Py_DECREF (meth);
  71. return 0;
  72. exception:
  73. Py_XDECREF (module);
  74. Py_XDECREF (func);
  75. Py_XDECREF (meth);
  76. return -1;
  77. }
  78. static PyObject *
  79. link_error_init (PyObject * self, PyObject * args)
  80. {
  81. PyObject *err_type = NULL;
  82. int status;
  83. if (!PyArg_ParseTuple (args, "O|O:__init__", &self, &err_type))
  84. return NULL;
  85. if (err_type == NULL)
  86. err_type = Py_None;
  87. Py_INCREF (err_type);
  88. /* set self.error */
  89. status = PyObject_SetAttrString (self, "error", err_type);
  90. Py_DECREF (err_type);
  91. if (status < 0)
  92. return NULL;
  93. return call_exception_init (args);
  94. }
  95. static PyObject *
  96. element_not_found_error_init (PyObject * self, PyObject * args)
  97. {
  98. PyObject *element_name = NULL;
  99. int status;
  100. if (!PyArg_ParseTuple (args, "O|O:__init__", &self, &element_name))
  101. return NULL;
  102. if (element_name == NULL)
  103. element_name = Py_None;
  104. Py_INCREF (element_name);
  105. /* set self.name */
  106. status = PyObject_SetAttrString (self, "name", element_name);
  107. Py_DECREF (element_name);
  108. if (status < 0)
  109. return NULL;
  110. return call_exception_init (args);
  111. }
  112. static PyMethodDef link_error_init_method = { "__init__",
  113. link_error_init, METH_VARARGS
  114. };
  115. static PyMethodDef element_not_found_error_init_method = { "__init__",
  116. element_not_found_error_init, METH_VARARGS
  117. };
  118. void
  119. pygst_exceptions_register_classes (PyObject * d)
  120. {
  121. PyObject *dict = NULL;
  122. /* register gst.LinkError */
  123. dict = PyDict_New ();
  124. if (dict == NULL)
  125. goto exception;
  126. PyGstExc_LinkError = PyErr_NewException ("gst.LinkError",
  127. PyExc_Exception, dict);
  128. if (PyGstExc_LinkError == NULL)
  129. goto exception;
  130. if (add_method (PyGstExc_LinkError, dict, &link_error_init_method) < 0)
  131. goto exception;
  132. Py_DECREF (dict);
  133. if (PyDict_SetItemString (d, "LinkError", PyGstExc_LinkError) < 0)
  134. goto exception;
  135. Py_DECREF (PyGstExc_LinkError);
  136. /* register gst.AddError */
  137. PyGstExc_AddError = PyErr_NewException ("gst.AddError",
  138. PyExc_Exception, NULL);
  139. if (PyGstExc_AddError == NULL)
  140. goto exception;
  141. if (PyDict_SetItemString (d, "AddError", PyGstExc_AddError) < 0)
  142. goto exception;
  143. Py_DECREF (PyGstExc_AddError);
  144. /* register gst.RemoveError */
  145. PyGstExc_RemoveError = PyErr_NewException ("gst.RemoveError",
  146. PyExc_Exception, NULL);
  147. if (PyGstExc_RemoveError == NULL)
  148. goto exception;
  149. if (PyDict_SetItemString (d, "RemoveError", PyGstExc_RemoveError) < 0)
  150. goto exception;
  151. Py_DECREF (PyGstExc_RemoveError);
  152. /* register gst.QueryError */
  153. PyGstExc_QueryError = PyErr_NewException ("gst.QueryError",
  154. PyExc_Exception, NULL);
  155. if (PyGstExc_QueryError == NULL)
  156. goto exception;
  157. if (PyDict_SetItemString (d, "QueryError", PyGstExc_QueryError) < 0)
  158. goto exception;
  159. Py_DECREF (PyGstExc_QueryError);
  160. /* FIXME: remove this method in 0.11; element_factory_make deals with element
  161. factories, not plug-ins */
  162. /* register gst.PluginNotFoundError */
  163. dict = PyDict_New ();
  164. if (dict == NULL)
  165. goto exception;
  166. PyGstExc_PluginNotFoundError =
  167. PyErr_NewException ("gst.PluginNotFoundError", PyExc_Exception, dict);
  168. if (PyGstExc_PluginNotFoundError == NULL)
  169. goto exception;
  170. if (add_method (PyGstExc_PluginNotFoundError,
  171. dict, &element_not_found_error_init_method) < 0)
  172. goto exception;
  173. Py_DECREF (dict);
  174. if (PyDict_SetItemString (d, "PluginNotFoundError",
  175. PyGstExc_PluginNotFoundError) < 0)
  176. goto exception;
  177. Py_DECREF (PyGstExc_PluginNotFoundError);
  178. /* register gst.ElementNotFoundError */
  179. dict = PyDict_New ();
  180. if (dict == NULL)
  181. goto exception;
  182. PyGstExc_ElementNotFoundError =
  183. PyErr_NewException ("gst.ElementNotFoundError",
  184. PyGstExc_PluginNotFoundError, dict);
  185. if (PyGstExc_ElementNotFoundError == NULL)
  186. goto exception;
  187. if (add_method (PyGstExc_ElementNotFoundError,
  188. dict, &element_not_found_error_init_method) < 0)
  189. goto exception;
  190. Py_DECREF (dict);
  191. if (PyDict_SetItemString (d, "ElementNotFoundError",
  192. PyGstExc_ElementNotFoundError) < 0)
  193. goto exception;
  194. Py_DECREF (PyGstExc_ElementNotFoundError);
  195. return;
  196. return;
  197. exception:
  198. Py_XDECREF (dict);
  199. Py_XDECREF (PyGstExc_LinkError);
  200. Py_XDECREF (PyGstExc_AddError);
  201. Py_XDECREF (PyGstExc_RemoveError);
  202. Py_XDECREF (PyGstExc_QueryError);
  203. Py_XDECREF (PyGstExc_PluginNotFoundError);
  204. Py_XDECREF (PyGstExc_ElementNotFoundError);
  205. return;
  206. }