⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qwscommand_qws.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        case QWSCommand::RegionName:            typeStr = "RegionName";            break;        case QWSCommand::Identify:            typeStr = "Identify";            break;        case QWSCommand::GrabKeyboard:            typeStr = "GrabKeyboard";            break;        case QWSCommand::RepaintRegion:            typeStr = "RepaintRegion";            break;        case QWSCommand::IMMouse:            typeStr = "IMMouse";            break;        case QWSCommand::IMUpdate:            typeStr = "IMUpdate";            break;        case QWSCommand::IMResponse:            typeStr = "IMResponse";            break;        case QWSCommand::Font:            typeStr = "Font";            break;        case QWSCommand::Unknown:        default:            typeStr = "Unknown";            break;    }    return typeStr;}/********************************************************************* * * Functions to read/write commands on/from a socket * *********************************************************************/#ifndef QT_NO_QWS_MULTIPROCESSvoid qws_write_command(QIODevice *socket, int type, char *simpleData, int simpleLen,                       char *rawData, int rawLen){#ifdef QWSCOMMAND_DEBUG    if (simpleLen) qDebug() << "WRITE simpleData " << QWSHexDump(simpleData, simpleLen);    if (rawLen > 0) qDebug() << "WRITE rawData " << QWSHexDump(rawData, rawLen);#endif#ifndef QT_NO_SXE    QTransportAuth *a = QTransportAuth::getInstance();    // ###### as soon as public API can be modified get rid of horrible casts    QIODevice *ad = a->passThroughByClient(reinterpret_cast<QWSClient*>(socket));    if (ad)        socket = ad;#endif    qws_write_uint(socket, type);    if (rawLen > MAX_COMMAND_SIZE) {        qWarning("qws_write_command: Message of size %d too big. "                 "Truncated to %d", rawLen, MAX_COMMAND_SIZE);        rawLen = MAX_COMMAND_SIZE;    }    qws_write_uint(socket, rawLen == -1 ? 0 : rawLen);    // Add total length of command here, allowing for later command expansion...    // qws_write_uint(socket, rawLen == -1 ? 0 : rawLen);    if (simpleData && simpleLen)        socket->write(simpleData, simpleLen);    if (rawLen && rawData)        socket->write(rawData, rawLen);}/*  command format: [type][rawLen][simpleData][rawData]  type is already read when entering this function*/bool qws_read_command(QIODevice *socket, char *&simpleData, int &simpleLen,                      char *&rawData, int &rawLen, int &bytesRead){    // read rawLen    if (rawLen == -1) {        rawLen = qws_read_uint(socket);        if (rawLen == -1)            return false;    }    // read simpleData, assumes socket is capable of buffering all the data    if (simpleLen && !rawData) {        if (socket->bytesAvailable() < uint(simpleLen))            return false;        int tmp = socket->read(simpleData, simpleLen);        Q_ASSERT(tmp == simpleLen);        Q_UNUSED(tmp);    }    if (rawLen > MAX_COMMAND_SIZE) {        socket->close();        qWarning("qws_read_command: Won't read command of length %d, "                 "connection closed.", rawLen);        return false;    }    // read rawData    if (rawLen && !rawData) {        rawData = new char[rawLen];        bytesRead = 0;    }    if (bytesRead < rawLen && socket->bytesAvailable())        bytesRead += socket->read(rawData + bytesRead, rawLen - bytesRead);    return (bytesRead == rawLen);}#endif/********************************************************************* * * QWSCommand base class - only use derived classes from that * *********************************************************************/QWSProtocolItem::~QWSProtocolItem() {    if (deleteRaw)        delete []rawDataPtr;}#ifndef QT_NO_QWS_MULTIPROCESSvoid QWSProtocolItem::write(QIODevice *s) {#ifdef QWSCOMMAND_DEBUG    if (!qwsServer)        qDebug() << "QWSProtocolItem::write sending type " << static_cast<QWSCommand::Type>(type);    else        qDebug() << "QWSProtocolItem::write sending event " << (type < N_EVENTS ? eventNames[type] : "unknown");#endif    qws_write_command(s, type, simpleDataPtr, simpleLen, rawDataPtr, rawLen);}bool QWSProtocolItem::read(QIODevice *s) {#ifdef QWSCOMMAND_DEBUG    QLatin1String reread( (rawLen == -1) ? "" : "REREAD");    if (qwsServer)        qDebug() << "QWSProtocolItem::read reading type " << static_cast<QWSCommand::Type>(type) << reread;    else        qDebug() << "QWSProtocolItem::read reading event " << (type < N_EVENTS ? eventNames[type] : "unknown") << reread;    //qDebug("QWSProtocolItem::read reading event %s", type < N_EVENTS ? eventNames[type] : "unknown");#endif    bool b = qws_read_command(s, simpleDataPtr, simpleLen, rawDataPtr, rawLen, bytesRead);    if (b) {        setData(rawDataPtr, rawLen, false);        deleteRaw = true;    }#ifdef QWSCOMMAND_DEBUG    else    {        qDebug() << "error in reading command " << static_cast<QWSCommand::Type>(type);    }#endif    return b;}#endif // QT_NO_QWS_MULTIPROCESSvoid QWSProtocolItem::copyFrom(const QWSProtocolItem *item) {    if (this == item)        return;    simpleLen = item->simpleLen;    memcpy(simpleDataPtr, item->simpleDataPtr, simpleLen);    setData(item->rawDataPtr, item->rawLen);}void QWSProtocolItem::setData(const char *data, int len, bool allocateMem) {    if (deleteRaw)        delete [] rawDataPtr;    if (!data || len <= 0) {        rawDataPtr = 0;        rawLen = 0;        return;    }    if (allocateMem) {        rawDataPtr = new char[len];        memcpy(rawDataPtr, data, len);        deleteRaw = true;    } else {        rawDataPtr = const_cast<char *>(data);        deleteRaw = false;    }    rawLen = len;}QWSCommand *QWSCommand::factory(int type){    QWSCommand *command = 0;    switch (type) {    case QWSCommand::Create:        command = new QWSCreateCommand;        break;    case QWSCommand::Shutdown:        command = new QWSCommand(type, 0, 0);        break;    case QWSCommand::Region:        command = new QWSRegionCommand;        break;    case QWSCommand::RegionMove:        command = new QWSRegionMoveCommand;        break;    case QWSCommand::RegionDestroy:        command = new QWSRegionDestroyCommand;        break;    case QWSCommand::AddProperty:        command = new QWSAddPropertyCommand;        break;    case QWSCommand::SetProperty:        command = new QWSSetPropertyCommand;        break;    case QWSCommand::RemoveProperty:        command = new QWSRemovePropertyCommand;        break;    case QWSCommand::GetProperty:        command = new QWSGetPropertyCommand;        break;    case QWSCommand::SetSelectionOwner:        command = new QWSSetSelectionOwnerCommand;        break;    case QWSCommand::RequestFocus:        command = new QWSRequestFocusCommand;        break;    case QWSCommand::ChangeAltitude:        command = new QWSChangeAltitudeCommand;        break;    case QWSCommand::SetOpacity:        command = new QWSSetOpacityCommand;        break;    case QWSCommand::DefineCursor:        command = new QWSDefineCursorCommand;        break;    case QWSCommand::SelectCursor:        command = new QWSSelectCursorCommand;        break;    case QWSCommand::GrabMouse:        command = new QWSGrabMouseCommand;        break;    case QWSCommand::GrabKeyboard:        command = new QWSGrabKeyboardCommand;        break;#ifndef QT_NO_SOUND    case QWSCommand::PlaySound:        command = new QWSPlaySoundCommand;        break;#endif#ifndef QT_NO_COP    case QWSCommand::QCopRegisterChannel:        command = new QWSQCopRegisterChannelCommand;        break;    case QWSCommand::QCopSend:        command = new QWSQCopSendCommand;        break;#endif    case QWSCommand::RegionName:        command = new QWSRegionNameCommand;        break;    case QWSCommand::Identify:        command = new QWSIdentifyCommand;        break;    case QWSCommand::RepaintRegion:        command = new QWSRepaintRegionCommand;        break;#ifndef QT_NO_QWS_INPUTMETHODS    case QWSCommand::IMUpdate:        command = new QWSIMUpdateCommand;        break;    case QWSCommand::IMMouse:        command = new QWSIMMouseCommand;        break;    case QWSCommand::IMResponse:        command = new QWSIMResponseCommand;        break;#endif    case QWSCommand::PositionCursor:        command = new QWSPositionCursorCommand;        break;#ifndef QT_NO_QWSEMBEDWIDGET    case QWSCommand::Embed:        command = new QWSEmbedCommand;        break;#endif    case QWSCommand::Font:        command = new QWSFontCommand;        break;    default:        qWarning("QWSCommand::factory : Type error - got %08x!", type);    }    return command;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -