Usermode/AxWin4 - Fix deserialiser, ::std::map for client windows, debugging
authorJohn Hodge <[email protected]>
Sat, 31 May 2014 05:44:11 +0000 (13:44 +0800)
committerJohn Hodge <[email protected]>
Sat, 31 May 2014 05:44:11 +0000 (13:44 +0800)
Usermode/Applications/axwin4_src/Common/include/serialisation.hpp
Usermode/Applications/axwin4_src/Common/serialisation.cpp
Usermode/Applications/axwin4_src/Server/CClient.cpp
Usermode/Applications/axwin4_src/Server/CWindow.cpp
Usermode/Applications/axwin4_src/Server/include/CClient.hpp
Usermode/Applications/axwin4_src/Server/ipc.cpp
Usermode/Applications/axwin4_src/Server/main.cpp
Usermode/Applications/axwin4_src/Server/video.cpp

index d680043..7212018 100644 (file)
@@ -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
index 8dad5d3..3dc2071 100644 (file)
@@ -8,6 +8,7 @@
 #include <serialisation.hpp>
 #include <cstddef>
 #include <stdexcept>
+#include <acess/sys.h> // 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<const char*>(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()
 {
 }
index f61ca31..9fe806e 100644 (file)
@@ -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)
index bd952aa..0090eec 100644 (file)
@@ -17,7 +17,7 @@ CWindow::CWindow(CCompositor& compositor, CClient& client, const ::std::string&
        m_client(client),
        m_name(name)
 {
-       
+       _SysDebug("CWindow::CWindow()");
 }
 
 CWindow::~CWindow()
index 6e8a09b..a42d9fa 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "CWindow.hpp"
 #include "serialisation.hpp"
+#include <map>
 
 namespace AxWin {
 
@@ -19,8 +20,8 @@ class CClient
 {
        IIPCChannel&    m_channel;
        
-       //::std::map<unsigned int,CWindow*>     m_windows;
-       CWindow*        m_windows[1];
+       ::std::map<unsigned int,CWindow*>       m_windows;
+       //CWindow*      m_windows[1];
 public:
        CClient(::AxWin::IIPCChannel& channel);
        virtual ~CClient();
index 46ba551..f830820 100644 (file)
@@ -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):
index 0cd048f..f32b285 100644 (file)
@@ -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;
 }
index 14fb76d..d2eb26a 100644 (file)
@@ -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));
 }
 

UCC git Repository :: git.ucc.asn.au