| 1 |
#ifndef ASCXX_REPORTER_H |
| 2 |
#define ASCXX_REPORTER_H |
| 3 |
|
| 4 |
#include "config.h" |
| 5 |
|
| 6 |
#ifdef ASCXX_USE_PYTHON |
| 7 |
# include <Python.h> |
| 8 |
#endif |
| 9 |
|
| 10 |
extern "C"{ |
| 11 |
#include <utilities/ascConfig.h> |
| 12 |
#include <utilities/error.h> |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
#ifdef ASCXX_USE_PYTHON |
| 17 |
extern "C"{ |
| 18 |
/** |
| 19 |
This function is a hook function that will convey errors |
| 20 |
back to Python via the C++ 'Reporter' class. |
| 21 |
*/ |
| 22 |
ASC_EXPORT(int) reporter_error_python(ERROR_REPORTER_CALLBACK_ARGS); |
| 23 |
} |
| 24 |
#endif |
| 25 |
|
| 26 |
/** |
| 27 |
This class provides C++ abstraction of the error.h error callback |
| 28 |
interface. |
| 29 |
|
| 30 |
Initially, it's trying to just handling the conveying of error |
| 31 |
messages back to python, but it could be used to pass back |
| 32 |
all sorts of other 'messages' eventually. |
| 33 |
|
| 34 |
Maybe raising alerts, notifying of the progress of big tasks, etc. |
| 35 |
|
| 36 |
The client_data pointer allows callback context to be set. This will |
| 37 |
be used to specify which Python function should be used for error |
| 38 |
reporting, in the case of the Python extension to this class. |
| 39 |
*/ |
| 40 |
class Reporter{ |
| 41 |
private: |
| 42 |
void *client_data; |
| 43 |
Reporter(); // This class will be a singleton |
| 44 |
~Reporter(); |
| 45 |
static Reporter *_instance; |
| 46 |
#ifdef ASCXX_USE_PYTHON |
| 47 |
bool is_python; |
| 48 |
#endif |
| 49 |
|
| 50 |
public: |
| 51 |
static ASC_EXPORT(Reporter *) Instance(); |
| 52 |
void setErrorCallback(error_reporter_callback_t, void *client_data=NULL); |
| 53 |
|
| 54 |
#ifdef ASCXX_USE_PYTHON |
| 55 |
void setPythonErrorCallback(PyObject *pyfunc); |
| 56 |
void clearPythonErrorCallback(); |
| 57 |
int reportErrorPython(ERROR_REPORTER_CALLBACK_ARGS); |
| 58 |
#endif |
| 59 |
|
| 60 |
}; |
| 61 |
|
| 62 |
Reporter *getReporter(); |
| 63 |
|
| 64 |
#endif // ASCXX_REPORTER_H |