From 7ef772c54ff216fee6c8a73198bf6c219887f8d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gyuhwan=20Park=E2=98=85?= Date: Sat, 28 Jan 2023 23:56:16 +0900 Subject: =?UTF-8?q?refactor:=20move=20implementations=20to=20Xrdp=CB=86Ula?= =?UTF-8?q?lacaPrivate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile.am | 4 + XrdpEvent.cpp | 13 ++++ XrdpUlalacaPrivate.cpp | 43 +++++++++++ XrdpUlalacaPrivate.hpp | 112 ++++++++++++++++++++++++++++ XrdpUlalacaPrivate.xrdpmodule.cpp | 150 ++++++++++++++++++++++++++++++++++++++ ulalaca.cpp | 143 +++++------------------------------- ulalaca.hpp | 65 ++--------------- 7 files changed, 347 insertions(+), 183 deletions(-) create mode 100644 XrdpEvent.cpp create mode 100644 XrdpUlalacaPrivate.cpp create mode 100644 XrdpUlalacaPrivate.hpp create mode 100644 XrdpUlalacaPrivate.xrdpmodule.cpp diff --git a/Makefile.am b/Makefile.am index 6099528..018681e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,6 +19,7 @@ libulalaca_la_SOURCES = \ SystemCallException.cpp \ SystemCallException.hpp \ XrdpEvent.hpp \ + XrdpEvent.cpp \ XrdpTransport.hpp \ XrdpTransport.cpp \ XrdpStream.hpp \ @@ -29,6 +30,9 @@ libulalaca_la_SOURCES = \ ProjectionThread.hpp \ ProjectionThread.cpp \ KeycodeMap.cpp \ + XrdpUlalacaPrivate.cpp \ + XrdpUlalacaPrivate.xrdpmodule.cpp \ + XrdpUlalacaPrivate.hpp \ ulalaca.cpp \ ulalaca.hpp diff --git a/XrdpEvent.cpp b/XrdpEvent.cpp new file mode 100644 index 0000000..2ddf58a --- /dev/null +++ b/XrdpEvent.cpp @@ -0,0 +1,13 @@ +// +// Created by Gyuhwan Park on 2023/01/28. +// + +#include "XrdpEvent.hpp" + +bool XrdpEvent::isKeyEvent() const { + return type == KEY_DOWN || type == KEY_UP; +} + +bool XrdpEvent::isMouseEvent() const { + return type >= MOUSE_MOVE && type <= MOUSE_UNKNOWN_2; +} diff --git a/XrdpUlalacaPrivate.cpp b/XrdpUlalacaPrivate.cpp new file mode 100644 index 0000000..60ca516 --- /dev/null +++ b/XrdpUlalacaPrivate.cpp @@ -0,0 +1,43 @@ +// +// Created by Gyuhwan Park on 2023/01/28. +// + +#include "XrdpUlalacaPrivate.hpp" + +#include "ProjectionThread.hpp" + +XrdpUlalacaPrivate::XrdpUlalacaPrivate(XrdpUlalaca *mod): + _mod(mod), + _error(0), + + _sessionSize(), + _screenLayouts(), + + _bpp(0), + + _frameId(0), + _ackFrameId(0), + + _username(), + _password(), + _ip(), + _port(), + + _keyLayout(0), + _delayMs(0), + _guid(), + _encodingsMask(0), + _clientInfo(), + + _socket(), + _projectionThread(), + + _fullInvalidate(false), + _commitUpdateLock(), + + _dirtyRects() +{ + +} + + diff --git a/XrdpUlalacaPrivate.hpp b/XrdpUlalacaPrivate.hpp new file mode 100644 index 0000000..45b0136 --- /dev/null +++ b/XrdpUlalacaPrivate.hpp @@ -0,0 +1,112 @@ +#ifndef XRDP_XRDPULALACAPRIVATE_HPP +#define XRDP_XRDPULALACAPRIVATE_HPP + +#if defined(HAVE_CONFIG_H) +#include +#endif + +extern "C" { +#include "arch.h" +#include "parse.h" +#include "os_calls.h" +#include "defines.h" +#include "guid.h" +#include "xrdp_client_info.h" +}; + +#include + +#include "XrdpEvent.hpp" +#include "XrdpTransport.hpp" +#include "XrdpStream.hpp" + +#include "UnixSocket.hpp" + +#include "messages/projector.h" + +struct XrdpUlalaca; +class ProjectionThread; + +class XrdpUlalacaPrivate { +public: + constexpr static const int RECT_SIZE_BYPASS_CREATE = 0; + + constexpr static const int NO_ERROR = 0; + + explicit XrdpUlalacaPrivate(XrdpUlalaca *mod); + XrdpUlalacaPrivate(XrdpUlalacaPrivate &) = delete; + + /* lib_mod_* */ + int libModStart(int width, int height, int bpp); + int libModConnect(); + int libModEvent(int type, long arg1, long arg2, long arg3, long arg4); + int libModSignal(); + int libModEnd(); + int libModSetParam(const char *cstrName, const char *cstrValue); + int libModSessionChange(int, int); + int libModGetWaitObjs(tbus *readObjs, int *rcount, + tbus *writeObjs, int *wcount, int *timeout); + int libModCheckWaitObjs(); + int libModFrameAck(int flags, int frameId); + int libModSuppressOutput(int suppress, + int left, int top, int right, int bottom); + int libModServerMonitorResize(int width, int height); + int libModServerMonitorFullInvalidate(int width, int height); + int libModServerVersionMessage(); + + /* utility methods / lib_server_* wrappers */ + void serverMessage(const char *message, int code); + + /* session-broker related */ + inline std::string getSessionSocketPathUsingCredential( + const std::string &username, + const std::string &password + ); + + /* paint related */ + inline int decideCopyRectSize() const; + inline std::unique_ptr> createCopyRects(std::vector &dirtyRects, int rectSize) const; + + void addDirtyRect(Rect &rect); + void commitUpdate(const uint8_t *image, int32_t width, int32_t height); + + void calculateSessionSize(); + + inline bool isRFXCodec() const; + inline bool isJPEGCodec() const; + inline bool isH264Codec() const; + inline bool isGFXH264Codec() const; + inline bool isRawBitmap() const; + +private: + XrdpUlalaca *_mod; + int _error = 0; + + ULIPCRect _sessionSize; + std::vector _screenLayouts; + + int _bpp; + + std::atomic_int64_t _frameId; + std::atomic_int64_t _ackFrameId; + + std::string _username; + std::string _password; + std::string _ip; + std::string _port; + int _keyLayout; + int _delayMs; + guid _guid; + int _encodingsMask; + xrdp_client_info _clientInfo; + + std::unique_ptr _socket; + std::unique_ptr _projectionThread; + + std::atomic_bool _fullInvalidate; + std::mutex _commitUpdateLock; + + std::vector _dirtyRects; +}; + +#endif \ No newline at end of file diff --git a/XrdpUlalacaPrivate.xrdpmodule.cpp b/XrdpUlalacaPrivate.xrdpmodule.cpp new file mode 100644 index 0000000..1400046 --- /dev/null +++ b/XrdpUlalacaPrivate.xrdpmodule.cpp @@ -0,0 +1,150 @@ +#include "XrdpUlalacaPrivate.hpp" +#include "ulalaca.hpp" + +int XrdpUlalacaPrivate::libModStart(int width, int height, int bpp) { + // #517eb9 + constexpr const unsigned int BACKGROUND_COLOR = 0xb97e51; + + _screenLayouts.clear(); + _screenLayouts.emplace_back(ULIPCRect { + 0, 0, (short) width, (short) height + }); + calculateSessionSize(); + + _mod->server_begin_update(_mod); + _mod->server_set_fgcolor(_mod, (int) BACKGROUND_COLOR); + _mod->server_fill_rect(_mod, 0, 0, width, height); + _mod->server_end_update(_mod); + + if (!isBPPSupported(bpp)) { + return 1; + } + + _bpp = bpp; + // _this->updateBpp(bpp); + + return 0; +} + +int XrdpUlalacaPrivate::libModConnect() { + try { + std::string socketPath = _this->getSessionSocketPathUsingCredential( + _this->_username, _this->_password + ); + _this->_password.clear(); + + if (socketPath.empty()) { + return 1; + } + + _this->_projectionThread = std::make_unique( + *_this, socketPath + ); + + _this->_projectionThread->start(); + + LOG(LOG_LEVEL_TRACE, "sessionSize: %d, %d", _this->_sessionSize.width, _this->_sessionSize.height); + _this->_projectionThread->setViewport(_this->_sessionSize); + _this->_projectionThread->setOutputSuppression(false); + } catch (SystemCallException &e) { + _this->serverMessage(e.what(), 0); + return 1; + } + + _this->serverMessage("welcome to the fantasy zone, get ready!", 0); + + return 0; +} + +int XrdpUlalacaPrivate::libModEvent(int type, long arg1, long arg2, long arg3, long arg4) { + XrdpEvent event { + (XrdpEvent::Type) type, + arg1, arg2, arg3, arg4 + }; + + if (_projectionThread != nullptr) { + _projectionThread->handleEvent(std::move(event)); + } + + return 0; +} + +int XrdpUlalacaPrivate::libModSignal() { + LOG(LOG_LEVEL_INFO, "lib_mod_signal() called"); + return 0; +} + +int XrdpUlalacaPrivate::libModEnd() { + LOG(LOG_LEVEL_INFO, "lib_mod_end() called"); + + if (_this->_projectionThread != nullptr) { + _this->_projectionThread->stop(); + } + + return 0; +} + +int XrdpUlalacaPrivate::libModSetParam(const char *cstrName, const char *cstrValue) { + std::string name(cstrName); + std::string value(cstrValue); + + if (name == "username") { + _username = value; + } else if (name == "password") { + _password = value; + } else if (name == "ip") { + _ip = value; + } else if (name == "port") { + _port = value; + } else if (name == "keylayout") { + _keyLayout = std::stoi(value); + } else if (name == "delay_ms") { + _delayMs = std::stoi(value); + } else if (name == "guid") { + auto *_guid = reinterpret_cast(value); + _guid = *_guid; + } else if (name == "disabled_encodings_mask") { + _encodingsMask = ~std::stoi(value); + } else if (name == "client_info") { + auto *clientInfo = reinterpret_cast(value); + _clientInfo = *clientInfo; + } + + return 0; +} + +int XrdpUlalacaPrivate::libModSessionChange(int, int) { + return 0; +} + +int XrdpUlalacaPrivate::libModGetWaitObjs(tbus *readObjs, int *rcount, tbus *writeObjs, int *wcount, int *timeout) { + return 0; +} + +int XrdpUlalacaPrivate::libModCheckWaitObjs() { + return 0; +} + +int XrdpUlalacaPrivate::libModFrameAck(int flags, int frameId) { + LOG(LOG_LEVEL_TRACE, "lib_mod_frame_ack() called: %d", frame_id); + _this->_ackFrameId = frame_id; + + return 0; +} + +int XrdpUlalacaPrivate::libModSuppressOutput(int suppress, int left, int top, int right, int bottom) { + return 0; +} + +int XrdpUlalacaPrivate::libModServerMonitorResize(int width, int height) { + return 0; +} + +int XrdpUlalacaPrivate::libModServerMonitorFullInvalidate(int width, int height) { + _this->_fullInvalidate = true; + return 0; +} + +int XrdpUlalacaPrivate::libModServerVersionMessage() { + return 0; +} diff --git a/ulalaca.cpp b/ulalaca.cpp index f0c79cf..b660d40 100644 --- a/ulalaca.cpp +++ b/ulalaca.cpp @@ -15,17 +15,13 @@ #include "messages/broker.h" #include "ulalaca.hpp" + +#include "XrdpUlalacaPrivate.hpp" #include "SocketStream.hpp" #include "ProjectionThread.hpp" -bool XrdpEvent::isKeyEvent() const { - return type == KEY_DOWN || type == KEY_UP; -} -bool XrdpEvent::isMouseEvent() const { - return type >= MOUSE_MOVE && type <= MOUSE_UNKNOWN_2; -} XrdpUlalaca::XrdpUlalaca(): size(sizeof(XrdpUlalaca)), @@ -47,165 +43,66 @@ XrdpUlalaca::XrdpUlalaca(): mod_server_version_message(&lib_mod_server_version_message), si(nullptr), - - _fullInvalidate(true), - _sessionSize { 0, 0, 640, 480 }, - - _bpp(0), - _encodingsMask(0), - _keyLayout(0), - _delayMs(0) + + _impl(std::make_unique(this)) { } int XrdpUlalaca::lib_mod_event(XrdpUlalaca *_this, int type, long arg1, long arg2, long arg3, long arg4) { - LOG(LOG_LEVEL_DEBUG, "lib_mod_event() called: %d", type); - - XrdpEvent event { - (XrdpEvent::Type) type, - arg1, arg2, arg3, arg4 - }; - - if (_this->_projectionThread != nullptr) { - _this->_projectionThread->handleEvent(event); - } - - return 0; + return _this->_impl->libModEvent(type, arg1, arg2, arg3, arg4); } int XrdpUlalaca::lib_mod_start(XrdpUlalaca *_this, int width, int height, int bpp) { - constexpr const unsigned int BACKGROUND_COLOR = 0xb97e51; - - _this->_screenLayouts.clear(); - _this->_screenLayouts.emplace_back(Rect { - 0, 0, (short) width, (short) height - }); - _this->calculateSessionSize(); - - - _this->server_begin_update(_this); - _this->server_set_fgcolor(_this, (int) BACKGROUND_COLOR); - _this->server_fill_rect(_this, 0, 0, width, height); - _this->server_end_update(_this); - - _this->_bpp = bpp; - // _this->updateBpp(bpp); - - return 0; + return _this->_impl->libModStart(width, height, bpp); } -int XrdpUlalaca::lib_mod_set_param(XrdpUlalaca *_this, const char *_name, const char *_value) { - std::string name(_name); - std::string value(_value); - - if (name == "username") { - _this->_username = value; - } else if (name == "password") { - _this->_password = value; - } else if (name == "ip") { - _this->_ip = value; - } else if (name == "port") { - _this->_port = value; - } else if (name == "keylayout") { - _this->_keyLayout = std::stoi(value); - } else if (name == "delay_ms") { - _this->_delayMs = std::stoi(value); - } else if (name == "guid") { - auto *_guid = reinterpret_cast(_value); - _this->_guid = *_guid; - } else if (name == "disabled_encodings_mask") { - _this->_encodingsMask = ~std::stoi(value); - } else if (name == "client_info") { - auto *clientInfo = reinterpret_cast(_value); - _this->_clientInfo = *clientInfo; - } - - return 0; +int XrdpUlalaca::lib_mod_set_param(XrdpUlalaca *_this, const char *name, const char *value) { + return _this->_impl->libModSetParam(name, value); } int XrdpUlalaca::lib_mod_connect(XrdpUlalaca *_this) { - try { - std::string socketPath = _this->getSessionSocketPathUsingCredential( - _this->_username, _this->_password - ); - _this->_password.clear(); - - if (socketPath.empty()) { - return 1; - } - - _this->_projectionThread = std::make_unique( - *_this, socketPath - ); - - _this->_projectionThread->start(); - - LOG(LOG_LEVEL_TRACE, "sessionSize: %d, %d", _this->_sessionSize.width, _this->_sessionSize.height); - _this->_projectionThread->setViewport(_this->_sessionSize); - _this->_projectionThread->setOutputSuppression(false); - } catch (SystemCallException &e) { - _this->serverMessage(e.what(), 0); - return 1; - } - - _this->serverMessage("welcome to the fantasy zone, get ready!", 0); - - return 0; + return _this->_impl->libModConnect(); } int XrdpUlalaca::lib_mod_signal(XrdpUlalaca *_this) { - LOG(LOG_LEVEL_INFO, "lib_mod_signal() called"); - return 0; + return _this->_impl->libModSignal(); } int XrdpUlalaca::lib_mod_end(XrdpUlalaca *_this) { - LOG(LOG_LEVEL_INFO, "lib_mod_end() called"); - - if (_this->_projectionThread != nullptr) { - _this->_projectionThread->stop(); - } - - return 0; + return _this->_impl->libModEnd(); } -int XrdpUlalaca::lib_mod_session_change(XrdpUlalaca *_this, int, int) { - return 0; +int XrdpUlalaca::lib_mod_session_change(XrdpUlalaca *_this, int arg1, int arg2) { + return _this->_impl->libModSessionChange(arg1, arg2); } int XrdpUlalaca::lib_mod_get_wait_objs(XrdpUlalaca *_this, tbus *read_objs, int *rcount, tbus *write_objs, int *wcount, int *timeout) { - // LOG(LOG_LEVEL_INFO, "lib_mod_get_wait_objs() called"); - return 0; + return _this->_impl->libModGetWaitObjs(read_objs, rcount, write_objs, wcount, timeout); } int XrdpUlalaca::lib_mod_check_wait_objs(XrdpUlalaca *_this) { - // LOG(LOG_LEVEL_INFO, "lib_mod_check_wait_objs() called"); - return 0; + return _this->_impl->libModCheckWaitObjs(); } int XrdpUlalaca::lib_mod_frame_ack(XrdpUlalaca *_this, int flags, int frame_id) { - LOG(LOG_LEVEL_TRACE, "lib_mod_frame_ack() called: %d", frame_id); - _this->_ackFrameId = frame_id; - - return 0; + return _this->_impl->libModFrameAck(flags, frame_id); } int XrdpUlalaca::lib_mod_suppress_output(XrdpUlalaca *_this, int suppress, int left, int top, int right, int bottom) { - LOG(LOG_LEVEL_INFO, "lib_mod_suppress_output() called"); - return 0; + return _this->_impl->libModSuppressOutput(suppress, left, top, right, bottom); } int XrdpUlalaca::lib_mod_server_monitor_resize(XrdpUlalaca *_this, int width, int height) { - return 0; + return _this->_impl->libModServerMonitorResize(width, height); } int XrdpUlalaca::lib_mod_server_monitor_full_invalidate(XrdpUlalaca *_this, int width, int height) { - _this->_fullInvalidate = true; - return 0; + return _this->_impl->libModServerMonitorFullInvalidate(width, height); } int XrdpUlalaca::lib_mod_server_version_message(XrdpUlalaca *_this) { - return 0; + return _this->_impl->libModServerVersionMessage(); } std::string XrdpUlalaca::getSessionSocketPathUsingCredential( diff --git a/ulalaca.hpp b/ulalaca.hpp index bd4c54e..62e386c 100644 --- a/ulalaca.hpp +++ b/ulalaca.hpp @@ -24,7 +24,9 @@ extern "C" { #include "messages/projector.h" -class ProjectionThread; +constexpr static const int ULALACA_VERSION = 1; + +class XrdpUlalacaPrivate; extern "C" { @@ -157,15 +159,8 @@ struct XrdpUlalaca { tintptr wm; /* struct xrdp_wm* */ tintptr painter; struct source_info *si; - -public: - using Rect = ULIPCRect; - - static const int RECT_SIZE_BYPASS_CREATE = 0; - constexpr static const int ULALACA_VERSION = 1; - constexpr static const int NO_ERROR = 0; - +public: explicit XrdpUlalaca(); static int lib_mod_start(XrdpUlalaca *_this, int width, int height, int bpp); @@ -187,59 +182,9 @@ public: static int lib_mod_server_monitor_full_invalidate(XrdpUlalaca *_this, int width, int height); static int lib_mod_server_version_message(XrdpUlalaca *_this); - - /* session-broker related */ - inline std::string getSessionSocketPathUsingCredential( - const std::string &username, - const std::string &password - ); - - /* paint related */ - inline int decideCopyRectSize() const; - inline std::unique_ptr> createCopyRects(std::vector &dirtyRects, int rectSize) const; - void addDirtyRect(Rect &rect); - void commitUpdate(const uint8_t *image, int32_t width, int32_t height); - - void calculateSessionSize(); - - inline bool isRFXCodec() const; - inline bool isJPEGCodec() const; - inline bool isH264Codec() const; - inline bool isGFXH264Codec() const; - inline bool isRawBitmap() const; - - /* utility methods / lib_server_* wrappers */ - void serverMessage(const char *message, int code); - private: - int _error = 0; - - Rect _sessionSize; - std::vector _screenLayouts; - - int _bpp; - - std::atomic_int64_t _frameId = 0; - std::atomic_int64_t _ackFrameId = 0; - - std::string _username; - std::string _password; - std::string _ip; - std::string _port; - int _keyLayout; - int _delayMs; - guid _guid; - int _encodingsMask; - xrdp_client_info _clientInfo; - - std::unique_ptr _socket; - std::unique_ptr _projectionThread; - - std::atomic_bool _fullInvalidate; - std::mutex _commitUpdateLock; - - std::vector _dirtyRects; + std::unique_ptr _impl; }; }; -- cgit v1.2.3