KIO::Slave is inextensible!

Leo Savernik l.savernik at aon.at
Wed Feb 5 11:59:52 GMT 2003


Hello,

In an attempt to create a highly optimized KIO::Slave for data urls that 
avoids the need to spawn an own kioslave process, I hit the following 
problems:

	KIO::Slave *KIO::Slave::createSlave(...)
	KIO::Slave *KIO::Slave::holdSlave(...)

Those return a Slave and not a SlaveInterface, so I *must* derive from Slave 
at any rate, leading to another, really grave problem:

	KIO::Connection *KIO::Slave::connection() { return &slaveconn; }

While SlaveInterface also defines this method and returns a pointer to some 
dynamically allocated Connection object, KIO::Slave::connection() returns an 
embedded object. That wouldn't be troublesome if this getter method weren't 
inline. So it's *impossible* to hook in an alternative Connection object for 
a Slave-derived class, but I need this badly.

Possible solutions:
- simplest solution: ditch KIO::Slave::connection() and let 
KIO::SlaveInterface::connection() do the work. However, it's BIC.
- alternative solution: have KIO::Slave::createSlave(...) and 
KIO::Slave::holdSlave(...) return SlaveInterface instead of Slave. But it's 
also BIC and there's certainly a good reason why they return a Slave object.
- utmost ugliest solution: Giving KIO::Connection a hint to morph itself into 
another class and then pass through the parameters to the effective object in 
every method. Illustration:
void Connection::setSpecial(Connection *effective_connection) {
  reinterpret_cast<Connection *>(d) = effective_connection;
}

and passing through would look like (done for every other method):
void Connection::init(KSocket *sock)
{
  if (d) {
    reinterpret_cast<Connection *>(d)->init(sock); return;
  }
  delete notifier;
  ...
}

Yes, it's butt ugly, but BC.

If anybody knows better solutions please tell me. If this is too complicated 
for KDE 3 to implement, I opt for removal of the offending 
Slave::connection() method for KDE 4.

mfg
	Leo





More information about the kfm-devel mailing list