Converted a lot of BSession use to PortLink where streamed messaging is not appropriate

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5622 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm
2003-12-07 23:24:12 +00:00
parent e0c894a088
commit 5936e65050
+138 -132
View File
@@ -233,12 +233,13 @@ BWindow::~BWindow(){
delete cmdKey; delete cmdKey;
} }
// TODO: release other dinamicaly alocated objects // TODO: release other dynamically-allocated objects
// disable pulsing // disable pulsing
SetPulseRate( 0 ); SetPulseRate( 0 );
delete session; delete session;
delete fServerLink;
delete_port( receive_port ); delete_port( receive_port );
} }
@@ -373,9 +374,9 @@ void BWindow::Minimize(bool minimize){
return; return;
Lock(); Lock();
session->WriteInt32( AS_WINDOW_MINIMIZE ); fServerLink->SetOpCode(AS_WINDOW_MINIMIZE);
session->WriteBool( minimize ); fServerLink->Attach<bool>( minimize );
session->Sync( ); fServerLink->Flush();
Unlock(); Unlock();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -385,16 +386,14 @@ status_t BWindow::SendBehind(const BWindow* window){
if (!window) if (!window)
return B_ERROR; return B_ERROR;
int32 rCode;
Lock(); Lock();
session->WriteInt32( AS_SEND_BEHIND ); PortMessage pmsg;
session->WriteInt32( _get_object_token_(window) ); fServerLink->SetOpCode( AS_SEND_BEHIND );
session->Sync(); fServerLink->Attach<int32>( _get_object_token_(window) );
session->ReadInt32( &rCode ); fServerLink->FlushWithReply(&pmsg);
Unlock(); Unlock();
return rCode == SERVER_TRUE? B_OK : B_ERROR; return (pmsg.Code() == SERVER_TRUE)? B_OK : B_ERROR;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -961,24 +960,23 @@ void BWindow::MenusEnded(){
void BWindow::SetSizeLimits(float minWidth, float maxWidth, void BWindow::SetSizeLimits(float minWidth, float maxWidth,
float minHeight, float maxHeight){ float minHeight, float maxHeight){
int32 rCode;
if (minWidth > maxWidth) if (minWidth > maxWidth)
return; return;
if (minHeight > maxHeight) if (minHeight > maxHeight)
return; return;
Lock(); Lock();
session->WriteInt32( AS_SET_SIZE_LIMITS ); PortMessage pmsg;
session->WriteFloat( fMinWindWidth );
session->WriteFloat( fMaxWindWidth ); fServerLink->Attach<int32>( AS_SET_SIZE_LIMITS );
session->WriteFloat( fMinWindHeight ); fServerLink->Attach<float>( fMinWindWidth );
session->WriteFloat( fMaxWindHeight ); fServerLink->Attach<float>( fMaxWindWidth );
session->Sync(); fServerLink->Attach<float>( fMinWindHeight );
session->ReadInt32( &rCode ); fServerLink->Attach<float>( fMaxWindHeight );
fServerLink->FlushWithReply(&pmsg);
Unlock(); Unlock();
if (rCode == SERVER_TRUE){ if (pmsg.Code() == SERVER_TRUE){
fMinWindHeight = minHeight; fMinWindHeight = minHeight;
fMinWindWidth = minWidth; fMinWindWidth = minWidth;
fMaxWindHeight = maxHeight; fMaxWindHeight = maxHeight;
@@ -1248,9 +1246,9 @@ void BWindow::Activate(bool active){
return; return;
Lock(); Lock();
session->WriteInt32( AS_ACTIVATE_WINDOW ); fServerLink->SetOpCode( AS_ACTIVATE_WINDOW );
session->WriteBool( active ); fServerLink->Attach<bool>( active );
session->Sync( ); fServerLink->Flush();
Unlock(); Unlock();
} }
@@ -1391,9 +1389,9 @@ void BWindow::SetTitle(const char* title){
// we notify the app_server so we can actually see the change // we notify the app_server so we can actually see the change
Lock(); Lock();
session->WriteInt32( AS_WINDOW_TITLE); fServerLink->SetOpCode( AS_WINDOW_TITLE );
session->WriteString( fTitle ); fServerLink->AttachString( fTitle );
session->Sync( ); fServerLink->Flush();
Unlock(); Unlock();
} }
else else
@@ -1451,19 +1449,18 @@ status_t BWindow::AddToSubset(BWindow* window){
if ( !window ) if ( !window )
return B_ERROR; return B_ERROR;
int32 rCode; PortMessage pmsg;
if (window->Feel() == B_MODAL_SUBSET_WINDOW_FEEL || if (window->Feel() == B_MODAL_SUBSET_WINDOW_FEEL ||
window->Feel() == B_FLOATING_SUBSET_WINDOW_FEEL){ window->Feel() == B_FLOATING_SUBSET_WINDOW_FEEL){
Lock(); Lock();
session->WriteInt32( AS_ADD_TO_SUBSET ); fServerLink->SetOpCode( AS_ADD_TO_SUBSET );
session->WriteInt32( _get_object_token_(window) ); fServerLink->Attach<int32>( _get_object_token_(window) );
session->Sync(); fServerLink->FlushWithReply(&pmsg);
session->ReadInt32( &rCode );
Unlock(); Unlock();
return rCode == SERVER_TRUE? B_OK : B_ERROR; return (pmsg.Code() == SERVER_TRUE)? B_OK : B_ERROR;
} }
return B_ERROR; return B_ERROR;
@@ -1475,16 +1472,15 @@ status_t BWindow::RemoveFromSubset(BWindow* window){
if ( !window ) if ( !window )
return B_ERROR; return B_ERROR;
int32 rCode; PortMessage pmsg;
Lock(); Lock();
session->WriteInt32( AS_REM_FROM_SUBSET ); fServerLink->SetOpCode( AS_REM_FROM_SUBSET );
session->WriteInt32( _get_object_token_(window) ); fServerLink->Attach<int32>( _get_object_token_(window) );
session->Sync(); fServerLink->FlushWithReply(&pmsg);
session->ReadInt32( &rCode );
Unlock(); Unlock();
return rCode == SERVER_TRUE? B_OK : B_ERROR; return ( pmsg.Code() == SERVER_TRUE)? B_OK : B_ERROR;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -1497,8 +1493,15 @@ status_t BWindow::Perform(perform_code d, void* arg){
status_t BWindow::SetType(window_type type){ status_t BWindow::SetType(window_type type){
decomposeType(type, &fLook, &fFeel); decomposeType(type, &fLook, &fFeel);
SetLook( fLook );
SetFeel( fFeel ); status_t stat1, stat2;
stat1=SetLook( fLook );
stat2=SetFeel( fFeel );
if(stat1==B_OK && stat2==B_OK)
return B_OK;
return B_ERROR;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -1511,17 +1514,16 @@ window_type BWindow::Type() const{
status_t BWindow::SetLook(window_look look){ status_t BWindow::SetLook(window_look look){
int32 rCode; PortMessage pmsg;
Lock(); Lock();
session->WriteInt32( AS_SET_LOOK ); fServerLink->SetOpCode( AS_SET_LOOK );
session->WriteInt32( (int32)look ); fServerLink->Attach<window_look>( fLook );
session->Sync(); fServerLink->FlushWithReply(&pmsg);
session->ReadInt32( &rCode );
Unlock(); Unlock();
if (rCode == SERVER_TRUE){ if(pmsg.Code() == SERVER_TRUE){
fLook = look; fLook = look;
return B_OK; return B_OK;
} }
@@ -1540,20 +1542,19 @@ status_t BWindow::SetFeel(window_feel feel){
/* TODO: See what happens when a window that is part of a subset, changes its /* TODO: See what happens when a window that is part of a subset, changes its
feel!? should it be removed from the subset??? feel!? should it be removed from the subset???
*/ */
int32 rCode; PortMessage pmsg;
Lock(); Lock();
session->WriteInt32( AS_SET_FEEL ); fServerLink->SetOpCode( AS_SET_FEEL );
session->WriteInt32( (int32)feel ); fServerLink->Attach<window_feel>( fFeel );
session->Sync(); fServerLink->FlushWithReply(&pmsg);
session->ReadInt32( &rCode );
Unlock(); Unlock();
if (rCode == SERVER_TRUE){ if(pmsg.Code() == SERVER_TRUE){
fFeel = feel; fFeel = feel;
return B_OK; return B_OK;
} }
return B_ERROR; return B_ERROR;
} }
@@ -1567,20 +1568,19 @@ window_feel BWindow::Feel() const{
status_t BWindow::SetFlags(uint32 flags){ status_t BWindow::SetFlags(uint32 flags){
int32 rCode; PortMessage pmsg;
Lock(); Lock();
session->WriteInt32( AS_SET_FLAGS ); fServerLink->SetOpCode( AS_SET_FLAGS );
session->WriteUInt32( flags ); fServerLink->Attach<int32>( fFlags );
session->Sync(); fServerLink->FlushWithReply(&pmsg);
session->ReadInt32( &rCode );
Unlock(); Unlock();
if (rCode == SERVER_TRUE){ if(pmsg.Code() == SERVER_TRUE){
fFlags = flags; fFlags = flags;
return B_OK; return B_OK;
} }
return B_ERROR; return B_ERROR;
} }
@@ -1617,28 +1617,24 @@ status_t BWindow::SetWindowAlignment(window_alignment mode,
return B_ERROR; return B_ERROR;
// TODO: test if hOffset = 0 and set it to 1 if true. // TODO: test if hOffset = 0 and set it to 1 if true.
int32 rCode; PortMessage pmsg;
Lock(); Lock();
session->WriteInt32( AS_SET_ALIGNMENT ); fServerLink->SetOpCode( AS_SET_ALIGNMENT );
session->WriteInt32( (int32)mode );
session->WriteInt32( h ); fServerLink->Attach<window_alignment>( mode );
session->WriteInt32( hOffset ); fServerLink->Attach<int32>( h );
session->WriteInt32( width ); fServerLink->Attach<int32>( hOffset );
session->WriteInt32( widthOffset ); fServerLink->Attach<int32>( width );
session->WriteInt32( v ); fServerLink->Attach<int32>( widthOffset );
session->WriteInt32( vOffset ); fServerLink->Attach<int32>( v );
session->WriteInt32( height ); fServerLink->Attach<int32>( vOffset );
session->WriteInt32( heightOffset ); fServerLink->Attach<int32>( height );
session->Sync(); fServerLink->Attach<int32>( heightOffset );
session->ReadInt32( &rCode ); fServerLink->FlushWithReply( &pmsg );
Unlock(); Unlock();
if ( rCode == SERVER_TRUE){ return ( pmsg.Code() == SERVER_TRUE) ? B_OK : B_ERROR;
return B_NO_ERROR;
}
return B_ERROR;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -1649,25 +1645,24 @@ status_t BWindow::GetWindowAlignment(window_alignment* mode,
int32* v, int32* vOffset, int32* v, int32* vOffset,
int32* height, int32* heightOffset) const int32* height, int32* heightOffset) const
{ {
int32 rCode; PortMessage pmsg;
const_cast<BWindow*>(this)->Lock(); const_cast<BWindow*>(this)->Lock();
session->WriteInt32( AS_GET_ALIGNMENT ); fServerLink->SetOpCode( AS_GET_ALIGNMENT );
session->Sync(); fServerLink->FlushWithReply( &pmsg );
session->ReadInt32( &rCode );
if (rCode == SERVER_TRUE){
session->ReadInt32( (int32*)mode );
session->ReadInt32( h );
session->ReadInt32( hOffset );
session->ReadInt32( width );
session->ReadInt32( widthOffset );
session->ReadInt32( v );
session->ReadInt32( hOffset );
session->ReadInt32( height );
session->ReadInt32( heightOffset );
return B_NO_ERROR; if (pmsg.Code() == SERVER_TRUE){
pmsg.Read<window_alignment>( mode );
pmsg.Read<int32>( h );
pmsg.Read<int32>( hOffset );
pmsg.Read<int32>( width );
pmsg.Read<int32>( widthOffset );
pmsg.Read<int32>( v );
pmsg.Read<int32>( hOffset );
pmsg.Read<int32>( height );
pmsg.Read<int32>( heightOffset );
return B_OK;
} }
const_cast<BWindow*>(this)->Unlock(); const_cast<BWindow*>(this)->Unlock();
@@ -1677,13 +1672,16 @@ status_t BWindow::GetWindowAlignment(window_alignment* mode,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
uint32 BWindow::Workspaces() const{ uint32 BWindow::Workspaces() const{
uint32 workspaces;
uint32 workspaces;
PortMessage pmsg;
const_cast<BWindow*>(this)->Lock(); const_cast<BWindow*>(this)->Lock();
session->WriteInt32( AS_GET_WORKSPACES ); fServerLink->SetOpCode( AS_GET_WORKSPACES );
session->Sync(); fServerLink->FlushWithReply( &pmsg );
session->ReadInt32( (int32*)&workspaces );
const_cast<BWindow*>(this)->Unlock(); const_cast<BWindow*>(this)->Unlock();
pmsg.Read<uint32>( &workspaces );
return workspaces; return workspaces;
} }
@@ -1693,9 +1691,9 @@ uint32 BWindow::Workspaces() const{
void BWindow::SetWorkspaces(uint32 workspaces){ void BWindow::SetWorkspaces(uint32 workspaces){
Lock(); Lock();
session->WriteInt32( AS_SET_WORKSPACES ); fServerLink->SetOpCode( AS_SET_WORKSPACES );
session->WriteInt32( (int32)workspaces ); fServerLink->Attach<uint32>( workspaces );
session->Sync( ); fServerLink->Flush();
Unlock(); Unlock();
} }
@@ -1725,10 +1723,10 @@ void BWindow::MoveTo( BPoint point ){
void BWindow::MoveTo(float x, float y){ void BWindow::MoveTo(float x, float y){
Lock(); Lock();
session->WriteInt32( AS_WINDOW_MOVE ); fServerLink->SetOpCode( AS_WINDOW_MOVE );
session->WriteFloat( x ); fServerLink->Attach<float>( x );
session->WriteFloat( y ); fServerLink->Attach<float>( y );
session->Sync(); fServerLink->Flush();
Unlock(); Unlock();
} }
@@ -1758,10 +1756,10 @@ void BWindow::ResizeTo(float width, float height){
height = (height > fMaxWindHeight) ? fMaxWindHeight : height; height = (height > fMaxWindHeight) ? fMaxWindHeight : height;
Lock(); Lock();
session->WriteInt32( AS_WINDOW_RESIZE ); fServerLink->SetOpCode( AS_WINDOW_RESIZE );
session->WriteFloat( width ); fServerLink->Attach<float>( width );
session->WriteFloat( height ); fServerLink->Attach<float>( height );
session->Sync( ); fServerLink->Flush();
Unlock(); Unlock();
} }
@@ -1774,17 +1772,22 @@ void BWindow::Show(){
if (fShowLevel == 0){ if (fShowLevel == 0){
STRACE(("BWindow(%s): sending AS_SHOW_WINDOW message...\n", Name() )); STRACE(("BWindow(%s): sending AS_SHOW_WINDOW message...\n", Name() ));
if ( !isLocked ) Lock(); if ( !isLocked )
session->WriteInt32( AS_SHOW_WINDOW ); Lock();
session->Sync( );
if ( !isLocked) Unlock(); fServerLink->SetOpCode( AS_SHOW_WINDOW );
fServerLink->Flush();
if ( !isLocked)
Unlock();
} }
// if it's the fist time Show() is called... start the Looper thread. // if it's the fist time Show() is called, start the Looper thread.
if ( Thread() == B_ERROR ) if ( Thread() == B_ERROR )
{ {
// normaly this won't happen, but I want to be sure! // normally this won't happen, but I want to be sure!
if ( !isLocked ) Lock(); if ( !isLocked )
Lock();
Run(); Run();
} }
@@ -1795,8 +1798,8 @@ void BWindow::Show(){
void BWindow::Hide(){ void BWindow::Hide(){
if (fShowLevel == 0){ if (fShowLevel == 0){
Lock(); Lock();
session->WriteInt32( AS_HIDE_WINDOW ); fServerLink->SetOpCode( AS_HIDE_WINDOW );
session->Sync(); fServerLink->Flush();
Unlock(); Unlock();
} }
fShowLevel++; fShowLevel++;
@@ -2012,6 +2015,8 @@ void BWindow::InitData( BRect frame,
delete serverlink; delete serverlink;
fServerLink=new PortLink(send_port);
// unlock, so other threads can do their job. // unlock, so other threads can do their job.
if( locked ) if( locked )
be_app->Unlock(); be_app->Unlock();
@@ -2260,14 +2265,15 @@ void BWindow::BuildTopView(){
top_view->setOwner( this ); top_view->setOwner( this );
// send top_view's information to app_server // send top_view's information to app_server
session->WriteInt32( AS_LAYER_CREATE_ROOT ); fServerLink->SetOpCode( AS_LAYER_CREATE_ROOT );
session->WriteInt32( _get_object_token_( top_view ) ); fServerLink->Attach<int32>( AS_LAYER_CREATE_ROOT );
session->WriteRect( top_view->Frame() ); fServerLink->Attach<int32>( _get_object_token_( top_view ) );
session->WriteInt32( top_view->ResizingMode() ); fServerLink->Attach<BRect>( top_view->Frame() );
session->WriteInt32( top_view->Flags() ); fServerLink->Attach<int32>( top_view->ResizingMode() );
session->WriteString( top_view->Name() ); fServerLink->Attach<int32>( top_view->Flags() );
fServerLink->AttachString( top_view->Name() );
// we DO NOT send our current state; the server knows the default values! // we DO NOT send our current state; the server knows the default values!
session->Sync(); fServerLink->Flush();
fLastViewToken = _get_object_token_( top_view ); fLastViewToken = _get_object_token_( top_view );
} }
@@ -2276,8 +2282,8 @@ void BWindow::BuildTopView(){
void BWindow::stopConnection(){ void BWindow::stopConnection(){
Lock(); Lock();
session->WriteInt32( AS_QUIT_WINDOW ); fServerLink->SetOpCode( AS_QUIT_WINDOW );
session->Sync(); fServerLink->Flush();
Unlock(); Unlock();
} }