QtDataSync
4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
|
An extension of QtService to create a synchronization service for android. More...
#include <androidbackgroundservice.h>
Public Slots | |
void | setWaitFullSync (bool waitFullSync) |
WRITE accessor for AndroidBackgroundService::waitFullSync. | |
Public Slots inherited from QtService::Service | |
void | quit () |
void | reload () |
void | setTerminalActive (bool terminalActive) |
void | setTerminalMode (TerminalMode terminalMode) |
void | setGlobalTerminal (bool globalTerminal) |
void | setStartWithTerminal (bool startWithTerminal) |
Signals | |
void | waitFullSyncChanged (bool waitFullSync, QPrivateSignal) |
NOTIFY accessor for AndroidBackgroundService::waitFullSync. | |
Signals inherited from QtService::Service | |
void | started (bool success) |
Q_DECL_DEPRECATED void | started () |
void | stopped (int exitCode=EXIT_SUCCESS) |
void | reloaded (bool success) |
Q_DECL_DEPRECATED void | reloaded () |
void | paused (bool success) |
Q_DECL_DEPRECATED void | paused () |
void | resumed (bool success) |
Q_DECL_DEPRECATED void | resumed () |
void | terminalActiveChanged (bool terminalActive, QPrivateSignal) |
void | terminalModeChanged (TerminalMode terminalMode, QPrivateSignal) |
void | globalTerminalChanged (bool globalTerminal, QPrivateSignal) |
void | startWithTerminalChanged (bool startWithTerminal, QPrivateSignal) |
Public Member Functions | |
AndroidBackgroundService (int &argc, char **argv, int=QCoreApplication::ApplicationFlags) | |
Default constructor. | |
bool | waitFullSync () const |
READ accessor for AndroidBackgroundService::waitFullSync. | |
Public Member Functions inherited from QtService::Service | |
Service (int &argc, char **argv, int=QCoreApplication::ApplicationFlags) | |
int | exec () |
Q_INVOKABLE QList< int > | getSockets (const QByteArray &socketName) |
Q_INVOKABLE int | getSocket () |
QString | backend () const |
QDir | runtimeDir () const |
bool | isTerminalActive () const |
TerminalMode | terminalMode () const |
bool | isGlobalTerminal () const |
bool | startWithTerminal () const |
Public Member Functions inherited from QObject | |
virtual const QMetaObject * | metaObject () const const |
virtual void * | qt_metacast (const char *) |
virtual int | qt_metacall (QMetaObject::Call, int, void **) |
QObject (QObject *parent) | |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
QString | objectName () const const |
void | setObjectName (const QString &name) |
bool | isWidgetType () const const |
bool | isWindowType () const const |
bool | signalsBlocked () const const |
bool | blockSignals (bool block) |
QThread * | thread () const const |
void | moveToThread (QThread *targetThread) |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType) |
void | killTimer (int id) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegExp ®Exp, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
const QObjectList & | children () const const |
void | setParent (QObject *parent) |
void | installEventFilter (QObject *filterObj) |
void | removeEventFilter (QObject *obj) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
bool | disconnect (const QObject *receiver, const char *method) const const |
void | dumpObjectTree () |
void | dumpObjectInfo () |
void | dumpObjectTree () const const |
void | dumpObjectInfo () const const |
bool | setProperty (const char *name, const QVariant &value) |
QVariant | property (const char *name) const const |
QList< QByteArray > | dynamicPropertyNames () const const |
void | destroyed (QObject *obj) |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
bool | inherits (const char *className) const const |
void | deleteLater () |
Static Public Attributes | |
static const QString | BackgroundSyncAction |
The Intent Action used to start the background synchronization. | |
static const QString | RegisterSyncAction |
The Intent Action used to register the service for background synchronization. | |
static const int | ForegroundNotificationId |
The ID of the Foreground notification shown by the service while synchronizing. | |
Protected Member Functions | |
virtual QString | setupName () const |
Returns the name of the setup to be synchronized. More... | |
virtual void | prepareSetup (Setup &setup) |
Prepares the setup to be synchronized. More... | |
CommandResult | onStart () override |
Inherits QtService::Service::onStart. | |
CommandResult | onStop (int &exitCode) override |
Inherits QtService::Service::onStop. | |
virtual void | onSyncCompleted (SyncManager::SyncState state) |
Is called by the service as soon the the synchronization has been completed. More... | |
void | exitAfterSync () |
Tells the service to quit itself after a synchronization. More... | |
virtual int | onStartCommand (const QAndroidIntent &intent, int flags, int startId) |
Is called on the android thread to deliver the start command. More... | |
virtual QAndroidJniObject | createForegroundNotification ()=0 |
Is called on the android thread to create a foreground notification. More... | |
virtual bool | stopSelf (int startId) |
Is called by the service to stop itself once finished, based on the id it was started with. More... | |
Protected Member Functions inherited from QtService::Service | |
virtual bool | preStart () |
virtual CommandResult | onReload () |
virtual CommandResult | onPause () |
virtual CommandResult | onResume () |
virtual QVariant | onCallback (const QByteArray &kind, const QVariantList &args) |
virtual bool | verifyCommand (const QStringList &arguments) |
void | addCallback (const QByteArray &kind, const std::function< QVariant(QVariantList)> &fn) |
void | addCallback (const QByteArray &kind, const TFunction &fn) |
void | addCallback (const QByteArray &kind, TReturn(TClass::*fn)(TArgs...), std::enable_if_t< std::is_base_of< QtService::Service, TClass >::value, void * >=nullptr) |
Protected Member Functions inherited from QObject | |
QObject * | sender () const const |
int | senderSignalIndex () const const |
int | receivers (const char *signal) const const |
bool | isSignalConnected (const QMetaMethod &signal) const const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
Properties | |
bool | waitFullSync |
Specify whether the service should wait for a full synchronization or only the download. More... | |
Properties inherited from QtService::Service | |
QString | backend |
QDir | runtimeDir |
bool | terminalActive |
TerminalMode | terminalMode |
bool | globalTerminal |
bool | startWithTerminal |
Properties inherited from QObject | |
objectName | |
Additional Inherited Members | |
Public Types inherited from QtService::Service | |
enum | CommandResult |
enum | TerminalMode |
Static Public Member Functions inherited from QtService::Service | |
static Service * | instance () |
Static Public Member Functions inherited from QObject | |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
Public Attributes inherited from QtService::Service | |
OperationCompleted | |
OperationPending | |
OperationFailed | |
OperationExit | |
QT_SERVICE_POST_ENUM_DEPRECATED | |
ReadOnly | |
WriteOnly | |
ReadWritePassive | |
ReadWriteActive | |
Protected Slots inherited from QtService::Service | |
virtual void | terminalConnected (Terminal *terminal) |
An extension of QtService to create a synchronization service for android.
This service is part of the QtDataSyncAndroid
module and can be used as Android service to create a background synchronizations service without much effort. However, a few additional setup steps are needed. This class only extends the QtService implementation of an android service to add the synchronization aspect.
Definition at line 19 of file androidbackgroundservice.h.
|
protectedpure virtual |
Is called on the android thread to create a foreground notification.
You must implement this method to create a working service, as since Android 8, all services that want to run must show a foreground notification while running in order to not be killed by the system. A basic sample could be the following.
The code to create the notification was first written in java:
And that method is then simply called from the implementation:
|
protected |
Tells the service to quit itself after a synchronization.
Call this method if you reimplement onSyncCompleted(). It will quit the service gracefully, honoring the order of start commands, if multiple have been used. Internally, this method calls stopSelf() with the most recently used startId of a BackgroundSyncAction.
|
protectedvirtual |
Is called on the android thread to deliver the start command.
intent | The intent that was used to start the service |
flags | The flags that were used to start the service |
startId | The id of this start request |
This method is registered within QtService via QtService::Service::addCallback. Check Android Backend documentation for details on the method itself. Its bascially just a forwarding of the Android Service method.
Only implement this if you need to do custom stuff here. You should always call this base implementation in your overload, as this method internally handles the synchronization intents.
|
protectedvirtual |
Is called by the service as soon the the synchronization has been completed.
state | The state in which the synchronization finished |
This method is called as soon as the datasync instance has finished the data synchronization. You can override it to perform additional operations with the data before quitting the service.
The default implementation only calls exitAfterSync() to quit the service gracefully. You must do the same in your implementation. You do not have to call it from within the method, but must call it eventually. Otherwise it will keep running indefinitely
Possible states can be:
|
protectedvirtual |
Prepares the setup to be synchronized.
setup | The setup to be prepared |
You should override this method to configure the setup before creation (i.e. set properties on it). The default implementation does nothing.
|
protectedvirtual |
Returns the name of the setup to be synchronized.
The default implementation returns QtDataSync::DefaultSetup
. You can override the method if you need the service to create the setup under a different name.
|
protectedvirtual |
Is called by the service to stop itself once finished, based on the id it was started with.
startId | The id of the start command that was finished and thus is beeing stopped |
Internally this method simply calls stopSelfResult on the android service. You can reimplement it if you want to customize how to quit the service.
|
readwrite |
Specify whether the service should wait for a full synchronization or only the download.
Default: true
If set to true, the serivce will internally call SyncManager::runOnSynchronized() with the onSyncCompleted() as handler. If disable, SyncManager::runOnDownloaded() is used instead. Check the documentation of these two methods.
Accessors | |
---|---|
READ | waitFullSync() |
WRITE | setWaitFullSync() |
NOTIFY | waitFullSyncChanged() |
Definition at line 24 of file androidbackgroundservice.h.