|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.kde.koala.SlaveBase
public class SlaveBase
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.
Constructor Summary | |
---|---|
protected |
SlaveBase(java.lang.Class dummy)
|
Method Summary | |
---|---|
void |
canResume()
|
boolean |
canResume(long offset)
Call this at the beginning of put(), to give the size of the existing partial file, if there is one. |
void |
chmod(KURL url,
int permissions)
Change permissions on path
The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHMOD |
void |
closeConnection()
Closes the connection (forced) Called when the application disconnects the slave to close any open network connections. |
KConfigBase |
config()
Returns a configuration object to query config/meta-data information from. |
void |
connected()
Call in openConnection, if you reimplement it, when you're done. |
Connection |
connection()
|
void |
connectSlave(java.lang.String path)
internal function to connect a slave to/ disconnect from either the slave pool or the application |
int |
connectTimeout()
|
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. |
void |
data(byte[] data)
Sends data in the slave to the job (i.e. |
void |
dataReq()
Asks for data from the job. |
DCOPClient |
dcopClient()
Return the dcop client used by this slave. |
void |
del(KURL url,
boolean isfile)
Delete a file or directory. |
void |
disconnectSlave()
|
boolean |
dispatch()
|
void |
dispatch(int command,
byte[] data)
|
void |
dispatchLoop()
|
void |
dropNetwork()
|
void |
dropNetwork(java.lang.String host)
Used by the slave to withdraw a connection requested by requestNetwork. |
void |
error(int _errid,
java.lang.String _text)
Call to signal an error. |
void |
errorPage()
Tell that we will only get an error page here. |
void |
exit()
Terminate the slave by calling the destructor and then .exit() |
void |
finished()
Call to signal successful completion of any command (besides openConnection and closeConnection) |
void |
get(KURL url)
get, aka read. |
boolean |
hasMetaData(java.lang.String key)
Queries for the existence of a certain config/meta-data entry send by the application to the slave. |
void |
infoMessage(java.lang.String msg)
Call to signal a message, to be displayed if the application wants to, for instance in a status bar. |
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. |
java.lang.String |
metaData(java.lang.String key)
Queries for config/meta-data send by the application to the slave. |
void |
mimetype(KURL url)
Finds mimetype for one file or directory. |
void |
mimeType(java.lang.String _type)
Call this in mimetype() and in get(), when you know the mimetype. |
void |
mkdir(KURL url,
int permissions)
Create a directory |
void |
multiGet(byte[] data)
Used for multiple get. |
void |
needSubURLData()
Call to signal that data from the sub-URL is needed |
void |
openConnection()
Opens the connection (forced) When this function gets called the slave is operating in connection-oriented mode. |
boolean |
openPassDlg(AuthInfo info)
Same as above function except it does not need error message. |
boolean |
openPassDlg(AuthInfo info,
java.lang.String errorMsg)
Prompt the user for Authorization info (login & password). |
void |
processedPercent(float percent)
Only use this if you can't know in advance the size of the copied data. |
void |
processedSize(long _bytes)
Call this during get and copy, once in a while, to give some info about the current state. |
int |
proxyConnectTimeout()
|
void |
put(KURL url,
int permissions,
boolean overwrite,
boolean resume)
put, aka write. |
int |
readData(byte[] buffer)
Read data send by the job, after a dataReq |
int |
readTimeout()
|
void |
redirection(KURL _url)
Call this to signal a redirection The job will take care of going to that url. |
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. |
void |
reparseConfiguration()
Called by the scheduler to tell the slave that the configuration changed (i.e. |
boolean |
requestNetwork()
|
boolean |
requestNetwork(java.lang.String host)
Used by the slave to check if it can connect to a given host. |
int |
responseTimeout()
|
void |
sendMetaData()
Internal function to transmit meta data to the application. |
void |
setConnection(Connection connection)
|
void |
setHost(java.lang.String host,
int port,
java.lang.String user,
java.lang.String pass)
Set the host |
void |
setKillFlag()
Internally used. |
void |
setMetaData(java.lang.String key,
java.lang.String value)
Sets meta-data to be send to the application before the first data() or finished() signal. |
void |
setSubURL(KURL url)
Prepare slave for streaming operation |
void |
setTimeoutSpecialCommand(int timeout)
|
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. |
static void |
sigpipe_handler(int arg1)
|
static void |
sigsegv_handler(int arg1)
|
void |
slave_status()
Called to get the status of the slave. |
void |
slaveStatus(java.lang.String host,
boolean connected)
Used to report the status of the slave. |
void |
special(byte[] data)
Used for any command that is specific to this slave (protocol) Examples are : HTTP POST, mount and unmount (kio_file) |
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) |
void |
stat(KURL url)
Finds all details for one file or directory. |
void |
symlink(java.lang.String target,
KURL dest,
boolean overwrite)
Creates a symbolic link named dest , pointing to target , which
may be a relative or an absolute path. |
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. |
int |
waitForAnswer(int expected1,
int expected2,
byte[] data)
|
int |
waitForAnswer(int expected1,
int expected2,
byte[] data,
int[] pCmd)
Wait for an answer to our request, until we get expected1 or expected2 |
void |
warning(java.lang.String msg)
Call to signal a warning, to be displayed in a dialog box. |
boolean |
wasKilled()
If your ioslave was killed by a signal, wasKilled() returns true. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected SlaveBase(java.lang.Class dummy)
Method Detail |
---|
public void exit()
public void dispatchLoop()
public void setConnection(Connection connection)
public Connection connection()
public void data(byte[] data)
data
- the data read by the slavepublic void dataReq()
readData(byte[])
public void error(int _errid, java.lang.String _text)
_errid
- the error code from KIO.Error_text
- the rich text error messageError
,
KTextBrowser
public void connected()
public void finished()
public void needSubURLData()
public void slaveStatus(java.lang.String host, boolean connected)
host
- the slave is currently connected to. (Should be
empty if not connected)connected
- Whether an actual network connection exists.public boolean canResume(long offset)
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)
public void canResume()
public void totalSize(long _bytes)
public void processedSize(long _bytes)
public void processedPercent(float percent)
public void speed(long _bytes_per_second)
public void redirection(KURL _url)
public void errorPage()
public void mimeType(java.lang.String _type)
public void warning(java.lang.String msg)
public void infoMessage(java.lang.String msg)
public void setMetaData(java.lang.String key, java.lang.String value)
public boolean hasMetaData(java.lang.String key)
public java.lang.String metaData(java.lang.String key)
public KConfigBase config()
public void setHost(java.lang.String host, int port, java.lang.String user, java.lang.String pass)
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.public void setSubURL(KURL url)
public void openConnection()
public void closeConnection()
public void get(KURL url)
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 datapublic void put(KURL url, int permissions, boolean overwrite, boolean resume)
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.public void stat(KURL url)
public void mimetype(KURL url)
public void listDir(KURL url)
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.
public void mkdir(KURL url, int permissions)
url
- path to the directory to createpermissions
- the permissions to set after creating the directory
(-1 if no permissions to be set)
The slave emits ERR_COULD_NOT_MKDIR if failure.public void rename(KURL src, KURL dest, boolean overwrite)
oldname
into newname.
If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will
ask for copy + del instead.
src
- where to move the file fromdest
- where to move the file tooverwrite
- if true, any existing file will be overwrittenpublic void symlink(java.lang.String target, KURL dest, boolean overwrite)
dest
, pointing to target
, which
may be a relative or an absolute path.
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 existspublic void chmod(KURL url, int permissions)
path
The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHMOD
public void copy(KURL src, KURL dest, int permissions, boolean overwrite)
src
into dest.
If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will
ask for get + put instead.
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 overwrittenpublic void del(KURL url, boolean isfile)
url
- file/directory to deleteisfile
- if true, a file should be deleted.
if false, a directory should be deleted.public void special(byte[] data)
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.public void multiGet(byte[] data)
data
- packed data; Contains number of URLs to fetch, and for
each URL the URL itself and its associated MetaData.public void slave_status()
public void reparseConfiguration()
public int connectTimeout()
public int proxyConnectTimeout()
public int responseTimeout()
public int readTimeout()
public void setTimeoutSpecialCommand(int timeout, byte[] data)
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.
public void setTimeoutSpecialCommand(int timeout)
public boolean dispatch()
public void dispatch(int command, byte[] data)
public int readData(byte[] buffer)
buffer
- buffer where data is stored
public void connectSlave(java.lang.String path)
public void disconnectSlave()
public boolean openPassDlg(AuthInfo info, java.lang.String errorMsg)
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.
info
- See AuthInfo.errorMsg
- Error message to show
true
if user clicks on "OK", false
otherwsie.#checkCachedAuthentication
public boolean openPassDlg(AuthInfo info)
public boolean requestNetwork(java.lang.String host)
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)
public boolean requestNetwork()
public void dropNetwork(java.lang.String host)
host
- the host passed to requestNetwork
A slave should call this function every time it disconnect from a host.public void dropNetwork()
public DCOPClient dcopClient()
public int waitForAnswer(int expected1, int expected2, byte[] data, int[] pCmd)
expected1
or expected2
data
public int waitForAnswer(int expected1, int expected2, byte[] data)
public void sendMetaData()
public boolean wasKilled()
public void setKillFlag()
public static void sigsegv_handler(int arg1)
public static void sigpipe_handler(int arg1)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |