org.kde.koala

Class SlaveBase

public class SlaveBase extends Object implements QtSupport

There are two classes that specifies the protocol between application (job) and kioslave. SlaveInterface is the class to use on the application end, SlaveBase is the one to use on the slave end. Slave implementations should simply inherit SlaveBase A call to foo() results in a call to slotFoo() on the other end.

UNKNOWN: There are two classes that specifies the protocol between application (job) and kioslave.

Constructor Summary
protected SlaveBase(Class dummy)
Method Summary
booleancanResume(long offset)
Call this at the beginning of put(), to give the size of the existing partial file, if there is one.
voidcanResume()
voidchmod(KURL url, int permissions)
Change permissions on path The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHMOD
voidcloseConnection()
Closes the connection (forced) Called when the application disconnects the slave to close any open network connections.
KConfigBaseconfig()
Returns a configuration object to query config/meta-data information from.
voidconnected()
Call in openConnection, if you reimplement it, when you're done.
Connectionconnection()
voidconnectSlave(String path)
internal function to connect a slave to/ disconnect from either the slave pool or the application
intconnectTimeout()
voidcopy(KURL src, KURL dest, int permissions, boolean overwrite)
Copy src into dest. If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will ask for get + put instead.
voiddata(byte[] data)
Sends data in the slave to the job (i.e. in get).
voiddataReq()
Asks for data from the job.
DCOPClientdcopClient()
Return the dcop client used by this slave.
voiddel(KURL url, boolean isfile)
Delete a file or directory.
voiddisconnectSlave()
booleandispatch()
voiddispatch(int command, byte[] data)
voiddispatchLoop()
voiddropNetwork(String host)
Used by the slave to withdraw a connection requested by requestNetwork.
voiddropNetwork()
voiderror(int _errid, String _text)
Call to signal an error.
voiderrorPage()
Tell that we will only get an error page here.
voidexit()
Terminate the slave by calling the destructor and then .exit()
voidfinished()
Call to signal successful completion of any command (besides openConnection and closeConnection)
voidget(KURL url)
get, aka read.
booleanhasMetaData(String key)
Queries for the existence of a certain config/meta-data entry send by the application to the slave.
voidinfoMessage(String msg)
Call to signal a message, to be displayed if the application wants to, for instance in a status bar.
voidlistDir(KURL url)
Lists the contents of url. The slave should emit ERR_CANNOT_ENTER_DIRECTORY if it doesn't exist, if we don't have enough permissions, or if it is a file It should also emit totalFiles as soon as it knows how many files it will list.
StringmetaData(String key)
Queries for config/meta-data send by the application to the slave.
voidmimetype(KURL url)
Finds mimetype for one file or directory.
voidmimeType(String _type)
Call this in mimetype() and in get(), when you know the mimetype.
voidmkdir(KURL url, int permissions)
Create a directory
voidmultiGet(byte[] data)
Used for multiple get.
voidneedSubURLData()
Call to signal that data from the sub-URL is needed
voidopenConnection()
Opens the connection (forced) When this function gets called the slave is operating in connection-oriented mode.
booleanopenPassDlg(AuthInfo info, String errorMsg)
Prompt the user for Authorization info (login & password).
booleanopenPassDlg(AuthInfo info)
Same as above function except it does not need error message.
voidprocessedPercent(float percent)
Only use this if you can't know in advance the size of the copied data.
voidprocessedSize(long _bytes)
Call this during get and copy, once in a while, to give some info about the current state.
intproxyConnectTimeout()
voidput(KURL url, int permissions, boolean overwrite, boolean resume)
put, aka write.
intreadData(byte[] buffer)
Read data send by the job, after a dataReq
intreadTimeout()
voidredirection(KURL _url)
Call this to signal a redirection The job will take care of going to that url.
voidrename(KURL src, KURL dest, boolean overwrite)
Rename oldname into newname. If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will ask for copy + del instead.
voidreparseConfiguration()
Called by the scheduler to tell the slave that the configuration changed (i.e. proxy settings) .
booleanrequestNetwork(String host)
Used by the slave to check if it can connect to a given host.
booleanrequestNetwork()
intresponseTimeout()
voidsendMetaData()
Internal function to transmit meta data to the application.
voidsetConnection(Connection connection)
voidsetHost(String host, int port, String user, String pass)
Set the host
voidsetKillFlag()
Internally used.
voidsetMetaData(String key, String value)
Sets meta-data to be send to the application before the first data() or finished() signal.
voidsetSubURL(KURL url)
Prepare slave for streaming operation
voidsetTimeoutSpecialCommand(int timeout, byte[] data)
This function sets a timeout of timeout seconds and calls special(data) when the timeout occurs as if it was called by the application.
voidsetTimeoutSpecialCommand(int timeout)
static voidsigpipe_handler(int arg1)
static voidsigsegv_handler(int arg1)
voidslaveStatus(String host, boolean connected)
Used to report the status of the slave.
voidslave_status()
Called to get the status of the slave.
voidspecial(byte[] data)
Used for any command that is specific to this slave (protocol) Examples are : HTTP POST, mount and unmount (kio_file)
voidspeed(long _bytes_per_second)
Call this in get and copy, to give the current transfer speed, but only if it can't be calculated out of the size you passed to processedSize (in most cases you don't want to call it)
voidstat(KURL url)
Finds all details for one file or directory.
voidsymlink(String target, KURL dest, boolean overwrite)
Creates a symbolic link named dest, pointing to target, which may be a relative or an absolute path.
voidtotalSize(long _bytes)
Call this in get and copy, to give the total size of the file Call in listDir too, when you know the total number of items.
intwaitForAnswer(int expected1, int expected2, byte[] data, int[] pCmd)
Wait for an answer to our request, until we get expected1 or expected2
intwaitForAnswer(int expected1, int expected2, byte[] data)
voidwarning(String msg)
Call to signal a warning, to be displayed in a dialog box.
booleanwasKilled()
If your ioslave was killed by a signal, wasKilled() returns true.

Constructor Detail

SlaveBase

protected SlaveBase(Class dummy)

Method Detail

canResume

public boolean canResume(long offset)
Call this at the beginning of put(), to give the size of the existing partial file, if there is one. The offset argument notifies the other job (the one that gets the data) about the offset to use. In this case, the booleanean returns whether we can indeed resume or not (we can't if the protocol doing the get() doesn't support setting an offset)

UNKNOWN: Call this at the beginning of put(), to give the size of the existing partial file, if there is one.

canResume

public void canResume()

chmod

public void chmod(KURL url, int permissions)
Change permissions on path The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHMOD

UNKNOWN: Change permissions on path The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHMOD

closeConnection

public void closeConnection()
Closes the connection (forced) Called when the application disconnects the slave to close any open network connections. When the slave was operating in connection-oriented mode, it should reset itself to connectionless (default) mode.

UNKNOWN: Closes the connection (forced) Called when the application disconnects the slave to close any open network connections.

config

public KConfigBase config()
Returns a configuration object to query config/meta-data information from. The application provides the slave with all configuration information relevant for the current protocol and host.

UNKNOWN: Returns a configuration object to query config/meta-data information from.

connected

public void connected()
Call in openConnection, if you reimplement it, when you're done.

UNKNOWN: Call in openConnection, if you reimplement it, when you're done.

connection

public Connection connection()

UNKNOWN:

connectSlave

public void connectSlave(String path)
internal function to connect a slave to/ disconnect from either the slave pool or the application

UNKNOWN: internal function to connect a slave to/ disconnect from either the slave pool or the application

connectTimeout

public int connectTimeout()

Returns: timeout value for connecting to remote host.

UNKNOWN:

copy

public void copy(KURL src, KURL dest, int permissions, boolean overwrite)
Copy src into dest. If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will ask for get + put instead.

Parameters: src where to copy the file from (decoded) dest where to copy the file to (decoded) permissions may be -1. In this case no special permission mode is set. overwrite if true, any existing file will be overwritten

UNKNOWN: Copy src into dest.

data

public void data(byte[] data)
Sends data in the slave to the job (i.e. in get). To signal end of data, simply send an empty byte[]().

Parameters: data the data read by the slave

UNKNOWN: Sends data in the slave to the job (i.

dataReq

public void dataReq()
Asks for data from the job.

See Also: SlaveBase

UNKNOWN: Asks for data from the job.

dcopClient

public DCOPClient dcopClient()
Return the dcop client used by this slave.

UNKNOWN: Return the dcop client used by this slave.

del

public void del(KURL url, boolean isfile)
Delete a file or directory.

Parameters: url file/directory to delete isfile if true, a file should be deleted. if false, a directory should be deleted.

UNKNOWN: Delete a file or directory.

disconnectSlave

public void disconnectSlave()

dispatch

public boolean dispatch()

UNKNOWN:

dispatch

public void dispatch(int command, byte[] data)

UNKNOWN:

dispatchLoop

public void dispatchLoop()

UNKNOWN:

dropNetwork

public void dropNetwork(String host)
Used by the slave to withdraw a connection requested by requestNetwork. This function cancels the last call to requestNetwork. If a client uses more than one internet connection, it must use dropNetwork(host) to stop each request. If KNetMgr is not running, then this is a no-op.

Parameters: host the host passed to requestNetwork A slave should call this function every time it disconnect from a host.

UNKNOWN: Used by the slave to withdraw a connection requested by requestNetwork.

dropNetwork

public void dropNetwork()

error

public void error(int _errid, String _text)
Call to signal an error. This also finishes the job, no need to call finished. If the Error code is KIO.ERR_SLAVE_DEFINED then the _text should contain the complete translated text of of the error message. This message will be displayed in an KTextBrowser which allows rich text complete with hyper links. Email links will call the default mailer, "exec:/command arg1 arg2" will be forked and all other links will call the default browser.

Parameters: _errid the error code from KIO.Error _text the rich text error message

See Also: Error KTextBrowser

UNKNOWN: Call to signal an error.

errorPage

public void errorPage()
Tell that we will only get an error page here. This means: the data you'll get isn't the data you requested, but an error page (usually HTML) that describes an error.

UNKNOWN: Tell that we will only get an error page here.

exit

public void exit()
Terminate the slave by calling the destructor and then .exit()

UNKNOWN:

finished

public void finished()
Call to signal successful completion of any command (besides openConnection and closeConnection)

UNKNOWN: Call to signal successful completion of any command (besides openConnection and closeConnection)

get

public void get(KURL url)
get, aka read.

Parameters: url the full url for this request. Host, port and user of the URL can be assumed to be the same as in the last setHost() call. The slave emits the data through data

UNKNOWN: get, aka read.

hasMetaData

public boolean hasMetaData(String key)
Queries for the existence of a certain config/meta-data entry send by the application to the slave.

UNKNOWN: Queries for the existence of a certain config/meta-data entry send by the application to the slave.

infoMessage

public void infoMessage(String msg)
Call to signal a message, to be displayed if the application wants to, for instance in a status bar. Usual examples are "connecting to host xyz", etc.

UNKNOWN: Call to signal a message, to be displayed if the application wants to, for instance in a status bar.

listDir

public void listDir(KURL url)
Lists the contents of url. The slave should emit ERR_CANNOT_ENTER_DIRECTORY if it doesn't exist, if we don't have enough permissions, or if it is a file It should also emit totalFiles as soon as it knows how many files it will list.

UNKNOWN: Lists the contents of url.

metaData

public String metaData(String key)
Queries for config/meta-data send by the application to the slave.

UNKNOWN: Queries for config/meta-data send by the application to the slave.

mimetype

public void mimetype(KURL url)
Finds mimetype for one file or directory. This method should either emit 'mimeType' or it should send a block of data big enough to be able to determine the mimetype. If the slave doesn't reimplement it, a get will be issued, i.e. the whole file will be downloaded before determining the mimetype on it - this is obviously not a good thing in most cases.

UNKNOWN: Finds mimetype for one file or directory.

mimeType

public void mimeType(String _type)
Call this in mimetype() and in get(), when you know the mimetype. See mimetype about other ways to implement it.

UNKNOWN: Call this in mimetype() and in get(), when you know the mimetype.

mkdir

public void mkdir(KURL url, int permissions)
Create a directory

Parameters: url path to the directory to create permissions the permissions to set after creating the directory (-1 if no permissions to be set) The slave emits ERR_COULD_NOT_MKDIR if failure.

UNKNOWN: Create a directory

multiGet

public void multiGet(byte[] data)
Used for multiple get. Currently only used foir HTTP pielining support.

Parameters: data packed data; Contains number of URLs to fetch, and for each URL the URL itself and its associated MetaData.

UNKNOWN: Used for multiple get.

needSubURLData

public void needSubURLData()
Call to signal that data from the sub-URL is needed

UNKNOWN: Call to signal that data from the sub-URL is needed

openConnection

public void openConnection()
Opens the connection (forced) When this function gets called the slave is operating in connection-oriented mode. When a connection gets lost while the slave operates in connection oriented mode, the slave should report ERR_CONNECTION_BROKEN instead of reconnecting. The user is expected to disconnect the slave in the error handler.

UNKNOWN: Opens the connection (forced) When this function gets called the slave is operating in connection-oriented mode.

openPassDlg

public boolean openPassDlg(AuthInfo info, String errorMsg)
Prompt the user for Authorization info (login & password). Use this function to request authorization information from the end user. You can also pass an error message which explains why a previous authorization attempt failed. Here is a very simple example:
		 KIO.AuthInfo authInfo;
		 if ( openPassDlg( authInfo ) )
		 {
		    kdDebug() << String.fromLatin1("User: ")
		              << authInfo.username << endl;
		    kdDebug() << String.fromLatin1("Password: ")
		              << String.fromLatin1("Not displayed here!") << endl;
		 }
		 
You can also preset some values like the username, caption or comment as follows:
		 KIO.AuthInfo authInfo;
		 authInfo.caption= "Acme Password Dialog";
		 authInfo.username= "Wile E. Coyote";
		 String errorMsg = "You entered an incorrect password.";
		 if ( openPassDlg( authInfo, errorMsg ) )
		 {
		    kdDebug() << String.fromLatin1("User: ")
		              << authInfo.username << endl;
		    kdDebug() << String.fromLatin1("Password: ")
		              << String.fromLatin1("Not displayed here!") << endl;
		 }
		 
Note:<> You should consider using checkCachedAuthentication() to see if the password is available in kpasswdserver before calling this function. Note:<> A call to this function can fail and return false, if the UIServer could not be started for whatever reason.

Parameters: info See AuthInfo. errorMsg Error message to show

Returns: true if user clicks on "OK", false otherwsie.

See Also: SlaveBase

UNKNOWN: Prompt the user for Authorization info (login & password).

openPassDlg

public boolean openPassDlg(AuthInfo info)
Same as above function except it does not need error message. BIC: Combine this function with the above for KDE4.

UNKNOWN: Same as above function except it does not need error message.

processedPercent

public void processedPercent(float percent)
Only use this if you can't know in advance the size of the copied data. For example, if you're doing variable bitrate compression of the source. STUB ! Currently unimplemented. Here now for binary compatibility. Call this during get and copy, once in a while, to give some info about the current state. Don't emit it in listDir, listEntries speaks for itself.

UNKNOWN: Only use this if you can't know in advance the size of the copied data.

processedSize

public void processedSize(long _bytes)
Call this during get and copy, once in a while, to give some info about the current state. Don't emit it in listDir, listEntries speaks for itself.

UNKNOWN: Call this during get and copy, once in a while, to give some info about the current state.

proxyConnectTimeout

public int proxyConnectTimeout()

Returns: timeout value for connecting to proxy in secs.

UNKNOWN:

put

public void put(KURL url, int permissions, boolean overwrite, boolean resume)
put, aka write.

Parameters: url where to write the file (decoded) permissions may be -1. In this case no special permission mode is set. overwrite if true, any existing file will be overwritten. If the file indeed already exists, the slave should NOT apply the permissions change to it. resume @short put, aka write.

readData

public int readData(byte[] buffer)
Read data send by the job, after a dataReq

Parameters: buffer buffer where data is stored

Returns: 0 on end of data, > 0 bytes read < 0 error

UNKNOWN: Read data send by the job, after a dataReq

readTimeout

public int readTimeout()

Returns: timeout value for read from subsequent data from remote host in secs.

UNKNOWN:

redirection

public void redirection(KURL _url)
Call this to signal a redirection The job will take care of going to that url.

UNKNOWN: Call this to signal a redirection The job will take care of going to that url.

rename

public void rename(KURL src, KURL dest, boolean overwrite)
Rename oldname into newname. If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will ask for copy + del instead.

Parameters: src where to move the file from dest where to move the file to overwrite if true, any existing file will be overwritten

UNKNOWN: Rename oldname into newname.

reparseConfiguration

public void reparseConfiguration()
Called by the scheduler to tell the slave that the configuration changed (i.e. proxy settings) .

UNKNOWN: Called by the scheduler to tell the slave that the configuration changed (i.

requestNetwork

public boolean requestNetwork(String host)
Used by the slave to check if it can connect to a given host. This should be called where the slave is ready to do a .connect() on a socket. For each call to requestNetwork must exist a matching call to dropNetwork, or the system will stay online until KNetMgr gets closed (or the SlaveBase gets destructed)! If KNetMgr is not running, then this is a no-op and returns true

Parameters: host tells the netmgr the host the slave wants to connect to. As this could also be a proxy, we can't just take the host currenctly connected to (but that's the default value)

Returns: true in theorie, the host is reachable false the system is offline and the host is in a remote network.

UNKNOWN: Used by the slave to check if it can connect to a given host.

requestNetwork

public boolean requestNetwork()

responseTimeout

public int responseTimeout()

Returns: timeout value for read from first data from remote host in seconds.

UNKNOWN:

sendMetaData

public void sendMetaData()
Internal function to transmit meta data to the application.

UNKNOWN: Internal function to transmit meta data to the application.

setConnection

public void setConnection(Connection connection)

UNKNOWN:

setHost

public void setHost(String host, int port, String user, String pass)
Set the host

Parameters: pass Called directly by createSlave, this is why there is no equivalent in SlaveInterface, unlike the other methods. This method is called whenever a change in host, port or user occurs.

UNKNOWN: Set the host

setKillFlag

public void setKillFlag()
Internally used.

UNKNOWN: Internally used.

setMetaData

public void setMetaData(String key, String value)
Sets meta-data to be send to the application before the first data() or finished() signal.

UNKNOWN: Sets meta-data to be send to the application before the first data() or finished() signal.

setSubURL

public void setSubURL(KURL url)
Prepare slave for streaming operation

UNKNOWN: Prepare slave for streaming operation

setTimeoutSpecialCommand

public void setTimeoutSpecialCommand(int timeout, byte[] data)
This function sets a timeout of timeout seconds and calls special(data) when the timeout occurs as if it was called by the application. A timeout can only occur when the slave is waiting for a command from the application. Specifying a negative timeout cancels a pending timeout. Only one timeout at a time is supported, setting a timeout cancels any pending timeout.

UNKNOWN: This function sets a timeout of timeout seconds and calls special(data) when the timeout occurs as if it was called by the application.

setTimeoutSpecialCommand

public void setTimeoutSpecialCommand(int timeout)

sigpipe_handler

public static void sigpipe_handler(int arg1)

UNKNOWN:

sigsegv_handler

public static void sigsegv_handler(int arg1)

UNKNOWN:

slaveStatus

public void slaveStatus(String host, boolean connected)
Used to report the status of the slave.

Parameters: host the slave is currently connected to. (Should be empty if not connected) connected Whether an actual network connection exists.

UNKNOWN: Used to report the status of the slave.

slave_status

public void slave_status()
Called to get the status of the slave. Slave should respond by calling slaveStatus(...)

UNKNOWN: Called to get the status of the slave.

special

public void special(byte[] data)
Used for any command that is specific to this slave (protocol) Examples are : HTTP POST, mount and unmount (kio_file)

Parameters: data packed data; the meaning is completely dependent on the slave, but usually starts with an int for the command number. Document your slave's commands, at least in its header file.

UNKNOWN: Used for any command that is specific to this slave (protocol) Examples are : HTTP POST, mount and unmount (kio_file)

speed

public void speed(long _bytes_per_second)
Call this in get and copy, to give the current transfer speed, but only if it can't be calculated out of the size you passed to processedSize (in most cases you don't want to call it)

UNKNOWN: Call this in get and copy, to give the current transfer speed, but only if it can't be calculated out of the size you passed to processedSize (in most cases you don't want to call it)

stat

public void stat(KURL url)
Finds all details for one file or directory. The information returned is the same as what listDir returns, but only for one file or directory.

UNKNOWN: Finds all details for one file or directory.

symlink

public void symlink(String target, KURL dest, boolean overwrite)
Creates a symbolic link named dest, pointing to target, which may be a relative or an absolute path.

Parameters: target The string that will become the "target" of the link (can be relative) dest The symlink to create. overwrite whether to automatically overwrite if the dest exists

UNKNOWN: Creates a symbolic link named dest, pointing to target, which may be a relative or an absolute path.

totalSize

public void totalSize(long _bytes)
Call this in get and copy, to give the total size of the file Call in listDir too, when you know the total number of items.

UNKNOWN: Call this in get and copy, to give the total size of the file Call in listDir too, when you know the total number of items.

waitForAnswer

public int waitForAnswer(int expected1, int expected2, byte[] data, int[] pCmd)
Wait for an answer to our request, until we get expected1 or expected2

Returns: the result from readData, as well as the cmd in *pCmd if set, and the data in data

UNKNOWN: Wait for an answer to our request, until we get expected1 or expected2

waitForAnswer

public int waitForAnswer(int expected1, int expected2, byte[] data)

warning

public void warning(String msg)
Call to signal a warning, to be displayed in a dialog box.

UNKNOWN: Call to signal a warning, to be displayed in a dialog box.

wasKilled

public boolean wasKilled()
If your ioslave was killed by a signal, wasKilled() returns true. Check it regularly in lengthy functions (e.g. in get();) and return as fast as possible from this function if wasKilled() returns true. This will ensure that your slave destructor will be called correctly.

UNKNOWN: If your ioslave was killed by a signal, wasKilled() returns true.