/* !
    Constructs a new QCop channel monitor for \a channel and
    attaches it to \a parent.

    If \a channel is already registered by one of the clients in the
    system, then the registered() signal will be emitted after this
    constructor exits and control returns to the event loop.

    If the channel is not already registered, then the unregistered()
    signal will be emitted instead.

    The state() will be Unknown until the initial registration
    status has been determined.

    \sa registered(), unregistered(), state()
*/
QCopChannelMonitor::QCopChannelMonitor(const QString& channel, QObject *parent)
    : QObject(parent)
{
    d = new QCopChannelMonitorPrivate(this, channel);
    d->ref.ref();

    QCopThreadData *td = QCopThreadData::instance();

    // Do we need a new monitor list for this channel name?
    QCopClientMonitorMap::Iterator it = td->clientMonitorMap.find(channel);
    if (it != td->clientMonitorMap.end()) {
        it.value().append(QCopChannelMonitorPrivatePointer(d));

        // Copy the state from the previous object on this channel.
        // Either the state is already known, or a request is
        // in transit from the previous object and we will get the
        // update at the same time.
        const QCopChannelMonitorPrivate *prev = it.value()[0].constData();
        d->state = prev->state;
        if (d->state == QCopChannelMonitor::Registered)
            QTimer::singleShot(0, this, SIGNAL(registered()));
        else if (d->state == QCopChannelMonitor::Unregistered)
            QTimer::singleShot(0, this, SIGNAL(unregistered()));
        return;
    }

    it = td->clientMonitorMap.insert
        (channel, QList<QCopChannelMonitorPrivatePointer>());
    it.value().append(QCopChannelMonitorPrivatePointer(d));

    // Inform the server about this channel
    td->clientConnection()->sendChannelCommand(QCopCmd_RegisterMonitor, channel);
}
Exemplo n.º 2
0
void RDOKernel::proc( RDOMessageInfo& msg )
{
	switch ( msg.message ) {
		// Закрыть все треды
		case RT_THREAD_CLOSE: {
#ifdef TR_TRACE
			trace( thread_name + " stop begin" );
#endif
#ifdef RDO_MT
			threads_mutex.Lock();
#endif
			std::list< RDOThread* >::iterator it = threads.begin();
			while ( it != threads.end() ) {
				RDOThread* thread = *it;
#ifdef RDO_MT
				if ( !thread->isGUI() ) {
					CEvent* thread_destroy = thread->getDestroyEvent();
					threads_mutex.Unlock();
					sendMessage( thread, RDOThread::RT_THREAD_CLOSE );
					thread_destroy->Lock();
					threads_mutex.Lock();
					delete thread_destroy;
					it = threads.begin();
				} else {
					++it;
				}
#else
				sendMessage( thread, RDOThread::RT_THREAD_CLOSE );
				it = threads.begin();
#endif
			}
#ifdef RDO_MT
			threads_mutex.Unlock();
#endif
#ifdef TR_TRACE
			trace ( thread_name + " stop end" );
#endif
			break;
		}
		case RT_THREAD_CONNECTION: {
			if ( msg.from != this ) {
				registration( msg.from );
			}
			break;
		}
		case RT_THREAD_DISCONNECTION: {
			if ( msg.from != this ) {
				unregistered( msg.from );
			}
			break;
		}
		default: break;
	}
}
Exemplo n.º 3
0
// Handle messages that were forwarded on QPE/Application/* channels.
void QCopServerPrivate::forwarded
        (const QString& msg, const QByteArray &data, const QString& channel)
{
    QCopThreadData *td = QCopThreadData::instance();
    QCopServerAppInfo *info;

    // Do we already know about this application?
    QString appName = channel.mid(16);
    QMap<QString, QCopServerAppInfo *>::ConstIterator it;
    it = applications.find(appName);
    if (it != applications.constEnd()) {
        info = it.value();
    } else {
        // We haven't seen this application before, so try to start it.
        qint64 pid = td->server->activateApplication(appName);
        if (pid == -1)
            return;
        info = new QCopServerAppInfo();
        info->pidChannelAvailable = false;
        info->pid = pid;
        info->pidChannel = QLatin1String("QPE/Pid/") + QString::number(pid);
        info->monitor = new QCopChannelMonitor(info->pidChannel);
        connect(info->monitor, SIGNAL(registered()), this, SLOT(registered()));
        connect(info->monitor, SIGNAL(unregistered()), this, SLOT(unregistered()));
        applications.insert(appName, info);
        pidChannels.insert(info->pidChannel, info);
    }

    // Add the message to the application's saved message queue.
    QCopServerSavedMessage saved;
    saved.message = msg;
    saved.data = data;
    info->queue.append(saved);

    // If the application is already running, then pass it on.
    if (info->pidChannelAvailable) {
        // XXX - not right, should use answer()
        td->clientConnection()->send
            (info->pidChannel, msg, data, QCopCmd_SendRequestAck);
    }
}
Exemplo n.º 4
0
void RDOKernelGUI::proc( RDOMessageInfo& msg )
{
	switch ( msg.message ) {
		// Удалить прикрепленные треды
		case RT_THREAD_CLOSE: {
#ifdef TR_TRACE
			trace( thread_name + " stop begin" );
#endif
			std::list< RDOThread* >::iterator it = threads.begin();
			while ( it != threads.end() ) {
				RDOThread* thread = *it;
				threads.erase( it );
				thread->stop();
				delete thread;
				it = threads.begin();
			}
#ifdef TR_TRACE
			trace ( thread_name + " stop end" );
#endif
			return;
		}
		case RT_THREAD_CONNECTION: {
			if ( msg.from != this ) {
				registration( msg.from );
				return;
			}
			break;
		}
		case RT_THREAD_DISCONNECTION: {
			if ( msg.from != this ) {
				unregistered( msg.from );
				return;
			}
			break;
		}
		default: break;
	}
	std::list< RDOThread* >::iterator it = threads.begin();
	while ( it != threads.end() ) {
		// it_next используется из-за того, что в RDOThreadRunTime->idle() м.б. удален RDOThreadRunTime и убран из threads
		std::list< RDOThread* >::iterator it_next = it;
		++it_next;
		if ( *it != msg.from ) {
			(*it)->proc( msg );
		}
		it = it_next;
	}
}