1a45ae5f8SJohn Marino /* Python interface to new object file loading events.
2a45ae5f8SJohn Marino
3*ef5ccd6cSJohn Marino Copyright (C) 2011-2013 Free Software Foundation, Inc.
4a45ae5f8SJohn Marino
5a45ae5f8SJohn Marino This file is part of GDB.
6a45ae5f8SJohn Marino
7a45ae5f8SJohn Marino This program is free software; you can redistribute it and/or modify
8a45ae5f8SJohn Marino it under the terms of the GNU General Public License as published by
9a45ae5f8SJohn Marino the Free Software Foundation; either version 3 of the License, or
10a45ae5f8SJohn Marino (at your option) any later version.
11a45ae5f8SJohn Marino
12a45ae5f8SJohn Marino This program is distributed in the hope that it will be useful,
13a45ae5f8SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
14a45ae5f8SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15a45ae5f8SJohn Marino GNU General Public License for more details.
16a45ae5f8SJohn Marino
17a45ae5f8SJohn Marino You should have received a copy of the GNU General Public License
18a45ae5f8SJohn Marino along with this program. If not, see <http://www.gnu.org/licenses/>. */
19a45ae5f8SJohn Marino
20*ef5ccd6cSJohn Marino #include "defs.h"
21a45ae5f8SJohn Marino #include "py-event.h"
22a45ae5f8SJohn Marino
23a45ae5f8SJohn Marino static PyTypeObject new_objfile_event_object_type;
24a45ae5f8SJohn Marino
25*ef5ccd6cSJohn Marino static PyObject *
create_new_objfile_event_object(struct objfile * objfile)26a45ae5f8SJohn Marino create_new_objfile_event_object (struct objfile *objfile)
27a45ae5f8SJohn Marino {
28a45ae5f8SJohn Marino PyObject *objfile_event;
29a45ae5f8SJohn Marino PyObject *py_objfile;
30a45ae5f8SJohn Marino
31a45ae5f8SJohn Marino objfile_event = create_event_object (&new_objfile_event_object_type);
32a45ae5f8SJohn Marino if (!objfile_event)
33a45ae5f8SJohn Marino goto fail;
34a45ae5f8SJohn Marino
35*ef5ccd6cSJohn Marino /* Note that objfile_to_objfile_object returns a borrowed reference,
36*ef5ccd6cSJohn Marino so we don't need a decref here. */
37a45ae5f8SJohn Marino py_objfile = objfile_to_objfile_object (objfile);
38a45ae5f8SJohn Marino if (!py_objfile || evpy_add_attribute (objfile_event,
39a45ae5f8SJohn Marino "new_objfile",
40a45ae5f8SJohn Marino py_objfile) < 0)
41a45ae5f8SJohn Marino goto fail;
42a45ae5f8SJohn Marino
43a45ae5f8SJohn Marino return objfile_event;
44a45ae5f8SJohn Marino
45a45ae5f8SJohn Marino fail:
46a45ae5f8SJohn Marino Py_XDECREF (objfile_event);
47a45ae5f8SJohn Marino return NULL;
48a45ae5f8SJohn Marino }
49a45ae5f8SJohn Marino
50a45ae5f8SJohn Marino /* Callback function which notifies observers when a new objfile event occurs.
51a45ae5f8SJohn Marino This function will create a new Python new_objfile event object.
52a45ae5f8SJohn Marino Return -1 if emit fails. */
53a45ae5f8SJohn Marino
54a45ae5f8SJohn Marino int
emit_new_objfile_event(struct objfile * objfile)55a45ae5f8SJohn Marino emit_new_objfile_event (struct objfile *objfile)
56a45ae5f8SJohn Marino {
57a45ae5f8SJohn Marino PyObject *event;
58a45ae5f8SJohn Marino
59a45ae5f8SJohn Marino if (evregpy_no_listeners_p (gdb_py_events.new_objfile))
60a45ae5f8SJohn Marino return 0;
61a45ae5f8SJohn Marino
62a45ae5f8SJohn Marino event = create_new_objfile_event_object (objfile);
63a45ae5f8SJohn Marino if (event)
64a45ae5f8SJohn Marino return evpy_emit_event (event, gdb_py_events.new_objfile);
65a45ae5f8SJohn Marino return -1;
66a45ae5f8SJohn Marino }
67a45ae5f8SJohn Marino
68a45ae5f8SJohn Marino GDBPY_NEW_EVENT_TYPE (new_objfile,
69a45ae5f8SJohn Marino "gdb.NewObjFileEvent",
70a45ae5f8SJohn Marino "NewObjFileEvent",
71a45ae5f8SJohn Marino "GDB new object file event object",
72a45ae5f8SJohn Marino event_object_type,
73a45ae5f8SJohn Marino static);
74