Warning: That file was not part of the compilation database. It may have many parsing errors.

1/*
2 Copyright (c) 2008 Volker Krause <vkrause@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "sinkbase.h"
21#include <KDebug>
22
23#define WRAP(X) \
24 osync_trace( TRACE_ENTRY, "%s(%p, %p, %p)", __PRETTY_FUNCTION__, userdata, info, ctx ); \
25 SinkBase *sink = reinterpret_cast<SinkBase*>( \
26 osync_objtype_sink_get_userdata( osync_plugin_info_get_sink( info ) ) ); \
27 sink->setContext( ctx ); \
28 sink->setPluginInfo( info ); \
29 sink->X; \
30 osync_trace( TRACE_EXIT, "%s", __PRETTY_FUNCTION__ );
31
32extern "C"
33{
34
35static void connect_wrapper( void *userdata, OSyncPluginInfo *info, OSyncContext *ctx )
36{
37 WRAP( connect() )
38}
39
40static void disconnect_wrapper(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx)
41{
42 WRAP( disconnect() )
43}
44
45static void get_changes_wrapper(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx)
46{
47 WRAP( getChanges() )
48}
49
50static void commit_wrapper(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg)
51{
52kDebug() << "commitwrap";
53 WRAP( commit( chg ) )
54}
55
56static void sync_done_wrapper(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx)
57{
58 WRAP( syncDone() )
59}
60
61} // extern C
62
63
64SinkBase::SinkBase( int features ) :
65 mContext( 0 ),
66 mSink( 0 ),
67 mPluginInfo( 0 )
68{
69 mWrapedFunctions.connect = ( features & Connect ) ? connect_wrapper : 0;
70 mWrapedFunctions.disconnect = ( features & Disconnect ) ? disconnect_wrapper : 0;
71 mWrapedFunctions.get_changes = ( features & GetChanges ) ? get_changes_wrapper : 0;
72 mWrapedFunctions.commit = ( features & Commit ) ? commit_wrapper : 0;
73 mWrapedFunctions.write = ( features & Write ) ? 0 : 0;
74 mWrapedFunctions.committed_all = ( features & CommittedAll ) ? 0 : 0;
75 mWrapedFunctions.read = ( features & Read ) ? 0 : 0;
76 mWrapedFunctions.batch_commit = ( features & BatchCommit ) ? 0 : 0;
77 mWrapedFunctions.sync_done = ( features & SyncDone ) ? sync_done_wrapper : 0;
78}
79
80SinkBase::~SinkBase()
81{
82 if ( mSink )
83 osync_objtype_sink_unref( mSink );
84}
85
86void SinkBase::connect()
87{
88 Q_ASSERT( false );
89}
90
91void SinkBase::disconnect()
92{
93 Q_ASSERT( false );
94}
95
96void SinkBase::getChanges()
97{
98 Q_ASSERT( false );
99}
100
101void SinkBase::commit(OSyncChange * chg)
102{
103 Q_UNUSED( chg );
104 Q_ASSERT( false );
105}
106
107void SinkBase::syncDone()
108{
109 Q_ASSERT( false );
110}
111
112void SinkBase::success() const
113{
114kDebug();
115 Q_ASSERT( mContext );
116 osync_context_report_success( mContext );
117 mContext = 0;
118}
119
120void SinkBase::error(OSyncErrorType type, const QString &msg) const
121{
122kDebug();
123 Q_ASSERT( mContext );
124 osync_context_report_error( mContext, type, msg.toUtf8() );
125 mContext = 0;
126}
127
128void SinkBase::warning(OSyncError * error) const
129{
130kDebug();
131 Q_ASSERT( mContext );
132 osync_context_report_osyncwarning( mContext, error );
133 osync_error_unref( &error );
134}
135
136void SinkBase::wrapSink(OSyncObjTypeSink * sink)
137{
138kDebug();
139 Q_ASSERT( sink );
140 Q_ASSERT( mSink == 0 );
141 mSink = sink;
142
143 osync_objtype_sink_set_functions( sink, mWrapedFunctions, this );
144}
145
146void SinkBase::setPluginInfo(OSyncPluginInfo * info)
147{
148 Q_ASSERT( mPluginInfo == 0 || mPluginInfo == info );
149 mPluginInfo = info;
150}
151
152void SinkBase::setContext(OSyncContext * context)
153{
154 Q_ASSERT( mContext == 0 || context == mContext );
155 // ### do I need to ref() that here? and then probably deref() the old one somewhere above?
156 mContext = context;
157}
158
159

Warning: That file was not part of the compilation database. It may have many parsing errors.