iWARPEM_Status_t InsertConnectRequest( const iWARPEM_StreamId_t aClientId, const iWARPEM_Message_Hdr_t *aHdr, const iWARPEM_Private_Data_t *aPrivData, const MultiplexedConnectionType *aClientEP ) { return InsertMessage( aClientId, aHdr, (char*)aPrivData, sizeof( iWARPEM_Private_Data_t )); }
CConsole::CConsole() { m_bToggle = false; m_bVisible = false; m_fVisibleFrac = 0.0f; m_szBuffer = new wchar_t[CONSOLE_BUFFER_SIZE]; FlushBuffer(); m_iMsgHistPos = 1; m_charsPerPage = 0; InsertMessage(L"[ 0 A.D. Console v0.14 ]"); InsertMessage(L""); }
iWARPEM_Status_t InsertAcceptResponse( iWARPEM_StreamId_t aClientID, iWARPEM_Private_Data_t *aPrivData ) { iWARPEM_Message_Hdr_t msg; int slen = 0; msg.mMsg_Type = iWARPEM_SOCKET_CONNECT_RESP_TYPE; msg.mTotalDataLen = sizeof( iWARPEM_Private_Data_t ); return InsertMessage( aClientID, &msg, (char*)aPrivData, msg.mTotalDataLen ); }
CConsole::CConsole() { m_bToggle = false; m_bVisible = false; m_fVisibleFrac = 0.0f; m_szBuffer = new wchar_t[CONSOLE_BUFFER_SIZE]; FlushBuffer(); m_iMsgHistPos = 1; m_charsPerPage = 0; m_prevTime = 0.0; m_bCursorVisState = true; m_cursorBlinkRate = 0.5; InsertMessage("[ 0 A.D. Console v0.14 ]"); InsertMessage(""); }
iWARPEM_Status_t InsertDisconnectResponse( const iWARPEM_StreamId_t aClientId ) { BegLogLine( 1 ) << "Inserting DISCONNECT Response for client: " << aClientId << EndLogLine; iWARPEM_Message_Hdr_t Hdr; Hdr.mMsg_Type = iWARPEM_DISCONNECT_RESP_TYPE; Hdr.mTotalDataLen = 0; char *data = (char*)&Hdr.mTotalDataLen; return InsertMessage( aClientId, &Hdr, data, 0 ); }
iWARPEM_Status_t InsertCloseRequest( const iWARPEM_StreamId_t aClientId ) { BegLogLine( 1 ) << "Inserting CLOSE Request for client: " << aClientId << EndLogLine; iWARPEM_Message_Hdr_t Hdr; Hdr.mMsg_Type = iWARPEM_SOCKET_CLOSE_REQ_TYPE; Hdr.mTotalDataLen = 0; char *data = (char*)&Hdr.mTotalDataLen; return InsertMessage( aClientId, &Hdr, data, 0 ); }
static void InsertMessage( DebugSource source, DebugType type, GLuint id, DebugSeverity severity, const GLchar (&message)[N] ) { InsertMessage( source, type, id, severity, N, message ); }
/// Inserts a new message into the debug output static void InsertMessage( DebugSource source, DebugType type, GLuint id, DebugSeverity severity, StrCRef message ) { InsertMessage( source, type, id, severity, message.size(), message.c_str() ); }
void CConsole::ProcessBuffer(const wchar_t* szLine) { if (szLine == NULL) return; if (wcslen(szLine) <= 0) return; ENSURE(wcslen(szLine) < CONSOLE_BUFFER_SIZE); m_deqBufHistory.push_front(szLine); SaveHistory(); // Do this each line for the moment; if a script causes // a crash it's a useful record. // Process it as JavaScript jsval rval = g_ScriptingHost.ExecuteScript(szLine, L"Console"); if (!JSVAL_IS_VOID(rval)) InsertMessage(L"%ls", g_ScriptingHost.GetScriptInterface().ToString(rval).c_str()); }
void CConsole::ProcessBuffer(const wchar_t* szLine) { if (szLine == NULL) return; if (wcslen(szLine) <= 0) return; ENSURE(wcslen(szLine) < CONSOLE_BUFFER_SIZE); m_deqBufHistory.push_front(szLine); SaveHistory(); // Do this each line for the moment; if a script causes // a crash it's a useful record. // Process it as JavaScript CScriptVal rval; g_GUI->GetActiveGUI()->GetScriptInterface()->Eval(szLine, rval); if (!rval.undefined()) InsertMessage(L"%ls", g_GUI->GetActiveGUI()->GetScriptInterface()->ToString(rval.get()).c_str()); }
void CConsole::ProcessBuffer(const wchar_t* szLine) { shared_ptr<ScriptInterface> pScriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface(); JSContext* cx = pScriptInterface->GetContext(); JSAutoRequest rq(cx); if (szLine == NULL) return; if (wcslen(szLine) <= 0) return; ENSURE(wcslen(szLine) < CONSOLE_BUFFER_SIZE); m_deqBufHistory.push_front(szLine); SaveHistory(); // Do this each line for the moment; if a script causes // a crash it's a useful record. // Process it as JavaScript JS::RootedValue rval(cx); pScriptInterface->Eval(szLine, &rval); if (!rval.isUndefined()) InsertMessage(pScriptInterface->ToString(&rval)); }
/** * 好友广播消息. */ void UdpData::SomeoneBcstmsg() { GroupInfo *grpinf; PalInfo *pal; uint32_t commandno, packetno; char *text; /* 如果对方兼容iptux协议,则无须再转换编码 */ pal = cthrd.GetPalFromList(ipv4); if (!pal || !FLAG_ISSET(pal->flags, 0)) ConvertEncode(pal ? pal->encode : progdt.encode); /* 确保好友在线,并对编码作出适当调整 */ pal = AssertPalOnline(); if (strcasecmp(pal->encode, encode ? encode : "utf-8") != 0) { g_free(pal->encode); pal->encode = g_strdup(encode ? encode : "utf-8"); } /* 检查此消息是否过时 */ packetno = iptux_get_dec_number(buf, ':', 1); if (packetno <= pal->packetn) return; pal->packetn = packetno; /* 插入消息&在消息队列中注册 */ text = ipmsg_get_attach(buf, ':', 5); if (text && *text != '\0') { commandno = iptux_get_dec_number(buf, ':', 4); /*/* 插入消息 */ switch (GET_OPT(commandno)) { case IPTUX_BROADCASTOPT: InsertMessage(pal, GROUP_BELONG_TYPE_BROADCAST, text); break; case IPTUX_GROUPOPT: InsertMessage(pal, GROUP_BELONG_TYPE_GROUP, text); break; case IPTUX_SEGMENTOPT: InsertMessage(pal, GROUP_BELONG_TYPE_SEGMENT, text); break; case IPTUX_REGULAROPT: default: InsertMessage(pal, GROUP_BELONG_TYPE_REGULAR, text); break; } /*/* 注册消息 */ pthread_mutex_lock(cthrd.GetMutex()); switch (GET_OPT(commandno)) { case IPTUX_BROADCASTOPT: grpinf = cthrd.GetPalBroadcastItem(pal); break; case IPTUX_GROUPOPT: grpinf = cthrd.GetPalGroupItem(pal); break; case IPTUX_SEGMENTOPT: grpinf = cthrd.GetPalSegmentItem(pal); break; case IPTUX_REGULAROPT: default: grpinf = cthrd.GetPalRegularItem(pal); break; } if (!grpinf->dialog && !cthrd.MsglineContainItem(grpinf)) cthrd.PushItemToMsgline(grpinf); pthread_mutex_unlock(cthrd.GetMutex()); } g_free(text); /* 播放提示音 */ if (FLAG_ISSET(progdt.sndfgs, 1)) sndsys.Playing(progdt.msgtip); }
/** * 好友发送消息. * */ void UdpData::SomeoneSendmsg() { GroupInfo *grpinf; PalInfo *pal; Command cmd; uint32_t commandno, packetno; char *text; pthread_t pid; DialogPeer *dlgpr; GtkWidget *window; /* 如果对方兼容iptux协议,则无须再转换编码 */ pal = cthrd.GetPalFromList(ipv4); if (!pal || !FLAG_ISSET(pal->flags, 0)) ConvertEncode(pal ? pal->encode : progdt.encode); /* 确保好友在线,并对编码作出适当调整 */ pal = AssertPalOnline(); if (strcasecmp(pal->encode, encode ? encode : "utf-8") != 0) { g_free(pal->encode); pal->encode = g_strdup(encode ? encode : "utf-8"); } /* 回复好友并检查此消息是否过时 */ commandno = iptux_get_dec_number(buf, ':', 4); packetno = iptux_get_dec_number(buf, ':', 1); if (commandno & IPMSG_SENDCHECKOPT) cmd.SendReply(cthrd.UdpSockQuote(), pal, packetno); if (packetno <= pal->packetn) return; pal->packetn = packetno; /* 插入消息&在消息队列中注册 */ text = ipmsg_get_attach(buf, ':', 5); if (text && *text != '\0') { /*/* 插入消息 */ // if ((commandno & IPMSG_BROADCASTOPT) || (commandno & IPMSG_MULTICASTOPT)) // InsertMessage(pal, GROUP_BELONG_TYPE_BROADCAST, text); // else InsertMessage(pal, GROUP_BELONG_TYPE_REGULAR, text); } g_free(text); /*/* 注册消息 */ pthread_mutex_lock(cthrd.GetMutex()); // if ((commandno & IPMSG_BROADCASTOPT) || (commandno & IPMSG_MULTICASTOPT)) // grpinf = cthrd.GetPalBroadcastItem(pal); // else grpinf = cthrd.GetPalRegularItem(pal); if (!grpinf->dialog && !cthrd.MsglineContainItem(grpinf)) cthrd.PushItemToMsgline(grpinf); pthread_mutex_unlock(cthrd.GetMutex()); /* 标记位处理 先处理底层数据,后面显示窗口*/ if (commandno & IPMSG_FILEATTACHOPT) { if ((commandno & IPTUX_SHAREDOPT) && (commandno & IPTUX_PASSWDOPT)) { pthread_create(&pid, NULL, ThreadFunc(ThreadAskSharedPasswd), pal); pthread_detach(pid); } else RecvPalFile(); } window = GTK_WIDGET(grpinf->dialog); //这里不知道为什么运行时一直会提示window不是object dlgpr = (DialogPeer *)(g_object_get_data(G_OBJECT(window),"dialog")); if(grpinf->dialog) dlgpr->ShowDialogPeer(dlgpr); /* 是否直接弹出聊天窗口 */ if (FLAG_ISSET(progdt.flags, 7)) { gdk_threads_enter(); if (!(grpinf->dialog)) { // switch (grpinf->type) { // case GROUP_BELONG_TYPE_REGULAR: DialogPeer::PeerDialogEntry(grpinf); // break; // case GROUP_BELONG_TYPE_SEGMENT: // case GROUP_BELONG_TYPE_GROUP: // case GROUP_BELONG_TYPE_BROADCAST: // DialogGroup::GroupDialogEntry(grpinf); // default: // break; // } } else { gtk_window_present(GTK_WINDOW(grpinf->dialog)); } gdk_threads_leave(); } /* 播放提示音 */ if (FLAG_ISSET(progdt.sndfgs, 1)) sndsys.Playing(progdt.msgtip); }
void CConsole::ReceivedChatMessage(const wchar_t *szSender, const wchar_t *szMessage) { InsertMessage(L"%ls: %ls", szSender, szMessage); }
iWARPEM_Status_t InsertMessageVector( const iWARPEM_StreamId_t aClientId, struct iovec *aIOV, int aIOV_Count, int *aLen, bool aFirstIsHeader = true ) { iWARPEM_Status_t status = IWARPEM_SUCCESS; int i=0; *aLen = 0; // only create the msg header for the first vector iWARPEM_Message_Hdr_t *hdr = NULL; if( aFirstIsHeader ) { hdr = (iWARPEM_Message_Hdr_t*)aIOV[ 0 ].iov_base; *aLen += sizeof( iWARPEM_Message_Hdr_t ); i++; } int send_size = aIOV[ i ].iov_len; if( GetSendSpace() < send_size ) { status = FlushSendBuffer(); BegLogLine( FXLOG_IT_API_O_SOCKETS_MULTIPLEX_LOG ) << "Remaining space is too small. Sending existing data first.." << " req_size: " << send_size << " rem_space: " << GetSendSpace() << EndLogLine; } status = InsertMessage( aClientId, hdr, (char*)(aIOV[ i ].iov_base), aIOV[ i ].iov_len, true ); if( status == IWARPEM_SUCCESS ) *aLen += send_size; pthread_spin_lock( &mAccessLock ); i++; for( ; (i < aIOV_Count ) && ( status == IWARPEM_SUCCESS ); i++ ) { send_size = aIOV[ i ].iov_len; StrongAssertLogLine( send_size < GetSendSpace() ) << "Message vector entry " << i << " doesn't fit into send buffer. Space: " << GetSendSpace() << " requested: " << send_size << " already inserted: " << *aLen << EndLogLine; mSendBuffer->AddDataContigous( (const char*)aIOV[ i ].iov_base, aIOV[ i ].iov_len ); *aLen += send_size; } pthread_spin_unlock( &mAccessLock ); BegLogLine( FXLOG_IT_API_O_SOCKETS_MULTIPLEX_LOG ) << "Inserted Message Vector to send buffer: " << " ClientId: " << aClientId << " entries: " << aIOV_Count << " msg_size: " << *aLen << " bytes in buffer: " << mSendBuffer->GetDataLen() << EndLogLine; // initiate a send of data once we've filled up the buffer beyond a threshold if( mSendBuffer->FlushRecommended() ) status = FlushSendBuffer(); return status; }