~renatofilho/buteo-syncfw/more-verbose

« back to all changes in this revision

Viewing changes to msyncd/synchronizer.h

  • Committer: Sergey Gerasimenko
  • Date: 2010-06-29 12:51:21 UTC
  • Revision ID: git-v1:cd8dab07b102ac96752ece4f3cde5fc62697d717
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of buteo-syncfw package
 
3
 *
 
4
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 
5
 *
 
6
 * Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
 
7
 *
 
8
 * This library is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public License
 
10
 * version 2.1 as published by the Free Software Foundation.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
15
 * Lesser General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
20
 * 02110-1301 USA
 
21
 *
 
22
 */
 
23
 
 
24
 
 
25
#ifndef SYNCHRONIZER_H
 
26
#define SYNCHRONIZER_H
 
27
 
 
28
#include "SyncDBusInterface.h"
 
29
#include "SyncQueue.h"
 
30
#include "StorageBooker.h"
 
31
#include "SyncScheduler.h"
 
32
 
 
33
#include "SyncCommonDefs.h"
 
34
#include "ProfileManager.h"
 
35
#include "PluginManager.h"
 
36
#include "PluginCbInterface.h"
 
37
#include "ClientPlugin.h"
 
38
 
 
39
#include <QVector>
 
40
#include <QMutex>
 
41
#include <QCoreApplication>
 
42
#include <QMap>
 
43
#include <QString>
 
44
 
 
45
 
 
46
class ContextProperty;
 
47
 
 
48
/*! \mainpage Harmattan Sync Framework
 
49
 *
 
50
* The Synchronization framework subsystem provides a generic framework for
 
51
* application developers wanting to develop Synchronization plug-ins for any
 
52
* synchronization service. It provides a plug-in API for the client, server and the storage
 
53
* plug-ins in the framework. It also provides services like profile management, sync
 
54
* controller functionality for sequencing simultaneous sync requests, a sync daemon and
 
55
* other common sync related functionality. This subsystem also provides an
 
56
* implementation of the OMA DS SyncML specification. The SyncML engine is provided as a
 
57
* public API for application developers. It also provides an implementation of the MTP 1.0
 
58
* specification, but this library interface is not open.
 
59
*
 
60
*/
 
61
 
 
62
namespace Buteo {
 
63
 
 
64
class PluginManager;
 
65
class ServerPluginRunner;
 
66
class TransportTracker;
 
67
class ServerActivator;
 
68
class AccountsHelper;
 
69
 
 
70
/// \brief The main entry point to the synchronization framework.
 
71
///
 
72
/// This class manages other components and connects them to provide
 
73
/// the fully functioning synchronization framework.
 
74
class Synchronizer : public SyncDBusInterface, // Derived from QObject
 
75
                     public PluginCbInterface
 
76
{
 
77
    Q_OBJECT
 
78
 
 
79
public:
 
80
 
 
81
    /// \brief The contructor.
 
82
    Synchronizer(QCoreApplication *aApplication);
 
83
 
 
84
    /// \brief Destructor
 
85
    virtual ~Synchronizer();
 
86
 
 
87
    bool initialize();
 
88
 
 
89
    void close();
 
90
 
 
91
 
 
92
// From PluginCbInterface
 
93
// ---------------------------------------------------------------------------
 
94
 
 
95
    virtual bool requestStorage(const QString &aStorageName,
 
96
                                const SyncPluginBase *aCaller);
 
97
 
 
98
    virtual void releaseStorage(const QString &aStorageName,
 
99
                                const SyncPluginBase *aCaller);
 
100
 
 
101
    virtual StoragePlugin* createStorage(const QString &aPluginName);
 
102
 
 
103
    virtual void destroyStorage(StoragePlugin *aStorage);
 
104
 
 
105
    virtual bool isConnectivityAvailable( Sync::ConnectivityType aType );
 
106
 
 
107
 
 
108
// From SyncDBusInterface
 
109
// --------------------------------------------------------------------------
 
110
 
 
111
public slots:
 
112
 
 
113
    //! \see SyncDBusInterface::startSync
 
114
    virtual bool startSync(QString aProfileName);
 
115
 
 
116
    //! \see SyncDBusInterface::abortSync
 
117
    virtual void abortSync(QString aProfileName);
 
118
 
 
119
    //! \see SyncDBusInterface::profileChanged
 
120
    virtual void profileChanged(QString aProfileName);
 
121
 
 
122
    //! \see SyncDBusInterface::profileDeleted
 
123
    virtual void profileDeleted(QString aProfileName);
 
124
    
 
125
    //! \see SyncDBusInterface::requestStorages
 
126
    virtual bool requestStorages(QStringList aStorageNames);
 
127
 
 
128
    //! \see SyncDBusInterface::releaseStorages
 
129
    virtual void releaseStorages(QStringList aStorageNames);
 
130
 
 
131
    //! \see SyncDBusInterface::runningSyncs
 
132
    virtual QStringList runningSyncs();
 
133
 
 
134
// --------------------------------------------------------------------------
 
135
 
 
136
    bool startScheduledSync(QString aProfileName);
 
137
 
 
138
signals:
 
139
 
 
140
    void storageReleased();
 
141
 
 
142
private slots:
 
143
 
 
144
    /*! \brief Handler for storage released signal.
 
145
     *
 
146
     * Tries to start the next sync in queue, which may have been blocked
 
147
     * earlier by storage reservations.
 
148
     */
 
149
    void onStorageReleased();
 
150
 
 
151
    void onTransferProgress( const QString &aProfileName,
 
152
        Sync::TransferDatabase aDatabase, Sync::TransferType aType,
 
153
        const QString &aMimeType );
 
154
 
 
155
    void onSessionFinished( const QString &aProfileName,
 
156
        Sync::SyncStatus aStatus, const QString &aMessage, int aErrorCode );
 
157
 
 
158
    void onStorageAccquired(const QString &aProfileName, const QString &aMimeType);
 
159
    
 
160
    void onServerDone();
 
161
 
 
162
    void onNewSession(const QString &aDestination);
 
163
 
 
164
    /*! \brief Starts a server plug-in
 
165
     *
 
166
     * @param aProfileName Server profile name
 
167
     */
 
168
    void startServer(const QString &aProfileName);
 
169
 
 
170
    /*! \brief Stops a server plug-in
 
171
     *
 
172
     * @param aProfileName Server profile name
 
173
     */
 
174
    void stopServer(const QString &aProfileName);
 
175
 
 
176
private:
 
177
 
 
178
    bool startSync(const QString &aProfileName, bool aScheduled);
 
179
 
 
180
    /*! \brief Starts a sync with the given profile.
 
181
     *
 
182
     * \param aProfile Profile to use in sync. Ownership is transferred.
 
183
     *  The profile is automatically deleted when the sync finishes.
 
184
     */
 
185
    bool startSyncNow(SyncSession *aSession);
 
186
 
 
187
    /*! \brief Tries to starts next sync request from the sync queue.
 
188
     *
 
189
     * \return Is it possible to try starting more syncs by calling this
 
190
     *  function again. Will be true if the first sync request in the queue
 
191
     *  is not blocked by already reserved storages.
 
192
     */
 
193
    bool startNextSync();
 
194
 
 
195
    void cleanupSession(SyncSession *aSession);
 
196
 
 
197
    /*! \brief Start all server plug-ins
 
198
     *
 
199
     */
 
200
    void startServers();
 
201
 
 
202
    /*! \brief Stop all server plug-ins
 
203
     *
 
204
     */
 
205
    void stopServers();
 
206
 
 
207
    /*! \brief Adds a profile to sync scheduler
 
208
     *
 
209
     * @param aProfileName Name of the profile to schedule.
 
210
     */
 
211
    void reschedule(const QString &aProfileName);
 
212
 
 
213
    bool isTransportAvailable(const SyncSession *aSession);
 
214
 
 
215
    QMap<QString, SyncSession*> iActiveSessions;
 
216
 
 
217
    QMap<QString, ServerPluginRunner*> iServers;
 
218
 
 
219
    PluginManager iPluginManager;
 
220
 
 
221
    ProfileManager iProfileManager;
 
222
 
 
223
    SyncQueue iSyncQueue;
 
224
 
 
225
    StorageBooker iStorageBooker;
 
226
 
 
227
    SyncScheduler *iSyncScheduler;
 
228
 
 
229
    TransportTracker *iTransportTracker;
 
230
 
 
231
    ServerActivator *iServerActivator;
 
232
 
 
233
    AccountsHelper *iAccounts;
 
234
 
 
235
    ContextProperty *iLowPower;
 
236
 
 
237
    bool iClosing;
 
238
 
 
239
    friend class SynchronizerTest;
 
240
};
 
241
 
 
242
}
 
243
 
 
244
#endif // SYNCHRONIZER_H