21 #include "../syncml.h" 22 #include "../syncml_internals.h" 23 #include "data_sync_devinf.h" 24 #include "libsyncml/sml_error_internals.h" 26 static gboolean _prepare(GSource *source, gint *timeout_)
28 smlTrace(TRACE_INTERNAL,
"%s(%p, %p)", __func__, source, timeout_);
33 static gboolean _check(GSource *source)
37 GList *o = dsObject->datastores;
38 for (; o; o = o->next)
41 if (datastore->session && smlDsSessionCheck(datastore->session))
45 return smlManagerCheck(dsObject->manager);
48 static gboolean _dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
50 smlTrace(TRACE_INTERNAL,
"%s(%p, %p, %p)", __func__, source, callback, user_data);
53 GList *o = dsObject->datastores;
54 for (; o; o = o->next)
57 if (datastore->session)
58 smlDsSessionDispatch(datastore->session);
61 smlManagerDispatch(dsObject->manager);
67 smlTrace(TRACE_ENTRY,
"%s", __func__);
72 dsObject->functions =
smlTryMalloc0(
sizeof(GSourceFuncs), error);
73 if (!dsObject->functions)
76 dsObject->functions->prepare = _prepare;
77 dsObject->functions->check = _check;
78 dsObject->functions->dispatch = _dispatch;
79 dsObject->functions->finalize = NULL;
83 dsObject->context = g_main_context_new();
84 if (!dsObject->context)
86 dsObject->thread = smlThreadNew(dsObject->context, error);
87 if (!dsObject->thread)
89 smlThreadStart(dsObject->thread);
93 dsObject->source = g_source_new(dsObject->functions,
sizeof(GSource) +
sizeof(
SmlDataSyncObject *));
96 g_source_set_callback(dsObject->source, NULL, dsObject, NULL);
97 g_source_attach(dsObject->source, dsObject->context);
98 g_main_context_ref(dsObject->context);
100 smlTrace(TRACE_EXIT,
"%s - TRUE", __func__);
109 smlTrace(TRACE_ENTRY,
"%s", __func__);
112 smlThreadStop(dsObject->thread);
113 smlThreadFree(dsObject->thread);
114 dsObject->thread = NULL;
117 g_source_unref(dsObject->source);
118 dsObject->source = NULL;
121 g_main_context_unref(dsObject->context);
122 dsObject->context = NULL;
125 smlSafeFree((gpointer *)&(dsObject->functions));
126 dsObject->functions = NULL;
128 smlTrace(TRACE_EXIT,
"%s - TRUE", __func__);
This object represents an OMA DS datastore.
const char * smlErrorPrint(SmlError **error)
Returns the message of the error.
This is the central synchronization object.
void smlTrace(SmlTraceType type, const char *message,...)
Used for tracing the application.
void * smlTryMalloc0(long n_bytes, SmlError **error)
Safely mallocs.