Usermode/AxWin3 - Implemented WM_CreateWindow
[tpg/acess2.git] / Usermode / Applications / axwin2_src / WM / messages.c
index f876f50..f25e1c4 100644 (file)
@@ -19,6 +19,7 @@ void  IPC_Init(void);
 void   IPC_FillSelect(int *nfds, fd_set *set);
 void   IPC_HandleSelect(fd_set *set);
 void   IPC_Handle(tIPC_Type *IPCType, void *Ident, size_t MsgLen, tAxWin_Message *Msg);
+void   IPC_ReturnValue(tIPC_Type *IPCType, void *Ident, int MessageID, uint32_t Value);
  int   IPC_Type_Datagram_GetSize(void *Ident);
  int   IPC_Type_Datagram_Compare(void *Ident1, void *Ident2);
 void   IPC_Type_Datagram_Send(void *Ident, size_t Length, void *Data);
@@ -63,13 +64,13 @@ void IPC_HandleSelect(fd_set *set)
                 int    readlen, identlen;
                char    *msg;
 
-               readlen = read(giNetworkFileHandle, sizeof(staticBuf), staticBuf);
+               readlen = read(giNetworkFileHandle, staticBuf, sizeof(staticBuf));
                
-               // Assume that all connections are from localhost
                identlen = 4 + Net_GetAddressSize( ((uint16_t*)staticBuf)[1] );
                msg = staticBuf + identlen;
 
                IPC_Handle(&gIPC_Type_Datagram, staticBuf, readlen - identlen, (void*)msg);
+               _SysDebug("IPC_HandleSelect: UDP handled");
        }
 
        while(SysGetMessage(NULL, NULL))
@@ -80,12 +81,17 @@ void IPC_HandleSelect(fd_set *set)
                SysGetMessage(NULL, data);
 
                IPC_Handle(&gIPC_Type_SysMessage, &tid, len, (void*)data);
+               _SysDebug("IPC_HandleSelect: Message handled");
        }
 }
 
 void IPC_Handle(tIPC_Type *IPCType, void *Ident, size_t MsgLen, tAxWin_Message *Msg)
 {
        tApplication    *app;
+       tElement        *ele;
+       
+       _SysDebug("IPC_Handle: (IPCType=%p, Ident=%p, MsgLen=%i, Msg=%p)",
+               IPCType, Ident, MsgLen, Msg);
        
        if( MsgLen < sizeof(tAxWin_Message) )
                return ;
@@ -98,6 +104,7 @@ void IPC_Handle(tIPC_Type *IPCType, void *Ident, size_t MsgLen, tAxWin_Message *
        {
        // --- Ping message (reset timeout and get server version)
        case MSG_SREQ_PING:
+               _SysDebug(" IPC_Handle: MSG_SREQ_PING");
                if( MsgLen < sizeof(tAxWin_Message) + 4 )       return;
                Msg->ID = MSG_SRSP_VERSION;
                Msg->Size = 4;
@@ -110,8 +117,10 @@ void IPC_Handle(tIPC_Type *IPCType, void *Ident, size_t MsgLen, tAxWin_Message *
 
        // --- Register an application
        case MSG_SREQ_REGISTER:
+               _SysDebug(" IPC_Handle: MSG_SREQ_REGISTER");
                if( Msg->Data[Msg->Size-1] != '\0' ) {
                        // Invalid message
+                       _SysDebug("IPC_Handle: RETURN - Not NULL terminated");
                        return ;
                }
                
@@ -126,13 +135,35 @@ void IPC_Handle(tIPC_Type *IPCType, void *Ident, size_t MsgLen, tAxWin_Message *
        
        // --- Create a window
        case MSG_SREQ_ADDWIN:
+               _SysDebug(" IPC_Handle: MSG_SREQ_ADDWIN");
                if( Msg->Data[Msg->Size-1] != '\0' ) {
                        // Invalid message
                        return ;
                }
                
+               ele = AxWin_CreateAppWindow(app, Msg->Data);
+               IPC_ReturnValue(IPCType, Ident, MSG_SREQ_ADDWIN, ele->ApplicationID);
+               break;
+       
+       // --- Set a window's icon
+       case MSG_SREQ_SETICON:
+               _SysDebug(" IPC_Handle: MSG_SREQ_SETICON");
+               // TODO: Find a good way of implementing this
                break;
        
+       // --- Create an element
+       case MSG_SREQ_INSERT: {
+               _SysDebug(" IPC_Handle: MSG_SREQ_INSERT");
+               struct sAxWin_SReq_NewElement   *info = (void *)Msg->Data;
+               
+               if( Msg->Size != sizeof(*info) )        return;
+               
+               if( !app || info->Parent > app->MaxElementIndex )       return ;
+               
+               ele = AxWin_CreateElement( app->EleIndex[info->Parent], info->Type, info->Flags, NULL );
+               IPC_ReturnValue(IPCType, Ident, MSG_SREQ_ADDWIN, ele->ApplicationID);
+               break; }
+       
        // --- Unknown message
        default:
                fprintf(stderr, "WARNING: Unknown message %i (%p)\n", Msg->ID, IPCType);
@@ -141,6 +172,22 @@ void IPC_Handle(tIPC_Type *IPCType, void *Ident, size_t MsgLen, tAxWin_Message *
        }
 }
 
+void IPC_ReturnValue(tIPC_Type *IPCType, void *Ident, int MessageID, uint32_t Value)
+{
+       char    data[sizeof(tAxWin_Message) + sizeof(tAxWin_RetMsg)];
+       tAxWin_Message  *msg = (void *)data;
+       tAxWin_RetMsg   *ret_msg = (void *)msg->Data;
+       
+       msg->Source = 0;        // 0 = Server
+       msg->ID = MSG_SRSP_RETURN;
+       msg->Size = sizeof(tAxWin_RetMsg);
+       ret_msg->ReqID = MessageID;
+       ret_msg->Rsvd = 0;
+       ret_msg->Value = Value;
+       
+       IPCType->SendMessage(Ident, sizeof(data), data);
+}
+
 int IPC_Type_Datagram_GetSize(void *Ident)
 {
        return 4 + Net_GetAddressSize( ((uint16_t*)Ident)[1] );
@@ -161,7 +208,7 @@ void IPC_Type_Datagram_Send(void *Ident, size_t Length, void *Data)
        memcpy(tmpbuf, Ident, identlen);        // Header
        memcpy(tmpbuf + identlen, Data, Length);        // Data
        // TODO: Handle fragmented packets
-       write(giNetworkFileHandle, sizeof(tmpbuf), tmpbuf);
+       write(giNetworkFileHandle, tmpbuf, sizeof(tmpbuf));
 }
 
 int IPC_Type_Sys_GetSize(void *Ident)

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