From: John Hodge Date: Sat, 31 May 2014 05:44:11 +0000 (+0800) Subject: Usermode/AxWin4 - Fix deserialiser, ::std::map for client windows, debugging X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=0868c6e02b76236ea70a6daa232b3c373f61e131;p=tpg%2Facess2.git Usermode/AxWin4 - Fix deserialiser, ::std::map for client windows, debugging --- diff --git a/Usermode/Applications/axwin4_src/Common/include/serialisation.hpp b/Usermode/Applications/axwin4_src/Common/include/serialisation.hpp index d680043d..7212018e 100644 --- a/Usermode/Applications/axwin4_src/Common/include/serialisation.hpp +++ b/Usermode/Applications/axwin4_src/Common/include/serialisation.hpp @@ -33,6 +33,8 @@ public: ::uint16_t ReadU16(); ::int16_t ReadS16(); const ::std::string ReadString(); +private: + void RangeCheck(const char *Method, size_t bytes) throw(::std::out_of_range); }; class CSerialiser diff --git a/Usermode/Applications/axwin4_src/Common/serialisation.cpp b/Usermode/Applications/axwin4_src/Common/serialisation.cpp index 8dad5d33..3dc20710 100644 --- a/Usermode/Applications/axwin4_src/Common/serialisation.cpp +++ b/Usermode/Applications/axwin4_src/Common/serialisation.cpp @@ -8,6 +8,7 @@ #include #include #include +#include // SysDebug namespace AxWin { @@ -53,19 +54,24 @@ bool CDeserialiser::IsConsumed() const const ::std::string CDeserialiser::ReadString() { - if( m_offset + 1 >= m_length ) - throw ::std::out_of_range("CDeserialiser::ReadString"); + RangeCheck("CDeserialiser::ReadString(len)", 1); uint8_t len = m_data[m_offset]; m_offset ++; - if( m_offset + len >= m_length ) - throw ::std::out_of_range("CDeserialiser::ReadString"); - + RangeCheck("CDeserialiser::ReadString(data)", len); ::std::string ret( reinterpret_cast(m_data+m_offset), len ); m_offset += len; return ret; } +void CDeserialiser::RangeCheck(const char *Method, size_t bytes) throw(::std::out_of_range) +{ + if( m_offset + bytes > m_length ) { + ::_SysDebug("%s - out of range %i+%i >= %i", Method, m_offset, bytes, m_length); + throw ::std::out_of_range(Method); + } +} + CSerialiser::CSerialiser() { } diff --git a/Usermode/Applications/axwin4_src/Server/CClient.cpp b/Usermode/Applications/axwin4_src/Server/CClient.cpp index f61ca31a..9fe806e3 100644 --- a/Usermode/Applications/axwin4_src/Server/CClient.cpp +++ b/Usermode/Applications/axwin4_src/Server/CClient.cpp @@ -32,10 +32,13 @@ CWindow* CClient::GetWindow(int ID) void CClient::SetWindow(int ID, CWindow* window) { + _SysDebug("SetWindow(ID=%i,window=%p)", ID, 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/CWindow.cpp b/Usermode/Applications/axwin4_src/Server/CWindow.cpp index bd952aa0..0090eeca 100644 --- a/Usermode/Applications/axwin4_src/Server/CWindow.cpp +++ b/Usermode/Applications/axwin4_src/Server/CWindow.cpp @@ -17,7 +17,7 @@ CWindow::CWindow(CCompositor& compositor, CClient& client, const ::std::string& m_client(client), m_name(name) { - + _SysDebug("CWindow::CWindow()"); } CWindow::~CWindow() diff --git a/Usermode/Applications/axwin4_src/Server/include/CClient.hpp b/Usermode/Applications/axwin4_src/Server/include/CClient.hpp index 6e8a09b1..a42d9fac 100644 --- a/Usermode/Applications/axwin4_src/Server/include/CClient.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/CClient.hpp @@ -10,6 +10,7 @@ #include "CWindow.hpp" #include "serialisation.hpp" +#include namespace AxWin { @@ -19,8 +20,8 @@ class CClient { IIPCChannel& m_channel; - //::std::map m_windows; - CWindow* m_windows[1]; + ::std::map m_windows; + //CWindow* m_windows[1]; public: CClient(::AxWin::IIPCChannel& channel); virtual ~CClient(); diff --git a/Usermode/Applications/axwin4_src/Server/ipc.cpp b/Usermode/Applications/axwin4_src/Server/ipc.cpp index 46ba551e..f830820b 100644 --- a/Usermode/Applications/axwin4_src/Server/ipc.cpp +++ b/Usermode/Applications/axwin4_src/Server/ipc.cpp @@ -149,6 +149,7 @@ void HandleMessage_CreateWindow(CClient& client, CDeserialiser& message) //CWindow* parent = client.GetWindow( parent_id ); ::std::string name = message.ReadString(); + ::_SysDebug("_CreateWindow: (%i, '%s')", new_id, name.c_str()); client.SetWindow( new_id, gpCompositor->CreateWindow(client, name) ); } @@ -257,7 +258,9 @@ void HandleMessage(CClient& client, CDeserialiser& message) return ; } + _SysDebug("IPC::HandleMessage - command=%i", command); (message_handlers[command])(client, message); + _SysDebug("IPC::HandleMessage - Completed"); } CClientFailure::CClientFailure(std::string&& what): diff --git a/Usermode/Applications/axwin4_src/Server/main.cpp b/Usermode/Applications/axwin4_src/Server/main.cpp index 0cd048f8..f32b2857 100644 --- a/Usermode/Applications/axwin4_src/Server/main.cpp +++ b/Usermode/Applications/axwin4_src/Server/main.cpp @@ -121,12 +121,17 @@ int main(int argc, char *argv[]) } _SysDebug("rv=%i, timeout=%lli", rv, timeout); - Timing::CheckEvents(); - - input->HandleSelect(rfds); - IPC::HandleSelect(rfds); - - compositor->Redraw(); + try { + Timing::CheckEvents(); + + input->HandleSelect(rfds); + IPC::HandleSelect(rfds); + + compositor->Redraw(); + } + catch(...) { + ::_SysDebug("Exception during select handling"); + } } return 0; } diff --git a/Usermode/Applications/axwin4_src/Server/video.cpp b/Usermode/Applications/axwin4_src/Server/video.cpp index 14fb76df..d2eb26a9 100644 --- a/Usermode/Applications/axwin4_src/Server/video.cpp +++ b/Usermode/Applications/axwin4_src/Server/video.cpp @@ -88,7 +88,7 @@ void CVideo::SetCursorBitmap() SetBufFormat(PTYBUFFMT_2DCMD); _SysWrite(m_fd, &hdr, sizeof(hdr)); - _SysDebug("size = %i (%04x:%02x * 4)", size, hdr.len_hi, hdr.len_low); + _SysDebug("SetCursorBitmap - size = %i (%04x:%02x * 4)", size, hdr.len_hi, hdr.len_low); _SysWrite(m_fd, &cCursorBitmap, size-sizeof(hdr)); }