WUploadThread::WUploadThread(QObject * owner, bool * optShutdownFlag) : QObject(owner), fOwner(owner), fShutdownFlag(optShutdownFlag) { PRINT("WUploadThread ctor\n"); setName( "WUploadThread" ); fFile = NULL; fFileUl = QString::null; fRemoteSessionID = QString::null; // Default status if (!fShutdownFlag) // Force use of Shutdown Flag { fShutdown = false; fShutdownFlag = &fShutdown; } fCurFile = -1; fNumFiles = 0; fPort = 0; fSocket = 0; fForced = false; timerID = 0; fActive = false; fBlocked = false; fFinished = false; fManuallyQueued = false; fLocallyQueued = false; fRemotelyQueued = false; fDisconnected = false; fConnecting = true; fTunneled = false; fTXRate = 0; fTimeLeft = 0; fStartTime = 0; fPacket = 8.0; fIdles = 0; fCompression = -1; InitTransferRate(); InitTransferETA(); CTimer = new QTimer(this, "Connect Timer"); Q_CHECK_PTR(CTimer); connect( CTimer, SIGNAL(timeout()), this, SLOT(ConnectTimer()) ); fBlockTimer = new QTimer(this, "Blocked Timer"); Q_CHECK_PTR(fBlockTimer); connect( fBlockTimer, SIGNAL(timeout()), this, SLOT(BlockedTimer()) ); // QMessageTransceiverThread qmtt = new QMessageTransceiverThread(this, "QMessageTransceiverThread"); Q_CHECK_PTR(qmtt); connect(qmtt, SIGNAL(MessageReceived(const MessageRef &, const String &)), this, SLOT(MessageReceived(const MessageRef &, const String &))); connect(qmtt, SIGNAL(OutputQueuesDrained(const MessageRef &)), this, SLOT(OutputQueuesDrained(const MessageRef &))); connect(qmtt, SIGNAL(SessionConnected(const String &, const IPAddressAndPort &)), this, SLOT(SessionConnected(const String &, const IPAddressAndPort &))); connect(qmtt, SIGNAL(SessionDisconnected(const String &)), this, SLOT(SessionDisconnected(const String &))); connect(qmtt, SIGNAL(SessionAttached(const String &)), this, SLOT(SessionAttached(const String &))); connect(qmtt, SIGNAL(SessionDetached(const String &)), this, SLOT(SessionDetached(const String &))); connect(qmtt, SIGNAL(ServerExited()), this, SLOT(ServerExited())); // End of QMessageTransceiverThread PRINT("WUploadThread ctor OK\n"); }
void QMessageTransceiverThread :: HandleQueuedIncomingEvents() { uint32 code; MessageRef next; String sessionID; uint32 factoryID; bool seenIncomingMessage = false; IPAddressAndPort iap; // Check for any new messages from our internal thread while(GetNextEventFromInternalThread(code, &next, &sessionID, &factoryID, &iap) >= 0) { switch(code) { case MTT_EVENT_INCOMING_MESSAGE: default: if (seenIncomingMessage == false) { seenIncomingMessage = true; emit BeginMessageBatch(); } emit MessageReceived(next, sessionID); break; case MTT_EVENT_SESSION_ACCEPTED: emit SessionAccepted(sessionID, factoryID, iap); break; case MTT_EVENT_SESSION_ATTACHED: emit SessionAttached(sessionID); break; case MTT_EVENT_SESSION_CONNECTED: emit SessionConnected(sessionID, iap); break; case MTT_EVENT_SESSION_DISCONNECTED: emit SessionDisconnected(sessionID); break; case MTT_EVENT_SESSION_DETACHED: emit SessionDetached(sessionID); break; case MTT_EVENT_FACTORY_ATTACHED: emit FactoryAttached(factoryID); break; case MTT_EVENT_FACTORY_DETACHED: emit FactoryDetached(factoryID); break; case MTT_EVENT_OUTPUT_QUEUES_DRAINED: emit OutputQueuesDrained(next); break; case MTT_EVENT_SERVER_EXITED: emit ServerExited(); break; } emit InternalThreadEvent(code, next, sessionID, factoryID); // these get emitted for any event const char * id = _handlers.HasItems() ? strchr(sessionID()+1, '/') : NULL; if (id) { QMessageTransceiverHandler * handler; if (_handlers.Get(atoi(id+1), handler) == B_NO_ERROR) { // If it's not already in the list, prepend it to the list and tell it to emit its BeginMessageBatch() signal if ((code == MTT_EVENT_INCOMING_MESSAGE)&&(handler != _lastSeenHandler)&&(handler->_nextSeen == NULL)) { if (_firstSeenHandler == NULL) _firstSeenHandler = _lastSeenHandler = handler; else { _firstSeenHandler->_prevSeen = handler; handler->_nextSeen = _firstSeenHandler; _firstSeenHandler = handler; } handler->EmitBeginMessageBatch(); } handler->HandleIncomingEvent(code, next, iap); } } } FlushSeenHandlers(true); if (seenIncomingMessage) emit EndMessageBatch(); }