#include <inbandbytestreammanager.h>
Inherits IqHandler.
Inheritance diagram for InBandBytestreamManager:
Public Member Functions | |
InBandBytestreamManager (ClientBase *parent, Disco *disco) | |
virtual | ~InBandBytestreamManager () |
bool | requestInBandBytestream (const JID &to, InBandBytestreamHandler *ibbh) |
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) |
class MyClass : public InBandBytestreamHandler { ... private: InBandBytestreamManager *m_ibbManager; ... };
Create a new InBandBytestreamManager and request a new bytestream:
MyClass::MyClass() { m_ibbManager = new InBandBytestreamManager( m_client, m_client->disco() ); } void MyClass::myFunc() { JID jid( "entity@server/resource" ); m_ibbManager->requestInBandBytestream( jid, this ); }
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.
void MyClass::handleOutgoingInBandBytestream( const JID& to, InBandBytestream *ibb ) { MessageSessionList::iterator it = m_messageSessions.find( to.full() ); if( it != m_messageSessions.end() ) { ibb->attachTo( (*it).second ); } else { MessageSession *session = new MessageSession( m_client, to ); ibb->attachTo( session ); m_messageSessions[to.full()] = session; } m_ibbs[to.full()] = ibb; }
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.
m_ibbManager->registerInBandBytestreamHandler( this );
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.
bool MyClass::handleIncomingInBandBytestream( const JID& from, InBandBytestream *ibb ) { // Check whether you want to accept the bytestream // add an InBandBytestreamDataHandler ibb->registerInBandBytestreamDataHandler( this ); // The rest of this function probaly looks similar to the implementation of // handleOutgoingInBandBytestream() above. // You should *not* start to send blocks of data from within this // function, though. // return true to accept the bytestream, false to reject it return true; }
void MyClass::mainloop() { if( m_client->connect(false) ) { ConnectionError ce = ConnNoError; while( ce == ConnNoError ) { ce = m_client->recv(); sendIBBData(); } printf( "disconnected. reason: %d\n", ce ); } }
In sendIBBData() you would then iterate over your bytestreams and send a block of data where appropriate.
void MyClass::sendIBBData() { IBBList::iterator it = m_ibbs.begin(); for( ; it != m_ibbs.end(); ++it ) { (*it).second->sendBlock( "some data" ); } }
m_ibbManager->dispose( ibb ); ibb = 0;
In the excerpts above, only one bytestream per remote entity is possible (without leaking). However, gloox in general does not impose such a limitation, nor does the In-Band Bytestreams specification.
Definition at line 177 of file inbandbytestreammanager.h.
InBandBytestreamManager | ( | ClientBase * | parent, | |
Disco * | disco | |||
) |
Constructs a new InBandBytestreamManager.
parent | The ClientBase to use for sending data. | |
disco | The Disco object to announce the IBB feature with. |
Definition at line 22 of file inbandbytestreammanager.cpp.
~InBandBytestreamManager | ( | ) | [virtual] |
Virtual destructor.
Definition at line 33 of file inbandbytestreammanager.cpp.
bool requestInBandBytestream | ( | const JID & | to, | |
InBandBytestreamHandler * | ibbh | |||
) |
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. |
Definition at line 46 of file inbandbytestreammanager.cpp.
void setBlockSize | ( | int | blockSize | ) | [inline] |
Sets the default block-size. Default: 4096
blockSize | The default block-size in byte. |
Definition at line 210 of file inbandbytestreammanager.h.
int blockSize | ( | ) | const [inline] |
Returns the currently set block-size.
Definition at line 216 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 220 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 129 of file inbandbytestreammanager.cpp.
Referenced by InBandBytestreamManager::handleIq().
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 142 of file inbandbytestreammanager.cpp.
Referenced by InBandBytestreamManager::handleIq().
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 233 of file inbandbytestreammanager.cpp.
void removeInBandBytestreamHandler | ( | ) |
Removes the registered InBandBytestreamHandler.
Definition at line 240 of file inbandbytestreammanager.cpp.
bool handleIq | ( | Stanza * | stanza | ) | [virtual] |
Reimplement this function if you want to be notified about incoming IQs.
stanza | The complete Stanza. |
Implements IqHandler.
Definition at line 72 of file inbandbytestreammanager.cpp.
bool handleIqID | ( | Stanza * | stanza, | |
int | context | |||
) | [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 182 of file inbandbytestreammanager.cpp.