gloox
0.9.9.12
|
#include <inbandbytestreammanager.h>
Public Member Functions | |
GLOOX_DEPRECATED_CTOR | InBandBytestreamManager (ClientBase *parent) |
virtual | ~InBandBytestreamManager () |
bool | requestInBandBytestream (const JID &to, InBandBytestreamHandler *ibbh, const std::string &sid="") |
void | setBlockSize (int blockSize) |
int | blockSize () const |
bool | dispose (InBandBytestream *ibb) |
void | acceptInBandBytestream (InBandBytestream *ibb) |
void | rejectInBandBytestream (InBandBytestream *ibb) |
void | registerInBandBytestreamHandler (InBandBytestreamHandler *ibbh, bool sync=true) |
void | removeInBandBytestreamHandler () |
virtual bool | handleIq (Stanza *stanza) |
virtual bool | handleIqID (Stanza *stanza, int context) |
Public Member Functions inherited from IqHandler | |
virtual | ~IqHandler () |
An InBandBytestreamManager dispatches In-Band Bytestreams.
To initiate a new bytestream, you need an InBandBytestreamManager object. You will also need an InBandBytestreamHandler-derived object which will receive incoming and outgoing bytestreams (not the data but the InBandBytestream objects).
Create a new InBandBytestreamManager and request a new bytestream:
After the bytestream has been negotiated with the peer, InBandBytestreamHandler::handleOutgoingInBandBytestream() is called. Here you should attach the bytestream to a MessageSession associated with the remote entity. This is necessary since message stanzas are used for the actual data exchange and the MessageSession class offers a convenient interface to filter these out. In this example, there is a map of JID/MessageSession pairs and a map of JID/InBandBytestreams.
If you want to receive data from the bytestream (In-Band Bytestreams can be bi-directional), you have to register a InBandBytestreamDataHandler here, similar to the folowing example.
When sending data you should make sure you never try to send a block larger than the negotiated blocksize (which defaults to 4096 bytes). If a block is larger than this it will not be sent.
To receive a bytestream you need a InBandBytestreamManager, too, and you have to register an InBandBytestreamHandler which will receive the incoming bytestreams.
Upon an incoming request the InBandBytestreamManager notifies the registered InBandBytestreamHandler by calling handleIncomingInBandBytestream() . The return value of the handler determines whether the stream shall be accepted or not.
To actually send data, you should utilise some kind of mainloop integration that allows to call a function periodically. It is important to remember the following:
The following is an example of a primitive mainloop integration:
In sendIBBData() you would then iterate over your bytestreams and send a block of data where appropriate.
When you're done with a bytestream you can get rid of it by calling the dispose() function. The bytestream will be recycled and you should no longer use it.
Definition at line 179 of file inbandbytestreammanager.h.
InBandBytestreamManager | ( | ClientBase * | parent | ) |
Constructs a new InBandBytestreamManager.
parent | The ClientBase to use for sending data. |
Definition at line 23 of file inbandbytestreammanager.cpp.
|
virtual |
Virtual destructor.
Definition at line 34 of file inbandbytestreammanager.cpp.
void acceptInBandBytestream | ( | InBandBytestream * | ibb | ) |
When using asynchronous InBandBytestream notifications (if you used registerInBandBytestreamHandler() with a second argument of true) you have to call either this function or rejectInBandBytestream() after receiving an InBandBytestream from the InBandBytestreamHandler. Else the initiator will never know whether the request was actually received.
ibb | The InBandBytestream (as received from InBandBytestreamHandler) to accept. |
Definition at line 134 of file inbandbytestreammanager.cpp.
|
inline |
Returns the currently set block-size.
Definition at line 221 of file inbandbytestreammanager.h.
bool dispose | ( | InBandBytestream * | ibb | ) |
To get rid of a bytestream (i.e., close and delete it), call this function. You should not use the bytestream any more. The remote entity will be notified about the closing of the stream.
ibb | The bytestream to dispose. It will be deleted here. |
Definition at line 225 of file inbandbytestreammanager.cpp.
|
virtual |
Reimplement this function if you want to be notified about incoming IQs.
stanza | The complete Stanza. |
Implements IqHandler.
Definition at line 77 of file inbandbytestreammanager.cpp.
|
virtual |
Reimplement this function if you want to be notified about incoming IQs with a specific value of the id
attribute. You have to enable tracking of those IDs using Client::trackID(). This is usually useful for IDs that generate a positive reply, i.e. <iq type='result' id='reg'/> where a namespace filter wouldn't work.
stanza | The complete Stanza. |
context | A value to restore context, stored with ClientBase::trackID(). |
Implements IqHandler.
Definition at line 187 of file inbandbytestreammanager.cpp.
void registerInBandBytestreamHandler | ( | InBandBytestreamHandler * | ibbh, |
bool | sync = true |
||
) |
Use this function to register an object that will receive new incoming bytestream requests from the InBandBytestreamManager. Only one InBandBytestreamHandler can be registered at any one time.
ibbh | The InBandBytestreamHandler derived object to receive notifications. |
sync | Whether incoming bytestrams shall be announced syncronously. Default: true (syncronous) |
Definition at line 238 of file inbandbytestreammanager.cpp.
void rejectInBandBytestream | ( | InBandBytestream * | ibb | ) |
When using asynchronous InBandBytestream notifications (if you used registerInBandBytestreamHandler() with a second argument of true) you have to call either this function or acceptInBandBytestream() after receiving an InBandBytestream from the InBandBytestreamHandler. Else the initiator will never know whether the request was actually received.
ibb | The InBandBytestream (as received from InBandBytestreamHandler) to reject. |
Definition at line 147 of file inbandbytestreammanager.cpp.
void removeInBandBytestreamHandler | ( | ) |
Removes the registered InBandBytestreamHandler.
Definition at line 245 of file inbandbytestreammanager.cpp.
bool requestInBandBytestream | ( | const JID & | to, |
InBandBytestreamHandler * | ibbh, | ||
const std::string & | sid = "" |
||
) |
This function initiates opening of a bytestream with the MessageSession's remote entity. Data can only be sent over an open stream. Use isOpen() to find out what the stream's current state is. However, successful opening/initiation will be announced by means of the InBandBytestreamHandler interface. Multiple bytestreams (even per JID) can be initiated without waiting for success.
to | The recipient of the requested bytestream. |
ibbh | The InBandBytestreamHandler to send the new bytestream to. |
sid | The bytestream's stream ID, if previously negotiated e.g. using SI (XEP-0095). |
Definition at line 50 of file inbandbytestreammanager.cpp.
|
inline |
Sets the default block-size. Default: 4096
blockSize | The default block-size in byte. |
Definition at line 215 of file inbandbytestreammanager.h.