TQCopChannel Class

Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# TQCopChannel Class Reference

The TQCopChannel class provides communication capabilities between several clients. More...

`#include <qcopchannel_qws.h>`

Inherits TQObject.

List of all member functions.

## Public Members

- TQCopChannel ( const TQCString & channel, TQObject * parent = 0, const char * name = 0 )
- virtual ~TQCopChannel ()
- TQCString channel () const
- virtual void receive ( const TQCString & msg, const TQByteArray & data )

## Signals

- void received ( const TQCString & msg, const TQByteArray & data )

## Static Public Members

- bool isRegistered ( const TQCString & channel )
- bool send ( const TQCString & channel, const TQCString & msg )
- bool send ( const TQCString & channel, const TQCString & msg, const TQByteArray & data )

## Detailed Description

The TQCopChannel class provides communication capabilities between several clients.

The TQt Cop (TQCOP) is a COmmunication Protocol, allowing clients to communicate both within the same address space and between different processes.

Currently, this facility is only available on TQt/Embedded. On X11 and Windows we are exploring the use of existing standards such as DCOP and COM.

TQCopChannel provides send() and isRegistered() which are static functions usable without an object.

The channel() function returns the name of the channel.

In order to listen to the traffic on a channel, you should either subclass TQCopChannel and reimplement receive(), or connect() to the received() signal.

## Member Function Documentation

### TQCopChannel::TQCopChannel ( const TQCString & channel, TQObject * parent = 0, const char * name = 0 )

Constructs a TQCop channel and registers it with the server using the name channel. The standard parent and name arguments are passed on to the TQObject constructor.

### TQCopChannel::~TQCopChannel ()`[virtual]`

Destroys the client's end of the channel and notifies the server that the client has closed its connection. The server will keep the channel open until the last registered client detaches.

### TQCString TQCopChannel::channel () const

Returns the name of the channel.

### bool TQCopChannel::isRegistered ( const TQCString & channel )`[static]`

Queries the server for the existence of channel.

Returns TRUE if channel is registered; otherwise returns FALSE.

### void TQCopChannel::receive ( const TQCString & msg, const TQByteArray & data )`[virtual]`

This virtual function allows subclasses of TQCopChannel to process data received from their channel.

The default implementation emits the received() signal.

Note that the format of data has to be well defined in order to extract the information it contains.

Example:

        void MyClass::receive( const TQCString &msg, const TQByteArray &data )
        {
            TQDataStream stream( data, IO_ReadOnly );
            if ( msg == "execute(TQString,TQString)" ) {
                TQString cmd, arg;
                stream >> cmd >> arg;
                ...
            } else if ( msg == "delete(TQString)" ) {
                TQString filenname;
                stream >> filename;
                ...
            } else ...
        }

This example assumes that the msg is a DCOP-style function signature and the data contains the function's arguments. (See send().)

Using the DCOP convention is a recommendation, but not a requirement. Whatever convention you use the sender and receiver must agree on the argument types.

See also send().

### void TQCopChannel::received ( const TQCString & msg, const TQByteArray & data )`[signal]`

This signal is emitted with the msg and data whenever the receive() function gets incoming data.

### bool TQCopChannel::send ( const TQCString & channel, const TQCString & msg, const TQByteArray & data )`[static]`

Send the message msg on channel channel with data data. The message will be distributed to all clients subscribed to the channel.

Note that TQDataStream provides a convenient way to fill the byte array with auxiliary data.

Example:

        TQByteArray ba;
        TQDataStream stream( ba, IO_WriteOnly );
        stream << TQString("cat") << TQString("file.txt");
        TQCopChannel::send( "System/Shell", "execute(TQString,TQString)", ba );

Here the channel is "System/Shell". The msg is an arbitrary string, but in the example we've used the DCOP convention of passing a function signature. Such a signature is formatted as functionname(types) where types is a list of zero or more comma-separated type names, with no whitespace, no consts and no pointer or reference marks, i.e. no "*" or "&".

Using the DCOP convention is a recommendation, but not a requirement. Whatever convention you use the sender and receiver must agree on the argument types.

See also receive().

### bool TQCopChannel::send ( const TQCString & channel, const TQCString & msg )`[static]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Send the message msg on channel channel. The message will be distributed to all clients subscribed to the channel.

See also receive().

This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.