mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 00:54:20 +02:00
QSharedPtrify dbcmd creation.
This commit is contained in:
@@ -53,17 +53,16 @@
|
|||||||
#define MAX_WORKER_THREADS 16
|
#define MAX_WORKER_THREADS 16
|
||||||
|
|
||||||
|
|
||||||
DatabaseCommand*
|
dbcmd_ptr
|
||||||
DatabaseCommandFactory::newInstance()
|
DatabaseCommandFactory::newInstance()
|
||||||
{
|
{
|
||||||
DatabaseCommand* command = create();
|
dbcmd_ptr command = dbcmd_ptr( create() );
|
||||||
|
|
||||||
emit created( command );
|
emit created( command );
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Database* Database::s_instance = 0;
|
Database* Database::s_instance = 0;
|
||||||
|
|
||||||
|
|
||||||
@@ -260,7 +259,7 @@ void
|
|||||||
Database::registerCommand( DatabaseCommandFactory* commandFactory )
|
Database::registerCommand( DatabaseCommandFactory* commandFactory )
|
||||||
{
|
{
|
||||||
// this is ugly, but we don't have virtual static methods in C++ :(
|
// this is ugly, but we don't have virtual static methods in C++ :(
|
||||||
QScopedPointer<DatabaseCommand> command( commandFactory->newInstance() );
|
dbcmd_ptr command = commandFactory->newInstance();
|
||||||
|
|
||||||
const QString commandName = command->commandname();
|
const QString commandName = command->commandname();
|
||||||
const QString className = command->metaObject()->className();
|
const QString className = command->metaObject()->className();
|
||||||
@@ -294,7 +293,7 @@ Database::commandFactoryByCommandName(const QString& commandName )
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
DatabaseCommand*
|
dbcmd_ptr
|
||||||
Database::createCommandInstance( const QString& commandName )
|
Database::createCommandInstance( const QString& commandName )
|
||||||
{
|
{
|
||||||
DatabaseCommandFactory* factory = commandFactoryByCommandName( commandName );
|
DatabaseCommandFactory* factory = commandFactoryByCommandName( commandName );
|
||||||
@@ -302,21 +301,21 @@ Database::createCommandInstance( const QString& commandName )
|
|||||||
if( !factory )
|
if( !factory )
|
||||||
{
|
{
|
||||||
tLog() << "Unknown database command" << commandName;
|
tLog() << "Unknown database command" << commandName;
|
||||||
return 0;
|
return dbcmd_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
return factory->newInstance();
|
return factory->newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DatabaseCommand*
|
dbcmd_ptr
|
||||||
Database::createCommandInstance(const QVariant& op, const source_ptr& source)
|
Database::createCommandInstance(const QVariant& op, const source_ptr& source)
|
||||||
{
|
{
|
||||||
const QString commandName = op.toMap().value( "command" ).toString();
|
const QString commandName = op.toMap().value( "command" ).toString();
|
||||||
|
|
||||||
DatabaseCommand* command = createCommandInstance( commandName );
|
dbcmd_ptr command = createCommandInstance( commandName );
|
||||||
command->setSource( source );
|
command->setSource( source );
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), command );
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), command.data() );
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,16 +36,19 @@ class DatabaseWorker;
|
|||||||
class IdThreadWorker;
|
class IdThreadWorker;
|
||||||
|
|
||||||
|
|
||||||
|
typedef QSharedPointer< DatabaseCommand> dbcmd_ptr;
|
||||||
|
|
||||||
|
|
||||||
class DLLEXPORT DatabaseCommandFactory : public QObject
|
class DLLEXPORT DatabaseCommandFactory : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~DatabaseCommandFactory() {};
|
virtual ~DatabaseCommandFactory() {};
|
||||||
DatabaseCommand* newInstance();
|
dbcmd_ptr newInstance();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void created( DatabaseCommand* command );
|
void created( const dbcmd_ptr& command );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual DatabaseCommand* create() const = 0;
|
virtual DatabaseCommand* create() const = 0;
|
||||||
@@ -55,7 +58,7 @@ template <class COMMAND>
|
|||||||
class DatabaseCommandFactoryImplementation : public DatabaseCommandFactory
|
class DatabaseCommandFactoryImplementation : public DatabaseCommandFactory
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
virtual COMMAND* create() const { return new COMMAND(); };
|
virtual COMMAND* create() const { return new COMMAND(); };
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -83,7 +86,7 @@ public:
|
|||||||
|
|
||||||
DatabaseImpl* impl();
|
DatabaseImpl* impl();
|
||||||
|
|
||||||
DatabaseCommand* createCommandInstance( const QVariant& op, const Tomahawk::source_ptr& source );
|
dbcmd_ptr createCommandInstance( const QVariant& op, const Tomahawk::source_ptr& source );
|
||||||
|
|
||||||
// Template implementations need to stay in header!
|
// Template implementations need to stay in header!
|
||||||
template<typename T> void registerCommand()
|
template<typename T> void registerCommand()
|
||||||
@@ -114,7 +117,7 @@ private:
|
|||||||
void registerCommand( DatabaseCommandFactory* commandFactory );
|
void registerCommand( DatabaseCommandFactory* commandFactory );
|
||||||
DatabaseCommandFactory* commandFactoryByClassName( const QString& className );
|
DatabaseCommandFactory* commandFactoryByClassName( const QString& className );
|
||||||
DatabaseCommandFactory* commandFactoryByCommandName( const QString& commandName );
|
DatabaseCommandFactory* commandFactoryByCommandName( const QString& commandName );
|
||||||
DatabaseCommand* createCommandInstance( const QString& commandName );
|
dbcmd_ptr createCommandInstance( const QString& commandName );
|
||||||
|
|
||||||
bool m_ready;
|
bool m_ready;
|
||||||
|
|
||||||
|
@@ -199,11 +199,10 @@ DBSyncConnection::handleMsg( msg_ptr msg )
|
|||||||
// a db sync op msg
|
// a db sync op msg
|
||||||
if ( msg->is( Msg::DBOP ) )
|
if ( msg->is( Msg::DBOP ) )
|
||||||
{
|
{
|
||||||
DatabaseCommand* cmd = Database::instance()->createCommandInstance( m, m_source );
|
dbcmd_ptr cmd = Database::instance()->createCommandInstance( m, m_source );
|
||||||
if ( cmd )
|
if ( !cmd.isNull() )
|
||||||
{
|
{
|
||||||
QSharedPointer<DatabaseCommand> cmdsp = QSharedPointer<DatabaseCommand>(cmd);
|
m_source->addCommand( cmd );
|
||||||
m_source->addCommand( cmdsp );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !msg->is( Msg::FRAGMENT ) ) // last msg in this batch
|
if ( !msg->is( Msg::FRAGMENT ) ) // last msg in this batch
|
||||||
|
Reference in New Issue
Block a user