From 4c33e0fb837f9a5deacc92c957261ed4717fb149 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 18 Jan 2020 20:19:38 -0500 Subject: [PATCH] Filled up more of the Haiku port, enough to build the library itself. --- haiku/controls.cpp | 20 +++++++++++++++++++ haiku/main.cpp | 44 ++++++++++++++++++++++++++++++++++++++++-- haiku/meson.build | 1 + haiku/uipriv_haiku.hpp | 5 +++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 haiku/controls.cpp diff --git a/haiku/controls.cpp b/haiku/controls.cpp new file mode 100644 index 00000000..5a0bd6ee --- /dev/null +++ b/haiku/controls.cpp @@ -0,0 +1,20 @@ +// 18 january 2020 +#include "uipriv_haiku.hpp" + +bool uiprivOSVtableValid(const uiControlOSVtable *osVtable, const char *func) +{ + if (osVtable->Size != sizeof (uiControlOSVtable)) { + uiprivProgrammerErrorWrongStructSize(osVtable->Size, "uiControlOSVtable", func); + return false; + } + return true; +} + +uiControlOSVtable *uiprivCloneOSVtable(const uiControlOSVtable *osVtable) +{ + uiControlOSVtable *v2; + + v2 = uiprivNew(uiControlOSVtable); + *v2 = *osVtable; + return v2; +} diff --git a/haiku/main.cpp b/haiku/main.cpp index 3dc96dfc..74c96ea9 100644 --- a/haiku/main.cpp +++ b/haiku/main.cpp @@ -5,7 +5,7 @@ uiprivApplication *uiprivApp; // TODO add format string warning detection to all these functions, where available // TODO also see if we can convert this to a string, or use a known type for status_t instead of assuming it's int(32_t) -#define uiprivInitReturnStatus(err, msg, status) uiprivInitReturnErrorf(err, "%s: %d", msg, status) +#define uiprivInitReturnStatus(err, msg, status) uiprivInitReturnErrorf(err, "%s: %ld", msg, status) static thread_id mainThread; @@ -35,9 +35,49 @@ void uiQuit(void) uiprivApp->Quit(); } +struct queueMainArgs { + void (*f)(void *data); + void *data; +}; + +void uiprivApplication::MessageReceived(BMessage *msg) +{ + const void *data; + const struct queueMainArgs *args; + ssize_t size; + status_t status; + + switch (msg->what) { + case uiprivMsgQueueMain: + status = msg->FindData("args", B_ANY_TYPE, + &data, &size); + if (status != B_OK) + uiprivInternalError("BMessage::FindData() failed in uiprivApplication::MessageReceived() for uiQueueMain(): %ld", status); + args = (const struct queueMainArgs *) data; + (*(args->f))(args->data); + delete msg; + return; + } + BApplication::MessageReceived(msg); +} + void uiprivSysQueueMain(void (*f)(void *data), void *data) { -// TODO + BMessage *msg; + struct queueMainArgs args; + status_t status; + + args.f = f; + args.data = data; + msg = new BMessage(uiprivMsgQueueMain); + status = msg->AddData("args", B_RAW_TYPE, + &args, sizeof (struct queueMainArgs), true, 1); + if (status != B_OK) + // TODO decide if we should just give up in this case like we do with user errors + uiprivInternalError("BMessage::AddData() failed in uiQueueMain(): %ld", status); + status = uiprivApp->PostMessage(msg); + if (status != B_OK) + uiprivInternalError("BApplication::PostMessage() failed in uiQueueMain(): %ld", status); } bool uiprivSysCheckThread(void) diff --git a/haiku/meson.build b/haiku/meson.build index db8067b4..956fc6f5 100644 --- a/haiku/meson.build +++ b/haiku/meson.build @@ -1,6 +1,7 @@ # 12 january 2020 libui_sources += [ + 'haiku/controls.cpp', 'haiku/main.cpp', ] diff --git a/haiku/uipriv_haiku.hpp b/haiku/uipriv_haiku.hpp index 32cb44d8..bf2d200a 100644 --- a/haiku/uipriv_haiku.hpp +++ b/haiku/uipriv_haiku.hpp @@ -6,7 +6,12 @@ #define uiprivOSHeader "../ui_haiku.h" #include "../common/uipriv.h" +constexpr uint32 uiprivMsgQueueMain = 'uiQM'; + // main.cpp class uiprivApplication : public BApplication { +public: + using BApplication::BApplication; + virtual void MessageReceived(BMessage *msg) override; }; extern uiprivApplication *uiprivApp;