? slavemanager.h ? slavemanager.cpp Index: Makefile.am =================================================================== RCS file: /home/kde/kdelibs/kio/Makefile.am,v retrieving revision 1.145 diff -u -3 -p -r1.145 Makefile.am --- Makefile.am 2001/03/14 14:16:45 1.145 +++ Makefile.am 2001/03/30 09:06:23 @@ -79,7 +79,8 @@ libkio_la_SOURCES = \ statusbarprogress.cpp \ kdirnotify.cpp kdirnotify.skel kdirnotify.stub \ observer.cpp uiserver.stub observer.skel \ - kemailsettings.cpp authinfo.cpp + kemailsettings.cpp authinfo.cpp \ + slavemanager.cpp kio_uiserver_SOURCES = dummy.cpp kio_uiserver_LDADD = kio_uiserver.la @@ -101,7 +102,8 @@ kioinclude_HEADERS = connection.h \ statusbarprogress.h uiserver.h uiserver_stub.h tcpslavebase.h \ renamedlg.h skipdlg.h slave.h \ observer.h chmodjob.h \ - kpac.h kmdbase.h authinfo.h + kpac.h kmdbase.h authinfo.h \ + slavemanager.h # Internal noinst_HEADERS = ksycocafactory.h kservicetypefactory.h kservicefactory.h \ Index: job.cpp =================================================================== RCS file: /home/kde/kdelibs/kio/job.cpp,v retrieving revision 1.246 diff -u -3 -p -r1.246 job.cpp --- job.cpp 2001/03/28 11:09:09 1.246 +++ job.cpp 2001/03/30 09:06:30 @@ -59,6 +59,7 @@ extern "C" { #include + using namespace KIO; template class QList; @@ -106,6 +107,9 @@ void Job::addSubjob(Job *job) connect( job, SIGNAL(result(KIO::Job*)), SLOT(slotResult(KIO::Job*)) ); + connect( job, SIGNAL(needConfiguration(KIO::Job*, const KIO::MetaData&)), + SLOT(slotNeedConfiguration(KIO::Job*, const KIO::MetaData&)) ); + // Forward information from that subjob. connect( job, SIGNAL(speed( KIO::Job*, unsigned long )), SLOT(slotSpeed(KIO::Job*, unsigned long)) ); @@ -179,6 +183,11 @@ void Job::kill( bool quietly ) } } +void Job::slotNeedConfiguration( Job *, const MetaData &data ) +{ + emit needConfiguration(this, data); +} + void Job::slotResult( Job *job ) { // Did job have an error ? @@ -235,10 +244,23 @@ QWidget *Job::window() const return m_window; } + +SlaveManagerGlobal * SimpleJob::m_slaveManager = 0; + +SlaveManagerGlobal * SimpleJob::managerInstance() +{ + if (m_slaveManager == 0) + { + KConfig *globalConfig = new KConfig("/tmp/kioconfig"); // define here the location for global config + m_slaveManager = new SlaveManagerGlobal(globalConfig, 0); + } + return m_slaveManager; +} + SimpleJob::SimpleJob(const KURL& url, int command, const QByteArray &packedArgs, bool showProgressInfo ) : Job(showProgressInfo), m_slave(0), m_packedArgs(packedArgs), - m_url(url), m_command(command), m_totalSize(0) + m_url(url), m_command(command), m_totalSize(0), m_configurationSent(false) { if (m_url.isMalformed()) { @@ -327,6 +349,9 @@ void SimpleJob::start(Slave *slave) connect( slave, SIGNAL( needProgressId() ), SLOT( slotNeedProgressId() ) ); + connect( m_slave, SIGNAL( needConfiguration( const KIO::MetaData& ) ), + SLOT( slotSlaveNeedConfiguration( const KIO::MetaData& ) ) ); + if (!m_subUrl.isEmpty()) { KIO_ARGS << m_subUrl; @@ -342,6 +367,31 @@ void SimpleJob::slaveDone() disconnect(m_slave); // Remove all signals between slave and job Scheduler::jobFinished( this, m_slave ); m_slave = 0; +} + +void SimpleJob::sendConfiguration( const MetaData &metadata ) +{ + kdDebug(7007) << "SimpleJob: send configuration to " << m_slave << endl; + m_configurationSent = true; + KIO_ARGS << metadata; + m_slave->connection()->send( CMD_CONFIG, packedArgs ); +} + +void SimpleJob::slotSlaveNeedConfiguration( const MetaData &data ) +{ + kdDebug(7007) << "SimpleJob::slotSlaveNeedConfiguration" << endl; + m_configurationSent = false; + emit needConfiguration(this, data); + //FIXME waiting for some virtual methods + // if the app don't handle configuration, we have to do it here + // this way is valid only if the sendConfiguration method is called in the + // slot connected to needConfiguration signal. + if (!m_configurationSent) + { + QString proto = url().protocol(); + SlaveManager *mngr = managerInstance()->manager(proto); + sendConfiguration(mngr->data(data["Group"])); + } } void SimpleJob::slotFinished( ) Index: jobclasses.h =================================================================== RCS file: /home/kde/kdelibs/kio/jobclasses.h,v retrieving revision 1.75 diff -u -3 -p -r1.75 jobclasses.h --- jobclasses.h 2001/02/07 00:06:48 1.75 +++ jobclasses.h 2001/03/30 09:06:32 @@ -35,6 +35,8 @@ #include +#include + class Observer; class QTimer; @@ -187,6 +189,11 @@ namespace KIO { */ void speed( KIO::Job *, unsigned long bytes_per_second ); + /** + * Emitted on slave's configuration request + */ + void needConfiguration( KIO::Job *, const MetaData &); + protected slots: /** * Called whenever a subjob finishes. @@ -197,6 +204,12 @@ namespace KIO { virtual void slotResult( KIO::Job *job ); /** + * Called whenever a slave connected to a subjob send a + * configuration's request + */ + void slotNeedConfiguration(KIO::Job *job, const MetaData &data); + + /** * Forward signal from subjob */ void slotSpeed( KIO::Job*, unsigned long bytes_per_second ); @@ -315,6 +328,20 @@ namespace KIO { */ int command() { return m_command; } + /** + * Send configuration to slave. + * You have to use this method from the slot connected to needConnection + * signal, because after the slave has emitted needConfiguration, it + * expects that its configuration has been updated, and the job-subjob + * structure needs this too. + */ + void sendConfiguration(const MetaData &); + + /** + * global instance for manager's managements + */ + static SlaveManagerGlobal * managerInstance(); + protected slots: /** * Called when the slave marks the job @@ -351,6 +378,15 @@ namespace KIO { */ void slotSpeed( unsigned long bytes_per_second ); + /** + * Called when the slave needs configuration data. Emit + * needConfiguration signal, and send global config if no data has been + * sent (i.e. if needConfiguration signal of main job is not handled). + * To select the "group" of entries needed, the slave use the key + * "Group". + */ + void slotSlaveNeedConfiguration( const KIO::MetaData &data ); + public slots: /** * @internal @@ -372,6 +408,10 @@ namespace KIO { KURL m_subUrl; int m_command; unsigned long m_totalSize; + bool m_configurationSent; + + private: + static SlaveManagerGlobal *m_slaveManager; }; // Stat Job Index: slavebase.cpp =================================================================== RCS file: /home/kde/kdelibs/kio/slavebase.cpp,v retrieving revision 1.73 diff -u -3 -p -r1.73 slavebase.cpp --- slavebase.cpp 2001/03/23 11:35:59 1.73 +++ slavebase.cpp 2001/03/30 09:06:35 @@ -59,6 +59,7 @@ namespace KIO { class SlaveBasePrivate { public: QString slaveid; + MetaData configuration; bool resume:1; bool needSendCanResume:1; }; @@ -93,6 +94,11 @@ SlaveBase::SlaveBase( const QCString &pr d->slaveid += QString::number(getpid()); d->resume = false; d->needSendCanResume = false; + // set initial configuration + //d->configuration = ??; + + //FIXME send config request ONLY TO TEST + needConfiguration(MetaData()); } SlaveBase::~SlaveBase() @@ -246,6 +252,13 @@ void SlaveBase::needSubURLData() m_pConnection->send( MSG_NEED_SUBURL_DATA ); } +void SlaveBase::needConfiguration(const MetaData &meta_data) +{ + kdDebug(7019) << "slaveBase: send needConfiguration request" << endl; + KIO_DATA << meta_data; + m_pConnection->send( MSG_NEED_CONFIG, data ); +} + void SlaveBase::slaveStatus( const QString &host, bool connected ) { pid_t pid = getpid(); @@ -310,6 +323,7 @@ void SlaveBase::mimeType( const QString } if ( (cmd == CMD_REPARSECONFIGURATION) || (cmd == CMD_META_DATA) || + (cmd == CMD_CONFIG) || //FIXME is this correct? (cmd == CMD_SUBURL) ) { dispatch( cmd, data ); @@ -458,6 +472,18 @@ void SlaveBase::setHost(QString const &h kdDebug( 7019 ) << "setHost( host = " << host << ")" << endl; } +void SlaveBase::setConfiguration(const MetaData &metadata) +{ + kdDebug(7019) << "setConfiguration: " << endl; + // save metadata to local + d->configuration = metadata; +} + +MetaData SlaveBase::configuration() const +{ + return d->configuration; +} + void SlaveBase::openConnection(void) { error( ERR_UNSUPPORTED_ACTION, "open" ); } void SlaveBase::closeConnection(void) @@ -494,6 +520,9 @@ void SlaveBase::slave_status() void SlaveBase::reparseConfiguration() { + // fill with infos for job + MetaData data; + needConfiguration(data); } bool SlaveBase::dispatch() @@ -640,9 +669,14 @@ void SlaveBase::dispatch( int command, c slave_status(); break; case CMD_REPARSECONFIGURATION: - KProtocolManager::reparseConfiguration(); + //KProtocolManager::reparseConfiguration(); to remove reparseConfiguration(); break; + case CMD_CONFIG: { + MetaData meta_data; + stream >> meta_data; + setConfiguration(meta_data); + } case CMD_GET: { stream >> url; get( url ); Index: slavebase.h =================================================================== RCS file: /home/kde/kdelibs/kio/slavebase.h,v retrieving revision 1.52 diff -u -3 -p -r1.52 slavebase.h --- slavebase.h 2001/03/23 11:35:59 1.52 +++ slavebase.h 2001/03/30 09:06:37 @@ -59,6 +59,12 @@ public: Connection *connection() const { return m_pConnection; } + /** + * get slave's configuration + * FIXME maybe it's better to define this as protected + */ + MetaData configuration() const; + /////////// // Message Signals to send to the job /////////// @@ -100,6 +106,13 @@ public: void needSubURLData(); /** + * Call to signal a request for slave configuration data + * @param data informations for job to know the slave's state + * to select the "group" of entries needed, use the key "Group". + */ + void needConfiguration(const MetaData &data); + + /** * Used to report the status of the slave. * @param host the slave is currently connected to. (Should be * empty if not connected) @@ -230,6 +243,11 @@ public: // Commands sent by the job, the slave has to override what it wants to implement /////////// + /** + * Set the slave config + */ + void setConfiguration(const MetaData &data); + /** * Set the host * @param host Index: slaveinterface.cpp =================================================================== RCS file: /home/kde/kdelibs/kio/slaveinterface.cpp,v retrieving revision 1.50 diff -u -3 -p -r1.50 slaveinterface.cpp --- slaveinterface.cpp 2001/03/23 11:35:59 1.50 +++ slaveinterface.cpp 2001/03/30 09:06:38 @@ -125,7 +125,6 @@ bool SlaveInterface::dispatch( int _cmd, case MSG_CONNECTED: emit connected(); break; - case INF_TOTAL_SIZE: stream >> ul; emit totalSize( ul ); @@ -212,6 +211,13 @@ bool SlaveInterface::dispatch( int _cmd, emit needSubURLData(); break; } + case MSG_NEED_CONFIG: { + kdDebug(7007) << "emit needConfiguration" << endl; + MetaData meta_data; + stream >> meta_data; + emit needConfiguration(meta_data); + break; + } case MSG_AUTH_KEY: { bool keep; QCString key, group; @@ -254,6 +260,15 @@ void SlaveInterface::sendResumeAnswer( b { kdDebug(7007) << "SlaveInterface::sendResumeAnswer ok for resuming :" << resume << endl; m_pConnection->sendnow( resume ? CMD_RESUMEANSWER : CMD_NONE, QByteArray() ); +} + +void SlaveInterface::sendConfiguration( const MetaData &data ) +{ + kdDebug(7007) << "SlaveInterface::sendConfiguration" << endl; + QByteArray packedArgs; + QDataStream stream( packedArgs, IO_WriteOnly ); + stream << data; + m_pConnection->sendnow(CMD_CONFIG, packedArgs); } void SlaveInterface::openPassDlg( const QString& prompt, const QString& user, bool readOnly ) Index: slaveinterface.h =================================================================== RCS file: /home/kde/kdelibs/kio/slaveinterface.h,v retrieving revision 1.47 diff -u -3 -p -r1.47 slaveinterface.h --- slaveinterface.h 2001/03/23 11:35:59 1.47 +++ slaveinterface.h 2001/03/30 09:06:38 @@ -65,7 +65,8 @@ class SlaveInterfacePrivate; CMD_SYMLINK = 'Q', // 81 CMD_SUBURL = 'R', // 82 Inform the slave about the url it is streaming on. CMD_MESSAGEBOXANSWER = 'S', // 83 - CMD_RESUMEANSWER = 'T' // 84 + CMD_RESUMEANSWER = 'T', // 84 + CMD_CONFIG = 'U' // 85 // Add new ones here once a release is done, to avoid breaking binary compatibility. // Note that protocol-specific commands shouldn't be added here, but should use special. }; @@ -110,7 +111,8 @@ class SlaveInterfacePrivate; MSG_NEED_SUBURL_DATA, MSG_CANRESUME, MSG_AUTH_KEY, - MSG_DEL_AUTH_KEY + MSG_DEL_AUTH_KEY, + MSG_NEED_CONFIG // add new ones here once a release is done, to avoid breaking binary compatibility }; @@ -139,6 +141,11 @@ public: // (to tell the "put" job whether to resume or not) void sendResumeAnswer( bool resume ); + /** + * Send configuration to slave + */ + void sendConfiguration(const MetaData &); + signals: /////////// // Messages sent by the slave @@ -154,6 +161,7 @@ signals: void statEntry( const KIO::UDSEntry& ); void needSubURLData(); void needProgressId(); + void needConfiguration(const KIO::MetaData &); void canResume( unsigned long ) ;