int Window::listen_event(int event_mask, grEvent* grevent) { acquire_sem(_locker); _event_queue.Lock(); BMessage* m = _event_queue.NextMessage(); if (!_event_queue.IsEmpty()) release_sem(_locker); _event_queue.Unlock(); grevent->type = gr_key_down; grevent->key = (grKey)m->what; delete m; return 0; }
void ArpRemoteTerminal::MessageReceived(BMessage *message) { ArpD(cdb << ADH << "ArpRemoteTerminal::MessageReceived: " << *message << endl); switch( message->what ) { case TERM_XFER_TEXT_MSG: { #if 1 const ichar* txt = NULL; long len=0; int32 idx=0; while( message->FindData("text", B_ASCII_TYPE, idx, (const void**)&txt, &len) == B_NO_ERROR ) { if( txt && len > 0 ) { Emulator().EmulateToTTY(txt,len); } idx++; } message->SendReply(B_NO_REPLY); #else int32 recpos = 0; BMessage* curmsg = Window()->DetachCurrentMessage(); BMessageQueue* queue = Window()->MessageQueue(); while( curmsg ) { ichar* txt = NULL; long len=0; int32 idx=0; while( curmsg->FindData("text", B_ASCII_TYPE, idx, &txt, &len) == B_NO_ERROR ) { if( txt ) { if( recpos + len > sizeof(receiveBuffer) ) { if( recpos > 0 ) { Emulator().EmulateToTTY(&receiveBuffer[0],recpos); recpos = 0; } } if( len > sizeof(receiveBuffer) ) { Emulator().EmulateToTTY(txt,len); } else { memcpy(&receiveBuffer[recpos],txt,len); recpos += len; } } idx++; } delete curmsg; curmsg = NULL; if( queue ) { curmsg = queue->FindMessage((int32)0); if( curmsg && curmsg->what == TERM_XFER_TEXT_MSG ) { curmsg = queue->NextMessage(); } else curmsg = NULL; } } if( recpos > 0 ) { Emulator().EmulateToTTY(&receiveBuffer[0],recpos); } return; #endif } break; case TERM_RESET_MSG: { bool hard = false; if( message->FindBool("hard", &hard) != B_OK ) hard = false; Emulator().Reset(hard); TermClean(); // HACK: The emulator often changes the terminal's mode // flags after calling its reset, leaving any active // settings view with incorrect settings. Until we can // do better at tracking state changes, for this situation // send another update to the settings view. if( HaveWatchers() ) { BMessage config; if( GetConfiguration(&config) == B_NO_ERROR ) { ArpD(cdb << ADH << "Reporting change: " << config << endl); ReportChange(&config); } } } break; case TERM_START_SESSION_MSG: { StartSession(); TermClean(); Owner().SendMessage(message); } break; case TERM_END_SESSION_MSG: { EndSession(); TermClean(); Owner().SendMessage(message); } break; case TERM_REQUEST_STATUS_MSG: { int32 rows,cols; TermGetSize(&rows,&cols); SendSizeMsg(rows,cols); SendEmulatorsMsg(); } break; case TERM_WINDOW_SIZE_MSG: { int32 rows,cols; TermGetFixedSize(&rows,&cols); message->FindInt32("rows",&rows); message->FindInt32("columns",&cols); TermSetFixedSize(rows,cols); } break; case TERM_SELECT_EMULATION_MSG: { BMenuItem* item = NULL; if( message->FindPointer("source",(void**)&item) ) item = NULL; BMenu* menu = NULL; if( item ) menu = item->Menu(); int32 num=0; type_code type; if( !message->GetInfo("name",&type,&num) ) { for( int i=0; i<num; i++ ) { const char* str; if( !message->FindString("name",i,&str) ) { delete SetEmulator(str); if( !IsDefaultEmulator() ) { if( menu ) CheckEmulationMenu(menu); return; } } } } if( menu ) CheckEmulationMenu(menu); } break; case ARP_PUT_CONFIGURATION_MSG: { BMessage config; if( message->FindMessage("settings",&config) == B_NO_ERROR ) { PutConfiguration(&config); } else { inherited::MessageReceived(message); } } break; case TERM_ADD_WATCHER_MSG: { BMessenger w; if( message->FindMessenger("watch",&w) == B_NO_ERROR ) { AddWatcher(w); BMessage config; if( GetConfiguration(&config) == B_NO_ERROR ) { ReportChange(&config, &w); } } else { inherited::MessageReceived(message); } } break; case TERM_REM_WATCHER_MSG: { BMessenger w; if( message->FindMessenger("watch",&w) == B_NO_ERROR ) { RemWatcher(w); } else { inherited::MessageReceived(message); } } break; default: inherited::MessageReceived(message); } }