[gnote] Split SyncManager to interface and implementation
- From: Aurimas Äernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Split SyncManager to interface and implementation
- Date: Sat, 19 Jan 2013 16:48:24 +0000 (UTC)
commit f45d60163a409fd705a95562f8008c072b79be43
Author: Aurimas Äernius <aurisc4 gmail com>
Date: Sat Jan 19 17:08:04 2013 +0200
Split SyncManager to interface and implementation
Move all interfaces to isyncmanager.hpp and cpp files.
src/Makefile.am | 1 +
.../webdavsyncservice/webdavsyncserviceaddin.cpp | 4 +-
src/preferencesdialog.cpp | 4 +-
src/synchronization/filesystemsyncserver.hpp | 4 +-
src/synchronization/gnotesyncclient.hpp | 2 +-
src/synchronization/isyncmanager.cpp | 65 ++++++++++++
src/synchronization/isyncmanager.hpp | 111 ++++++++++++++++++++
src/synchronization/silentui.cpp | 4 +-
src/synchronization/syncdialog.cpp | 12 +-
src/synchronization/syncmanager.cpp | 45 ++------
src/synchronization/syncmanager.hpp | 83 ++-------------
src/synchronization/syncserviceaddin.hpp | 4 +-
12 files changed, 217 insertions(+), 122 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 1ea3309..9ac9351 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -150,6 +150,7 @@ libgnote_la_SOURCES = \
synchronization/silentui.hpp synchronization/silentui.cpp \
synchronization/syncdialog.hpp synchronization/syncdialog.cpp \
synchronization/syncmanager.hpp synchronization/syncmanager.cpp \
+ synchronization/isyncmanager.hpp synchronization/isyncmanager.cpp \
synchronization/syncui.hpp synchronization/syncui.cpp \
synchronization/syncutils.hpp synchronization/syncutils.cpp \
synchronization/syncserviceaddin.hpp synchronization/syncserviceaddin.cpp \
diff --git a/src/addins/webdavsyncservice/webdavsyncserviceaddin.cpp b/src/addins/webdavsyncservice/webdavsyncserviceaddin.cpp
index 0b3447d..2694f64 100644
--- a/src/addins/webdavsyncservice/webdavsyncserviceaddin.cpp
+++ b/src/addins/webdavsyncservice/webdavsyncserviceaddin.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 Aurimas Cernius
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@
#include "gnome_keyring/keyringexception.hpp"
#include "gnome_keyring/ring.hpp"
#include "sharp/string.hpp"
-#include "synchronization/syncmanager.hpp"
+#include "synchronization/isyncmanager.hpp"
using gnome::keyring::KeyringException;
diff --git a/src/preferencesdialog.cpp b/src/preferencesdialog.cpp
index a0f7893..bdd5f65 100644
--- a/src/preferencesdialog.cpp
+++ b/src/preferencesdialog.cpp
@@ -1244,7 +1244,7 @@ DBG_OUT("no addin");
// Reset conflict handling behavior
settings->set_int(Preferences::SYNC_CONFIGURED_CONFLICT_BEHAVIOR, DEFAULT_SYNC_CONFIGURED_CONFLICT_BEHAVIOR);
- sync::SyncManager::obj().reset_client();
+ sync::ISyncManager::obj().reset_client();
m_sync_addin_combo->set_sensitive(true);
m_sync_addin_combo->unset_active();
@@ -1284,7 +1284,7 @@ DBG_OUT("no addin");
m_reset_sync_addin_button->set_sensitive(true);
m_save_sync_addin_button->set_sensitive(false);
- sync::SyncManager::obj().reset_client();
+ sync::ISyncManager::obj().reset_client();
// Give the user a visual letting them know that connecting
// was successful.
diff --git a/src/synchronization/filesystemsyncserver.hpp b/src/synchronization/filesystemsyncserver.hpp
index 7949c2a..636f31b 100644
--- a/src/synchronization/filesystemsyncserver.hpp
+++ b/src/synchronization/filesystemsyncserver.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 Aurimas Cernius
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
#ifndef _SYNCHRONIZATION_FILESYSTEMSYNCSERVER_HPP_
#define _SYNCHRONIZATION_FILESYSTEMSYNCSERVER_HPP_
-#include "syncmanager.hpp"
+#include "isyncmanager.hpp"
#include "utils.hpp"
#include "sharp/datetime.hpp"
diff --git a/src/synchronization/gnotesyncclient.hpp b/src/synchronization/gnotesyncclient.hpp
index 5a9c6ba..8c1a4dd 100644
--- a/src/synchronization/gnotesyncclient.hpp
+++ b/src/synchronization/gnotesyncclient.hpp
@@ -20,7 +20,7 @@
#include <giomm/file.h>
-#include "syncmanager.hpp"
+#include "isyncmanager.hpp"
diff --git a/src/synchronization/isyncmanager.cpp b/src/synchronization/isyncmanager.cpp
new file mode 100644
index 0000000..059b042
--- /dev/null
+++ b/src/synchronization/isyncmanager.cpp
@@ -0,0 +1,65 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2012-2013 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <boost/format.hpp>
+
+#include "isyncmanager.hpp"
+#include "preferences.hpp"
+#include "sharp/uuid.hpp"
+
+
+namespace gnote {
+namespace sync {
+
+
+SyncLockInfo::SyncLockInfo()
+ : client_id(Preferences::obj().get_schema_settings(Preferences::SCHEMA_SYNC)->get_string(Preferences::SYNC_CLIENT_ID))
+ , transaction_id(sharp::uuid().string())
+ , renew_count(0)
+ , duration(0, 2, 0) // default of 2 minutes
+ , revision(0)
+{
+}
+
+std::string SyncLockInfo::hash_string()
+{
+ return str(boost::format("%1%-%2%-%3%-%4%-%5%") % transaction_id % client_id % renew_count % duration.string() % revision);
+}
+
+
+
+SyncClient::~SyncClient()
+{
+}
+
+
+ISyncManager::~ISyncManager()
+{
+}
+
+
+
+SyncServer::~SyncServer()
+{}
+
+
+}
+}
+
diff --git a/src/synchronization/isyncmanager.hpp b/src/synchronization/isyncmanager.hpp
new file mode 100644
index 0000000..a2a004d
--- /dev/null
+++ b/src/synchronization/isyncmanager.hpp
@@ -0,0 +1,111 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2012-2013 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _SYNCHRONIZATION_ISYNCMANAGER_HPP_
+#define _SYNCHRONIZATION_ISYNCMANAGER_HPP_
+
+#include <list>
+#include <string>
+#include <tr1/memory>
+
+#include "note.hpp"
+#include "syncui.hpp"
+#include "syncutils.hpp"
+
+namespace gnote {
+namespace sync {
+
+class SyncLockInfo
+{
+public:
+ std::string client_id;
+ std::string transaction_id;
+ int renew_count;
+ sharp::TimeSpan duration;
+ int revision;
+
+ SyncLockInfo();
+ std::string hash_string();
+};
+
+class SyncClient
+{
+public:
+ typedef std::tr1::shared_ptr<SyncClient> Ptr;
+
+ virtual ~SyncClient();
+
+ virtual int last_synchronized_revision() = 0;
+ virtual void last_synchronized_revision(int) = 0;
+ virtual sharp::DateTime last_sync_date() = 0;
+ virtual void last_sync_date(const sharp::DateTime &) = 0;
+ virtual int get_revision(const Note::Ptr & note) = 0;
+ virtual void set_revision(const Note::Ptr & note, int revision) = 0;
+ virtual std::map<std::string, std::string> deleted_note_titles() = 0;
+ virtual void reset() = 0;
+ virtual std::string associated_server_id() = 0;
+ virtual void associated_server_id(const std::string &) = 0;
+};
+
+class ISyncManager
+ : public base::Singleton<ISyncManager>
+{
+public:
+ virtual ~ISyncManager();
+
+ virtual void reset_client() = 0;
+ virtual void perform_synchronization(const std::tr1::shared_ptr<SyncUI> & sync_ui) = 0;
+ virtual void resolve_conflict(SyncTitleConflictResolution resolution) = 0;
+ virtual bool synchronized_note_xml_matches(const std::string & noteXml1, const std::string & noteXml2) = 0;
+ virtual SyncState state() const = 0;
+};
+
+class SyncServer
+{
+public:
+ typedef std::tr1::shared_ptr<SyncServer> Ptr;
+
+ virtual ~SyncServer();
+
+ virtual bool begin_sync_transaction() = 0;
+ virtual bool commit_sync_transaction() = 0;
+ virtual bool cancel_sync_transaction() = 0;
+ virtual std::list<std::string> get_all_note_uuids() = 0;
+ virtual std::map<std::string, NoteUpdate> get_note_updates_since(int revision) = 0;
+ virtual void delete_notes(const std::list<std::string> & deletedNoteUUIDs) = 0;
+ virtual void upload_notes(const std::list<Note::Ptr> & notes) = 0;
+ virtual int latest_revision() = 0; // NOTE: Only reliable during a transaction
+ virtual SyncLockInfo current_sync_lock() = 0;
+ virtual std::string id() = 0;
+ virtual bool updates_available_since(int revision) = 0;
+};
+
+class GnoteSyncException
+ : public std::runtime_error
+{
+public:
+ GnoteSyncException(const char * what_arg) : std::runtime_error(what_arg){}
+};
+
+}
+}
+
+#endif
+
diff --git a/src/synchronization/silentui.cpp b/src/synchronization/silentui.cpp
index 19a1565..acc1d2e 100644
--- a/src/synchronization/silentui.cpp
+++ b/src/synchronization/silentui.cpp
@@ -19,7 +19,7 @@
#include "debug.hpp"
-#include "syncmanager.hpp"
+#include "isyncmanager.hpp"
#include "silentui.hpp"
@@ -84,7 +84,7 @@ namespace sync {
if(localConflictNote->id() != remoteNote.m_uuid) {
manager.delete_note(localConflictNote);
}
- SyncManager::obj().resolve_conflict(OVERWRITE_EXISTING);
+ ISyncManager::obj().resolve_conflict(OVERWRITE_EXISTING);
}
diff --git a/src/synchronization/syncdialog.cpp b/src/synchronization/syncdialog.cpp
index 70578df..3685821 100644
--- a/src/synchronization/syncdialog.cpp
+++ b/src/synchronization/syncdialog.cpp
@@ -33,7 +33,7 @@
#include "notewindow.hpp"
#include "preferences.hpp"
#include "syncdialog.hpp"
-#include "syncmanager.hpp"
+#include "isyncmanager.hpp"
namespace gnote {
@@ -413,7 +413,7 @@ void SyncDialog::on_realize()
{
Gtk::Dialog::on_realize();
- SyncState state = SyncManager::obj().state();
+ SyncState state = ISyncManager::obj().state();
if(state == IDLE) {
// Kick off a timer to keep the progress bar going
//m_progress_barTimeoutId = GLib.Timeout.Add (500, OnPulseProgressBar);
@@ -422,7 +422,7 @@ void SyncDialog::on_realize()
timeout->attach();
// Kick off a new synchronization
- SyncManager::obj().perform_synchronization(this->shared_from_this());
+ ISyncManager::obj().perform_synchronization(this->shared_from_this());
}
else {
// Adjust the GUI accordingly
@@ -433,7 +433,7 @@ void SyncDialog::on_realize()
bool SyncDialog::on_pulse_progress_bar()
{
- if(SyncManager::obj().state() == IDLE) {
+ if(ISyncManager::obj().state() == IDLE) {
return false;
}
@@ -690,7 +690,7 @@ void SyncDialog::on_note_conflict_detected(GObject*, gpointer data, gpointer thi
SyncTitleConflictDialog conflictDlg(args->localConflictNote, args->noteUpdateTitles);
Gtk::ResponseType reponse = Gtk::RESPONSE_OK;
- bool noteSyncBitsMatch = SyncManager::obj().synchronized_note_xml_matches(
+ bool noteSyncBitsMatch = ISyncManager::obj().synchronized_note_xml_matches(
args->localConflictNote->get_complete_note_xml(), args->remoteNote->m_xml_content);
// If the synchronized note content is in conflict
@@ -747,7 +747,7 @@ void SyncDialog::on_note_conflict_detected(GObject*, gpointer data, gpointer thi
conflictDlg.hide();
// Let the SyncManager continue
- SyncManager::obj().resolve_conflict(/*localConflictNote, */args->resolution);
+ ISyncManager::obj().resolve_conflict(/*localConflictNote, */args->resolution);
}
catch(std::exception & e) {
args->mainThreadException = new std::exception(e);
diff --git a/src/synchronization/syncmanager.cpp b/src/synchronization/syncmanager.cpp
index fe45e2c..14f531e 100644
--- a/src/synchronization/syncmanager.cpp
+++ b/src/synchronization/syncmanager.cpp
@@ -20,7 +20,6 @@
#include "config.h"
-#include <boost/format.hpp>
#include <glibmm/i18n.h>
#include <gtkmm/actiongroup.h>
#include <sigc++/sigc++.h>
@@ -36,7 +35,6 @@
#include "silentui.hpp"
#include "syncmanager.hpp"
#include "syncserviceaddin.hpp"
-#include "sharp/uuid.hpp"
#include "sharp/xmlreader.hpp"
@@ -124,8 +122,8 @@ namespace sync {
void SyncManager::init(NoteManager & m)
{
- new SyncManager(m);
- SyncManager::obj()._init(m);
+ SyncManager *manager = new SyncManager(m);
+ manager->_init(m);
}
@@ -189,7 +187,7 @@ namespace sync {
finally() : addin(NULL){}
~finally()
{
- SyncManager::obj().m_sync_thread = NULL;
+ SyncManager::_obj().m_sync_thread = NULL;
try {
if(addin) {
addin->post_sync_cleanup();
@@ -741,19 +739,19 @@ namespace sync {
try {
SyncServer::Ptr & server = *static_cast<SyncServer::Ptr*>(serv);
// Make list of all local notes
- std::list<Note::Ptr> localNotes = SyncManager::obj().note_mgr().get_notes();
+ std::list<Note::Ptr> localNotes = SyncManager::_obj().note_mgr().get_notes();
// Get all notes currently on server
std::list<std::string> serverNotes = server->get_all_note_uuids();
// Delete notes locally that have been deleted on the server
for(std::list<Note::Ptr>::iterator iter = localNotes.begin(); iter != localNotes.end(); ++iter) {
- if(SyncManager::obj().m_client->get_revision(*iter) != -1
+ if(SyncManager::_obj().m_client->get_revision(*iter) != -1
&& std::find(serverNotes.begin(), serverNotes.end(), (*iter)->id()) == serverNotes.end()) {
- if(SyncManager::obj().m_sync_ui != 0) {
- SyncManager::obj().m_sync_ui->note_synchronized((*iter)->get_title(), DELETE_FROM_CLIENT);
+ if(SyncManager::_obj().m_sync_ui != 0) {
+ SyncManager::_obj().m_sync_ui->note_synchronized((*iter)->get_title(), DELETE_FROM_CLIENT);
}
- SyncManager::obj().note_mgr().delete_note(*iter);
+ SyncManager::_obj().note_mgr().delete_note(*iter);
}
}
}
@@ -770,8 +768,8 @@ namespace sync {
{
try {
NoteUpdate & noteUpdate = *static_cast<NoteUpdate*>(note_update);
- Note::Ptr existingNote = SyncManager::obj().note_mgr().create_with_guid(noteUpdate.m_title, noteUpdate.m_uuid);
- SyncManager::obj().update_local_note(existingNote, noteUpdate, DOWNLOAD_NEW);
+ Note::Ptr existingNote = SyncManager::_obj().note_mgr().create_with_guid(noteUpdate.m_title, noteUpdate.m_uuid);
+ SyncManager::_obj().update_local_note(existingNote, noteUpdate, DOWNLOAD_NEW);
}
catch(std::exception & e) {
DBG_OUT("Exception caught in %s: %s\n", __func__, e.what());
@@ -787,7 +785,7 @@ namespace sync {
try {
Note::Ptr *existingNote = static_cast<Note::Ptr*>(existing_note);
NoteUpdate & noteUpdate = *static_cast<NoteUpdate*>(note_update);
- SyncManager::obj().update_local_note(*existingNote, noteUpdate, DOWNLOAD_MODIFIED);
+ SyncManager::_obj().update_local_note(*existingNote, noteUpdate, DOWNLOAD_MODIFIED);
}
catch(std::exception & e) {
DBG_OUT("Exception caught in %s: %s\n", __func__, e.what());
@@ -802,7 +800,7 @@ namespace sync {
{
try {
Note::Ptr *existingNote = static_cast<Note::Ptr*>(existing_note);
- SyncManager::obj().note_mgr().delete_note(*existingNote);
+ SyncManager::_obj().note_mgr().delete_note(*existingNote);
}
catch(std::exception & e) {
DBG_OUT("Exception caught in %s: %s\n", __func__, e.what());
@@ -821,24 +819,5 @@ namespace sync {
}
- SyncLockInfo::SyncLockInfo()
- : client_id(Preferences::obj().get_schema_settings(Preferences::SCHEMA_SYNC)->get_string(Preferences::SYNC_CLIENT_ID))
- , transaction_id(sharp::uuid().string())
- , renew_count(0)
- , duration(0, 2, 0) // default of 2 minutes
- , revision(0)
- {
- }
-
-
- std::string SyncLockInfo::hash_string()
- {
- return str(boost::format("%1%-%2%-%3%-%4%-%5%") % transaction_id % client_id % renew_count % duration.string() % revision);
- }
-
-
- SyncServer::~SyncServer()
- {}
-
}
}
diff --git a/src/synchronization/syncmanager.hpp b/src/synchronization/syncmanager.hpp
index 3a931ed..11f8a24 100644
--- a/src/synchronization/syncmanager.hpp
+++ b/src/synchronization/syncmanager.hpp
@@ -22,18 +22,12 @@
#define _SYNCHRONIZATION_SYNCMANAGER_HPP_
-#include <exception>
#include <map>
-#include <string>
#include <glibmm/main.h>
#include <glibmm/thread.h>
-#include "note.hpp"
-#include "syncui.hpp"
-#include "base/singleton.hpp"
-#include "sharp/datetime.hpp"
-#include "sharp/timespan.hpp"
+#include "isyncmanager.hpp"
namespace gnote {
@@ -41,40 +35,27 @@ namespace sync {
class SyncServiceAddin;
- class SyncClient
- {
- public:
- typedef std::tr1::shared_ptr<SyncClient> Ptr;
-
- virtual int last_synchronized_revision() = 0;
- virtual void last_synchronized_revision(int) = 0;
- virtual sharp::DateTime last_sync_date() = 0;
- virtual void last_sync_date(const sharp::DateTime &) = 0;
- virtual int get_revision(const Note::Ptr & note) = 0;
- virtual void set_revision(const Note::Ptr & note, int revision) = 0;
- virtual std::map<std::string, std::string> deleted_note_titles() = 0;
- virtual void reset() = 0;
- virtual std::string associated_server_id() = 0;
- virtual void associated_server_id(const std::string &) = 0;
- };
-
class SyncManager
- : public base::Singleton<SyncManager>
+ : public ISyncManager
{
public:
SyncManager(NoteManager &);
~SyncManager();
static void init(NoteManager &);
- void reset_client();
- void perform_synchronization(const std::tr1::shared_ptr<SyncUI> & sync_ui);
+ virtual void reset_client();
+ virtual void perform_synchronization(const std::tr1::shared_ptr<SyncUI> & sync_ui);
void synchronization_thread();
- void resolve_conflict(SyncTitleConflictResolution resolution);
- bool synchronized_note_xml_matches(const std::string & noteXml1, const std::string & noteXml2);
- SyncState state() const
+ virtual void resolve_conflict(SyncTitleConflictResolution resolution);
+ virtual bool synchronized_note_xml_matches(const std::string & noteXml1, const std::string & noteXml2);
+ virtual SyncState state() const
{
return m_state;
}
private:
+ static SyncManager & _obj()
+ {
+ return static_cast<SyncManager&>(obj());
+ }
void _init(NoteManager &);
void handle_note_saved_or_deleted(const Note::Ptr & note);
void handle_note_buffer_changed(const Note::Ptr & note);
@@ -111,48 +92,6 @@ namespace sync {
};
- class SyncLockInfo
- {
- public:
- std::string client_id;
- std::string transaction_id;
- int renew_count;
- sharp::TimeSpan duration;
- int revision;
-
- SyncLockInfo();
- std::string hash_string();
- };
-
-
- class SyncServer
- {
- public:
- typedef std::tr1::shared_ptr<SyncServer> Ptr;
-
- virtual ~SyncServer();
-
- virtual bool begin_sync_transaction() = 0;
- virtual bool commit_sync_transaction() = 0;
- virtual bool cancel_sync_transaction() = 0;
- virtual std::list<std::string> get_all_note_uuids() = 0;
- virtual std::map<std::string, NoteUpdate> get_note_updates_since(int revision) = 0;
- virtual void delete_notes(const std::list<std::string> & deletedNoteUUIDs) = 0;
- virtual void upload_notes(const std::list<Note::Ptr> & notes) = 0;
- virtual int latest_revision() = 0; // NOTE: Only reliable during a transaction
- virtual SyncLockInfo current_sync_lock() = 0;
- virtual std::string id() = 0;
- virtual bool updates_available_since(int revision) = 0;
- };
-
-
- class GnoteSyncException
- : public std::runtime_error
- {
- public:
- GnoteSyncException(const char * what_arg) : std::runtime_error(what_arg){}
- };
-
}
}
diff --git a/src/synchronization/syncserviceaddin.hpp b/src/synchronization/syncserviceaddin.hpp
index f966ff1..d1d86e6 100644
--- a/src/synchronization/syncserviceaddin.hpp
+++ b/src/synchronization/syncserviceaddin.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 Aurimas Cernius
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
#include <gtkmm/widget.h>
#include "abstractaddin.hpp"
-#include "syncmanager.hpp"
+#include "isyncmanager.hpp"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]