Qt 4.8
Signals | Public Functions | Static Public Functions | Private Functions | Static Private Functions | Properties | Friends | List of all members
QCopChannel Class Reference

The QCopChannel class provides communication capabilities between clients in Qt for Embedded Linux. More...

#include <qcopchannel_qws.h>

Inheritance diagram for QCopChannel:
QObject

Signals

void received (const QString &msg, const QByteArray &data)
 This signal is emitted whenever this object's channel receives new messages (i. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

QString channel () const
 Returns the name of this object's channel. More...
 
 QCopChannel (const QString &channel, QObject *parent=0)
 Constructs a QCopChannel object for the specified channel, with the given parent. More...
 
virtual void receive (const QString &msg, const QByteArray &data)
 Processes the incoming message and data. More...
 
virtual ~QCopChannel ()
 Destroys this QCopChannel object. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Static Public Functions

static bool flush ()
 Flushes all queued messages to the registered listeners. More...
 
static bool isRegistered (const QString &channel)
 Queries the server for the existence of the given channel. More...
 
static void reregisterAll ()
 
static bool send (const QString &channel, const QString &msg)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
static bool send (const QString &channel, const QString &msg, const QByteArray &data)
 Sends the given message on the specified channel with the given data. More...
 
static void sendLocally (const QString &ch, const QString &msg, const QByteArray &data)
 Client side: distribute received event to the QCop instance managing the channel. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 

Private Functions

void init (const QString &channel)
 

Static Private Functions

static void answer (QWSClient *cl, const QString &ch, const QString &msg, const QByteArray &data)
 Server side: transmit the message to all clients registered to the specified channel. More...
 
static void detach (QWSClient *cl)
 Server side: unsubscribe cl from all channels. More...
 
static void registerChannel (const QString &ch, QWSClient *cl)
 Server side: subscribe client cl on channel ch. More...
 

Properties

QCopChannelPrivated
 

Friends

class QApplication
 
class QWSServer
 
class QWSServerPrivate
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QCopChannel class provides communication capabilities between clients in Qt for Embedded Linux.

Note that this class is only available in Qt for Embedded Linux.

The Qt COmmunication Protocol (QCOP) is a many-to-many protocol for transferring messages across registered channels. A channel is registered by name, and anyone who wants to can listen to the channel as well as send messages through it. The QCOP protocol allows clients to communicate both within the same address space and between different processes.

To send messages to a given channel, QCopChannel provides the static send() function. Using this function alone, the messages are queued until Qt re-enters the event loop. To immediately flush all queued messages to the registered listeners, call the static flush() function.

To listen to the traffic on a given channel, you typically instantiate a QCopChannel object for the given channel and connect to its received() signal that is emitted whenever there is incoming data. Use the static isRegistered() function to query the server for the existence of a given channel. QCopChannel provides the channel() function returning the name of this QCopChannel object's channel.

In additon, QCopChannel provides the virtual receive() function that can be reimplemented to filter the incoming messages and data. The default implementation simply emits the received() signal.

See also
QWSServer, QWSClient, {Qt for Embedded Linux Architecture}

Definition at line 58 of file qcopchannel_qws.h.

Constructors and Destructors

◆ QCopChannel()

QCopChannel::QCopChannel ( const QString channel,
QObject parent = 0 
)
explicit

Constructs a QCopChannel object for the specified channel, with the given parent.

Once created, the channel is registered by the server.

See also
isRegistered(), channel()

Definition at line 157 of file qcopchannel_qws.cpp.

157  :
158  QObject(parent)
159 {
160  init(channel);
161 }
void init(const QString &channel)
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ ~QCopChannel()

QCopChannel::~QCopChannel ( )
virtual

Destroys this QCopChannel object.

The server is notified that this particular listener has closed its connection. The server will keep the channel open until the last registered listener detaches.

See also
isRegistered(), channel()

Definition at line 232 of file qcopchannel_qws.cpp.

233 {
234  QMutexLocker locker(qcopClientMapMutex());
236  Q_ASSERT(it != qcopClientMap->end());
237  it.value().removeAll(this);
238  // still any clients connected locally ?
239  if (it.value().isEmpty()) {
242  s << d->channel;
243  if (qt_fbdpy)
244  send(QLatin1String(""), QLatin1String("detach()"), data);
246  }
247 
248  delete d;
249 }
#define it(className, varName)
Q_GUI_EXPORT QWSDisplay * qt_fbdpy
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static bool send(const QString &channel, const QString &msg)
This is an overloaded member function, provided for convenience. It differs from the above function o...
iterator find(const Key &key)
Returns an iterator pointing to the item with key key in the map.
Definition: qmap.h:618
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qmap.h:251
QCopChannelPrivate * d
static const char * data(const QByteArray &arr)
static QCopClientMap * qcopClientMap
int remove(const Key &key)
Removes all the items that have the key key from the map.
Definition: qmap.h:662
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap.
Definition: qmap.h:233
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71

Functions

◆ answer()

void QCopChannel::answer ( QWSClient cl,
const QString ch,
const QString msg,
const QByteArray data 
)
staticprivate

Server side: transmit the message to all clients registered to the specified channel.

Warning
This function is not part of the public interface.

Definition at line 514 of file qcopchannel_qws.cpp.

Referenced by QWSServerPrivate::invokeQCopSend().

516 {
517  // internal commands
518  if (ch.isEmpty()) {
519  if (msg == QLatin1String("isRegistered()")) {
520  QString c;
521  QDataStream s(data);
522  s >> c;
523  bool known = qcopServerMap && qcopServerMap->contains(c)
524  && !((*qcopServerMap)[c]).isEmpty();
525  // Yes, it's a typo, it's not user-visible, and we choose not to fix it for compatibility
526  QLatin1String ans = QLatin1String(known ? "known" : "unknown");
528  ans, data, true);
529  return;
530  } else if (msg == QLatin1String("detach()")) {
531  QString c;
532  QDataStream s(data);
533  s >> c;
536  if (it != qcopServerMap->end()) {
537  //Q_ASSERT(it.value().contains(cl));
538  it.value().removeAll(cl);
539  if (it.value().isEmpty()) {
540  // If this was the last client in the channel, announce the channel as dead
541  QWSServerSignalBridge* qwsBridge = new QWSServerSignalBridge();
542  connect(qwsBridge, SIGNAL(removedChannel(QString)), qwsServer, SIGNAL(removedChannel(QString)));
543  qwsBridge->emitRemovedChannel(it.key());
544  delete qwsBridge;
545  qcopServerMap->erase(it);
546  }
547  }
549  // Remove references to a wildcarded channel.
552  while(it != qcopServerRegexpList->end()) {
553  if ((*it).client == cl && (*it).channel == c)
554  it = qcopServerRegexpList->erase(it);
555  else
556  ++it;
557  }
558  }
559  return;
560  }
561  qWarning("QCopChannel: unknown internal command %s", qPrintable(msg));
563  QLatin1String("bad"), data);
564  return;
565  }
566 
567  if (qcopServerMap) {
569  for (int i=0; i < clist.size(); ++i) {
570  QWSClient *c = clist.at(i);
571  QWSServerPrivate::sendQCopEvent(c, ch, msg, data);
572  }
573  }
574 
576  // Search for wildcard matches and forward the message on.
578  for (; it != qcopServerRegexpList->constEnd(); ++it) {
579  if ((*it).regexp.exactMatch(ch)) {
580  QByteArray newData;
581  {
584  stream << ch;
585  stream << msg;
586  stream << data;
587  // Stream is flushed and closed at this point.
588  }
590  ((*it).client, (*it).channel,
591  QLatin1String("forwardedMessage(QString,QString,QByteArray)"),
592  newData);
593  }
594  }
595  }
596 }
unsigned char c[8]
Definition: qnumeric_p.h:62
static void sendQCopEvent(QWSClient *c, const QString &ch, const QString &msg, const QByteArray &data, bool response=false)
static QCopServerRegexpList * qcopServerRegexpList
#define it(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void emitRemovedChannel(const QString &channel)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
The QList::const_iterator class provides an STL-style const iterator for QList and QQueue...
Definition: qlist.h:228
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
iterator find(const Key &key)
Returns an iterator pointing to the item with key key in the map.
Definition: qmap.h:618
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static FILE * stream
static bool isEmpty(const char *str)
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
iterator Iterator
Qt-style synonym for QMap::iterator.
Definition: qmap.h:388
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
static bool containsWildcards(const QString &channel)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
Definition: qlist.h:181
iterator erase(iterator pos)
Removes the item associated with the iterator pos from the list, and returns an iterator to the next ...
Definition: qlist.h:464
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
Definition: qmap.h:553
static QCopServerMap * qcopServerMap
iterator erase(iterator it)
Removes the (key, value) pair pointed to by the iterator pos from the map, and returns an iterator to...
Definition: qmap.h:717
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
#define qPrintable(string)
Definition: qglobal.h:1750
The QWSClient class encapsulates a client process in Qt for Embedded Linux.
QWSServer Q_GUI_EXPORT * qwsServer
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ channel()

QString QCopChannel::channel ( ) const

Returns the name of this object's channel.

See also
isRegistered()

Definition at line 257 of file qcopchannel_qws.cpp.

Referenced by init(), isRegistered(), and QCopChannel().

258 {
259  return d->channel;
260 }
QCopChannelPrivate * d

◆ detach()

void QCopChannel::detach ( QWSClient cl)
staticprivate

Server side: unsubscribe cl from all channels.

Warning
This function is not part of the public interface.

Definition at line 474 of file qcopchannel_qws.cpp.

Referenced by QWSServerPrivate::_q_clientClosed().

475 {
476  if (!qcopServerMap)
477  return;
478 
480  for (; it != qcopServerMap->end(); ++it) {
481  if (it.value().contains(cl)) {
482  it.value().removeAll(cl);
483  // If this was the last client in the channel, announce the channel as dead.
484  if (it.value().count() == 0) {
485  QWSServerSignalBridge* qwsBridge = new QWSServerSignalBridge();
486  connect(qwsBridge, SIGNAL(removedChannel(QString)), qwsServer, SIGNAL(removedChannel(QString)));
487  qwsBridge->emitRemovedChannel(it.key());
488  delete qwsBridge;
489  }
490  }
491  }
492 
494  return;
495 
497  while(it2 != qcopServerRegexpList->end()) {
498  if ((*it2).client == cl)
499  it2 = qcopServerRegexpList->erase(it2);
500  else
501  ++it2;
502  }
503 }
static QCopServerRegexpList * qcopServerRegexpList
#define it(className, varName)
void emitRemovedChannel(const QString &channel)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
iterator Iterator
Qt-style synonym for QMap::iterator.
Definition: qmap.h:388
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
Definition: qlist.h:181
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
iterator erase(iterator pos)
Removes the item associated with the iterator pos from the list, and returns an iterator to the next ...
Definition: qlist.h:464
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
static QCopServerMap * qcopServerMap
QWSServer Q_GUI_EXPORT * qwsServer

◆ flush()

bool QCopChannel::flush ( )
static

Flushes all queued messages to the registered listeners.

Since
4.2

Note that this function returns false if no QApplication has been constructed, otherwise it returns true.

See also
send()

Definition at line 395 of file qcopchannel_qws.cpp.

396 {
397  if (!qt_fbdpy) {
398  qFatal("QCopChannel::flush: Must construct a QApplication "
399  "before using QCopChannel");
400  return false;
401  }
402 
404 
405  return true;
406 }
Q_GUI_EXPORT QWSDisplay * qt_fbdpy
Q_CORE_EXPORT void qFatal(const char *,...)

◆ init()

void QCopChannel::init ( const QString channel)
private

Definition at line 176 of file qcopchannel_qws.cpp.

Referenced by QCopChannel().

177 {
178  d = new QCopChannelPrivate;
179  d->channel = channel;
180 
181  if (!qt_fbdpy) {
182  qFatal("QCopChannel: Must construct a QApplication "
183  "before QCopChannel");
184  return;
185  }
186 
187  {
188  QMutexLocker locker(qcopClientMapMutex());
189 
190  if (!qcopClientMap)
192 
193  // do we need a new channel list ?
195  if (it != qcopClientMap->end()) {
196  it.value().append(this);
197  return;
198  }
199 
200  it = qcopClientMap->insert(channel, QList< QPointer<QCopChannel> >());
201  it.value().append(QPointer<QCopChannel>(this));
202  }
203 
204  // inform server about this channel
205  qt_fbdpy->registerChannel(channel);
206 }
void registerChannel(const QString &channel)
#define it(className, varName)
Q_GUI_EXPORT QWSDisplay * qt_fbdpy
iterator find(const Key &key)
Returns an iterator pointing to the item with key key in the map.
Definition: qmap.h:618
The QPointer class is a template class that provides guarded pointers to QObject. ...
Definition: qpointer.h:54
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qmap.h:251
QCopChannelPrivate * d
QString channel() const
Returns the name of this object&#39;s channel.
static QCopClientMap * qcopClientMap
Q_CORE_EXPORT void qFatal(const char *,...)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap.
Definition: qmap.h:233
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
QMap< QString, QList< QPointer< QCopChannel > > > QCopClientMap
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ isRegistered()

bool QCopChannel::isRegistered ( const QString channel)
static

Queries the server for the existence of the given channel.

Returns true if the channel is registered; otherwise returns false.

See also
channel(), send()

Definition at line 314 of file qcopchannel_qws.cpp.

315 {
318  s << channel;
319  if (!send(QLatin1String(""), QLatin1String("isRegistered()"), data))
320  return false;
321 
323  bool known = e->message == "known";
324  delete e;
325  return known;
326 }
Q_GUI_EXPORT QWSDisplay * qt_fbdpy
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static bool send(const QString &channel, const QString &msg)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QWSQCopMessageEvent * waitForQCopResponse()
static const char * data(const QByteArray &arr)
QString channel() const
Returns the name of this object&#39;s channel.
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71

◆ receive()

void QCopChannel::receive ( const QString message,
const QByteArray data 
)
virtual

Processes the incoming message and data.

This function is called by the server when this object's channel receives new messages. Note that the default implementation simply emits the received() signal; reimplement this function to process the incoming message and data.

Note that the format of the given data has to be well defined in order to extract the information it contains. In addition, it is recommended to use the DCOP convention. This is not a requirement, but you must ensure that the sender and receiver agree on the argument types. For example:

void MyClass::receive(const QString &message, const QByteArray &data)
{
QDataStream in(data);
if (message == "execute(QString,QString)") {
QString cmd;
QString arg;
in >> cmd >> arg;
...
} else if (message == "delete(QString)") {
in >> fileName;
...
} else {
...
}
}

The above code assumes that the message is a DCOP-style function signature and the data contains the function's arguments.

See also
send(), channel(), received()

Definition at line 289 of file qcopchannel_qws.cpp.

Referenced by sendLocally().

290 {
291  emit received(msg, data);
292 }
void received(const QString &msg, const QByteArray &data)
This signal is emitted whenever this object&#39;s channel receives new messages (i.
#define emit
Definition: qobjectdefs.h:76

◆ received

void QCopChannel::received ( const QString message,
const QByteArray data 
)
signal

This signal is emitted whenever this object's channel receives new messages (i.

e., it is emitted by the receive() function), passing the incoming message and data as parameters.

See also
receive(), channel()

Referenced by receive().

◆ registerChannel()

void QCopChannel::registerChannel ( const QString ch,
QWSClient cl 
)
staticprivate

Server side: subscribe client cl on channel ch.

Warning
This function is not part of the public interface.

Definition at line 436 of file qcopchannel_qws.cpp.

Referenced by QWSServerPrivate::invokeRegisterChannel().

437 {
438  if (!qcopServerMap)
440 
441  // do we need a new channel list ?
443  if (it == qcopServerMap->end())
445 
446  // If the channel name contains wildcard characters, then we also
447  // register it on the server regexp matching list.
448  if (containsWildcards( ch )) {
449  QCopServerRegexp item(ch, cl);
452  qcopServerRegexpList->append( item );
453  }
454 
455  // If this is the first client in the channel, announce the channel as being created.
456  if (it.value().count() == 0) {
457  QWSServerSignalBridge* qwsBridge = new QWSServerSignalBridge();
458  connect(qwsBridge, SIGNAL(newChannel(QString)), qwsServer, SIGNAL(newChannel(QString)));
459  qwsBridge->emitNewChannel(ch);
460  delete qwsBridge;
461  }
462 
463  it.value().append(cl);
464 }
void emitNewChannel(const QString &channel)
static QCopServerRegexpList * qcopServerRegexpList
#define it(className, varName)
iterator find(const Key &key)
Returns an iterator pointing to the item with key key in the map.
Definition: qmap.h:618
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QMap< QString, QList< QWSClient * > > QCopServerMap
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
iterator Iterator
Qt-style synonym for QMap::iterator.
Definition: qmap.h:388
static bool containsWildcards(const QString &channel)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
static QCopServerMap * qcopServerMap
QList< QCopServerRegexp > QCopServerRegexpList
QWSServer Q_GUI_EXPORT * qwsServer
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ reregisterAll()

void QCopChannel::reregisterAll ( )
static
Warning
This function is not part of the public interface.

Resend all channel registrations

Definition at line 213 of file qcopchannel_qws.cpp.

Referenced by QWSDisplay::Data::reinit().

214 {
215  if(qcopClientMap)
217  iter != qcopClientMap->end();
218  ++iter)
219  qt_fbdpy->registerChannel(iter.key());
220 }
void registerChannel(const QString &channel)
Q_GUI_EXPORT QWSDisplay * qt_fbdpy
static QCopClientMap * qcopClientMap
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap.
Definition: qmap.h:233
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375

◆ send() [1/2]

bool QCopChannel::send ( const QString channel,
const QString msg 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 333 of file qcopchannel_qws.cpp.

Referenced by QtopiaPrintEngine::end(), isRegistered(), and ~QCopChannel().

334 {
336  return send(channel, msg, data);
337 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static bool send(const QString &channel, const QString &msg)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static const char * data(const QByteArray &arr)

◆ send() [2/2]

bool QCopChannel::send ( const QString channel,
const QString message,
const QByteArray data 
)
static

Sends the given message on the specified channel with the given data.

The message will be distributed to all clients subscribed to the channel. Returns true if the message is sent successfully; otherwise returns false.

It is recommended to use the DCOP convention. This is not a requirement, but you must ensure that the sender and receiver agree on the argument types.

Note that QDataStream provides a convenient way to fill the byte array with auxiliary data. For example:

out << QString("cat") << QString("file.txt");
QCopChannel::send("System/Shell", "execute(QString,QString)", data);

In the code above the channel is "System/Shell". The message 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 "&".

See also
receive(), isRegistered()

Definition at line 367 of file qcopchannel_qws.cpp.

369 {
370  if (!qt_fbdpy) {
371  qFatal("QCopChannel::send: Must construct a QApplication "
372  "before using QCopChannel");
373  return false;
374  }
375 
376  qt_fbdpy->sendMessage(channel, msg, data);
377 
378  return true;
379 }
Q_GUI_EXPORT QWSDisplay * qt_fbdpy
Q_CORE_EXPORT void qFatal(const char *,...)
void sendMessage(const QString &channel, const QString &msg, const QByteArray &data)

◆ sendLocally()

void QCopChannel::sendLocally ( const QString ch,
const QString msg,
const QByteArray data 
)
static

Client side: distribute received event to the QCop instance managing the channel.

Warning
This function is not part of the public interface.

Definition at line 606 of file qcopchannel_qws.cpp.

Referenced by QApplication::qwsProcessEvent().

608 {
610 
611  // filter out internal events
612  if (ch.isEmpty())
613  return;
614 
615  // feed local clients with received data
617  {
618  QMutexLocker locker(qcopClientMapMutex());
619  clients = (*qcopClientMap)[ch];
620  }
621  for (int i = 0; i < clients.size(); ++i) {
622  QCopChannel *channel = (QCopChannel *)clients.at(i);
623  if ( channel )
624  channel->receive(msg, data);
625  }
626 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QString channel() const
Returns the name of this object&#39;s channel.
static QCopClientMap * qcopClientMap
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QCopChannel class provides communication capabilities between clients in Qt for Embedded Linux...
virtual void receive(const QString &msg, const QByteArray &data)
Processes the incoming message and data.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

Friends and Related Functions

◆ QApplication

friend class QApplication
friend

Definition at line 99 of file qcopchannel_qws.h.

◆ QWSServer

friend class QWSServer
friend

Definition at line 97 of file qcopchannel_qws.h.

◆ QWSServerPrivate

friend class QWSServerPrivate
friend

Definition at line 98 of file qcopchannel_qws.h.

Properties

◆ d

QCopChannelPrivate* QCopChannel::d
private

Definition at line 95 of file qcopchannel_qws.h.

Referenced by channel(), init(), and ~QCopChannel().


The documentation for this class was generated from the following files: