diff --git a/frontends/qt/BitBox.pro b/frontends/qt/BitBox.pro index 79400f65ac..c408298544 100644 --- a/frontends/qt/BitBox.pro +++ b/frontends/qt/BitBox.pro @@ -56,8 +56,7 @@ SOURCES += \ main.cpp \ filedialog.cpp -# server/libserver.h is generated by building server.go, see the Makefiles in server/. -HEADERS += server/libserver.h webclass.h filedialog.h +HEADERS += libserver.h webclass.h filedialog.h unix:macx { # Those frameworks are needed for Go's http/net packages. diff --git a/frontends/qt/libserver.h b/frontends/qt/libserver.h new file mode 100644 index 0000000000..91d2d7f863 --- /dev/null +++ b/frontends/qt/libserver.h @@ -0,0 +1,55 @@ +#ifndef BACKEND_H +#define BACKEND_H +#include +#include +#include + +// Workaround to be able to use `const char*` as a param type in the exported Go functions. +typedef const char cchar_t; + +typedef void (*pushNotificationsCallback) (const char*); +static void pushNotify(pushNotificationsCallback f, const char* msg) { + f(msg); +} + +typedef void (*responseCallback) (int, const char*); +static void respond(responseCallback f, int queryID, const char* msg) { + f(queryID, msg); +} + +typedef void (*notifyUserCallback) (const char*); +static void notifyUser(notifyUserCallback f, const char* msg) { + f(msg); +} + +typedef char* (*getSaveFilenameCallback) (const char*); +static char* getSaveFilename(getSaveFilenameCallback f, const char* suggestedfilename) { + return f(suggestedfilename); +} + +// equivalent to C.free but suitable for releasing a memory malloc'ed +// in a non-posix portable environment, incompatible with cgo. +// this is especially important on windows where the standard C runtime +// memory management used by cgo and mingw is different from win32 API used +// when compiling C++ code with MSVC. hence, the memory allocated with malloc +// in C++ must always be freed by this function in Go instead of C.free. +typedef void (*cppHeapFree) (void* ptr); +static void customHeapFree(cppHeapFree f, void* ptr) { + f(ptr); +} + +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +extern void backendCall(int queryID, cchar_t* s); +extern void handleURI(cchar_t* uri); +extern void serve(cppHeapFree cppHeapFreeFn, pushNotificationsCallback pushNotificationsFn, responseCallback responseFn, notifyUserCallback notifyUserFn, cchar_t* preferredLocale, getSaveFilenameCallback getSaveFilenameFn); +extern void systemOpen(cchar_t* url); +extern void goLog(cchar_t* msg); + +#ifdef __cplusplus +} +#endif diff --git a/frontends/qt/main.cpp b/frontends/qt/main.cpp index 9914d82245..5a50581156 100644 --- a/frontends/qt/main.cpp +++ b/frontends/qt/main.cpp @@ -43,7 +43,7 @@ #include #include "filedialog.h" -#include "server/libserver.h" +#include "libserver.h" #include "webclass.h" #define APPNAME "BitBoxApp" diff --git a/frontends/qt/webclass.h b/frontends/qt/webclass.h index 625defe90b..fb38f02cfc 100644 --- a/frontends/qt/webclass.h +++ b/frontends/qt/webclass.h @@ -14,7 +14,7 @@ #include -#include "server/libserver.h" +#include "libserver.h" class WebClass : public QObject {