dcop Library: dcopsignals.cpp Source File (dcop Library)

| # dcop Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# dcopsignals.cpp

    00001 /*
    00002 Copyright (c) 2000 Waldo Bastian <bastian@kde.org>
    00003
    00004 Permission is hereby granted, free of charge, to any person obtaining a copy
    00005 of this software and associated documentation files (the "Software"), to deal
    00006 in the Software without restriction, including without limitation the rights
    00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00008 copies of the Software, and to permit persons to whom the Software is
    00009 furnished to do so, subject to the following conditions:
    00010
    00011 The above copyright notice and this permission notice shall be included in
    00012 all copies or substantial portions of the Software.
    00013
    00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    00017 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    00018 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    00019 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00020 */
    00021
    00022 #include <dcopserver.h>
    00023 #include <dcopsignals.h>
    00024
    00025 template class QPtrList<DCOPSignalConnection>;
    00026
    00027 DCOPSignals::DCOPSignals()
    00028 {
    00029    connections.setAutoDelete(true);
    00030 }
    00031
    00037 void
    00038 DCOPSignals::emitSignal( DCOPConnection *conn, const QCString &_fun, const QByteArray &data, bool excludeSelf)
    00039 {
    00040 #ifdef Q_OS_UNIX
    00041    QCString senderObj;
    00042    QCString fun = _fun;
    00043    int i = fun.find('#');
    00044    if (i > -1)
    00045    {
    00046       senderObj = fun.left(i);
    00047       fun = fun.mid(i+1);
    00048    }
    00049
    00050    DCOPSignalConnectionList *list = connections.find(fun);
    00051    if (!list) return;
    00052    for(DCOPSignalConnection *current = list->first(); current; current = list->next())
    00053    {
    00054       bool doSend = false;
    00055       if (current->senderConn)
    00056       {
    00057          if (current->senderConn == conn)
    00058         doSend = true;
    00059       }
    00060       else if (!current->sender.isEmpty())
    00061       {
    00062          if ((conn && current->sender == conn->appId) || (current->sender == "DCOPServer"))
    00063         doSend = true;
    00064       }
    00065       else
    00066       {
    00067          doSend = true;
    00068       }
    00069
    00070       if (!current->senderObj.isEmpty() &&
    00071           (current->senderObj != senderObj))
    00072       {
    00073          doSend = false;
    00074       }
    00075
    00076       if (excludeSelf && (conn == current->recvConn))
    00077          doSend = false;
    00078       if (doSend)
    00079       {
    00080          the_server->sendMessage(current->recvConn, conn ? conn->appId : QCString("DCOPServer"),
    00081                                  current->recvConn->appId, current->recvObj,
    00082                                  current->slot, data);
    00083       }
    00084    }
    00085 #endif //Q_OS_UNIX
    00086 }
    00087
    00098 bool
    00099 DCOPSignals::connectSignal( const QCString &sender, const QCString &senderObj,
    00100                        const QCString &signal,
    00101                        DCOPConnection *conn, const QCString &receiverObj,
    00102                        const QCString &slot, bool Volatile)
    00103 {
    00104 #ifdef Q_OS_UNIX
    00105    // TODO: Check if signal and slot match
    00106    QCString signalArgs, slotArgs;
    00107    int i,j;
    00108    i = signal.find('(');
    00109    if (i < 0) return false;
    00110    signalArgs = signal.mid(i+1);
    00111    j = signalArgs.find(')');
    00112    if (j < 0) return false;
    00113    signalArgs.truncate(j);
    00114    i = slot.find('(');
    00115    if (i < 0) return false;
    00116    slotArgs = slot.mid(i+1);
    00117    j = slotArgs.find(')');
    00118    if (j < 0) return false;
    00119    slotArgs.truncate(j);
    00120
    00121    if(signalArgs != slotArgs)
    00122    {
    00123       // Maybe the signal has more arguments than the slot...
    00124       if (signalArgs.length() <= slotArgs.length())
    00125          return false;
    00126       if ((slotArgs.length() > 0) && (signalArgs[slotArgs.length()] != ','))
    00127          return false;
    00128       if (signalArgs.left(slotArgs.length()) != slotArgs)
    00129          return false;
    00130    }
    00131
    00132    DCOPConnection *senderConn = 0;
    00133    if (Volatile)
    00134    {
    00135       senderConn = the_server->findApp(sender);
    00136       if (!senderConn)
    00137          return false; // Sender does not exist.
    00138    }
    00139    DCOPSignalConnection *current = new DCOPSignalConnection;
    00140    current->sender = sender;
    00141    current->senderObj = senderObj;
    00142    current->senderConn = senderConn;
    00143    current->signal = signal;
    00144    current->recvConn = conn;
    00145    current->recvObj = receiverObj;
    00146    current->slot = slot;
    00147
    00148    DCOPSignalConnectionList *list = connections.find(signal);
    00149    if (!list)
    00150    {
    00151       list = new DCOPSignalConnectionList;
    00152       connections.insert(signal, list);
    00153    }
    00154
    00155    list->append( current );
    00156    conn->signalConnectionList()->append(current);
    00157    if (senderConn)
    00158       senderConn->signalConnectionList()->append(current);
    00159    return true;
    00160 #else
    00161    return false;
    00162 #endif
    00163 }
    00164
    00174 bool
    00175 DCOPSignals::disconnectSignal( const QCString &sender, const QCString &senderObj,
    00176                        const QCString &signal,
    00177                        DCOPConnection *conn, const QCString &receiverObj,
    00178                        const QCString &slot)
    00179 {
    00180    if (sender.isEmpty() && signal.isEmpty())
    00181    {
    00182       removeConnections(conn, receiverObj);
    00183       return true;
    00184    }
    00185
    00186    DCOPSignalConnectionList *list = connections.find(signal);
    00187    if (!list)
    00188       return false; // Not found...
    00189
    00190    DCOPSignalConnection *next = 0;
    00191    bool result = false;
    00192
    00193 #ifdef Q_OS_UNIX
    00194    for(DCOPSignalConnection *current = list->first(); current; current = next)
    00195    {
    00196       next = list->next();
    00197
    00198       if (current->recvConn != conn)
    00199          continue;
    00200
    00201       if (current->senderConn)
    00202       {
    00203          if (current->senderConn->appId != sender)
    00204         continue;
    00205       }
    00206       else if (current->sender != sender)
    00207         continue;
    00208
    00209       if (!senderObj.isEmpty() &&
    00210           (current->senderObj != senderObj))
    00211          continue;
    00212
    00213       if (!receiverObj.isEmpty() &&
    00214           (current->recvObj != receiverObj))
    00215          continue;
    00216
    00217       if (!slot.isEmpty() &&
    00218           (current->slot != slot))
    00219          continue;
    00220
    00221       result = true;
    00222       list->removeRef(current);
    00223       conn->signalConnectionList()->removeRef(current);
    00224       if (current->senderConn)
    00225          current->senderConn->signalConnectionList()->removeRef(current);
    00226       delete current;
    00227    }
    00228 #endif //Q_OS_UNIX
    00229    return result;
    00230 }
    00231
    00238 void
    00239 DCOPSignals::removeConnections(DCOPConnection *conn, const QCString &obj)
    00240 {
    00241 #ifdef Q_OS_UNIX
    00242    DCOPSignalConnectionList *list = conn->_signalConnectionList;
    00243    if (!list)
    00244       return; // Nothing to do...
    00245
    00246    DCOPSignalConnection *next = 0;
    00247
    00248    for(DCOPSignalConnection *current = list->first(); current; current = next)
    00249    {
    00250       next = list->next();
    00251
    00252       if (!obj.isEmpty())
    00253       {
    00254          if ((current->senderConn == conn) && (current->senderObj != obj))
    00255             continue;
    00256
    00257          if ((current->recvConn == conn) && (current->recvObj != obj))
    00258             continue;
    00259       }
    00260
    00261       if (current->senderConn && (current->senderConn != conn))
    00262          current->senderConn->signalConnectionList()->removeRef(current);
    00263
    00264       if (current->recvConn != conn)
    00265          current->recvConn->signalConnectionList()->removeRef(current);
    00266
    00267       DCOPSignalConnectionList *signalList = connections.find(current->signal);
    00268       if (signalList)
    00269       {
    00270          signalList->removeRef(current);
    00271          if (signalList->isEmpty())
    00272             connections.remove(current->signal);
    00273       }
    00274       else
    00275       {
    00276          qDebug("Error: Signal Connection was not in signalList!\n");
    00277       }
    00278       list->removeRef(current);
    00279       delete current;
    00280    }
    00281 #endif //Q_OS_UNIX
    00282 }
    00283
    00284

This file is part of the documentation for dcop Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:16:55 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003