[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: KDE 2.2beta1
From:       Sergio Moretti <sermore () libero ! it>
Date:       2001-03-30 12:45:18
[Download RAW message or body]

On Wednesday 28 March 2001 06:40, Waldo Bastian wrote:
> * new kio-slave configuration

third attempt, seems to work, but I made some changes to SimpleJob and 
to Scheduler::startJob*

["slavemanager.h" (text/x-c++)]

/* This file is part of the KDE libraries

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/
#ifndef __slavemanager_h__
#define __slavemanager_h__

#include <qstring.h>
#include <kconfig.h>
#include <qdict.h>
#include <kio/global.h>


namespace KIO {

   class SlaveManager;

   /**
    * Factory for SlaveManager objects.
    * Read its state from a desktop-wide config file.
    * For every slave type there must be a group named as the slave's protocol.
    * The group can contain directly the config entries for the slave, or an
    * entry named "configFile", which points to a config file dedicated to a
    * single slave type.
    * If is created with null appConfig then it creates "global" managers, 
    * i.e. managers that read/modify only desktop-wide settings.
    */
   class SlaveManagerFactory
   {
   public:
      /**
       * constructor
       * @param globalConfig desktop-wide configuration
       * @param appConfig application-wide configuration
       */
      SlaveManagerFactory(KConfig *globalConfig, KConfig *appConfig);

      ~SlaveManagerFactory();

      /**
       * Create a new manager for protocol.
       * For either global and app config, 
       * parse group <protocol> in config, if an entry "configFile file"
       * is found, then open a new KConfig object pointing at "file", otherwise
       * pass current KConfig instances
       */
      SlaveManager * manager(const QString &protocol);

   protected:
      /**
       * Return a pointer to the KConfig object associated to proto, creating
       * it if necessary.
       */
      KConfig * getConfig(KConfig *cfg, const QString &proto, bool create);

   private:
      KConfig *_glbCfg;
      KConfig *_appCfg;
   };


   /**
    * Manager for slave's configuration.
    * Act as desktop-level manager if global is null.
    * Act as application-level manager if global and app are defined.
    * Entries are grouped, a group is the minimal set of data sent to / received 
    * from slave, to permit to distinguish between different kind of entries.
    */
   class SlaveManager
   {
      friend class SlaveManagerFactory;

   public:
      ~SlaveManager();

      /**
       * query, for key, app and (if defined) global confs, in this order. 
       * If key is found, the associated value is returned
       */
      QString entry(const QString &group, const QString &key) const;

      /**
       * create (or update) key, value pair in app config
       */
      void setEntry(const QString &group, const QString &key, 
		    const QString &value);

      /**
       * remove the entry associated with key from app config
       */
      void removeEntry(const QString &group, const QString &key);
      
      /**
       * pack entries to metadata
       */
      MetaData data(const QString &group) const;

      /**
       * unpack and merge entries from metadata
       */
      void setData(const QString &group, const MetaData &data);

   protected:
      /**
       * constructor
       * If group is null, then a new KConfig is passed to object, for which 
       * this object has the responsibility to delete it.
       * If group is not null, the KConfig object passed is shared amongs
       * sibling managers and factory.
       * If app config is null, work in read/write mode on global config.
       */
      SlaveManager(KConfig *globalCfg, const QString &globalGroup, 
		   KConfig *appCfg, const QString &appGroup);

      /**
       * build real group name 
       */
      static QString group(const QString &group, const QString &subGroup);
      
   private:
      KConfig *_glbCfg, *_appCfg;
      QString _glbGrp, _appGrp;
   };


   /**
    * Factory for SlaveManager objects.
    * Handle created managers instances internally, 
    * extending the set/get interface to manager's entries with a parameter to 
    * specify the protocol.
    */
   class SlaveManagerGlobal : public SlaveManagerFactory
   {
   public:
      /**
       * constructor
       * @param appConfig application-wide configuration
       * @param globalConfig desktop-wide configuration
       */
      SlaveManagerGlobal(KConfig *globalConfig, KConfig *appConfig);

      ~SlaveManagerGlobal();

      /**
       * retrieve or create if not existent a new manager for protocol
       */
      SlaveManager * manager(const QString &protocol);

      /**
       * Query manager associate to protocol, creating it if it is not existent.
       */
      QString entry(const QString &protocol, const QString &group, 
		    const QString &key);

      /**
       * Set key, value pair in manager associate to protocol, creating it if it
       * is not existent.
       */
      void setEntry(const QString &protocol, const QString &group, 
		    const QString &key, const QString &value);
      
      /**
       * remove the entry associated with key
       */
      void removeEntry(const QString &protocol, const QString &group, 
		       const QString &key);

   private:
      QDict<SlaveManager> _managers;
   };

}; // namespace KIO

#endif

["slavemanager.cpp" (text/x-c++)]

/* This file is part of the KDE libraries

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#include <kdebug.h>
#include "slavemanager.h"

// debug area
#define DBA 7007

using namespace KIO;

SlaveManagerFactory::SlaveManagerFactory(KConfig *globalConfig, 
					 KConfig *appConfig)
   : _glbCfg(globalConfig), _appCfg(appConfig)
{
   kdDebug(DBA) << "SlaveManagerFactory : create " << (_appCfg != 0 ? "application" : \
"global") << " factory" << endl;  kdFatal(_glbCfg == 0, DBA) << "SlaveManagerFactory \
: global config null" << endl; }

SlaveManagerFactory::~SlaveManagerFactory()
{
   delete _glbCfg;
   if (_appCfg)
      delete _appCfg;
}

KConfig * SlaveManagerFactory::getConfig(KConfig *cfg, const QString &proto, 
					 bool create)
{
   if (!cfg->hasGroup(proto) && !create)
      return 0;
   cfg->setGroup(proto);
   if (cfg->hasKey("configFile"))
      return new KConfig(cfg->readEntry("configFile"));
   return cfg;
}
   

SlaveManager * SlaveManagerFactory::manager(const QString &proto)
{
   kdDebug(DBA) << "SlaveManagerFactory::manager : create manager for protocol:" << \
proto << endl;  // references to config for protocol
   KConfig *appCfg = (_appCfg != 0 ? getConfig(_appCfg, proto, true) : 0);
   // if this is a global factory, then it creates managers with permission to 
   // change global config
   KConfig *glbCfg = getConfig(_glbCfg, proto, _appCfg == 0); 
   QString appGrp = (appCfg == _appCfg ? proto : QString::null);
   QString glbGrp = (glbCfg == _glbCfg ? proto : QString::null);
   kdFatal(((_appCfg != 0 && appCfg == 0) || glbCfg == 0), DBA) << \
"SlaveManagerFactory::manager : error creating config for protocol:" << proto << \
endl;  return new SlaveManager(glbCfg, glbGrp, appCfg, appGrp);
}

///////////////////////////////////////////////////////////////////////

SlaveManager::SlaveManager(KConfig *globalCfg, const QString &globalGrp,
			   KConfig *appCfg, const QString &appGrp)
   : _glbCfg(globalCfg), _appCfg(appCfg), _glbGrp(globalGrp), _appGrp(appGrp)
{
}

SlaveManager::~SlaveManager()
{
   if (_glbGrp.isEmpty())
      delete _glbCfg;
   if (_appGrp.isEmpty() && _appCfg != 0)
      delete _appCfg;
}

QString SlaveManager::group(const QString &grp, const QString &subGrp)
{
   if (subGrp.isEmpty())
      return grp;
   if (grp.isEmpty())
      return subGrp;
   return QString("%1 %2").arg(grp).arg(subGrp);
}

QString SlaveManager::entry(const QString &grp, const QString &key) const
{

   if (_appCfg)
   {
      // read from app config
      QString g = group(_appGrp, grp);
      _appCfg->setGroup(g);
      if (_appCfg->hasKey(key))
	 return _appCfg->readEntry(key);
   }
   // if key is not found in app, read from global config
   QString g = group(_glbGrp, grp);
   _glbCfg->setGroup(g);
   if (_glbCfg->hasKey(key))
      return _glbCfg->readEntry(key);
   
   return QString::null;
}

void SlaveManager::setEntry(const QString &grp, const QString &key, 
			    const QString &value)
{
   KConfig *cfg = (_appCfg != 0 ? _appCfg : _glbCfg);
   QString g = (_appCfg != 0 ? group(_appGrp, grp) : group(_glbGrp, grp));
   cfg->setGroup(g);
   cfg->writeEntry(key, value);
}

void SlaveManager::removeEntry(const QString &, const QString &)
{
   // why there isn't a deleteEntry method in KConfig?
   // some hack to perform this, as is needed to pass from local to global 
   // mapping.
}

MetaData SlaveManager::data(const QString &grp) const
{
   KConfig *cfg = (_appCfg != 0 ? _appCfg : _glbCfg);
   QString g = (_appCfg != 0 ? group(_appGrp, grp) : group(_glbGrp, grp));
   MetaData metadata;

   //MetaData metadata = _appCfg->entryMap(g); add an operator= to MetaData
   QMap<QString, QString> map = cfg->entryMap(g);
   for (QMap<QString, QString>::ConstIterator it = map.begin(); 
	it != map.end(); ++it)
      metadata.insert(it.key(), it.data());

   if (_appCfg)
   { 
      // add the global entries not contained in app
      g = group(_glbGrp, grp);
      map = _glbCfg->entryMap(g);
      for (QMap<QString, QString>::ConstIterator it = map.begin(); 
	   it != map.end(); ++it)
	 if (!metadata.contains(it.key()))
	    metadata.insert(it.key(), it.data());
   }
   return metadata;
}

void SlaveManager::setData(const QString &grp, const MetaData &data)
{
   KConfig *cfg = (_appCfg != 0 ? _appCfg : _glbCfg);
   QString g = (_appCfg != 0 ? group(_appGrp, grp) : group(_glbGrp, grp));
   cfg->setGroup(g);
   for (QMap<QString, QString>::ConstIterator it = data.begin(); 
	it != data.end(); ++it)
      cfg->writeEntry(it.key(), it.data());
}

/////////////////////////////////////////////////////////////////////////

SlaveManagerGlobal::SlaveManagerGlobal(KConfig *appConfig, 
				       KConfig *globalConfig)
   : SlaveManagerFactory(appConfig, globalConfig)
{
}

SlaveManagerGlobal::~SlaveManagerGlobal()
{
   _managers.setAutoDelete(true);
}

SlaveManager * SlaveManagerGlobal::manager(const QString &protocol)
{
   SlaveManager *m = _managers.find(protocol);
   if (m == 0)
   {
      m = SlaveManagerFactory::manager(protocol);
      _managers.insert(protocol, m);
   }
   return m;
}

QString SlaveManagerGlobal::entry(const QString &protocol, const QString &group, 
				  const QString &key)
{
   return manager(protocol)->entry(group, key);
}

void SlaveManagerGlobal::setEntry(const QString &protocol, const QString &group, 
				  const QString &key, const QString &value)
{
   manager(protocol)->setEntry(group, key, value);
}
      
void SlaveManagerGlobal::removeEntry(const QString &protocol, 
				     const QString &group, const QString &key)
{
   manager(protocol)->removeEntry(group, key);
}


["kiopatch" (text/plain)]

? 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 12:44:02
@@ -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 12:44:08
@@ -59,6 +59,7 @@ extern "C" {
 
 #include <kdirnotify_stub.h>
 
+
 using namespace KIO;
 template class QList<KIO::Job>;
 
@@ -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,29 @@ QWidget *Job::window() const
   return m_window;
 }
 
+
+SlaveManagerGlobal * SimpleJob::m_managerFactory = 0;
+
+SlaveManagerGlobal * SimpleJob::factoryInstance()
+{
+   if (m_managerFactory == 0)
+   {
+      KConfig *globalConfig = new KConfig("/tmp/kioconfig"); // define here the \
location for global config +      m_managerFactory = new \
SlaveManagerGlobal(globalConfig, 0); +      \
qAddPostRoutine(SimpleJob::cleanManagerInstance); +   }
+   return m_managerFactory;
+}
+
+void SimpleJob::cleanManagerInstance()
+{
+   delete m_managerFactory;
+}
+
 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())
     {
@@ -296,37 +324,8 @@ SimpleJob::~SimpleJob()
     }
 }
 
-void SimpleJob::start(Slave *slave)
+void SimpleJob::start(Slave *)
 {
-    m_slave = slave;
-
-    connect( m_slave, SIGNAL( error( int , const QString & ) ),
-             SLOT( slotError( int , const QString & ) ) );
-
-    connect( m_slave, SIGNAL( warning( const QString & ) ),
-             SLOT( slotWarning( const QString & ) ) );
-
-    connect( m_slave, SIGNAL( infoMessage( const QString & ) ),
-             SLOT( slotInfoMessage( const QString & ) ) );
-
-    connect( m_slave, SIGNAL( connected() ),
-             SLOT( slotConnected() ) );
-
-    connect( m_slave, SIGNAL( finished() ),
-             SLOT( slotFinished() ) );
-
-    connect( m_slave, SIGNAL( totalSize( unsigned long ) ),
-             SLOT( slotTotalSize( unsigned long ) ) );
-
-    connect( m_slave, SIGNAL( processedSize( unsigned long ) ),
-             SLOT( slotProcessedSize( unsigned long ) ) );
-
-    connect( m_slave, SIGNAL( speed( unsigned long ) ),
-             SLOT( slotSpeed( unsigned long ) ) );
-
-    connect( slave, SIGNAL( needProgressId() ),
-             SLOT( slotNeedProgressId() ) );
-
     if (!m_subUrl.isEmpty())
     {
        KIO_ARGS << m_subUrl;
@@ -342,6 +341,73 @@ void SimpleJob::slaveDone()
    disconnect(m_slave); // Remove all signals between slave and job
    Scheduler::jobFinished( this, m_slave );
    m_slave = 0;
+}
+
+void SimpleJob::connectToSlave(Slave *slave)
+{
+   //FIXME when this function will become virtual, move all connect ops 
+   // of derived classes from start methods to connectToSlave.
+   // For now this is an hack, because after a connectToSlave, the job-slave
+   // connection isn't complete.
+   m_slave = slave;
+   
+   connect( m_slave, SIGNAL( error( int , const QString & ) ),
+	    SLOT( slotError( int , const QString & ) ) );
+   
+   connect( m_slave, SIGNAL( warning( const QString & ) ),
+	    SLOT( slotWarning( const QString & ) ) );
+   
+   connect( m_slave, SIGNAL( infoMessage( const QString & ) ),
+	    SLOT( slotInfoMessage( const QString & ) ) );
+
+   connect( m_slave, SIGNAL( connected() ),
+	    SLOT( slotConnected() ) );
+
+   connect( m_slave, SIGNAL( finished() ),
+	    SLOT( slotFinished() ) );
+   
+   connect( m_slave, SIGNAL( totalSize( unsigned long ) ),
+	    SLOT( slotTotalSize( unsigned long ) ) );
+
+   connect( m_slave, SIGNAL( processedSize( unsigned long ) ),
+	    SLOT( slotProcessedSize( unsigned long ) ) );
+
+   connect( m_slave, SIGNAL( speed( unsigned long ) ),
+	    SLOT( slotSpeed( unsigned long ) ) );
+
+   connect( slave, SIGNAL( needProgressId() ),
+	    SLOT( slotNeedProgressId() ) );
+
+   connect( slave, SIGNAL( needConfiguration( const KIO::MetaData& ) ),
+	    SLOT( slotSlaveNeedConfiguration( const KIO::MetaData& ) ) );
+}
+
+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: slave " << m_slave << " \
group " << data["Group"] << 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 = factoryInstance()->manager(proto);
+      QString grp = data["Group"];
+      mngr->setEntry(grp, "dummy1", QString::number((int)this));
+      mngr->setEntry(grp, "dummy2", name());
+      sendConfiguration(mngr->data(grp));
+   }
 }
 
 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 12:44:11
@@ -35,6 +35,8 @@
 
 #include <kio/global.h>
 
+#include <kio/slavemanager.h>
+
 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 KIO::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,32 @@ 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 &);
+
+       /**
+	* Connect job to slave.
+	* There's a need to distinguish between start op and connect op, since 
+	* some operations have to be done after a slave-job connection has been
+	* established, but before the job is started
+	*/
+       void connectToSlave(Slave *slave);
+
+        /**
+	 * Global factory instance for manager's managements
+	 */
+        static SlaveManagerGlobal * factoryInstance();
+        /**
+	 * Routine to clean factory's instance
+	 */
+        static void cleanManagerInstance();
+
     protected slots:
         /**
          * Called when the slave marks the job
@@ -351,6 +390,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 +420,10 @@ namespace KIO {
         KURL m_subUrl;
         int m_command;
         unsigned long m_totalSize;
+        bool m_configurationSent;
+
+    private:
+       static SlaveManagerGlobal *m_managerFactory;
     };
 
     // Stat Job
Index: scheduler.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/scheduler.cpp,v
retrieving revision 1.54
diff -u -3 -p -r1.54 scheduler.cpp
--- scheduler.cpp	2001/03/25 21:08:10	1.54
+++ scheduler.cpp	2001/03/30 12:44:13
@@ -294,6 +294,21 @@ bool Scheduler::startJobScheduled(Protoc
     protInfo->joblist.removeRef(job);
 //       kdDebug(7006) << "scheduler: job started " << job << endl;
 
+    job->connectToSlave(slave);
+
+    if (newSlave)
+    {
+       // retrieve "init" group config
+       MetaData m;
+       m.insert("Group", "init");
+       slave->emitNeedConfiguration(m);
+    }
+
+    // retrieve "start" group config
+    MetaData m;
+    m.insert("Group", "start");
+    slave->emitNeedConfiguration(m);
+
     KURL url =job->url();
     QString host = url.host();
     int port = url.port();
@@ -338,6 +353,21 @@ bool Scheduler::startJobDirect()
 
     idleSlaves->removeRef(slave);
 //       kdDebug(7006) << "scheduler: job started " << job << endl;
+
+    job->connectToSlave(slave);
+
+    if (newSlave)
+    {
+       // retrieve "init" group config
+       MetaData m;
+       m.insert("Group", "init");
+       slave->emitNeedConfiguration(m);
+    }
+
+    // retrieve "start" group config
+    MetaData m;
+    m.insert("Group", "start");
+    slave->emitNeedConfiguration(m);
 
     KURL url =job->url();
     QString host = url.host();
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 12:44:15
@@ -59,6 +59,7 @@ namespace KIO {
 class SlaveBasePrivate {
 public:
     QString slaveid;
+    MetaData configuration;
     bool resume:1;
     bool needSendCanResume:1;
 };
@@ -93,6 +94,8 @@ SlaveBase::SlaveBase( const QCString &pr
     d->slaveid += QString::number(getpid());
     d->resume = false;
     d->needSendCanResume = false;
+    // set initial configuration
+    //d->configuration = ???;
 }
 
 SlaveBase::~SlaveBase()
@@ -246,6 +249,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 +320,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 +469,22 @@ 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;
+   QString msg;
+   for (MetaData::ConstIterator it = d->configuration.begin(); it != \
d->configuration.end(); ++it) +      msg += it.key() + ": " + it.data() + ", ";
+   kdDebug(7019) << "Cfg = " << msg << endl;
+}
+
+const MetaData & SlaveBase::configuration() const
+{
+   return d->configuration;
+}
+
 void SlaveBase::openConnection(void)
 { error(  ERR_UNSUPPORTED_ACTION, "open" ); }
 void SlaveBase::closeConnection(void)
@@ -494,6 +521,9 @@ void SlaveBase::slave_status()
 
 void SlaveBase::reparseConfiguration()
 {
+    // fill with infos for job
+    MetaData data;
+    needConfiguration(data);
 }
 
 bool SlaveBase::dispatch()
@@ -640,9 +670,16 @@ void SlaveBase::dispatch( int command, c
         slave_status();
         break;
     case CMD_REPARSECONFIGURATION:
-        KProtocolManager::reparseConfiguration();
+        KProtocolManager::reparseConfiguration();//FIXME to remove
         reparseConfiguration();
 	break;
+    case CMD_CONFIG: {
+        kdDebug(7019) << "received CMD_CONFIG" << endl;
+        MetaData meta_data;
+        stream >> meta_data;
+	setConfiguration(meta_data);
+	break;
+    }
     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 12:44:17
@@ -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
+     */
+    const 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 12:44:18
@@ -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: {
+        MetaData meta_data;
+        stream >> meta_data;
+	kdDebug(7007) << "emit needConfiguration for group " << meta_data["Group"] << endl;
+        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 12:44:18
@@ -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,17 @@ public:
     // (to tell the "put" job whether to resume or not)
     void sendResumeAnswer( bool resume );
 
+    /**
+     * Send configuration to slave
+     */
+   void sendConfiguration(const MetaData &);
+
+   /**
+    * Emit a needConfiguration signal, called from scheduler for "init" 
+    * and "start" groups.
+    */
+   void emitNeedConfiguration(const MetaData &d) { emit needConfiguration(d); }
+
 signals:
     ///////////
     // Messages sent by the slave
@@ -154,6 +167,7 @@ signals:
     void statEntry( const KIO::UDSEntry& );
     void needSubURLData();
     void needProgressId();
+    void needConfiguration(const KIO::MetaData &);
 
     void canResume( unsigned long ) ;
 


>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic