Commit 01d25fab authored by Volker Krause's avatar Volker Krause
Browse files

Support for distributing search queries to agents.

svn path=/trunk/kdesupport/akonadi/; revision=1056580
parent d73ef3bb
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.Akonadi.Agent.Search">
<method name="addSearch">
<arg name="query" type="s" direction="in"/>
<arg name="queryLanguage" type="s" direction="in"/>
<arg name="destination" type="x" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="removeSearch">
<arg name="destination" type="x" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
</interface>
</node>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.Akonadi.AgentManagerInternal">
<method name="addSearch">
<arg name="query" type="s" direction="in"/>
<arg name="queryLanguage" type="s" direction="in"/>
<arg name="destination" type="x" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="removeSearch">
<arg name="destination" type="x" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
</interface>
</node>
......@@ -30,6 +30,7 @@
#define AKONADI_AGENT_CAPABILITY_NOCONFIG "NoConfig"
#define AKONADI_AGENT_CAPABILITY_PREPROCESSOR "Preprocessor"
#define AKONADI_AGENT_CAPABILITY_RESOURCE "Resource"
#define AKONADI_AGENT_CAPABILITY_SEARCH "Search"
#define AKONADI_AGENT_CAPABILITY_UNIQUE "Unique"
#define AKONADI_AGENT_CAPABILITY_VIRTUAL "Virtual"
......
......@@ -32,6 +32,8 @@
#define AKONADI_DBUS_SERVER_SERVICE "org.freedesktop.Akonadi"
#define AKONADI_DBUS_CONTROL_SERVICE "org.freedesktop.Akonadi.Control"
#define AKONADI_DBUS_AGENTMANAGER_PATH "/AgentManager"
// Commands
#define AKONADI_CMD_COLLECTIONCOPY "COLCOPY"
#define AKONADI_CMD_COLLECTIONCREATE "CREATE"
......
......@@ -25,10 +25,12 @@ set( control_SRCS
qt4_add_dbus_adaptor( control_SRCS ${Akonadi_SOURCE_DIR}/interfaces/org.freedesktop.Akonadi.AgentManager.xml agentmanager.h AgentManager )
qt4_add_dbus_adaptor( control_SRCS ${Akonadi_SOURCE_DIR}/server/interfaces/org.freedesktop.Akonadi.ControlManager.xml controlmanager.h ControlManager )
qt4_add_dbus_adaptor( control_SRCS ${Akonadi_SOURCE_DIR}/interfaces/org.freedesktop.Akonadi.AgentManagerInternal.xml agentmanager.h AgentManager )
qt4_add_dbus_interfaces( control_SRCS
${Akonadi_SOURCE_DIR}/interfaces/org.freedesktop.Akonadi.Tracer.xml
${Akonadi_SOURCE_DIR}/interfaces/org.freedesktop.Akonadi.Agent.Control.xml
${Akonadi_SOURCE_DIR}/interfaces/org.freedesktop.Akonadi.Agent.Status.xml
${Akonadi_SOURCE_DIR}/interfaces/org.freedesktop.Akonadi.Agent.Search.xml
${Akonadi_SOURCE_DIR}/interfaces/org.freedesktop.Akonadi.Resource.xml
${Akonadi_SOURCE_DIR}/interfaces/org.freedesktop.Akonadi.Preprocessor.xml
${Akonadi_SOURCE_DIR}/server/interfaces/org.freedesktop.Akonadi.Server.xml
......
......@@ -30,6 +30,7 @@ AgentInstance::AgentInstance(AgentManager * manager) :
mController( 0 ),
mAgentControlInterface( 0 ),
mAgentStatusInterface( 0 ),
mSearchInterface( 0 ),
mResourceInterface( 0 ),
mPreprocessorInterface( 0 ),
mStatus( 0 ),
......@@ -108,6 +109,14 @@ bool AgentInstance::obtainAgentInterface()
}
mAgentStatusInterface = agentStatusIface;
mSearchInterface = new org::freedesktop::Akonadi::Agent::Search( "org.freedesktop.Akonadi.Agent." + mIdentifier,
"/", QDBusConnection::sessionBus(), this );
if ( !mSearchInterface || !mSearchInterface->isValid() ) {
delete mSearchInterface;
mSearchInterface = 0;
}
connect( agentStatusIface, SIGNAL(status(int,QString)), SLOT(statusChanged(int,QString)) );
connect( agentStatusIface, SIGNAL(percent(int)), SLOT(percentChanged(int)) );
connect( agentStatusIface, SIGNAL(warning(QString)), SLOT(warning(QString)) );
......
......@@ -25,6 +25,7 @@
#include "resourceinterface.h"
#include "tracerinterface.h"
#include "preprocessorinterface.h"
#include "searchinterface.h"
#include <QDBusError>
#include <QString>
......@@ -76,6 +77,7 @@ class AgentInstance : public QObject
org::freedesktop::Akonadi::Agent::Control* controlInterface() const { return mAgentControlInterface; }
org::freedesktop::Akonadi::Agent::Status* statusInterface() const { return mAgentStatusInterface; }
org::freedesktop::Akonadi::Agent::Search* searchInterface() const { return mSearchInterface; }
org::freedesktop::Akonadi::Resource* resourceInterface() const { return mResourceInterface; }
org::freedesktop::Akonadi::Preprocessor * preProcessorInterface() const { return mPreprocessorInterface; }
......@@ -105,6 +107,7 @@ class AgentInstance : public QObject
Akonadi::ProcessControl *mController;
org::freedesktop::Akonadi::Agent::Control *mAgentControlInterface;
org::freedesktop::Akonadi::Agent::Status *mAgentStatusInterface;
org::freedesktop::Akonadi::Agent::Search* mSearchInterface;
org::freedesktop::Akonadi::Resource *mResourceInterface;
org::freedesktop::Akonadi::Preprocessor * mPreprocessorInterface;
......
......@@ -21,6 +21,7 @@
#include "agentmanager.h"
#include "agentmanageradaptor.h"
#include "agentmanagerinternaladaptor.h"
#include "processcontrol.h"
#include "serverinterface.h"
#include "libs/xdgbasedirs_p.h"
......@@ -45,6 +46,7 @@ AgentManager::AgentManager( QObject *parent )
mAgentWatcher( new QFileSystemWatcher( this ) )
{
new AgentManagerAdaptor( this );
new AgentManagerInternalAdaptor( this );
QDBusConnection::sessionBus().registerObject( "/AgentManager", this );
mTracer = new org::freedesktop::Akonadi::Tracer( "org.freedesktop.Akonadi", "/tracing", QDBusConnection::sessionBus(), this );
......@@ -678,4 +680,25 @@ void AgentManager::registerAgentAtServer( const AgentInstance::Ptr &instance, co
}
}
void AgentManager::addSearch(const QString& query, const QString& queryLanguage, qint64 resultCollectionId)
{
qDebug() << "AgentManager::addSearch" << query << queryLanguage << resultCollectionId;
foreach ( const AgentInstance::Ptr &instance, mAgentInstances ) {
const AgentType type = mAgents.value( instance->agentType() );
if ( type.capabilities.contains( AgentType::CapabilitySearch ) && instance->searchInterface() )
instance->searchInterface()->addSearch( query, queryLanguage, resultCollectionId );
}
}
void AgentManager::removeSearch(quint64 resultCollectionId)
{
qDebug() << "AgentManager::removeSearch" << resultCollectionId;
foreach ( const AgentInstance::Ptr &instance, mAgentInstances ) {
const AgentType type = mAgents.value( instance->agentType() );
if ( type.capabilities.contains( AgentType::CapabilitySearch ) && instance->searchInterface() )
instance->searchInterface()->removeSearch( resultCollectionId );
}
}
#include "agentmanager.moc"
......@@ -213,6 +213,16 @@ class AgentManager : public QObject
*/
void restartAgentInstance( const QString &identifier );
/**
* Add a persistent search to remote search agents.
*/
void addSearch( const QString &query, const QString &queryLanguage, qint64 resultCollectionId );
/**
* Removes a persistent search for the given result collection.
*/
void removeSearch( quint64 resultCollectionId );
Q_SIGNALS:
/**
* This signal is emitted whenever a new agent type was installed on the system.
......
......@@ -31,6 +31,7 @@ QLatin1String AgentType::CapabilityUnique = QLatin1String( AKONADI_AGENT_CAPABIL
QLatin1String AgentType::CapabilityResource = QLatin1String( AKONADI_AGENT_CAPABILITY_RESOURCE );
QLatin1String AgentType::CapabilityAutostart = QLatin1String( AKONADI_AGENT_CAPABILITY_AUTOSTART );
QLatin1String AgentType::CapabilityPreprocessor = QLatin1String( AKONADI_AGENT_CAPABILITY_PREPROCESSOR );
QLatin1String AgentType::CapabilitySearch = QLatin1String( AKONADI_AGENT_CAPABILITY_SEARCH );
AgentType::AgentType() :
instanceCounter( 0 )
......
......@@ -51,6 +51,7 @@ class AgentType
static QLatin1String CapabilityResource;
static QLatin1String CapabilityAutostart;
static QLatin1String CapabilityPreprocessor;
static QLatin1String CapabilitySearch;
};
#endif
......@@ -29,6 +29,10 @@
#include "imapstreamparser.h"
#include <storage/selectquerybuilder.h>
#include <storage/collectionqueryhelper.h>
#include "libs/protocol_p.h"
#include <akdebug.h>
#include <QDBusInterface>
using namespace Akonadi;
......@@ -78,6 +82,18 @@ bool Delete::parseStream()
return failureResponse( "Cannot delete virtual root collection" );
AbstractSearchManager::instance()->removeSearch( collection.id() );
// disable remote searches
QDBusInterface agentMgr( QLatin1String( AKONADI_DBUS_CONTROL_SERVICE ),
QLatin1String( AKONADI_DBUS_AGENTMANAGER_PATH ),
QLatin1String( "org.freedesktop.Akonadi.AgentManagerInternal" ) );
if ( agentMgr.isValid() ) {
QList<QVariant> args;
args << collection.id();
agentMgr.callWithArgumentList( QDBus::NoBlock, QLatin1String( "removeSearch" ), args );
} else {
akError() << "Failed to connect to agent manager: " << agentMgr.lastError();
}
}
if ( !deleteRecursive( collection ) )
......
......@@ -28,8 +28,12 @@
#include "handlerhelper.h"
#include "abstractsearchmanager.h"
#include "imapstreamparser.h"
#include "libs/protocol_p.h"
#include <akdebug.h>
#include <QtCore/QStringList>
#include <qdbusinterface.h>
#include <QtDBus/qdbusreply.h>
using namespace Akonadi;
......@@ -78,6 +82,20 @@ bool SearchPersistent::parseStream()
if ( !transaction.commit() )
return failureResponse( "Unable to commit transaction" );
// distribute to remote search agents
QDBusInterface agentMgr( QLatin1String( AKONADI_DBUS_CONTROL_SERVICE ),
QLatin1String( AKONADI_DBUS_AGENTMANAGER_PATH ),
QLatin1String( "org.freedesktop.Akonadi.AgentManagerInternal" ) );
if ( agentMgr.isValid() ) {
QList<QVariant> args;
args << QString::fromUtf8( queryString );
args << QString::fromLatin1( "SPARQL" );
args << col.id();
agentMgr.callWithArgumentList( QDBus::NoBlock, QLatin1String( "addSearch" ), args );
} else {
akError() << "Failed to connect to agent manager: " << agentMgr.lastError();
}
const QByteArray b = HandlerHelper::collectionToByteArray( col );
Response colResponse;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment