QList<QString> HistoryKeeper::generateAddChatEntryCmd(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt, bool isSent, QString dispName) { QList<QString> cmds; int chat_id = getChatID(chat, ctSingle).first; int sender_id = getAliasID(sender); cmds.push_back(QString("INSERT INTO history (timestamp, chat_id, sender, message, alias) VALUES (%1, %2, %3, '%4', '%5');") .arg(dt.toMSecsSinceEpoch()).arg(chat_id).arg(sender_id).arg(wrapMessage(message)).arg(dispName)); cmds.push_back(QString("INSERT INTO sent_status (status) VALUES (%1);").arg(isSent)); return cmds; }
MessageWrapper *ConnectMessagingEndPoint::preprocessMessage(MessageWrapper *mw){ Message *inmsg = 0; switch (mw->getType()){ case MessageWrapper::mwTask:{ /* fall through */ getLogStream(LOG_DEBUG) << "I've been assigned to a task" << endl; ostringstream ofs; ofs << mw->getAnyCastID(); getLogStream(LOG_DEBUG) << "TASKID:" << ofs.str() << endl; // Store the MessageWrapper so that we can send an ack when we are done _taskmap[mw->getPayLoad()] = mw; mw = wrapMessage(mw->getPayLoad()); return mw; } case MessageWrapper::mwTaskProgress: case MessageWrapper::mwUser:{ inmsg = mw->getPayLoad(); if (inmsg == 0){ // Maybe just return here? Or do we consider the digiwash corrupt?? getLogStream(LOG_CRIT) << "Received messageWrapper with empty payload" << endl; getLogStream(LOG_CRIT) << "anycastId is " << mw->getAnyCastID() << endl; getLogStream(LOG_CRIT) << "type is " << static_cast<int>(mw->getType()) << endl; throw OcfaException("Received a messagewrapper with empty payload!"); } // FIXME : reintroduce priority check ? getLogStream(LOG_DEBUG) << "returning message with type " << static_cast<int>(inmsg->getType())<< endl; return mw; } break; case MessageWrapper::mwInternalConnect:{ getLogStream(LOG_ERR) << "mwInternalConnect in ConnectMessagingEndPoint" << endl; return 0; } break; case MessageWrapper::mwInternalDisconnect:{ getLogStream(LOG_CRIT) << "Lost connection" << endl; // throw away the envelope but keep the payload. The caller MUST delete msg1 ! inmsg = new ConcreteMessage(_moduleinstance, _moduleinstance, Message::BROADCAST, Message::mtModuleDisconnect, "","",0 ); //RJM:CODEREVIEW does this transfer responsability? if it does the interface is wrong. If it does not than //we have a tricky issue as normally inmsg is a pointer without responsablity, so we may need to delete it //and set it to NULL here. mw->setPayLoad(inmsg); return mw; } } return 0; //This should not hapen; }
int HistoryKeeper::addChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt, bool isSent) { int chat_id = getChatID(chat, ctSingle).first; int sender_id = getAliasID(sender); db->exec("BEGIN TRANSACTION;"); db->exec(QString("INSERT INTO history (timestamp, chat_id, sender, message) ") + QString("VALUES (%1, %2, %3, '%4');") .arg(dt.toMSecsSinceEpoch()).arg(chat_id).arg(sender_id).arg(wrapMessage(message))); db->exec(QString("INSERT INTO sent_status (status) VALUES (%1);").arg(isSent)); db->exec("COMMIT TRANSACTION;"); messageID++; return messageID; }