1 typedef struct
{} Context
;
3 /* called by python-module plugin
*/
4 Context
(PyObject
*obj
) {
5 Context
*context
= PyCObject_AsVoidPtr
(obj
);
6 osync_context_ref
(context
);
12 Context
*context
= osync_context_new
(&err);
13 if
(raise_exception_on_error
(err
))
20 osync_context_unref
(self
);
23 void report_error
(ErrorType type
, const char
*msg
) {
24 osync_context_report_error
(self
, type
, "%s", msg
);
27 void report_success
() {
28 osync_context_report_success
(self
);
31 void report_osyncerror
(Error
*error
) {
32 osync_context_report_osyncerror
(self
, error
);
35 void report_osyncwarning
(Error
*error
) {
36 osync_context_report_osyncwarning
(self
, error
);
39 void report_change
(Change
*change
) {
40 osync_context_report_change
(self
, change
);
44 static void context_callback_wrapper
(void
*clientdata
, OSyncError
*err
) {
45 PyGILState_STATE pystate
= PyGILState_Ensure
();
47 PyObject
*handler
= clientdata
;
48 PyObject
*errobj
= SWIG_NewPointerObj
(err
, SWIGTYPE_p_Error
, 0);
49 PyObject
*result
= PyObject_CallMethod
(handler
, "callback", "(O)", errobj
);
52 /* there's no way to report an error to OpenSync
, so we just print it
*/
56 PyGILState_Release
(pystate
);
59 static void context_changes_wrapper
(OSyncChange
*change
, void
*clientdata
) {
60 PyGILState_STATE pystate
= PyGILState_Ensure
();
62 PyObject
*handler
= clientdata
;
63 PyObject
*chgobj
= SWIG_NewPointerObj
(change
, SWIGTYPE_p_Change
, 0);
64 PyObject
*result
= PyObject_CallMethod
(handler
, "changes", "(O)", chgobj
);
67 /* there's no way to report an error to OpenSync
, so we just print it
*/
71 PyGILState_Release
(pystate
);
74 static void context_warning_wrapper
(void
*clientdata
, OSyncError
*err
) {
75 PyGILState_STATE pystate
= PyGILState_Ensure
();
77 PyObject
*handler
= clientdata
;
78 PyObject
*errobj
= SWIG_NewPointerObj
(err
, SWIGTYPE_p_Error
, 0);
79 PyObject
*result
= PyObject_CallMethod
(handler
, "warning", "(O)", errobj
);
82 /* there's no way to report an error to OpenSync
, so we just print it
*/
86 PyGILState_Release
(pystate
);
90 /* this should be passed an instance of a subclass of the ContextCallbacks class below
91 * FIXME
: we'll leak a reference to the handler object if this callback is replaced
*/
92 void set_callback_object
(PyObject
*handler
) {
95 osync_context_set_callback
(self
, context_callback_wrapper
, handler
);
96 osync_context_set_changes_callback
(self
, context_changes_wrapper
);
97 osync_context_set_warning_callback
(self
, context_warning_wrapper
);
102 class ContextCallbacks
:
103 """A purely-Python class that should be subclassed by code that wishes to handle context callbacks."""
104 def callback
(self
, err
):
105 """If err is set, this call indicates that an error was reported. Otherwise success."""
108 def changes
(self
, change
):
109 """Called to report a change object."""
112 def warning
(self
, err
):
113 """Called to report a non-fatal error."""