summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2012-12-03 11:49:59 +0100
committerPatrick Ohly <patrick.ohly@intel.com>2012-12-07 20:00:44 +0100
commit34562f4893a213afcf8c4b56bbd84cca77f6dbff (patch)
tree50c8937f7bdb6c8129e40d73f97425508b0ddb88
parent36eaa323bc455bb74233ccc8a04587c70f87ac53 (diff)
PIM: share ESourceRegistry via libsyncevolution
Switch to the new EDSRegistryLoader from libsyncevolution. This will allow sharing the ESourceRegistry with the EDS backend. We use the asynchronous loading method, to avoid blocking the server. This requires turning the search() method into an asynchronous method. The actual code runs once the ESourceRegistry is available, whether it is needed or not (keeps the logic simpler and minimizes code changes). To avoid reindenting the old code, the try/catch block and error checking for the callback was added in a separate intermediate function which then calls the old code.
-rw-r--r--src/dbus/server/pim/manager.cpp67
-rw-r--r--src/dbus/server/pim/manager.h23
2 files changed, 72 insertions, 18 deletions
diff --git a/src/dbus/server/pim/manager.cpp b/src/dbus/server/pim/manager.cpp
index d8cb8318..b4c8e544 100644
--- a/src/dbus/server/pim/manager.cpp
+++ b/src/dbus/server/pim/manager.cpp
@@ -29,6 +29,7 @@
#include "../session.h"
#include <syncevo/IniConfigNode.h>
+#include <syncevo/BoostHelper.h>
#include <boost/scoped_ptr.hpp>
#include <deque>
@@ -616,13 +617,60 @@ public:
};
unsigned int ViewResource::m_counter;
-GDBusCXX::DBusObject_t Manager::search(const GDBusCXX::Caller_t &ID,
- const boost::shared_ptr<GDBusCXX::Watch> &watch,
- const LocaleFactory::Filter_t &filter,
- const GDBusCXX::DBusObject_t &agentPath)
+void Manager::search(const boost::shared_ptr< GDBusCXX::Result1<GDBusCXX::DBusObject_t> > &result,
+ const GDBusCXX::Caller_t &ID,
+ const boost::shared_ptr<GDBusCXX::Watch> &watch,
+ const LocaleFactory::Filter_t &filter,
+ const GDBusCXX::DBusObject_t &agentPath)
{
+ // Start folks in parallel with asking for an ESourceRegistry.
start();
+ // We don't know for sure whether we'll need the ESourceRegistry.
+ // Ask for it, just to be sure. If we need to hurry because we are
+ // doing a caller ID lookup during startup, then we'll need it.
+ EDSRegistryLoader::getESourceRegistryAsync(boost::bind(&Manager::searchWithRegistry,
+ m_self,
+ _1,
+ _2,
+ result,
+ ID,
+ watch,
+ filter,
+ agentPath));
+}
+
+void Manager::searchWithRegistry(const ESourceRegistryCXX &registry,
+ const GError *gerror,
+ const boost::shared_ptr< GDBusCXX::Result1<GDBusCXX::DBusObject_t> > &result,
+ const GDBusCXX::Caller_t &ID,
+ const boost::shared_ptr<GDBusCXX::Watch> &watch,
+ const LocaleFactory::Filter_t &filter,
+ const GDBusCXX::DBusObject_t &agentPath) throw()
+{
+ try {
+ if (!registry) {
+ GErrorCXX::throwError("create ESourceRegistry", gerror);
+ }
+ doSearch(registry,
+ result,
+ ID,
+ watch,
+ filter,
+ agentPath);
+ } catch (...) {
+ // Tell caller about specific error.
+ dbusErrorCallback(result);
+ }
+}
+
+void Manager::doSearch(const ESourceRegistryCXX &registry,
+ const boost::shared_ptr< GDBusCXX::Result1<GDBusCXX::DBusObject_t> > &result,
+ const GDBusCXX::Caller_t &ID,
+ const boost::shared_ptr<GDBusCXX::Watch> &watch,
+ const LocaleFactory::Filter_t &filter,
+ const GDBusCXX::DBusObject_t &agentPath)
+{
// Create and track view which is owned by the caller.
boost::shared_ptr<Client> client = m_server->addClient(ID, watch);
@@ -658,15 +706,6 @@ GDBusCXX::DBusObject_t Manager::search(const GDBusCXX::Caller_t &ID,
IndividualCompare::defaultCompare() :
m_locale->createCompare(m_sortOrder);
- // TODO: use global registry
- ESourceRegistryCXX registry;
- GErrorCXX gerror;
- SYNCEVO_GLIB_CALL_SYNC(registry, gerror,
- e_source_registry_new,
- NULL);
- if (!registry) {
- gerror.throwError("unable to access databases registry");
- }
BOOST_FOREACH (const std::string &uuid, m_enabledEBooks) {
searches.push_back(EDSFView::create(registry,
uuid,
@@ -690,7 +729,7 @@ GDBusCXX::DBusObject_t Manager::search(const GDBusCXX::Caller_t &ID,
client->attach(boost::shared_ptr<Resource>(viewResource));
// created local resource
- return viewResource->getPath();
+ result->done(viewResource->getPath());
}
void Manager::runInSession(const std::string &config,
diff --git a/src/dbus/server/pim/manager.h b/src/dbus/server/pim/manager.h
index 08e181fb..3a950311 100644
--- a/src/dbus/server/pim/manager.h
+++ b/src/dbus/server/pim/manager.h
@@ -28,6 +28,7 @@
#include "folks.h"
#include "locale-factory.h"
#include "../server.h"
+#include <syncevo/EDSClient.h>
#include <syncevo/declarations.h>
SE_BEGIN_CXX
@@ -72,10 +73,24 @@ class Manager : public GDBusCXX::DBusObjectHelper
/** Manager.GetSortOrder() */
std::string getSortOrder() { return m_sortOrder; }
/** Manager.Search() */
- GDBusCXX::DBusObject_t search(const GDBusCXX::Caller_t &ID,
- const boost::shared_ptr<GDBusCXX::Watch> &watch,
- const LocaleFactory::Filter_t &filter,
- const GDBusCXX::DBusObject_t &agentPath);
+ void search(const boost::shared_ptr< GDBusCXX::Result1<GDBusCXX::DBusObject_t> > &result,
+ const GDBusCXX::Caller_t &ID,
+ const boost::shared_ptr<GDBusCXX::Watch> &watch,
+ const LocaleFactory::Filter_t &filter,
+ const GDBusCXX::DBusObject_t &agentPath);
+ void searchWithRegistry(const ESourceRegistryCXX &registry,
+ const GError *gerror,
+ const boost::shared_ptr< GDBusCXX::Result1<GDBusCXX::DBusObject_t> > &result,
+ const GDBusCXX::Caller_t &ID,
+ const boost::shared_ptr<GDBusCXX::Watch> &watch,
+ const LocaleFactory::Filter_t &filter,
+ const GDBusCXX::DBusObject_t &agentPath) throw();
+ void doSearch(const ESourceRegistryCXX &registry,
+ const boost::shared_ptr< GDBusCXX::Result1<GDBusCXX::DBusObject_t> > &result,
+ const GDBusCXX::Caller_t &ID,
+ const boost::shared_ptr<GDBusCXX::Watch> &watch,
+ const LocaleFactory::Filter_t &filter,
+ const GDBusCXX::DBusObject_t &agentPath);
/** Manager.GetActiveAddressBooks() */
void getActiveAddressBooks(std::vector<std::string> &dbIDs);