From d74e5edc75b4fca94b71eef800b9d3a04760da05 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 24 May 2014 23:12:50 +0800 Subject: [PATCH] Usermode/AxWin4 - Starting work on client-side library --- .../{Server => Common}/include/ipc_proto.hpp | 11 +-- .../Common/include/serialisation.hpp | 58 +++++++++++++ .../axwin4_src/Common/serialisation.cpp | 85 +++++++++++++++++++ .../Applications/axwin4_src/Server/Makefile | 11 ++- .../Server/include/serialisation.hpp | 44 ---------- .../axwin4_src/Server/serialisation.cpp | 50 ----------- Usermode/Libraries/Makefile.cfg | 2 +- Usermode/Libraries/Makefile.tpl | 5 ++ Usermode/Libraries/libaxwin4.so_src/Makefile | 28 ++++++ .../include/CIPCChannel_AcessIPCPipe.hpp | 30 +++++++ .../libaxwin4.so_src/include/IIPCChannel.hpp | 33 +++++++ .../libaxwin4.so_src/include/common.hpp | 25 ++++++ .../include_exp/axwin4/axwin.h | 33 +++++++ Usermode/Libraries/libaxwin4.so_src/ipc.cpp | 78 +++++++++++++++++ .../libaxwin4.so_src/ipc_acessipcpipe.cpp | 47 ++++++++++ Usermode/Libraries/libaxwin4.so_src/main.c | 8 ++ Usermode/Libraries/libaxwin4.so_src/wm.cpp | 40 +++++++++ 17 files changed, 486 insertions(+), 102 deletions(-) rename Usermode/Applications/axwin4_src/{Server => Common}/include/ipc_proto.hpp (77%) create mode 100644 Usermode/Applications/axwin4_src/Common/include/serialisation.hpp create mode 100644 Usermode/Applications/axwin4_src/Common/serialisation.cpp delete mode 100644 Usermode/Applications/axwin4_src/Server/include/serialisation.hpp delete mode 100644 Usermode/Applications/axwin4_src/Server/serialisation.cpp create mode 100644 Usermode/Libraries/libaxwin4.so_src/Makefile create mode 100644 Usermode/Libraries/libaxwin4.so_src/include/CIPCChannel_AcessIPCPipe.hpp create mode 100644 Usermode/Libraries/libaxwin4.so_src/include/IIPCChannel.hpp create mode 100644 Usermode/Libraries/libaxwin4.so_src/include/common.hpp create mode 100644 Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/axwin.h create mode 100644 Usermode/Libraries/libaxwin4.so_src/ipc.cpp create mode 100644 Usermode/Libraries/libaxwin4.so_src/ipc_acessipcpipe.cpp create mode 100644 Usermode/Libraries/libaxwin4.so_src/main.c create mode 100644 Usermode/Libraries/libaxwin4.so_src/wm.cpp diff --git a/Usermode/Applications/axwin4_src/Server/include/ipc_proto.hpp b/Usermode/Applications/axwin4_src/Common/include/ipc_proto.hpp similarity index 77% rename from Usermode/Applications/axwin4_src/Server/include/ipc_proto.hpp rename to Usermode/Applications/axwin4_src/Common/include/ipc_proto.hpp index a3464248..7018a620 100644 --- a/Usermode/Applications/axwin4_src/Server/include/ipc_proto.hpp +++ b/Usermode/Applications/axwin4_src/Common/include/ipc_proto.hpp @@ -37,15 +37,16 @@ enum enum eIPC_GlobalAttrs { IPC_GLOBATTR_SCREENDIMS, // Screen dimensions - Readonly - IPC_GLOBATTR_MAXAREA, // Maximum window area for screen (hint, not enforced) + IPC_GLOBATTR_MAXAREA, // Maximum window area for screen (hint only, not enforced) }; enum eIPC_WinAttrs { - IPC_WINATTR_SHOW, - IPC_WINATTR_FLAGS, // Decoration enabled, always-on-top - IPC_WINATTR_POSITION, - IPC_WINATTR_DIMENSIONS, + IPC_WINATTR_SHOW, // u8 - Window shown + IPC_WINATTR_FLAGS, // u32 - Decoration enabled, always-on-top + IPC_WINATTR_POSITION, // s16, s16 + IPC_WINATTR_DIMENSIONS, // u16, u16 + IPC_WINATTR_TITLE, // string }; }; diff --git a/Usermode/Applications/axwin4_src/Common/include/serialisation.hpp b/Usermode/Applications/axwin4_src/Common/include/serialisation.hpp new file mode 100644 index 00000000..32ba4659 --- /dev/null +++ b/Usermode/Applications/axwin4_src/Common/include/serialisation.hpp @@ -0,0 +1,58 @@ +/* + * Acess2 GUI v4 + * - By John Hodge (thePowersGang) + * + * serialisation.hpp + * - Generic (de)serialisation code + */ +#ifndef _SERIALISATION_H_ +#define _SERIALISATION_H_ + +#include +#include +#include +#include +#include + +namespace AxWin { + +class CDeserialiseException: + public ::std::exception +{ +}; + +class CDeserialiser +{ + const size_t m_length; + const uint8_t* m_data; + size_t m_offset; +public: + CDeserialiser(size_t Length, const uint8_t *Buffer); + ::uint8_t ReadU8(); + ::uint16_t ReadU16(); + ::int16_t ReadS16(); + ::std::string ReadString(); +}; + +class CSerialiser +{ + ::std::vector m_data; +public: + CSerialiser(); + void WriteU8(::uint8_t val); + void WriteU16(::uint16_t val); + void WriteS16(::int16_t val); + void WriteString(const char* val, size_t n); + void WriteString(const char* val) { + WriteString(val, ::std::char_traits::length(val)); + } + void WriteString(const ::std::string& val) { + WriteString(val.data(), val.size()); + } + void WriteSub(const CSerialiser& val); +}; + +}; + +#endif + diff --git a/Usermode/Applications/axwin4_src/Common/serialisation.cpp b/Usermode/Applications/axwin4_src/Common/serialisation.cpp new file mode 100644 index 00000000..4388eab7 --- /dev/null +++ b/Usermode/Applications/axwin4_src/Common/serialisation.cpp @@ -0,0 +1,85 @@ +/* + * Acess2 GUI v4 + * - By John Hodge (thePowersGang) + * + * serialisation.cpp + * - IPC Serialisation + */ +#include +#include + +namespace AxWin { + +CDeserialiser::CDeserialiser(size_t Length, const uint8_t *Buffer): + m_length(Length), + m_data(Buffer), + m_offset(0) +{ +} + +::uint8_t CDeserialiser::ReadU8() +{ + return 0; +} + +::uint16_t CDeserialiser::ReadU16() +{ + return 0; +} + +::int16_t CDeserialiser::ReadS16() +{ + return 0; +} + +::std::string CDeserialiser::ReadString() +{ + return ""; +} + +CSerialiser::CSerialiser() +{ +} + +void CSerialiser::WriteU8(::uint8_t Value) +{ + m_data.push_back(Value); +} + +void CSerialiser::WriteU16(::uint16_t Value) +{ + m_data.push_back(Value & 0xFF); + m_data.push_back(Value >> 8); +} + +void CSerialiser::WriteS16(::int16_t Value) +{ + if( Value < 0 ) + { + ::uint16_t rawval = 0x10000 - (::int32_t)Value; + WriteU16(rawval); + } + else + { + WriteU16(Value); + } +} + +void CSerialiser::WriteString(const char* val, size_t n) +{ + //if( n >= 256 ) + // throw ::std::out_of_range("CSerialiser::WriteString"); + WriteU8(n); + for( size_t i = 0; i < n; i ++ ) + WriteU8(val[i]); +} + +void CSerialiser::WriteSub(const CSerialiser& val) +{ + m_data.reserve( m_data.size() + val.m_data.size() ); + for( auto byte : val.m_data ) + m_data.push_back( byte ); +} + +}; // namespace AxWin + diff --git a/Usermode/Applications/axwin4_src/Server/Makefile b/Usermode/Applications/axwin4_src/Server/Makefile index 2c7a74e9..6f88f14d 100644 --- a/Usermode/Applications/axwin4_src/Server/Makefile +++ b/Usermode/Applications/axwin4_src/Server/Makefile @@ -1,10 +1,11 @@ include ../../Makefile.cfg -CPPFLAGS += -Iinclude/ +CPPFLAGS += -Iinclude/ -I../Common/include/ OBJ := main.o ipc.o CConfig.o video.o input.o timing.o OBJ += compositor.o CWindow.o -OBJ += serialisation.o CClient.o +OBJ += Common__serialisation.o +OBJ += CClient.o OBJ += CIPCChannel_AcessIPCPipe.o OBJ += CRect.o CSurface.o BIN := AxWinServer @@ -12,3 +13,9 @@ BIN := AxWinServer LDFLAGS += -lc++ include ../../Makefile.tpl + +$(_OBJPREFIX)Common__%.o: ../Common/%.cpp + @echo [CXX] -o $@ + @mkdir -p $(dir $@) + $V$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@ -MQ $@ -MP -MD -MF $(@:%.o=%.dep) + diff --git a/Usermode/Applications/axwin4_src/Server/include/serialisation.hpp b/Usermode/Applications/axwin4_src/Server/include/serialisation.hpp deleted file mode 100644 index ca397b4e..00000000 --- a/Usermode/Applications/axwin4_src/Server/include/serialisation.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Acess2 GUI v4 - * - By John Hodge (thePowersGang) - * - * serialisation.hpp - * - Generic (de)serialisation code - */ -#ifndef _SERIALISATION_H_ -#define _SERIALISATION_H_ - -#include -#include -#include -#include - -namespace AxWin { - -class CDeserialiseException: - public ::std::exception -{ -}; - -class CDeserialiser -{ -public: - CDeserialiser(size_t Length, const void *Buffer); - ::uint8_t ReadU8(); - ::uint16_t ReadU16(); - ::int16_t ReadS16(); - ::std::string ReadString(); -}; - -class CSerialiser -{ -public: - CSerialiser(); - void WriteU8(::uint8_t val); - void WriteU16(::uint16_t val); -}; - -}; - -#endif - diff --git a/Usermode/Applications/axwin4_src/Server/serialisation.cpp b/Usermode/Applications/axwin4_src/Server/serialisation.cpp deleted file mode 100644 index 7d605875..00000000 --- a/Usermode/Applications/axwin4_src/Server/serialisation.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Acess2 GUI v4 - * - By John Hodge (thePowersGang) - * - * serialisation.cpp - * - IPC Serialisation - */ -#include -#include - -namespace AxWin { - -CDeserialiser::CDeserialiser(size_t Length, const void *Buffer) -{ -} - -::uint8_t CDeserialiser::ReadU8() -{ - return 0; -} - -::uint16_t CDeserialiser::ReadU16() -{ - return 0; -} - -::int16_t CDeserialiser::ReadS16() -{ - return 0; -} - -::std::string CDeserialiser::ReadString() -{ - return ""; -} - -CSerialiser::CSerialiser() -{ -} - -void CSerialiser::WriteU8(::uint8_t Value) -{ -} - -void CSerialiser::WriteU16(::uint16_t Value) -{ -} - -}; // namespace AxWin - diff --git a/Usermode/Libraries/Makefile.cfg b/Usermode/Libraries/Makefile.cfg index 16f423de..113e65c8 100644 --- a/Usermode/Libraries/Makefile.cfg +++ b/Usermode/Libraries/Makefile.cfg @@ -32,7 +32,7 @@ else CXXFLAGS := -fno-stack-protector -fPIC LDFLAGS := -I/Acess/Libs/ld-acess.so -lld-acess `$(CC) -print-libgcc-file-name` endif -LDFLAGS += -g -nostdlib -shared -eSoMain -x --no-undefined -L$(OUTPUTDIR)Libs/ +LDFLAGS += -g -nostdlib -shared -eSoMain -x --no-undefined -L$(OUTPUTDIR)Libs/ --defsym __dso_handle=SoMain CXXFLAGS += -std=gnu++11 -include $(_libsdir)../common_settings.mk diff --git a/Usermode/Libraries/Makefile.tpl b/Usermode/Libraries/Makefile.tpl index d04a6ff7..27de5f67 100644 --- a/Usermode/Libraries/Makefile.tpl +++ b/Usermode/Libraries/Makefile.tpl @@ -100,6 +100,11 @@ $(_OBJPREFIX)%.o: %.cc @mkdir -p $(dir $@) $V$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ -c $< -MMD -MP -MT $@ -MF $@.dep +$(_OBJPREFIX)%.o: %.cpp + @echo [CXX] -o $@ + @mkdir -p $(dir $@) + $V$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ -c $< -MMD -MP -MT $@ -MF $@.dep + $(_OBJPREFIX)%.ao: %.$(ASSUFFIX) @echo [AS] -o $@ @mkdir -p $(dir $@) diff --git a/Usermode/Libraries/libaxwin4.so_src/Makefile b/Usermode/Libraries/libaxwin4.so_src/Makefile new file mode 100644 index 00000000..31626671 --- /dev/null +++ b/Usermode/Libraries/libaxwin4.so_src/Makefile @@ -0,0 +1,28 @@ +# Acess2 AxWin4 Library +# Makefile + +-include ../Makefile.cfg + +AXWIN4DIR := ../../Applications/axwin4_src/ + +CPPFLAGS += -I$(AXWIN4DIR)Common/include/ +CFLAGS += -Wextra +CXXFLAGS += +ASFLAGS += +LDFLAGS += -soname libaxwin4.so -Map map.txt -lc -lc++ + +OBJ = main.o ipc.o ipc_acessipcpipe.o +OBJ += wm.o +OBJ += Common__serialisation.o +DEPFILES := $(OBJ:%.o=%.d) +BIN = libaxwin4.so + +include ../Makefile.tpl + +$(_OBJPREFIX)Common__%.o: $(AXWIN4DIR)/Common/%.cpp + @echo [CXX] -o $@ + @mkdir -p $(dir $@) + $V$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@ -MQ $@ -MP -MD -MF $(@:%.o=%.dep) + + + diff --git a/Usermode/Libraries/libaxwin4.so_src/include/CIPCChannel_AcessIPCPipe.hpp b/Usermode/Libraries/libaxwin4.so_src/include/CIPCChannel_AcessIPCPipe.hpp new file mode 100644 index 00000000..d04d0524 --- /dev/null +++ b/Usermode/Libraries/libaxwin4.so_src/include/CIPCChannel_AcessIPCPipe.hpp @@ -0,0 +1,30 @@ +/* + * Acess2 GUIv4 Library + * - By John Hodge (thePowersGang) + * + * CIPCChannel_AcessIPCPipe.h + * - Acess IPC Datagram pipe + */ +#ifndef _LIBAXWIN4_CIPCCHANNEL_ACESSIPCPIPE_H_ +#define _LIBAXWIN4_CIPCCHANNEL_ACESSIPCPIPE_H_ + +#include "IIPCChannel.hpp" + +namespace AxWin { + +class CIPCChannel_AcessIPCPipe: + public IIPCChannel +{ + int m_fd; +public: + CIPCChannel_AcessIPCPipe(const char *Path); + virtual ~CIPCChannel_AcessIPCPipe(); + virtual int FillSelect(fd_set& fds); + virtual bool HandleSelect(const fd_set& fds); + virtual void Send(CSerialiser& message); +}; + +}; // namespace AxWin + +#endif + diff --git a/Usermode/Libraries/libaxwin4.so_src/include/IIPCChannel.hpp b/Usermode/Libraries/libaxwin4.so_src/include/IIPCChannel.hpp new file mode 100644 index 00000000..c4a514f7 --- /dev/null +++ b/Usermode/Libraries/libaxwin4.so_src/include/IIPCChannel.hpp @@ -0,0 +1,33 @@ +/* + * Acess2 GUIv4 Library + * - By John Hodge (thePowersGang) + * + * IIPCChannel.h + * - IPC Channel interface + */ +#ifndef _LIBAXWIN4_IIPCCHANNEL_H_ +#define _LIBAXWIN4_IIPCCHANNEL_H_ + +#include + +#include + +namespace AxWin { + +class IIPCChannel +{ +public: + virtual ~IIPCChannel(); + virtual int FillSelect(fd_set& fds) = 0; + /** + * \return False if the connection has dropped/errored + */ + virtual bool HandleSelect(const fd_set& fds) = 0; + + virtual void Send(CSerialiser& message) = 0; +}; + +}; // namespace AxWin + +#endif + diff --git a/Usermode/Libraries/libaxwin4.so_src/include/common.hpp b/Usermode/Libraries/libaxwin4.so_src/include/common.hpp new file mode 100644 index 00000000..431fce58 --- /dev/null +++ b/Usermode/Libraries/libaxwin4.so_src/include/common.hpp @@ -0,0 +1,25 @@ +/* + * Acess2 GUIv4 Library + * - By John Hodge (thePowersGang) + * + * common.h + * - Library internal header + */ +#ifndef _LIBAXWIN4_COMMON_H_ +#define _LIBAXWIN4_COMMON_H_ + +#include + +namespace AxWin { + +extern void SendMessage(CSerialiser& message); + +}; + +struct sAxWin4_Window +{ + unsigned int m_id; +}; + +#endif + diff --git a/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/axwin.h b/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/axwin.h new file mode 100644 index 00000000..fd545819 --- /dev/null +++ b/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/axwin.h @@ -0,0 +1,33 @@ +/* + */ +#ifndef _LIBAXWIN4_AXWIN4_AXWIN_H_ +#define _LIBAXWIN4_AXWIN4_AXWIN_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +typedef struct sAxWin4_Window tAxWin4_Window; + +// - Abstractions of core IPC methods +extern bool AxWin4_Connect(const char *URI); + +extern bool AxWin4_WaitEventQueue(uint64_t Timeout); +extern bool AxWin4_WaitEventQueueSelect(int nFDs, fd_set *rfds, fd_set *wfds, fd_set *efds, uint64_t Timeout); + +extern tAxWin4_Window *AxWin4_CreateWindow(const char *Name); +extern void AxWin4_ShowWindow(tAxWin4_Window *Window); +extern void AxWin4_SetTitle(tAxWin4_Window *Window, const char *Title); +extern void AxWin4_DrawBitmap(tAxWin4_Window *Window, int X, int Y, unsigned int W, unsigned int H, void *Data); + + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/Usermode/Libraries/libaxwin4.so_src/ipc.cpp b/Usermode/Libraries/libaxwin4.so_src/ipc.cpp new file mode 100644 index 00000000..c7a24555 --- /dev/null +++ b/Usermode/Libraries/libaxwin4.so_src/ipc.cpp @@ -0,0 +1,78 @@ +/* + * AxWin4 Interface Library + * - By John Hodge (thePowersGang) + * + * ipc.c + * - IPC Abstraction + */ +#include +#include "include/common.hpp" +#include "include/IIPCChannel.hpp" +#include "include/CIPCChannel_AcessIPCPipe.hpp" +#include + +#include +#include + +namespace AxWin { + +IIPCChannel* gIPCChannel; + +extern "C" bool AxWin4_Connect(const char *URI) +{ + if( gIPCChannel ) { + return false; + } + try { + if( strncmp(URI, "ipcpipe://", 3+4+3) == 0 ) + { + gIPCChannel = new CIPCChannel_AcessIPCPipe(URI); + } + else + { + return false; + } + } + catch( const ::std::exception& e ) + { + fprintf(stderr, "AxWin4_Connect: %s\n", e.what()); + return false; + } + return true; +} + +extern "C" bool AxWin4_PeekEventQueue(void) +{ + return false; +} + +extern "C" bool AxWin4_WaitEventQueue(uint64_t Timeout) +{ + AxWin4_WaitEventQueueSelect(0, NULL, NULL, NULL, Timeout); +} + +extern "C" bool AxWin4_WaitEventQueueSelect(int nFDs, fd_set *rfds, fd_set *wfds, fd_set *efds, uint64_t Timeout) +{ + fd_set local_rfds; + if( !rfds ) + rfds = &local_rfds; + + int64_t select_timeout = Timeout; + int64_t *select_timeout_p = (Timeout ? &select_timeout : 0); + + nFDs = ::std::max(nFDs, gIPCChannel->FillSelect(*rfds)); + _SysSelect(nFDs, rfds, wfds, efds, select_timeout_p, 0); + return gIPCChannel->HandleSelect(*rfds); +} + +void SendMessage(CSerialiser& message) +{ + gIPCChannel->Send(message); +} + +IIPCChannel::~IIPCChannel() +{ +} + +}; // namespace AxWin + diff --git a/Usermode/Libraries/libaxwin4.so_src/ipc_acessipcpipe.cpp b/Usermode/Libraries/libaxwin4.so_src/ipc_acessipcpipe.cpp new file mode 100644 index 00000000..b7a509ce --- /dev/null +++ b/Usermode/Libraries/libaxwin4.so_src/ipc_acessipcpipe.cpp @@ -0,0 +1,47 @@ +/* + * AxWin4 Interface Library + * - By John Hodge (thePowersGang) + * + * ipc_acessipcpipe.c + * - Acess2 /Devices/ipcpipe/ IPC Channel + */ +#include "include/CIPCChannel_AcessIPCPipe.hpp" +#include +#include + +namespace AxWin { + +CIPCChannel_AcessIPCPipe::CIPCChannel_AcessIPCPipe(const char *Path) +{ + m_fd = _SysOpen(Path, OPENFLAG_READ|OPENFLAG_WRITE); + if( m_fd == -1 ) { + throw ::std::system_error(errno, ::std::system_category()); + } +} + +CIPCChannel_AcessIPCPipe::~CIPCChannel_AcessIPCPipe() +{ +} + +int CIPCChannel_AcessIPCPipe::FillSelect(fd_set& fds) +{ + FD_SET(m_fd, &fds); + return m_fd+1; +} + +bool CIPCChannel_AcessIPCPipe::HandleSelect(const fd_set& fds) +{ + if( FD_ISSET(m_fd, &fds) ) + { + } + return true; +} + +void CIPCChannel_AcessIPCPipe::Send(CSerialiser& message) +{ + // TODO: +} + + +}; // namespace AxWin + diff --git a/Usermode/Libraries/libaxwin4.so_src/main.c b/Usermode/Libraries/libaxwin4.so_src/main.c new file mode 100644 index 00000000..5d555823 --- /dev/null +++ b/Usermode/Libraries/libaxwin4.so_src/main.c @@ -0,0 +1,8 @@ +/* + */ +// === CODE === +int SoMain(void) +{ + return 0; +} + diff --git a/Usermode/Libraries/libaxwin4.so_src/wm.cpp b/Usermode/Libraries/libaxwin4.so_src/wm.cpp new file mode 100644 index 00000000..12c02c58 --- /dev/null +++ b/Usermode/Libraries/libaxwin4.so_src/wm.cpp @@ -0,0 +1,40 @@ +/* + * AxWin4 Interface Library + * - By John Hodge (thePowersGang) + * + * wm.cpp + * - Window Management + */ +#include +#include "include/common.hpp" +#include + +namespace AxWin { + +extern "C" tAxWin4_Window *AxWin4_CreateWindow(const char *Name) +{ + // Allocate a window ID + // Create window structure locally + // Request creation of window +} + +extern "C" void AxWin4_ShowWindow(tAxWin4_Window *Window) +{ + CSerialiser message; + message.WriteU16(Window->m_id); + message.WriteU16(IPC_WINATTR_SHOW); + message.WriteU8(1); + ::AxWin::SendMessage(message); +} + +extern "C" void AxWin4_SetTitle(tAxWin4_Window *Window, const char *Title) +{ + CSerialiser message; + message.WriteU16(Window->m_id); + message.WriteU16(IPC_WINATTR_TITLE); + message.WriteString(Title); + ::AxWin::SendMessage(message); +} + +}; // namespace AxWin + -- 2.20.1