From 73872ce04c3759b35e010af9c16367bc57a14d38 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 8 Jun 2014 14:23:17 +0800 Subject: [PATCH] Usermode/AxWin4 - Slowly implementing --- .../axwin4_src/Common/serialisation.cpp | 7 ++-- .../axwin4_src/Server/CClient.cpp | 13 ++++---- .../Server/CIPCChannel_AcessIPCPipe.cpp | 23 +++++++------ .../Applications/axwin4_src/Server/CRect.cpp | 9 ++++++ .../axwin4_src/Server/CSurface.cpp | 8 ++++- .../axwin4_src/Server/CWindow.cpp | 6 ++-- .../axwin4_src/Server/include/CRect.hpp | 2 ++ .../axwin4_src/Server/include/CSurface.hpp | 4 ++- .../axwin4_src/Server/include/ipc.hpp | 3 ++ .../Applications/axwin4_src/Server/ipc.cpp | 32 ++++++++++--------- .../Applications/axwin4_src/Server/main.cpp | 6 +++- 11 files changed, 70 insertions(+), 43 deletions(-) diff --git a/Usermode/Applications/axwin4_src/Common/serialisation.cpp b/Usermode/Applications/axwin4_src/Common/serialisation.cpp index 3dc20710..7bb77bf5 100644 --- a/Usermode/Applications/axwin4_src/Common/serialisation.cpp +++ b/Usermode/Applications/axwin4_src/Common/serialisation.cpp @@ -26,8 +26,7 @@ bool CDeserialiser::IsConsumed() const ::uint8_t CDeserialiser::ReadU8() { - if( m_offset + 1 >= m_length ) - throw ::std::out_of_range("CDeserialiser::ReadU8"); + RangeCheck("CDeserialiser::ReadU8", 1); uint8_t rv = m_data[m_offset]; m_offset ++; return rv; @@ -35,9 +34,7 @@ bool CDeserialiser::IsConsumed() const ::uint16_t CDeserialiser::ReadU16() { - if( m_offset + 2 >= m_length ) - throw ::std::out_of_range("CDeserialiser::ReadU16"); - + RangeCheck("CDeserialiser::ReadU16", 2); uint16_t rv = m_data[m_offset] | ((uint16_t)m_data[m_offset+1] << 8); m_offset += 2; return rv; diff --git a/Usermode/Applications/axwin4_src/Server/CClient.cpp b/Usermode/Applications/axwin4_src/Server/CClient.cpp index 9fe806e3..92898b11 100644 --- a/Usermode/Applications/axwin4_src/Server/CClient.cpp +++ b/Usermode/Applications/axwin4_src/Server/CClient.cpp @@ -24,10 +24,13 @@ CClient::~CClient() CWindow* CClient::GetWindow(int ID) { - if( ID == 0 ) - return 0; - - return m_windows[ID]; + _SysDebug("GetWindow(ID=%i)", ID); + try { + return m_windows.at(ID); + } + catch(const std::exception& e) { + return NULL; + } } void CClient::SetWindow(int ID, CWindow* window) @@ -36,9 +39,7 @@ void CClient::SetWindow(int ID, CWindow* window) if( m_windows[ID] ) { delete m_windows[ID]; } - _SysDebug("SetWindow - Set", ID, window); m_windows[ID] = window; - _SysDebug("SetWindow - END"); } void CClient::HandleMessage(CDeserialiser& message) diff --git a/Usermode/Applications/axwin4_src/Server/CIPCChannel_AcessIPCPipe.cpp b/Usermode/Applications/axwin4_src/Server/CIPCChannel_AcessIPCPipe.cpp index 183253b8..b222cea8 100644 --- a/Usermode/Applications/axwin4_src/Server/CIPCChannel_AcessIPCPipe.cpp +++ b/Usermode/Applications/axwin4_src/Server/CIPCChannel_AcessIPCPipe.cpp @@ -30,13 +30,11 @@ CIPCChannel_AcessIPCPipe::~CIPCChannel_AcessIPCPipe() int CIPCChannel_AcessIPCPipe::FillSelect(fd_set& rfds) { - _SysDebug("CIPCChannel_AcessIPCPipe::FillSelect"); int maxfd = m_fd; FD_SET(m_fd, &rfds); for( auto& clientref : m_clients ) { - _SysDebug("CIPCChannel_AcessIPCPipe::FillSelect - FD%i", clientref.m_fd); maxfd = ::std::max(maxfd, clientref.m_fd); FD_SET(clientref.m_fd, &rfds); } @@ -46,22 +44,24 @@ int CIPCChannel_AcessIPCPipe::FillSelect(fd_set& rfds) void CIPCChannel_AcessIPCPipe::HandleSelect(const fd_set& rfds) { - _SysDebug("CIPCChannel_AcessIPCPipe::HandleSelect"); if( FD_ISSET(m_fd, &rfds) ) { - _SysDebug("CIPCChannel_AcessIPCPipe::HandleSelect - New client on FD %i", m_fd); int newfd = _SysOpenChild(m_fd, "newclient", OPENFLAG_READ|OPENFLAG_WRITE); - _SysDebug("newfd = %i", newfd); - - // emplace creates a new object within the list - m_clients.emplace( m_clients.end(), *this, newfd ); - IPC::RegisterClient( m_clients.back() ); + if( newfd == -1 ) { + _SysDebug("ERROR - Failure to open new client on FD%i", m_fd); + } + else { + _SysDebug("CIPCChannel_AcessIPCPipe::HandleSelect - New client on FD %i with FD%i", m_fd, newfd); + + // emplace creates a new object within the list + m_clients.emplace( m_clients.end(), *this, newfd ); + IPC::RegisterClient( m_clients.back() ); + } } for( auto it = m_clients.begin(); it != m_clients.end(); ) { CClient_AcessIPCPipe& clientref = *it; - _SysDebug("CIPCChannel_AcessIPCPipe::HandleSelect - Trying FD%i", clientref.m_fd); ++ it; if( FD_ISSET(clientref.m_fd, &rfds) ) @@ -70,14 +70,13 @@ void CIPCChannel_AcessIPCPipe::HandleSelect(const fd_set& rfds) clientref.HandleReceive(); } catch( const ::std::exception& e ) { - _SysDebug("ERROR - Exception processing IPCPipe FD%i: %s", + _SysDebug("ERROR - Exception processing IPCPipe FD%i: '%s', removing", clientref.m_fd, e.what() ); it = m_clients.erase(--it); } } } - _SysDebug("CIPCChannel_AcessIPCPipe::HandleSelect - END"); } diff --git a/Usermode/Applications/axwin4_src/Server/CRect.cpp b/Usermode/Applications/axwin4_src/Server/CRect.cpp index 5d603e5a..34013b1c 100644 --- a/Usermode/Applications/axwin4_src/Server/CRect.cpp +++ b/Usermode/Applications/axwin4_src/Server/CRect.cpp @@ -17,6 +17,15 @@ CRect::CRect(int x, int y, unsigned int w, unsigned int h): { } +void CRect::Move(int NewX, int NewY) +{ + // TODO: Add a parent rectangle, and prevent this from fully leaving its bounds + m_x = NewX; + m_y = NewY; + m_x2 = m_x + m_w; + m_y2 = m_y + m_h; +} + bool CRect::HasIntersection(const CRect& other) const { // If other's origin is past our far corner diff --git a/Usermode/Applications/axwin4_src/Server/CSurface.cpp b/Usermode/Applications/axwin4_src/Server/CSurface.cpp index a7206b67..d52298cd 100644 --- a/Usermode/Applications/axwin4_src/Server/CSurface.cpp +++ b/Usermode/Applications/axwin4_src/Server/CSurface.cpp @@ -6,10 +6,11 @@ * - Window */ #include +#include namespace AxWin { -CSurface::CSurface(unsigned int x, unsigned int y, unsigned int w, unsigned int h): +CSurface::CSurface(int x, int y, unsigned int w, unsigned int h): m_rect(x,y, w,h) { } @@ -18,6 +19,11 @@ CSurface::~CSurface() { } +void CSurface::Resize(unsigned int W, unsigned int H) +{ + assert(!"TODO: CSurface::Resize"); +} + const uint32_t* CSurface::GetScanline(unsigned int row, unsigned int x_ofs) const { return 0; diff --git a/Usermode/Applications/axwin4_src/Server/CWindow.cpp b/Usermode/Applications/axwin4_src/Server/CWindow.cpp index 0090eeca..db43bac8 100644 --- a/Usermode/Applications/axwin4_src/Server/CWindow.cpp +++ b/Usermode/Applications/axwin4_src/Server/CWindow.cpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace AxWin { @@ -45,11 +46,12 @@ void CWindow::Show(bool bShow) void CWindow::Move(int X, int Y) { - assert(!"TODO: CWindow::Move"); + m_surface.m_rect.Move(X, Y); } void CWindow::Resize(unsigned int W, unsigned int H) { - assert(!"TODO: CWindow::Resize"); + m_surface.Resize(W, H); + IPC::SendNotify_Dims(m_client, W, H); } uint64_t CWindow::ShareSurface() { diff --git a/Usermode/Applications/axwin4_src/Server/include/CRect.hpp b/Usermode/Applications/axwin4_src/Server/include/CRect.hpp index 7461568c..e8f9dc82 100644 --- a/Usermode/Applications/axwin4_src/Server/include/CRect.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/CRect.hpp @@ -14,6 +14,8 @@ public: }; CRect(int X, int Y, unsigned int W, unsigned int H); + void Move(int NewX, int NewY); + bool HasIntersection(const CRect& other) const; CRect Intersection(const CRect& other) const; diff --git a/Usermode/Applications/axwin4_src/Server/include/CSurface.hpp b/Usermode/Applications/axwin4_src/Server/include/CSurface.hpp index 91b61f8c..c0c6c8b9 100644 --- a/Usermode/Applications/axwin4_src/Server/include/CSurface.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/CSurface.hpp @@ -11,9 +11,11 @@ namespace AxWin { class CSurface { public: - CSurface(unsigned int x, unsigned int y, unsigned int w, unsigned int h); + CSurface(int x, int y, unsigned int w, unsigned int h); ~CSurface(); + void Resize(unsigned int new_w, unsigned int new_h); + const uint32_t* GetScanline(unsigned int row, unsigned int x_ofs) const; CRect m_rect; diff --git a/Usermode/Applications/axwin4_src/Server/include/ipc.hpp b/Usermode/Applications/axwin4_src/Server/include/ipc.hpp index cb06f67e..8e1c4aa4 100644 --- a/Usermode/Applications/axwin4_src/Server/include/ipc.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/ipc.hpp @@ -29,6 +29,9 @@ extern int FillSelect(::fd_set& rfds); extern void HandleSelect(const ::fd_set& rfds); extern void RegisterClient(CClient& client); extern void DeregisterClient(CClient& client); + +extern void SendNotify_Dims(CClient& client, unsigned int W, unsigned int H); + extern void HandleMessage(CClient& client, CDeserialiser& message); class CClientFailure: diff --git a/Usermode/Applications/axwin4_src/Server/ipc.cpp b/Usermode/Applications/axwin4_src/Server/ipc.cpp index f830820b..4e5ba76b 100644 --- a/Usermode/Applications/axwin4_src/Server/ipc.cpp +++ b/Usermode/Applications/axwin4_src/Server/ipc.cpp @@ -39,7 +39,6 @@ void Initialise(const CConfigIPC& config, CCompositor& compositor) int FillSelect(fd_set& rfds) { int ret = 0; - _SysDebug("IPC::FillSelect"); for( auto channel : glChannels ) { _SysDebug("IPC::FillSelect - channel=%p", channel); @@ -50,10 +49,8 @@ int FillSelect(fd_set& rfds) void HandleSelect(const fd_set& rfds) { - _SysDebug("IPC::HandleSelect"); for( auto channel : glChannels ) { - _SysDebug("IPC::HandleSelect - channel=%p", channel); channel->HandleSelect(rfds); } } @@ -71,6 +68,11 @@ void DeregisterClient(CClient& client) } +void SendNotify_Dims(CClient& client, unsigned int NewW, unsigned int NewH) +{ + assert(!"TODO: CClient::SendNotify_Dims"); +} + void HandleMessage_Nop(CClient& client, CDeserialiser& message) { @@ -156,10 +158,11 @@ void HandleMessage_CreateWindow(CClient& client, CDeserialiser& message) void HandleMessage_DestroyWindow(CClient& client, CDeserialiser& message) { uint16_t win_id = message.ReadU16(); + _SysDebug("_DestroyWindow: (%i)", win_id); CWindow* win = client.GetWindow(win_id); if(!win) { - throw IPC::CClientFailure("Bad window"); + throw IPC::CClientFailure("_DestroyWindow: Bad window"); } client.SetWindow(win_id, 0); @@ -171,10 +174,11 @@ void HandleMessage_SetWindowAttr(CClient& client, CDeserialiser& message) { uint16_t win_id = message.ReadU16(); uint16_t attr_id = message.ReadU16(); - + _SysDebug("_SetWindowAttr: (%i, %i)", win_id, attr_id); + CWindow* win = client.GetWindow(win_id); if(!win) { - throw IPC::CClientFailure("Bad window"); + throw IPC::CClientFailure("_SetWindowAttr - Bad window"); } switch(attr_id) @@ -183,13 +187,11 @@ void HandleMessage_SetWindowAttr(CClient& client, CDeserialiser& message) uint16_t new_w = message.ReadU16(); uint16_t new_h = message.ReadU16(); win->Resize(new_w, new_h); - assert(!"TODO: IPC_WINATTR_DIMENSIONS"); break; } case IPC_WINATTR_POSITION: { int16_t new_x = message.ReadS16(); int16_t new_y = message.ReadS16(); win->Move(new_x, new_y); - assert(!"TODO: IPC_WINATTR_POSITION"); break; } default: _SysDebug("HandleMessage_SetWindowAttr - Bad attr %u", attr_id); @@ -199,34 +201,34 @@ void HandleMessage_SetWindowAttr(CClient& client, CDeserialiser& message) void HandleMessage_GetWindowAttr(CClient& client, CDeserialiser& message) { - assert(!"TODO"); + assert(!"TODO HandleMessage_GetWindowAttr"); } void HandleMessage_SendIPC(CClient& client, CDeserialiser& message) { - assert(!"TODO"); + assert(!"TODO HandleMessage_SendIPC"); } void HandleMessage_GetWindowBuffer(CClient& client, CDeserialiser& message) { - assert(!"TODO"); + assert(!"TODO HandleMessage_GetWindowBuffer"); } void HandleMessage_PushData(CClient& client, CDeserialiser& message) { - assert(!"TODO"); + assert(!"TODO HandleMessage_PushData"); } void HandleMessage_Blit(CClient& client, CDeserialiser& message) { - assert(!"TODO"); + assert(!"TODO HandleMessage_Blit"); } void HandleMessage_DrawCtl(CClient& client, CDeserialiser& message) { - assert(!"TODO"); + assert(!"TODO HandleMessage_DrawCtl"); } void HandleMessage_DrawText(CClient& client, CDeserialiser& message) { - assert(!"TODO"); + assert(!"TODO HandleMessage_DrawText"); } typedef void MessageHandler_op_t(CClient& client, CDeserialiser& message); diff --git a/Usermode/Applications/axwin4_src/Server/main.cpp b/Usermode/Applications/axwin4_src/Server/main.cpp index f32b2857..a15774ec 100644 --- a/Usermode/Applications/axwin4_src/Server/main.cpp +++ b/Usermode/Applications/axwin4_src/Server/main.cpp @@ -95,11 +95,13 @@ int main(int argc, char *argv[]) if( FD_ISSET(i, &rfds) ) FD_SET(i, &efds); + #if 0 for( int i = 0; i < nfd; i ++ ) { if( FD_ISSET(i, &rfds) ) { _SysDebug("FD%i", i); } } + #endif // TODO: Support _SysSendMessage IPC? int64_t timeout = Timing::GetTimeToNextEvent(); @@ -114,12 +116,14 @@ int main(int argc, char *argv[]) } int rv = ::_SysSelect(nfd, &rfds, NULL, NULL/*&efds*/, timeoutp, 0); + #if 0 for( int i = 0; i < nfd; i ++ ) { if( FD_ISSET(i, &rfds) ) { _SysDebug("FD%i", i); } } - _SysDebug("rv=%i, timeout=%lli", rv, timeout); + #endif + //_SysDebug("rv=%i, timeout=%lli", rv, timeout); try { Timing::CheckEvents(); -- 2.20.1