1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
/*
* This file is part of buteo-sync-plugins package
*
* Copyright (C) 2013 Jolla Ltd. and/or its subsidiary(-ies).
*
* Author: Sateesh Kavuri <sateesh.kavuri@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef SYNCMLSERVER_H
#define SYNCMLSERVER_H
#include "syncmlserver_global.h"
#include "USBConnection.h"
#include "BTConnection.h"
#include "SyncMLStorageProvider.h"
#include <buteosyncfw5/ServerPlugin.h>
#include <buteosyncfw5/SyncPluginLoader.h>
#include <buteosyncfw5/SyncCommonDefs.h>
#include <buteosyncfw5/SyncResults.h>
#include <buteosyncml5/StorageProvider.h>
#include <buteosyncml5/SyncAgent.h>
#include <buteosyncml5/Transport.h>
#include <buteosyncml5/SyncAgentConfig.h>
#include <buteosyncml5/OBEXTransport.h>
namespace Buteo {
class ServerPlugin;
class Profile;
}
namespace DataSync {
class SyncAgent;
class Transport;
}
class SYNCMLSERVERSHARED_EXPORT SyncMLServer : public Buteo::ServerPlugin
{
Q_OBJECT
public:
SyncMLServer (const QString& pluginName,
const Buteo::Profile profile,
Buteo::PluginCbInterface *cbInterface);
virtual ~SyncMLServer ();
virtual bool init ();
virtual bool uninit ();
virtual void abortSync (Sync::SyncStatus status = Sync::SYNC_ABORTED);
virtual bool cleanUp ();
virtual Buteo::SyncResults getSyncResults () const;
virtual bool startListen ();
virtual void stopListen ();
virtual void suspend ();
virtual void resume ();
signals:
void syncFinished (Sync::SyncStatus);
void sessionInProgress (Sync::ConnectivityType);
public slots:
virtual void connectivityStateChanged (Sync::ConnectivityType type, bool state);
protected slots:
void handleUSBConnected (int fd);
void handleBTConnected (int fd, QString btAddr);
void handleSyncFinished (DataSync::SyncState state);
void handleStateChanged (DataSync::SyncState state);
void handleStorageAccquired (QString storageType);
void handleItemProcessed (DataSync::ModificationType modificationType,
DataSync::ModifiedDatabase modifiedDb,
QString localDb,
QString dbType, int committedItems);
private:
bool initSyncAgent ();
void closeSyncAgent ();
void closeUSBTransport ();
void closeBTTransport ();
DataSync::SyncAgentConfig *initSyncAgentConfig ();
void closeSyncAgentConfig ();
bool initStorageProvider ();
bool createUSBTransport ();
bool createBTTransport ();
bool startNewSession (QString address);
void generateResults (bool success);
QMap<QString, QString> mProperties;
DataSync::SyncAgent* mAgent;
DataSync::SyncAgentConfig* mConfig;
USBConnection mUSBConnection;
BTConnection mBTConnection;
DataSync::Transport* mTransport;
Buteo::SyncResults mResults;
SyncMLStorageProvider mStorageProvider;
qint32 mCommittedItems;
/**
* ! \brief The connectivity type used for the current sync session
*/
Sync::ConnectivityType mConnectionType;
/**
* ! \brief Flag to indicate if the sync session is in progress
*/
bool mIsSessionInProgress;
/**
* ! \brief Flag to indicate if bluetooth is active
*/
bool mBTActive;
/**
* ! \brief Flag to indicate if USB is active
*/
bool mUSBActive;
};
class SyncMLServerLoader : public Buteo::SyncPluginLoader
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "com.buteo.plugins.sync.SyncMLServerLoader")
Q_INTERFACES(Buteo::SyncPluginLoader)
public:
/*! \brief Creates SyncML server plugin
*
* @param aPluginName Name of this server plugin
* @param aProfile Profile to use
* @param aCbInterface Pointer to the callback interface
* @return Server plugin on success, otherwise NULL
*/
Buteo::ServerPlugin* createServerPlugin(const QString& pluginName,
const Buteo::Profile& profile,
Buteo::PluginCbInterface* cbInterface) override;
};
#endif // SYNCMLSERVER_H
|