Added OSYNC_TEST_EXPORT to export symbols in test mode - required for windows port
[opensync.git] / opensync / engine / opensync_sink_engine.c
blob35901863704e93de7a3cbe8f041b2f311ea776dd
1 /*
2 * libosengine - A synchronization engine for the opensync framework
3 * Copyright (C) 2004-2005 Armin Bauer <armin.bauer@opensync.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "opensync.h"
22 #include "opensync_internals.h"
24 #include "opensync-archive.h"
25 #include "opensync-group.h"
26 #include "opensync-engine.h"
27 #include "opensync-data.h"
28 #include "opensync-mapping.h"
30 #include "opensync_obj_engine.h"
31 #include "opensync_obj_engine_internals.h"
32 #include "opensync_sink_engine_internals.h"
34 #include "opensync_mapping_entry_engine_internals.h"
36 OSyncSinkEngine *osync_sink_engine_new(int position, OSyncClientProxy *proxy, OSyncObjEngine *objengine, OSyncError **error)
38 OSyncSinkEngine *sinkengine = NULL;
39 osync_trace(TRACE_ENTRY, "%s(%i, %p, %p, %p)", __func__, position, proxy, objengine, error);
40 osync_assert(proxy);
41 osync_assert(objengine);
43 sinkengine = osync_try_malloc0(sizeof(OSyncSinkEngine), error);
44 if (!sinkengine)
45 goto error;
46 sinkengine->ref_count = 1;
47 sinkengine->position = position;
49 /* we dont reference the proxy to avoid circular dependencies. This object is completely
50 * dependent on the proxy anyways */
51 sinkengine->proxy = proxy;
53 sinkengine->engine = objengine;
55 osync_trace(TRACE_EXIT, "%s: %p", __func__, sinkengine);
56 return sinkengine;
58 error:
59 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
60 return NULL;
63 OSyncSinkEngine *osync_sink_engine_ref(OSyncSinkEngine *engine)
65 osync_assert(engine);
67 g_atomic_int_inc(&(engine->ref_count));
69 return engine;
72 void osync_sink_engine_unref(OSyncSinkEngine *engine)
74 osync_assert(engine);
76 if (g_atomic_int_dec_and_test(&(engine->ref_count))) {
77 while (engine->unmapped) {
78 OSyncChange *change = engine->unmapped->data;
79 osync_change_unref(change);
81 engine->unmapped = g_list_remove(engine->unmapped, engine->unmapped->data);
84 while (engine->entries) {
85 OSyncMappingEntryEngine *entry = engine->entries->data;
86 osync_entry_engine_unref(entry);
88 engine->entries = g_list_remove(engine->entries, engine->entries->data);
91 g_free(engine);
95 osync_bool osync_sink_engine_is_connected(OSyncSinkEngine *engine)
97 OSyncObjEngine *objengine = NULL;
98 osync_assert(engine);
100 objengine = engine->engine;
102 if (!objengine)
103 return FALSE;
105 return !!(objengine->sink_connects & (1 << engine->position));