/[ascend]/trunk/pygtk/interface/reporter.cpp
ViewVC logotype

Contents of /trunk/pygtk/interface/reporter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 500 - (show annotations) (download) (as text)
Tue Apr 18 11:55:12 2006 UTC (14 years, 7 months ago) by johnpye
File MIME type: text/x-c++src
File size: 2422 byte(s)
Reduced some runtime debug messages from Python and C++ and base/generic/compiler/type_descio.c.
Fixed up support for GCC Visibility and add SCons 'sniffer' for this.
Fixed a bug with 'fileopenpath' in PyGTK interface (File->Open location is remembered from last time).
Fixed a bug with missing includes in C++.
1 #ifdef ASCXX_USE_PYTHON
2 # include <Python.h>
3 #endif
4
5 #include <cstdio>
6 #include <iostream>
7 using namespace std;
8
9 #include "config.h"
10 #ifndef ASCXX_USE_PYTHON
11 # error "Where's ASCXX_USE_PYTHON?"
12 #endif
13
14 #include "reporter.h"
15
16 static const int REPORTER_MAX_ERROR_MSG = 1024;
17
18 #ifdef ASCXX_USE_PYTHON
19 // Python-invoking callback function
20 int reporter_error_python(ERROR_REPORTER_CALLBACK_ARGS){
21 Reporter *reporter = Reporter::Instance();
22 return reporter->reportErrorPython(ERROR_REPORTER_CALLBACK_VARS);
23 }
24 #endif
25
26 Reporter::Reporter(){
27 error_reporter_set_callback(NULL);
28 }
29
30 Reporter *Reporter::_instance;
31
32 Reporter *
33 Reporter::Instance(){
34 if(_instance==0){
35 _instance = new Reporter();
36 }
37 return _instance;
38 }
39
40 Reporter *getReporter(){
41 return Reporter::Instance();
42 }
43
44 Reporter::~Reporter(){
45 error_reporter_set_callback(NULL);
46 }
47
48 void
49 Reporter::setErrorCallback(error_reporter_callback_t callback, void *client_data){
50 this->client_data = client_data;
51 error_reporter_set_callback(callback);
52 }
53
54 /*
55 int
56 Reporter::reportError(ERROR_REPORTER_CALLBACK_ARGS){
57 char msg[REPORTER_MAX_ERROR_MSG];
58 vsnprintf(msg,REPORTER_MAX_ERROR_MSG,fmt,args);
59 cerr << char(27) << "[32;1m" << msg << char(27) << "[0m";
60 return strlen(msg) + 11; // 11 chars worth of escape codes
61 }
62 */
63
64 #ifdef ASCXX_USE_PYTHON
65 int
66 Reporter::reportErrorPython(ERROR_REPORTER_CALLBACK_ARGS){
67 PyObject *pyfunc, *pyarglist, *pyresult;
68 pyfunc = (PyObject *)client_data;
69
70 char msg[REPORTER_MAX_ERROR_MSG];
71 vsprintf(msg,fmt,args);
72
73 //cerr << "reportErrorPython: msg=" << msg ;
74 //cerr << "reportErrorPython: pyfunc=" << pyfunc << endl;
75
76 pyarglist = Py_BuildValue("(H,z,i,z)",sev,filename,line,msg); // Build argument list
77 pyresult = PyEval_CallObject(pyfunc,pyarglist); // Call Python
78 Py_DECREF(pyarglist); // Trash arglist
79
80 int res = 0;
81 if (pyresult) { // If no errors, return int
82 long long_res = PyInt_AsLong(pyresult);
83 res = int(long_res);
84 }else{
85 //cerr << "pyresult = 0"<< endl;
86 }
87
88 Py_XDECREF(pyresult);
89 return res;
90 }
91
92 void
93 Reporter::setPythonErrorCallback(PyObject *pyfunc) {
94 setErrorCallback(reporter_error_python, (void *) pyfunc);
95 Py_INCREF(pyfunc);
96 is_python = true;
97 }
98
99 void
100 Reporter::clearPythonErrorCallback(){
101 if(is_python){
102 PyObject *pyfunc = (PyObject *)client_data;
103 Py_DECREF(pyfunc);
104 is_python=false;
105 }
106 setErrorCallback(NULL);
107 }
108
109 #endif

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22