MessageIn Network::getNextMessage() { while (!messageReady()) { if (mState == NET_ERROR) break; } MutexLocker lock(&mMutex); uint16_t msgId = readWord(0); uint16_t len = 0; if (msgId == SMSG_SERVER_VERSION_RESPONSE) len = 10; else if (msgId < 0x220) len = packet_lengths[msgId]; if (len == VAR) len = readWord(2); #ifdef DEBUG logger->log("Received packet 0x%x of length %d", msgId, len); #endif return MessageIn(mInBuffer, len); }
MessageIn Network::getNextMessage() { while (!messageReady()) { if (mState == NET_ERROR) break; } SDL_mutexP(mMutex); int msgId = readWord(0); int len; if (msgId == SMSG_SERVER_VERSION_RESPONSE) len = 10; else if (msgId == SMSG_UPDATE_HOST2) len = -1; else len = packet_lengths[msgId]; if (len == -1) len = readWord(2); #ifdef ENABLEDEBUGLOG // logger->dlog(strprintf("Received packet 0x%x of length %d\n", // msgId, len)); #endif MessageIn msg(mInBuffer, len); SDL_mutexV(mMutex); return msg; }
void NetworkQueue::addMessage(QSharedPointer<Message> msg) { mutex.lock(); queue.push(msg); mutex.unlock(); emit messageReady(); }
HRESULT CWizKMSyncEvents::OnText(WizKMSyncProgressStatusType type, const QString& strStatus) { qDebug() << "[OnText] type: " << type << " status: " << strStatus; TOLOG(strStatus); Q_EMIT messageReady(strStatus); return 0; }
void MessageQueue::enqueue(void const *msg, size_t size) { mStorage.startTransaction(Akonadi2::Storage::ReadWrite); const qint64 revision = mStorage.maxRevision() + 1; const QByteArray key = QString("%1").arg(revision).toUtf8(); mStorage.write(key.data(), key.size(), msg, size); mStorage.setMaxRevision(revision); mStorage.commitTransaction(); emit messageReady(); }
void Network::dispatchMessages() { while (messageReady()) { SDL_mutexP(mMutexIn); const unsigned int msgId = readWord(0); int len = -1; if (msgId == SMSG_SERVER_VERSION_RESPONSE) { len = 10; } else if (msgId == SMSG_UPDATE_HOST2) { len = -1; } else { if (msgId < packet_lengths_size) len = packet_lengths[msgId]; } if (len == -1) len = readWord(2); MessageIn msg(mInBuffer, len); msg.postInit(); SDL_mutexV(mMutexIn); if (len == 0) { // need copy data for safty std::string str = strprintf("Wrong packet %u ""received. Exiting.", msgId); logger->safeError(str); } if (msgId < messagesSize) { MessageHandler *const handler = mMessageHandlers[msgId]; if (handler) handler->handleMessage(msg); else logger->log("Unhandled packet: %x", msgId); } skip(len); } }
void MessageDialog::sendPressed() { QString mess = ui->plainTextEdit->toPlainText(); if (mess.isEmpty()) return; ui->plainTextEdit->storeLastMessage(); ui->plainTextEdit->clear(); playSound(SND_SENDMSG); QStringList messages = mess.split(QString("\n")); for (int i=0; i<messages.size(); i++) { if (messages[i].isEmpty()) continue; emit messageReady(nick, messages[i]); smilebar->printParsedMessage(ui->textBrowser, currentnick, messages[i]); } }
void MainWindow::userDoubleClicked(const QString &nick) { if (!usersChatting.contains(nick)) { MessageDialog *msgdlg = new MessageDialog(nick, 0); connect(msgdlg, SIGNAL(messageReady(QString,QString)), irc, SLOT(sendMessage(QString,QString))); QFont chatfont; if (chatfont.fromString(settings.chatfont)) msgdlg->setFont(chatfont); msgdlg->show(); usersChatting.insert(nick, msgdlg); } MessageDialog *msgdlg = usersChatting.value(nick); if (msgdlg) msgdlg->show(); }
void Network::dispatchMessages() { while (messageReady()) { MessageIn msg = getNextMessage(); MessageHandlerIterator iter = mMessageHandlers.find(msg.getId()); if (msg.getLength() == 0) logger->error("Zero length packet received. Exiting."); if (iter != mMessageHandlers.end()) { iter->second->handleMessage(msg); } else { logger->log("Unhandled packet: %x", msg.getId()); } skip(msg.getLength()); } }
void MessageSender::sendMessage(MessageCommunication *messageCommunication, ResponseHandler *responseHandler) { // Sending a message is about preparing a handler for the response // that is expected to be received and sending the message information // via the socker to the destination node. // // Check we have a message and a socket to send data. if (messageCommunication == 0 || messageCommunication->message() == 0 || messageCommunication->socket() == 0) { return; } // Get the socket used for the communication rountrip. QTcpSocket *socket = messageCommunication->socket(); // Prepare the response waiter in case a response handler was // provided. if (responseHandler == 0) { responseHandler = new ResponseHandler(this); } // Prepare a new ResponseWaiter to use and throw away. ResponseWaiter * responseWaiter = new ResponseWaiter( this->m_communication_manager, messageCommunication, responseHandler, this); // Connect the receiving of a message in the socket with the // response handler of the response waiter. QObject::connect(socket, SIGNAL(readyRead()), responseWaiter, SLOT(messageReady())); // Prepare the message data to send via the socket. MessageModel *message = messageCommunication->message(); QString *jsonMessage = message->toCommJSON(); QByteArray dataMessage = jsonMessage->toUtf8(); // Send the message via the socket socket->write(dataMessage); // A response is expected to be received soon that will be handled // by the ResponseWaiter once it arrives. // cerr << "[MessageSender] Message sent : " << message->toJSON()->toStdString() << endl; }
void EditWidget::sendMessage() { emit messageAboutToBeSend(); appendMessageToBuffer(); emit messageReady(); }