#include <inbandbytestreammanager.h>
Inherits IqHandler.
Inheritance diagram for InBandBytestreamManager:


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) |
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 );
}
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 179 of file inbandbytestreammanager.h.
|
|
Constructs a new InBandBytestreamManager.
Definition at line 23 of file inbandbytestreammanager.cpp. |
|
|
Virtual destructor. Definition at line 34 of file inbandbytestreammanager.cpp. |
|
|
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.
Definition at line 134 of file inbandbytestreammanager.cpp. |
|
|
Returns the currently set block-size.
Definition at line 221 of file inbandbytestreammanager.h. |
|
|
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.
Definition at line 225 of file inbandbytestreammanager.cpp. |
|
|
Reimplement this function if you want to be notified about incoming IQs.
Implements IqHandler. Definition at line 77 of file inbandbytestreammanager.cpp. |
|
||||||||||||
|
Reimplement this function if you want to be notified about incoming IQs with a specific value of the
Implements IqHandler. Definition at line 187 of file inbandbytestreammanager.cpp. |
|
||||||||||||
|
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.
Definition at line 238 of file inbandbytestreammanager.cpp. |
|
|
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.
Definition at line 147 of file inbandbytestreammanager.cpp. |
|
|
Removes the registered InBandBytestreamHandler. Definition at line 245 of file inbandbytestreammanager.cpp. |
|
||||||||||||||||
|
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.
Definition at line 50 of file inbandbytestreammanager.cpp. |
|
|
Sets the default block-size. Default: 4096
Definition at line 215 of file inbandbytestreammanager.h. |
1.4.1