//----------------------------------------------------------// // CPacket::GetMessages //----------------------------------------------------------// CPacket::Error::Enum CPacket::GetMessages(TMessageList& tempList) { //-- DataBuffer should have exactly m_HeaderV1.m_nMessages inside it. tempList.clear(); u16 nProcessedMessages = 0; CPacketSerializer messageDeserializer(ISerializer::Mode::Deserializing, m_DataBuffer.Buffer(), m_DataBuffer.UsedSize()); CPacketSerializer::Error::Enum eSerError = CPacketSerializer::Error::Ok; while ( (CPacketSerializer::Error::Ok == eSerError) && (messageDeserializer.GetOffset() < messageDeserializer.GetSize()) ) { CMessage::Type nMessageType = CMessage::kTypeUnknown; if (IS_ZERO(messageDeserializer.SerializeU32(nMessageType, 'type'))) { return Error::Serializer; } CMessage* pMessage = CMessageFactory::CreateType(nMessageType); if (IS_NULL_PTR(pMessage)) { return Error::ProtocolMismatch; } pMessage->Serialize(messageDeserializer); eSerError = messageDeserializer.GetError(); if (CPacketSerializer::Error::Ok != eSerError) { return Error::Serializer; } SysSmartPtr<CMessage> pSmart(pMessage); tempList.push_back(pSmart); ++nProcessedMessages; } //-- Sanity tests //-- messageSerializer should have consumed all its bytes. assert(messageDeserializer.GetOffset() == messageDeserializer.GetSize()); if (messageDeserializer.GetOffset() != messageDeserializer.GetSize()) { return Error::SanityFail; } //-- We should have processed exactly the right number of messages. assert(nProcessedMessages == GetMessageCount()); if (nProcessedMessages != GetMessageCount()) { return Error::SanityFail; } return Error::Ok; }
UIdArray MMessagesDataObject::GetMessages() const { UIdArray messages; size_t count = GetMessageCount(); messages.Alloc(count); for ( size_t n = 0; n < count; n++ ) { messages.Add(GetMessageUId(n)); } return messages; }
void GUIScreenMessageAllocator::Process() { if(GetMessageCount() > 0) { static int startup_time = current_time; tick2 = current_time - startup_time; if(tick2 - tick1 >= 1000) { tick1 = tick2; for(vector<GUIScreenMessage>::iterator it = messages.begin(); it != messages.end(); it++) { GUIScreenMessage* msg = &(*it); msg->time_remains--; if(msg->time_remains <= 0) Delete(msg); } UINT i = 0; while(i < GetMessageCount()) { if(messages[i].time_remains <= 0) { messages.erase(messages.begin()+i); SetMessageCount(GetMessageCount()-1); continue; } else i++; } } } }
bool NetPacket::IsValid() { //validate myself then validate others //BinaryBufferParser bp = BinaryBufferParser(buffer, curSize); unsigned short ackID = GetAckID(); UNUSED(ackID); Byte messageCount = GetMessageCount(); // if (ackID == 0xffff) { // return true; // } int validMessageCount = 0; for(int i = 0; i < messageCount; i++){ BinaryBufferParser bp(readMessagesPtr, curSize); unsigned short messageLen = bp.ReadNextUShort(); Byte messageID = bp.ReadNextUChar(); if (messageLen < MESSAGE_MTU) { if (IsNetMessageIDInRegistry(messageID)) { validMessageCount++; } } readMessagesPtr += messageLen; //make sure it ends at packetLength //everything after that in the buffer is messages //validate each messageIDsocketNetPacketQueue->DequeueRead(); } //add all message lengths + 3 should be packet length //reset read messages readMessagesPtr = buffer + GetHeaderLength(); if (validMessageCount == messageCount) { return true; } return false; }
void Print_ClientRun(void) { char buffer[80]; if ((client_obj.activity == _RUNNING_) || (client_obj.activity == _READY_)) { sprintf(buffer, "Messages x%d recvd\n",GetMessageCount()); if (client_obj.activity == _RUNNING_) Draw_TString(_NET_SCREEN_X, _NET_SCREEN_Y1,"Client Running"); else Draw_TString(_NET_SCREEN_X, _NET_SCREEN_Y1,"Client Waiting"); Draw_TString(_NET_SCREEN_X, _NET_SCREEN_Y2,buffer); } // end of the if } // end of the function
//----------------------------------------------------------// // CPacket::Validate //----------------------------------------------------------// //-- Description // Basic valid data test on header. Returns current header // version if header is valid. //----------------------------------------------------------// CPacket::Version::Enum CPacket::Validate(void) const { switch (m_nVersion) { case Version::V1: { if ( (GetDataSize() > 0) && (GetMessageCount() > 0) ) { return (Version::Enum)m_nVersion; } } break; default: break; } return Version::Unknown; }
void GUIScreenMessageAllocator::Draw() { static const font_t* font = FontByName(LOG_SCREEN_FONT); static const int left = cfg.scr_width / 2 - LOG_SCREEN_MARGIN; if(GetMessageCount() > 0) { UINT Count = 0; for(vector<GUIScreenMessage>::iterator it = messages.begin(); it != messages.end(); it++) { Count++; GUIScreenMessage msg = *it; COLOR4 c = DEFAULT_SCREEN_MESSAGE_COLOR; glColor4ub(c.r, c.g, c.b, c.a); PrintText(msg.message, font, left, LOG_SCREEN_Y + Count * LOG_SCREEN_DY); } } }
void DrawInputBar(InputWindow* inputWindow, int iCursorPos, Messages * msgup, Messages *msgdown ,unsigned int * iheight, unsigned int *iwidth) { int i; char *strUp[MAX_MESSAGE_COUNT]; char *strDown[MAX_MESSAGE_COUNT]; int posUpX[MAX_MESSAGE_COUNT], posUpY[MAX_MESSAGE_COUNT]; int posDownX[MAX_MESSAGE_COUNT], posDownY[MAX_MESSAGE_COUNT]; int oldHeight = *iheight, oldWidth = *iwidth; int newHeight = 0, newWidth = 0; int cursor_pos=0; int inputWidth = 0, outputWidth = 0; int outputHeight = 0; FcitxInputState* input = &inputWindow->owner->owner->input; FcitxInstance* instance = inputWindow->owner->owner; int iChar = iCursorPos; int strWidth = 0, strHeight = 0; int fontSize = FONTHEIGHT; if (!IsMessageChanged(msgup) && !IsMessageChanged(msgdown)) return; inputWidth = 0; strHeight = FONTHEIGHT; for (i = 0; i < GetMessageCount(msgup) ; i++) { char *trans = ProcessOutputFilter(instance, GetMessageString(msgup, i)); if (trans) strUp[i] = trans; else strUp[i] = GetMessageString(msgup, i); posUpX[i] = MarginLeft + inputWidth; strWidth = StringWidth(inputWindow->dpy, inputWindow->owner->xftfont, strUp[i]); posUpY[i] = MarginTop + InputPos - strHeight; inputWidth += strWidth; if (input->bShowCursor) { int length = strlen(GetMessageString(msgup, i)); if (iChar >= 0) { if (iChar < length) { char strTemp[MESSAGE_MAX_LENGTH]; char *strGBKT = NULL; strncpy(strTemp, strUp[i], iChar); strTemp[iChar] = '\0'; strGBKT = strTemp; strWidth = StringWidth(inputWindow->dpy, inputWindow->owner->xftfont, strGBKT); cursor_pos= posUpX[i] + strWidth + 2; } iChar -= length; } } } if (iChar >= 0) cursor_pos = inputWidth + MarginLeft; outputWidth = 0; outputHeight = 0; int currentX = 0; for (i = 0; i < GetMessageCount(msgdown) ; i++) { char *trans = ProcessOutputFilter(instance, GetMessageString(msgdown, i)); if (trans) strDown[i] = trans; else strDown[i] = GetMessageString(msgdown, i); if (inputWindow->owner->bVerticalList) /* vertical */ { if (GetMessageType(msgdown, i) == MSG_INDEX) { if (currentX > outputWidth) outputWidth = currentX; if (i != 0) { outputHeight += fontSize + 2; currentX = 0; } } posDownX[i] = MarginLeft + currentX; strWidth = StringWidth(inputWindow->dpy, inputWindow->owner->xftfont, strDown[i]); currentX += strWidth; posDownY[i] = MarginTop + OutputPos + outputHeight - strHeight; } else /* horizontal */ { posDownX[i] = MarginLeft + outputWidth; strWidth = StringWidth(inputWindow->dpy, inputWindow->owner->xftfont, strDown[i]); posDownY[i] = MarginTop + OutputPos - strHeight; outputWidth += strWidth; } } if (inputWindow->owner->bVerticalList && currentX > outputWidth) outputWidth = currentX; newHeight = MarginTop + OutputPos + outputHeight + MarginBottom; newWidth = (inputWidth<outputWidth)?outputWidth:inputWidth; newWidth+=MarginLeft+MarginRight; /* round to ROUND_SIZE in order to decrease resize */ newWidth = (newWidth / ROUND_SIZE) * ROUND_SIZE + ROUND_SIZE; //输入条长度应该比背景图长度要长,比最大长度要短 newWidth=(newWidth>=INPUT_BAR_MAX_WIDTH)?INPUT_BAR_MAX_WIDTH:newWidth; if (inputWindow->owner->bVerticalList) /* vertical */ { newWidth = (newWidth < INPUT_BAR_VMIN_WIDTH)?INPUT_BAR_VMIN_WIDTH:newWidth; } else { newWidth = (newWidth < INPUT_BAR_HMIN_WIDTH)?INPUT_BAR_HMIN_WIDTH:newWidth; } *iwidth = newWidth; *iheight = newHeight; if (oldHeight != newHeight || oldWidth != newWidth) { DrawResizableBackground(inputWindow->owner, inputWindow->pixmap2, newHeight, newWidth, inputWindow->owner->backcolor, inputWindow->owner->bordercolor, inputWindow->pixmap2_gc ); } XGCValues gcvalues; GC gc = XCreateGC(inputWindow->dpy, inputWindow->pixmap, 0, &gcvalues); XCopyArea( inputWindow->dpy, inputWindow->pixmap2, inputWindow->pixmap, gc, 0, 0, inputWindow->iInputWindowWidth, inputWindow->iInputWindowHeight, 0, 0 ); XFreeGC(inputWindow->dpy, gc); if (input->bShowCursor ) { //画向前向后箭头 } for (i = 0; i < GetMessageCount(msgup) ; i++) { OutputString(inputWindow->dpy, inputWindow->xftDraw, inputWindow->pixmap, inputWindow->owner->xftfont, strUp[i], posUpX[i], posUpY[i], inputWindow->owner->fontColor[GetMessageType(msgup, i)]); if (strUp[i] != GetMessageString(msgup, i)) free(strUp[i]); } for (i = 0; i < GetMessageCount(msgdown) ; i++) { OutputString(inputWindow->dpy, inputWindow->xftDraw, inputWindow->pixmap, inputWindow->owner->xftfont, strDown[i], posDownX[i], posDownY[i], inputWindow->owner->fontColor[GetMessageType(msgdown, i)]); if (strDown[i] != GetMessageString(msgdown, i)) free(strDown[i]); } //画光标 if (input->bShowCursor ) { GC gc = LightUICreateGC(inputWindow->dpy, inputWindow->pixmap, inputWindow->owner->cursorColor); XDrawLine(inputWindow->dpy, inputWindow->pixmap, gc, cursor_pos, MarginTop + InputPos, cursor_pos, MarginTop + InputPos - fontSize - 4); XFreeGC(inputWindow->dpy, gc); } SetMessageChanged(msgup, false); SetMessageChanged(msgdown, false); }