CHAPTER 4. DEVELOPING APPLICATIONS
4.8 MzCopChannel & MzCopEnvelope HOWTO
A. Overview
QCopChannel of Qt/Embedded enables asynchronous data exchanging,
however it can NOT be used in Qt/X11 environments.
Instead of QCopChannel, MIZI Prizm 2.0 provides a wrapper,
named MzCopChannel, to be used in X-window environment. Also MzCopEnvelope
class could be used to transfer data to MzCopChannel at ease.
Let's learn that how to use MzCopChannel and MzCopEnvelope
class in this section.
B. Example
Following is an example that explains about MzCopChannel and MzCopEnvelope.
#include <mzcopchannel.h>
#include <mzcopenvelope.h>
void Example::Example ()
{
cop = new MzCopChannel ("LINUETTE/Example");
connect (cop, SIGNAL (received (const QCString &, const QByteArray &)),
SLOT (message (const QCString &, const QByteArray &)));
}
void Example::sendData ()
{
MzCopEnvelope cop ("LINUETTE/Example", "sendData()");
cop << QCString ("string data");
}
void Example::message (const QCString &msg, const QByteArray &data)
{
QDataStream stream (data, IO_ReadOnly);
if (msg == "sendData()") {
QCString text;
stream >> text;
printf ("sendData(): %s\n", text.data ());
}
}
|
In the above example, the constructor connects an object to channel "LINUETTE/Example".
Then it calls connect() function for reading message from the channel through
the connection of MzCopChannel::received () and Example::message
().
Example::sendData () shows that transfers stream data via MzCopEnvelope.
The MzCopEnvelope can use all Qt supported stream since it
regards QDataStream as parent class.
The MzCopEnvelope starts to transfer data when destructor is
called, then transferred data to all applications which are connected to channel.
When a message is delivered to channel, then signal MzCopChannel::received
() will be generated.
In the example, Example::message () that is connected with
this signal will be called. The above sample shows how that function manipulate
data.
C. Class MzCopChannel
Followings are API of the class;
class MzCopChannel : public QObject
{
Q_OBJECT public: MzCopChannel( const QCString& channel, QObject* parent=0, const char* name=0 ); virtual ~MzCopChannel(); QCString channel() const;
static bool isRegistered( const QCString& channel ); static bool send( const QCString &channel, const QCString &msg ); static bool send( const QCString &channel, const QCString &msg, const QByteArray &data ); static void sendLocally( const QCString &ch, const QCString &msg, const QByteArray &data ); virtual void receive( const QCString &msg, const QByteArray &data ); signals: void received( const QCString &msg, const QByteArray &data ); };
|
However, you don't need to learn this API in detail if you use class MzCopEnvelope.
D. class MzCopEnvelope
Followings are interface of MzCopEnvelope
class MzCopEnvelope : public QDataStream { public: MzCopEnvelope (const QCString& channel, const QCString& message); ~MzCopEnvelope (); private: QCString m_channel; QCString m_message; };
|
|