Usermode/AxWin4 - Slowly implementing
authorJohn Hodge <[email protected]>
Sun, 8 Jun 2014 06:23:17 +0000 (14:23 +0800)
committerJohn Hodge <[email protected]>
Sun, 8 Jun 2014 06:23:17 +0000 (14:23 +0800)
Usermode/Applications/axwin4_src/Common/serialisation.cpp
Usermode/Applications/axwin4_src/Server/CClient.cpp
Usermode/Applications/axwin4_src/Server/CIPCChannel_AcessIPCPipe.cpp
Usermode/Applications/axwin4_src/Server/CRect.cpp
Usermode/Applications/axwin4_src/Server/CSurface.cpp
Usermode/Applications/axwin4_src/Server/CWindow.cpp
Usermode/Applications/axwin4_src/Server/include/CRect.hpp
Usermode/Applications/axwin4_src/Server/include/CSurface.hpp
Usermode/Applications/axwin4_src/Server/include/ipc.hpp
Usermode/Applications/axwin4_src/Server/ipc.cpp
Usermode/Applications/axwin4_src/Server/main.cpp

index 3dc2071..7bb77bf 100644 (file)
@@ -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;
index 9fe806e..92898b1 100644 (file)
@@ -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)
index 183253b..b222cea 100644 (file)
@@ -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");
 }
 
 
index 5d603e5..34013b1 100644 (file)
@@ -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
index a7206b6..d52298c 100644 (file)
@@ -6,10 +6,11 @@
  * - Window
  */
 #include <CSurface.hpp>
+#include <cassert>
 
 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;
index 0090eec..db43bac 100644 (file)
@@ -8,6 +8,7 @@
 #include <CWindow.hpp>
 #include <CCompositor.hpp>
 #include <assert.h>
+#include <ipc.hpp>
 
 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()
 {
index 7461568..e8f9dc8 100644 (file)
@@ -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;
        
index 91b61f8..c0c6c8b 100644 (file)
@@ -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;
index cb06f67..8e1c4aa 100644 (file)
@@ -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:
index f830820..4e5ba76 100644 (file)
@@ -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);
index f32b285..a15774e 100644 (file)
@@ -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();

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