Changeset 1232
- Timestamp:
- 08/25/06 13:57:03 (2 years ago)
- Location:
- plugins/python-module/src
- Files:
-
- 2 modified
-
python_module.c (modified) (16 diffs)
-
sample.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
plugins/python-module/src/python_module.c
r1150 r1232 30 30 typedef struct MemberData { 31 31 PyThreadState *interp_thread; 32 PyObject *osync_module; 32 33 PyObject *module; 33 34 PyObject *object; … … 68 69 } 69 70 70 static PyObject *pm_make_change(PyObject * module, OSyncChange *change, OSyncError **error)71 static PyObject *pm_make_change(PyObject *osync_module, OSyncChange *change, OSyncError **error) 71 72 { 72 73 PyObject *pychg_cobject = PyCObject_FromVoidPtr(change, NULL); … … 77 78 } 78 79 79 PyObject *pychg = PyObject_CallMethod( module, "OSyncChange", "O", pychg_cobject);80 PyObject *pychg = PyObject_CallMethod(osync_module, "OSyncChange", "O", pychg_cobject); 80 81 if (!pychg) { 81 82 osync_error_set(error, OSYNC_ERROR_GENERIC, "Cannot create Python OSyncChange"); … … 87 88 } 88 89 89 static PyObject *pm_make_context(PyObject * module, OSyncContext *ctx, OSyncError **error)90 static PyObject *pm_make_context(PyObject *osync_module, OSyncContext *ctx, OSyncError **error) 90 91 { 91 92 PyObject *pyctx_cobject = PyCObject_FromVoidPtr(ctx, NULL); … … 96 97 } 97 98 98 PyObject *pyctx = PyObject_CallMethod( module, "OSyncContext", "O", pyctx_cobject);99 PyObject *pyctx = PyObject_CallMethod(osync_module, "OSyncContext", "O", pyctx_cobject); 99 100 if (!pyctx) { 100 101 osync_error_set(error, OSYNC_ERROR_GENERIC, "Cannot create Python OSyncContext"); … … 106 107 } 107 108 108 static PyObject *pm_make_member(PyObject * module, OSyncMember *member, OSyncError **error)109 static PyObject *pm_make_member(PyObject *osync_module, OSyncMember *member, OSyncError **error) 109 110 { 110 111 PyObject *pymember_cobject = PyCObject_FromVoidPtr(member, NULL); … … 115 116 } 116 117 117 PyObject *pymember = PyObject_CallMethod( module, "OSyncMember", "O", pymember_cobject);118 PyObject *pymember = PyObject_CallMethod(osync_module, "OSyncMember", "O", pymember_cobject); 118 119 if (!pymember) { 119 120 osync_error_set(error, OSYNC_ERROR_GENERIC, "Cannot create Python OSyncMember"); … … 146 147 } 147 148 148 if (! pm_load_opensync(error))149 if (!(data->osync_module = pm_load_opensync(error))) 149 150 goto error_free_interp; 150 151 … … 152 153 goto error_free_interp; 153 154 154 PyObject *pymember = pm_make_member(data-> module, member, error);155 PyObject *pymember = pm_make_member(data->osync_module, member, error); 155 156 if (!pymember) 156 157 goto error_unload_module; … … 214 215 PyEval_AcquireThread(data->interp_thread); 215 216 216 pycontext = pm_make_context(data-> module, ctx, error);217 pycontext = pm_make_context(data->osync_module, ctx, error); 217 218 if (!pycontext) { 218 219 PyEval_ReleaseThread(data->interp_thread); … … 223 224 224 225 if (chg) { 225 PyObject *pychange = pm_make_change(data-> module, chg, error);226 PyObject *pychange = pm_make_change(data->osync_module, chg, error); 226 227 if (!pychange) { 227 228 PyEval_ReleaseThread(data->interp_thread); … … 312 313 * accepted objtypes/formats info) 313 314 */ 314 static osync_bool register_plugin(OSyncEnv *env, const char *filename, OSyncError **error) 315 static osync_bool register_plugin(OSyncEnv *env, PyObject *osync_module, 316 const char *filename, OSyncError **error) 315 317 { 316 318 osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, env, filename, error); … … 341 343 } 342 344 343 PyObject *pyinfo = PyObject_CallMethod( module, "OSyncPluginInfo", "O", pyinfo_cobject);345 PyObject *pyinfo = PyObject_CallMethod(osync_module, "OSyncPluginInfo", "O", pyinfo_cobject); 344 346 if (!pyinfo) { 345 347 osync_error_set(error, OSYNC_ERROR_GENERIC, "Cannot create Python OSyncPluginInfo"); … … 369 371 } 370 372 371 static osync_bool scan_for_plugins(OSyncEnv *env )373 static osync_bool scan_for_plugins(OSyncEnv *env, PyObject *osync_module) 372 374 { 373 375 osync_trace(TRACE_ENTRY, "%s(%p)", __func__, env); … … 385 387 char *filename = g_build_filename(path, de, NULL); 386 388 OSyncError *error = NULL; 387 if (!register_plugin(env, filename, &error))389 if (!register_plugin(env, osync_module, filename, &error)) 388 390 osync_debug("python", 1, "Couldn't register plugin \"%s\": %s", filename, osync_error_print(&error)); 389 391 … … 408 410 409 411 OSyncError *error = NULL; 410 if (!pm_load_opensync(&error)) 412 PyObject *osync_module = pm_load_opensync(&error); 413 if (!osync_module) 411 414 return; 412 415 413 scan_for_plugins(env );414 } 416 scan_for_plugins(env, osync_module); 417 } -
plugins/python-module/src/sample.py
r532 r1232 1 from opensync import * 1 import opensync 2 2 3 3 class SyncClass: … … 13 13 if self.__member.get_slow_sync("data"): 14 14 print "Slow-sync requested" 15 change = OSyncChange()15 change = opensync.OSyncChange() 16 16 change.uid = "testuid" 17 change. set_data("testdata", 9, TRUE)17 change.data = "testdata" 18 18 change.format = "plain" 19 19 change.objtype = "data" 20 change.changetype = CHANGE_ADDED20 change.changetype = opensync.CHANGE_ADDED 21 21 change.report(ctx) 22 22 ctx.report_success() … … 25 25 def commit_change(self, ctx, chg): 26 26 print "commit called!!" 27 print "Opensync wants me to write data with size " + str(chg.datasize)27 print "Opensync wants me to write data with size " + len(chg.data) 28 28 ctx.report_success() 29 29
