Commit bae5b942 authored by Bertjan Broeksema's avatar Bertjan Broeksema
Browse files

Start preparing Akonadi server for yet another way to launch agents.

To make it easy to switch between running agents in the AgentServer,
i.e. threaded, and running them in their own process (in case of unstable
agents), we'll use the agent_launcher helper program soon. This will do
practically the same as the AgentServer, but only running one Agent.
This approach prevents AgentWriters to have to provide a plugin *and* an
executable.

svn path=/branches/work/akonadi-agentserver/; revision=1181544
parent d80d98b7
......@@ -190,10 +190,21 @@ QStringList AgentManager::agentCapabilities( const QString &identifier ) const
AgentInstance::Ptr AgentManager::createAgentInstance( const AgentType &info )
{
if ( info.runInAgentServer )
return AgentInstance::Ptr( new Akonadi::AgentThreadInstance( this ) );
else
switch ( info.execMethod ) {
case AgentType::Process:
return AgentInstance::Ptr( new Akonadi::AgentProcessInstance( this ) );
break;
case AgentType::Server:
return AgentInstance::Ptr( new Akonadi::AgentThreadInstance( this ) );
break;
case AgentType::Launcher:
Q_ASSERT_X( false, "AgentManager::createAgentInstance", "NOT IMPLEMENTED" );
break;
default:
Q_ASSERT_X( false, "AgentManger::createAgentInstance", "Unhandled AgentType::ExecMethod case" );
}
return AgentInstance::Ptr();
}
QString AgentManager::createAgentInstance( const QString &identifier )
......@@ -695,11 +706,15 @@ void AgentManager::ensureAutoStart(const AgentType & info)
if ( mAgentInstances.contains( info.identifier ) || agentServer.started( info.identifier ) )
return; // already running
if ( info.runInAgentServer ) {
switch ( info.execMethod ) {
case AgentType::Server:
agentServer.startAgent( info.identifier, info.exec );
registerAgentAtServer( info.identifier, info );
save();
} else {
break;
case AgentType::Process: // Fall through
case AgentType::Launcher:
{
AgentInstance::Ptr instance = createAgentInstance( info );
instance->setIdentifier( info.identifier );
if ( instance->start( info ) ) {
......@@ -707,6 +722,10 @@ void AgentManager::ensureAutoStart(const AgentType & info)
registerAgentAtServer( instance->identifier(), info );
save();
}
break;
}
default:
Q_ASSERT_X( false, "AgentManager::ensureAutoStart", "unhandled AgentType::ExecMethod case" );
}
}
......
......@@ -61,11 +61,19 @@ bool AgentType::load(const QString & fileName, AgentManager * manager)
capabilities = file.value( "X-Akonadi-Capabilities" ).toStringList();
exec = file.value( "Exec" ).toString();
identifier = file.value( "X-Akonadi-Identifier" ).toString();
runInAgentServer = false; // Save default
if ( file.contains( "X-Akonadi-RunInAgentServer" ) ) {
runInAgentServer = file.value( "X-Akonadi-RunInAgentServer" ).toBool();
execMethod = Process; // Save default
const QString method = file.value( "X-Akonadi-ExecMethod" ).toString();
if ( method.compare( QLatin1String( "AgentProcess" ), Qt::CaseInsensitive ) ) {
execMethod = Process;
} else if ( method.compare( QLatin1String( "AgentManager" ), Qt::CaseInsensitive ) ) {
execMethod = Server;
} else if ( method.compare( QLatin1String( "AgentLauncher" ), Qt::CaseInsensitive ) ) {
execMethod = Launcher;
} else if ( !method.isEmpty() ) {
akError() << Q_FUNC_INFO << "Invalid exec method:" << method << "falling back to AgentProcess";
}
file.endGroup();
if ( identifier.isEmpty() ) {
......
......@@ -33,6 +33,13 @@ class QSettings;
class AgentType
{
public:
enum LaunchMethod {
Process, /// Standalone executable
Server, /// Agent plugin launched in AgentManager
Launcher /// Agent plugin launched in own process
};
public:
AgentType();
bool load( const QString &fileName, AgentManager *manager );
......@@ -46,7 +53,7 @@ class AgentType
QStringList capabilities;
QString exec;
uint instanceCounter;
bool runInAgentServer;
LaunchMethod execMethod;
static QLatin1String CapabilityUnique;
static QLatin1String CapabilityResource;
......
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