From 78b10d53be7ae04b15922ee267958c6627caa3b3 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 12 Feb 2024 09:47:22 +0100 Subject: [PATCH 001/115] add partial AppFileInfo --- Jamfile | 2 +- bindings/__init__.py | 2 ++ bindings/storage/AppFileInfo.cpp | 20 ++++++-------------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Jamfile b/Jamfile index 1d43c2d..d3a8de9 100644 --- a/Jamfile +++ b/Jamfile @@ -229,7 +229,7 @@ local sourceFiles = Query.cpp NodeMonitor.cpp NodeInfo.cpp - #AppFileInfo.cpp + AppFileInfo.cpp #DiskDeviceDefs.cpp FilePanel.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index f301b56..660c749 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -121,6 +121,8 @@ from .Mime import * from .MimeType import * +from .NodeInfo import * +from .AppFileInfo import * from .Resources import * from .ResourceStrings import * from .EntryList import * diff --git a/bindings/storage/AppFileInfo.cpp b/bindings/storage/AppFileInfo.cpp index fd4be12..d98899d 100644 --- a/bindings/storage/AppFileInfo.cpp +++ b/bindings/storage/AppFileInfo.cpp @@ -8,7 +8,7 @@ namespace py = pybind11; -struct version_info { +/*struct version_info { uint32_t major; uint32_t middle; uint32_t minor; @@ -16,7 +16,7 @@ struct version_info { uint32_t internal; char short_info[64]; char long_info[256]; -}; +};*/ PYBIND11_MODULE(AppFileInfo, m) { @@ -39,16 +39,7 @@ py::enum_(m, "version_kind", "") .value("B_APP_VERSION_KIND", version_kind::B_APP_VERSION_KIND, "") .value("B_SYSTEM_VERSION_KIND", version_kind::B_SYSTEM_VERSION_KIND, "") .export_values(); -/* -py::class_(m, "version_info") -.def_readwrite("major", &version_info::major, "") -.def_readwrite("middle", &version_info::middle, "") -.def_readwrite("minor", &version_info::minor, "") -.def_readwrite("variety", &version_info::variety, "") -.def_readwrite("internal", &version_info::internal, "") -.def_readwrite("short_info", &version_info::short_info, "") -.def_readwrite("long_info", &version_info::long_info, "") -;*/ + py::class_(m, "version_info") .def(py::init<>()) .def_readwrite("major", &version_info::major, "") @@ -56,8 +47,9 @@ py::class_(m, "version_info") .def_readwrite("minor", &version_info::minor, "") .def_readwrite("variety", &version_info::variety, "") .def_readwrite("internal", &version_info::internal, "") -.def_readwrite("short_info", &version_info::short_info, "") -.def_readwrite("long_info", &version_info::long_info, ""); +//.def_readwrite("short_info", &version_info::short_info, "") +//.def_readwrite("long_info", &version_info::long_info, "") +; py::class_(m, "BAppFileInfo") .def(py::init(), "") From 1ef7ea82e0329ffab64aa24aed2593d702f88c33 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 13 Feb 2024 06:59:54 +0100 Subject: [PATCH 002/115] TODO note --- bindings/interface/GraphicsDefs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/interface/GraphicsDefs.cpp b/bindings/interface/GraphicsDefs.cpp index 273b38f..8b57444 100644 --- a/bindings/interface/GraphicsDefs.cpp +++ b/bindings/interface/GraphicsDefs.cpp @@ -175,7 +175,7 @@ py::class_(m, "rgb_color") .def_readwrite("alpha", &rgb_color::alpha, "") ; -py::class_(m, "color_map") +py::class_(m, "color_map")//TODO: color_list,inversion_map,index_map are writable .def_readwrite("id", &color_map::id, "") //.def_readwrite("color_list", &color_map::color_list, "") .def_readonly("color_list", &color_map::color_list, "") From aafba5542e3571d23037e86759fa3fae85c050fa Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 13 Feb 2024 10:46:19 +0100 Subject: [PATCH 003/115] Add short_info & long_info in version_info --- bindings/storage/AppFileInfo.cpp | 48 +++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/bindings/storage/AppFileInfo.cpp b/bindings/storage/AppFileInfo.cpp index d98899d..8fb2278 100644 --- a/bindings/storage/AppFileInfo.cpp +++ b/bindings/storage/AppFileInfo.cpp @@ -8,7 +8,9 @@ namespace py = pybind11; -/*struct version_info { +/* +// promemoria +struct version_info { uint32_t major; uint32_t middle; uint32_t minor; @@ -47,8 +49,52 @@ py::class_(m, "version_info") .def_readwrite("minor", &version_info::minor, "") .def_readwrite("variety", &version_info::variety, "") .def_readwrite("internal", &version_info::internal, "") +// TODO Test short_info & long_info //.def_readwrite("short_info", &version_info::short_info, "") +.def_property( + "short_info", + [](const version_info &info) { + return py::cast(info.short_info); + }, + //tentativo non provato n.1 + /*py::array_t result(){ + char data[64]; + return py::array_t{64},{1},data + }; + }. + std::memcpy(result.mutable_data(), &info.short_info, sizeof(info.short_info)); + return result; + }, + [](version_info &info, py::array_t value) { + if (value.size() != 64) { //check how write minor + throw std::runtime_error("Array must have size 64"); + } + std::memcpy(&info.short_info, value.data(), sizeof(info.short_info)); + }*/ + [](version_info &info, const std::string &value) { + if (value.size()(m, "BAppFileInfo") From 563042e2630aa1a2b945f42ec95b1b368e11bdc7 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 13 Feb 2024 10:48:20 +0100 Subject: [PATCH 004/115] todo/ask comments --- bindings/interface/InterfaceDefs.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindings/interface/InterfaceDefs.cpp b/bindings/interface/InterfaceDefs.cpp index 5b248aa..0e50974 100644 --- a/bindings/interface/InterfaceDefs.cpp +++ b/bindings/interface/InterfaceDefs.cpp @@ -286,7 +286,7 @@ m.attr("B_DISABLED_MARK_TINT") = B_DISABLED_MARK_TINT; py::class_(m, "key_info") .def_readwrite("modifiers", &key_info::modifiers, "") -.def_readonly("key_states", &key_info::key_states, "") +.def_readonly("key_states", &key_info::key_states, "") //TODO is this really Read-Only? ; py::class_(m, "key_map") @@ -304,6 +304,7 @@ py::class_(m, "key_map") .def_readwrite("right_option_key", &key_map::right_option_key, "") .def_readwrite("menu_key", &key_map::menu_key, "") .def_readwrite("lock_settings", &key_map::lock_settings, "") +// TODO are these read-only? .def_readonly("control_map", &key_map::control_map, "") .def_readonly("option_caps_shift_map", &key_map::option_caps_shift_map, "") .def_readonly("option_caps_map", &key_map::option_caps_map, "") From fdd1693932b1e4154ebb15b94d6c8ea69335f62a Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 17 Feb 2024 17:38:57 +0100 Subject: [PATCH 005/115] AppFileInfo test --- fstest.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fstest.py b/fstest.py index ff46c4e..2e61820 100644 --- a/fstest.py +++ b/fstest.py @@ -1,7 +1,8 @@ import os, sys, struct#, ctypes -from Be import BApplication,BNode,BEntry,BBitmap,BNodeInfo +from Be import BApplication,BNode,BEntry,BBitmap,BNodeInfo,BFile,BAppFileInfo from Be.Entry import entry_ref from Be import BMimeType,BRect,BPathFinder,BStringList +from Be.AppFileInfo import version_info,version_kind from Be.Mime import icon_size from Be.GraphicsDefs import * from Be.FindDirectory import directory_which,path_base_directory @@ -79,6 +80,18 @@ def ReadyToRun(self): #f=os.path.abspath("/boot/system/Tracker")#Haiku-friûl.png")#fstest.py") carta=card(f) #print(f) + bf = BFile(f,0) + vi = version_info() + bafi = BAppFileInfo(bf) + bafi.GetVersionInfo(vi,version_kind.B_APP_VERSION_KIND) + try: + print(vi.short_info) + except: + print("no short_info") + try: + print(vi.long_info) + except: + print("no long_info") nf = BNode(f) Ni = BNodeInfo(nf) icondata=[] From f9ad055833a75986fe8a8507f61bb27a417157e5 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 17 Feb 2024 17:45:29 +0100 Subject: [PATCH 006/115] short_info write test --- fstest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fstest.py b/fstest.py index 2e61820..3ac0e22 100644 --- a/fstest.py +++ b/fstest.py @@ -84,6 +84,8 @@ def ReadyToRun(self): vi = version_info() bafi = BAppFileInfo(bf) bafi.GetVersionInfo(vi,version_kind.B_APP_VERSION_KIND) + #vi.short_info="File system tests" + #bafi.SetVersionInfo(vi,version_kind.B_APP_VERSION_KIND) try: print(vi.short_info) except: From f896f049535eb53d6d07d6b9ec0b1199a23d3a64 Mon Sep 17 00:00:00 2001 From: Zardshard <0azrune6@zard.anonaddy.com> Date: Thu, 29 Feb 2024 19:27:35 -0500 Subject: [PATCH 007/115] Mark BLooper as py::nodelete --- bindings/app/Looper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/app/Looper.cpp b/bindings/app/Looper.cpp index 38b23ad..1347dc2 100644 --- a/bindings/app/Looper.cpp +++ b/bindings/app/Looper.cpp @@ -69,7 +69,7 @@ void QuitWrapper(BLooper& self) { PYBIND11_MODULE(Looper,m) { -py::class_(m, "BLooper") +py::class_>(m, "BLooper") .def(py::init(), "", py::arg("name")=NULL, py::arg("priority")=B_NORMAL_PRIORITY, py::arg("portCapacity")=B_LOOPER_PORT_DEFAULT_CAPACITY) .def(py::init(), "", py::arg("data")) .def_static("Instantiate", &BLooper::Instantiate, "", py::arg("data")) From 4b6d3f24295fac739368574f299e8e4c0ce134ca Mon Sep 17 00:00:00 2001 From: Zardshard <0azrune6@zard.anonaddy.com> Date: Fri, 5 Apr 2024 19:50:54 -0400 Subject: [PATCH 008/115] Fix Python object inheritance problem for BLooper Makes that a Python class subclassing BLooper is not "forgotten" as soon as Python no longer holds any references to it, even though C++ is still using it. This "forgetting" is caused by Python being unaware that C++ holds a reference to the Python subclass. So, once Python no longer holds any references, it frees the subclass. This, in effect, removes all of the method overrides of the base class and leads to methods of the base class being called directly. Part of this commit involves switching to the smart_holder branch of pybind11. Smart holders ensure that C++ gaining a shared_pointer to a class also increments the reference count. This turned out to be unnecessary to fix the problem, at least in the case of BLooper. However, it is likely that it will be necessary for some other classes so I have decided to keep those changes. This commit partially breaks BWindow, since it had to be switch from py::nodelete to py::smart_holder. --- .gitmodules | 4 ++ Jamfile | 2 +- bindings/app/Application.cpp | 6 ++- bindings/app/Handler.cpp | 6 ++- bindings/app/Looper.cpp | 64 ++++++++++++++++++++++++----- bindings/interface/Alert.cpp | 6 ++- bindings/interface/Window.cpp | 6 ++- pybind11 | 1 + tests/README | 3 ++ tests/looperLifetime.py | 76 +++++++++++++++++++++++++++++++++++ 10 files changed, 154 insertions(+), 20 deletions(-) create mode 100644 .gitmodules create mode 160000 pybind11 create mode 100644 tests/README create mode 100644 tests/looperLifetime.py diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0a6f1a6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "pybind11"] + path = pybind11 + url = https://github.com/pybind/pybind11 + branch = smart_holder diff --git a/Jamfile b/Jamfile index d3a8de9..bdb95fc 100644 --- a/Jamfile +++ b/Jamfile @@ -78,7 +78,7 @@ SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/stora SubDirHdrs headers ; SubDirHdrs headers/app ; SubDirHdrs headers/interface ; -SubDirHdrs /system/lib/python$(python_version)/vendor-packages/pybind11/include/ ; +SubDirHdrs pybind11/include/ ; SubDirHdrs /system/develop/headers/python$(python_version)/ ; # Additional C++ flags to use when compiling diff --git a/bindings/app/Application.cpp b/bindings/app/Application.cpp index 4707368..f67b237 100644 --- a/bindings/app/Application.cpp +++ b/bindings/app/Application.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -88,11 +88,13 @@ void ArgvReceivedWrapper(BApplication& self, int32 argc, std::vector argv self.ArgvReceived(argc, argv.data()); } +PYBIND11_SMART_HOLDER_TYPE_CASTERS(BApplication); + PYBIND11_MODULE(Application,m) { py::module_::import("Be.Messenger"); -py::class_(m, "BApplication") +py::class_(m, "BApplication") .def(py::init(), "", py::arg("signature")) .def(py::init(), "", py::arg("signature"), py::arg("error")) .def(py::init(), "", py::arg("data")) diff --git a/bindings/app/Handler.cpp b/bindings/app/Handler.cpp index a2cef55..e30dbf7 100644 --- a/bindings/app/Handler.cpp +++ b/bindings/app/Handler.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -14,6 +14,8 @@ namespace py = pybind11; using namespace BPrivate; +PYBIND11_SMART_HOLDER_TYPE_CASTERS(BHandler); + class PyBHandler : public BHandler{ public: using BHandler::BHandler; @@ -53,7 +55,7 @@ PYBIND11_MODULE(Handler,m) { m.attr("B_OBSERVER_OBSERVE_ALL") = B_OBSERVER_OBSERVE_ALL; -py::class_(m, "BHandler") +py::class_(m, "BHandler") .def(py::init(), "", py::arg("name")=NULL) .def(py::init(), "", py::arg("data")) .def_static("Instantiate", &BHandler::Instantiate, "", py::arg("data")) diff --git a/bindings/app/Looper.cpp b/bindings/app/Looper.cpp index 1347dc2..d9679dd 100644 --- a/bindings/app/Looper.cpp +++ b/bindings/app/Looper.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -17,6 +17,23 @@ using namespace BPrivate; class PyBLooper : public BLooper{ public: using BLooper::BLooper; + ~PyBLooper() override { + try { + // Call function overriding the destructor, if any. We can't + // use PYBIND11_OVERLOAD since that attempts to return from the + // destructor. + py::gil_scoped_acquire acquire; + py::function override = py::get_override(this, "__del__"); + if (override) { + override(); + } + } catch (py::error_already_set &e) { + // Return Python exception back to Python. Throwing from a + // destructor would crash the program, but we just want Python + // to print an error message. + e.discard_as_unraisable(__func__); + } + } status_t Archive(BMessage* data, bool deep = true) const override { PYBIND11_OVERLOAD(status_t, BLooper, Archive, data, deep); } @@ -26,12 +43,28 @@ class PyBLooper : public BLooper{ void MessageReceived(BMessage* message) override { PYBIND11_OVERLOAD(void, BLooper, MessageReceived, message); } - thread_id Run() override { - PYBIND11_OVERLOAD(thread_id, BLooper, Run); - } - void Quit() override { - PYBIND11_OVERLOAD(void, BLooper, Quit); - } + thread_id Run() override { + py::gil_scoped_acquire acquire; + + // Python should not delete the class after run is called + // FIXME: What if the Python overload never actually calls + // BLooper::Run? Then the looper isn't actually running and should + // still be deletable + do_not_delete = py::cast(this); + + PYBIND11_OVERLOAD(thread_id, BLooper, Run); + } + void Quit() override { + py::gil_scoped_acquire acquire; + + // Not sure if it's actually necessary to release the reference + // to ourselves, since we will delete ourselves anyway. + // FIXME: What if the Python overload never actually calls + // BLooper::Quit? + do_not_delete.release(); + + PYBIND11_OVERLOAD(void, BLooper, Quit); + } bool QuitRequested() override { PYBIND11_OVERLOAD(bool, BLooper, QuitRequested); } @@ -53,6 +86,11 @@ class PyBLooper : public BLooper{ status_t Perform(perform_code d, void* arg) override { PYBIND11_OVERLOAD(status_t, BLooper, Perform, d, arg); } + + private: + // holds a reference to our object in Python to prevent Python from + // deleting us when we're not ready + py::object do_not_delete; }; void QuitWrapper(BLooper& self) { @@ -62,16 +100,20 @@ void QuitWrapper(BLooper& self) { // running Python code. py::gil_scoped_release release; - self.Quit(); + self.BLooper::Quit(); + // Avoids calling PyBLooper::Quit + // If the code reaches this point, the global interpreter lock is // reacquired, otherwise, it isn't. Exactly the behaviour we want. } +PYBIND11_SMART_HOLDER_TYPE_CASTERS(BLooper); + PYBIND11_MODULE(Looper,m) { -py::class_>(m, "BLooper") -.def(py::init(), "", py::arg("name")=NULL, py::arg("priority")=B_NORMAL_PRIORITY, py::arg("portCapacity")=B_LOOPER_PORT_DEFAULT_CAPACITY) -.def(py::init(), "", py::arg("data")) +py::class_(m, "BLooper") +.def(py::init_alias(), "", py::arg("name")=NULL, py::arg("priority")=B_NORMAL_PRIORITY, py::arg("portCapacity")=B_LOOPER_PORT_DEFAULT_CAPACITY) +.def(py::init_alias(), "", py::arg("data")) .def_static("Instantiate", &BLooper::Instantiate, "", py::arg("data")) .def("Archive", &BLooper::Archive, "", py::arg("data"), py::arg("deep")=true) .def("PostMessage", py::overload_cast(&BLooper::PostMessage), "", py::arg("command")) diff --git a/bindings/interface/Alert.cpp b/bindings/interface/Alert.cpp index 21e4d25..b14a3eb 100644 --- a/bindings/interface/Alert.cpp +++ b/bindings/interface/Alert.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -13,6 +13,8 @@ namespace py = pybind11; +PYBIND11_SMART_HOLDER_TYPE_CASTERS(BAlert); + class PyBAlert : public BAlert{ public: using BAlert::BAlert; @@ -51,7 +53,7 @@ py::enum_(m, "button_spacing", "") .value("B_OFFSET_SPACING", button_spacing::B_OFFSET_SPACING, "") .export_values(); -py::class_>(m, "BAlert") +py::class_(m, "BAlert") .def(py::init(), "") .def(py::init(), "", py::arg("title"), py::arg("text"), py::arg("button1"), py::arg("button2")=NULL, py::arg("button3")=NULL, py::arg("width")=B_WIDTH_AS_USUAL, py::arg("type")=B_INFO_ALERT) .def(py::init(), "", py::arg("title"), py::arg("text"), py::arg("button1"), py::arg("button2"), py::arg("button3"), py::arg("width"), py::arg("spacing"), py::arg("type")=B_INFO_ALERT) diff --git a/bindings/interface/Window.cpp b/bindings/interface/Window.cpp index 0bb5eb0..231d37d 100644 --- a/bindings/interface/Window.cpp +++ b/bindings/interface/Window.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -103,6 +103,8 @@ void QuitWrapper(BWindow& self) { self.Quit(); } +PYBIND11_SMART_HOLDER_TYPE_CASTERS(BWindow); + PYBIND11_MODULE(Window,m) { py::enum_(m, "window_type", "") @@ -163,7 +165,7 @@ m.attr("B_MOVE_IF_PARTIALLY_OFFSCREEN") = 2; //m.attr("PortLink") = PortLink; -py::class_>(m, "BWindow") +py::class_(m, "BWindow") .def(py::init(), "", py::arg("frame"), py::arg("title"), py::arg("type"), py::arg("flags"), py::arg("workspace")=B_CURRENT_WORKSPACE) .def(py::init(), "", py::arg("frame"), py::arg("title"), py::arg("look"), py::arg("feel"), py::arg("flags"), py::arg("workspace")=B_CURRENT_WORKSPACE) .def(py::init(), "", py::arg("archive")) diff --git a/pybind11 b/pybind11 new file mode 160000 index 0000000..b8cf161 --- /dev/null +++ b/pybind11 @@ -0,0 +1 @@ +Subproject commit b8cf16143e7261a48863e02604546a5a2ef43072 diff --git a/tests/README b/tests/README new file mode 100644 index 0000000..80421af --- /dev/null +++ b/tests/README @@ -0,0 +1,3 @@ +This directory holds tests for Haiku-PyAPI. Currently, the tests are informal, +since we do not have any testing framework setup yet. (Help would be +appreciated!) diff --git a/tests/looperLifetime.py b/tests/looperLifetime.py new file mode 100644 index 0000000..24867d7 --- /dev/null +++ b/tests/looperLifetime.py @@ -0,0 +1,76 @@ +# Tests that a Python class subclassing BLooper is not "forgotten" as soon as +# Python no longer holds any references to it, even though C++ is still using +# it. +# +# The more complicated, fuller explanation: +# This "forgetting" is caused by Python being unaware that C++ holds a +# reference to the Python subclass. So, once Python no longer holds any +# references, it frees the subclass. This, in effect, removes all of the method +# overrides of the base class and leads to methods of the base class being +# called directly. + +from Be import BLooper, BMessenger, B_QUIT_REQUESTED +import time + +looper_quit_called = False +looper_deleted = False + +# The main character of this test is TestLooper +class TestLooper(BLooper): + def __init__(self): + BLooper.__init__(self, "TestLooper") + + def Quit(self): + global looper_quit_called + looper_quit_called = True + BLooper.Quit(self) + + def __del__(self): + global looper_deleted + looper_deleted = True + # give_me_exception() # FIXME: causes program to crash with ugly error message + +testLooper = TestLooper() +testLooper.Run() + +# Make C++ obtain a reference to testLooper +messenger = BMessenger(None, testLooper) + +# Remove Python's reference to testLooper +# One of two things will now happen: +# 1. Python will know C++ has a reference and not delete testLooper yet +# (correct) +# 2. Python will not realize that C++ still has a reference to testLooper and +# will free it (incorrect) +del testLooper + +# Now tell the looper to quit. In effect, this calls the Quit function +# One of two things will now happen: +# 1. C++ will see that TestLooper exists and that its Quit function overrides +# BLooper.Quit, and will call TestLooper.Quit instead (correct) +# 2. C++ will see that nothing extends BLooper.Quit (since TestLooper.Quit has +# been freed) and call BLooper.Quit directly (incorrect) +messenger.SendMessage(B_QUIT_REQUESTED, None) + +# Free the messenger. Now we have no references to it either directly (through +# testLooper), or indirectly. This means that as soon as testLooper quits it +# should call its destructor. Otherwise, there is likely a memory leak. +del messenger + +# Give the looper a bit time to receive and process the message, quit, and +# clean up +time.sleep(.1) + +if looper_quit_called and looper_deleted: + print("Test passed!") + +if not looper_quit_called: + print("TestLooper.Quit wasn't called. This likely means that TestLooper " + " was freed too early, which probably means that something either" + " did not obtain a reference to it when it should have, or else" + " released it too early.") + +if not looper_deleted: + print("TestLooper.__del__ wasn't called. This likely signifies a memory" + " leak. Something that obtained a reference to TestLooper likely never" + " released it.") From f43d8a70d857bcf23ede5177f0a8d80891a8e86d Mon Sep 17 00:00:00 2001 From: Zardshard <0azrune6@zard.anonaddy.com> Date: Tue, 9 Apr 2024 19:49:01 -0400 Subject: [PATCH 009/115] Fix BWindow being freed too early Fixes the problem mentioned in the previous commit --- bindings/interface/Window.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/bindings/interface/Window.cpp b/bindings/interface/Window.cpp index 231d37d..2bef299 100644 --- a/bindings/interface/Window.cpp +++ b/bindings/interface/Window.cpp @@ -39,7 +39,18 @@ class PyBWindow : public BWindow{ PYBIND11_OVERLOAD(status_t, BWindow, Archive, archive, deep); } void Quit() override { - PYBIND11_OVERLOAD(void, BWindow, Quit); + // limit the scope of py::gil_scoped_acquire, otherwise there may + // be a deadlock, likely due to us holding the lock even after + // the window thread has terminated. + { + py::gil_scoped_acquire acquire; + + // FIXME: What if the Python overload never actually calls + // BWindow::Quit? + do_not_delete.release(); + } + + PYBIND11_OVERLOAD(void, BWindow, Quit); } void DispatchMessage(BMessage* message, BHandler* handler) override { PYBIND11_OVERLOAD(void, BWindow, DispatchMessage, message, handler); @@ -90,11 +101,21 @@ class PyBWindow : public BWindow{ PYBIND11_OVERLOAD(status_t, BWindow, Perform, code, data); } thread_id Run() override { - PYBIND11_OVERLOAD(thread_id, BWindow, Run); + py::gil_scoped_acquire acquire; + + // FIXME: What if the Python overload never actually calls + // BWindow::Run? + do_not_delete = py::cast(this); + + PYBIND11_OVERLOAD(thread_id, BWindow, Run); } void SetLayout(BLayout* layout) override { PYBIND11_OVERLOAD(void, BWindow, SetLayout, layout); } + + private: + // For an explanation, see do_not_delete in Looper.cpp + py::object do_not_delete; }; void QuitWrapper(BWindow& self) { @@ -166,9 +187,9 @@ m.attr("B_MOVE_IF_PARTIALLY_OFFSCREEN") = 2; //m.attr("PortLink") = PortLink; py::class_(m, "BWindow") -.def(py::init(), "", py::arg("frame"), py::arg("title"), py::arg("type"), py::arg("flags"), py::arg("workspace")=B_CURRENT_WORKSPACE) -.def(py::init(), "", py::arg("frame"), py::arg("title"), py::arg("look"), py::arg("feel"), py::arg("flags"), py::arg("workspace")=B_CURRENT_WORKSPACE) -.def(py::init(), "", py::arg("archive")) +.def(py::init_alias(), "", py::arg("frame"), py::arg("title"), py::arg("type"), py::arg("flags"), py::arg("workspace")=B_CURRENT_WORKSPACE) +.def(py::init_alias(), "", py::arg("frame"), py::arg("title"), py::arg("look"), py::arg("feel"), py::arg("flags"), py::arg("workspace")=B_CURRENT_WORKSPACE) +.def(py::init_alias(), "", py::arg("archive")) .def_static("Instantiate", &BWindow::Instantiate, "", py::arg("archive")) .def("Archive", &BWindow::Archive, "", py::arg("archive"), py::arg("deep")=true) .def("Quit", &QuitWrapper, "") From 4f17a8539a54217b5c615fc6954280c5dccdda99 Mon Sep 17 00:00:00 2001 From: Zardshard <0azrune6@zard.anonaddy.com> Date: Fri, 10 May 2024 16:21:49 -0400 Subject: [PATCH 010/115] Update current status --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c6c1be3..62050c3 100644 --- a/README.md +++ b/README.md @@ -9,15 +9,17 @@ where we have had to deviate from the C++ API, however. ## Current status +Currently, Haiku-PyAPI is best suited to scripts and small, simple +applications. + Almost everything in the app and interface kits have been ported. The storage kit has mostly been ported. The support kit has only partially been ported. The other kits haven't been ported yet. Of the kits that have been ported, many of the functions haven't been tested -yet. You should, therefore, expect to encounter problems when using some of the -functions. Besides this, you can expect memory leaks, as little work has been -done on getting memory freed correctly once it is no longer needed. And, of -course, you should expect many miscellaneous bugs. +yet. You should, therefore, expect to encounter problems occasionally. Besides +this, you can expect memory leaks, as little work has been done on getting +memory freed correctly once it is no longer needed. ## Installing From c97ce1f2d438aca38d780320c10ac54c16910103 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 2 Jun 2024 22:23:58 +0200 Subject: [PATCH 011/115] Add Behavior enum --- bindings/interface/Button.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bindings/interface/Button.cpp b/bindings/interface/Button.cpp index 2f143ae..ea64632 100644 --- a/bindings/interface/Button.cpp +++ b/bindings/interface/Button.cpp @@ -101,6 +101,12 @@ class PyBButton : public BButton{ PYBIND11_MODULE(Button,m) { +py::enum_(m, "BBehavior", "") +.value("B_BUTTON_BEHAVIOR", BButton::BBehavior::B_BUTTON_BEHAVIOR, "") +.value("B_TOGGLE_BEHAVIOR", BButton::BBehavior::B_TOGGLE_BEHAVIOR, "") +.value("B_POP_UP_BEHAVIOR", BButton::BBehavior::B_POP_UP_BEHAVIOR, "") +.export_values(); + py::class_>(m, "BButton") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("message"), py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE) .def(py::init(), "", py::arg("name"), py::arg("label"), py::arg("message"), py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE) From bdc1c6084f8466ca2db0c3e50e84553b9428f90f Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 6 Jun 2024 21:13:20 +0200 Subject: [PATCH 012/115] Add BOutlineListView overrides --- bindings/interface/OutlineListView.cpp | 80 +++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/bindings/interface/OutlineListView.cpp b/bindings/interface/OutlineListView.cpp index 61bc1fb..abcefe4 100644 --- a/bindings/interface/OutlineListView.cpp +++ b/bindings/interface/OutlineListView.cpp @@ -8,7 +8,85 @@ namespace py = pybind11; - +class PyBOutlineListView : public BOutlineListView{ + public: + using BOutlineListView::BOutlineListView; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BOutlineListView, Archive, archive, deep); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BOutlineListView, MouseDown, where); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BOutlineListView, KeyDown, bytes, numBytes); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BOutlineListView, MouseUp, where); + } + bool AddUnder(BListItem* item, BListItem* superItem) override{ + PYBIND11_OVERLOAD(bool, BOutlineListView, AddUnder, item, superItem); + } + bool AddItem(BListItem* item) override { + PYBIND11_OVERLOAD(bool, BOutlineListView, AddItem, item); + } + bool AddItem(BListItem* item, int32 fullListIndex) override { + PYBIND11_OVERLOAD(bool, BOutlineListView, AddItem, item, fullListIndex); + } + bool AddList(BList* newItems) override { + PYBIND11_OVERLOAD(bool, BOutlineListView, AddList, newItems); + } + bool AddList(BList* newItems, int32 fullListIndex) override { + PYBIND11_OVERLOAD(bool, BOutlineListView, AddList, newItems, fullListIndex); + } + bool RemoveItem(BListItem* item) override { + PYBIND11_OVERLOAD(bool, BOutlineListView, RemoveItem, item); + } + BListItem* RemoveItem(int32 fullListIndex) override { + PYBIND11_OVERLOAD(BListItem*, BOutlineListView, RemoveItem, fullListIndex); + } + bool RemoveItems(int32 fullListIndex, int32 count) override { + PYBIND11_OVERLOAD(bool, BOutlineListView, RemoveItems, fullListIndex, count); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BOutlineListView, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BOutlineListView, FrameResized, newWidth, newHeight); + } + void MakeEmpty() override { + PYBIND11_OVERLOAD(void, BOutlineListView, MakeEmpty); + } + BHandler* ResolveSpecifier(BMessage* message, + int32 index, BMessage* specifier, + int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BOutlineListView, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BOutlineListView, GetSupportedSuites, data); + } + status_t Perform(perform_code code, void* data) override { + PYBIND11_OVERLOAD(status_t, BOutlineListView, Perform, code, data); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BOutlineListView, ResizeToPreferred); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BOutlineListView, GetPreferredSize, _width, _height); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERLOAD(void, BOutlineListView, MakeFocus, focus); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BOutlineListView, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BOutlineListView, AllDetached); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BOutlineListView, DetachedFromWindow); + } +}; + PYBIND11_MODULE(OutlineListView,m) { py::class_(m, "BOutlineListView") From 8153431a7bedc329ad8a2a6e7db7440fb3328b9f Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 6 Jun 2024 21:46:17 +0200 Subject: [PATCH 013/115] add override class in py::class_ --- bindings/interface/OutlineListView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/interface/OutlineListView.cpp b/bindings/interface/OutlineListView.cpp index abcefe4..de5c157 100644 --- a/bindings/interface/OutlineListView.cpp +++ b/bindings/interface/OutlineListView.cpp @@ -89,7 +89,7 @@ class PyBOutlineListView : public BOutlineListView{ PYBIND11_MODULE(OutlineListView,m) { -py::class_(m, "BOutlineListView") +py::class_(m, "BOutlineListView") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("type")=B_SINGLE_SELECTION_LIST, py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE) .def(py::init(), "", py::arg("name"), py::arg("type")=B_SINGLE_SELECTION_LIST, py::arg("flags")=B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE) .def(py::init(), "", py::arg("archive")) From 839f4e42fd2995cabf5185eb8436ed9fc955e3b8 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 6 Jun 2024 21:47:07 +0200 Subject: [PATCH 014/115] add override class in py::class_ --- bindings/interface/StringItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/interface/StringItem.cpp b/bindings/interface/StringItem.cpp index 202beea..b8f0f85 100644 --- a/bindings/interface/StringItem.cpp +++ b/bindings/interface/StringItem.cpp @@ -34,7 +34,7 @@ class PyStringItem : public BStringItem{ PYBIND11_MODULE(StringItem,m) { -py::class_>(m, "BStringItem") +py::class_>(m, "BStringItem") .def(py::init(), "", py::arg("text"), py::arg("outlineLevel")=0, py::arg("expanded")=true) .def(py::init(), "", py::arg("archive")) .def_static("Instantiate", &BStringItem::Instantiate, "", py::arg("archive")) From 5d540bf6d053fc2d9f101cf462fbd99776658430 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 11 Jul 2024 16:19:28 +0200 Subject: [PATCH 015/115] Add ArgvReceived override --- bindings/app/Application.cpp | 53 +++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/bindings/app/Application.cpp b/bindings/app/Application.cpp index f67b237..7514c0a 100644 --- a/bindings/app/Application.cpp +++ b/bindings/app/Application.cpp @@ -18,6 +18,25 @@ namespace py = pybind11; using namespace BPrivate; +void RunWrapper(BApplication& self) { + // Why release the gil (global interpreter lock) here? Because its a long- + // running function (it usually runs for the lifetime of the application). + // See https://pybind11.readthedocs.io/en/stable/advanced/misc.html#global-interpreter-lock-gil + // for more details. + py::gil_scoped_release release; + self.Run(); +} + +void QuitWrapper(BApplication& self) { + // For an explanation, see QuitWrapper in Looper.cpp + py::gil_scoped_release release; + self.Quit(); +} + +void ArgvReceivedWrapper(BApplication& self, int32 argc, std::vector argv) { + self.ArgvReceived(argc, argv.data()); +} + class PyBApplication : public BApplication{ public: using BApplication::BApplication; @@ -42,10 +61,17 @@ class PyBApplication : public BApplication{ void MessageReceived(BMessage* message) override { PYBIND11_OVERLOAD(void, BApplication, MessageReceived, message); } - //void ArgvReceived(int32 argc, char** argv) override { - //ArgvReceivedWrapper(argc, argv); - //PYBIND11_OVERLOAD(void, BApplication, ArgvReceived, argc, argv); //look at this - //} + void ArgvReceived(int32 argc, std::vector argv) { + pybind11::gil_scoped_acquire gil; + pybind11::function override = pybind11::get_override(static_cast(this), "ArgvReceived"); + if (override) { + // It exists! Let's call it. + override(argc, argv); + } else { + // Doesn't exist. Let's call our wrapper instead + ArgvReceivedWrapper(*this, argc, argv); + } + } void AppActivated(bool active) override { PYBIND11_OVERLOAD(void, BApplication, AppActivated, active); } @@ -69,24 +95,6 @@ class PyBApplication : public BApplication{ } }; -void RunWrapper(BApplication& self) { - // Why release the gil (global interpreter lock) here? Because its a long- - // running function (it usually runs for the lifetime of the application). - // See https://pybind11.readthedocs.io/en/stable/advanced/misc.html#global-interpreter-lock-gil - // for more details. - py::gil_scoped_release release; - self.Run(); -} - -void QuitWrapper(BApplication& self) { - // For an explanation, see QuitWrapper in Looper.cpp - py::gil_scoped_release release; - self.Quit(); -} - -void ArgvReceivedWrapper(BApplication& self, int32 argc, std::vector argv) { - self.ArgvReceived(argc, argv.data()); -} PYBIND11_SMART_HOLDER_TYPE_CASTERS(BApplication); @@ -108,6 +116,7 @@ py::class_(m, "BApplicati .def("ReadyToRun", &BApplication::ReadyToRun, "") .def("MessageReceived", &BApplication::MessageReceived, "", py::arg("message")) .def("ArgvReceived", &ArgvReceivedWrapper, "", py::arg("argc"), py::arg("argv")) +//.def("ArgvReceivedWrapper", &PyBApplication::ArgvReceivedWrapper, "", py::arg("args")) // Usare il metodo wrapper qui .def("AppActivated", &BApplication::AppActivated, "", py::arg("active")) .def("RefsReceived", &BApplication::RefsReceived, "", py::arg("message")) .def("AboutRequested", &BApplication::AboutRequested, "") From ee5e67ff533920f9bf1946f97e58e8e2ecab2f64 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 12 Jul 2024 20:08:06 +0200 Subject: [PATCH 016/115] Fix BApplication::ArgvReceived override --- bindings/app/Application.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bindings/app/Application.cpp b/bindings/app/Application.cpp index 7514c0a..3b20748 100644 --- a/bindings/app/Application.cpp +++ b/bindings/app/Application.cpp @@ -61,17 +61,23 @@ class PyBApplication : public BApplication{ void MessageReceived(BMessage* message) override { PYBIND11_OVERLOAD(void, BApplication, MessageReceived, message); } - void ArgvReceived(int32 argc, std::vector argv) { + void ArgvReceived(int32 argc, char** argv) { + std::vector args; + for (int32 i = 0; i < argc; ++i) { + args.push_back(argv[i]); + } pybind11::gil_scoped_acquire gil; pybind11::function override = pybind11::get_override(static_cast(this), "ArgvReceived"); if (override) { // It exists! Let's call it. - override(argc, argv); + override(argc, args); } else { + // Doesn't exist. Let's call our wrapper instead - ArgvReceivedWrapper(*this, argc, argv); + ArgvReceivedWrapper(*this, argc, args); } - } + } + void AppActivated(bool active) override { PYBIND11_OVERLOAD(void, BApplication, AppActivated, active); } From fb061ca57f6ec390bfd36d7881660c5894d0dccc Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 22 Jul 2024 14:17:44 +0200 Subject: [PATCH 017/115] Fix ReadAttr Int64 type --- bindings/storage/Node.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index 6555f1e..05cb976 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -136,6 +136,8 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed switch (type) { //test Int64 for reinterpretation in int32* case B_INT64_TYPE: + ret = py::int_(*reinterpret_cast(PyLong_AsVoidPtr(PyLong_FromVoidPtr(tmp)))); + break; case B_INT32_TYPE: case B_INT16_TYPE: case B_INT8_TYPE: From f987d182ff01515525d3b1d370f25e66ecfa9b99 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 22 Jul 2024 21:43:39 +0200 Subject: [PATCH 018/115] Fix Slider py::nodelete --- bindings/interface/Slider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/interface/Slider.cpp b/bindings/interface/Slider.cpp index 0afbe18..a94ffe7 100644 --- a/bindings/interface/Slider.cpp +++ b/bindings/interface/Slider.cpp @@ -202,7 +202,7 @@ py::enum_(m, "thumb_style", "") .value("B_TRIANGLE_THUMB", thumb_style::B_TRIANGLE_THUMB, "") .export_values(); -py::class_(m, "BSlider") +py::class_>(m, "BSlider") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("message"), py::arg("minValue"), py::arg("maxValue"), py::arg("thumbType")=B_BLOCK_THUMB, py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS) .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("message"), py::arg("minValue"), py::arg("maxValue"), py::arg("posture"), py::arg("thumbType")=B_BLOCK_THUMB, py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS) .def(py::init(), "", py::arg("name"), py::arg("label"), py::arg("message"), py::arg("minValue"), py::arg("maxValue"), py::arg("posture"), py::arg("thumbType")=B_BLOCK_THUMB, py::arg("flags")=B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS) From 3146e996aef75b746e3c5ba6e71bfdf4a1756856 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 29 Jul 2024 14:25:51 +0200 Subject: [PATCH 019/115] Update for Haiku_nightly API changes --- bindings/interface/Font.cpp | 74 ++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/bindings/interface/Font.cpp b/bindings/interface/Font.cpp index 320811e..7a82720 100644 --- a/bindings/interface/Font.cpp +++ b/bindings/interface/Font.cpp @@ -12,8 +12,42 @@ #include namespace py = pybind11; +/* +py::list GetHasGlyphsWrapper1(BFont& self, std::vector charArray, int32 numChars) { + py::list hasArray; + std::vector boolArray(numChars); + std::unique_ptr tempArray(new bool[numChars]); + + self.GetHasGlyphs(charArray.data(), numChars, tempArray.get()); + + for (int32 i = 0; i < numChars; ++i) { + boolArray[i] = tempArray[i]; + } + for (size_t i = 0; i < boolArray.size(); ++i) { + hasArray.append(boolArray[i]); + } + + return hasArray; +} + +py::list GetHasGlyphsWrapper2(BFont& self, std::vector charArray, int32 numChars, bool useFallbacks){ + py::list hasArray; + std::vector boolArray(numChars); + std::unique_ptr tempArray(new bool[numChars]); + + self.GetHasGlyphs(charArray.data(), numChars, tempArray.get(), useFallbacks); + + for (int32 i = 0; i < numChars; ++i) { + boolArray[i] = tempArray[i]; + } + + for (size_t i = 0; i < boolArray.size(); ++i) { + hasArray.append(boolArray[i]); + } + return hasArray; +}*/ PYBIND11_MODULE(Font,m) { @@ -289,7 +323,45 @@ py::class_(m, "BFont") return glyphShapeList; },"",py::arg("charArray")) -.def("GetHasGlyphs", &BFont::GetHasGlyphs, "", py::arg("charArray"), py::arg("numChars"), py::arg("hasArray")) +//.def("GetHasGlyphs", &BFont::GetHasGlyphs, "", py::arg("charArray"), py::arg("numChars"), py::arg("hasArray")) +//.def("GetHasGlyphs",&GetHasGlyphsWrapper1, "", py::arg("charArray"), py::arg("numChars")) //this works +//.def("GetHasGlyphs",&GetHasGlyphsWrapper2, "", py::arg("charArray"), py::arg("numChars"), py::arg("useFallbacks")) //this works +.def("GetHasGlyphs",[](BFont& self,std::vector charArray, int32 numChars){ + py::list hasArray; + std::vector boolArray(numChars); + std::unique_ptr tempArray(new bool[numChars]); + + self.GetHasGlyphs(charArray.data(), numChars, tempArray.get()); + + for (int32 i = 0; i < numChars; ++i) { + boolArray[i] = tempArray[i]; + } + + for (size_t i = 0; i < boolArray.size(); ++i) { + hasArray.append(boolArray[i]); + } + + return hasArray; +},"", py::arg("charArray"), py::arg("numChars")) +#if (B_HAIKU_VERSION > B_HAIKU_VERSION_1_BETA_4) +.def("GetHasGlyphs", [](BFont& self,std::vector charArray, int32 numChars, bool useFallbacks){ + py::list hasArray; + std::vector boolArray(numChars); + std::unique_ptr tempArray(new bool[numChars]); + + self.GetHasGlyphs(charArray.data(), numChars, tempArray.get(), useFallbacks); + + for (int32 i = 0; i < numChars; ++i) { + boolArray[i] = tempArray[i]; + } + + for (size_t i = 0; i < boolArray.size(); ++i) { + hasArray.append(boolArray[i]); + } + + return hasArray; +},"", py::arg("charArray"), py::arg("numChars"), py::arg("useFallbacks")) +#endif .def("operator=", &BFont::operator=, "", py::arg("font")) .def("__eq__", &BFont::operator==, "", py::arg("font")) .def("__ne__", &BFont::operator!=, "", py::arg("font")) From f03dffb1af41fce700d4f5fe9dc69d2f102b24f8 Mon Sep 17 00:00:00 2001 From: Zardshard <0azrune6@zard.anonaddy.com> Date: Mon, 29 Jul 2024 09:56:54 -0400 Subject: [PATCH 020/115] Fix PyBApplication::ArgvReceived If PyBApplication::ArgvReceived couldn't find an overload, it called ArgvReceivedWrapper which called ArgvReceived which is overrided by PyBApplication::ArgvReceived, creating an endless loop! Also makes indentation (spaces vs. tabs) consistent. --- bindings/app/Application.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/bindings/app/Application.cpp b/bindings/app/Application.cpp index 3b20748..ddd008a 100644 --- a/bindings/app/Application.cpp +++ b/bindings/app/Application.cpp @@ -61,22 +61,22 @@ class PyBApplication : public BApplication{ void MessageReceived(BMessage* message) override { PYBIND11_OVERLOAD(void, BApplication, MessageReceived, message); } - void ArgvReceived(int32 argc, char** argv) { - std::vector args; - for (int32 i = 0; i < argc; ++i) { - args.push_back(argv[i]); - } - pybind11::gil_scoped_acquire gil; - pybind11::function override = pybind11::get_override(static_cast(this), "ArgvReceived"); - if (override) { - // It exists! Let's call it. - override(argc, args); - } else { - - // Doesn't exist. Let's call our wrapper instead - ArgvReceivedWrapper(*this, argc, args); - } - } + void ArgvReceived(int32 argc, char** argv) override { + pybind11::gil_scoped_acquire gil; + pybind11::function override = pybind11::get_override(static_cast(this), "ArgvReceived"); + if (override) { + // It exists! Let's call it. + std::vector args; + for (int32 i = 0; i < argc; ++i) { + args.push_back(argv[i]); + } + + override(argc, args); + } else { + // Doesn't exist. Let's call the default ArgvReceived instead + BApplication::ArgvReceived(argc, argv); + } + } void AppActivated(bool active) override { PYBIND11_OVERLOAD(void, BApplication, AppActivated, active); From 235a3f8de857b6cf31bb2b642a63d2c7c5a06998 Mon Sep 17 00:00:00 2001 From: Zardshard <0azrune6@zard.anonaddy.com> Date: Mon, 29 Jul 2024 13:17:18 -0400 Subject: [PATCH 021/115] Improve build system * Allow specifying debug or release build * Allow specifying build directory * Make default build directory build/python$(python_version)_$(type) --- Jamfile | 19 +++++++++++++++---- README.md | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Jamfile b/Jamfile index bdb95fc..5511b18 100644 --- a/Jamfile +++ b/Jamfile @@ -68,6 +68,8 @@ rule Symlink # Set user configurable variables to default value if user did not specify value py ?= 3.10 ; python_version ?= $(py) ; +type ?= release ; +build_location ?= build/python$(python_version)_$(type) ; install_location ?= /boot/system/non-packaged/lib/python$(python_version)/site-packages ; @@ -82,15 +84,24 @@ SubDirHdrs pybind11/include/ ; SubDirHdrs /system/develop/headers/python$(python_version)/ ; # Additional C++ flags to use when compiling -# TODO: only run -Os for release builds. Development builds should prioritize -# build time -SubDirC++Flags -std=c++14 -pipe -fPIC -Os -fvisibility=hidden ; +SubDirC++Flags -std=c++14 -pipe -fPIC -fvisibility=hidden ; +if $(type) = release { + # Optimize for build size when making a release build + SubDirC++Flags -Os ; +} else if $(type) = debug { + # Include debug symbols when making a debug build + # It seems Haiku's debugger still doesn't fully support dwarf-5 (the + # default), so we'll tell it to use dwarf-4. + SubDirC++Flags -gdwarf-4 ; +} else { + Exit "Bad type given. Valid options are \"release\" and \"debug\"" ; +} # Flags to use when linking LINKLIBS = -lbe ; # Where to put the generated build files -LOCATE_TARGET = bin/x86_64/python$(python_version) ; # TODO: hardcoded arch +LOCATE_TARGET = $(build_location) ; # The source files that we want to compile: local sourceFiles = diff --git a/README.md b/README.md index 62050c3..e0bdfbd 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ specify a build parameter, add `-sPARAMETER=VALUE` to the build command line. | ---------------- | --------------------------------------------- | | python_version | Version of python to build for. Default: 3.10 | | py | Alias of `python_version` | +| type | Debug or release build. Default: release | +| build_location | Location to put build files. Default: build/python$(python_version)_$(type) | | install_location | Where to install build files to. Default: /boot/system/non-packaged/lib/python$(python_version)/site-packages | ## Example projects From fcdd8115db5340b4d346f97558946844e2fe6746 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 6 Aug 2024 22:26:24 +0200 Subject: [PATCH 022/115] Overloads for recent updates --- bindings/interface/InterfaceDefs.cpp | 36 +++++++++++++++++++++------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/bindings/interface/InterfaceDefs.cpp b/bindings/interface/InterfaceDefs.cpp index 0e50974..ad404bb 100644 --- a/bindings/interface/InterfaceDefs.cpp +++ b/bindings/interface/InterfaceDefs.cpp @@ -347,29 +347,49 @@ m.def("get_scroll_bar_info", &get_scroll_bar_info, "", py::arg("info")); m.def("set_scroll_bar_info", &set_scroll_bar_info, "", py::arg("info")); -//m.def("get_mouse_type", py::overload_cast(&get_mouse_type, py::const_), "", py::arg("type")); -//m.def("get_mouse_type", py::overload_cast(&get_mouse_type, py::const_), "", py::arg("mouse_name"), py::arg("type")); +//#if (B_HAIKU_VERSION > B_HAIKU_VERSION_1_BETA_4) +m.def("get_mouse_type", py::overload_cast(&get_mouse_type), "", py::arg("type")); +m.def("get_mouse_type", py::overload_cast(&get_mouse_type), "", py::arg("mouse_name"), py::arg("type")); +//#endif m.def("set_mouse_type", &set_mouse_type, "", py::arg("mouse_name"), py::arg("type")); +#if (B_HAIKU_VERSION > B_HAIKU_VERSION_1_BETA_4) +m.def("get_mouse_map", py::overload_cast(&get_mouse_map), "", py::arg("map")); +m.def("get_mouse_map", py::overload_cast(&get_mouse_map), "",py::arg("mouse_name"), py::arg("map")); +#else m.def("get_mouse_map", &get_mouse_map, "", py::arg("map")); +#endif +#if (B_HAIKU_VERSION > B_HAIKU_VERSION_1_BETA_4) +m.def("set_mouse_map", py::overload_cast(&set_mouse_map), "", py::arg("map")); +m.def("set_mouse_map", py::overload_cast(&set_mouse_map), "", py::arg("mouse_name"), py::arg("map")); +#else m.def("set_mouse_map", &set_mouse_map, "", py::arg("map")); +#endif +#if (B_HAIKU_VERSION > B_HAIKU_VERSION_1_BETA_4) +m.def("get_click_speed", py::overload_cast(&get_click_speed), "", py::arg("speed")); +m.def("get_click_speed", py::overload_cast(&get_click_speed), "", py::arg("mouse_name"), py::arg("speed")); +#else m.def("get_click_speed", &get_click_speed, "", py::arg("speed")); +#endif +#if (B_HAIKU_VERSION > B_HAIKU_VERSION_1_BETA_4) +m.def("set_click_speed", py::overload_cast(&set_click_speed), "", py::arg("speed")); +m.def("set_click_speed", py::overload_cast(&set_click_speed), "", py::arg("mouse_name"), py::arg("speed")); +#else m.def("set_click_speed", &set_click_speed, "", py::arg("speed")); +#endif -//m.def("get_mouse_speed", py::overload_cast(&get_mouse_speed, py::const_), "", py::arg("speed")); - -//m.def("get_mouse_speed", py::overload_cast(&get_mouse_speed, py::const_), "", py::arg("mouse_name"), py::arg("speed")); +m.def("get_mouse_speed", py::overload_cast(&get_mouse_speed), "", py::arg("speed")); +m.def("get_mouse_speed", py::overload_cast(&get_mouse_speed), "", py::arg("mouse_name"), py::arg("speed")); m.def("set_mouse_speed", &set_mouse_speed, "", py::arg("mouse_name"), py::arg("speed")); -//m.def("get_mouse_acceleration", py::overload_cast(&get_mouse_acceleration, py::const_), "", py::arg("speed")); - -//m.def("get_mouse_acceleration", py::overload_cast(&get_mouse_acceleration, py::const_), "", py::arg("mouse_name"), py::arg("speed")); +m.def("get_mouse_acceleration", py::overload_cast(&get_mouse_acceleration), "", py::arg("speed")); +m.def("get_mouse_acceleration", py::overload_cast(&get_mouse_acceleration), "", py::arg("mouse_name"), py::arg("speed")); m.def("set_mouse_acceleration", &set_mouse_acceleration, "", py::arg("mouse_name"), py::arg("speed")); From 61d971904bee032013a62e8939b0ffdc1499c53a Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 28 Aug 2024 14:58:26 +0200 Subject: [PATCH 023/115] Fix wrong module name --- bindings/support/DataIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/support/DataIO.cpp b/bindings/support/DataIO.cpp index 17e212e..1fe9a17 100644 --- a/bindings/support/DataIO.cpp +++ b/bindings/support/DataIO.cpp @@ -103,7 +103,7 @@ py::class_(m, "BDataIO") ; -py::class_(m, "BLayout"); +py::class_(m, "BPositionIO"); py::class_(m, "BMemoryIO"); py::class_(m, "BMallocIO"); /* From 73f3f60fb3677581b1fd78c5eb4b53358f8d9857 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 28 Aug 2024 14:59:09 +0200 Subject: [PATCH 024/115] Add add-ons --- Jamfile | 17 +- bindings/__init__.py | 14 + bindings/add-ons/graphics/Accelerant.cpp | 299 ++++++++++++++++++ bindings/add-ons/graphics/GraphicsCard.cpp | 168 ++++++++++ .../input_server/InputServerDevice.cpp | 89 ++++++ .../input_server/InputServerFilter.cpp | 34 ++ .../input_server/InputServerMethod.cpp | 34 ++ bindings/add-ons/mail_daemon/MailFilter.cpp | 79 +++++ bindings/add-ons/mail_daemon/MailProtocol.cpp | 104 ++++++ .../add-ons/mail_daemon/MailSettingsView.cpp | 33 ++ .../network_settings/NetworkProfile.cpp | 33 ++ .../network_settings/NetworkSettings.cpp | 203 ++++++++++++ .../network_settings/NetworkSettingsAddOn.cpp | 186 +++++++++++ .../add-ons/registrar/MimeSnifferAddon.cpp | 35 ++ bindings/add-ons/screen_saver/ScreenSaver.cpp | 72 +++++ 15 files changed, 1399 insertions(+), 1 deletion(-) create mode 100644 bindings/add-ons/graphics/Accelerant.cpp create mode 100644 bindings/add-ons/graphics/GraphicsCard.cpp create mode 100644 bindings/add-ons/input_server/InputServerDevice.cpp create mode 100644 bindings/add-ons/input_server/InputServerFilter.cpp create mode 100644 bindings/add-ons/input_server/InputServerMethod.cpp create mode 100644 bindings/add-ons/mail_daemon/MailFilter.cpp create mode 100644 bindings/add-ons/mail_daemon/MailProtocol.cpp create mode 100644 bindings/add-ons/mail_daemon/MailSettingsView.cpp create mode 100644 bindings/add-ons/network_settings/NetworkProfile.cpp create mode 100644 bindings/add-ons/network_settings/NetworkSettings.cpp create mode 100644 bindings/add-ons/network_settings/NetworkSettingsAddOn.cpp create mode 100644 bindings/add-ons/registrar/MimeSnifferAddon.cpp create mode 100644 bindings/add-ons/screen_saver/ScreenSaver.cpp diff --git a/Jamfile b/Jamfile index 5511b18..8e64aa9 100644 --- a/Jamfile +++ b/Jamfile @@ -74,7 +74,7 @@ install_location ?= /boot/system/non-packaged/lib/python$(python_version)/site-packages ; # Where to search for .cpp files -SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/storage bindings/kernel bindings/translation ; +SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/storage bindings/kernel bindings/translation bindings/add-ons/screen_saver bindings/add-ons/registrar bindings/add-ons/graphics bindings/add-ons/input_server bindings/add-ons/mail_daemon bindings/add-ons/network_settings ; # Where to look for header files SubDirHdrs headers ; @@ -253,6 +253,21 @@ local sourceFiles = Translator.cpp stat.cpp + + #add-ons + ScreenSaver.cpp + MimeSnifferAddon.cpp + Accelerant.cpp + GraphicsCard.cpp + InputServerDevice.cpp + InputServerFilter.cpp + InputServerMethod.cpp + MailProtocol.cpp + MailFilter.cpp + MailSettingsView.cpp + NetworkProfile.cpp + NetworkSettings.cpp + NetworkSettingsAddOn.cpp ; # The .so files can be built from the .cpp files, each .cpp file mapping to diff --git a/bindings/__init__.py b/bindings/__init__.py index 660c749..4b776c8 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -139,6 +139,20 @@ from .Translator import * from .stat import * +#from .ScreenSaver import * +#from .MimeSnifferAddon import * +#from .Accelerant import * +#from .GraphicsCard import * +#from .InputServerDevice import * +#from .InputServerFilter import * +#from .InputServerMethod import * +#from .MailFilter import * +#from .MailSettingsView import * +#from .MailProtocol import * +#from .NetworkProfile import * +#from .NetworkSettings import * +#from .NetworkSettingsAddOn import * + _BWindow=BWindow _BApplication=BApplication def MessageReceived(self, msg, parent): diff --git a/bindings/add-ons/graphics/Accelerant.cpp b/bindings/add-ons/graphics/Accelerant.cpp new file mode 100644 index 0000000..4315f5c --- /dev/null +++ b/bindings/add-ons/graphics/Accelerant.cpp @@ -0,0 +1,299 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +class MyClass { +public: +enum production { + week, + year +}; +}; + +PYBIND11_MODULE(Accelerant, m) +{ +m.attr("B_INIT_ACCELERANT") = py::cast(B_INIT_ACCELERANT); +m.attr("B_ACCELERANT_CLONE_INFO_SIZE") = py::cast(B_ACCELERANT_CLONE_INFO_SIZE); +m.attr("B_GET_ACCELERANT_CLONE_INFO") = py::cast(B_GET_ACCELERANT_CLONE_INFO); +m.attr("B_CLONE_ACCELERANT") = py::cast(B_CLONE_ACCELERANT); +m.attr("B_UNINIT_ACCELERANT") = py::cast(B_UNINIT_ACCELERANT); +m.attr("B_GET_ACCELERANT_DEVICE_INFO") = py::cast(B_GET_ACCELERANT_DEVICE_INFO); +m.attr("B_ACCELERANT_RETRACE_SEMAPHORE") = py::cast(B_ACCELERANT_RETRACE_SEMAPHORE); +m.attr("B_ACCELERANT_MODE_COUNT") = py::cast(B_ACCELERANT_MODE_COUNT); +m.attr("B_GET_MODE_LIST") = py::cast(B_GET_MODE_LIST); +m.attr("B_PROPOSE_DISPLAY_MODE") = py::cast(B_PROPOSE_DISPLAY_MODE); +m.attr("B_SET_DISPLAY_MODE") = py::cast(B_SET_DISPLAY_MODE); +m.attr("B_GET_DISPLAY_MODE") = py::cast(B_GET_DISPLAY_MODE); +m.attr("B_GET_FRAME_BUFFER_CONFIG") = py::cast(B_GET_FRAME_BUFFER_CONFIG); +m.attr("B_GET_PIXEL_CLOCK_LIMITS") = py::cast(B_GET_PIXEL_CLOCK_LIMITS); +m.attr("B_GET_TIMING_CONSTRAINTS") = py::cast(B_GET_TIMING_CONSTRAINTS); +m.attr("B_MOVE_DISPLAY") = py::cast(B_MOVE_DISPLAY); +m.attr("B_SET_INDEXED_COLORS") = py::cast(B_SET_INDEXED_COLORS); +m.attr("B_DPMS_CAPABILITIES") = py::cast(B_DPMS_CAPABILITIES); +m.attr("B_DPMS_MODE") = py::cast(B_DPMS_MODE); +m.attr("B_SET_DPMS_MODE") = py::cast(B_SET_DPMS_MODE); +m.attr("B_GET_PREFERRED_DISPLAY_MODE") = py::cast(B_GET_PREFERRED_DISPLAY_MODE); +m.attr("B_GET_MONITOR_INFO") = py::cast(B_GET_MONITOR_INFO); +m.attr("B_GET_EDID_INFO") = py::cast(B_GET_EDID_INFO); +m.attr("B_SET_BRIGHTNESS") = py::cast(B_SET_BRIGHTNESS); +m.attr("B_GET_BRIGHTNESS") = py::cast(B_GET_BRIGHTNESS); +m.attr("B_MOVE_CURSOR") = py::cast(B_MOVE_CURSOR); +m.attr("B_SET_CURSOR_SHAPE") = py::cast(B_SET_CURSOR_SHAPE); +m.attr("B_SHOW_CURSOR") = py::cast(B_SHOW_CURSOR); +m.attr("B_SET_CURSOR_BITMAP") = py::cast(B_SET_CURSOR_BITMAP); +m.attr("B_ACCELERANT_ENGINE_COUNT") = py::cast(B_ACCELERANT_ENGINE_COUNT); +m.attr("B_ACQUIRE_ENGINE") = py::cast(B_ACQUIRE_ENGINE); +m.attr("B_RELEASE_ENGINE") = py::cast(B_RELEASE_ENGINE); +m.attr("B_WAIT_ENGINE_IDLE") = py::cast(B_WAIT_ENGINE_IDLE); +m.attr("B_GET_SYNC_TOKEN") = py::cast(B_GET_SYNC_TOKEN); +m.attr("B_SYNC_TO_TOKEN") = py::cast(B_SYNC_TO_TOKEN); +m.attr("B_SCREEN_TO_SCREEN_BLIT") = py::cast(B_SCREEN_TO_SCREEN_BLIT); +m.attr("B_FILL_RECTANGLE") = py::cast(B_FILL_RECTANGLE); +m.attr("B_INVERT_RECTANGLE") = py::cast(B_INVERT_RECTANGLE); +m.attr("B_FILL_SPAN") = py::cast(B_FILL_SPAN); +m.attr("B_SCREEN_TO_SCREEN_TRANSPARENT_BLIT") = py::cast(B_SCREEN_TO_SCREEN_TRANSPARENT_BLIT); +m.attr("B_SCREEN_TO_SCREEN_SCALED_FILTERED_BLIT") = py::cast(B_SCREEN_TO_SCREEN_SCALED_FILTERED_BLIT); +m.attr("B_ACCELERANT_PRIVATE_START") = py::cast(B_ACCELERANT_PRIVATE_START); + +m.attr("B_SCROLL") = py::cast(B_SCROLL); +m.attr("B_8_BIT_DAC") = py::cast(B_8_BIT_DAC); +m.attr("B_HARDWARE_CURSOR") = py::cast(B_HARDWARE_CURSOR); +m.attr("B_PARALLEL_ACCESS") = py::cast(B_PARALLEL_ACCESS); +m.attr("B_DPMS") = py::cast(B_DPMS); +m.attr("B_IO_FB_NA") = py::cast(B_IO_FB_NA); + +m.attr("B_DPMS_ON") = py::cast(B_DPMS_ON); +m.attr("B_DPMS_STAND_BY") = py::cast(B_DPMS_STAND_BY); +m.attr("B_DPMS_SUSPEND") = py::cast(B_DPMS_SUSPEND); +m.attr("B_DPMS_OFF") = py::cast(B_DPMS_OFF); + +m.attr("B_BLANK_PEDESTAL") = py::cast(B_BLANK_PEDESTAL); +m.attr("B_TIMING_INTERLACED") = py::cast(B_TIMING_INTERLACED); +m.attr("B_POSITIVE_HSYNC") = py::cast(B_POSITIVE_HSYNC); +m.attr("B_POSITIVE_VSYNC") = py::cast(B_POSITIVE_VSYNC); +m.attr("B_SYNC_ON_GREEN") = py::cast(B_SYNC_ON_GREEN); + +m.attr("B_2D_ACCELERATION") = py::cast(B_2D_ACCELERATION); +m.attr("B_3D_ACCELERATION") = py::cast(B_3D_ACCELERATION); + +py::class_(m, "accelerant_device_info") +.def_readwrite("version", &accelerant_device_info::version, "") +//.def_readwrite("name", &accelerant_device_info::name, "") +//.def_readwrite("chipset", &accelerant_device_info::chipset, "") +//.def_readwrite("serial_no", &accelerant_device_info::serial_no, "") +.def_property( + "name", + [](const accelerant_device_info &acc_info) { + return py::cast(acc_info.name); + }, + [](accelerant_device_info &acc_info, const std::string &value) { + if (value.size()(m, "display_timing") +.def_readwrite("pixel_clock", &display_timing::pixel_clock, "") +.def_readwrite("h_display", &display_timing::h_display, "") +.def_readwrite("h_sync_start", &display_timing::h_sync_start, "") +.def_readwrite("h_sync_end", &display_timing::h_sync_end, "") +.def_readwrite("h_total", &display_timing::h_total, "") +.def_readwrite("v_display", &display_timing::v_display, "") +.def_readwrite("v_sync_start", &display_timing::v_sync_start, "") +.def_readwrite("v_sync_end", &display_timing::v_sync_end, "") +.def_readwrite("v_total", &display_timing::v_total, "") +.def_readwrite("flags", &display_timing::flags, "") +; + +py::class_(m, "display_mode") +.def_readwrite("timing", &display_mode::timing, "") +.def_readwrite("space", &display_mode::space, "") +.def_readwrite("virtual_width", &display_mode::virtual_width, "") +.def_readwrite("virtual_height", &display_mode::virtual_height, "") +.def_readwrite("h_display_start", &display_mode::h_display_start, "") +.def_readwrite("v_display_start", &display_mode::v_display_start, "") +.def_readwrite("flags", &display_mode::flags, "") +; + +py::class_(m, "frame_buffer_config") +.def_readwrite("frame_buffer", &frame_buffer_config::frame_buffer, "") +.def_readwrite("frame_buffer_dma", &frame_buffer_config::frame_buffer_dma, "") +.def_readwrite("bytes_per_row", &frame_buffer_config::bytes_per_row, "") +; + +py::class_(m, "display_timing_constraints") +.def_readwrite("h_res", &display_timing_constraints::h_res, "") +.def_readwrite("h_sync_min", &display_timing_constraints::h_sync_min, "") +.def_readwrite("h_sync_max", &display_timing_constraints::h_sync_max, "") +.def_readwrite("h_blank_min", &display_timing_constraints::h_blank_min, "") +.def_readwrite("h_blank_max", &display_timing_constraints::h_blank_max, "") +.def_readwrite("v_res", &display_timing_constraints::v_res, "") +.def_readwrite("v_sync_min", &display_timing_constraints::v_sync_min, "") +.def_readwrite("v_sync_max", &display_timing_constraints::v_sync_max, "") +.def_readwrite("v_blank_min", &display_timing_constraints::v_blank_min, "") +.def_readwrite("v_blank_max", &display_timing_constraints::v_blank_max, "") +; + +py::enum_(m, "production") +.value("week",MyClass::production::week) +.value("year",MyClass::production::year) +.export_values(); +//py::class_(m, "") +//.def_readwrite("week", &::week, "") +//.def_readwrite("year", &::year, "") +//; + +py::class_(m, "monitor_info") +.def_readwrite("version", &monitor_info::version, "") +//.def_readwrite("vendor", &monitor_info::vendor, "") +.def_property( + "vendor", + [](const monitor_info &info) { + return py::cast(info.vendor); + }, + [](monitor_info &info, const std::string &value) { + if (value.size()(m, "blit_params") +.def_readwrite("src_left", &blit_params::src_left, "") +.def_readwrite("src_top", &blit_params::src_top, "") +.def_readwrite("dest_left", &blit_params::dest_left, "") +.def_readwrite("dest_top", &blit_params::dest_top, "") +.def_readwrite("width", &blit_params::width, "") +.def_readwrite("height", &blit_params::height, "") +; + +py::class_(m, "scaled_blit_params") +.def_readwrite("src_left", &scaled_blit_params::src_left, "") +.def_readwrite("src_top", &scaled_blit_params::src_top, "") +.def_readwrite("src_width", &scaled_blit_params::src_width, "") +.def_readwrite("src_height", &scaled_blit_params::src_height, "") +.def_readwrite("dest_left", &scaled_blit_params::dest_left, "") +.def_readwrite("dest_top", &scaled_blit_params::dest_top, "") +.def_readwrite("dest_width", &scaled_blit_params::dest_width, "") +.def_readwrite("dest_height", &scaled_blit_params::dest_height, "") +; + +py::class_(m, "fill_rect_params") +.def_readwrite("left", &fill_rect_params::left, "") +.def_readwrite("top", &fill_rect_params::top, "") +.def_readwrite("right", &fill_rect_params::right, "") +.def_readwrite("bottom", &fill_rect_params::bottom, "") +; + +py::class_(m, "engine_token") +.def_readwrite("engine_id", &engine_token::engine_id, "") +.def_readwrite("capability_mask", &engine_token::capability_mask, "") +.def_readwrite("opaque", &engine_token::opaque, "") +; + +py::class_(m, "sync_token") +.def_readwrite("counter", &sync_token::counter, "") +.def_readwrite("engine_id", &sync_token::engine_id, "") +//.def_readwrite("opaque", &sync_token::opaque, "") +.def_property( + "opaque", + [](const sync_token &token) { + return py::cast(token.opaque); + }, + [](sync_token &token, const std::string &value) { + if (value.size() +#include +#include +#include + +#include + +namespace py = pybind11; + +PYBIND11_MODULE(GraphicsCard, m) +{ +m.attr("B_OPEN_GRAPHICS_CARD") = py::cast(B_OPEN_GRAPHICS_CARD); +m.attr("B_CLOSE_GRAPHICS_CARD") = py::cast(B_CLOSE_GRAPHICS_CARD); +m.attr("B_GET_GRAPHICS_CARD_INFO") = py::cast(B_GET_GRAPHICS_CARD_INFO); +m.attr("B_GET_GRAPHICS_CARD_HOOKS") = py::cast(B_GET_GRAPHICS_CARD_HOOKS); +m.attr("B_SET_INDEXED_COLOR") = py::cast(B_SET_INDEXED_COLOR); +m.attr("B_GET_SCREEN_SPACES") = py::cast(B_GET_SCREEN_SPACES); +m.attr("B_CONFIG_GRAPHICS_CARD") = py::cast(B_CONFIG_GRAPHICS_CARD); +m.attr("B_GET_REFRESH_RATES") = py::cast(B_GET_REFRESH_RATES); +m.attr("B_SET_SCREEN_GAMMA") = py::cast(B_SET_SCREEN_GAMMA); +m.attr("B_GET_INFO_FOR_CLONE_SIZE") = py::cast(B_GET_INFO_FOR_CLONE_SIZE); +m.attr("B_GET_INFO_FOR_CLONE") = py::cast(B_GET_INFO_FOR_CLONE); +m.attr("B_SET_CLONED_GRAPHICS_CARD") = py::cast(B_SET_CLONED_GRAPHICS_CARD); +m.attr("B_CLOSE_CLONED_GRAPHICS_CARD") = py::cast(B_CLOSE_CLONED_GRAPHICS_CARD); +m.attr("B_PROPOSE_FRAME_BUFFER") = py::cast(B_PROPOSE_FRAME_BUFFER); +m.attr("B_SET_FRAME_BUFFER") = py::cast(B_SET_FRAME_BUFFER); +m.attr("B_SET_DISPLAY_AREA") = py::cast(B_SET_DISPLAY_AREA); +m.attr("B_MOVE_DISPLAY_AREA") = py::cast(B_MOVE_DISPLAY_AREA); + +m.attr("B_CRT_CONTROL") = py::cast(B_CRT_CONTROL); +m.attr("B_GAMMA_CONTROL") = py::cast(B_GAMMA_CONTROL); +m.attr("B_FRAME_BUFFER_CONTROL") = py::cast(B_FRAME_BUFFER_CONTROL); +m.attr("B_PARALLEL_BUFFER_ACCESS") = py::cast(B_PARALLEL_BUFFER_ACCESS); +m.attr("B_LAME_ASS_CARD") = py::cast(B_LAME_ASS_CARD); + +py::class_(m, "graphics_card_info") +.def_readwrite("version", &graphics_card_info::version, "") +.def_readwrite("id", &graphics_card_info::id, "") +.def_readwrite("frame_buffer", &graphics_card_info::frame_buffer, "") +//.def_readwrite("rgba_order", &graphics_card_info::rgba_order, "") +.def_property( + "rgba_order", + [](const graphics_card_info &info) { + return py::cast(info.rgba_order); + }, + [](graphics_card_info &info, const std::string &value) { + if (value.size()(m, "indexed_color") +.def_readwrite("index", &indexed_color::index, "") +.def_readwrite("color", &indexed_color::color, "") +; + +py::class_(m, "graphics_card_config") +.def_readwrite("space", &graphics_card_config::space, "") +.def_readwrite("refresh_rate", &graphics_card_config::refresh_rate, "") +.def_readwrite("h_position", &graphics_card_config::h_position, "") +.def_readwrite("v_position", &graphics_card_config::v_position, "") +.def_readwrite("h_size", &graphics_card_config::h_size, "") +.def_readwrite("v_size", &graphics_card_config::v_size, "") +; + +py::class_(m, "refresh_rate_info") +.def_readwrite("min", &refresh_rate_info::min, "") +.def_readwrite("max", &refresh_rate_info::max, "") +.def_readwrite("current", &refresh_rate_info::current, "") +; + +py::class_(m, "graphics_card_spec") +.def_readwrite("screen_base", &graphics_card_spec::screen_base, "") +.def_readwrite("io_base", &graphics_card_spec::io_base, "") +.def_readwrite("vendor_id", &graphics_card_spec::vendor_id, "") +.def_readwrite("device_id", &graphics_card_spec::device_id, "") +.def_readwrite("_reserved1_", &graphics_card_spec::_reserved1_, "") +.def_readwrite("_reserved2_", &graphics_card_spec::_reserved2_, "") +; + +py::class_(m, "rgb_color_line") +.def_readwrite("x1", &rgb_color_line::x1, "") +.def_readwrite("y1", &rgb_color_line::y1, "") +.def_readwrite("x2", &rgb_color_line::x2, "") +.def_readwrite("y2", &rgb_color_line::y2, "") +.def_readwrite("color", &rgb_color_line::color, "") +; + +py::class_(m, "indexed_color_line") +.def_readwrite("x1", &indexed_color_line::x1, "") +.def_readwrite("y1", &indexed_color_line::y1, "") +.def_readwrite("x2", &indexed_color_line::x2, "") +.def_readwrite("y2", &indexed_color_line::y2, "") +.def_readwrite("color", &indexed_color_line::color, "") +; + +py::class_(m, "frame_buffer_info") +.def_readwrite("bits_per_pixel", &frame_buffer_info::bits_per_pixel, "") +.def_readwrite("bytes_per_row", &frame_buffer_info::bytes_per_row, "") +.def_readwrite("width", &frame_buffer_info::width, "") +.def_readwrite("height", &frame_buffer_info::height, "") +.def_readwrite("display_width", &frame_buffer_info::display_width, "") +.def_readwrite("display_height", &frame_buffer_info::display_height, "") +.def_readwrite("display_x", &frame_buffer_info::display_x, "") +.def_readwrite("display_y", &frame_buffer_info::display_y, "") +; + +py::class_(m, "screen_gamma") +//.def_readwrite("red", &screen_gamma::red, "") +.def_property( + "red", + [](const screen_gamma &gamma) { + return py::cast(gamma.red); + }, + [](screen_gamma &gamma, const std::string &value) { + if (value.size() +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; + +class PyBInputServerDevice : public BInputServerDevice { +public: + using BInputServerDevice::BInputServerDevice; + status_t InitCheck() override { + PYBIND11_OVERLOAD(status_t, BInputServerDevice, InitCheck); + } + status_t SystemShuttingDown() override { + PYBIND11_OVERLOAD(status_t, BInputServerDevice, SystemShuttingDown); + } + status_t Start(const char* device, void* cookie) override { + PYBIND11_OVERLOAD(status_t, BInputServerDevice, Start, device, cookie); + } + status_t Stop(const char* device, void* cookie) override { + PYBIND11_OVERLOAD(status_t, BInputServerDevice, Stop, device, cookie); + } + status_t Control(const char* device, void* cookie, uint32 code, BMessage* message) override { + PYBIND11_OVERLOAD(status_t, BInputServerDevice, Control, device, cookie, code, message); + } +}; + +PYBIND11_MODULE(InputServerDevice, m) +{ + +py::class_(m, "input_device_ref") +.def(py::init(), "") +.def_readwrite("name", &input_device_ref::name, "") +.def_readwrite("type", &input_device_ref::type, "") +.def_readwrite("cookie", &input_device_ref::cookie, "") +; + +py::class_(m, "BInputServerDevice") +.def(py::init(), "") +.def("InitCheck", &BInputServerDevice::InitCheck, "") +.def("SystemShuttingDown", &BInputServerDevice::SystemShuttingDown, "") +.def("Start", &BInputServerDevice::Start, "", py::arg("device"), py::arg("cookie")) +.def("Stop", &BInputServerDevice::Stop, "", py::arg("device"), py::arg("cookie")) +.def("Control", &BInputServerDevice::Control, "", py::arg("device"), py::arg("cookie"), py::arg("code"), py::arg("message")) +//.def("RegisterDevices", &BInputServerDevice::RegisterDevices, "", py::arg("devices")) +.def("RegisterDevices", [](BInputServerDevice &self, py::list &py_devices) { + std::vector devices; + for (auto item : py_devices) { + devices.push_back(item.cast()); + } + status_t status = self.RegisterDevices(devices.data()); + //for (size_t i = 0; i < devices.size(); ++i) { + // py_devices[i] = py::cast(devices[i]); + //} + return status; + }, py::arg("devices")) +//.def("UnregisterDevices", &BInputServerDevice::UnregisterDevices, "", py::arg("devices")) +.def("UnregisterDevices", [](BInputServerDevice &self, py::list &py_devices) { + std::vector devices; + for (auto item : py_devices) { + devices.push_back(item.cast()); + } + status_t status = self.UnregisterDevices(devices.data()); + //for (size_t i = 0; i < devices.size(); ++i) { + // py_devices[i] = py::cast(devices[i]); + //} + return status; + }, py::arg("devices")) +.def("EnqueueMessage", &BInputServerDevice::EnqueueMessage, "", py::arg("message")) +.def("StartMonitoringDevice", &BInputServerDevice::StartMonitoringDevice, "", py::arg("device")) +.def("StopMonitoringDevice", &BInputServerDevice::StopMonitoringDevice, "", py::arg("device")) +.def("AddDevices", &BInputServerDevice::AddDevices, "", py::arg("path")) +; + +//m.attr("DeviceAddOn") = py::cast(DeviceAddOn); +m.attr("B_KEY_MAP_CHANGED") = py::cast(B_KEY_MAP_CHANGED); +m.attr("B_KEY_LOCKS_CHANGED") = py::cast(B_KEY_LOCKS_CHANGED); +m.attr("B_KEY_REPEAT_DELAY_CHANGED") = py::cast(B_KEY_REPEAT_DELAY_CHANGED); +m.attr("B_KEY_REPEAT_RATE_CHANGED") = py::cast(B_KEY_REPEAT_RATE_CHANGED); +m.attr("B_MOUSE_TYPE_CHANGED") = py::cast(B_MOUSE_TYPE_CHANGED); +m.attr("B_MOUSE_MAP_CHANGED") = py::cast(B_MOUSE_MAP_CHANGED); +m.attr("B_MOUSE_SPEED_CHANGED") = py::cast(B_MOUSE_SPEED_CHANGED); +m.attr("B_CLICK_SPEED_CHANGED") = py::cast(B_CLICK_SPEED_CHANGED); +m.attr("B_MOUSE_ACCELERATION_CHANGED") = py::cast(B_MOUSE_ACCELERATION_CHANGED); +m.attr("B_SET_TOUCHPAD_SETTINGS") = py::cast(B_SET_TOUCHPAD_SETTINGS); +} diff --git a/bindings/add-ons/input_server/InputServerFilter.cpp b/bindings/add-ons/input_server/InputServerFilter.cpp new file mode 100644 index 0000000..421a781 --- /dev/null +++ b/bindings/add-ons/input_server/InputServerFilter.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; + +class PyBInputServerFilter : public BInputServerFilter { +public: + using BInputServerFilter::BInputServerFilter; + status_t InitCheck() override { + PYBIND11_OVERLOAD(status_t, BInputServerFilter, InitCheck); + } + filter_result Filter(BMessage* message, BList* _list) override { + PYBIND11_OVERLOAD(filter_result, BInputServerFilter, Filter, message, _list); + } +}; + +PYBIND11_MODULE(InputServerFilter, m) +{ +py::class_(m, "BInputServerFilter") +.def(py::init(), "") +.def("InitCheck", &BInputServerFilter::InitCheck, "") +.def("Filter", &BInputServerFilter::Filter, "", py::arg("message"), py::arg("_list")) +.def("GetScreenRegion", &BInputServerFilter::GetScreenRegion, "", py::arg("region")) +; + + +} diff --git a/bindings/add-ons/input_server/InputServerMethod.cpp b/bindings/add-ons/input_server/InputServerMethod.cpp new file mode 100644 index 0000000..0125476 --- /dev/null +++ b/bindings/add-ons/input_server/InputServerMethod.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; + +class PyBInputServerMethod : public BInputServerMethod { +public: + using BInputServerMethod::BInputServerMethod; + status_t MethodActivated(bool active) override { + PYBIND11_OVERLOAD(status_t, BInputServerMethod, MethodActivated, active); + } +}; + +PYBIND11_MODULE(InputServerMethod, m) +{ +py::class_(m, "BInputServerMethod") +.def(py::init(), "", py::arg("name"), py::arg("icon")) +.def("MethodActivated", &BInputServerMethod::MethodActivated, "", py::arg("active")) +.def("EnqueueMessage", &BInputServerMethod::EnqueueMessage, "", py::arg("message")) +.def("SetName", &BInputServerMethod::SetName, "", py::arg("name")) +.def("SetIcon", &BInputServerMethod::SetIcon, "", py::arg("icon")) +.def("SetMenu", &BInputServerMethod::SetMenu, "", py::arg("menu"), py::arg("target")) +; + + +} diff --git a/bindings/add-ons/mail_daemon/MailFilter.cpp b/bindings/add-ons/mail_daemon/MailFilter.cpp new file mode 100644 index 0000000..8e14b42 --- /dev/null +++ b/bindings/add-ons/mail_daemon/MailFilter.cpp @@ -0,0 +1,79 @@ +#include +#include +#include +#include + +#include +#include +#include +namespace py = pybind11; + +class PyBMailFilter : public BMailFilter{ + public: + using BMailFilter::BMailFilter; + BMailFilterAction HeaderFetched(entry_ref& ref, BFile& file, BMessage& attributes) override { + PYBIND11_OVERLOAD(BMailFilterAction, BMailFilter, HeaderFetched, ref, file, attributes); + } + void BodyFetched(const entry_ref& ref, BFile& file, BMessage& attributes) override { + PYBIND11_OVERLOAD(void, BMailFilter, BodyFetched, ref, file, attributes); + } + void MailboxSynchronized(status_t status) override { + PYBIND11_OVERLOAD(void, BMailFilter, MailboxSynchronized, status); + } + void MessageReadyToSend(const entry_ref& ref, BFile& file) override { + PYBIND11_OVERLOAD(void, BMailFilter, MessageReadyToSend, ref, file); + } + void MessageSent(const entry_ref& ref, BFile& file) override { + PYBIND11_OVERLOAD(void, BMailFilter, MessageSent, ref, file); + } +}; + +PYBIND11_MODULE(MailFilter, m) +{ +py::class_(m, "BMailFilter") +.def(py::init(), "", py::arg("protocol"),py::arg("settings")) +.def("HeaderFetched", &BMailFilter::HeaderFetched, "", py::arg("ref"),py::arg("file"), py::arg("attributes")) +/*.def("HeaderFetched", [](BMailFilter& self) { + entry_ref ref; +BFile file; +BMessage attributes; + BMailFilterAction r = self.HeaderFetched(ref, file, attributes); + return std::make_tuple(r,ref,file,attributes); +} +, "")*/ +.def("BodyFetched", &BMailFilter::BodyFetched, "", py::arg("ref"),py::arg("file"), py::arg("attributes")) +/*.def("BodyFetched", [](BMailFilter& self,const entry_ref & ref) { + BFile file; +BMessage attributes; + self.BodyFetched(ref, file, attributes); + return std::make_tuple(file,attributes); +} +, "", py::arg("ref"))*/ +.def("MailboxSynchronized", &BMailFilter::MailboxSynchronized, "", py::arg("status")) +.def("MessageReadyToSend", &BMailFilter::MessageReadyToSend, "", py::arg("ref"), py::arg("file")) +/*.def("MessageReadyToSend", [](BMailFilter& self,const entry_ref & ref) { + BFile file; + self.MessageReadyToSend(ref, file); + return file; +} +, "", py::arg("ref"))*/ +.def("MessageSent", &BMailFilter::MessageSent, "", py::arg("ref"), py::arg("file")) +/*.def("MessageSent", [](BMailFilter& self,const entry_ref & ref) { + BFile file; + self.MessageSent(ref, file); + return file; +} +, "", py::arg("ref"))*/ +; + +m.def("instantiate_filter_settings_view", &instantiate_filter_settings_view, "", py::arg("accountSettings"), py::arg("settings")); + +m.def("filter_name", &filter_name, "", py::arg("accountSettings"), py::arg("settings")); + +m.def("instantiate_filter", [](BMailProtocol& protocol, const BMailAddOnSettings & settings) { + BMailFilter * r = instantiate_filter(protocol, settings); + return r;//std::make_tuple(r,protocol); +} +, "", py::arg("protocol"), py::arg("settings")); + +} diff --git a/bindings/add-ons/mail_daemon/MailProtocol.cpp b/bindings/add-ons/mail_daemon/MailProtocol.cpp new file mode 100644 index 0000000..c16d1a8 --- /dev/null +++ b/bindings/add-ons/mail_daemon/MailProtocol.cpp @@ -0,0 +1,104 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace py = pybind11; + +class PyBMailNotifier : public BMailNotifier{ + public: + using BMailNotifier::BMailNotifier; + BMailNotifier* Clone() override { + PYBIND11_OVERLOAD_PURE(BMailNotifier*, BMailNotifier, Clone); + } + void ShowError(const char* error) override { + PYBIND11_OVERLOAD_PURE(void, BMailNotifier, ShowError, error); + } + void ShowMessage(const char* message) override { + PYBIND11_OVERLOAD_PURE(void, BMailNotifier, ShowMessage, message); + } + void SetTotalItems(uint32 items) override { + PYBIND11_OVERLOAD_PURE(void, BMailNotifier, SetTotalItems, items); + } + void SetTotalItemsSize(uint64 size) override { + PYBIND11_OVERLOAD_PURE(void, BMailNotifier, SetTotalItemsSize, size); + } + void ReportProgress(uint32 items, uint64 bytes, const char* message = NULL) override { + PYBIND11_OVERLOAD_PURE(void, BMailNotifier, ReportProgress, items, bytes, message); + } + void ResetProgress(const char* message = NULL) override { + PYBIND11_OVERLOAD_PURE(void, BMailNotifier, ResetProgress, message); + } +}; + +class PyBMailProtocol : public BMailProtocol{ + public: + using BMailProtocol::BMailProtocol; + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BMailProtocol, MessageReceived, message); + } +}; + + +PYBIND11_MODULE(MailProtocol, m) +{ +py::class_(m, "BMailNotifier") +.def("Clone", &BMailNotifier::Clone, "") +.def("ShowError", &BMailNotifier::ShowError, "", py::arg("error")) +.def("ShowMessage", &BMailNotifier::ShowMessage, "", py::arg("message")) +.def("SetTotalItems", &BMailNotifier::SetTotalItems, "", py::arg("items")) +.def("SetTotalItemsSize", &BMailNotifier::SetTotalItemsSize, "", py::arg("size")) +.def("ReportProgress", &BMailNotifier::ReportProgress, "", py::arg("items"), py::arg("bytes"), py::arg("message")=NULL) +.def("ResetProgress", &BMailNotifier::ResetProgress, "", py::arg("message")=NULL) +; + +py::class_(m, "BMailProtocol") +.def(py::init(), "", py::arg("name"), py::arg("settings")) +.def("AccountSettings", &BMailProtocol::AccountSettings, "") +.def("SetMailNotifier", &BMailProtocol::SetMailNotifier, "", py::arg("mailNotifier")) +.def("MailNotifier", &BMailProtocol::MailNotifier, "") +.def("AddFilter", py::overload_cast(&BMailProtocol::AddFilter), "", py::arg("filter")) +.def("CountFilter", &BMailProtocol::CountFilter, "") +.def("FilterAt", &BMailProtocol::FilterAt, "", py::arg("index")) +.def("RemoveFilter", py::overload_cast(&BMailProtocol::RemoveFilter), "", py::arg("index")) +.def("RemoveFilter", py::overload_cast(&BMailProtocol::RemoveFilter), "", py::arg("filter")) +.def("MessageReceived", &BMailProtocol::MessageReceived, "", py::arg("message")) +.def("ShowError", &BMailProtocol::ShowError, "", py::arg("error")) +.def("ShowMessage", &BMailProtocol::ShowMessage, "", py::arg("message")) +//.def_readwrite("AddFilter", &BMailProtocol::AddFilter, "") +//.def_readwrite("RemoveFilter", &BMailProtocol::RemoveFilter, "") +; + +/* +py::class_(m, "BInboundMailProtocol") +.def(py::init(), "", py::arg("name"), py::arg("settings")) +.def("MessageReceived", &BInboundMailProtocol::MessageReceived, "", py::arg("message")) +.def("SyncMessages", &BInboundMailProtocol::SyncMessages, "") +.def("FetchBody", &BInboundMailProtocol::FetchBody, "", py::arg("ref"), py::arg("replyTo")) +.def("MarkMessageAsRead", &BInboundMailProtocol::MarkMessageAsRead, "", py::arg("ref"), py::arg("flags")=B_READ) +.def_static("ReplyBodyFetched", &BInboundMailProtocol::ReplyBodyFetched, "", py::arg("replyTo"), py::arg("ref"), py::arg("status")) +; + +py::class_(m, "BOutboundMailProtocol") +.def(py::init(), "", py::arg("name"), py::arg("settings")) +.def("SendMessages", &BOutboundMailProtocol::SendMessages, "", py::arg("message"), py::arg("totalBytes")) +.def("MessageReceived", &BOutboundMailProtocol::MessageReceived, "", py::arg("message")) +;*/ + +m.def("instantiate_inbound_protocol", &instantiate_inbound_protocol, "", py::arg("settings")); + +m.def("instantiate_outbound_protocol", &instantiate_outbound_protocol, "", py::arg("settings")); + +m.def("instantiate_protocol_settings_view", &instantiate_protocol_settings_view, "", py::arg("accountSettings"), py::arg("settings")); + +//#define B_NO_MAIL_ACTION 0 +//#define B_MOVE_MAIL_ACTION 1 +//#define B_DELETE_MAIL_ACTION 2 + +} diff --git a/bindings/add-ons/mail_daemon/MailSettingsView.cpp b/bindings/add-ons/mail_daemon/MailSettingsView.cpp new file mode 100644 index 0000000..d0e6cef --- /dev/null +++ b/bindings/add-ons/mail_daemon/MailSettingsView.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +class PyBMailSettingsView : public BMailSettingsView { +public: + using BMailSettingsView::BMailSettingsView; + status_t SaveInto(BMailAddOnSettings& settings) const override { + PYBIND11_OVERLOAD_PURE(status_t, BMailSettingsView, SaveInto, settings); + } +}; + +PYBIND11_MODULE(MailSettingsView, m) +{ +py::class_(m, "BMailSettingsView") +.def(py::init(), "", py::arg("name")) +.def("SaveInto", &BMailSettingsView::SaveInto, "", py::arg("settings")) +/*.def("SaveInto", [](BMailSettingsView& self) { + BMailAddOnSettings settings; + status_t r = self.SaveInto(settings); + return std::make_tuple(r,settings); +} +, "")*/ + +; + + +} diff --git a/bindings/add-ons/network_settings/NetworkProfile.cpp b/bindings/add-ons/network_settings/NetworkProfile.cpp new file mode 100644 index 0000000..62496ae --- /dev/null +++ b/bindings/add-ons/network_settings/NetworkProfile.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BNetworkKit; + +PYBIND11_MODULE(NetworkProfile, m) +{ +py::class_(m, "BNetworkProfile") +.def(py::init(), "") +.def(py::init(), "", py::arg("path")) +.def(py::init(), "", py::arg("ref")) +.def(py::init(), "", py::arg("entry")) +.def("SetTo", py::overload_cast(&BNetworkProfile::SetTo), "", py::arg("path")) +.def("SetTo", py::overload_cast(&BNetworkProfile::SetTo), "", py::arg("ref")) +.def("SetTo", py::overload_cast(&BNetworkProfile::SetTo), "", py::arg("entry")) +.def("Exists", &BNetworkProfile::Exists, "") +.def("Name", &BNetworkProfile::Name, "") +.def("SetName", &BNetworkProfile::SetName, "", py::arg("name")) +.def("IsDefault", &BNetworkProfile::IsDefault, "") +.def("IsCurrent", &BNetworkProfile::IsCurrent, "") +.def("MakeCurrent", &BNetworkProfile::MakeCurrent, "") +.def("Delete", &BNetworkProfile::Delete, "") +.def_static("Default", &BNetworkProfile::Default, "") +.def_static("Current", &BNetworkProfile::Current, "") +; + + +} diff --git a/bindings/add-ons/network_settings/NetworkSettings.cpp b/bindings/add-ons/network_settings/NetworkSettings.cpp new file mode 100644 index 0000000..a93efc1 --- /dev/null +++ b/bindings/add-ons/network_settings/NetworkSettings.cpp @@ -0,0 +1,203 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BNetworkKit; + +class AltBNetworkSettingsRead : public BNetworkSettings { +public: + using BNetworkSettings::BNetworkSettings; + static const uint32 kMsgInterfaceSettingsUpdated() { + return BNetworkSettings::kMsgInterfaceSettingsUpdated; + } + static const uint32 kMsgNetworkSettingsUpdated() { + return BNetworkSettings::kMsgNetworkSettingsUpdated; + } + static const uint32 kMsgServiceSettingsUpdated() { + return BNetworkSettings::kMsgServiceSettingsUpdated; + } +}; + +PYBIND11_MODULE(NetworkSettings, m) +{ +py::class_(m, "BNetworkSettings") +.def(py::init(), "") +.def("GetNextInterface", [](BNetworkSettings& self, uint32 cookie) { + BMessage interface; + status_t r = self.GetNextInterface(cookie, interface); + return std::make_tuple(r,interface); +} +, "", py::arg("cookie")) +.def("GetInterface", [](BNetworkSettings& self,const char * name) { + BMessage interface; + status_t r = self.GetInterface(name, interface); + return std::make_tuple(r,interface); +} +, "", py::arg("name")) +.def("AddInterface", &BNetworkSettings::AddInterface, "", py::arg("interface")) +.def("RemoveInterface", &BNetworkSettings::RemoveInterface, "", py::arg("name")) +.def("Interface", py::overload_cast(&BNetworkSettings::Interface), "", py::arg("name")) +.def("Interface", py::overload_cast(&BNetworkSettings::Interface, py::const_), "", py::arg("name")) +.def("CountNetworks", &BNetworkSettings::CountNetworks, "") +.def("GetNextNetwork", [](BNetworkSettings& self,uint32 cookie) { + BMessage network; + status_t r = self.GetNextNetwork(cookie, network); + return std::make_tuple(r,network); +} +, "", py::arg("cookie")) +.def("GetNetwork", [](BNetworkSettings& self,const char * name) { + BMessage network; + status_t r = self.GetNetwork(name, network); + return std::make_tuple(r,network); +} +, "", py::arg("name")) +.def("AddNetwork", &BNetworkSettings::AddNetwork, "", py::arg("network")) +.def("RemoveNetwork", &BNetworkSettings::RemoveNetwork, "", py::arg("name")) +.def("Services", &BNetworkSettings::Services, "") +.def("GetNextService", [](BNetworkSettings& self,uint32 cookie) { + BMessage service; + status_t r = self.GetNextService(cookie, service); + return std::make_tuple(r,service); +} +, "", py::arg("cookie")) +.def("GetService", [](BNetworkSettings& self,const char * name) { + BMessage service; + status_t r = self.GetService(name, service); + return std::make_tuple(r,service); +} +, "", py::arg("name")) +.def("AddService", &BNetworkSettings::AddService, "", py::arg("service")) +.def("RemoveService", &BNetworkSettings::RemoveService, "", py::arg("name")) +.def("Service", py::overload_cast(&BNetworkSettings::Service), "", py::arg("name")) +.def("Service", py::overload_cast(&BNetworkSettings::Service), "", py::arg("name")) +.def("StartMonitoring", &BNetworkSettings::StartMonitoring, "", py::arg("target")) +.def("StopMonitoring", &BNetworkSettings::StopMonitoring, "", py::arg("target")) +.def("Update", &BNetworkSettings::Update, "", py::arg("message")) +//.def_readwrite("kMsgInterfaceSettingsUpdated", &BNetworkSettings::kMsgInterfaceSettingsUpdated, "") +.def_property_readonly_static("kMsgInterfaceSettingsUpdated", []() { + return AltBNetworkSettingsRead::kMsgInterfaceSettingsUpdated(); + }, "") +//.def_readwrite("kMsgNetworkSettingsUpdated", &BNetworkSettings::kMsgNetworkSettingsUpdated, "") +.def_property_readonly_static("kMsgNetworkSettingsUpdated", []() { + return AltBNetworkSettingsRead::kMsgNetworkSettingsUpdated(); + }, "") +//.def_readwrite("kMsgServiceSettingsUpdated", &BNetworkSettings::kMsgServiceSettingsUpdated, "") +.def_property_readonly_static("kMsgServiceSettingsUpdated", []() { + return AltBNetworkSettingsRead::kMsgServiceSettingsUpdated(); + }, "") +; + +py::class_(m, "BNetworkInterfaceAddressSettings") +.def(py::init(), "") +.def(py::init(), "", py::arg("data")) +.def(py::init(), "", py::arg("other")) +.def("Family", &BNetworkInterfaceAddressSettings::Family, "") +.def("SetFamily", &BNetworkInterfaceAddressSettings::SetFamily, "", py::arg("family")) +.def("IsAutoConfigure", &BNetworkInterfaceAddressSettings::IsAutoConfigure, "") +.def("SetAutoConfigure", &BNetworkInterfaceAddressSettings::SetAutoConfigure, "", py::arg("configure")) +.def("Address", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Address), "") +.def("Address", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Address), "") +.def("Mask", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Mask), "") +.def("Mask", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Mask), "") +.def("Peer", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Peer), "") +.def("Peer", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Peer), "") +.def("Broadcast", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Broadcast), "") +.def("Broadcast", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Broadcast), "") +.def("Gateway", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Gateway), "") +.def("Gateway", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Gateway), "") +.def("GetMessage", [](BNetworkInterfaceAddressSettings& self) { + BMessage data; + status_t r = self.GetMessage(data); + return std::make_tuple(r,data); +} +, "") +.def("operator=", &BNetworkInterfaceAddressSettings::operator=, "", py::arg("other")) +; + +py::class_(m, "BNetworkInterfaceSettings") +.def(py::init(), "") +.def(py::init(), "", py::arg("message")) +.def("Name", &BNetworkInterfaceSettings::Name, "") +.def("SetName", &BNetworkInterfaceSettings::SetName, "", py::arg("name")) +.def("Flags", &BNetworkInterfaceSettings::Flags, "") +.def("SetFlags", &BNetworkInterfaceSettings::SetFlags, "", py::arg("flags")) +.def("MTU", &BNetworkInterfaceSettings::MTU, "") +.def("SetMTU", &BNetworkInterfaceSettings::SetMTU, "", py::arg("mtu")) +.def("Metric", &BNetworkInterfaceSettings::Metric, "") +.def("SetMetric", &BNetworkInterfaceSettings::SetMetric, "", py::arg("metric")) +.def("CountAddresses", &BNetworkInterfaceSettings::CountAddresses, "") +.def("AddressAt", py::overload_cast(&BNetworkInterfaceSettings::AddressAt), "", py::arg("index")) +.def("AddressAt", py::overload_cast(&BNetworkInterfaceSettings::AddressAt), "", py::arg("index")) +.def("FindFirstAddress", &BNetworkInterfaceSettings::FindFirstAddress, "", py::arg("family")) +.def("AddAddress", &BNetworkInterfaceSettings::AddAddress, "", py::arg("address")) +.def("RemoveAddress", &BNetworkInterfaceSettings::RemoveAddress, "", py::arg("index")) +.def("IsAutoConfigure", &BNetworkInterfaceSettings::IsAutoConfigure, "", py::arg("family")) +.def("GetMessage", [](BNetworkInterfaceSettings& self) { + BMessage data; + status_t r = self.GetMessage(data); + return std::make_tuple(r,data); +} +, "") +; + +py::class_(m, "BNetworkServiceAddressSettings") +.def(py::init(), "") +.def(py::init(), "", py::arg("data"), py::arg("family")=- 1, py::arg("type")=- 1, py::arg("protocol")=- 1, py::arg("port")=- 1) +.def("Family", &BNetworkServiceAddressSettings::Family, "") +.def("SetFamily", &BNetworkServiceAddressSettings::SetFamily, "", py::arg("family")) +.def("Protocol", &BNetworkServiceAddressSettings::Protocol, "") +.def("SetProtocol", &BNetworkServiceAddressSettings::SetProtocol, "", py::arg("protocol")) +.def("Type", &BNetworkServiceAddressSettings::Type, "") +.def("SetType", &BNetworkServiceAddressSettings::SetType, "", py::arg("type")) +.def("Address", py::overload_cast<>(&BNetworkServiceAddressSettings::Address), "") +.def("Address", py::overload_cast<>(&BNetworkServiceAddressSettings::Address), "") +.def("GetMessage", [](BNetworkServiceAddressSettings& self) { + BMessage data; + status_t r = self.GetMessage(data); + return std::make_tuple(r,data); +} +, "") +.def("__eq__", &BNetworkServiceAddressSettings::operator==, "", py::arg("other")) +; + +py::class_(m, "BNetworkServiceSettings") +.def(py::init(), "") +.def(py::init(), "", py::arg("message")) +.def("InitCheck", &BNetworkServiceSettings::InitCheck, "") +.def("Name", &BNetworkServiceSettings::Name, "") +.def("SetName", &BNetworkServiceSettings::SetName, "", py::arg("name")) +.def("IsStandAlone", &BNetworkServiceSettings::IsStandAlone, "") +.def("SetStandAlone", &BNetworkServiceSettings::SetStandAlone, "", py::arg("alone")) +.def("IsEnabled", &BNetworkServiceSettings::IsEnabled, "") +.def("SetEnabled", &BNetworkServiceSettings::SetEnabled, "", py::arg("enable")) +.def("Family", &BNetworkServiceSettings::Family, "") +.def("SetFamily", &BNetworkServiceSettings::SetFamily, "", py::arg("family")) +.def("Protocol", &BNetworkServiceSettings::Protocol, "") +.def("SetProtocol", &BNetworkServiceSettings::SetProtocol, "", py::arg("protocol")) +.def("Type", &BNetworkServiceSettings::Type, "") +.def("SetType", &BNetworkServiceSettings::SetType, "", py::arg("type")) +.def("Port", &BNetworkServiceSettings::Port, "") +.def("SetPort", &BNetworkServiceSettings::SetPort, "", py::arg("port")) +.def("CountArguments", &BNetworkServiceSettings::CountArguments, "") +.def("ArgumentAt", &BNetworkServiceSettings::ArgumentAt, "", py::arg("index")) +.def("AddArgument", &BNetworkServiceSettings::AddArgument, "", py::arg("argument")) +.def("RemoveArgument", &BNetworkServiceSettings::RemoveArgument, "", py::arg("index")) +.def("CountAddresses", &BNetworkServiceSettings::CountAddresses, "") +.def("AddressAt", &BNetworkServiceSettings::AddressAt, "", py::arg("index")) +.def("AddAddress", &BNetworkServiceSettings::AddAddress, "", py::arg("address")) +.def("RemoveAddress", &BNetworkServiceSettings::RemoveAddress, "", py::arg("index")) +.def("IsRunning", &BNetworkServiceSettings::IsRunning, "") +.def("GetMessage", [](BNetworkServiceSettings& self) { + BMessage data; + status_t r = self.GetMessage(data); + return std::make_tuple(r,data); +} +, "") +; + + +} diff --git a/bindings/add-ons/network_settings/NetworkSettingsAddOn.cpp b/bindings/add-ons/network_settings/NetworkSettingsAddOn.cpp new file mode 100644 index 0000000..6bccd78 --- /dev/null +++ b/bindings/add-ons/network_settings/NetworkSettingsAddOn.cpp @@ -0,0 +1,186 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; +using namespace BNetworkKit; + +class PyBNetworkConfigurationListener : public BNetworkConfigurationListener{ + public: + using BNetworkConfigurationListener::BNetworkConfigurationListener; + void ConfigurationUpdated(const BMessage& message) override { + PYBIND11_OVERLOAD_PURE(void, BNetworkConfigurationListener, ConfigurationUpdated, message); + } +}; + +class PyBNetworkSettingsListener : public BNetworkSettingsListener{ + public: + using BNetworkSettingsListener::BNetworkSettingsListener; + void SettingsUpdated(uint32 type) override { + PYBIND11_OVERLOAD_PURE(void, BNetworkSettingsListener, SettingsUpdated, type); + } +}; + +class PyBNetworkSettingsItem : public BNetworkSettingsItem{ + public: + using BNetworkSettingsItem::BNetworkSettingsItem; + BNetworkSettingsType Type() const override { + PYBIND11_OVERLOAD_PURE(BNetworkSettingsType, BNetworkSettingsItem, Type); + } + BListItem* ListItem() override { + PYBIND11_OVERLOAD_PURE(BListItem*,BNetworkSettingsItem,ListItem); + } + BView* View() override { + PYBIND11_OVERLOAD_PURE(BView*,BNetworkSettingsItem,View); + } + status_t ProfileChanged(const BNetworkProfile* newProfile) override { + PYBIND11_OVERLOAD(status_t,BNetworkSettingsItem,ProfileChanged,newProfile); + } + status_t Revert() override { + PYBIND11_OVERLOAD_PURE(status_t,BNetworkSettingsItem,Revert); + } + bool IsRevertable() override { + PYBIND11_OVERLOAD_PURE(bool,BNetworkSettingsItem,IsRevertable); + } + void SettingsUpdated(uint32 type) override { + PYBIND11_OVERLOAD(void,BNetworkSettingsItem,SettingsUpdated,type); + } + void ConfigurationUpdated(const BMessage& message) override { + PYBIND11_OVERLOAD(void,BNetworkSettingsItem,ConfigurationUpdated,message); + } + void NotifySettingsUpdated() override { + PYBIND11_OVERLOAD(void, BNetworkSettingsItem, NotifySettingsUpdated); + } +}; + +class PyBNetworkSettingsInterfaceItem : public BNetworkSettingsInterfaceItem{ + public: + using BNetworkSettingsInterfaceItem::BNetworkSettingsInterfaceItem; + BNetworkSettingsType Type() const override { + PYBIND11_OVERLOAD_PURE(BNetworkSettingsType, BNetworkSettingsInterfaceItem, Type); + } + /* BNetworkSettingsType Type() const override { + PYBIND11_OVERLOAD_PURE(BNetworkSettingsType, BNetworkSettingsInterfaceItem, Type); + }*/ + + BListItem* ListItem() override { + PYBIND11_OVERLOAD_PURE(BListItem*, BNetworkSettingsInterfaceItem, ListItem); + } + + BView* View() override { + PYBIND11_OVERLOAD_PURE(BView*, BNetworkSettingsInterfaceItem, View); + } + + status_t Revert() override { + PYBIND11_OVERLOAD_PURE(status_t, BNetworkSettingsInterfaceItem, Revert); + } + + bool IsRevertable() override { + PYBIND11_OVERLOAD_PURE(bool, BNetworkSettingsInterfaceItem, IsRevertable); + } + void SettingsUpdated(uint32 type) override { + PYBIND11_OVERLOAD(void, BNetworkSettingsInterfaceItem, SettingsUpdated, type); + } + + void ConfigurationUpdated(const BMessage& message) override { + PYBIND11_OVERLOAD(void, BNetworkSettingsInterfaceItem, ConfigurationUpdated, message); + } + + void NotifySettingsUpdated() override { + PYBIND11_OVERLOAD(void, BNetworkSettingsInterfaceItem, NotifySettingsUpdated); + } +}; + +class PyBNetworkInterfaceListItem : public BNetworkInterfaceListItem{ + public: + using BNetworkInterfaceListItem::BNetworkInterfaceListItem; + void DrawItem(BView* owner,BRect bounds, bool complete) override { + PYBIND11_OVERLOAD(void, BNetworkInterfaceListItem, DrawItem, owner, bounds, complete); + } + void Update(BView* owner, const BFont* font) override { + PYBIND11_OVERLOAD(void, BNetworkInterfaceListItem, Update, owner, font); + } + void ConfigurationUpdated(const BMessage& message) override { + PYBIND11_OVERLOAD(void, BNetworkInterfaceListItem, ConfigurationUpdated, message); + } +}; + +class PyBNetworkSettingsAddOn : public BNetworkSettingsAddOn{ + public: + using BNetworkSettingsAddOn::BNetworkSettingsAddOn; + BNetworkSettingsInterfaceItem* CreateNextInterfaceItem(uint32& cookie, const char* interface) override { + PYBIND11_OVERLOAD(BNetworkSettingsInterfaceItem*, BNetworkSettingsAddOn, CreateNextInterfaceItem, cookie, interface); + } + BNetworkSettingsItem* CreateNextItem(uint32& cookie) override { + PYBIND11_OVERLOAD(BNetworkSettingsItem*, BNetworkSettingsAddOn, CreateNextItem, cookie); + } +}; + +PYBIND11_MODULE(NetworkSettingsAddOn, m) +{ +py::enum_(m, "BNetworkSettingsType", "") +.value("B_NETWORK_SETTINGS_TYPE_INTERFACE", BNetworkSettingsType::B_NETWORK_SETTINGS_TYPE_INTERFACE, "") +.value("B_NETWORK_SETTINGS_TYPE_SERVICE", BNetworkSettingsType::B_NETWORK_SETTINGS_TYPE_SERVICE, "") +.value("B_NETWORK_SETTINGS_TYPE_DIAL_UP", BNetworkSettingsType::B_NETWORK_SETTINGS_TYPE_DIAL_UP, "") +.value("B_NETWORK_SETTINGS_TYPE_VPN", BNetworkSettingsType::B_NETWORK_SETTINGS_TYPE_VPN, "") +.value("B_NETWORK_SETTINGS_TYPE_OTHER", BNetworkSettingsType::B_NETWORK_SETTINGS_TYPE_OTHER, "") +.export_values(); + +py::class_(m, "BNetworkConfigurationListener") +.def("ConfigurationUpdated", &BNetworkConfigurationListener::ConfigurationUpdated, "", py::arg("message")) +; + +py::class_(m, "BNetworkSettingsListener") +.def("SettingsUpdated", &BNetworkSettingsListener::SettingsUpdated, "", py::arg("type")) +; + +py::class_(m, "BNetworkSettingsItem") +.def(py::init(), "") +.def("Type", &BNetworkSettingsItem::Type, "") +.def("ListItem", &BNetworkSettingsItem::ListItem, "") +.def("View", &BNetworkSettingsItem::View, "") +.def("ProfileChanged", &BNetworkSettingsItem::ProfileChanged, "", py::arg("newProfile")) +.def("Profile", &BNetworkSettingsItem::Profile, "") +.def("Revert", &BNetworkSettingsItem::Revert, "") +.def("IsRevertable", &BNetworkSettingsItem::IsRevertable, "") +.def("SettingsUpdated", &BNetworkSettingsItem::SettingsUpdated, "", py::arg("type")) +.def("ConfigurationUpdated", &BNetworkSettingsItem::ConfigurationUpdated, "", py::arg("message")) +.def("NotifySettingsUpdated", &BNetworkSettingsItem::NotifySettingsUpdated, "") +; + +py::class_(m, "BNetworkSettingsInterfaceItem") +.def(py::init(), "", py::arg("interface")) +.def("Type", &BNetworkSettingsInterfaceItem::Type, "") +.def("Interface", &BNetworkSettingsInterfaceItem::Interface, "") +; + +py::class_(m, "BNetworkInterfaceListItem") +.def(py::init(), "", py::arg("family"), py::arg("interface"), py::arg("label"), py::arg("settings")) +.def("Label", &BNetworkInterfaceListItem::Label, "") +.def("DrawItem", &BNetworkInterfaceListItem::DrawItem, "", py::arg("owner"), py::arg("bounds"), py::arg("complete")) +.def("Update", &BNetworkInterfaceListItem::Update, "", py::arg("owner"), py::arg("font")) +.def("ConfigurationUpdated", &BNetworkInterfaceListItem::ConfigurationUpdated, "", py::arg("message")) +; + +py::class_(m, "BNetworkSettingsAddOn")//, PyBNetworkSettingsAddOn>(m, "BNetworkSettingsAddOn") +.def(py::init(), "", py::arg("image"), py::arg("settings")) +.def("CreateNextInterfaceItem", &BNetworkSettingsAddOn::CreateNextInterfaceItem, "", py::arg("cookie"), py::arg("interface")) +.def("CreateNextItem", &BNetworkSettingsAddOn::CreateNextItem, "", py::arg("cookie")) +.def("Image", &BNetworkSettingsAddOn::Image, "") +.def("Resources", &BNetworkSettingsAddOn::Resources, "") +.def("Settings", &BNetworkSettingsAddOn::Settings, "") +; + +m.def("instantiate_network_settings_add_on", [](image_id image) { + BNetworkSettings settings; + BNetworkSettingsAddOn * r = instantiate_network_settings_add_on(image, settings); + return std::make_tuple(r,settings); +} +, "", py::arg("image")); + +} diff --git a/bindings/add-ons/registrar/MimeSnifferAddon.cpp b/bindings/add-ons/registrar/MimeSnifferAddon.cpp new file mode 100644 index 0000000..2c93e54 --- /dev/null +++ b/bindings/add-ons/registrar/MimeSnifferAddon.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +#include +//#include +#include +namespace py = pybind11; + +class PyBMimeSnifferAddon : public BMimeSnifferAddon{ + public: + using BMimeSnifferAddon::BMimeSnifferAddon; + size_t MinimalBufferSize() override { + PYBIND11_OVERLOAD(size_t, BMimeSnifferAddon, MinimalBufferSize); + } + float GuessMimeType(const char* fileName, BMimeType* type) override { + PYBIND11_OVERLOAD(float, BMimeSnifferAddon, GuessMimeType, fileName, type); + } + float GuessMimeType(BFile* file, const void* buffer, int32 length, BMimeType* type) override { + PYBIND11_OVERLOAD(float, BMimeSnifferAddon, GuessMimeType, file, buffer, length, type); + } +}; + +PYBIND11_MODULE(MimeSnifferAddon, m) +{ +py::class_(m, "BMimeSnifferAddon") +.def(py::init(), "") +.def("MinimalBufferSize", &BMimeSnifferAddon::MinimalBufferSize, "") +.def("GuessMimeType", py::overload_cast(&BMimeSnifferAddon::GuessMimeType), "", py::arg("fileName"), py::arg("type")) +.def("GuessMimeType", py::overload_cast(&BMimeSnifferAddon::GuessMimeType), "", py::arg("file"), py::arg("buffer"), py::arg("length"), py::arg("type")) +; + + +} diff --git a/bindings/add-ons/screen_saver/ScreenSaver.cpp b/bindings/add-ons/screen_saver/ScreenSaver.cpp new file mode 100644 index 0000000..883749c --- /dev/null +++ b/bindings/add-ons/screen_saver/ScreenSaver.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +class PyBScreenSaver : public BScreenSaver{ + public: + using BScreenSaver::BScreenSaver; + status_t InitCheck() override { + PYBIND11_OVERLOAD(status_t, BScreenSaver, InitCheck); + } + status_t StartSaver(BView* view, bool preview) override { + PYBIND11_OVERLOAD(status_t, BScreenSaver, StartSaver, view, preview); + } + void StopSaver() override { + PYBIND11_OVERLOAD(void, BScreenSaver, StopSaver); + } + void Draw(BView* view, int32 frame) override { + PYBIND11_OVERLOAD(void, BScreenSaver, Draw, view, frame); + } + void DirectConnected(direct_buffer_info* info) override { + PYBIND11_OVERLOAD(void, BScreenSaver, DirectConnected, info); + } + void DirectDraw(int32 frame) override { + PYBIND11_OVERLOAD(void, BScreenSaver, DirectDraw, frame); + } + void StartConfig(BView* configView) override { + PYBIND11_OVERLOAD(void, BScreenSaver, StartConfig, configView); + } + void StopConfig() override { + PYBIND11_OVERLOAD(void, BScreenSaver, StopConfig); + } + void SupplyInfo(BMessage* info) const override { + PYBIND11_OVERLOAD(void, BScreenSaver, SupplyInfo, info); + } + void ModulesChanged(const BMessage* info) override { + PYBIND11_OVERLOAD(void, BScreenSaver, ModulesChanged, info); + } + status_t SaveState(BMessage* into) const override { + PYBIND11_OVERLOAD(status_t, BScreenSaver, SaveState, into); + } +}; + +PYBIND11_MODULE(ScreenSaver, m) +{ +py::class_(m, "BScreenSaver") +.def(py::init(), "", py::arg("archive"), py::arg("thisImage")) +.def("InitCheck", &BScreenSaver::InitCheck, "") +.def("StartSaver", &BScreenSaver::StartSaver, "", py::arg("view"), py::arg("preview")) +.def("StopSaver", &BScreenSaver::StopSaver, "") +.def("Draw", &BScreenSaver::Draw, "", py::arg("view"), py::arg("frame")) +.def("DirectConnected", &BScreenSaver::DirectConnected, "", py::arg("info")) +.def("DirectDraw", &BScreenSaver::DirectDraw, "", py::arg("frame")) +.def("StartConfig", &BScreenSaver::StartConfig, "", py::arg("configView")) +.def("StopConfig", &BScreenSaver::StopConfig, "") +.def("SupplyInfo", &BScreenSaver::SupplyInfo, "", py::arg("info")) +.def("ModulesChanged", &BScreenSaver::ModulesChanged, "", py::arg("info")) +.def("SaveState", &BScreenSaver::SaveState, "", py::arg("into")) +.def("SetTickSize", &BScreenSaver::SetTickSize, "", py::arg("tickSize")) +.def("TickSize", &BScreenSaver::TickSize, "") +.def("SetLoop", &BScreenSaver::SetLoop, "", py::arg("onCount"), py::arg("offCount")) +.def("LoopOnCount", &BScreenSaver::LoopOnCount, "") +.def("LoopOffCount", &BScreenSaver::LoopOffCount, "") +; + +m.def("instantiate_screen_saver", &instantiate_screen_saver, "", py::arg("msg"), py::arg("id")); + +} From e3304be13cb28a3586794b194934afdb299477ad Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 30 Aug 2024 10:00:02 +0200 Subject: [PATCH 025/115] Add non-working device/drivers plus working OS --- Jamfile | 27 +- bindings/__init__.py | 14 +- bindings/device/A2D.cpp | 22 ++ bindings/device/D2A.cpp | 23 ++ bindings/device/DigitalPort.cpp | 27 ++ bindings/device/Joystick.cpp | 49 +++ bindings/device/SerialPort.cpp | 88 +++++ bindings/device/USBKit.cpp | 109 ++++++ bindings/drivers/bios.cpp | 89 +++++ bindings/drivers/bus_manager.cpp | 37 ++ bindings/drivers/module.cpp | 187 ++++++++++ bindings/kernel/OS.cpp | 569 +++++++++++++++++++++++++++++++ 12 files changed, 1238 insertions(+), 3 deletions(-) create mode 100644 bindings/device/A2D.cpp create mode 100644 bindings/device/D2A.cpp create mode 100644 bindings/device/DigitalPort.cpp create mode 100644 bindings/device/Joystick.cpp create mode 100644 bindings/device/SerialPort.cpp create mode 100644 bindings/device/USBKit.cpp create mode 100644 bindings/drivers/bios.cpp create mode 100644 bindings/drivers/bus_manager.cpp create mode 100644 bindings/drivers/module.cpp create mode 100644 bindings/kernel/OS.cpp diff --git a/Jamfile b/Jamfile index 8e64aa9..bca5457 100644 --- a/Jamfile +++ b/Jamfile @@ -74,7 +74,7 @@ install_location ?= /boot/system/non-packaged/lib/python$(python_version)/site-packages ; # Where to search for .cpp files -SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/storage bindings/kernel bindings/translation bindings/add-ons/screen_saver bindings/add-ons/registrar bindings/add-ons/graphics bindings/add-ons/input_server bindings/add-ons/mail_daemon bindings/add-ons/network_settings ; +SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/storage bindings/kernel bindings/translation bindings/add-ons/screen_saver bindings/add-ons/registrar bindings/add-ons/graphics bindings/add-ons/input_server bindings/add-ons/mail_daemon bindings/add-ons/network_settings bindings/drivers bindings/device ; # Where to look for header files SubDirHdrs headers ; @@ -217,6 +217,7 @@ local sourceFiles = #Kernel fs_attr.cpp + OS.cpp #StorageKit StorageDefs.cpp @@ -268,6 +269,19 @@ local sourceFiles = NetworkProfile.cpp NetworkSettings.cpp NetworkSettingsAddOn.cpp + + #drivers + #bios.cpp + #module.cpp + #bus_manager.cpp + + #device + SerialPort.cpp + Joystick.cpp + USBKit.cpp + A2D.cpp + D2A.cpp + DigitalPort.cpp ; # The .so files can be built from the .cpp files, each .cpp file mapping to @@ -285,6 +299,17 @@ LINKLIBS on TranslatorRoster.so = $(LINKLIBS) -ltranslation ; LINKLIBS on TranslationUtils.so = $(LINKLIBS) -ltranslation ; LINKLIBS on Translator.so = $(LINKLIBS) -ltranslation ; +LINKLIBS on ScreenSaver.so = $(LINKLIBS) -lscreensaver ; +#LINKLIBS on MimeSnifferAddon.so = $(LINKLIBS) -lstoragekit ; +#LINKLIBS on InputServerDevice.so = $(LINKLIBS) -linputkit ; +#LINKLIBS on InputServerFilter.so = $(LINKLIBS) -linputkit ; +#LINKLIBS on InputServerMethod.so = $(LINKLIBS) -linputkit ; +LINKLIBS on MailFilter.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailSettingsView.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailProtocol.so = $(LINKLIBS) -lmail ; +LINKLIBS on NetworkSettings.so = $(LINKLIBS) -lbnetapi ; + + # __init__.py can be built by simply copying the file MakeLocate __init__.py : $(LOCATE_TARGET) ; # Put it in the build directory File __init__.py : bindings/__init__.py ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 4b776c8..4d5ff49 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -106,6 +106,7 @@ from .Url import * from .fs_attr import * +from .OS import * from .StorageDefs import * from .Statable import * @@ -147,12 +148,21 @@ #from .InputServerFilter import * #from .InputServerMethod import * #from .MailFilter import * -#from .MailSettingsView import * +from .MailSettingsView import * #from .MailProtocol import * #from .NetworkProfile import * -#from .NetworkSettings import * +from .NetworkSettings import * #from .NetworkSettingsAddOn import * +#from .bus_manager import * + +#from .SerialPort import * +#from .Joystick import * +#from .USBKit import * +#from .A2D import * +#from .D2A import * +#from .DigitalPort import * + _BWindow=BWindow _BApplication=BApplication def MessageReceived(self, msg, parent): diff --git a/bindings/device/A2D.cpp b/bindings/device/A2D.cpp new file mode 100644 index 0000000..2539f96 --- /dev/null +++ b/bindings/device/A2D.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(A2D,m) +{ +py::class_(m, "BA2D") +.def(py::init(), "") +.def("Open", &BA2D::Open, "", py::arg("portName")) +.def("Close", &BA2D::Close, "") +.def("IsOpen", &BA2D::IsOpen, "") +.def("Read", &BA2D::Read, "", py::arg("buf")) +; + + +} diff --git a/bindings/device/D2A.cpp b/bindings/device/D2A.cpp new file mode 100644 index 0000000..b75a18d --- /dev/null +++ b/bindings/device/D2A.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(D2A,m) +{ +py::class_(m, "BD2A") +.def(py::init(), "") +.def("Open", &BD2A::Open, "", py::arg("portName")) +.def("Close", &BD2A::Close, "") +.def("IsOpen", &BD2A::IsOpen, "") +.def("Read", &BD2A::Read, "", py::arg("buf")) +.def("Write", &BD2A::Write, "", py::arg("value")) +; + + +} diff --git a/bindings/device/DigitalPort.cpp b/bindings/device/DigitalPort.cpp new file mode 100644 index 0000000..df3e383 --- /dev/null +++ b/bindings/device/DigitalPort.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(DigitalPort,m) +{ +py::class_(m, "BDigitalPort") +.def(py::init(), "") +.def("Open", &BDigitalPort::Open, "", py::arg("portName")) +.def("Close", &BDigitalPort::Close, "") +.def("IsOpen", &BDigitalPort::IsOpen, "") +.def("Read", &BDigitalPort::Read, "", py::arg("buf")) +.def("Write", &BDigitalPort::Write, "", py::arg("value")) +.def("SetAsOutput", &BDigitalPort::SetAsOutput, "") +.def("IsOutput", &BDigitalPort::IsOutput, "") +.def("SetAsInput", &BDigitalPort::SetAsInput, "") +.def("IsInput", &BDigitalPort::IsInput, "") +; + + +} diff --git a/bindings/device/Joystick.cpp b/bindings/device/Joystick.cpp new file mode 100644 index 0000000..5bb23f5 --- /dev/null +++ b/bindings/device/Joystick.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(Joystick,m) +{ +py::class_(m, "BJoystick") +.def(py::init(), "") +.def("Open", py::overload_cast(&BJoystick::Open), "", py::arg("portName")) +.def("Open", py::overload_cast(&BJoystick::Open), "", py::arg("portName"), py::arg("enhanced")) +.def("Close", &BJoystick::Close, "") +.def("Update", &BJoystick::Update, "") +.def("SetMaxLatency", &BJoystick::SetMaxLatency, "", py::arg("maxLatency")) +.def("CountDevices", &BJoystick::CountDevices, "") +.def("GetDeviceName", &BJoystick::GetDeviceName, "", py::arg("index"), py::arg("name"), py::arg("bufSize")=B_OS_NAME_LENGTH) +.def("RescanDevices", &BJoystick::RescanDevices, "") +.def("EnterEnhancedMode", &BJoystick::EnterEnhancedMode, "", py::arg("ref")=NULL) +.def("CountSticks", &BJoystick::CountSticks, "") +.def("CountAxes", &BJoystick::CountAxes, "") +.def("GetAxisValues", &BJoystick::GetAxisValues, "", py::arg("outValues"), py::arg("forStick")=0) +.def("GetAxisNameAt", &BJoystick::GetAxisNameAt, "", py::arg("index"), py::arg("outName")) +.def("CountHats", &BJoystick::CountHats, "") +.def("GetHatValues", &BJoystick::GetHatValues, "", py::arg("outHats"), py::arg("forStick")=0) +.def("GetHatNameAt", &BJoystick::GetHatNameAt, "", py::arg("index"), py::arg("outName")) +.def("CountButtons", &BJoystick::CountButtons, "") +.def("ButtonValues", &BJoystick::ButtonValues, "", py::arg("forStick")=0) +.def("GetButtonValues", &BJoystick::GetButtonValues, "", py::arg("outButtons"), py::arg("forStick")=0) +.def("GetButtonNameAt", &BJoystick::GetButtonNameAt, "", py::arg("index"), py::arg("outName")) +.def("GetControllerModule", &BJoystick::GetControllerModule, "", py::arg("outName")) +.def("GetControllerName", &BJoystick::GetControllerName, "", py::arg("outName")) +.def("IsCalibrationEnabled", &BJoystick::IsCalibrationEnabled, "") +.def("EnableCalibration", &BJoystick::EnableCalibration, "", py::arg("calibrates")=true) +.def_readwrite("timestamp", &BJoystick::timestamp, "") +.def_readwrite("horizontal", &BJoystick::horizontal, "") +.def_readwrite("vertical", &BJoystick::vertical, "") +.def_readwrite("button1", &BJoystick::button1, "") +.def_readwrite("button2", &BJoystick::button2, "") +; + + +} diff --git a/bindings/device/SerialPort.cpp b/bindings/device/SerialPort.cpp new file mode 100644 index 0000000..040e7cd --- /dev/null +++ b/bindings/device/SerialPort.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +PYBIND11_MODULE(SerialPort,m) +{ +py::enum_(m, "data_rate", "") +.value("B_0_BPS", data_rate::B_0_BPS, "") +.value("B_50_BPS", data_rate::B_50_BPS, "") +.value("B_75_BPS", data_rate::B_75_BPS, "") +.value("B_110_BPS", data_rate::B_110_BPS, "") +.value("B_134_BPS", data_rate::B_134_BPS, "") +.value("B_150_BPS", data_rate::B_150_BPS, "") +.value("B_200_BPS", data_rate::B_200_BPS, "") +.value("B_300_BPS", data_rate::B_300_BPS, "") +.value("B_600_BPS", data_rate::B_600_BPS, "") +.value("B_1200_BPS", data_rate::B_1200_BPS, "") +.value("B_1800_BPS", data_rate::B_1800_BPS, "") +.value("B_2400_BPS", data_rate::B_2400_BPS, "") +.value("B_4800_BPS", data_rate::B_4800_BPS, "") +.value("B_9600_BPS", data_rate::B_9600_BPS, "") +.value("B_19200_BPS", data_rate::B_19200_BPS, "") +.value("B_38400_BPS", data_rate::B_38400_BPS, "") +.value("B_57600_BPS", data_rate::B_57600_BPS, "") +.value("B_115200_BPS", data_rate::B_115200_BPS, "") +.value("B_230400_BPS", data_rate::B_230400_BPS, "") +.value("B_31250_BPS", data_rate::B_31250_BPS, "") +.export_values(); + +py::enum_(m, "data_bits", "") +.value("B_DATA_BITS_7", data_bits::B_DATA_BITS_7, "") +.value("B_DATA_BITS_8", data_bits::B_DATA_BITS_8, "") +.export_values(); + +py::enum_(m, "stop_bits", "") +.value("B_STOP_BITS_1", stop_bits::B_STOP_BITS_1, "") +.value("B_STOP_BITS_2", stop_bits::B_STOP_BITS_2, "") +.export_values(); + +py::enum_(m, "parity_mode", "") +.value("B_NO_PARITY", parity_mode::B_NO_PARITY, "") +.value("B_ODD_PARITY", parity_mode::B_ODD_PARITY, "") +.value("B_EVEN_PARITY", parity_mode::B_EVEN_PARITY, "") +.export_values(); + +m.attr("B_NOFLOW_CONTROL") = py::cast(B_NOFLOW_CONTROL); +m.attr("B_HARDWARE_CONTROL") = py::cast(B_HARDWARE_CONTROL); +m.attr("B_SOFTWARE_CONTROL") = py::cast(B_SOFTWARE_CONTROL); + +py::class_(m, "BSerialPort") +.def(py::init(), "") +.def("Open", &BSerialPort::Open, "", py::arg("portName")) +.def("Close", &BSerialPort::Close, "") +.def("Read", &BSerialPort::Read, "", py::arg("buf"), py::arg("count")) +.def("Write", &BSerialPort::Write, "", py::arg("buf"), py::arg("count")) +.def("SetBlocking", &BSerialPort::SetBlocking, "", py::arg("blocking")) +.def("SetTimeout", &BSerialPort::SetTimeout, "", py::arg("microSeconds")) +.def("SetDataRate", &BSerialPort::SetDataRate, "", py::arg("bitsPerSecond")) +.def("DataRate", &BSerialPort::DataRate, "") +.def("SetDataBits", &BSerialPort::SetDataBits, "", py::arg("numBits")) +.def("DataBits", &BSerialPort::DataBits, "") +.def("SetStopBits", &BSerialPort::SetStopBits, "", py::arg("numBits")) +.def("StopBits", &BSerialPort::StopBits, "") +.def("SetParityMode", &BSerialPort::SetParityMode, "", py::arg("which")) +.def("ParityMode", &BSerialPort::ParityMode, "") +.def("ClearInput", &BSerialPort::ClearInput, "") +.def("ClearOutput", &BSerialPort::ClearOutput, "") +.def("SetFlowControl", &BSerialPort::SetFlowControl, "", py::arg("method")) +.def("FlowControl", &BSerialPort::FlowControl, "") +.def("SetDTR", &BSerialPort::SetDTR, "", py::arg("asserted")) +.def("SetRTS", &BSerialPort::SetRTS, "", py::arg("asserted")) +.def("NumCharsAvailable", &BSerialPort::NumCharsAvailable, "", py::arg("waitThisMany")) +.def("IsCTS", &BSerialPort::IsCTS, "") +.def("IsDSR", &BSerialPort::IsDSR, "") +.def("IsRI", &BSerialPort::IsRI, "") +.def("IsDCD", &BSerialPort::IsDCD, "") +.def("WaitForInput", &BSerialPort::WaitForInput, "") +.def("CountDevices", &BSerialPort::CountDevices, "") +.def("GetDeviceName", &BSerialPort::GetDeviceName, "", py::arg("index"), py::arg("name"), py::arg("bufSize")=B_OS_NAME_LENGTH) +; + + +} diff --git a/bindings/device/USBKit.cpp b/bindings/device/USBKit.cpp new file mode 100644 index 0000000..f61c528 --- /dev/null +++ b/bindings/device/USBKit.cpp @@ -0,0 +1,109 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +class PyBUSBRoster : public BUSBRoster{ + public: + using BUSBRoster::BUSBRoster; + status_t DeviceAdded(BUSBDevice *device) override { + PYBIND11_OVERLOAD_PURE(status_t,BUSBRoster,DeviceAdded,device) + } + void DeviceRemoved(BUSBDevice *device) override { + PYBIND11_OVERLOAD_PURE(void,BUSBRoster,DeviceRemoved,device) + } +}; + +PYBIND11_MODULE(USBKit,m) +{ +py::class_(m, "BUSBRoster") +.def(py::init(), "") +.def("DeviceAdded", &BUSBRoster::DeviceAdded, "", py::arg("device")) +.def("DeviceRemoved", &BUSBRoster::DeviceRemoved, "", py::arg("device")) +.def("Start", &BUSBRoster::Start, "") +.def("Stop", &BUSBRoster::Stop, "") +; + +py::class_(m, "BUSBDevice") +.def(py::init(), "", py::arg("path")=NULL) +.def("InitCheck", &BUSBDevice::InitCheck, "") +.def("SetTo", &BUSBDevice::SetTo, "", py::arg("path")) +.def("Unset", &BUSBDevice::Unset, "") +.def("Location", &BUSBDevice::Location, "") +.def("IsHub", &BUSBDevice::IsHub, "") +.def("USBVersion", &BUSBDevice::USBVersion, "") +.def("Class", &BUSBDevice::Class, "") +.def("Subclass", &BUSBDevice::Subclass, "") +.def("Protocol", &BUSBDevice::Protocol, "") +.def("MaxEndpoint0PacketSize", &BUSBDevice::MaxEndpoint0PacketSize, "") +.def("VendorID", &BUSBDevice::VendorID, "") +.def("ProductID", &BUSBDevice::ProductID, "") +.def("Version", &BUSBDevice::Version, "") +.def("ManufacturerString", &BUSBDevice::ManufacturerString, "") +.def("ProductString", &BUSBDevice::ProductString, "") +.def("SerialNumberString", &BUSBDevice::SerialNumberString, "") +.def("Descriptor", &BUSBDevice::Descriptor, "") +.def("GetStringDescriptor", &BUSBDevice::GetStringDescriptor, "", py::arg("index"), py::arg("descriptor"), py::arg("length")) +.def("DecodeStringDescriptor", &BUSBDevice::DecodeStringDescriptor, "", py::arg("index")) +.def("GetDescriptor", &BUSBDevice::GetDescriptor, "", py::arg("type"), py::arg("index"), py::arg("languageID"), py::arg("data"), py::arg("length")) +.def("CountConfigurations", &BUSBDevice::CountConfigurations, "") +.def("ConfigurationAt", &BUSBDevice::ConfigurationAt, "", py::arg("index")) +.def("ActiveConfiguration", &BUSBDevice::ActiveConfiguration, "") +.def("SetConfiguration", &BUSBDevice::SetConfiguration, "", py::arg("configuration")) +.def("ControlTransfer", &BUSBDevice::ControlTransfer, "", py::arg("requestType"), py::arg("request"), py::arg("value"), py::arg("index"), py::arg("length"), py::arg("data")) +; + +py::class_>(m, "BUSBConfiguration") +.def("Index", &BUSBConfiguration::Index, "") +.def("Device", &BUSBConfiguration::Device, "") +.def("ConfigurationString", &BUSBConfiguration::ConfigurationString, "") +.def("Descriptor", &BUSBConfiguration::Descriptor, "") +.def("CountInterfaces", &BUSBConfiguration::CountInterfaces, "") +.def("InterfaceAt", &BUSBConfiguration::InterfaceAt, "", py::arg("index")) +; + +py::class_>(m, "BUSBInterface") +.def("Index", &BUSBInterface::Index, "") +.def("AlternateIndex", &BUSBInterface::AlternateIndex, "") +.def("Configuration", &BUSBInterface::Configuration, py::return_value_policy::reference) +.def("Device", &BUSBInterface::Device, py::return_value_policy::reference) +.def("Class", &BUSBInterface::Class, "") +.def("Subclass", &BUSBInterface::Subclass, "") +.def("Protocol", &BUSBInterface::Protocol, "") +.def("InterfaceString", &BUSBInterface::InterfaceString, "") +.def("Descriptor", &BUSBInterface::Descriptor, "") +.def("OtherDescriptorAt", &BUSBInterface::OtherDescriptorAt, "", py::arg("index"), py::arg("descriptor"), py::arg("length")) +.def("CountEndpoints", &BUSBInterface::CountEndpoints, "") +.def("EndpointAt", &BUSBInterface::EndpointAt, "", py::arg("index")) +.def("CountAlternates", &BUSBInterface::CountAlternates, "") +.def("ActiveAlternateIndex", &BUSBInterface::ActiveAlternateIndex, "") +.def("AlternateAt", &BUSBInterface::AlternateAt, "", py::arg("alternateIndex")) +.def("SetAlternate", &BUSBInterface::SetAlternate, "", py::arg("alternateIndex")) +; + +py::class_>(m, "BUSBEndpoint") +.def("Index", &BUSBEndpoint::Index, "") +.def("Interface", &BUSBEndpoint::Interface, "") +.def("Configuration", &BUSBEndpoint::Configuration, "") +.def("Device", &BUSBEndpoint::Device, "") +.def("IsBulk", &BUSBEndpoint::IsBulk, "") +.def("IsInterrupt", &BUSBEndpoint::IsInterrupt, "") +.def("IsIsochronous", &BUSBEndpoint::IsIsochronous, "") +.def("IsControl", &BUSBEndpoint::IsControl, "") +.def("IsInput", &BUSBEndpoint::IsInput, "") +.def("IsOutput", &BUSBEndpoint::IsOutput, "") +.def("MaxPacketSize", &BUSBEndpoint::MaxPacketSize, "") +.def("Interval", &BUSBEndpoint::Interval, "") +.def("Descriptor", &BUSBEndpoint::Descriptor, "") +.def("ControlTransfer", &BUSBEndpoint::ControlTransfer, "", py::arg("requestType"), py::arg("request"), py::arg("value"), py::arg("index"), py::arg("length"), py::arg("data")) +.def("InterruptTransfer", &BUSBEndpoint::InterruptTransfer, "", py::arg("data"), py::arg("length")) +.def("BulkTransfer", &BUSBEndpoint::BulkTransfer, "", py::arg("data"), py::arg("length")) +.def("IsochronousTransfer", &BUSBEndpoint::IsochronousTransfer, "", py::arg("data"), py::arg("length"), py::arg("packetDescriptors"), py::arg("packetCount")) +.def("IsStalled", &BUSBEndpoint::IsStalled, "") +.def("ClearStall", &BUSBEndpoint::ClearStall, "") +; + +} diff --git a/bindings/drivers/bios.cpp b/bindings/drivers/bios.cpp new file mode 100644 index 0000000..6fe8d61 --- /dev/null +++ b/bindings/drivers/bios.cpp @@ -0,0 +1,89 @@ +#include +#include +#include +#include + +#include // Per supportare std::function +#include + +namespace py = pybind11; + +//struct bios_state; +//struct bios_regs; + +// Wrapping class + +class BiosModuleInfo { +public: + struct bios_module_info info; + + //std::function prepare; + std::function interrupt; + std::function finish; + + std::function allocate_mem; + std::function physical_address; + std::function virtual_address; + + BiosModuleInfo() { + // Initialize function pointers with null callbacks by default. + /*info.prepare = [this](bios_state** _state) -> status_t { + return this->prepare(_state); + };*/ + info.interrupt = [this](bios_state* state, uint8 vector, bios_regs* regs) -> status_t { + return this->interrupt(state, vector, regs); + }; + info.finish = [this](bios_state* state) { + this->finish(state); + }; + info.allocate_mem = [this](bios_state* state, size_t size) -> void* { + return this->allocate_mem(state, size); + }; + info.physical_address = [this](bios_state* state, void* virtualAddress) -> uint32 { + return this->physical_address(state, virtualAddress); + }; + info.virtual_address = [this](bios_state* state, uint32 physicalAddress) -> void* { + return this->virtual_address(state, physicalAddress); + }; + } +}; + + +PYBIND11_MODULE(bios, m) +{ +py::class_(m, "bios_regs") +.def_readwrite("eax", &bios_regs::eax, "") +.def_readwrite("ebx", &bios_regs::ebx, "") +.def_readwrite("ecx", &bios_regs::ecx, "") +.def_readwrite("edx", &bios_regs::edx, "") +.def_readwrite("edi", &bios_regs::edi, "") +.def_readwrite("esi", &bios_regs::esi, "") +.def_readwrite("ebp", &bios_regs::ebp, "") +.def_readwrite("eflags", &bios_regs::eflags, "") +.def_readwrite("ds", &bios_regs::ds, "") +.def_readwrite("es", &bios_regs::es, "") +.def_readwrite("fs", &bios_regs::fs, "") +.def_readwrite("gs", &bios_regs::gs, "") +; + +py::class_(m, "bios_module_info") +/* +.def_readwrite("info", &bios_module_info::info, "") +//.def_readwrite("prepare", &bios_module_info::prepare, "") +//.def_readwrite("interrupt", &bios_module_info::interrupt, "") +.def_readwrite("finish", &bios_module_info::finish, "") +.def_readwrite("allocate_mem", &bios_module_info::allocate_mem, "") +.def_readwrite("physical_address", &bios_module_info::physical_address, "") +.def_readwrite("virtual_address", &bios_module_info::virtual_address, "")*/ +; + +.def(py::init<>()) +//.def_readonly("prepare", &BiosModuleInfo::prepare) +.def_readonly("interrupt", &BiosModuleInfo::interrupt) +.def_readonly("finish", &BiosModuleInfo::finish) +.def_readonly("allocate_mem", &BiosModuleInfo::allocate_mem) +.def_readonly("physical_address", &BiosModuleInfo::physical_address) +.def_readonly("virtual_address", &BiosModuleInfo::virtual_address); +; + +} diff --git a/bindings/drivers/bus_manager.cpp b/bindings/drivers/bus_manager.cpp new file mode 100644 index 0000000..78dc0fd --- /dev/null +++ b/bindings/drivers/bus_manager.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +#include // Per std::function +#include + +namespace py = pybind11; +/* +PYBIND11_MODULE(bus_manager, m) +{ +py::class_(m, "bus_manager_info") +.def_readwrite("minfo", &bus_manager_info::minfo, "") +.def_readwrite("rescan", &bus_manager_info::rescan, "") +; + + +} +*/ + + +// Binding con pybind11 +PYBIND11_MODULE(bus_manager, m) +{ +py::class_(m, "BusManagerInfo") + .def(py::init<>()) + .def_readwrite("minfo", &bus_manager_info::minfo, "") + //.def_readwrite("rescan", &bus_manager_info::rescan) + .def("rescan", [](bus_manager_info& self) { + if (self.rescan) { + return self.rescan(); + } + return static_cast(-1); // Errore se rescan non è impostato + }) +; +} diff --git a/bindings/drivers/module.cpp b/bindings/drivers/module.cpp new file mode 100644 index 0000000..64bc82b --- /dev/null +++ b/bindings/drivers/module.cpp @@ -0,0 +1,187 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +/* +py::object get_module_wrapper(const std::string& path) { + module_info* info = nullptr; + status_t status = get_module(path.c_str(), &info); + + // Crea una lista di module_info da info, se necessario + std::vector info_vector; + if (info) { + // Supponiamo che info sia una lista terminata da nullptr + while (*info) { + info_vector.push_back(*info); + ++info; + } + } + + // Ritorna un tuple (status, info_vector) + return py::make_tuple(status, info_vector); +}*/ +/* +std::tuple> get_module_wrapper(const std::string& path) { + // Alloca un puntatore a module_info + module_info* info = nullptr; + + // Chiama la funzione C + status_t status = get_module(path.c_str(), &info); + + // Crea un vettore per contenere i module_info + std::vector info_vector; + + if (status == B_OK && info != nullptr) { + // Itera attraverso l'array di module_info + // Supponiamo che l'array di module_info termini con un nullptr + module_info* current = info; + while (*current != nullptr) { + info_vector.push_back(*current); + ++current; + } + } else { + throw std::runtime_error("Failed to get module."); + } + + // Ritorna il tuple (status, info_vector) + return std::make_tuple(status, info_vector); +}*/ +#include +#include +#include +std::tuple> get_module_wrapper(const std::string& path) { + // Alloca un puntatore a array di puntatori a module_info + module_info* info = nullptr; + + // Chiama la funzione C + status_t status = get_module(path.c_str(), &info); + + // Crea un vettore per contenere i module_info + std::vector info_vector; + + if (status == B_OK && info != nullptr) { + // Itera attraverso l'array di puntatori a module_info + module_info* current = info; + while (current != nullptr) { + info_vector.push_back(*current); // Aggiunge una copia di module_info al vettore + ++current; + } + } else { + throw std::runtime_error("Failed to get module."); + } + + // Ritorna il tuple (status, info_vector) + return std::make_tuple(status, info_vector); +} + +/*status_t call_std_ops(module_info* info, int32_t operation, const std::vector& args) { + if (info == nullptr || info->std_ops == nullptr) { + return -1; // Ritorna un codice di errore o un valore di default + } + + // Preparazione dei variadic arguments + va_list ap; + va_start(ap, operation); + for (int arg : args) { + va_arg(ap, int) = arg; + } + va_end(ap); + + // Chiama la funzione std_ops + return info->std_ops(operation, ap); +}*/ +#include +/*template +status_t call_with_tuple(module_info* info, int32_t operation, Tuple&& args, std::index_sequence) { + return info->std_ops(operation, std::get(args)...); +} +status_t call_std_ops(module_info* info, int32_t operation, py::args args) { + if (info == nullptr || info->std_ops == nullptr) { + return -1; // Codice di errore o valore di default + } + + // Convert args to a tuple of integers + auto args_tuple = std::make_tuple(args.cast()...); + + // Call the function using the tuple and apply + return call_with_tuple(info, operation, args_tuple, std::make_index_sequence()); +}*/ +template +status_t call_with_tuple(module_info* info, int32_t operation, Tuple&& args, std::index_sequence) { + return info->std_ops(operation, std::get(args)...); +} + +status_t call_std_ops(module_info* info, int32_t operation, py::args args) { + if (info == nullptr || info->std_ops == nullptr) { + return -1; // Codice di errore o valore di default + } + + // Convert py::args to a tuple of integers + auto args_tuple = std::apply([](auto&&... elems) { + return std::make_tuple(elems.cast()...); + }, args); + + // Call the function using the tuple and apply + return std::apply([&](auto&&... unpackedArgs) { + return info->std_ops(operation, unpackedArgs...); + }, args_tuple); +} + +PYBIND11_MODULE(module, m) +{ +py::class_(m, "module_info") +.def_readwrite("name", &module_info::name, "") +.def_readwrite("flags", &module_info::flags, "") +//.def_readwrite("std_ops", &module_info::std_ops, "") + +.def("call_std_ops", &call_std_ops, "Call the std_ops function", py::arg("info"), py::arg("operation"), py::arg("args")); +; + +py::class_(m, "module_dependency") +.def_readwrite("name", &module_dependency::name, "") +//.def_readwrite("info", &module_dependency::info, "") +.def("get_info", [](const module_dependency &self) { + std::vector info_vector; + if (self.info) { + // Converti l'array di puntatori a module_info in un vettore di module_info* + // Supponiamo che il numero di elementi sia conosciuto e sia 'count' + for (int i = 0; self.info[i] != nullptr; ++i) { + info_vector.push_back(self.info[i]); + } + } + return info_vector; + }) +.def("set_info", [](module_dependency &self, const std::vector &info_vector) { + // Funzione per impostare l'array di module_info* dalla lista Python + self.info = new module_info*[info_vector.size() + 1]; // +1 per il terminatore nullptr + for (size_t i = 0; i < info_vector.size(); ++i) { + self.info[i] = info_vector[i]; + } + self.info[info_vector.size()] = nullptr; // Terminatore nullptr + }); + +; + +//m.def("get_module", &get_module, "", py::arg("path"), py::arg("_info")); +//nell'heaader status_t get_module(const char *path, module_info **_info); +//m.def("get_module", [](const char *path, module_info **_info){}, "", py::arg("path"), py::arg("_info")); +m.def("get_module", &get_module_wrapper, "", py::arg("path")); + +m.def("put_module", &put_module, "", py::arg("path")); + +m.def("get_next_loaded_module_name", &get_next_loaded_module_name, "", py::arg("cookie"), py::arg("buffer"), py::arg("_bufferSize")); + +m.def("open_module_list_etc", &open_module_list_etc, "", py::arg("prefix"), py::arg("suffix")); + +m.def("open_module_list", &open_module_list, "", py::arg("prefix")); + +m.def("close_module_list", &close_module_list, "", py::arg("cookie")); + +m.def("read_next_module_name", &read_next_module_name, "", py::arg("cookie"), py::arg("buffer"), py::arg("_bufferSize")); + +} diff --git a/bindings/kernel/OS.cpp b/bindings/kernel/OS.cpp new file mode 100644 index 0000000..b4cad2e --- /dev/null +++ b/bindings/kernel/OS.cpp @@ -0,0 +1,569 @@ +#include +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +unsigned long real_time_clock_wrapper() { + return real_time_clock(); +} + +bigtime_t real_time_clock_usecs_wrapper(){ + return real_time_clock_usecs(); +} + +bigtime_t system_time_wrapper(){ + return system_time(); +} + +nanotime_t system_time_nsecs_wrapper(){ + return system_time_nsecs(); +} + +int32 is_computer_on_wrapper(){ + return is_computer_on(); +} + +double is_computer_on_fire_wrapper(){ + return is_computer_on_fire(); +} + +std::string get_area_info_name(const area_info& self) { + return std::string(self.name); +} + +void set_area_info_name(area_info& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), B_OS_NAME_LENGTH - 1); + self.name[B_OS_NAME_LENGTH - 1] = '\0'; +} +// +std::string get_port_info_name(const port_info& self) { + return std::string(self.name); +} + +void set_port_info_name(port_info& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), B_OS_NAME_LENGTH - 1); + self.name[B_OS_NAME_LENGTH - 1] = '\0'; +} +// +std::string get_sem_info_name(const sem_info& self) { + return std::string(self.name); +} + +void set_sem_info_name(sem_info& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), B_OS_NAME_LENGTH - 1); + self.name[B_OS_NAME_LENGTH - 1] = '\0'; +} +// +std::string get_team_info_args(const team_info& self) { + return std::string(self.args); +} + +void set_team_info_args(team_info& self, const std::string& args) { + std::strncpy(self.args, args.c_str(), 64 - 1); + self.args[64 - 1] = '\0'; +} + +area_id create_area_wrapper(const std::string &name, py::capsule &startAddress, + uint32_t addressSpec, size_t size, uint32_t lock, + uint32_t protection) { + void *startAddressPtr = startAddress; // Converte il py::capsule in void* + return create_area(name.c_str(), &startAddressPtr, addressSpec, size, lock, protection); +} +area_id clone_area_wrapper(const std::string &name, py::capsule &destAddress, + uint32_t addressSpec, uint32_t protection, + area_id source) { + void *destAddressPtr = destAddress.get_pointer(); // Converte il py::capsule in void* + return clone_area(name.c_str(), &destAddressPtr, addressSpec, protection, source); +} +PYBIND11_MODULE(OS,m) +{ +/*m.attr("B_TIMEOUT") = py::cast(B_TIMEOUT); +m.attr("B_RELATIVE_TIMEOUT") = py::cast(B_RELATIVE_TIMEOUT); +m.attr("B_ABSOLUTE_TIMEOUT") = py::cast(B_ABSOLUTE_TIMEOUT); +m.attr("B_TIMEOUT_REAL_TIME_BASE") = py::cast(B_TIMEOUT_REAL_TIME_BASE); +m.attr("B_ABSOLUTE_REAL_TIME_TIMEOUT") = py::cast(B_ABSOLUTE_REAL_TIME_TIMEOUT);*/ +m.attr("B_TIMEOUT") = 0x8; +m.attr("B_RELATIVE_TIMEOUT") = 0x8; +m.attr("B_ABSOLUTE_TIMEOUT") = 0x10; +m.attr("B_TIMEOUT_REAL_TIME_BASE") = 0x40; +m.attr("B_ABSOLUTE_REAL_TIME_TIMEOUT") = 0x10|0x40; +/* +m.attr("B_CAN_INTERRUPT") = py::cast(B_CAN_INTERRUPT); +m.attr("B_CHECK_PERMISSION") = py::cast(B_CHECK_PERMISSION); +m.attr("B_KILL_CAN_INTERRUPT") = py::cast(B_KILL_CAN_INTERRUPT); +m.attr("B_DO_NOT_RESCHEDULE") = py::cast(B_DO_NOT_RESCHEDULE); +m.attr("B_RELEASE_ALL") = py::cast(B_RELEASE_ALL); +m.attr("B_RELEASE_IF_WAITING_ONLY") = py::cast(B_RELEASE_IF_WAITING_ONLY);*/ +m.attr("B_CAN_INTERRUPT") = 0x01; +m.attr("B_CHECK_PERMISSION") = 0x04; +m.attr("B_KILL_CAN_INTERRUPT") = 0x20; +m.attr("B_DO_NOT_RESCHEDULE") = 0x02; +m.attr("B_RELEASE_ALL") = 0x08; +m.attr("B_RELEASE_IF_WAITING_ONLY") = 0x10; + +/*m.attr("B_TEAM_USAGE_SELF") = py::cast(B_TEAM_USAGE_SELF); +m.attr("B_TEAM_USAGE_CHILDREN") = py::cast(B_TEAM_USAGE_CHILDREN);*/ +m.attr("B_TEAM_USAGE_SELF") = 0; +m.attr("B_TEAM_USAGE_CHILDREN") = -1; + +py::enum_(m, "thread_state", "") +.value("B_THREAD_RUNNING", thread_state::B_THREAD_RUNNING, "") +.value("B_THREAD_READY", thread_state::B_THREAD_READY, "") +.value("B_THREAD_RECEIVING", thread_state::B_THREAD_RECEIVING, "") +.value("B_THREAD_ASLEEP", thread_state::B_THREAD_ASLEEP, "") +.value("B_THREAD_SUSPENDED", thread_state::B_THREAD_SUSPENDED, "") +.value("B_THREAD_WAITING", thread_state::B_THREAD_WAITING, "") +.export_values(); +/* +m.attr("B_ONE_SHOT_ABSOLUTE_ALARM") = py::cast(B_ONE_SHOT_ABSOLUTE_ALARM); +m.attr("B_ONE_SHOT_RELATIVE_ALARM") = py::cast(B_ONE_SHOT_RELATIVE_ALARM); +m.attr("B_PERIODIC_ALARM") = py::cast(B_PERIODIC_ALARM);*/ +m.attr("B_ONE_SHOT_ABSOLUTE_ALARM") = 1; +m.attr("B_ONE_SHOT_RELATIVE_ALARM") = 2; +m.attr("B_PERIODIC_ALARM") = 3; + +py::enum_(m, "topology_level_type", "") +.value("B_TOPOLOGY_UNKNOWN", topology_level_type::B_TOPOLOGY_UNKNOWN, "") +.value("B_TOPOLOGY_ROOT", topology_level_type::B_TOPOLOGY_ROOT, "") +.value("B_TOPOLOGY_SMT", topology_level_type::B_TOPOLOGY_SMT, "") +.value("B_TOPOLOGY_CORE", topology_level_type::B_TOPOLOGY_CORE, "") +.value("B_TOPOLOGY_PACKAGE", topology_level_type::B_TOPOLOGY_PACKAGE, "") +.export_values(); + +py::enum_(m, "cpu_platform", "") +.value("B_CPU_UNKNOWN", cpu_platform::B_CPU_UNKNOWN, "") +.value("B_CPU_x86", cpu_platform::B_CPU_x86, "") +.value("B_CPU_x86_64", cpu_platform::B_CPU_x86_64, "") +.value("B_CPU_PPC", cpu_platform::B_CPU_PPC, "") +.value("B_CPU_PPC_64", cpu_platform::B_CPU_PPC_64, "") +.value("B_CPU_M68K", cpu_platform::B_CPU_M68K, "") +.value("B_CPU_ARM", cpu_platform::B_CPU_ARM, "") +.value("B_CPU_ARM_64", cpu_platform::B_CPU_ARM_64, "") +.value("B_CPU_ALPHA", cpu_platform::B_CPU_ALPHA, "") +.value("B_CPU_MIPS", cpu_platform::B_CPU_MIPS, "") +.value("B_CPU_SH", cpu_platform::B_CPU_SH, "") +.value("B_CPU_SPARC", cpu_platform::B_CPU_SPARC, "") +.value("B_CPU_RISC_V", cpu_platform::B_CPU_RISC_V, "") +.export_values(); + +py::enum_(m, "cpu_vendor", "") +.value("B_CPU_VENDOR_UNKNOWN", cpu_vendor::B_CPU_VENDOR_UNKNOWN, "") +.value("B_CPU_VENDOR_AMD", cpu_vendor::B_CPU_VENDOR_AMD, "") +.value("B_CPU_VENDOR_CYRIX", cpu_vendor::B_CPU_VENDOR_CYRIX, "") +.value("B_CPU_VENDOR_IDT", cpu_vendor::B_CPU_VENDOR_IDT, "") +.value("B_CPU_VENDOR_INTEL", cpu_vendor::B_CPU_VENDOR_INTEL, "") +.value("B_CPU_VENDOR_NATIONAL_SEMICONDUCTOR", cpu_vendor::B_CPU_VENDOR_NATIONAL_SEMICONDUCTOR, "") +.value("B_CPU_VENDOR_RISE", cpu_vendor::B_CPU_VENDOR_RISE, "") +.value("B_CPU_VENDOR_TRANSMETA", cpu_vendor::B_CPU_VENDOR_TRANSMETA, "") +.value("B_CPU_VENDOR_VIA", cpu_vendor::B_CPU_VENDOR_VIA, "") +.value("B_CPU_VENDOR_IBM", cpu_vendor::B_CPU_VENDOR_IBM, "") +.value("B_CPU_VENDOR_MOTOROLA", cpu_vendor::B_CPU_VENDOR_MOTOROLA, "") +.value("B_CPU_VENDOR_NEC", cpu_vendor::B_CPU_VENDOR_NEC, "") +.value("B_CPU_VENDOR_HYGON", cpu_vendor::B_CPU_VENDOR_HYGON, "") +.value("B_CPU_VENDOR_SUN", cpu_vendor::B_CPU_VENDOR_SUN, "") +.value("B_CPU_VENDOR_FUJITSU", cpu_vendor::B_CPU_VENDOR_FUJITSU, "") +.export_values(); +/* +m.attr("B_OBJECT_TYPE_FD") = py::cast(B_OBJECT_TYPE_FD); +m.attr("B_OBJECT_TYPE_SEMAPHORE") = py::cast(B_OBJECT_TYPE_SEMAPHORE); +m.attr("B_OBJECT_TYPE_PORT") = py::cast(B_OBJECT_TYPE_PORT); +m.attr("B_OBJECT_TYPE_THREAD") = py::cast(B_OBJECT_TYPE_THREAD);*/ +m.attr("B_OBJECT_TYPE_FD") = 0; +m.attr("B_OBJECT_TYPE_SEMAPHORE") = 1; +m.attr("B_OBJECT_TYPE_PORT") = 2; +m.attr("B_OBJECT_TYPE_THREAD") = 3; + +/* +m.attr("B_EVENT_READ") = py::cast(B_EVENT_READ); +m.attr("B_EVENT_WRITE") = py::cast(B_EVENT_WRITE); +m.attr("B_EVENT_ERROR") = py::cast(B_EVENT_ERROR); +m.attr("B_EVENT_PRIORITY_READ") = py::cast(B_EVENT_PRIORITY_READ); +m.attr("B_EVENT_PRIORITY_WRITE") = py::cast(B_EVENT_PRIORITY_WRITE); +m.attr("B_EVENT_HIGH_PRIORITY_READ") = py::cast(B_EVENT_HIGH_PRIORITY_READ); +m.attr("B_EVENT_HIGH_PRIORITY_WRITE") = py::cast(B_EVENT_HIGH_PRIORITY_WRITE); +m.attr("B_EVENT_DISCONNECTED") = py::cast(B_EVENT_DISCONNECTED); +m.attr("B_EVENT_ACQUIRE_SEMAPHORE") = py::cast(B_EVENT_ACQUIRE_SEMAPHORE); +m.attr("B_EVENT_INVALID") = py::cast(B_EVENT_INVALID);*/ +m.attr("B_EVENT_READ") = 0x0001; +m.attr("B_EVENT_WRITE") = 0x0002; +m.attr("B_EVENT_ERROR") = 0x0004; +m.attr("B_EVENT_PRIORITY_READ") = 0x0008; +m.attr("B_EVENT_PRIORITY_WRITE") = 0x0010; +m.attr("B_EVENT_HIGH_PRIORITY_READ") = 0x0020; +m.attr("B_EVENT_HIGH_PRIORITY_WRITE") = 0x0040; +m.attr("B_EVENT_DISCONNECTED") = 0x0080; +m.attr("B_EVENT_ACQUIRE_SEMAPHORE") = 0x0001; +m.attr("B_EVENT_INVALID") = 0x1000; + + +py::class_(m, "area_info") +.def(py::init(), "") +.def_readwrite("area", &area_info::area, "") +//.def_readwrite("name", &area_info::name, "") +.def_property("name", &get_area_info_name, &set_area_info_name, "") +.def_readwrite("size", &area_info::size, "") +.def_readwrite("lock", &area_info::lock, "") +.def_readwrite("protection", &area_info::protection, "") +.def_readwrite("team", &area_info::team, "") +.def_readwrite("ram_size", &area_info::ram_size, "") +.def_readwrite("copy_count", &area_info::copy_count, "") +.def_readwrite("in_count", &area_info::in_count, "") +.def_readwrite("out_count", &area_info::out_count, "") +.def_readwrite("address", &area_info::address, "") +; + +py::class_(m, "port_info") +.def(py::init(), "") +.def_readwrite("port", &port_info::port, "") +.def_readwrite("team", &port_info::team, "") +//.def_readwrite("name", &port_info::name, "") +.def_property("name", &get_port_info_name, &set_port_info_name, "") +.def_readwrite("capacity", &port_info::capacity, "") +.def_readwrite("queue_count", &port_info::queue_count, "") +.def_readwrite("total_count", &port_info::total_count, "") +; + +py::class_(m, "port_message_info") +.def(py::init(), "") +.def_readwrite("size", &port_message_info::size, "") +.def_readwrite("sender", &port_message_info::sender, "") +.def_readwrite("sender_group", &port_message_info::sender_group, "") +.def_readwrite("sender_team", &port_message_info::sender_team, "") +; + +py::class_(m, "sem_info") +.def(py::init(), "") +.def_readwrite("sem", &sem_info::sem, "") +.def_readwrite("team", &sem_info::team, "") +//.def_readwrite("name", &sem_info::name, "") +.def_property("name", &get_sem_info_name, &set_sem_info_name, "") +.def_readwrite("count", &sem_info::count, "") +.def_readwrite("latest_holder", &sem_info::latest_holder, "") +; + +py::class_(m, "team_info") +.def(py::init(), "") +.def_readwrite("team", &team_info::team, "") +.def_readwrite("thread_count", &team_info::thread_count, "") +.def_readwrite("image_count", &team_info::image_count, "") +.def_readwrite("area_count", &team_info::area_count, "") +.def_readwrite("debugger_nub_thread", &team_info::debugger_nub_thread, "") +.def_readwrite("debugger_nub_port", &team_info::debugger_nub_port, "") +.def_readwrite("argc", &team_info::argc, "") +//.def_readwrite("args", &team_info::args, "") +.def_property("args", &get_team_info_args, &set_team_info_args, "") +.def_readwrite("uid", &team_info::uid, "") +.def_readwrite("gid", &team_info::gid, "") +; + +py::class_(m, "team_usage_info") +.def(py::init(), "") +.def_readwrite("user_time", &team_usage_info::user_time, "") +.def_readwrite("kernel_time", &team_usage_info::kernel_time, "") +; + +py::class_(m, "thread_info") +.def(py::init(), "") +.def_readwrite("thread", &thread_info::thread, "") +.def_readwrite("team", &thread_info::team, "") +.def_readonly("name", &thread_info::name, "") +.def_readwrite("state", &thread_info::state, "") +.def_readwrite("priority", &thread_info::priority, "") +.def_readwrite("sem", &thread_info::sem, "") +.def_readwrite("user_time", &thread_info::user_time, "") +.def_readwrite("kernel_time", &thread_info::kernel_time, "") +.def_readwrite("stack_base", &thread_info::stack_base, "") +.def_readwrite("stack_end", &thread_info::stack_end, "") +; + +py::class_(m, "cpu_info") +.def(py::init(), "") +.def_readwrite("active_time", &cpu_info::active_time, "") +.def_readwrite("enabled", &cpu_info::enabled, "") +.def_readwrite("current_frequency", &cpu_info::current_frequency, "") +; + +py::class_(m, "system_info") +.def(py::init(), "") +.def_readwrite("boot_time", &system_info::boot_time, "") +.def_readwrite("cpu_count", &system_info::cpu_count, "") +.def_readwrite("max_pages", &system_info::max_pages, "") +.def_readwrite("used_pages", &system_info::used_pages, "") +.def_readwrite("cached_pages", &system_info::cached_pages, "") +.def_readwrite("block_cache_pages", &system_info::block_cache_pages, "") +.def_readwrite("ignored_pages", &system_info::ignored_pages, "") +.def_readwrite("needed_memory", &system_info::needed_memory, "") +.def_readwrite("free_memory", &system_info::free_memory, "") +.def_readwrite("max_swap_pages", &system_info::max_swap_pages, "") +.def_readwrite("free_swap_pages", &system_info::free_swap_pages, "") +.def_readwrite("page_faults", &system_info::page_faults, "") +.def_readwrite("max_sems", &system_info::max_sems, "") +.def_readwrite("used_sems", &system_info::used_sems, "") +.def_readwrite("max_ports", &system_info::max_ports, "") +.def_readwrite("used_ports", &system_info::used_ports, "") +.def_readwrite("max_threads", &system_info::max_threads, "") +.def_readwrite("used_threads", &system_info::used_threads, "") +.def_readwrite("max_teams", &system_info::max_teams, "") +.def_readwrite("used_teams", &system_info::used_teams, "") +.def_readonly("kernel_name", &system_info::kernel_name, "") +.def_readonly("kernel_build_date", &system_info::kernel_build_date, "") +.def_readonly("kernel_build_time", &system_info::kernel_build_time, "") +.def_readwrite("kernel_version", &system_info::kernel_version, "") +.def_readwrite("abi", &system_info::abi, "") +; + +py::class_(m, "cpu_topology_root_info") +.def(py::init(), "") +.def_readwrite("platform", &cpu_topology_root_info::platform, "") +; + +py::class_(m, "cpu_topology_package_info") +.def(py::init(), "") +.def_readwrite("vendor", &cpu_topology_package_info::vendor, "") +.def_readwrite("cache_line_size", &cpu_topology_package_info::cache_line_size, "") +; + +py::class_(m, "cpu_topology_core_info") +.def(py::init(), "") +.def_readwrite("model", &cpu_topology_core_info::model, "") +.def_readwrite("default_frequency", &cpu_topology_core_info::default_frequency, "") +; +/* +py::class_(m, "union ") +.def_readwrite("root", &union ::root, "") +.def_readwrite("package", &union ::package, "") +.def_readwrite("core", &union ::core, "") +; +*/ +py::class_(m, "cpu_topology_node_info") +.def(py::init(), "") +.def_readwrite("id", &cpu_topology_node_info::id, "") +.def_readwrite("type", &cpu_topology_node_info::type, "") +.def_readwrite("level", &cpu_topology_node_info::level, "") +//.def_readwrite("data", &cpu_topology_node_info::data, "") +.def("get_root", [](cpu_topology_node_info& self) -> cpu_topology_root_info& { + return self.data.root; + }, py::return_value_policy::reference) +.def("get_package", [](cpu_topology_node_info& self) -> cpu_topology_package_info& { + return self.data.package; + }, py::return_value_policy::reference) +.def("get_core", [](cpu_topology_node_info& self) -> cpu_topology_core_info& { + return self.data.core; + }, py::return_value_policy::reference); +; +/* +py::class_<>(m, "") +.def_readwrite("eax", &::eax, "") +.def_readwrite("ebx", &::ebx, "") +.def_readwrite("edx", &::edx, "") +.def_readwrite("ecx", &::ecx, "") +;*/ + +py::class_(m, "cpuid_info") +.def(py::init(), "") +.def_readwrite("eax_0", &cpuid_info::eax_0, "") +.def_readwrite("eax_1", &cpuid_info::eax_1, "") +.def_readwrite("eax_2", &cpuid_info::eax_2, "") +.def_readwrite("eax_3", &cpuid_info::eax_3, "") +.def_readonly("as_chars", &cpuid_info::as_chars, "") +//def property readonly? +.def("get_reg_eax",[](cpuid_info& self) -> uint32 { + return self.regs.eax; +}, py::return_value_policy::reference) +.def("get_reg_ebx",[](cpuid_info& self) -> uint32 { + return self.regs.ebx; +}, py::return_value_policy::reference) +.def("get_reg_edx",[](cpuid_info& self) -> uint32 { + return self.regs.edx; +}, py::return_value_policy::reference) +.def("get_reg_ecx",[](cpuid_info& self) -> uint32 { + return self.regs.ecx; +}, py::return_value_policy::reference) +//.def_readwrite("regs", &cpuid_info::regs, "") +; + +py::class_(m, "object_wait_info") +.def(py::init(), "") +.def_readwrite("object", &object_wait_info::object, "") +.def_readwrite("type", &object_wait_info::type, "") +.def_readwrite("events", &object_wait_info::events, "") +; + +//m.def("create_area", &create_area, "", py::arg("name"), py::arg("startAddress"), py::arg("addressSpec"), py::arg("size"), py::arg("lock"), py::arg("protection")); +m.def("create_area", &create_area_wrapper, "", py::arg("name"), py::arg("startAddress"), py::arg("addressSpec"), py::arg("size"), py::arg("lock"), py::arg("protection")); //in python declare "start_address = None" + +//m.def("clone_area", &clone_area, "", py::arg("name"), py::arg("destAddress"), py::arg("addressSpec"), py::arg("protection"), py::arg("source")); +m.def("clone_area", &clone_area_wrapper, "", py::arg("name"), py::arg("destAddress"), py::arg("addressSpec"), py::arg("protection"), py::arg("source")); + +m.def("find_area", &find_area, "", py::arg("name")); + +m.def("area_for", &area_for, "", py::arg("address")); + +m.def("delete_area", &delete_area, "", py::arg("id")); + +m.def("resize_area", &resize_area, "", py::arg("id"), py::arg("newSize")); + +m.def("set_area_protection", &set_area_protection, "", py::arg("id"), py::arg("newProtection")); + +m.def("_get_area_info", &_get_area_info, "", py::arg("id"), py::arg("areaInfo"), py::arg("size")); + +m.def("_get_next_area_info", &_get_next_area_info, "", py::arg("team"), py::arg("cookie"), py::arg("areaInfo"), py::arg("size")); + +m.def("create_port", &create_port, "", py::arg("capacity"), py::arg("name")); + +m.def("find_port", &find_port, "", py::arg("name")); + +m.def("read_port", &read_port, "", py::arg("port"), py::arg("code"), py::arg("buffer"), py::arg("bufferSize")); + +m.def("read_port_etc", &read_port_etc, "", py::arg("port"), py::arg("code"), py::arg("buffer"), py::arg("bufferSize"), py::arg("flags"), py::arg("timeout")); + +m.def("write_port", &write_port, "", py::arg("port"), py::arg("code"), py::arg("buffer"), py::arg("bufferSize")); + +m.def("write_port_etc", &write_port_etc, "", py::arg("port"), py::arg("code"), py::arg("buffer"), py::arg("bufferSize"), py::arg("flags"), py::arg("timeout")); + +m.def("close_port", &close_port, "", py::arg("port")); + +m.def("delete_port", &delete_port, "", py::arg("port")); + +m.def("port_buffer_size", &port_buffer_size, "", py::arg("port")); + +m.def("port_buffer_size_etc", &port_buffer_size_etc, "", py::arg("port"), py::arg("flags"), py::arg("timeout")); + +m.def("port_count", &port_count, "", py::arg("port")); + +m.def("set_port_owner", &set_port_owner, "", py::arg("port"), py::arg("team")); + +m.def("_get_port_info", &_get_port_info, "", py::arg("port"), py::arg("portInfo"), py::arg("portInfoSize")); + +m.def("_get_next_port_info", &_get_next_port_info, "", py::arg("team"), py::arg("cookie"), py::arg("portInfo"), py::arg("portInfoSize")); + +m.def("_get_port_message_info_etc", &_get_port_message_info_etc, "", py::arg("port"), py::arg("info"), py::arg("infoSize"), py::arg("flags"), py::arg("timeout")); + +m.def("create_sem", &create_sem, "", py::arg("count"), py::arg("name")); + +m.def("delete_sem", &delete_sem, "", py::arg("id")); + +m.def("acquire_sem", &acquire_sem, "", py::arg("id")); + +m.def("acquire_sem_etc", &acquire_sem_etc, "", py::arg("id"), py::arg("count"), py::arg("flags"), py::arg("timeout")); + +m.def("release_sem", &release_sem, "", py::arg("id")); + +m.def("release_sem_etc", &release_sem_etc, "", py::arg("id"), py::arg("count"), py::arg("flags")); + +m.def("switch_sem", &switch_sem, "", py::arg("semToBeReleased"), py::arg("id")); + +m.def("switch_sem_etc", &switch_sem_etc, "", py::arg("semToBeReleased"), py::arg("id"), py::arg("count"), py::arg("flags"), py::arg("timeout")); + +m.def("get_sem_count", &get_sem_count, "", py::arg("id"), py::arg("threadCount")); + +m.def("set_sem_owner", &set_sem_owner, "", py::arg("id"), py::arg("team")); + +m.def("_get_sem_info", &_get_sem_info, "", py::arg("id"), py::arg("info"), py::arg("infoSize")); + +m.def("_get_next_sem_info", &_get_next_sem_info, "", py::arg("team"), py::arg("cookie"), py::arg("info"), py::arg("infoSize")); + +m.def("kill_team", &kill_team, "", py::arg("team")); + +m.def("_get_team_info", &_get_team_info, "", py::arg("id"), py::arg("info"), py::arg("size")); + +m.def("_get_next_team_info", &_get_next_team_info, "", py::arg("cookie"), py::arg("info"), py::arg("size")); + +m.def("_get_team_usage_info", &_get_team_usage_info, "", py::arg("team"), py::arg("who"), py::arg("info"), py::arg("size")); + +m.def("spawn_thread", &spawn_thread, "", py::arg(""), py::arg("name"), py::arg("priority"), py::arg("data")); + +m.def("kill_thread", &kill_thread, "", py::arg("thread")); + +m.def("resume_thread", &resume_thread, "", py::arg("thread")); + +m.def("suspend_thread", &suspend_thread, "", py::arg("thread")); + +m.def("rename_thread", &rename_thread, "", py::arg("thread"), py::arg("newName")); + +m.def("set_thread_priority", &set_thread_priority, "", py::arg("thread"), py::arg("newPriority")); + +m.def("exit_thread", &exit_thread, "", py::arg("status")); + +m.def("wait_for_thread", &wait_for_thread, "", py::arg("thread"), py::arg("returnValue")); + +m.def("wait_for_thread_etc", &wait_for_thread_etc, "", py::arg("id"), py::arg("flags"), py::arg("timeout"), py::arg("_returnCode")); + +m.def("on_exit_thread", &on_exit_thread, "", py::arg(""), py::arg("data")); + +m.def("find_thread", &find_thread, "", py::arg("name")); + +m.def("send_data", &send_data, "", py::arg("thread"), py::arg("code"), py::arg("buffer"), py::arg("bufferSize")); + +m.def("receive_data", &receive_data, "", py::arg("sender"), py::arg("buffer"), py::arg("bufferSize")); + +m.def("has_data", &has_data, "", py::arg("thread")); + +m.def("snooze", &snooze, "", py::arg("amount")); + +m.def("snooze_etc", &snooze_etc, "", py::arg("amount"), py::arg("timeBase"), py::arg("flags")); + +m.def("snooze_until", &snooze_until, "", py::arg("time"), py::arg("timeBase")); + +m.def("_get_thread_info", &_get_thread_info, "", py::arg("id"), py::arg("info"), py::arg("size")); + +m.def("_get_next_thread_info", &_get_next_thread_info, "", py::arg("team"), py::arg("cookie"), py::arg("info"), py::arg("size")); + +//m.def("get_pthread_thread_id", &get_pthread_thread_id, "", py::arg("thread")); + +//m.def("real_time_clock", &real_time_clock, "", py::arg("")); +m.def("real_time_clock", &real_time_clock_wrapper, ""); + +m.def("set_real_time_clock", &set_real_time_clock, "", py::arg("secsSinceJan1st1970")); + +//m.def("real_time_clock_usecs", &real_time_clock_usecs, "", py::arg("")); +m.def("real_time_clock_usecs", &real_time_clock_usecs_wrapper, ""); + +//m.def("system_time", &system_time, "", py::arg("")); +m.def("system_time", &system_time_wrapper, ""); + +//m.def("system_time_nsecs", &system_time_nsecs, "", py::arg("")); +m.def("system_time_nsecs", &system_time_nsecs_wrapper, ""); + +m.def("set_alarm", &set_alarm, "", py::arg("when"), py::arg("flags")); + +m.def("debugger", &debugger, "", py::arg("message")); + +m.def("disable_debugger", &disable_debugger, "", py::arg("state")); + +//m.def("debug_printf", &debug_printf, "", py::arg("format")); + +m.def("debug_vprintf", &debug_vprintf, "", py::arg("format"), py::arg("args")); + +//m.def("ktrace_printf", &ktrace_printf, "", py::arg("format")); + +m.def("ktrace_vprintf", &ktrace_vprintf, "", py::arg("format"), py::arg("args")); + +m.def("get_system_info", &get_system_info, "", py::arg("info")); + +m.def("_get_cpu_info_etc", &_get_cpu_info_etc, "", py::arg("firstCPU"), py::arg("cpuCount"), py::arg("info"), py::arg("size")); + +m.def("get_cpu_topology_info", &get_cpu_topology_info, "", py::arg("topologyInfos"), py::arg("topologyInfoCount")); + +m.def("get_cpuid", &get_cpuid, "", py::arg("info"), py::arg("eaxRegister"), py::arg("cpuNum")); + +//m.def("is_computer_on", &is_computer_on, "", py::arg("")); +m.def("is_computer_on", &is_computer_on_wrapper, ""); + +//m.def("is_computer_on_fire", &is_computer_on_fire, "", py::arg("")); +m.def("is_computer_on_fire", &is_computer_on_fire_wrapper, ""); + +m.def("send_signal", &send_signal, "", py::arg("threadID"), py::arg("signal")); + +m.def("set_signal_stack", &set_signal_stack, "", py::arg("base"), py::arg("size")); + +m.def("wait_for_objects", &wait_for_objects, "", py::arg("infos"), py::arg("numInfos")); + +m.def("wait_for_objects_etc", &wait_for_objects_etc, "", py::arg("infos"), py::arg("numInfos"), py::arg("flags"), py::arg("timeout")); + +} From 7eddcb93927524d60693869471a4990d6141cc91 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 30 Aug 2024 10:16:06 +0200 Subject: [PATCH 026/115] add get_cpu_info function --- bindings/kernel/OS.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bindings/kernel/OS.cpp b/bindings/kernel/OS.cpp index b4cad2e..b5d5771 100644 --- a/bindings/kernel/OS.cpp +++ b/bindings/kernel/OS.cpp @@ -80,6 +80,12 @@ area_id clone_area_wrapper(const std::string &name, py::capsule &destAddress, void *destAddressPtr = destAddress.get_pointer(); // Converte il py::capsule in void* return clone_area(name.c_str(), &destAddressPtr, addressSpec, protection, source); } + +status_t get_cpu_info_wrapper(uint32 firstCPU, uint32 cpuCount, cpu_info* info) { + return _get_cpu_info_etc((firstCPU), (cpuCount), (info), sizeof(*(info))); +} + + PYBIND11_MODULE(OS,m) { /*m.attr("B_TIMEOUT") = py::cast(B_TIMEOUT); @@ -547,6 +553,7 @@ m.def("ktrace_vprintf", &ktrace_vprintf, "", py::arg("format"), py::arg("args")) m.def("get_system_info", &get_system_info, "", py::arg("info")); m.def("_get_cpu_info_etc", &_get_cpu_info_etc, "", py::arg("firstCPU"), py::arg("cpuCount"), py::arg("info"), py::arg("size")); +m.def("get_cpu_info", &get_cpu_info_wrapper, "", py::arg("firstCPU"), py::arg("cpuCount"), py::arg("info")); m.def("get_cpu_topology_info", &get_cpu_topology_info, "", py::arg("topologyInfos"), py::arg("topologyInfoCount")); From 35fbb3803f47aa72757bbab7be942c7ccbbc40bf Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 30 Aug 2024 10:55:45 +0200 Subject: [PATCH 027/115] add unexposed functions wrapped for python (alrady in header) --- bindings/kernel/OS.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/bindings/kernel/OS.cpp b/bindings/kernel/OS.cpp index b5d5771..bdb330e 100644 --- a/bindings/kernel/OS.cpp +++ b/bindings/kernel/OS.cpp @@ -85,6 +85,53 @@ status_t get_cpu_info_wrapper(uint32 firstCPU, uint32 cpuCount, cpu_info* info) return _get_cpu_info_etc((firstCPU), (cpuCount), (info), sizeof(*(info))); } +status_t get_thread_info_wrapper(thread_id id, thread_info *info) { + return _get_thread_info((id), (info), sizeof(*(info))); +} + +status_t get_next_thread_info_wrapper(team_id team, int32 *cookie, thread_info *info) { + return _get_next_thread_info((team), (cookie), (info), sizeof(*(info))); +} + +status_t get_team_usage_info_wrapper(team_id team, int32 who, team_usage_info *info) { + return _get_team_usage_info((team), (who), (info), sizeof(*(info))); +} + +status_t get_team_info_wrapper(team_id id, team_info *info) { + return _get_team_info((id), (info), sizeof(*(info))); +} + +status_t get_next_team_info_wrapper(int32 *cookie, team_info *info) { + return _get_next_team_info((cookie), (info), sizeof(*(info))); +} + +status_t get_sem_info_wrapper(sem_id id, struct sem_info *info) { + return _get_sem_info((id), (info), sizeof(*(info))); +} + +status_t get_next_sem_info_wrapper(team_id team, int32 *cookie, struct sem_info *info) { + return _get_next_sem_info((team), (cookie), (info), sizeof(*(info))); +} + +status_t get_port_message_info_etc_wrapper(port_id port, port_message_info *info, uint32 flags, bigtime_t timeout) { + return _get_port_message_info_etc((port), (info), sizeof(*(info)), flags, timeout); +} + +status_t get_next_port_info_wrapper(team_id team, int32 *cookie, port_info *info) { + return _get_next_port_info((team), (cookie), (info), sizeof(*(info))); +} + +status_t get_port_info_wrapper(port_id port, port_info *info) { + return _get_port_info((port), (info), sizeof(*(info))); +} + +status_t get_next_area_info_wrapper(team_id team, ssize_t *cookie, area_info *areaInfo){ + return _get_next_area_info((team), (cookie), (areaInfo), sizeof(*(areaInfo))); +} + +status_t get_area_info_wrapper(area_id id, area_info *areaInfo){ + return _get_area_info((id), (areaInfo),sizeof(*(areaInfo))); +} PYBIND11_MODULE(OS,m) { @@ -417,8 +464,10 @@ m.def("resize_area", &resize_area, "", py::arg("id"), py::arg("newSize")); m.def("set_area_protection", &set_area_protection, "", py::arg("id"), py::arg("newProtection")); m.def("_get_area_info", &_get_area_info, "", py::arg("id"), py::arg("areaInfo"), py::arg("size")); +m.def("get_area_info", &get_area_info_wrapper, "", py::arg("id"), py::arg("areaInfo")); m.def("_get_next_area_info", &_get_next_area_info, "", py::arg("team"), py::arg("cookie"), py::arg("areaInfo"), py::arg("size")); +m.def("get_next_area_info", &get_next_area_info_wrapper, "", py::arg("team"), py::arg("cookie"), py::arg("areaInfo")); m.def("create_port", &create_port, "", py::arg("capacity"), py::arg("name")); @@ -445,10 +494,13 @@ m.def("port_count", &port_count, "", py::arg("port")); m.def("set_port_owner", &set_port_owner, "", py::arg("port"), py::arg("team")); m.def("_get_port_info", &_get_port_info, "", py::arg("port"), py::arg("portInfo"), py::arg("portInfoSize")); +m.def("get_port_info", &get_port_info_wrapper, "", py::arg("port"), py::arg("portInfo")); m.def("_get_next_port_info", &_get_next_port_info, "", py::arg("team"), py::arg("cookie"), py::arg("portInfo"), py::arg("portInfoSize")); +m.def("get_next_port_info", &get_next_port_info_wrapper, "", py::arg("team"), py::arg("cookie"), py::arg("portInfo")); m.def("_get_port_message_info_etc", &_get_port_message_info_etc, "", py::arg("port"), py::arg("info"), py::arg("infoSize"), py::arg("flags"), py::arg("timeout")); +m.def("get_port_message_info_etc", &get_port_message_info_etc_wrapper, "", py::arg("port"), py::arg("info"), py::arg("flags"), py::arg("timeout")); m.def("create_sem", &create_sem, "", py::arg("count"), py::arg("name")); @@ -471,16 +523,21 @@ m.def("get_sem_count", &get_sem_count, "", py::arg("id"), py::arg("threadCount") m.def("set_sem_owner", &set_sem_owner, "", py::arg("id"), py::arg("team")); m.def("_get_sem_info", &_get_sem_info, "", py::arg("id"), py::arg("info"), py::arg("infoSize")); +m.def("get_sem_info", &get_sem_info_wrapper, "", py::arg("id"), py::arg("info")); m.def("_get_next_sem_info", &_get_next_sem_info, "", py::arg("team"), py::arg("cookie"), py::arg("info"), py::arg("infoSize")); +m.def("get_next_sem_info", &get_next_sem_info_wrapper, "", py::arg("team"), py::arg("cookie"), py::arg("info")); m.def("kill_team", &kill_team, "", py::arg("team")); m.def("_get_team_info", &_get_team_info, "", py::arg("id"), py::arg("info"), py::arg("size")); +m.def("get_team_info", &get_team_info_wrapper, "", py::arg("id"), py::arg("info")); m.def("_get_next_team_info", &_get_next_team_info, "", py::arg("cookie"), py::arg("info"), py::arg("size")); +m.def("get_next_team_info", &get_next_team_info_wrapper, "", py::arg("cookie"), py::arg("info")); m.def("_get_team_usage_info", &_get_team_usage_info, "", py::arg("team"), py::arg("who"), py::arg("info"), py::arg("size")); +m.def("get_team_usage_info", &get_team_usage_info_wrapper, "", py::arg("team"), py::arg("who"), py::arg("info")); m.def("spawn_thread", &spawn_thread, "", py::arg(""), py::arg("name"), py::arg("priority"), py::arg("data")); @@ -517,8 +574,10 @@ m.def("snooze_etc", &snooze_etc, "", py::arg("amount"), py::arg("timeBase"), py: m.def("snooze_until", &snooze_until, "", py::arg("time"), py::arg("timeBase")); m.def("_get_thread_info", &_get_thread_info, "", py::arg("id"), py::arg("info"), py::arg("size")); +m.def("get_thread_info", &get_thread_info_wrapper, "",py::arg("id"), py::arg("info")); m.def("_get_next_thread_info", &_get_next_thread_info, "", py::arg("team"), py::arg("cookie"), py::arg("info"), py::arg("size")); +m.def("get_next_thread_info", &get_next_thread_info_wrapper, "", py::arg("team"), py::arg("cookie"), py::arg("info")); //m.def("get_pthread_thread_id", &get_pthread_thread_id, "", py::arg("thread")); From c2873cf7df3da0e8f4ed9dc3d7837a520e61a7f3 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 30 Aug 2024 18:53:07 +0200 Subject: [PATCH 028/115] Set as header --- bindings/interface/InterfaceDefs.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/bindings/interface/InterfaceDefs.cpp b/bindings/interface/InterfaceDefs.cpp index ad404bb..88b0033 100644 --- a/bindings/interface/InterfaceDefs.cpp +++ b/bindings/interface/InterfaceDefs.cpp @@ -16,7 +16,7 @@ namespace py = pybind11; PYBIND11_MODULE(InterfaceDefs,m) { -m.attr("B_BACKSPACE") = 8; +/*m.attr("B_BACKSPACE") = 8; m.attr("B_RETURN") = 10; m.attr("B_ENTER") = 10; m.attr("B_SPACE") = 32; @@ -37,6 +37,28 @@ m.attr("B_FUNCTION_KEY") = 16; m.attr("B_KATAKANA_HIRAGANA") = 242; m.attr("B_HANKAKU_ZENKAKU") = 243; m.attr("B_HANGUL") = 240; +m.attr("B_HANGUL_HANJA") = 241;*/ +m.attr("B_BACKSPACE") = 0x08; +m.attr("B_RETURN") = 0x0a; +m.attr("B_ENTER") = 0x0a; +m.attr("B_SPACE") = 0x20; +m.attr("B_TAB") = 0x09; +m.attr("B_ESCAPE") = 0x1b; +m.attr("B_SUBSTITUTE") = 0x1a; +m.attr("B_LEFT_ARROW") = 0x1c; +m.attr("B_RIGHT_ARROW") = 0x1d; +m.attr("B_UP_ARROW") = 0x1e; +m.attr("B_DOWN_ARROW") = 0x1f; +m.attr("B_INSERT") = 0x05; +m.attr("B_DELETE") = 0x7f; +m.attr("B_HOME") = 0x01; +m.attr("B_END") = 0x04; +m.attr("B_PAGE_UP") = 0x0b; +m.attr("B_PAGE_DOWN") = 0x0c; +m.attr("B_FUNCTION_KEY") = 0x10; +m.attr("B_KATAKANA_HIRAGANA") = 0xf2; +m.attr("B_HANKAKU_ZENKAKU") = 0xf3; +m.attr("B_HANGUL") = 240; m.attr("B_HANGUL_HANJA") = 241; m.attr("B_F1_KEY") = 2; From 4e750481ef6807c7dba8b00723ce0ba3ddc2744c Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 30 Aug 2024 18:53:33 +0200 Subject: [PATCH 029/115] add UTF8 support --- bindings/support/UTF8.cpp | 63 ++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/bindings/support/UTF8.cpp b/bindings/support/UTF8.cpp index 90f176a..18e1bef 100644 --- a/bindings/support/UTF8.cpp +++ b/bindings/support/UTF8.cpp @@ -4,43 +4,44 @@ #include #include +#include namespace py = pybind11; -void define_UTF8(py::module_& m) +PYBIND11_MODULE(UTF8, m) { -m.attr("B_ISO1_CONVERSION") = py::cast(B_ISO1_CONVERSION); -m.attr("B_ISO2_CONVERSION") = py::cast(B_ISO2_CONVERSION); -m.attr("B_ISO3_CONVERSION") = py::cast(B_ISO3_CONVERSION); -m.attr("B_ISO4_CONVERSION") = py::cast(B_ISO4_CONVERSION); -m.attr("B_ISO5_CONVERSION") = py::cast(B_ISO5_CONVERSION); -m.attr("B_ISO6_CONVERSION") = py::cast(B_ISO6_CONVERSION); -m.attr("B_ISO7_CONVERSION") = py::cast(B_ISO7_CONVERSION); -m.attr("B_ISO8_CONVERSION") = py::cast(B_ISO8_CONVERSION); -m.attr("B_ISO9_CONVERSION") = py::cast(B_ISO9_CONVERSION); -m.attr("B_ISO10_CONVERSION") = py::cast(B_ISO10_CONVERSION); -m.attr("B_MAC_ROMAN_CONVERSION") = py::cast(B_MAC_ROMAN_CONVERSION); -m.attr("B_SJIS_CONVERSION") = py::cast(B_SJIS_CONVERSION); -m.attr("B_EUC_CONVERSION") = py::cast(B_EUC_CONVERSION); -m.attr("B_JIS_CONVERSION") = py::cast(B_JIS_CONVERSION); -m.attr("B_MS_WINDOWS_CONVERSION") = py::cast(B_MS_WINDOWS_CONVERSION); -m.attr("B_UNICODE_CONVERSION") = py::cast(B_UNICODE_CONVERSION); -m.attr("B_KOI8R_CONVERSION") = py::cast(B_KOI8R_CONVERSION); -m.attr("B_MS_WINDOWS_1251_CONVERSION") = py::cast(B_MS_WINDOWS_1251_CONVERSION); -m.attr("B_MS_DOS_866_CONVERSION") = py::cast(B_MS_DOS_866_CONVERSION); -m.attr("B_MS_DOS_CONVERSION") = py::cast(B_MS_DOS_CONVERSION); -m.attr("B_EUC_KR_CONVERSION") = py::cast(B_EUC_KR_CONVERSION); -m.attr("B_ISO13_CONVERSION") = py::cast(B_ISO13_CONVERSION); -m.attr("B_ISO14_CONVERSION") = py::cast(B_ISO14_CONVERSION); -m.attr("B_ISO15_CONVERSION") = py::cast(B_ISO15_CONVERSION); -m.attr("B_BIG5_CONVERSION") = py::cast(B_BIG5_CONVERSION); -m.attr("B_GBK_CONVERSION") = py::cast(B_GBK_CONVERSION); -m.attr("B_UTF16_CONVERSION") = py::cast(B_UTF16_CONVERSION); -m.attr("B_MS_WINDOWS_1250_CONVERSION") = py::cast(B_MS_WINDOWS_1250_CONVERSION); +m.attr("B_ISO1_CONVERSION") = 0;//py::cast(B_ISO....); +m.attr("B_ISO2_CONVERSION") = 1; +m.attr("B_ISO3_CONVERSION") = 2; +m.attr("B_ISO4_CONVERSION") = 3; +m.attr("B_ISO5_CONVERSION") = 4; +m.attr("B_ISO6_CONVERSION") = 5; +m.attr("B_ISO7_CONVERSION") = 6; +m.attr("B_ISO8_CONVERSION") = 7; +m.attr("B_ISO9_CONVERSION") = 8; +m.attr("B_ISO10_CONVERSION") = 9; +m.attr("B_MAC_ROMAN_CONVERSION") = 10; +m.attr("B_SJIS_CONVERSION") = 11; +m.attr("B_EUC_CONVERSION") = 12; +m.attr("B_JIS_CONVERSION") = 13; +m.attr("B_MS_WINDOWS_CONVERSION") = 14; +m.attr("B_UNICODE_CONVERSION") = 15; +m.attr("B_KOI8R_CONVERSION") = 16; +m.attr("B_MS_WINDOWS_1251_CONVERSION") = 17; +m.attr("B_MS_DOS_866_CONVERSION") = 18; +m.attr("B_MS_DOS_CONVERSION") = 19; +m.attr("B_EUC_KR_CONVERSION") = 20; +m.attr("B_ISO13_CONVERSION") = 21; +m.attr("B_ISO14_CONVERSION") = 22; +m.attr("B_ISO15_CONVERSION") = 23; +m.attr("B_BIG5_CONVERSION") = 24; +m.attr("B_GBK_CONVERSION") = 25; +m.attr("B_UTF16_CONVERSION") = 26; +m.attr("B_MS_WINDOWS_1250_CONVERSION") = 27; -m.def("convert_to_utf8", &convert_to_utf8, "", py::arg("sourceEncoding"), py::arg("source"), py::arg("sourceLength"), py::arg("dest"), py::arg("destLength"), py::arg("state"), py::arg("substitute")=B_SUBSTITUTE); +m.def("convert_to_utf8", &convert_to_utf8, "", py::arg("sourceEncoding"), py::arg("source"), py::arg("sourceLength"), py::arg("dest"), py::arg("destLength"), py::arg("state"), py::arg("substitute")=0x1a);//hardcoded B_SUBSTITUTE -m.def("convert_from_utf8", &convert_from_utf8, "", py::arg("destEncoding"), py::arg("source"), py::arg("sourceLength"), py::arg("dest"), py::arg("destLength"), py::arg("state"), py::arg("substitute")=B_SUBSTITUTE); +m.def("convert_from_utf8", &convert_from_utf8, "", py::arg("destEncoding"), py::arg("source"), py::arg("sourceLength"), py::arg("dest"), py::arg("destLength"), py::arg("state"), py::arg("substitute")=0x1a);//hardcoded B_SUBSTITUTE } From bebd37412702a7732a428777b6cb522ad032b73b Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 30 Aug 2024 18:54:34 +0200 Subject: [PATCH 030/115] add mail --- Jamfile | 12 ++- bindings/__init__.py | 3 + bindings/mail/Email.cpp | 110 ++++++++++++++++++++++++++ bindings/mail/MailAttachment.cpp | 63 +++++++++++++++ bindings/mail/MailComponent.cpp | 57 ++++++++++++++ bindings/mail/MailContainer.cpp | 39 ++++++++++ bindings/mail/MailDaemon.cpp | 31 ++++++++ bindings/mail/MailMessage.cpp | 70 +++++++++++++++++ bindings/mail/MailSettings.cpp | 128 +++++++++++++++++++++++++++++++ bindings/mail/mail_encoding.cpp | 41 ++++++++++ 10 files changed, 552 insertions(+), 2 deletions(-) create mode 100644 bindings/mail/Email.cpp create mode 100644 bindings/mail/MailAttachment.cpp create mode 100644 bindings/mail/MailComponent.cpp create mode 100644 bindings/mail/MailContainer.cpp create mode 100644 bindings/mail/MailDaemon.cpp create mode 100644 bindings/mail/MailMessage.cpp create mode 100644 bindings/mail/MailSettings.cpp create mode 100644 bindings/mail/mail_encoding.cpp diff --git a/Jamfile b/Jamfile index bca5457..434b5e4 100644 --- a/Jamfile +++ b/Jamfile @@ -1,6 +1,6 @@ # Example usage: # jam -j$(nproc) - build using all cpu cores -# jam clean - remove all build files +# jam clean - remove all build files # jam -sparameter=value - to pass a parameter # # Parameters: @@ -74,7 +74,7 @@ install_location ?= /boot/system/non-packaged/lib/python$(python_version)/site-packages ; # Where to search for .cpp files -SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/storage bindings/kernel bindings/translation bindings/add-ons/screen_saver bindings/add-ons/registrar bindings/add-ons/graphics bindings/add-ons/input_server bindings/add-ons/mail_daemon bindings/add-ons/network_settings bindings/drivers bindings/device ; +SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/storage bindings/kernel bindings/translation bindings/add-ons/screen_saver bindings/add-ons/registrar bindings/add-ons/graphics bindings/add-ons/input_server bindings/add-ons/mail_daemon bindings/add-ons/network_settings bindings/drivers bindings/device bindings/mail ; # Where to look for header files SubDirHdrs headers ; @@ -214,6 +214,7 @@ local sourceFiles = StringList.cpp DataIO.cpp Url.cpp + UTF8.cpp #Kernel fs_attr.cpp @@ -282,6 +283,10 @@ local sourceFiles = A2D.cpp D2A.cpp DigitalPort.cpp + + #mail + Email.cpp + MailDaemon.cpp ; # The .so files can be built from the .cpp files, each .cpp file mapping to @@ -290,6 +295,7 @@ for sourceFile in $(sourceFiles) { SharedLibrary $(sourceFile:S=.so) : $(sourceFile) ; } +LINKLIBS on UTF8.so = $(LINKLIBS) -ltextencoding ; # FilePanel.so needs to be linked with libtracker.so LINKLIBS on FilePanel.so = $(LINKLIBS) -ltracker ; @@ -307,6 +313,8 @@ LINKLIBS on ScreenSaver.so = $(LINKLIBS) -lscreensaver ; LINKLIBS on MailFilter.so = $(LINKLIBS) -lmail ; LINKLIBS on MailSettingsView.so = $(LINKLIBS) -lmail ; LINKLIBS on MailProtocol.so = $(LINKLIBS) -lmail ; +LINKLIBS on Email.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailDaemon.so = $(LINKLIBS) -lmail ; LINKLIBS on NetworkSettings.so = $(LINKLIBS) -lbnetapi ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 4d5ff49..07d41a8 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -104,6 +104,7 @@ from .StringList import * from .DataIO import * from .Url import * +from .UTF8 import * from .fs_attr import * from .OS import * @@ -162,6 +163,8 @@ #from .A2D import * #from .D2A import * #from .DigitalPort import * +from .Email import * +from .MailDaemon import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/mail/Email.cpp b/bindings/mail/Email.cpp new file mode 100644 index 0000000..b96ec50 --- /dev/null +++ b/bindings/mail/Email.cpp @@ -0,0 +1,110 @@ +#include +#include +#include +#include +#include +#include +#include + +namespace py = pybind11; + +std::string get_pop_name(const mail_pop_account& self) { + return std::string(self.pop_name); +} + +void set_pop_name(mail_pop_account& self, const std::string& name) { + std::strncpy(self.pop_name, name.c_str(), B_MAX_USER_NAME_LENGTH - 1); + self.pop_name[B_MAX_USER_NAME_LENGTH - 1] = '\0'; +} + +std::string get_pop_password(const mail_pop_account& self) { + return std::string(self.pop_password); +} + +void set_pop_password(mail_pop_account& self, const std::string& name) { + std::strncpy(self.pop_password, name.c_str(), B_MAX_USER_NAME_LENGTH - 1); + self.pop_password[B_MAX_USER_NAME_LENGTH - 1] = '\0'; +} + +std::string get_pop_host(const mail_pop_account& self) { + return std::string(self.pop_host); +} + +void set_pop_host(mail_pop_account& self, const std::string& name) { + std::strncpy(self.pop_host, name.c_str(), B_MAX_HOST_NAME_LENGTH - 1); + self.pop_host[B_MAX_HOST_NAME_LENGTH - 1] = '\0'; +} + +std::string get_real_name(const mail_pop_account& self) { + return std::string(self.real_name); +} + +void set_real_name(mail_pop_account& self, const std::string& name) { + std::strncpy(self.real_name, name.c_str(), 128 - 1); + self.real_name[128 - 1] = '\0'; +} + +std::string get_reply_to(const mail_pop_account& self) { + return std::string(self.reply_to); +} + +void set_reply_to(mail_pop_account& self, const std::string& name) { + std::strncpy(self.reply_to, name.c_str(), 128 - 1); + self.reply_to[128 - 1] = '\0'; +} + +PYBIND11_MODULE(Email, m) +{ +py::enum_(m, "read_flags", "") +.value("B_UNREAD", read_flags::B_UNREAD, "") +.value("B_SEEN", read_flags::B_SEEN, "") +.value("B_READ", read_flags::B_READ, "") +.export_values(); + +py::enum_(m, "mail_flags", "") +.value("B_MAIL_PENDING", mail_flags::B_MAIL_PENDING, "") +.value("B_MAIL_SENT", mail_flags::B_MAIL_SENT, "") +.value("B_MAIL_SAVE", mail_flags::B_MAIL_SAVE, "") +.export_values(); + +py::class_(m, "mail_pop_account") +//.def_readwrite("pop_name", &mail_pop_account::pop_name, "") +.def_property("pop_name", &get_pop_name, &set_pop_name, "") +//.def_readwrite("pop_password", &mail_pop_account::pop_password, "") +.def_property("pop_password", &get_pop_password, &set_pop_password, "") +//.def_readwrite("pop_host", &mail_pop_account::pop_host, "") +.def_property("pop_host", &get_pop_host, &set_pop_host, "") +//.def_readwrite("real_name", &mail_pop_account::real_name, "") +.def_property("real_name", &get_real_name, &set_real_name, "") +//.def_readwrite("reply_to", &mail_pop_account::reply_to, "") +.def_property("reply_to", &get_reply_to, &set_reply_to, "") +.def_readwrite("days", &mail_pop_account::days, "") +.def_readwrite("interval", &mail_pop_account::interval, "") +.def_readwrite("begin_time", &mail_pop_account::begin_time, "") +.def_readwrite("end_time", &mail_pop_account::end_time, "") +; + +py::class_(m, "mail_notification") +.def_readwrite("alert", &mail_notification::alert, "") +.def_readwrite("beep", &mail_notification::beep, "") +; + +py::class_(m, "BMailMessage") +.def(py::init(), "") +.def("AddContent", py::overload_cast(&BMailMessage::AddContent), "", py::arg("text"), py::arg("length"), py::arg("encoding")=0, py::arg("clobber")=false)//hardcoded B_ISO1_CONVERSION to 0 +.def("AddContent", py::overload_cast(&BMailMessage::AddContent), "", py::arg("text"), py::arg("length"), py::arg("encoding"), py::arg("clobber")=false) +.def("AddEnclosure", py::overload_cast(&BMailMessage::AddEnclosure), "", py::arg("ref"), py::arg("clobber")=false) +.def("AddEnclosure", py::overload_cast(&BMailMessage::AddEnclosure), "", py::arg("path"), py::arg("clobber")=false) +.def("AddEnclosure", py::overload_cast(&BMailMessage::AddEnclosure), "", py::arg("MIME_type"), py::arg("data"), py::arg("len"), py::arg("clobber")=false) +.def("AddHeaderField", py::overload_cast(&BMailMessage::AddHeaderField), "", py::arg("encoding"), py::arg("field_name"), py::arg("str"), py::arg("clobber")=false) +.def("AddHeaderField", py::overload_cast(&BMailMessage::AddHeaderField), "", py::arg("field_name"), py::arg("str"), py::arg("clobber")=false) +.def("Send", &BMailMessage::Send, "", py::arg("sendNow")=false, py::arg("removeAfterSending")=false) +; + +m.def("count_pop_accounts", &count_pop_accounts, ""); + +m.def("get_pop_account", &get_pop_account, "", py::arg(""), py::arg("index")=0); + +m.def("set_pop_account", &set_pop_account, "", py::arg(""), py::arg("index")=0, py::arg("save")=true); + +} diff --git a/bindings/mail/MailAttachment.cpp b/bindings/mail/MailAttachment.cpp new file mode 100644 index 0000000..80fd34c --- /dev/null +++ b/bindings/mail/MailAttachment.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_MailAttachment(py::module_& m) +{ +py::class_(m, "BMailAttachment") +.def("SetFileName", &BMailAttachment::SetFileName, "", py::arg("name")) +.def("FileName", &BMailAttachment::FileName, "", py::arg("name")) +.def("SetTo", py::overload_cast(&BMailAttachment::SetTo), "", py::arg("file"), py::arg("deleteFileWhenDone")=false) +.def("SetTo", py::overload_cast(&BMailAttachment::SetTo), "", py::arg("ref")) +.def("InitCheck", &BMailAttachment::InitCheck, "") +; + +py::class_(m, "BSimpleMailAttachment") +.def(py::init(), "", py::arg("dataToAttach"), py::arg("encoding")=base64) +.def(py::init(), "", py::arg("dataToAttach"), py::arg("lengthOfData"), py::arg("encoding")=base64) +.def(py::init(), "", py::arg("file"), py::arg("delete_when_done")) +.def(py::init(), "", py::arg("ref")) +.def(py::init(), "") +.def("SetTo", py::overload_cast(&BSimpleMailAttachment::SetTo), "", py::arg("file"), py::arg("delete_file_when_done")=false) +.def("SetTo", py::overload_cast(&BSimpleMailAttachment::SetTo), "", py::arg("ref")) +.def("InitCheck", &BSimpleMailAttachment::InitCheck, "") +.def("SetFileName", &BSimpleMailAttachment::SetFileName, "", py::arg("name")) +.def("FileName", &BSimpleMailAttachment::FileName, "", py::arg("name")) +.def("GetDecodedData", py::overload_cast(&BSimpleMailAttachment::GetDecodedData), "", py::arg("data")) +.def("SetDecodedData", py::overload_cast(&BSimpleMailAttachment::SetDecodedData), "", py::arg("data")) +.def("GetDecodedData", py::overload_cast<>(&BSimpleMailAttachment::GetDecodedData), "") +.def("SetDecodedData", py::overload_cast(&BSimpleMailAttachment::SetDecodedData), "", py::arg("data"), py::arg("length")) +.def("SetDecodedDataAndDeleteWhenDone", &BSimpleMailAttachment::SetDecodedDataAndDeleteWhenDone, "", py::arg("data")) +.def("SetEncoding", &BSimpleMailAttachment::SetEncoding, "", py::arg("encoding")=base64) +.def("Encoding", &BSimpleMailAttachment::Encoding, "") +.def("SetToRFC822", &BSimpleMailAttachment::SetToRFC822, "", py::arg("data"), py::arg("length"), py::arg("parse_now")=false) +.def("RenderToRFC822", &BSimpleMailAttachment::RenderToRFC822, "", py::arg("render_to")) +; + +py::class_(m, "BAttributedMailAttachment") +.def(py::init(), "", py::arg("file"), py::arg("delete_when_done")) +.def(py::init(), "", py::arg("ref")) +.def(py::init(), "") +.def("SetTo", py::overload_cast(&BAttributedMailAttachment::SetTo), "", py::arg("file"), py::arg("delete_file_when_done")=false) +.def("SetTo", py::overload_cast(&BAttributedMailAttachment::SetTo), "", py::arg("ref")) +.def("InitCheck", &BAttributedMailAttachment::InitCheck, "") +.def("SaveToDisk", &BAttributedMailAttachment::SaveToDisk, "", py::arg("entry")) +.def("SetEncoding", &BAttributedMailAttachment::SetEncoding, "", py::arg("encoding")) +.def("Encoding", &BAttributedMailAttachment::Encoding, "") +.def("FileName", &BAttributedMailAttachment::FileName, "", py::arg("name")) +.def("SetFileName", &BAttributedMailAttachment::SetFileName, "", py::arg("name")) +.def("GetDecodedData", &BAttributedMailAttachment::GetDecodedData, "", py::arg("data")) +.def("SetDecodedData", &BAttributedMailAttachment::SetDecodedData, "", py::arg("data")) +.def("SetToRFC822", &BAttributedMailAttachment::SetToRFC822, "", py::arg("data"), py::arg("length"), py::arg("parse_now")=false) +.def("RenderToRFC822", &BAttributedMailAttachment::RenderToRFC822, "", py::arg("render_to")) +.def("MIMEType", &BAttributedMailAttachment::MIMEType, "", py::arg("mime")) +; + + +} diff --git a/bindings/mail/MailComponent.cpp b/bindings/mail/MailComponent.cpp new file mode 100644 index 0000000..6fe478d --- /dev/null +++ b/bindings/mail/MailComponent.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_MailComponent(py::module_& m) +{ +py::enum_(m, "component_type", "") +.value("B_MAIL_PLAIN_TEXT_BODY", component_type::B_MAIL_PLAIN_TEXT_BODY, "") +.value("B_MAIL_SIMPLE_ATTACHMENT", component_type::B_MAIL_SIMPLE_ATTACHMENT, "") +.value("B_MAIL_ATTRIBUTED_ATTACHMENT", component_type::B_MAIL_ATTRIBUTED_ATTACHMENT, "") +.value("B_MAIL_MULTIPART_CONTAINER", component_type::B_MAIL_MULTIPART_CONTAINER, "") +.export_values(); + +m.attr("kHeaderCharsetString") = py::cast(kHeaderCharsetString); + +m.attr("kHeaderEncodingString") = py::cast(kHeaderEncodingString); + +py::class_(m, "BMailComponent") +.def(py::init(), "", py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) +.def("ComponentType", &BMailComponent::ComponentType, "") +.def("WhatIsThis", &BMailComponent::WhatIsThis, "") +.def("IsAttachment", &BMailComponent::IsAttachment, "") +.def("SetHeaderField", py::overload_cast(&BMailComponent::SetHeaderField), "", py::arg("key"), py::arg("value"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding, py::arg("replace_existing")=true) +.def("SetHeaderField", py::overload_cast(&BMailComponent::SetHeaderField), "", py::arg("key"), py::arg("structured_header"), py::arg("replace_existing")=true) +.def("HeaderAt", &BMailComponent::HeaderAt, "", py::arg("index")) +.def("HeaderField", py::overload_cast(&BMailComponent::HeaderField), "", py::arg("key"), py::arg("index")=0) +.def("HeaderField", py::overload_cast(&BMailComponent::HeaderField), "", py::arg("key"), py::arg("structured_header"), py::arg("index")=0) +.def("RemoveHeader", &BMailComponent::RemoveHeader, "", py::arg("key")) +.def("GetDecodedData", &BMailComponent::GetDecodedData, "", py::arg("data")) +.def("SetDecodedData", &BMailComponent::SetDecodedData, "", py::arg("data")) +.def("SetToRFC822", &BMailComponent::SetToRFC822, "", py::arg("data"), py::arg("length"), py::arg("parse_now")=false) +.def("RenderToRFC822", &BMailComponent::RenderToRFC822, "", py::arg("render_to")) +.def("MIMEType", &BMailComponent::MIMEType, "", py::arg("mime")) +; + +py::class_(m, "BTextMailComponent") +.def(py::init(), "", py::arg("text")=NULL, py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) +.def("SetEncoding", &BTextMailComponent::SetEncoding, "", py::arg("encoding"), py::arg("charset")) +.def("SetText", &BTextMailComponent::SetText, "", py::arg("text")) +.def("AppendText", &BTextMailComponent::AppendText, "", py::arg("text")) +.def("Text", &BTextMailComponent::Text, "") +.def("BStringText", &BTextMailComponent::BStringText, "") +.def("Quote", &BTextMailComponent::Quote, "", py::arg("message")=NULL, py::arg("quote_style")="> ") +.def("GetDecodedData", &BTextMailComponent::GetDecodedData, "", py::arg("data")) +.def("SetDecodedData", &BTextMailComponent::SetDecodedData, "", py::arg("data")) +.def("SetToRFC822", &BTextMailComponent::SetToRFC822, "", py::arg("data"), py::arg("length"), py::arg("parse_now")=false) +.def("RenderToRFC822", &BTextMailComponent::RenderToRFC822, "", py::arg("render_to")) +; + + +} diff --git a/bindings/mail/MailContainer.cpp b/bindings/mail/MailContainer.cpp new file mode 100644 index 0000000..8f0b50d --- /dev/null +++ b/bindings/mail/MailContainer.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_MailContainer(py::module_& m) +{ +py::class_(m, "BMailContainer") +.def(py::init(), "", py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) +.def("AddComponent", &BMailContainer::AddComponent, "", py::arg("component")) +.def("RemoveComponent", py::overload_cast(&BMailContainer::RemoveComponent), "", py::arg("component")) +.def("RemoveComponent", py::overload_cast(&BMailContainer::RemoveComponent), "", py::arg("index")) +.def("GetComponent", &BMailContainer::GetComponent, "", py::arg("index"), py::arg("parse_now")=false) +.def("CountComponents", &BMailContainer::CountComponents, "") +; + +py::class_(m, "BMIMEMultipartMailContainer") +.def(py::init(), "", py::arg("boundary")=NULL, py::arg("this_is_an_MIME_message_text")=NULL, py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) +.def(py::init(), "") +.def("SetBoundary", &BMIMEMultipartMailContainer::SetBoundary, "", py::arg("boundary")) +.def("SetThisIsAnMIMEMessageText", &BMIMEMultipartMailContainer::SetThisIsAnMIMEMessageText, "", py::arg("text")) +.def("AddComponent", &BMIMEMultipartMailContainer::AddComponent, "", py::arg("component")) +.def("RemoveComponent", py::overload_cast(&BMIMEMultipartMailContainer::RemoveComponent), "", py::arg("component")) +.def("RemoveComponent", py::overload_cast(&BMIMEMultipartMailContainer::RemoveComponent), "", py::arg("index")) +.def("GetComponent", &BMIMEMultipartMailContainer::GetComponent, "", py::arg("index"), py::arg("parse_now")=false) +.def("CountComponents", &BMIMEMultipartMailContainer::CountComponents, "") +.def("GetDecodedData", &BMIMEMultipartMailContainer::GetDecodedData, "", py::arg("data")) +.def("SetDecodedData", &BMIMEMultipartMailContainer::SetDecodedData, "", py::arg("data")) +.def("SetToRFC822", &BMIMEMultipartMailContainer::SetToRFC822, "", py::arg("data"), py::arg("length"), py::arg("parse_now")=false) +.def("RenderToRFC822", &BMIMEMultipartMailContainer::RenderToRFC822, "", py::arg("render_to")) +; + + +} diff --git a/bindings/mail/MailDaemon.cpp b/bindings/mail/MailDaemon.cpp new file mode 100644 index 0000000..170405b --- /dev/null +++ b/bindings/mail/MailDaemon.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(MailDaemon, m) +{ +//m.attr("B_MAIL_BODY_FETCHED") = py::cast(B_MAIL_BODY_FETCHED); // +m.attr("B_MAIL_BODY_FETCHED") = '_Mbf'; + +py::class_(m, "BMailDaemon") +.def(py::init(), "") +.def("IsRunning", &BMailDaemon::IsRunning, "") +.def("CheckMail", &BMailDaemon::CheckMail, "", py::arg("accountID")=- 1) +.def("CheckAndSendQueuedMail", &BMailDaemon::CheckAndSendQueuedMail, "", py::arg("accountID")=- 1) +.def("SendQueuedMail", &BMailDaemon::SendQueuedMail, "") +.def("CountNewMessages", &BMailDaemon::CountNewMessages, "", py::arg("waitForFetchCompletion")=false) +.def("MarkAsRead", &BMailDaemon::MarkAsRead, "", py::arg("account"), py::arg("ref"), py::arg("flag")=B_READ) +.def("FetchBody", &BMailDaemon::FetchBody, "", py::arg("ref"), py::arg("listener")=NULL) +.def("Quit", &BMailDaemon::Quit, "") +.def("Launch", &BMailDaemon::Launch, "") +; + + +} diff --git a/bindings/mail/MailMessage.cpp b/bindings/mail/MailMessage.cpp new file mode 100644 index 0000000..44ef512 --- /dev/null +++ b/bindings/mail/MailMessage.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_MailMessage(py::module_& m) +{ +py::enum_(m, "mail_reply_to_mode", "") +.value("B_MAIL_REPLY_TO", mail_reply_to_mode::B_MAIL_REPLY_TO, "") +.value("B_MAIL_REPLY_TO_ALL", mail_reply_to_mode::B_MAIL_REPLY_TO_ALL, "") +.value("B_MAIL_REPLY_TO_SENDER", mail_reply_to_mode::B_MAIL_REPLY_TO_SENDER, "") +.export_values(); + +py::class_(m, "BEmailMessage") +.def(py::init(), "", py::arg("stream")=NULL, py::arg("ownStream")=false, py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) +.def(py::init(), "", py::arg("ref"), py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) +.def("InitCheck", &BEmailMessage::InitCheck, "") +.def("Data", &BEmailMessage::Data, "") +.def("ReplyMessage", &BEmailMessage::ReplyMessage, "", py::arg("replyTo"), py::arg("accountFromMail"), py::arg("quoteStyle")="> ") +.def("ForwardMessage", &BEmailMessage::ForwardMessage, "", py::arg("accountFromMail"), py::arg("includeAttachments")=false) +.def("To", &BEmailMessage::To, "") +.def("From", &BEmailMessage::From, "") +.def("ReplyTo", &BEmailMessage::ReplyTo, "") +.def("CC", &BEmailMessage::CC, "") +.def("Subject", &BEmailMessage::Subject, "") +.def("Date", &BEmailMessage::Date, "") +.def("Priority", &BEmailMessage::Priority, "") +.def("SetSubject", &BEmailMessage::SetSubject, "", py::arg("to"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding) +.def("SetReplyTo", &BEmailMessage::SetReplyTo, "", py::arg("to"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding) +.def("SetFrom", &BEmailMessage::SetFrom, "", py::arg("to"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding) +.def("SetTo", &BEmailMessage::SetTo, "", py::arg("to"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding) +.def("SetCC", &BEmailMessage::SetCC, "", py::arg("to"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding) +.def("SetBCC", &BEmailMessage::SetBCC, "", py::arg("to")) +.def("SetPriority", &BEmailMessage::SetPriority, "", py::arg("to")) +.def("GetName", py::overload_cast(&BEmailMessage::GetName), "", py::arg("name"), py::arg("maxLength")) +.def("GetName", py::overload_cast(&BEmailMessage::GetName), "", py::arg("name")) +.def("SendViaAccountFrom", &BEmailMessage::SendViaAccountFrom, "", py::arg("message")) +.def("SendViaAccount", py::overload_cast(&BEmailMessage::SendViaAccount), "", py::arg("accountName")) +.def("SendViaAccount", py::overload_cast(&BEmailMessage::SendViaAccount), "", py::arg("account")) +.def("Account", &BEmailMessage::Account, "") +.def("GetAccountName", [](BEmailMessage& self) { + BString accountName; + status_t r = self.GetAccountName(accountName); + return std::make_tuple(r,accountName); +} +, "") +.def("AddComponent", &BEmailMessage::AddComponent, "", py::arg("component")) +.def("RemoveComponent", py::overload_cast(&BEmailMessage::RemoveComponent), "", py::arg("component")) +.def("RemoveComponent", py::overload_cast(&BEmailMessage::RemoveComponent), "", py::arg("index")) +.def("GetComponent", &BEmailMessage::GetComponent, "", py::arg("index"), py::arg("parseNow")=false) +.def("CountComponents", &BEmailMessage::CountComponents, "") +.def("Attach", &BEmailMessage::Attach, "", py::arg("ref"), py::arg("includeAttributes")=true) +.def("IsComponentAttachment", &BEmailMessage::IsComponentAttachment, "", py::arg("index")) +.def("SetBodyTextTo", &BEmailMessage::SetBodyTextTo, "", py::arg("text")) +.def("BodyText", &BEmailMessage::BodyText, "") +.def("SetBody", &BEmailMessage::SetBody, "", py::arg("body")) +.def("Body", &BEmailMessage::Body, "") +.def("SetToRFC822", &BEmailMessage::SetToRFC822, "", py::arg("data"), py::arg("length"), py::arg("parseNow")=false) +.def("RenderToRFC822", &BEmailMessage::RenderToRFC822, "", py::arg("renderTo")) +.def("RenderTo", &BEmailMessage::RenderTo, "", py::arg("dir"), py::arg("message")=NULL) +.def("Send", &BEmailMessage::Send, "", py::arg("sendNow")) +; + + +} diff --git a/bindings/mail/MailSettings.cpp b/bindings/mail/MailSettings.cpp new file mode 100644 index 0000000..43febc0 --- /dev/null +++ b/bindings/mail/MailSettings.cpp @@ -0,0 +1,128 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_MailSettings(py::module_& m) +{ +py::enum_(m, "b_mail_status_window_option", "") +.value("B_MAIL_SHOW_STATUS_WINDOW_NEVER", b_mail_status_window_option::B_MAIL_SHOW_STATUS_WINDOW_NEVER, "") +.value("B_MAIL_SHOW_STATUS_WINDOW_WHEN_SENDING", b_mail_status_window_option::B_MAIL_SHOW_STATUS_WINDOW_WHEN_SENDING, "") +.value("B_MAIL_SHOW_STATUS_WINDOW_WHEN_ACTIVE", b_mail_status_window_option::B_MAIL_SHOW_STATUS_WINDOW_WHEN_ACTIVE, "") +.value("B_MAIL_SHOW_STATUS_WINDOW_ALWAYS", b_mail_status_window_option::B_MAIL_SHOW_STATUS_WINDOW_ALWAYS, "") +.export_values(); + +py::class_(m, "BMailSettings") +.def(py::init(), "") +.def("Save", &BMailSettings::Save, "") +.def("Reload", &BMailSettings::Reload, "") +.def("InitCheck", &BMailSettings::InitCheck, "") +.def("WindowFollowsCorner", &BMailSettings::WindowFollowsCorner, "") +.def("SetWindowFollowsCorner", &BMailSettings::SetWindowFollowsCorner, "", py::arg("which_corner")) +.def("ShowStatusWindow", &BMailSettings::ShowStatusWindow, "") +.def("SetShowStatusWindow", &BMailSettings::SetShowStatusWindow, "", py::arg("mode")) +.def("DaemonAutoStarts", &BMailSettings::DaemonAutoStarts, "") +.def("SetDaemonAutoStarts", &BMailSettings::SetDaemonAutoStarts, "", py::arg("does_it")) +.def("SetConfigWindowFrame", &BMailSettings::SetConfigWindowFrame, "", py::arg("frame")) +.def("ConfigWindowFrame", &BMailSettings::ConfigWindowFrame, "") +.def("SetStatusWindowFrame", &BMailSettings::SetStatusWindowFrame, "", py::arg("frame")) +.def("StatusWindowFrame", &BMailSettings::StatusWindowFrame, "") +.def("StatusWindowWorkspaces", &BMailSettings::StatusWindowWorkspaces, "") +.def("SetStatusWindowWorkspaces", &BMailSettings::SetStatusWindowWorkspaces, "", py::arg("workspaces")) +.def("StatusWindowLook", &BMailSettings::StatusWindowLook, "") +.def("SetStatusWindowLook", &BMailSettings::SetStatusWindowLook, "", py::arg("look")) +.def("AutoCheckInterval", &BMailSettings::AutoCheckInterval, "") +.def("SetAutoCheckInterval", &BMailSettings::SetAutoCheckInterval, "", py::arg("")) +.def("CheckOnlyIfPPPUp", &BMailSettings::CheckOnlyIfPPPUp, "") +.def("SetCheckOnlyIfPPPUp", &BMailSettings::SetCheckOnlyIfPPPUp, "", py::arg("yes")) +.def("SendOnlyIfPPPUp", &BMailSettings::SendOnlyIfPPPUp, "") +.def("SetSendOnlyIfPPPUp", &BMailSettings::SetSendOnlyIfPPPUp, "", py::arg("yes")) +.def("DefaultOutboundAccount", &BMailSettings::DefaultOutboundAccount, "") +.def("SetDefaultOutboundAccount", &BMailSettings::SetDefaultOutboundAccount, "", py::arg("to")) +; + +py::class_(m, "BMailAddOnSettings") +.def(py::init(), "") +.def("Load", &BMailAddOnSettings::Load, "", py::arg("message")) +.def("Save", [](BMailAddOnSettings& self) { + BMessage message; + status_t r = self.Save(message); + return std::make_tuple(r,message); +} +, "") +.def("SetAddOnRef", &BMailAddOnSettings::SetAddOnRef, "", py::arg("ref")) +.def("AddOnRef", &BMailAddOnSettings::AddOnRef, "") +.def("HasBeenModified", &BMailAddOnSettings::HasBeenModified, "") +; + +py::class_(m, "BMailProtocolSettings") +.def(py::init(), "") +.def("Load", &BMailProtocolSettings::Load, "", py::arg("message")) +.def("Save", [](BMailProtocolSettings& self) { + BMessage message; + status_t r = self.Save(message); + return std::make_tuple(r,message); +} +, "") +.def("CountFilterSettings", &BMailProtocolSettings::CountFilterSettings, "") +.def("AddFilterSettings", &BMailProtocolSettings::AddFilterSettings, "", py::arg("ref")=NULL) +.def("RemoveFilterSettings", &BMailProtocolSettings::RemoveFilterSettings, "", py::arg("index")) +.def("MoveFilterSettings", &BMailProtocolSettings::MoveFilterSettings, "", py::arg("from"), py::arg("to")) +.def("FilterSettingsAt", &BMailProtocolSettings::FilterSettingsAt, "", py::arg("index")) +.def("HasBeenModified", &BMailProtocolSettings::HasBeenModified, "") +; + +py::class_(m, "BMailAccountSettings") +.def(py::init(), "") +.def(py::init(), "", py::arg("account")) +.def("InitCheck", &BMailAccountSettings::InitCheck, "") +.def("SetAccountID", &BMailAccountSettings::SetAccountID, "", py::arg("id")) +.def("AccountID", &BMailAccountSettings::AccountID, "") +.def("SetName", &BMailAccountSettings::SetName, "", py::arg("name")) +.def("Name", &BMailAccountSettings::Name, "") +.def("SetRealName", &BMailAccountSettings::SetRealName, "", py::arg("realName")) +.def("RealName", &BMailAccountSettings::RealName, "") +.def("SetReturnAddress", &BMailAccountSettings::SetReturnAddress, "", py::arg("returnAddress")) +.def("ReturnAddress", &BMailAccountSettings::ReturnAddress, "") +.def("SetInboundAddOn", &BMailAccountSettings::SetInboundAddOn, "", py::arg("name")) +.def("SetOutboundAddOn", &BMailAccountSettings::SetOutboundAddOn, "", py::arg("name")) +.def("InboundAddOnRef", &BMailAccountSettings::InboundAddOnRef, "") +.def("OutboundAddOnRef", &BMailAccountSettings::OutboundAddOnRef, "") +.def("InboundSettings", py::overload_cast<>(&BMailAccountSettings::InboundSettings), "") +.def("InboundSettings", py::overload_cast<>(&BMailAccountSettings::InboundSettings), "") +.def("OutboundSettings", py::overload_cast<>(&BMailAccountSettings::OutboundSettings), "") +.def("OutboundSettings", py::overload_cast<>(&BMailAccountSettings::OutboundSettings), "") +.def("HasInbound", &BMailAccountSettings::HasInbound, "") +.def("HasOutbound", &BMailAccountSettings::HasOutbound, "") +.def("SetInboundEnabled", &BMailAccountSettings::SetInboundEnabled, "", py::arg("enabled")=true) +.def("IsInboundEnabled", &BMailAccountSettings::IsInboundEnabled, "") +.def("SetOutboundEnabled", &BMailAccountSettings::SetOutboundEnabled, "", py::arg("enabled")=true) +.def("IsOutboundEnabled", &BMailAccountSettings::IsOutboundEnabled, "") +.def("Reload", &BMailAccountSettings::Reload, "") +.def("Save", &BMailAccountSettings::Save, "") +.def("Delete", &BMailAccountSettings::Delete, "") +.def("HasBeenModified", &BMailAccountSettings::HasBeenModified, "") +.def("AccountFile", &BMailAccountSettings::AccountFile, "") +; + +py::class_(m, "BMailAccounts") +.def(py::init(), "") +.def_static("AccountsPath", [](BMailAccounts& self) { + BPath path; + static status_t r = self.AccountsPath(path); + return std::make_tuple(r,path); +} +, "") +.def("CountAccounts", &BMailAccounts::CountAccounts, "") +.def("AccountAt", &BMailAccounts::AccountAt, "", py::arg("index")) +.def("AccountByID", &BMailAccounts::AccountByID, "", py::arg("id")) +.def("AccountByName", &BMailAccounts::AccountByName, "", py::arg("name")) +; + + +} diff --git a/bindings/mail/mail_encoding.cpp b/bindings/mail/mail_encoding.cpp new file mode 100644 index 0000000..5f10b6d --- /dev/null +++ b/bindings/mail/mail_encoding.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_mail_encoding(py::module_& m) +{ +py::enum_(m, "mail_encoding", "") +.value("base64", mail_encoding::base64, "") +.value("quoted_printable", mail_encoding::quoted_printable, "") +.value("seven_bit", mail_encoding::seven_bit, "") +.value("eight_bit", mail_encoding::eight_bit, "") +.value("uuencode", mail_encoding::uuencode, "") +.value("null_encoding", mail_encoding::null_encoding, "") +.value("no_encoding", mail_encoding::no_encoding, "") +.export_values(); + +m.def("encode", &encode, "", py::arg("encoding"), py::arg("out"), py::arg("in"), py::arg("length"), py::arg("headerMode")); + +m.def("decode", &decode, "", py::arg("encoding"), py::arg("out"), py::arg("in"), py::arg("length"), py::arg("underscore_is_space")); + +m.def("max_encoded_length", &max_encoded_length, "", py::arg("encoding"), py::arg("cur_length")); + +m.def("encoding_for_cte", &encoding_for_cte, "", py::arg("content_transfer_encoding")); + +m.def("encode_base64", &encode_base64, "", py::arg("out"), py::arg("in"), py::arg("length"), py::arg("headerMode")); + +m.def("decode_base64", &decode_base64, "", py::arg("out"), py::arg("in"), py::arg("length")); + +m.def("encode_qp", &encode_qp, "", py::arg("out"), py::arg("in"), py::arg("length"), py::arg("headerMode")); + +m.def("decode_qp", &decode_qp, "", py::arg("out"), py::arg("in"), py::arg("length"), py::arg("underscore_is_space")); + +m.def("uu_decode", &uu_decode, "", py::arg("out"), py::arg("in"), py::arg("length")); + +} From 57ce4c186dc32c8cae8de544b84630f477225a18 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 31 Aug 2024 08:09:36 +0200 Subject: [PATCH 031/115] Add mail_encoding.cpp --- Jamfile | 2 + bindings/__init__.py | 1 + bindings/mail/mail_encoding.cpp | 226 +++++++++++++++++++++++++++++++- 3 files changed, 227 insertions(+), 2 deletions(-) diff --git a/Jamfile b/Jamfile index 434b5e4..b8dd64e 100644 --- a/Jamfile +++ b/Jamfile @@ -286,6 +286,7 @@ local sourceFiles = #mail Email.cpp + mail_encoding.cpp MailDaemon.cpp ; @@ -314,6 +315,7 @@ LINKLIBS on MailFilter.so = $(LINKLIBS) -lmail ; LINKLIBS on MailSettingsView.so = $(LINKLIBS) -lmail ; LINKLIBS on MailProtocol.so = $(LINKLIBS) -lmail ; LINKLIBS on Email.so = $(LINKLIBS) -lmail ; +LINKLIBS on mail_encoding.so = $(LINKLIBS) -lmail ; LINKLIBS on MailDaemon.so = $(LINKLIBS) -lmail ; LINKLIBS on NetworkSettings.so = $(LINKLIBS) -lbnetapi ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 07d41a8..c5eaeb5 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -164,6 +164,7 @@ #from .D2A import * #from .DigitalPort import * from .Email import * +from .mail_encoding import * from .MailDaemon import * _BWindow=BWindow diff --git a/bindings/mail/mail_encoding.cpp b/bindings/mail/mail_encoding.cpp index 5f10b6d..de13131 100644 --- a/bindings/mail/mail_encoding.cpp +++ b/bindings/mail/mail_encoding.cpp @@ -2,13 +2,216 @@ #include #include #include - +#include #include +/* +#include +#include +#include */ namespace py = pybind11; +/* source mail_encoding.cpp from mail-kit +#define DEC(c) (((c) - ' ') & 077) + +static const char kHexAlphabet[16] = {'0', '1', '2', '3', '4', '5', '6', '7', + '8','9','A','B','C','D','E','F'}; + +ssize_t encode_qp_wrapper(char *out, const char *in, off_t length, int headerMode) +{ + int g = 0, i = 0; + + for (; i < length; i++) { + if (((uint8 *)(in))[i] > 127 || in[i] == '?' || in[i] == '=' + || in[i] == '_' + // Also encode the letter F in "From " at the start of the line, + // which Unix systems use to mark the start of messages in their + // mbox files. + || (in[i] == 'F' && i + 5 <= length && (i == 0 || in[i - 1] == '\n') + && in[i + 1] == 'r' && in[i + 2] == 'o' && in[i + 3] == 'm' + && in[i + 4] == ' ')) { + out[g++] = '='; + out[g++] = kHexAlphabet[(in[i] >> 4) & 0x0f]; + out[g++] = kHexAlphabet[in[i] & 0x0f]; + } else if (headerMode && (in[i] == ' ' || in[i] == '\t')) { + out[g++] = '_'; + } else if (headerMode && in[i] >= 0 && in[i] < 32) { + // Control codes in headers need to be sanitized, otherwise certain + // Japanese ISPs mangle the headers badly. But they don't mangle + // the body. + out[g++] = '='; + out[g++] = kHexAlphabet[(in[i] >> 4) & 0x0f]; + out[g++] = kHexAlphabet[in[i] & 0x0f]; + } else + out[g++] = in[i]; + } + + return g; +} + +ssize_t decode_qp_wrapper(char *out, const char *in, off_t length, int underscoreIsSpace) +{ + // decode Quoted Printable + char *dataout = out; + const char *datain = in, *dataend = in + length; + + while (datain < dataend) { + if (*datain == '=' && dataend - datain > 2) { + int a = toupper(datain[1]); + a -= a >= '0' && a <= '9' ? '0' : (a >= 'A' && a <= 'F' + ? 'A' - 10 : a + 1); + + int b = toupper(datain[2]); + b -= b >= '0' && b <= '9' ? '0' : (b >= 'A' && b <= 'F' + ? 'A' - 10 : b + 1); + + if (a >= 0 && b >= 0) { + *dataout++ = (a << 4) + b; + datain += 3; + continue; + } else if (datain[1] == '\r' && datain[2] == '\n') { + // strip = + datain += 3; + continue; + } + } else if (*datain == '_' && underscoreIsSpace) { + *dataout++ = ' '; + ++datain; + continue; + } + + *dataout++ = *datain++; + } + + *dataout = '\0'; + return dataout - out; +} + +ssize_t encode_wrapper(mail_encoding encoding, char *out, const char *in, off_t length, int headerMode) +{ + switch (encoding) { + case base64: + return encode_base64(out,in,length,headerMode); + case quoted_printable: + return encode_qp(out,in,length,headerMode); + case seven_bit: + case eight_bit: + case no_encoding: + memcpy(out,in,length); + return length; + case uuencode: + default: + return -1; + } + + return -1; +} + +ssize_t decode_wrapper(mail_encoding encoding, char *out, const char *in, off_t length, int underscoreIsSpace) +{ + switch (encoding) { + case base64: + return decode_base64(out, in, length); + case uuencode: + return uu_decode(out, in, length); + case seven_bit: + case eight_bit: + case no_encoding: + memcpy(out, in, length); + return length; + case quoted_printable: + return decode_qp(out, in, length, underscoreIsSpace); + default: + break; + } + + return -1; +} + +mail_encoding encoding_for_cte_wrapper(const char *cte) +{ + if (cte == NULL) + return no_encoding; + + if (strcasecmp(cte,"uuencode") == 0) + return uuencode; + if (strcasecmp(cte,"base64") == 0) + return base64; + if (strcasecmp(cte,"quoted-printable") == 0) + return quoted_printable; + if (strcasecmp(cte,"7bit") == 0) + return seven_bit; + if (strcasecmp(cte,"8bit") == 0) + return eight_bit; + + return no_encoding; +} + +ssize_t max_encoded_length_wrapper(mail_encoding encoding, off_t length) +{ + switch (encoding) { + case base64: + { + double result = length * 1.33333333333333; + result += (result / BASE64_LINELENGTH) * 2 + 20; + return (ssize_t)(result); + } + case quoted_printable: + return length * 3; + case seven_bit: + case eight_bit: + case no_encoding: + return length; + case uuencode: + default: + return -1; + } + + return -1; +} + +ssize_t uu_decode_wrapper(char *out, const char *in, off_t length) +{ + long n; + uint8 *p, *inBuffer = (uint8 *)in; + uint8 *outBuffer = (uint8 *)out; + + inBuffer = (uint8 *)strstr((char *)inBuffer, "begin"); + goto enterLoop; + + while ((inBuffer - (uint8 *)in) <= length + && strncmp((char *)inBuffer, "end", 3)) { + p = inBuffer; + n = DEC(inBuffer[0]); + for (++inBuffer; n > 0; inBuffer += 4, n -= 3) { + if (n >= 3) { + *outBuffer++ = DEC(inBuffer[0]) << 2 | DEC (inBuffer[1]) >> 4; + *outBuffer++ = DEC(inBuffer[1]) << 4 | DEC (inBuffer[2]) >> 2; + *outBuffer++ = DEC(inBuffer[2]) << 6 | DEC (inBuffer[3]); + } else { + if (n >= 1) { + *outBuffer++ = DEC(inBuffer[0]) << 2 + | DEC (inBuffer[1]) >> 4; + } + if (n >= 2) { + *outBuffer++ = DEC(inBuffer[1]) << 4 + | DEC (inBuffer[2]) >> 2; + } + } + } + inBuffer = p; -void define_mail_encoding(py::module_& m) + enterLoop: + while (inBuffer[0] != '\n' && inBuffer[0] != '\r' && inBuffer[0] != 0) + inBuffer++; + while (inBuffer[0] == '\n' || inBuffer[0] == '\r') + inBuffer++; + } + + return (ssize_t)(outBuffer - (uint8 *)in); +}*/ + +PYBIND11_MODULE(mail_encoding, m) { py::enum_(m, "mail_encoding", "") .value("base64", mail_encoding::base64, "") @@ -19,6 +222,25 @@ py::enum_(m, "mail_encoding", "") .value("null_encoding", mail_encoding::null_encoding, "") .value("no_encoding", mail_encoding::no_encoding, "") .export_values(); +/* +m.def("encode", &encode_wrapper, "", py::arg("encoding"), py::arg("out"), py::arg("in"), py::arg("length"), py::arg("headerMode")); + +m.def("decode", &decode_wrapper, "", py::arg("encoding"), py::arg("out"), py::arg("in"), py::arg("length"), py::arg("underscore_is_space")); + +m.def("max_encoded_length", &max_encoded_length_wrapper, "", py::arg("encoding"), py::arg("cur_length")); + +m.def("encoding_for_cte", &encoding_for_cte_wrapper, "", py::arg("content_transfer_encoding")); + +m.def("encode_base64", &encode_base64, "", py::arg("out"), py::arg("in"), py::arg("length"), py::arg("headerMode")); + +m.def("decode_base64", &decode_base64, "", py::arg("out"), py::arg("in"), py::arg("length")); + +m.def("encode_qp", &encode_qp_wrapper, "", py::arg("out"), py::arg("in"), py::arg("length"), py::arg("headerMode")); + +m.def("decode_qp", &decode_qp_wrapper, "", py::arg("out"), py::arg("in"), py::arg("length"), py::arg("underscore_is_space")); + +m.def("uu_decode", &uu_decode_wrapper, "", py::arg("out"), py::arg("in"), py::arg("length")); +*/ m.def("encode", &encode, "", py::arg("encoding"), py::arg("out"), py::arg("in"), py::arg("length"), py::arg("headerMode")); From d0e4be54b9c16844e982846b06fc43df866cfd29 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 31 Aug 2024 08:33:08 +0200 Subject: [PATCH 032/115] add MailAttachment and MailComponent --- Jamfile | 4 ++++ bindings/__init__.py | 3 +++ bindings/mail/MailAttachment.cpp | 5 ++++- bindings/mail/MailComponent.cpp | 14 +++++++------- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Jamfile b/Jamfile index b8dd64e..9334919 100644 --- a/Jamfile +++ b/Jamfile @@ -288,6 +288,8 @@ local sourceFiles = Email.cpp mail_encoding.cpp MailDaemon.cpp + MailComponent.cpp + MailAttachment.cpp ; # The .so files can be built from the .cpp files, each .cpp file mapping to @@ -317,6 +319,8 @@ LINKLIBS on MailProtocol.so = $(LINKLIBS) -lmail ; LINKLIBS on Email.so = $(LINKLIBS) -lmail ; LINKLIBS on mail_encoding.so = $(LINKLIBS) -lmail ; LINKLIBS on MailDaemon.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailComponent.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailAttachment.so = $(LINKLIBS) -lmail ; LINKLIBS on NetworkSettings.so = $(LINKLIBS) -lbnetapi ; diff --git a/bindings/__init__.py b/bindings/__init__.py index c5eaeb5..c3bcde2 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -165,8 +165,11 @@ #from .DigitalPort import * from .Email import * from .mail_encoding import * +from .MailComponent import * from .MailDaemon import * +from .MailAttachment import * + _BWindow=BWindow _BApplication=BApplication def MessageReceived(self, msg, parent): diff --git a/bindings/mail/MailAttachment.cpp b/bindings/mail/MailAttachment.cpp index 80fd34c..e980701 100644 --- a/bindings/mail/MailAttachment.cpp +++ b/bindings/mail/MailAttachment.cpp @@ -4,11 +4,14 @@ #include #include +#include +#include +#include namespace py = pybind11; -void define_MailAttachment(py::module_& m) +PYBIND11_MODULE(MailAttachment, m) { py::class_(m, "BMailAttachment") .def("SetFileName", &BMailAttachment::SetFileName, "", py::arg("name")) diff --git a/bindings/mail/MailComponent.cpp b/bindings/mail/MailComponent.cpp index 6fe478d..3ecaf2b 100644 --- a/bindings/mail/MailComponent.cpp +++ b/bindings/mail/MailComponent.cpp @@ -4,11 +4,11 @@ #include #include +#include namespace py = pybind11; - -void define_MailComponent(py::module_& m) +PYBIND11_MODULE(MailComponent, m) { py::enum_(m, "component_type", "") .value("B_MAIL_PLAIN_TEXT_BODY", component_type::B_MAIL_PLAIN_TEXT_BODY, "") @@ -22,15 +22,15 @@ m.attr("kHeaderCharsetString") = py::cast(kHeaderCharsetString); m.attr("kHeaderEncodingString") = py::cast(kHeaderEncodingString); py::class_(m, "BMailComponent") -.def(py::init(), "", py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) +.def(py::init(), "", py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) .def("ComponentType", &BMailComponent::ComponentType, "") .def("WhatIsThis", &BMailComponent::WhatIsThis, "") .def("IsAttachment", &BMailComponent::IsAttachment, "") -.def("SetHeaderField", py::overload_cast(&BMailComponent::SetHeaderField), "", py::arg("key"), py::arg("value"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding, py::arg("replace_existing")=true) +.def("SetHeaderField", py::overload_cast(&BMailComponent::SetHeaderField), "", py::arg("key"), py::arg("value"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding, py::arg("replace_existing")=true) .def("SetHeaderField", py::overload_cast(&BMailComponent::SetHeaderField), "", py::arg("key"), py::arg("structured_header"), py::arg("replace_existing")=true) .def("HeaderAt", &BMailComponent::HeaderAt, "", py::arg("index")) -.def("HeaderField", py::overload_cast(&BMailComponent::HeaderField), "", py::arg("key"), py::arg("index")=0) -.def("HeaderField", py::overload_cast(&BMailComponent::HeaderField), "", py::arg("key"), py::arg("structured_header"), py::arg("index")=0) +.def("HeaderField", py::overload_cast(&BMailComponent::HeaderField, py::const_), "", py::arg("key"), py::arg("index")=0) +.def("HeaderField", py::overload_cast(&BMailComponent::HeaderField, py::const_), "", py::arg("key"), py::arg("structured_header"), py::arg("index")=0) .def("RemoveHeader", &BMailComponent::RemoveHeader, "", py::arg("key")) .def("GetDecodedData", &BMailComponent::GetDecodedData, "", py::arg("data")) .def("SetDecodedData", &BMailComponent::SetDecodedData, "", py::arg("data")) @@ -40,7 +40,7 @@ py::class_(m, "BMailComponent") ; py::class_(m, "BTextMailComponent") -.def(py::init(), "", py::arg("text")=NULL, py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) +.def(py::init(), "", py::arg("text")=NULL, py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) .def("SetEncoding", &BTextMailComponent::SetEncoding, "", py::arg("encoding"), py::arg("charset")) .def("SetText", &BTextMailComponent::SetText, "", py::arg("text")) .def("AppendText", &BTextMailComponent::AppendText, "", py::arg("text")) From d4f3a441386f0679b1396541f844507dacd281da Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 31 Aug 2024 08:49:16 +0200 Subject: [PATCH 033/115] Update/add MailContainer MailMessage --- Jamfile | 4 ++++ bindings/__init__.py | 3 ++- bindings/mail/MailContainer.cpp | 23 +++++++++++++++++++++-- bindings/mail/MailMessage.cpp | 7 ++++--- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Jamfile b/Jamfile index 9334919..f655683 100644 --- a/Jamfile +++ b/Jamfile @@ -289,6 +289,8 @@ local sourceFiles = mail_encoding.cpp MailDaemon.cpp MailComponent.cpp + MailContainer.cpp + MailMessage.cpp MailAttachment.cpp ; @@ -321,6 +323,8 @@ LINKLIBS on mail_encoding.so = $(LINKLIBS) -lmail ; LINKLIBS on MailDaemon.so = $(LINKLIBS) -lmail ; LINKLIBS on MailComponent.so = $(LINKLIBS) -lmail ; LINKLIBS on MailAttachment.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailContainer.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailMessage.so = $(LINKLIBS) -lmail ; LINKLIBS on NetworkSettings.so = $(LINKLIBS) -lbnetapi ; diff --git a/bindings/__init__.py b/bindings/__init__.py index c3bcde2..c73acda 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -167,7 +167,8 @@ from .mail_encoding import * from .MailComponent import * from .MailDaemon import * - +from .MailContainer import * +from .MailMessage import * from .MailAttachment import * _BWindow=BWindow diff --git a/bindings/mail/MailContainer.cpp b/bindings/mail/MailContainer.cpp index 8f0b50d..992b7e0 100644 --- a/bindings/mail/MailContainer.cpp +++ b/bindings/mail/MailContainer.cpp @@ -7,10 +7,29 @@ namespace py = pybind11; +class PyBMailContainer : public BMailContainer{ + public: + using BMailContainer::BMailContainer; + status_t AddComponent(BMailComponent *component) override { + PYBIND11_OVERLOAD_PURE(status_t, BMailContainer, AddComponent, component); + } + status_t RemoveComponent(BMailComponent *component) override { + PYBIND11_OVERLOAD_PURE(status_t, BMailContainer, RemoveComponent, component); + } + status_t RemoveComponent(int32 index) override { + PYBIND11_OVERLOAD_PURE(status_t, BMailContainer, RemoveComponent, index); + } + BMailComponent *GetComponent(int32 index, bool parse_now = false) override { + PYBIND11_OVERLOAD_PURE(BMailComponent*, BMailContainer, GetComponent, index, parse_now); + } + int32 CountComponents() const override { + PYBIND11_OVERLOAD_PURE(int32, BMailContainer, CountComponents); + } +}; -void define_MailContainer(py::module_& m) +PYBIND11_MODULE(MailContainer, m) { -py::class_(m, "BMailContainer") +py::class_(m, "BMailContainer") .def(py::init(), "", py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) .def("AddComponent", &BMailContainer::AddComponent, "", py::arg("component")) .def("RemoveComponent", py::overload_cast(&BMailContainer::RemoveComponent), "", py::arg("component")) diff --git a/bindings/mail/MailMessage.cpp b/bindings/mail/MailMessage.cpp index 44ef512..132f6ff 100644 --- a/bindings/mail/MailMessage.cpp +++ b/bindings/mail/MailMessage.cpp @@ -4,11 +4,12 @@ #include #include +#include namespace py = pybind11; -void define_MailMessage(py::module_& m) +PYBIND11_MODULE(MailMessage, m) { py::enum_(m, "mail_reply_to_mode", "") .value("B_MAIL_REPLY_TO", mail_reply_to_mode::B_MAIL_REPLY_TO, "") @@ -37,8 +38,8 @@ py::class_(m, "BEmailMessage") .def("SetCC", &BEmailMessage::SetCC, "", py::arg("to"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding) .def("SetBCC", &BEmailMessage::SetBCC, "", py::arg("to")) .def("SetPriority", &BEmailMessage::SetPriority, "", py::arg("to")) -.def("GetName", py::overload_cast(&BEmailMessage::GetName), "", py::arg("name"), py::arg("maxLength")) -.def("GetName", py::overload_cast(&BEmailMessage::GetName), "", py::arg("name")) +.def("GetName", py::overload_cast(&BEmailMessage::GetName,py::const_), "", py::arg("name"), py::arg("maxLength")) +.def("GetName", py::overload_cast(&BEmailMessage::GetName,py::const_), "", py::arg("name")) .def("SendViaAccountFrom", &BEmailMessage::SendViaAccountFrom, "", py::arg("message")) .def("SendViaAccount", py::overload_cast(&BEmailMessage::SendViaAccount), "", py::arg("accountName")) .def("SendViaAccount", py::overload_cast(&BEmailMessage::SendViaAccount), "", py::arg("account")) From 1d2e40066040c3eec08abe802429e898890f8ed3 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 31 Aug 2024 09:00:09 +0200 Subject: [PATCH 034/115] update/add MailSettings.cpp --- Jamfile | 2 ++ bindings/__init__.py | 1 + bindings/mail/MailSettings.cpp | 21 ++++++++++++++------- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Jamfile b/Jamfile index f655683..4104bf5 100644 --- a/Jamfile +++ b/Jamfile @@ -292,6 +292,7 @@ local sourceFiles = MailContainer.cpp MailMessage.cpp MailAttachment.cpp + MailSettings.cpp ; # The .so files can be built from the .cpp files, each .cpp file mapping to @@ -325,6 +326,7 @@ LINKLIBS on MailComponent.so = $(LINKLIBS) -lmail ; LINKLIBS on MailAttachment.so = $(LINKLIBS) -lmail ; LINKLIBS on MailContainer.so = $(LINKLIBS) -lmail ; LINKLIBS on MailMessage.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailSettings.so = $(LINKLIBS) -lmail ; LINKLIBS on NetworkSettings.so = $(LINKLIBS) -lbnetapi ; diff --git a/bindings/__init__.py b/bindings/__init__.py index c73acda..3789dbf 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -170,6 +170,7 @@ from .MailContainer import * from .MailMessage import * from .MailAttachment import * +from .MailSettings import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/mail/MailSettings.cpp b/bindings/mail/MailSettings.cpp index 43febc0..c234edc 100644 --- a/bindings/mail/MailSettings.cpp +++ b/bindings/mail/MailSettings.cpp @@ -4,11 +4,12 @@ #include #include +#include namespace py = pybind11; -void define_MailSettings(py::module_& m) +PYBIND11_MODULE(MailSettings, m) { py::enum_(m, "b_mail_status_window_option", "") .value("B_MAIL_SHOW_STATUS_WINDOW_NEVER", b_mail_status_window_option::B_MAIL_SHOW_STATUS_WINDOW_NEVER, "") @@ -49,12 +50,14 @@ py::class_(m, "BMailSettings") py::class_(m, "BMailAddOnSettings") .def(py::init(), "") .def("Load", &BMailAddOnSettings::Load, "", py::arg("message")) -.def("Save", [](BMailAddOnSettings& self) { +//this below has been autogenerated but why not call save on a previously created BMessage()? +/*.def("Save", [](BMailAddOnSettings& self) { BMessage message; status_t r = self.Save(message); return std::make_tuple(r,message); } -, "") +, "")*/ +.def("Save",&BMailAddOnSettings::Save, "", py::arg("message")) .def("SetAddOnRef", &BMailAddOnSettings::SetAddOnRef, "", py::arg("ref")) .def("AddOnRef", &BMailAddOnSettings::AddOnRef, "") .def("HasBeenModified", &BMailAddOnSettings::HasBeenModified, "") @@ -63,12 +66,14 @@ py::class_(m, "BMailAddOnSettings") py::class_(m, "BMailProtocolSettings") .def(py::init(), "") .def("Load", &BMailProtocolSettings::Load, "", py::arg("message")) -.def("Save", [](BMailProtocolSettings& self) { +//same as above, why not use a previously created BMessage()? +/*.def("Save", [](BMailProtocolSettings& self) { BMessage message; status_t r = self.Save(message); return std::make_tuple(r,message); } -, "") +, "")*/ +.def("Save",&BMailProtocolSettings::Save, "", py::arg("message")) .def("CountFilterSettings", &BMailProtocolSettings::CountFilterSettings, "") .def("AddFilterSettings", &BMailProtocolSettings::AddFilterSettings, "", py::arg("ref")=NULL) .def("RemoveFilterSettings", &BMailProtocolSettings::RemoveFilterSettings, "", py::arg("index")) @@ -112,12 +117,14 @@ py::class_(m, "BMailAccountSettings") py::class_(m, "BMailAccounts") .def(py::init(), "") -.def_static("AccountsPath", [](BMailAccounts& self) { +//same as above, why not use a previously created BPath()? +/*.def_static("AccountsPath", [](BMailAccounts& self) { BPath path; static status_t r = self.AccountsPath(path); return std::make_tuple(r,path); } -, "") +, "")*/ +.def_static("AccountsPath", &BMailAccounts::AccountsPath, "", py::arg("path")) .def("CountAccounts", &BMailAccounts::CountAccounts, "") .def("AccountAt", &BMailAccounts::AccountAt, "", py::arg("index")) .def("AccountByID", &BMailAccounts::AccountByID, "", py::arg("id")) From 16fee2453ba6b39642a55f9045f696a17fd9b76d Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 31 Aug 2024 16:45:05 +0200 Subject: [PATCH 035/115] Update WriteAt in File.cpp --- bindings/storage/File.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bindings/storage/File.cpp b/bindings/storage/File.cpp index 82a9568..143a5d0 100644 --- a/bindings/storage/File.cpp +++ b/bindings/storage/File.cpp @@ -78,7 +78,13 @@ py::class_(m, "BFile") size_t length = info.size; return self.Write(data,length); }, "",py::arg("buffer")) -.def("WriteAt", &BFile::WriteAt, "", py::arg("location"), py::arg("buffer"), py::arg("size")) +//.def("WriteAt", &BFile::WriteAt, "", py::arg("location"), py::arg("buffer"), py::arg("size")) +.def("WriteAt", [](BFile& self, off_t location, py::buffer buffer){ + py::buffer_info info = buffer.request(); + const void* data = info.ptr; + size_t length = info.size; + return self.WriteAt(location,data,length); +}, "",py::arg("location"),py::arg("buffer")) .def("Seek", &BFile::Seek, "", py::arg("offset"), py::arg("seekMode")) .def("Position", &BFile::Position, "") .def("SetSize", &BFile::SetSize, "", py::arg("size")) From e60fb04d54965bdae5a42211c9ab843bb4fe4bf5 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 31 Aug 2024 16:45:32 +0200 Subject: [PATCH 036/115] Add BitmapStream.cpp --- Jamfile | 3 ++ bindings/__init__.py | 1 + bindings/translation/BitmapStream.cpp | 61 ++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/Jamfile b/Jamfile index 4104bf5..b743fff 100644 --- a/Jamfile +++ b/Jamfile @@ -253,6 +253,7 @@ local sourceFiles = TranslatorRoster.cpp TranslationUtils.cpp Translator.cpp + BitmapStream.cpp stat.cpp @@ -310,6 +311,8 @@ LINKLIBS on TranslationDefs.so = $(LINKLIBS) -ltranslation ; LINKLIBS on TranslatorRoster.so = $(LINKLIBS) -ltranslation ; LINKLIBS on TranslationUtils.so = $(LINKLIBS) -ltranslation ; LINKLIBS on Translator.so = $(LINKLIBS) -ltranslation ; +LINKLIBS on BitmapStream.so = $(LINKLIBS) -ltranslation ; + LINKLIBS on ScreenSaver.so = $(LINKLIBS) -lscreensaver ; #LINKLIBS on MimeSnifferAddon.so = $(LINKLIBS) -lstoragekit ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 3789dbf..deb3cb0 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -139,6 +139,7 @@ from .TranslatorRoster import * from .TranslationUtils import * from .Translator import * +from .BitmapStream import * from .stat import * #from .ScreenSaver import * diff --git a/bindings/translation/BitmapStream.cpp b/bindings/translation/BitmapStream.cpp index a37123f..b7621ff 100644 --- a/bindings/translation/BitmapStream.cpp +++ b/bindings/translation/BitmapStream.cpp @@ -4,21 +4,72 @@ #include #include +#include namespace py = pybind11; +/* +status_t DetachBitmap_wrapper(BBitmapStream& self, std::vector _bitmap) { + return self.DetachBitmap(_bitmap.data()); +}*/ +class PyBBitmapStream : public BBitmapStream{ + public: + using BBitmapStream::BBitmapStream; + ssize_t ReadAt(off_t offset, void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BBitmapStream, ReadAt, offset, buffer, size); + } + ssize_t WriteAt(off_t offset, const void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BBitmapStream, WriteAt, offset, buffer, size); + } + off_t Seek(off_t position, uint32 seekMode) override { + PYBIND11_OVERLOAD(off_t, BBitmapStream, Seek, position, seekMode); + } + off_t Position() const override { + PYBIND11_OVERLOAD(off_t, BBitmapStream, Position); + } + off_t Size() const override { + PYBIND11_OVERLOAD(off_t, BBitmapStream, Size); + } + status_t SetSize(off_t size) override { + PYBIND11_OVERLOAD(status_t, BBitmapStream, SetSize, size); + } +}; -void define_BitmapStream(py::module_& m) +PYBIND11_MODULE(BitmapStream,m) { -py::class_(m, "BBitmapStream") +py::class_(m, "BBitmapStream") .def(py::init(), "", py::arg("bitmap")=NULL) -.def("ReadAt", &BBitmapStream::ReadAt, "", py::arg("offset"), py::arg("buffer"), py::arg("size")) -.def("WriteAt", &BBitmapStream::WriteAt, "", py::arg("offset"), py::arg("buffer"), py::arg("size")) +//.def("ReadAt", &BBitmapStream::ReadAt, "", py::arg("offset"), py::arg("buffer"), py::arg("size")) //convert buffer +.def("ReadAt", [](BBitmapStream& self, off_t offset, size_t size)->py::tuple{ + std::vectorbuffer(size); + ssize_t bytesRead = self.ReadAt(offset, buffer.data(), size); + py::bytes pyBytes(buffer.data(),bytesRead); + return py::make_tuple(pyBytes, bytesRead); +},"", py::arg("offset"),py::arg("size")) +//.def("WriteAt", &BBitmapStream::WriteAt, "", py::arg("offset"), py::arg("buffer"), py::arg("size")) //convert buffer +.def("WriteAt", [](BBitmapStream& self, off_t offset, py::buffer buffer){ + py::buffer_info info = buffer.request(); + const void* data = info.ptr; + size_t length = info.size; + return self.WriteAt(offset,data,length); +}, "",py::arg("offset"),py::arg("buffer")) .def("Seek", &BBitmapStream::Seek, "", py::arg("position"), py::arg("seekMode")) .def("Position", &BBitmapStream::Position, "") .def("Size", &BBitmapStream::Size, "") .def("SetSize", &BBitmapStream::SetSize, "", py::arg("size")) -.def("DetachBitmap", &BBitmapStream::DetachBitmap, "", py::arg("_bitmap")) +//.def("DetachBitmap", &BBitmapStream::DetachBitmap, "", py::arg("_bitmap")) +//.def("DetachBitmap", &DetachBitmap_wrapper, "", py::arg("_bitmap")) //ok, it compiles, but... How do we pass the std::vector called _bitmap? +.def("DetachBitmap", [](BBitmapStream& self) { + BBitmap* bitmap = nullptr; + status_t status = self.DetachBitmap(&bitmap); + + if (bitmap != nullptr) { + return py::make_tuple(status, py::cast(bitmap)); + } else { + return py::make_tuple(status, py::none()); + } +}) + ; From a0d56da6ca1b5701a5bd9f5e105a0553ac1787ad Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 1 Sep 2024 07:04:59 +0200 Subject: [PATCH 037/115] Add TranslatorFormats.cpp --- Jamfile | 2 + bindings/__init__.py | 1 + bindings/translation/TranslatorFormats.cpp | 83 ++++++++++++++-------- 3 files changed, 56 insertions(+), 30 deletions(-) diff --git a/Jamfile b/Jamfile index b743fff..3fb7f59 100644 --- a/Jamfile +++ b/Jamfile @@ -254,6 +254,7 @@ local sourceFiles = TranslationUtils.cpp Translator.cpp BitmapStream.cpp + TranslatorFormats.cpp stat.cpp @@ -311,6 +312,7 @@ LINKLIBS on TranslationDefs.so = $(LINKLIBS) -ltranslation ; LINKLIBS on TranslatorRoster.so = $(LINKLIBS) -ltranslation ; LINKLIBS on TranslationUtils.so = $(LINKLIBS) -ltranslation ; LINKLIBS on Translator.so = $(LINKLIBS) -ltranslation ; +LINKLIBS on TranslatorFormats.so = $(LINKLIBS) -ltranslation ; LINKLIBS on BitmapStream.so = $(LINKLIBS) -ltranslation ; diff --git a/bindings/__init__.py b/bindings/__init__.py index deb3cb0..f2ca13f 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -140,6 +140,7 @@ from .TranslationUtils import * from .Translator import * from .BitmapStream import * +from .TranslatorFormats import * from .stat import * #from .ScreenSaver import * diff --git a/bindings/translation/TranslatorFormats.cpp b/bindings/translation/TranslatorFormats.cpp index 5941c9d..a231030 100644 --- a/bindings/translation/TranslatorFormats.cpp +++ b/bindings/translation/TranslatorFormats.cpp @@ -7,8 +7,7 @@ namespace py = pybind11; - -void define_TranslatorFormats(py::module_& m) +PYBIND11_MODULE(TranslatorFormats,m) { py::enum_(m, "TranslatorGroups", "") .value("B_TRANSLATOR_BITMAP", TranslatorGroups::B_TRANSLATOR_BITMAP, "") @@ -21,46 +20,61 @@ py::enum_(m, "TranslatorGroups", "") .value("B_TRANSLATOR_ANY_TYPE", TranslatorGroups::B_TRANSLATOR_ANY_TYPE, "") .export_values(); -m.attr("B_GIF_FORMAT") = py::cast(B_GIF_FORMAT); -m.attr("B_JPEG_FORMAT") = py::cast(B_JPEG_FORMAT); -m.attr("B_PNG_FORMAT") = py::cast(B_PNG_FORMAT); -m.attr("B_PPM_FORMAT") = py::cast(B_PPM_FORMAT); -m.attr("B_TGA_FORMAT") = py::cast(B_TGA_FORMAT); -m.attr("B_BMP_FORMAT") = py::cast(B_BMP_FORMAT); -m.attr("B_TIFF_FORMAT") = py::cast(B_TIFF_FORMAT); -m.attr("B_WEBP_FORMAT") = py::cast(B_WEBP_FORMAT); -m.attr("B_DXF_FORMAT") = py::cast(B_DXF_FORMAT); -m.attr("B_EPS_FORMAT") = py::cast(B_EPS_FORMAT); -m.attr("B_PICT_FORMAT") = py::cast(B_PICT_FORMAT); -m.attr("B_WAV_FORMAT") = py::cast(B_WAV_FORMAT); -m.attr("B_AIFF_FORMAT") = py::cast(B_AIFF_FORMAT); -m.attr("B_CD_FORMAT") = py::cast(B_CD_FORMAT); -m.attr("B_AU_FORMAT") = py::cast(B_AU_FORMAT); -m.attr("B_STYLED_TEXT_FORMAT") = py::cast(B_STYLED_TEXT_FORMAT); +m.attr("B_GIF_FORMAT") = 'GIF ';//py::cast(B_GIF_FORMAT); +m.attr("B_JPEG_FORMAT") = 'JPEG';//py::cast(B_JPEG_FORMAT); +m.attr("B_PNG_FORMAT") = 'PNG ';//py::cast(B_PNG_FORMAT); +m.attr("B_PPM_FORMAT") = 'PPM ';//py::cast(B_PPM_FORMAT); +m.attr("B_TGA_FORMAT") = 'TGA ';//py::cast(B_TGA_FORMAT); +m.attr("B_BMP_FORMAT") = 'BMP ';//py::cast(B_BMP_FORMAT); +m.attr("B_TIFF_FORMAT") = 'TIFF';//py::cast(B_TIFF_FORMAT); +m.attr("B_WEBP_FORMAT") = 'WebP';//py::cast(B_WEBP_FORMAT); +m.attr("B_DXF_FORMAT") = 'DXF ';//py::cast(B_DXF_FORMAT); +m.attr("B_EPS_FORMAT") = 'EPS ';//py::cast(B_EPS_FORMAT); +m.attr("B_PICT_FORMAT") = 'PICT';//py::cast(B_PICT_FORMAT); +m.attr("B_WAV_FORMAT") = 'WAV ';//py::cast(B_WAV_FORMAT); +m.attr("B_AIFF_FORMAT") = 'AIFF';//py::cast(B_AIFF_FORMAT); +m.attr("B_CD_FORMAT") = 'CD ';//py::cast(B_CD_FORMAT); +m.attr("B_AU_FORMAT") = 'AU ';//py::cast(B_AU_FORMAT); +m.attr("B_STYLED_TEXT_FORMAT") = 'STXT';//py::cast(B_STYLED_TEXT_FORMAT); + + +/* from TranslatorRoster.cpp in translation kit +char B_TRANSLATOR_EXT_HEADER_ONLY[] = "/headerOnly"; +char B_TRANSLATOR_EXT_DATA_ONLY[] = "/dataOnly"; +char B_TRANSLATOR_EXT_COMMENT[] = "/comment"; +char B_TRANSLATOR_EXT_TIME[] = "/time"; +char B_TRANSLATOR_EXT_FRAME[] = "/frame"; +char B_TRANSLATOR_EXT_BITMAP_RECT[] = "bits/Rect"; +char B_TRANSLATOR_EXT_BITMAP_COLOR_SPACE[] = "bits/space"; +char B_TRANSLATOR_EXT_BITMAP_PALETTE[] = "bits/palette"; +char B_TRANSLATOR_EXT_SOUND_CHANNEL[] = "nois/channel"; +char B_TRANSLATOR_EXT_SOUND_MONO[] = "nois/mono"; +char B_TRANSLATOR_EXT_SOUND_MARKER[] = "nois/marker"; +char B_TRANSLATOR_EXT_SOUND_LOOP[] = "nois/loop";*/ -m.attr("B_TRANSLATOR_EXT_HEADER_ONLY") = py::cast(B_TRANSLATOR_EXT_HEADER_ONLY); +m.attr("B_TRANSLATOR_EXT_HEADER_ONLY") = "/headerOnly";//py::cast(B_TRANSLATOR_EXT_HEADER_ONLY); -m.attr("B_TRANSLATOR_EXT_DATA_ONLY") = py::cast(B_TRANSLATOR_EXT_DATA_ONLY); +m.attr("B_TRANSLATOR_EXT_DATA_ONLY") = "/dataOnly";//py::cast(B_TRANSLATOR_EXT_DATA_ONLY); -m.attr("B_TRANSLATOR_EXT_COMMENT") = py::cast(B_TRANSLATOR_EXT_COMMENT); +m.attr("B_TRANSLATOR_EXT_COMMENT") = "/comment";//py::cast(B_TRANSLATOR_EXT_COMMENT); -m.attr("B_TRANSLATOR_EXT_TIME") = py::cast(B_TRANSLATOR_EXT_TIME); +m.attr("B_TRANSLATOR_EXT_TIME") = "/time";//py::cast(B_TRANSLATOR_EXT_TIME); -m.attr("B_TRANSLATOR_EXT_FRAME") = py::cast(B_TRANSLATOR_EXT_FRAME); +m.attr("B_TRANSLATOR_EXT_FRAME") = "/frame";//py::cast(B_TRANSLATOR_EXT_FRAME); -m.attr("B_TRANSLATOR_EXT_BITMAP_RECT") = py::cast(B_TRANSLATOR_EXT_BITMAP_RECT); +m.attr("B_TRANSLATOR_EXT_BITMAP_RECT") = "bits/Rect";//py::cast(B_TRANSLATOR_EXT_BITMAP_RECT); -m.attr("B_TRANSLATOR_EXT_BITMAP_COLOR_SPACE") = py::cast(B_TRANSLATOR_EXT_BITMAP_COLOR_SPACE); +m.attr("B_TRANSLATOR_EXT_BITMAP_COLOR_SPACE") = "bits/space";//py::cast(B_TRANSLATOR_EXT_BITMAP_COLOR_SPACE); -m.attr("B_TRANSLATOR_EXT_BITMAP_PALETTE") = py::cast(B_TRANSLATOR_EXT_BITMAP_PALETTE); +m.attr("B_TRANSLATOR_EXT_BITMAP_PALETTE") = "bits/palette";//py::cast(B_TRANSLATOR_EXT_BITMAP_PALETTE); -m.attr("B_TRANSLATOR_EXT_SOUND_CHANNEL") = py::cast(B_TRANSLATOR_EXT_SOUND_CHANNEL); +m.attr("B_TRANSLATOR_EXT_SOUND_CHANNEL") = "nois/channel";//py::cast(B_TRANSLATOR_EXT_SOUND_CHANNEL); -m.attr("B_TRANSLATOR_EXT_SOUND_MONO") = py::cast(B_TRANSLATOR_EXT_SOUND_MONO); +m.attr("B_TRANSLATOR_EXT_SOUND_MONO") = "nois/mono";//py::cast(B_TRANSLATOR_EXT_SOUND_MONO); -m.attr("B_TRANSLATOR_EXT_SOUND_MARKER") = py::cast(B_TRANSLATOR_EXT_SOUND_MARKER); +m.attr("B_TRANSLATOR_EXT_SOUND_MARKER") = "nois/marker";//py::cast(B_TRANSLATOR_EXT_SOUND_MARKER); -m.attr("B_TRANSLATOR_EXT_SOUND_LOOP") = py::cast(B_TRANSLATOR_EXT_SOUND_LOOP); +m.attr("B_TRANSLATOR_EXT_SOUND_LOOP") = "nois/loop";//py::cast(B_TRANSLATOR_EXT_SOUND_LOOP); py::class_(m, "TranslatorBitmap") .def_readwrite("magic", &TranslatorBitmap::magic, "") @@ -84,16 +98,25 @@ py::class_(m, "TranslatorStyledTextRecordHeade ; py::class_(m, "TranslatorStyledTextStreamHeader") +.def_property_readonly("STREAM_HEADER_MAGIC", []() { + return 'STXT'; +},"") .def_readwrite("header", &TranslatorStyledTextStreamHeader::header, "") .def_readwrite("version", &TranslatorStyledTextStreamHeader::version, "") ; py::class_(m, "TranslatorStyledTextTextHeader") +.def_property_readonly("TEXT_HEADER_MAGIC", []() { + return 'TEXT'; +},"") .def_readwrite("header", &TranslatorStyledTextTextHeader::header, "") .def_readwrite("charset", &TranslatorStyledTextTextHeader::charset, "") ; py::class_(m, "TranslatorStyledTextStyleHeader") +.def_property_readonly("STYLE_HEADER_MAGIC", []() { + return 'STYL'; +},"") .def_readwrite("header", &TranslatorStyledTextStyleHeader::header, "") .def_readwrite("apply_offset", &TranslatorStyledTextStyleHeader::apply_offset, "") .def_readwrite("apply_length", &TranslatorStyledTextStyleHeader::apply_length, "") From 9cfc71555e88c0a0bf463011b0eded16aa4ac259 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 1 Sep 2024 08:13:17 +0200 Subject: [PATCH 038/115] add overrides to MailAttachment --- bindings/mail/MailAttachment.cpp | 76 +++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/bindings/mail/MailAttachment.cpp b/bindings/mail/MailAttachment.cpp index e980701..479d225 100644 --- a/bindings/mail/MailAttachment.cpp +++ b/bindings/mail/MailAttachment.cpp @@ -10,6 +10,78 @@ namespace py = pybind11; +class PyBSimpleMailAttachment : public BSimpleMailAttachment{ + public: + using BSimpleMailAttachment::BSimpleMailAttachment; + status_t SetTo(BFile *file, bool delete_file_when_done = false) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, SetTo, file, delete_file_when_done); + } + status_t SetTo(entry_ref *ref) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, SetTo, ref); + } + status_t InitCheck() override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, InitCheck); + } + void SetFileName(const char *name) override { + PYBIND11_OVERLOAD(void, BSimpleMailAttachment, SetFileName, name); + } + status_t FileName(char *name) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, FileName, name); + } + status_t GetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, GetDecodedData, data); + } + status_t SetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, SetDecodedData, data); + } + BPositionIO *GetDecodedData() override { + PYBIND11_OVERLOAD(BPositionIO*, BSimpleMailAttachment, GetDecodedData); + } + status_t SetDecodedData(const void *data, size_t length /* data to attach */) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, SetDecodedData, data, length); + } + status_t SetToRFC822(BPositionIO *data, size_t length, bool parse_now = false) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, SetToRFC822, data, length, parse_now); + } + status_t RenderToRFC822(BPositionIO *render_to) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, RenderToRFC822, render_to); + } +}; + +class PyBAttributedMailAttachment : public BAttributedMailAttachment{ + public: + using BAttributedMailAttachment::BAttributedMailAttachment; + status_t SetTo(BFile *file, bool delete_file_when_done = false) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, SetTo, file, delete_file_when_done); + } + status_t SetTo(entry_ref *ref) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, SetTo, ref); + } + status_t InitCheck() override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, InitCheck); + } + void SetFileName(const char *name) override { + PYBIND11_OVERLOAD(void, BAttributedMailAttachment, SetFileName, name); + } + status_t FileName(char *name) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, FileName, name); + } + status_t GetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, GetDecodedData, data); + } + status_t SetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, SetDecodedData, data); + } + status_t SetToRFC822(BPositionIO *data, size_t length, bool parse_now = false) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, SetToRFC822, data, length, parse_now); + } + status_t RenderToRFC822(BPositionIO *render_to) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, RenderToRFC822, render_to); + } + status_t MIMEType(BMimeType *mime) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, MIMEType, mime); + } +}; PYBIND11_MODULE(MailAttachment, m) { @@ -21,7 +93,7 @@ py::class_(m, "BMailAttachment") .def("InitCheck", &BMailAttachment::InitCheck, "") ; -py::class_(m, "BSimpleMailAttachment") +py::class_(m, "BSimpleMailAttachment") .def(py::init(), "", py::arg("dataToAttach"), py::arg("encoding")=base64) .def(py::init(), "", py::arg("dataToAttach"), py::arg("lengthOfData"), py::arg("encoding")=base64) .def(py::init(), "", py::arg("file"), py::arg("delete_when_done")) @@ -43,7 +115,7 @@ py::class_(m, "BSimpleMailAttachment") .def("RenderToRFC822", &BSimpleMailAttachment::RenderToRFC822, "", py::arg("render_to")) ; -py::class_(m, "BAttributedMailAttachment") +py::class_(m, "BAttributedMailAttachment") .def(py::init(), "", py::arg("file"), py::arg("delete_when_done")) .def(py::init(), "", py::arg("ref")) .def(py::init(), "") From 6aa06a8edb1c6587eb0e75525dd21920c379698e Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 1 Sep 2024 08:18:38 +0200 Subject: [PATCH 039/115] add overrides to MailComponent.cpp --- bindings/mail/MailComponent.cpp | 41 +++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/bindings/mail/MailComponent.cpp b/bindings/mail/MailComponent.cpp index 3ecaf2b..fa893f2 100644 --- a/bindings/mail/MailComponent.cpp +++ b/bindings/mail/MailComponent.cpp @@ -8,6 +8,43 @@ namespace py = pybind11; +class PyBMailComponent : public BMailComponent{ + public: + using BMailComponent::BMailComponent; + status_t GetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BMailComponent, GetDecodedData, data); + } + status_t SetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BMailComponent, SetDecodedData, data); + } + status_t SetToRFC822(BPositionIO *data, size_t length, bool parse_now = false) override { + PYBIND11_OVERLOAD(status_t, BMailComponent, SetToRFC822, data, length, parse_now); + } + status_t RenderToRFC822(BPositionIO *render_to) override { + PYBIND11_OVERLOAD(status_t, BMailComponent, RenderToRFC822, render_to); + } + status_t MIMEType(BMimeType *mime) override { + PYBIND11_OVERLOAD(status_t, BMailComponent, MIMEType, mime); + } +}; + +class PyBTextMailComponent : public BTextMailComponent{ + public: + using BTextMailComponent::BTextMailComponent; + status_t GetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BTextMailComponent, GetDecodedData, data); + } + status_t SetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BTextMailComponent, SetDecodedData, data); + } + status_t SetToRFC822(BPositionIO *data, size_t length, bool parse_now = false) override { + PYBIND11_OVERLOAD(status_t, BTextMailComponent, SetToRFC822, data, length, parse_now); + } + status_t RenderToRFC822(BPositionIO *render_to) override { + PYBIND11_OVERLOAD(status_t, BTextMailComponent, RenderToRFC822, render_to); + } +}; + PYBIND11_MODULE(MailComponent, m) { py::enum_(m, "component_type", "") @@ -21,7 +58,7 @@ m.attr("kHeaderCharsetString") = py::cast(kHeaderCharsetString); m.attr("kHeaderEncodingString") = py::cast(kHeaderEncodingString); -py::class_(m, "BMailComponent") +py::class_(m, "BMailComponent") .def(py::init(), "", py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) .def("ComponentType", &BMailComponent::ComponentType, "") .def("WhatIsThis", &BMailComponent::WhatIsThis, "") @@ -39,7 +76,7 @@ py::class_(m, "BMailComponent") .def("MIMEType", &BMailComponent::MIMEType, "", py::arg("mime")) ; -py::class_(m, "BTextMailComponent") +py::class_(m, "BTextMailComponent") .def(py::init(), "", py::arg("text")=NULL, py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) .def("SetEncoding", &BTextMailComponent::SetEncoding, "", py::arg("encoding"), py::arg("charset")) .def("SetText", &BTextMailComponent::SetText, "", py::arg("text")) From 53e2d6815dbdebaaa7bf61970d961b858ae03a3f Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 1 Sep 2024 08:26:22 +0200 Subject: [PATCH 040/115] add BMIMEMultipartMailContainer overrides to MailContainer.cpp --- bindings/mail/MailContainer.cpp | 34 ++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/bindings/mail/MailContainer.cpp b/bindings/mail/MailContainer.cpp index 992b7e0..7cc1624 100644 --- a/bindings/mail/MailContainer.cpp +++ b/bindings/mail/MailContainer.cpp @@ -27,6 +27,38 @@ class PyBMailContainer : public BMailContainer{ } }; +class PyBMIMEMultipartMailContainer : public BMIMEMultipartMailContainer{ + public: + using BMIMEMultipartMailContainer::BMIMEMultipartMailContainer; + status_t AddComponent(BMailComponent *component) override { + PYBIND11_OVERLOAD(status_t, BMIMEMultipartMailContainer, AddComponent, component); + } + status_t RemoveComponent(BMailComponent *component) override { + PYBIND11_OVERLOAD(status_t, BMIMEMultipartMailContainer, RemoveComponent, component); + } + status_t RemoveComponent(int32 index) override { + PYBIND11_OVERLOAD(status_t, BMIMEMultipartMailContainer, RemoveComponent, index); + } + BMailComponent *GetComponent(int32 index, bool parse_now = false) override { + PYBIND11_OVERLOAD(BMailComponent* , BMIMEMultipartMailContainer, GetComponent, index, parse_now); + } + int32 CountComponents() const override { + PYBIND11_OVERLOAD(int32, BMIMEMultipartMailContainer, CountComponents); + } + status_t GetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BMIMEMultipartMailContainer, GetDecodedData, data); + } + status_t SetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BMIMEMultipartMailContainer, SetDecodedData, data); + } + status_t SetToRFC822(BPositionIO *data, size_t length, bool parse_now = false) override { + PYBIND11_OVERLOAD(status_t, BMIMEMultipartMailContainer, SetToRFC822, data, length, parse_now); + } + status_t RenderToRFC822(BPositionIO *render_to) override { + PYBIND11_OVERLOAD(status_t, BMIMEMultipartMailContainer, RenderToRFC822, render_to); + } +}; + PYBIND11_MODULE(MailContainer, m) { py::class_(m, "BMailContainer") @@ -38,7 +70,7 @@ py::class_(m, "BMailContainer" .def("CountComponents", &BMailContainer::CountComponents, "") ; -py::class_(m, "BMIMEMultipartMailContainer") +py::class_(m, "BMIMEMultipartMailContainer") .def(py::init(), "", py::arg("boundary")=NULL, py::arg("this_is_an_MIME_message_text")=NULL, py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) .def(py::init(), "") .def("SetBoundary", &BMIMEMultipartMailContainer::SetBoundary, "", py::arg("boundary")) From 7807b04cfe4bfcceac45ea8a754023fb3021c405 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 1 Sep 2024 08:32:58 +0200 Subject: [PATCH 041/115] Add MailMessage overrides --- bindings/mail/MailMessage.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/bindings/mail/MailMessage.cpp b/bindings/mail/MailMessage.cpp index 132f6ff..a89bc95 100644 --- a/bindings/mail/MailMessage.cpp +++ b/bindings/mail/MailMessage.cpp @@ -8,6 +8,31 @@ namespace py = pybind11; +class PyBEmailMessage : public BEmailMessage{ + public: + using BEmailMessage::BEmailMessage; + status_t AddComponent(BMailComponent *component) override { + PYBIND11_OVERLOAD(status_t, BEmailMessage, AddComponent, component); + } + status_t RemoveComponent(BMailComponent *component) override { + PYBIND11_OVERLOAD(status_t, BEmailMessage, RemoveComponent, component); + } + status_t RemoveComponent(int32 index) override { + PYBIND11_OVERLOAD(status_t, BEmailMessage, RemoveComponent, index); + } + BMailComponent* GetComponent(int32 index, bool parseNow = false) override { + PYBIND11_OVERLOAD(BMailComponent*, BEmailMessage, GetComponent, index, parseNow); + } + int32 CountComponents() const override { + PYBIND11_OVERLOAD(int32, BEmailMessage, CountComponents); + } + status_t SetToRFC822(BPositionIO* data, size_t length, bool parseNow = false) override { + PYBIND11_OVERLOAD(status_t, BEmailMessage, SetToRFC822, data, length, parseNow); + } + status_t RenderToRFC822(BPositionIO* renderTo) override { + PYBIND11_OVERLOAD(status_t, BEmailMessage, RenderToRFC822, renderTo); + } +}; PYBIND11_MODULE(MailMessage, m) { @@ -17,7 +42,7 @@ py::enum_(m, "mail_reply_to_mode", "") .value("B_MAIL_REPLY_TO_SENDER", mail_reply_to_mode::B_MAIL_REPLY_TO_SENDER, "") .export_values(); -py::class_(m, "BEmailMessage") +py::class_(m, "BEmailMessage") .def(py::init(), "", py::arg("stream")=NULL, py::arg("ownStream")=false, py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) .def(py::init(), "", py::arg("ref"), py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) .def("InitCheck", &BEmailMessage::InitCheck, "") From 554ae787a47edd2d600fee221f1fa36640cd6497 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 1 Sep 2024 08:38:25 +0200 Subject: [PATCH 042/115] add BMailAddOnSettings and BMailProtocolSettings overrides --- bindings/mail/MailSettings.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/bindings/mail/MailSettings.cpp b/bindings/mail/MailSettings.cpp index c234edc..6a2a8c1 100644 --- a/bindings/mail/MailSettings.cpp +++ b/bindings/mail/MailSettings.cpp @@ -8,6 +8,33 @@ namespace py = pybind11; +class PyBMailAddOnSettings : public BMailAddOnSettings{ + public: + using BMailAddOnSettings::BMailAddOnSettings; + status_t Load(const BMessage& message) override { + PYBIND11_OVERLOAD(status_t, BMailAddOnSettings, Load, message); + } + status_t Save(BMessage& message) override { + PYBIND11_OVERLOAD(status_t, BMailAddOnSettings, Save, message); + } + bool HasBeenModified() const override { + PYBIND11_OVERLOAD(bool, BMailAddOnSettings, HasBeenModified); + } +}; + +class PyBMailProtocolSettings : public BMailProtocolSettings{ + public: + using BMailProtocolSettings::BMailProtocolSettings; + status_t Load(const BMessage& message) override { + PYBIND11_OVERLOAD(status_t, BMailProtocolSettings, Load, message); + } + status_t Save(BMessage& message) override { + PYBIND11_OVERLOAD(status_t, BMailProtocolSettings, Save, message); + } + bool HasBeenModified() const override { + PYBIND11_OVERLOAD(bool, BMailProtocolSettings, HasBeenModified); + } +}; PYBIND11_MODULE(MailSettings, m) { @@ -47,7 +74,7 @@ py::class_(m, "BMailSettings") .def("SetDefaultOutboundAccount", &BMailSettings::SetDefaultOutboundAccount, "", py::arg("to")) ; -py::class_(m, "BMailAddOnSettings") +py::class_(m, "BMailAddOnSettings") .def(py::init(), "") .def("Load", &BMailAddOnSettings::Load, "", py::arg("message")) //this below has been autogenerated but why not call save on a previously created BMessage()? @@ -63,7 +90,7 @@ py::class_(m, "BMailAddOnSettings") .def("HasBeenModified", &BMailAddOnSettings::HasBeenModified, "") ; -py::class_(m, "BMailProtocolSettings") +py::class_(m, "BMailProtocolSettings") .def(py::init(), "") .def("Load", &BMailProtocolSettings::Load, "", py::arg("message")) //same as above, why not use a previously created BMessage()? From 6408aa6a36b04f1f77bafe39468af5e2d75f3067 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 1 Sep 2024 10:34:01 +0200 Subject: [PATCH 043/115] Updates to check for Archivable --- bindings/support/Archivable.cpp | 56 +++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/bindings/support/Archivable.cpp b/bindings/support/Archivable.cpp index e8efd50..fcd8f16 100644 --- a/bindings/support/Archivable.cpp +++ b/bindings/support/Archivable.cpp @@ -28,27 +28,15 @@ py::class_(m, "BArchivable") py::class_(m, "BArchiver") .def(py::init(), "", py::arg("archive")) .def("AddArchivable", &BArchiver::AddArchivable, "", py::arg("name"), py::arg("archivable"), py::arg("deep")=true) -//.def("GetTokenForArchivable", py::overload_cast(&BArchiver::GetTokenForArchivable), "", py::arg("archivable"), py::arg("_token")) -//.def("GetTokenForArchivable", py::overload_cast(&BArchiver::GetTokenForArchivable), "", py::arg("archivable"), py::arg("deep"), py::arg("_token")) +.def("GetTokenForArchivable", py::overload_cast(&BArchiver::GetTokenForArchivable), "", py::arg("archivable"), py::arg("_token")) //TODO Check this function +.def("GetTokenForArchivable", py::overload_cast(&BArchiver::GetTokenForArchivable), "", py::arg("archivable"), py::arg("deep"), py::arg("_token")) //TODO Check this function .def("IsArchived", &BArchiver::IsArchived, "", py::arg("archivable")) .def("Finish", &BArchiver::Finish, "", py::arg("err")=B_OK) .def("ArchiveMessage", &BArchiver::ArchiveMessage, "") ; -/* my attempt to import ownership_policy -py::enum_(m, "ownership_policy") -.value("B_ASSUME_OWNERSHIP", BUnarchiver::ownership_policy::B_ASSUME_OWNERSHIP, "") -.value("B_DONT_ASSUME_OWNERSHIP", BUnarchiver::ownership_policy::B_DONT_ASSUME_OWNERSHIP, "") -.export_values(); -*/ py::class_(m, "BUnarchiver") .def(py::init(), "", py::arg("archive")) -/* -.def("ownership_policy", py::enum_(m,"ownership_policy") - .value("B_ASSUME_OWNERSHIP",BUnarchiver::ownership_policy::B_ASSUME_OWNERSHIP) - .value("B_DONT_ASSUME_OWNERSHIP", BUnarchiver::ownership_policy::B_DONT_ASSUME_OWNERSHIP) -) -*/ /*.def("GetObject", [](BUnarchiver& self,int token) { T * object; inline status_t r = self.GetObject(token, object); @@ -101,20 +89,50 @@ py::class_(m, "BUnarchiver") }, "", py::arg("archive"))*/ ; -/* these do not generate errors on compile-time +///* these do not generate errors on compile-time m.def("instantiate_object", py::overload_cast(&instantiate_object), "", py::arg("from"), py::arg("id")); m.def("instantiate_object", py::overload_cast(&instantiate_object), "", py::arg("from")); m.def("validate_instantiation", &validate_instantiation, "", py::arg("from"), py::arg("className")); -*/ +//*/ //m.def("find_instantiation_func", py::overload_cast(&find_instantiation_func), "", py::arg("className"), py::arg("signature")); +//TODO: check these 3 functions +m.def("find_instantiation_func", [](const char* className, const char* signature) -> py::object { + instantiation_func func = find_instantiation_func(className, signature); + if (func == nullptr) { + return py::none(); + } + return py::cpp_function([func](BMessage* msg) -> BArchivable* { + return func(msg); + }); +}, py::arg("className"), py::arg("signature")); //m.def("find_instantiation_func", py::overload_cast(&find_instantiation_func), "", py::arg("className")); +m.def("find_instantiation_func", [](const char* className) -> py::object { + instantiation_func func = find_instantiation_func(className); + if (func == nullptr) { + return py::none(); + } + + return py::cpp_function([func](BMessage* msg) -> BArchivable* { + return func(msg); + }); +}, py::arg("className")); //m.def("find_instantiation_func", py::overload_cast(&find_instantiation_func), "", py::arg("archive")); +m.def("find_instantiation_func", [](BMessage* archive) -> py::object { + instantiation_func func = find_instantiation_func(archive); + if (func == nullptr) { + return py::none(); + } + + return py::cpp_function([func](BMessage* msg) -> BArchivable* { + return func(msg); + }); +}, py::arg("archive")); /* m.def(">", [](const char * name,int index,ownership_policy owning) { BArchivable * archivable; @@ -147,4 +165,10 @@ m.def(">", [](BMessage * from) { //m.attr("BArchiveManager") = py::cast(BArchiveManager); //m.attr("BUnarchiveManager") = py::cast(BUnarchiveManager); + +//my attempt to add ownership_policy: +//m.attr("B_ASSUME_OWNERSHIP") = py::cast(BUnarchiver::ownership_policy::B_ASSUME_OWNERSHIP); +m.attr("B_ASSUME_OWNERSHIP") = 0; +//m.attr("B_DONT_ASSUME_OWNERSHIP") = py::cast(BUnarchiver::ownership_policy::B_DONT_ASSUME_OWNERSHIP); +m.attr("B_DONT_ASSUME_OWNERSHIP") = 1; } From e29bd95e4f376705fabe31a253d5cd9dfa84a5a2 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 1 Sep 2024 10:39:37 +0200 Subject: [PATCH 044/115] Add support/BlockCache.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/support/BlockCache.cpp | 8 ++++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Jamfile b/Jamfile index 3fb7f59..81094d3 100644 --- a/Jamfile +++ b/Jamfile @@ -202,6 +202,7 @@ local sourceFiles = Beep.cpp Locker.cpp Autolock.cpp + BlockCache.cpp SupportDefs.cpp Archivable.cpp TypeConstants.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index f2ca13f..0e1f210 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -94,6 +94,7 @@ from .Beep import * from .Architecture import * from .Locker import * +from .BlockCache import * from .Autolock import * from .DateTime import * from .parsedate import * diff --git a/bindings/support/BlockCache.cpp b/bindings/support/BlockCache.cpp index f49441a..fccb5cf 100644 --- a/bindings/support/BlockCache.cpp +++ b/bindings/support/BlockCache.cpp @@ -8,13 +8,13 @@ namespace py = pybind11; -void define_BlockCache(py::module_& m) +PYBIND11_MODULE(BlockCache, m) { -m.attr("B_OBJECT_CACHE") = py::cast(B_OBJECT_CACHE); -m.attr("B_MALLOC_CACHE") = py::cast(B_MALLOC_CACHE); +m.attr("B_OBJECT_CACHE") = 0;//py::cast(B_OBJECT_CACHE); +m.attr("B_MALLOC_CACHE") = 1;//py::cast(B_MALLOC_CACHE); py::class_(m, "BBlockCache") -.def(py::init(), "", py::arg("blockCount"), py::arg("blockSize"), py::arg("allocationType")) +.def(py::init(), "", py::arg("blockCount"), py::arg("blockSize"), py::arg("allocationType")) .def("Get", &BBlockCache::Get, "", py::arg("blockSize")) .def("Save", &BBlockCache::Save, "", py::arg("pointer"), py::arg("blockSize")) ; From a15f555f7346f981c45f962c8c22445c0a68949d Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 1 Sep 2024 11:11:30 +0200 Subject: [PATCH 045/115] add BufferedDataIO.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/support/BufferedDataIO.cpp | 59 ++++++++++++++++++++++++++--- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/Jamfile b/Jamfile index 81094d3..16d0973 100644 --- a/Jamfile +++ b/Jamfile @@ -214,6 +214,7 @@ local sourceFiles = Flattenable.cpp StringList.cpp DataIO.cpp + BufferedDataIO.cpp Url.cpp UTF8.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 0e1f210..dc0e7d9 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -104,6 +104,7 @@ from .AffineTransform import * from .StringList import * from .DataIO import * +from .BufferedDataIO import * from .Url import * from .UTF8 import * diff --git a/bindings/support/BufferedDataIO.cpp b/bindings/support/BufferedDataIO.cpp index 1368602..2cfe22a 100644 --- a/bindings/support/BufferedDataIO.cpp +++ b/bindings/support/BufferedDataIO.cpp @@ -4,22 +4,71 @@ #include #include +#include namespace py = pybind11; +class PyBBufferedDataIO : public BBufferedDataIO{ + public: + using BBufferedDataIO::BBufferedDataIO; + ssize_t Read(void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BBufferedDataIO, Read, buffer, size); + } + ssize_t Write(const void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BBufferedDataIO, Write, buffer, size); + } +}; -void define_BufferedDataIO(py::module_& m) +ssize_t ReadWrapper(BBufferedDataIO& self, py::buffer buffer) { + py::buffer_info info = buffer.request(); + + if (info.ndim != 1) { + throw std::runtime_error("Buffer should be one-dimensional"); + } + + if (info.itemsize != 1) { + throw std::runtime_error("Buffer elements should be of size 1 byte"); + } + + return self.Read(info.ptr, info.size); +}; + +ssize_t WriteWrapper(BBufferedDataIO& self, py::buffer buffer) { + py::buffer_info info = buffer.request(); + + if (info.ndim != 1) { + throw std::runtime_error("Buffer should be one-dimensional"); + } + + if (info.itemsize != 1) { + throw std::runtime_error("Buffer elements should be of size 1 byte"); + } + + return self.Write(info.ptr, info.size); +}; + +PYBIND11_MODULE(BufferedDataIO, m) { -py::class_(m, "BBufferedDataIO") -.def(py::init(), "", py::arg("bufferSize")=65536 L, py::arg("ownsStream")=true, py::arg("partialReads")=false) +py::class_(m, "BBufferedDataIO") +.def(py::init(), "", py::arg("stream") ,py::arg("bufferSize")=65536L, py::arg("ownsStream")=true, py::arg("partialReads")=false) .def("InitCheck", &BBufferedDataIO::InitCheck, "") .def("Stream", &BBufferedDataIO::Stream, "") .def("BufferSize", &BBufferedDataIO::BufferSize, "") .def("OwnsStream", &BBufferedDataIO::OwnsStream, "") .def("SetOwnsStream", &BBufferedDataIO::SetOwnsStream, "", py::arg("ownsStream")) .def("Flush", &BBufferedDataIO::Flush, "") -.def("Read", &BBufferedDataIO::Read, "", py::arg("buffer"), py::arg("size")) -.def("Write", &BBufferedDataIO::Write, "", py::arg("buffer"), py::arg("size")) +//.def("Read", &BBufferedDataIO::Read, "", py::arg("buffer"), py::arg("size")) // change to correctly handle void* buffer +.def("Read", &ReadWrapper, "", py::arg("buffer")) //TODO test this +/* in python: +buffered_io = mymodule.BBufferedDataIO() +buffer = bytearray(1024) +read_bytes = buffered_io.Read(buffer)*/ +//.def("Write", &BBufferedDataIO::Write, "", py::arg("buffer"), py::arg("size")) // change to correctly handle void* buffer +.def("Write", &WriteWrapper, "", py::arg("buffer")) //TODO test this +/*in python: +buffered_io = mymodule.BBufferedDataIO() +data = bytearray(b"Hello, world!") +written_bytes = buffered_io.Write(data)*/ ; From 0195e46341b54435da021d6d07a20e35f11c9911 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 1 Sep 2024 11:55:42 +0200 Subject: [PATCH 046/115] Add StopWatch --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/support/StopWatch.cpp | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Jamfile b/Jamfile index 16d0973..9a5cc8c 100644 --- a/Jamfile +++ b/Jamfile @@ -199,6 +199,7 @@ local sourceFiles = PrintJob.cpp #SupportKit + StopWatch.cpp Beep.cpp Locker.cpp Autolock.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index dc0e7d9..56788fc 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -91,6 +91,7 @@ from .Input import * from .PrintJob import * +from .StopWatch import * from .Beep import * from .Architecture import * from .Locker import * diff --git a/bindings/support/StopWatch.cpp b/bindings/support/StopWatch.cpp index bb90a3b..9ffcdd0 100644 --- a/bindings/support/StopWatch.cpp +++ b/bindings/support/StopWatch.cpp @@ -7,8 +7,7 @@ namespace py = pybind11; - -void define_StopWatch(py::module_& m) +PYBIND11_MODULE(StopWatch, m) { py::class_(m, "BStopWatch") .def(py::init(), "", py::arg("name"), py::arg("silent")=false) From 55a8d97420c8df70b51a0d63f13cfd06c687a4a4 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 1 Sep 2024 12:00:00 +0200 Subject: [PATCH 047/115] Add support/TLS.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/support/TLS.cpp | 7 +++---- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Jamfile b/Jamfile index 9a5cc8c..eb6026e 100644 --- a/Jamfile +++ b/Jamfile @@ -218,6 +218,7 @@ local sourceFiles = BufferedDataIO.cpp Url.cpp UTF8.cpp + TLS.cpp #Kernel fs_attr.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 56788fc..8b1fde8 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -108,6 +108,7 @@ from .BufferedDataIO import * from .Url import * from .UTF8 import * +from .TLS import * from .fs_attr import * from .OS import * diff --git a/bindings/support/TLS.cpp b/bindings/support/TLS.cpp index 3ea7907..6169125 100644 --- a/bindings/support/TLS.cpp +++ b/bindings/support/TLS.cpp @@ -6,11 +6,10 @@ #include namespace py = pybind11; - - -void define_TLS(py::module_& m) +//TODO: Please, test this module +PYBIND11_MODULE(TLS, m) { -m.def("tls_allocate", &tls_allocate, "", py::arg("")); +m.def("tls_allocate", &tls_allocate, ""); m.def("tls_get", &tls_get, "", py::arg("index")); From 30c268c5e6cb9cc061103f446e526fc8d58b1fa3 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 1 Sep 2024 18:08:50 +0200 Subject: [PATCH 048/115] add locale autogen modules + fix some of them --- Jamfile | 17 +- bindings/__init__.py | 11 + bindings/locale/Catalog.cpp | 31 ++ bindings/locale/CatalogData.cpp | 44 +++ bindings/locale/Collator.cpp | 44 +++ bindings/locale/Country.cpp | 46 +++ bindings/locale/DateFormat.cpp | 88 ++++++ bindings/locale/DateTimeFormat.cpp | 42 +++ bindings/locale/DurationFormat.cpp | 31 ++ bindings/locale/Format.cpp | 37 +++ bindings/locale/FormattingConventions.cpp | 109 +++++++ bindings/locale/Language.cpp | 52 +++ bindings/locale/Locale.cpp | 31 ++ bindings/locale/LocaleRoster.cpp | 48 +++ bindings/locale/LocaleStrings.cpp | 88 ++++++ bindings/locale/NumberFormat.cpp | 59 ++++ bindings/locale/RelativeDateTimeFormat.cpp | 30 ++ bindings/locale/StringFormat.cpp | 30 ++ bindings/locale/TextEncoding.cpp | 41 +++ bindings/locale/TimeFormat.cpp | 58 ++++ bindings/locale/TimeUnitFormat.cpp | 44 +++ bindings/locale/TimeZone.cpp | 36 +++ bindings/locale/UnicodeChar.cpp | 348 +++++++++++++++++++++ 23 files changed, 1364 insertions(+), 1 deletion(-) create mode 100644 bindings/locale/Catalog.cpp create mode 100644 bindings/locale/CatalogData.cpp create mode 100644 bindings/locale/Collator.cpp create mode 100644 bindings/locale/Country.cpp create mode 100644 bindings/locale/DateFormat.cpp create mode 100644 bindings/locale/DateTimeFormat.cpp create mode 100644 bindings/locale/DurationFormat.cpp create mode 100644 bindings/locale/Format.cpp create mode 100644 bindings/locale/FormattingConventions.cpp create mode 100644 bindings/locale/Language.cpp create mode 100644 bindings/locale/Locale.cpp create mode 100644 bindings/locale/LocaleRoster.cpp create mode 100644 bindings/locale/LocaleStrings.cpp create mode 100644 bindings/locale/NumberFormat.cpp create mode 100644 bindings/locale/RelativeDateTimeFormat.cpp create mode 100644 bindings/locale/StringFormat.cpp create mode 100644 bindings/locale/TextEncoding.cpp create mode 100644 bindings/locale/TimeFormat.cpp create mode 100644 bindings/locale/TimeUnitFormat.cpp create mode 100644 bindings/locale/TimeZone.cpp create mode 100644 bindings/locale/UnicodeChar.cpp diff --git a/Jamfile b/Jamfile index eb6026e..a101d69 100644 --- a/Jamfile +++ b/Jamfile @@ -74,7 +74,7 @@ install_location ?= /boot/system/non-packaged/lib/python$(python_version)/site-packages ; # Where to search for .cpp files -SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/storage bindings/kernel bindings/translation bindings/add-ons/screen_saver bindings/add-ons/registrar bindings/add-ons/graphics bindings/add-ons/input_server bindings/add-ons/mail_daemon bindings/add-ons/network_settings bindings/drivers bindings/device bindings/mail ; +SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/storage bindings/kernel bindings/translation bindings/add-ons/screen_saver bindings/add-ons/registrar bindings/add-ons/graphics bindings/add-ons/input_server bindings/add-ons/mail_daemon bindings/add-ons/network_settings bindings/drivers bindings/device bindings/mail bindings/locale ; # Where to look for header files SubDirHdrs headers ; @@ -299,6 +299,19 @@ local sourceFiles = MailMessage.cpp MailAttachment.cpp MailSettings.cpp + + #locale + Country.cpp + Language.cpp + Format.cpp + FormattingConventions.cpp + DateFormat.cpp + DateTimeFormat.cpp + TimeUnitFormat.cpp + DurationFormat.cpp + TimeFormat.cpp + UnicodeChar.cpp + ; # The .so files can be built from the .cpp files, each .cpp file mapping to @@ -319,6 +332,8 @@ LINKLIBS on Translator.so = $(LINKLIBS) -ltranslation ; LINKLIBS on TranslatorFormats.so = $(LINKLIBS) -ltranslation ; LINKLIBS on BitmapStream.so = $(LINKLIBS) -ltranslation ; +#LINKLIBS on FormattingConventions.so = $(LINKLIBS) -llocalestub ; +#LINKLIBS on TimeFormat.so = $(LINKLIBS) -lsupport ; LINKLIBS on ScreenSaver.so = $(LINKLIBS) -lscreensaver ; #LINKLIBS on MimeSnifferAddon.so = $(LINKLIBS) -lstoragekit ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 8b1fde8..216df89 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -178,6 +178,17 @@ from .MailAttachment import * from .MailSettings import * +from .Country import * +from .Language import * +from .Format import * +from .FormattingConventions import * +from .DateFormat import * +from .DateTimeFormat import * +from .TimeUnitFormat import * +from .DurationFormat import * +from .TimeFormat import * +from .UnicodeChar import * + _BWindow=BWindow _BApplication=BApplication def MessageReceived(self, msg, parent): diff --git a/bindings/locale/Catalog.cpp b/bindings/locale/Catalog.cpp new file mode 100644 index 0000000..4d2d4f0 --- /dev/null +++ b/bindings/locale/Catalog.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_Catalog(py::module_& m) +{ +py::class_(m, "BCatalog") +.def(py::init(), "") +.def(py::init(), "", py::arg("catalogOwner"), py::arg("language")=NULL, py::arg("fingerprint")=0) +.def(py::init(), "", py::arg("signature"), py::arg("language")=NULL) +.def("GetString", py::overload_cast(&BCatalog::GetString), "", py::arg("string"), py::arg("context")=NULL, py::arg("comment")=NULL) +.def("GetString", py::overload_cast(&BCatalog::GetString), "", py::arg("id")) +.def("GetData", py::overload_cast(&BCatalog::GetData), "", py::arg("name"), py::arg("msg")) +.def("GetData", py::overload_cast(&BCatalog::GetData), "", py::arg("id"), py::arg("msg")) +.def("GetSignature", &BCatalog::GetSignature, "", py::arg("signature")) +.def("GetLanguage", &BCatalog::GetLanguage, "", py::arg("language")) +.def("GetFingerprint", &BCatalog::GetFingerprint, "", py::arg("fingerprint")) +.def("SetTo", py::overload_cast(&BCatalog::SetTo), "", py::arg("catalogOwner"), py::arg("language")=NULL, py::arg("fingerprint")=0) +.def("SetTo", py::overload_cast(&BCatalog::SetTo), "", py::arg("signature"), py::arg("language")=NULL) +.def("InitCheck", &BCatalog::InitCheck, "") +.def("CountItems", &BCatalog::CountItems, "") +; + + +} diff --git a/bindings/locale/CatalogData.cpp b/bindings/locale/CatalogData.cpp new file mode 100644 index 0000000..cd6791e --- /dev/null +++ b/bindings/locale/CatalogData.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_CatalogData(py::module_& m) +{ +m.attr("gCatalogAddOnPriority") = py::cast(gCatalogAddOnPriority); + +py::class_(m, "BCatalogData") +.def(py::init(), "", py::arg("signature"), py::arg("language"), py::arg("fingerprint")) +.def("GetString", py::overload_cast(&BCatalogData::GetString), "", py::arg("string"), py::arg("context")=NULL, py::arg("comment")=NULL) +.def("GetString", py::overload_cast(&BCatalogData::GetString), "", py::arg("id")) +.def("InitCheck", &BCatalogData::InitCheck, "") +.def("Next", &BCatalogData::Next, "") +.def("CanHaveData", &BCatalogData::CanHaveData, "") +.def("GetData", py::overload_cast(&BCatalogData::GetData), "", py::arg("name"), py::arg("msg")) +.def("GetData", py::overload_cast(&BCatalogData::GetData), "", py::arg("id"), py::arg("msg")) +.def("SetString", py::overload_cast(&BCatalogData::SetString), "", py::arg("string"), py::arg("translated"), py::arg("context")=NULL, py::arg("comment")=NULL) +.def("SetString", py::overload_cast(&BCatalogData::SetString), "", py::arg("id"), py::arg("translated")) +.def("CanWriteData", &BCatalogData::CanWriteData, "") +.def("SetData", py::overload_cast(&BCatalogData::SetData), "", py::arg("name"), py::arg("msg")) +.def("SetData", py::overload_cast(&BCatalogData::SetData), "", py::arg("id"), py::arg("msg")) +.def("ReadFromFile", &BCatalogData::ReadFromFile, "", py::arg("path")=NULL) +.def("ReadFromAttribute", &BCatalogData::ReadFromAttribute, "", py::arg("appOrAddOnRef")) +.def("ReadFromResource", &BCatalogData::ReadFromResource, "", py::arg("appOrAddOnRef")) +.def("WriteToFile", &BCatalogData::WriteToFile, "", py::arg("path")=NULL) +.def("WriteToAttribute", &BCatalogData::WriteToAttribute, "", py::arg("appOrAddOnRef")) +.def("WriteToResource", &BCatalogData::WriteToResource, "", py::arg("appOrAddOnRef")) +.def("MakeEmpty", &BCatalogData::MakeEmpty, "") +.def("CountItems", &BCatalogData::CountItems, "") +.def("SetNext", &BCatalogData::SetNext, "", py::arg("next")) +; + +m.def("instantiate_catalog", &instantiate_catalog, "", py::arg("signature"), py::arg("language"), py::arg("fingerprint")); + +m.def("create_catalog", &create_catalog, "", py::arg("signature"), py::arg("language")); + +} diff --git a/bindings/locale/Collator.cpp b/bindings/locale/Collator.cpp new file mode 100644 index 0000000..853b687 --- /dev/null +++ b/bindings/locale/Collator.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +void define_Collator(py::module_& m) +{ +py::enum_(m, "collator_strengths", "") +.value("B_COLLATE_DEFAULT", collator_strengths::B_COLLATE_DEFAULT, "") +.value("B_COLLATE_PRIMARY", collator_strengths::B_COLLATE_PRIMARY, "") +.value("B_COLLATE_SECONDARY", collator_strengths::B_COLLATE_SECONDARY, "") +.value("B_COLLATE_TERTIARY", collator_strengths::B_COLLATE_TERTIARY, "") +.value("B_COLLATE_QUATERNARY", collator_strengths::B_COLLATE_QUATERNARY, "") +.value("B_COLLATE_IDENTICAL", collator_strengths::B_COLLATE_IDENTICAL, "") +.export_values(); + +m.attr("Collator") = py::cast(Collator); + +py::class_(m, "BCollator") +.def(py::init(), "") +.def(py::init(), "", py::arg("locale"), py::arg("strength")=B_COLLATE_PRIMARY, py::arg("ignorePunctuation")=false) +.def(py::init(), "", py::arg("archive")) +.def(py::init(), "", py::arg("other")) +.def("operator=", &BCollator::operator=, "", py::arg("source")) +.def("SetStrength", &BCollator::SetStrength, "", py::arg("strength")) +.def("SetIgnorePunctuation", &BCollator::SetIgnorePunctuation, "", py::arg("ignore")) +.def("IgnorePunctuation", &BCollator::IgnorePunctuation, "") +.def("SetNumericSorting", &BCollator::SetNumericSorting, "", py::arg("enable")) +.def("GetSortKey", &BCollator::GetSortKey, "", py::arg("string"), py::arg("key")) +.def("Compare", &BCollator::Compare, "", py::arg("s1"), py::arg("s2")) +.def("Equal", &BCollator::Equal, "", py::arg("s1"), py::arg("s2")) +.def("Greater", &BCollator::Greater, "", py::arg("s1"), py::arg("s2")) +.def("GreaterOrEqual", &BCollator::GreaterOrEqual, "", py::arg("s1"), py::arg("s2")) +.def("Archive", &BCollator::Archive, "", py::arg("archive"), py::arg("deep")) +.def_static("Instantiate", &BCollator::Instantiate, "", py::arg("archive")) +; + + +} diff --git a/bindings/locale/Country.cpp b/bindings/locale/Country.cpp new file mode 100644 index 0000000..9dc5c62 --- /dev/null +++ b/bindings/locale/Country.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(Country, m) +{ + + +py::class_(m, "BCountry") +.def(py::init(), "", py::arg("countryCode")=NULL) +.def(py::init(), "", py::arg("other")) +.def("operator=", &BCountry::operator=, "", py::arg("other")) +.def("SetTo", &BCountry::SetTo, "", py::arg("countryCode")) +.def("InitCheck", &BCountry::InitCheck, "") +.def("GetNativeName", [](BCountry& self) { + BString name; + status_t r = self.GetNativeName(name); + return std::make_tuple(r,name); +} +, "") +.def("GetName", [](BCountry& self,const BLanguage * displayLanguage=NULL) { + BString name; + status_t r = self.GetName(name, displayLanguage); + return std::make_tuple(r,name); +} +, "", py::arg("displayLanguage")=NULL) +.def("GetPreferredLanguage", &BCountry::GetPreferredLanguage, "", py::arg("&")) +.def("Code", &BCountry::Code, "") +.def("GetIcon", &BCountry::GetIcon, "", py::arg("result")) +.def("GetAvailableTimeZones", &BCountry::GetAvailableTimeZones, "", py::arg("timeZones")) +//.def_readwrite("Private", &BCountry::Private, "") +; + +//m.attr("DateFormat") = py::cast(DateFormat); + +//m.attr("Locale") = py::cast(Locale); +} diff --git a/bindings/locale/DateFormat.cpp b/bindings/locale/DateFormat.cpp new file mode 100644 index 0000000..5355bd2 --- /dev/null +++ b/bindings/locale/DateFormat.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(DateFormat, m) +{ +py::enum_(m, "BWeekday", "") +.value("B_WEEKDAY_MONDAY", BWeekday::B_WEEKDAY_MONDAY, "") +.value("B_WEEKDAY_TUESDAY", BWeekday::B_WEEKDAY_TUESDAY, "") +.value("B_WEEKDAY_WEDNESDAY", BWeekday::B_WEEKDAY_WEDNESDAY, "") +.value("B_WEEKDAY_THURSDAY", BWeekday::B_WEEKDAY_THURSDAY, "") +.value("B_WEEKDAY_FRIDAY", BWeekday::B_WEEKDAY_FRIDAY, "") +.value("B_WEEKDAY_SATURDAY", BWeekday::B_WEEKDAY_SATURDAY, "") +.value("B_WEEKDAY_SUNDAY", BWeekday::B_WEEKDAY_SUNDAY, "") +.export_values(); + +//m.attr("DateFormat") = py::cast(DateFormat); + +py::class_(m, "BDateFormat") +.def(py::init(), "", py::arg("locale")=NULL) +.def(py::init(), "", py::arg("language"), py::arg("format")) +.def(py::init(), "", py::arg("other")) +.def("GetDateFormat", [](BDateFormat& self,BDateFormatStyle style) { + BString outFormat; + status_t r = self.GetDateFormat(style, outFormat); + return std::make_tuple(r,outFormat); +} +, "", py::arg("style")) +.def("SetDateFormat", &BDateFormat::SetDateFormat, "", py::arg("style"), py::arg("format")) +.def("Format", py::overload_cast(&BDateFormat::Format, py::const_), "", py::arg("string"), py::arg("maxSize"), py::arg("time"), py::arg("style")) +.def("Format", [](BDateFormat& self,const time_t time,const BDateFormatStyle style,const BTimeZone * timeZone=NULL) { + BString string; + status_t r = self.Format(string, time, style, timeZone); + return std::make_tuple(r,string); +} +, "", py::arg("time"), py::arg("style"), py::arg("timeZone")=NULL) +.def("Format", [](BDateFormat& self,const BDate & time,const BDateFormatStyle style,const BTimeZone * timeZone=NULL) { + BString string; + status_t r = self.Format(string, time, style, timeZone); + return std::make_tuple(r,string); +} +, "", py::arg("time"), py::arg("style"), py::arg("timeZone")=NULL) +.def("Format", [](BDateFormat& self,const time_t time,const BDateFormatStyle style) { + BString string; +int * fieldPositions; +int fieldCount; + status_t r = self.Format(string, fieldPositions, fieldCount, time, style); + return std::make_tuple(r,string,fieldPositions,fieldCount); +} +, "", py::arg("time"), py::arg("style")) +.def("GetFields", [](BDateFormat& self,BDateFormatStyle style) { + BDateElement * fields; +int fieldCount; + status_t r = self.GetFields(fields, fieldCount, style); + return std::make_tuple(r,fields,fieldCount); +} +, "", py::arg("style")) +.def("GetStartOfWeek", &BDateFormat::GetStartOfWeek, "", py::arg("weekday")) +.def("GetMonthName", [](BDateFormat& self,int month,const BDateFormatStyle style=B_FULL_DATE_FORMAT) { + BString outName; + status_t r = self.GetMonthName(month, outName, style); + return std::make_tuple(r,outName); +} +, "", py::arg("month"), py::arg("style")=B_FULL_DATE_FORMAT) +.def("GetDayName", [](BDateFormat& self,int day,const BDateFormatStyle style=B_FULL_DATE_FORMAT) { + BString outName; + status_t r = self.GetDayName(day, outName, style); + return std::make_tuple(r,outName); +} +, "", py::arg("day"), py::arg("style")=B_FULL_DATE_FORMAT) +.def("Parse", [](BDateFormat& self,BString source,BDateFormatStyle style) { + BDate output; + status_t r = self.Parse(source, style, output); + return std::make_tuple(r,output); +} +, "", py::arg("source"), py::arg("style")) +; + + +} diff --git a/bindings/locale/DateTimeFormat.cpp b/bindings/locale/DateTimeFormat.cpp new file mode 100644 index 0000000..b53d66b --- /dev/null +++ b/bindings/locale/DateTimeFormat.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; + +PYBIND11_MODULE(DateTimeFormat, m) +{ +py::enum_(m, "BDateElement", "") +.value("B_DATE_ELEMENT_INVALID", BDateElement::B_DATE_ELEMENT_INVALID, "") +.value("B_DATE_ELEMENT_YEAR", BDateElement::B_DATE_ELEMENT_YEAR, "") +.value("B_DATE_ELEMENT_MONTH", BDateElement::B_DATE_ELEMENT_MONTH, "") +.value("B_DATE_ELEMENT_WEEKDAY", BDateElement::B_DATE_ELEMENT_WEEKDAY, "") +.value("B_DATE_ELEMENT_DAY", BDateElement::B_DATE_ELEMENT_DAY, "") +.value("B_DATE_ELEMENT_AM_PM", BDateElement::B_DATE_ELEMENT_AM_PM, "") +.value("B_DATE_ELEMENT_HOUR", BDateElement::B_DATE_ELEMENT_HOUR, "") +.value("B_DATE_ELEMENT_MINUTE", BDateElement::B_DATE_ELEMENT_MINUTE, "") +.value("B_DATE_ELEMENT_SECOND", BDateElement::B_DATE_ELEMENT_SECOND, "") +.value("B_DATE_ELEMENT_TIMEZONE", BDateElement::B_DATE_ELEMENT_TIMEZONE, "") +.export_values(); + +py::class_(m, "BDateTimeFormat") +.def(py::init(), "", py::arg("locale")=NULL) +.def(py::init(), "", py::arg("language"), py::arg("conventions")) +.def(py::init(), "", py::arg("other")) +.def("SetDateTimeFormat", &BDateTimeFormat::SetDateTimeFormat, "", py::arg("dateStyle"), py::arg("timeStyle"), py::arg("elements")) +.def("Format", py::overload_cast(&BDateTimeFormat::Format, py::const_), "", py::arg("target"), py::arg("maxSize"), py::arg("time"), py::arg("dateStyle"), py::arg("timeStyle")) +.def("Format", [](BDateTimeFormat& self,const time_t time,BDateFormatStyle dateStyle,BTimeFormatStyle timeStyle,const BTimeZone * timeZone=NULL) { + BString buffer; + status_t r = self.Format(buffer, time, dateStyle, timeStyle, timeZone); + return std::make_tuple(r,buffer); +} +, "", py::arg("time"), py::arg("dateStyle"), py::arg("timeStyle"), py::arg("timeZone")=NULL) +; + + +} diff --git a/bindings/locale/DurationFormat.cpp b/bindings/locale/DurationFormat.cpp new file mode 100644 index 0000000..ffb2e58 --- /dev/null +++ b/bindings/locale/DurationFormat.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(DurationFormat, m) +{ +//m.attr("GregorianCalendar") = py::cast(GregorianCalendar); //TODO try to fix this gregocal.h in icu74 d + +py::class_(m, "BDurationFormat") +.def(py::init(), "", py::arg("language"), py::arg("conventions"), py::arg("separator")=", ", py::arg("style")=B_TIME_UNIT_FULL) +.def(py::init(), "", py::arg("separator")=", ", py::arg("style")=B_TIME_UNIT_FULL) +.def(py::init(), "", py::arg("other")) +.def("SetSeparator", &BDurationFormat::SetSeparator, "", py::arg("separator")) +.def("SetTimeZone", &BDurationFormat::SetTimeZone, "", py::arg("timeZone")) +.def("Format", [](BDurationFormat& self,const bigtime_t startValue,const bigtime_t stopValue) { + BString buffer; + status_t r = self.Format(buffer, startValue, stopValue); + return std::make_tuple(r,buffer); +} +, "", py::arg("startValue"), py::arg("stopValue")) +; + + +} diff --git a/bindings/locale/Format.cpp b/bindings/locale/Format.cpp new file mode 100644 index 0000000..f686be4 --- /dev/null +++ b/bindings/locale/Format.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(Format, m) +{ +m.attr("B_CURRENCY_FIELD") = 0;//py::cast(B_CURRENCY_FIELD); +m.attr("B_DECIMAL_SEPARATOR_FIELD") = 1;//py::cast(B_DECIMAL_SEPARATOR_FIELD); +m.attr("B_EXPONENT_FIELD") = 2;//py::cast(B_EXPONENT_FIELD); +m.attr("B_EXPONENT_SIGN_FIELD") = 3;//py::cast(B_EXPONENT_SIGN_FIELD); +m.attr("B_EXPONENT_SYMBOL_FIELD") = 4;//py::cast(B_EXPONENT_SYMBOL_FIELD); +m.attr("B_FRACTION_FIELD") = 5;//py::cast(B_FRACTION_FIELD); +m.attr("B_GROUPING_SEPARATOR_FIELD") = 6;//py::cast(B_GROUPING_SEPARATOR_FIELD); +m.attr("B_INTEGER_FIELD") = 7;//py::cast(B_INTEGER_FIELD); +m.attr("B_PERCENT_FIELD") = 8;//py::cast(B_PERCENT_FIELD); +m.attr("B_PERMILLE_FIELD") = 9;//py::cast(B_PERMILLE_FIELD); +m.attr("B_SIGN_FIELD") = 10;//py::cast(B_SIGN_FIELD); + +py::class_(m, "format_field_position") +.def_readwrite("field_type", &format_field_position::field_type, "") +.def_readwrite("start", &format_field_position::start, "") +.def_readwrite("length", &format_field_position::length, "") +; + +py::class_>(m, "BFormat") +.def("InitCheck", &BFormat::InitCheck, "") +; + + +} diff --git a/bindings/locale/FormattingConventions.cpp b/bindings/locale/FormattingConventions.cpp new file mode 100644 index 0000000..deb5833 --- /dev/null +++ b/bindings/locale/FormattingConventions.cpp @@ -0,0 +1,109 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(FormattingConventions, m) +{ +py::enum_(m, "BMeasurementKind", "") +.value("B_METRIC", BMeasurementKind::B_METRIC, "") +.value("B_US", BMeasurementKind::B_US, "") +.export_values(); + +py::enum_(m, "BDateFormatStyle", "") +.value("B_FULL_DATE_FORMAT", BDateFormatStyle::B_FULL_DATE_FORMAT, "") +.value("B_LONG_DATE_FORMAT", BDateFormatStyle::B_LONG_DATE_FORMAT, "") +.value("B_MEDIUM_DATE_FORMAT", BDateFormatStyle::B_MEDIUM_DATE_FORMAT, "") +.value("B_SHORT_DATE_FORMAT", BDateFormatStyle::B_SHORT_DATE_FORMAT, "") +.value("B_DATE_FORMAT_STYLE_COUNT", BDateFormatStyle::B_DATE_FORMAT_STYLE_COUNT, "") +.export_values(); + +py::enum_(m, "BTimeFormatStyle", "") +.value("B_FULL_TIME_FORMAT", BTimeFormatStyle::B_FULL_TIME_FORMAT, "") +.value("B_LONG_TIME_FORMAT", BTimeFormatStyle::B_LONG_TIME_FORMAT, "") +.value("B_MEDIUM_TIME_FORMAT", BTimeFormatStyle::B_MEDIUM_TIME_FORMAT, "") +.value("B_SHORT_TIME_FORMAT", BTimeFormatStyle::B_SHORT_TIME_FORMAT, "") +.value("B_TIME_FORMAT_STYLE_COUNT", BTimeFormatStyle::B_TIME_FORMAT_STYLE_COUNT, "") +.export_values(); + +//m.attr("DateFormat") = py::cast(DateFormat); + +//m.attr("Locale") = py::cast(Locale); + +py::class_(m, "BFormattingConventions") +.def(py::init(), "", py::arg("id")=NULL) +.def(py::init(), "", py::arg("other")) +.def(py::init(), "", py::arg("archive")) +.def("operator=", &BFormattingConventions::operator=, "", py::arg("other")) +.def("__eq__", &BFormattingConventions::operator==, "", py::arg("other")) +.def("__ne__", &BFormattingConventions::operator!=, "", py::arg("other")) +.def("ID", &BFormattingConventions::ID, "") +.def("LanguageCode", &BFormattingConventions::LanguageCode, "") +.def("CountryCode", &BFormattingConventions::CountryCode, "") +.def("AreCountrySpecific", &BFormattingConventions::AreCountrySpecific, "") +.def("GetNativeName", [](BFormattingConventions& self) { + BString name; + status_t r = self.GetNativeName(name); + return std::make_tuple(r,name); +} +, "") +.def("GetName", [](BFormattingConventions& self,const BLanguage * displayLanguage=NULL) { + BString name; + status_t r = self.GetName(name, displayLanguage); + return std::make_tuple(r,name); +} +, "", py::arg("displayLanguage")=NULL) +//.def("GetString", &BFormattingConventions::GetString, "", py::arg("id")) +.def("GetDateFormat", [](BFormattingConventions& self,BDateFormatStyle style) { + BString outFormat; + status_t r = self.GetDateFormat(style, outFormat); + return std::make_tuple(r,outFormat); +} +, "", py::arg("style")) +.def("GetTimeFormat", [](BFormattingConventions& self,BTimeFormatStyle style) { + BString outFormat; + status_t r = self.GetTimeFormat(style, outFormat); + return std::make_tuple(r,outFormat); +} +, "", py::arg("style")) +.def("GetDateTimeFormat", [](BFormattingConventions& self,BDateFormatStyle dateStyle,BTimeFormatStyle timeStyle) { + BString outFormat; + status_t r = self.GetDateTimeFormat(dateStyle, timeStyle, outFormat); + return std::make_tuple(r,outFormat); +} +, "", py::arg("dateStyle"), py::arg("timeStyle")) +.def("GetNumericFormat", [](BFormattingConventions& self) { + BString outFormat; + status_t r = self.GetNumericFormat(outFormat); + return std::make_tuple(r,outFormat); +} +, "") +.def("GetMonetaryFormat", [](BFormattingConventions& self) { + BString outFormat; + status_t r = self.GetMonetaryFormat(outFormat); + return std::make_tuple(r,outFormat); +} +, "") +.def("SetExplicitDateFormat", &BFormattingConventions::SetExplicitDateFormat, "", py::arg("style"), py::arg("format")) +.def("SetExplicitTimeFormat", &BFormattingConventions::SetExplicitTimeFormat, "", py::arg("style"), py::arg("format")) +.def("SetExplicitDateTimeFormat", &BFormattingConventions::SetExplicitDateTimeFormat, "", py::arg("dateStyle"), py::arg("timeStyle"), py::arg("format")) +.def("SetExplicitNumericFormat", &BFormattingConventions::SetExplicitNumericFormat, "", py::arg("format")) +.def("SetExplicitMonetaryFormat", &BFormattingConventions::SetExplicitMonetaryFormat, "", py::arg("format")) +.def("MeasurementKind", &BFormattingConventions::MeasurementKind, "") +.def("UseStringsFromPreferredLanguage", &BFormattingConventions::UseStringsFromPreferredLanguage, "") +.def("SetUseStringsFromPreferredLanguage", &BFormattingConventions::SetUseStringsFromPreferredLanguage, "", py::arg("value")) +.def("Use24HourClock", &BFormattingConventions::Use24HourClock, "") +.def("SetExplicitUse24HourClock", &BFormattingConventions::SetExplicitUse24HourClock, "", py::arg("value")) +.def("UnsetExplicitUse24HourClock", &BFormattingConventions::UnsetExplicitUse24HourClock, "") +.def("Archive", &BFormattingConventions::Archive, "", py::arg("archive"), py::arg("deep")=true) +//.def_readwrite("Private", &BFormattingConventions::Private, "") +; + + +} diff --git a/bindings/locale/Language.cpp b/bindings/locale/Language.cpp new file mode 100644 index 0000000..18cfcc9 --- /dev/null +++ b/bindings/locale/Language.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(Language, m) +{ +py::enum_(m, "script_direction", "") +.value("B_LEFT_TO_RIGHT", script_direction::B_LEFT_TO_RIGHT, "") +.value("B_RIGHT_TO_LEFT", script_direction::B_RIGHT_TO_LEFT, "") +.value("B_TOP_TO_BOTTOM", script_direction::B_TOP_TO_BOTTOM, "") +.export_values(); + +py::class_(m, "BLanguage") +.def(py::init(), "") +.def(py::init(), "", py::arg("language")) +.def(py::init(), "", py::arg("other")) +.def("SetTo", &BLanguage::SetTo, "", py::arg("language")) +.def("GetNativeName", [](BLanguage& self) { + BString name; + status_t r = self.GetNativeName(name); + return std::make_tuple(r,name); +} +, "") +.def("GetName", [](BLanguage& self,const BLanguage * displayLanguage=NULL) { + BString name; + status_t r = self.GetName(name, displayLanguage); + return std::make_tuple(r,name); +} +, "", py::arg("displayLanguage")=NULL) +.def("GetString", &BLanguage::GetString, "", py::arg("id")) +.def("GetIcon", &BLanguage::GetIcon, "", py::arg("result")) +.def("Code", &BLanguage::Code, "") +.def("CountryCode", &BLanguage::CountryCode, "") +.def("ScriptCode", &BLanguage::ScriptCode, "") +.def("Variant", &BLanguage::Variant, "") +.def("ID", &BLanguage::ID, "") +.def("IsCountrySpecific", &BLanguage::IsCountrySpecific, "") +.def("IsVariant", &BLanguage::IsVariant, "") +.def("Direction", &BLanguage::Direction, "") +.def("operator=", &BLanguage::operator=, "", py::arg("source")) +//.def_readwrite("Private", &BLanguage::Private, "") +; +//m.attr("Locale") = py::cast(Locale); + +} diff --git a/bindings/locale/Locale.cpp b/bindings/locale/Locale.cpp new file mode 100644 index 0000000..91ad78c --- /dev/null +++ b/bindings/locale/Locale.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_Locale(py::module_& m) +{ +py::class_(m, "BLocale") +.def(py::init(), "", py::arg("language")=NULL, py::arg("conventions")=NULL) +.def(py::init(), "", py::arg("other")) +.def_static("Default", &BLocale::Default, "") +.def("operator=", &BLocale::operator=, "", py::arg("other")) +.def("GetCollator", &BLocale::GetCollator, "", py::arg("collator")) +.def("GetLanguage", &BLocale::GetLanguage, "", py::arg("language")) +.def("GetFormattingConventions", &BLocale::GetFormattingConventions, "", py::arg("conventions")) +.def("SetFormattingConventions", &BLocale::SetFormattingConventions, "", py::arg("conventions")) +.def("SetCollator", &BLocale::SetCollator, "", py::arg("newCollator")) +.def("SetLanguage", &BLocale::SetLanguage, "", py::arg("newLanguage")) +.def("GetString", &BLocale::GetString, "", py::arg("id")) +.def("StringCompare", py::overload_cast(&BLocale::StringCompare), "", py::arg("s1"), py::arg("s2")) +.def("StringCompare", py::overload_cast(&BLocale::StringCompare), "", py::arg("s1"), py::arg("s2")) +.def("GetSortKey", &BLocale::GetSortKey, "", py::arg("string"), py::arg("sortKey")) +; + + +} diff --git a/bindings/locale/LocaleRoster.cpp b/bindings/locale/LocaleRoster.cpp new file mode 100644 index 0000000..f7d05f4 --- /dev/null +++ b/bindings/locale/LocaleRoster.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; + +void define_LocaleRoster(py::module_& m) +{ +m.attr("B_LOCALE_CHANGED") = py::cast(B_LOCALE_CHANGED); + +m.attr("LocaleRosterData") = py::cast(LocaleRosterData); + +py::class_(m, "BLocaleRoster") +.def_static("Default", &BLocaleRoster::Default, "") +.def("GetDefaultTimeZone", &BLocaleRoster::GetDefaultTimeZone, "", py::arg("timezone")) +.def("GetLanguage", &BLocaleRoster::GetLanguage, "", py::arg("languageCode"), py::arg("_language")) +.def("GetPreferredLanguages", &BLocaleRoster::GetPreferredLanguages, "", py::arg("message")) +.def("GetAvailableLanguages", &BLocaleRoster::GetAvailableLanguages, "", py::arg("message")) +.def("GetAvailableCountries", &BLocaleRoster::GetAvailableCountries, "", py::arg("timeZones")) +.def("GetAvailableTimeZones", &BLocaleRoster::GetAvailableTimeZones, "", py::arg("timeZones")) +.def("GetAvailableTimeZonesWithRegionInfo", &BLocaleRoster::GetAvailableTimeZonesWithRegionInfo, "", py::arg("timeZonesWithRegonInfo")) +.def("GetAvailableTimeZonesForCountry", &BLocaleRoster::GetAvailableTimeZonesForCountry, "", py::arg("message"), py::arg("countryCode")) +.def("GetFlagIconForCountry", &BLocaleRoster::GetFlagIconForCountry, "", py::arg("flagIcon"), py::arg("countryCode")) +.def("GetFlagIconForLanguage", &BLocaleRoster::GetFlagIconForLanguage, "", py::arg("flagIcon"), py::arg("languageCode")) +.def("GetAvailableCatalogs", &BLocaleRoster::GetAvailableCatalogs, "", py::arg("message"), py::arg("sigPattern")=NULL, py::arg("langPattern")=NULL, py::arg("fingerprint")=0) +.def("Refresh", &BLocaleRoster::Refresh, "") +.def("GetCatalog", &BLocaleRoster::GetCatalog, "") +.def("GetDefaultLocale", &BLocaleRoster::GetDefaultLocale, "") +.def("IsFilesystemTranslationPreferred", &BLocaleRoster::IsFilesystemTranslationPreferred, "") +.def("GetLocalizedFileName", [](BLocaleRoster& self,const entry_ref & ref,bool traverse=false) { + BString localizedFileName; + status_t r = self.GetLocalizedFileName(localizedFileName, ref, traverse); + return std::make_tuple(r,localizedFileName); +} +, "", py::arg("ref"), py::arg("traverse")=false) +.def_readwrite("kCatLangAttr", &BLocaleRoster::kCatLangAttr, "") +.def_readwrite("kCatSigAttr", &BLocaleRoster::kCatSigAttr, "") +.def_readwrite("kCatFingerprintAttr", &BLocaleRoster::kCatFingerprintAttr, "") +.def_readwrite("kEmbeddedCatAttr", &BLocaleRoster::kEmbeddedCatAttr, "") +.def_readwrite("kEmbeddedCatResId", &BLocaleRoster::kEmbeddedCatResId, "") +; + + +} diff --git a/bindings/locale/LocaleStrings.cpp b/bindings/locale/LocaleStrings.cpp new file mode 100644 index 0000000..925facb --- /dev/null +++ b/bindings/locale/LocaleStrings.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_LocaleStrings(py::module_& m) +{ +py::enum_(m, "country_strings", "") +.value("B_COUNTRY_STRINGS_BASE", country_strings::B_COUNTRY_STRINGS_BASE, "") +.value("B_DATE_TIME_FORMAT", country_strings::B_DATE_TIME_FORMAT, "") +.value("B_TIME_AM_PM_FORMAT", country_strings::B_TIME_AM_PM_FORMAT, "") +.value("B_SHORT_DATE_TIME_FORMAT", country_strings::B_SHORT_DATE_TIME_FORMAT, "") +.value("B_SHORT_TIME_AM_PM_FORMAT", country_strings::B_SHORT_TIME_AM_PM_FORMAT, "") +.value("B_AM_STRING", country_strings::B_AM_STRING, "") +.value("B_PM_STRING", country_strings::B_PM_STRING, "") +.value("B_DATE_SEPARATOR", country_strings::B_DATE_SEPARATOR, "") +.value("B_TIME_SEPARATOR", country_strings::B_TIME_SEPARATOR, "") +.value("B_NUM_COUNTRY_STRINGS", country_strings::B_NUM_COUNTRY_STRINGS, "") +.export_values(); + +py::enum_(m, "language_strings", "") +.value("B_LANGUAGE_STRINGS_BASE", language_strings::B_LANGUAGE_STRINGS_BASE, "") +.value("B_YESTERDAY_STRING", language_strings::B_YESTERDAY_STRING, "") +.value("B_TODAY_STRING", language_strings::B_TODAY_STRING, "") +.value("B_TOMORROW_STRING", language_strings::B_TOMORROW_STRING, "") +.value("B_FUTURE_STRING", language_strings::B_FUTURE_STRING, "") +.value("B_DAY_1", language_strings::B_DAY_1, "") +.value("B_DAY_2", language_strings::B_DAY_2, "") +.value("B_DAY_3", language_strings::B_DAY_3, "") +.value("B_DAY_4", language_strings::B_DAY_4, "") +.value("B_DAY_5", language_strings::B_DAY_5, "") +.value("B_DAY_6", language_strings::B_DAY_6, "") +.value("B_DAY_7", language_strings::B_DAY_7, "") +.value("B_AB_DAY_1", language_strings::B_AB_DAY_1, "") +.value("B_AB_DAY_2", language_strings::B_AB_DAY_2, "") +.value("B_AB_DAY_3", language_strings::B_AB_DAY_3, "") +.value("B_AB_DAY_4", language_strings::B_AB_DAY_4, "") +.value("B_AB_DAY_5", language_strings::B_AB_DAY_5, "") +.value("B_AB_DAY_6", language_strings::B_AB_DAY_6, "") +.value("B_AB_DAY_7", language_strings::B_AB_DAY_7, "") +.value("B_MON_1", language_strings::B_MON_1, "") +.value("B_MON_2", language_strings::B_MON_2, "") +.value("B_MON_3", language_strings::B_MON_3, "") +.value("B_MON_4", language_strings::B_MON_4, "") +.value("B_MON_5", language_strings::B_MON_5, "") +.value("B_MON_6", language_strings::B_MON_6, "") +.value("B_MON_7", language_strings::B_MON_7, "") +.value("B_MON_8", language_strings::B_MON_8, "") +.value("B_MON_9", language_strings::B_MON_9, "") +.value("B_MON_10", language_strings::B_MON_10, "") +.value("B_MON_11", language_strings::B_MON_11, "") +.value("B_MON_12", language_strings::B_MON_12, "") +.value("B_AB_MON_1", language_strings::B_AB_MON_1, "") +.value("B_AB_MON_2", language_strings::B_AB_MON_2, "") +.value("B_AB_MON_3", language_strings::B_AB_MON_3, "") +.value("B_AB_MON_4", language_strings::B_AB_MON_4, "") +.value("B_AB_MON_5", language_strings::B_AB_MON_5, "") +.value("B_AB_MON_6", language_strings::B_AB_MON_6, "") +.value("B_AB_MON_7", language_strings::B_AB_MON_7, "") +.value("B_AB_MON_8", language_strings::B_AB_MON_8, "") +.value("B_AB_MON_9", language_strings::B_AB_MON_9, "") +.value("B_AB_MON_10", language_strings::B_AB_MON_10, "") +.value("B_AB_MON_11", language_strings::B_AB_MON_11, "") +.value("B_AB_MON_12", language_strings::B_AB_MON_12, "") +.value("B_YES_EXPRESSION", language_strings::B_YES_EXPRESSION, "") +.value("B_NO_EXPRESSION", language_strings::B_NO_EXPRESSION, "") +.value("B_YES_STRING", language_strings::B_YES_STRING, "") +.value("B_NO_STRING", language_strings::B_NO_STRING, "") +.value("B_NUM_LANGUAGE_STRINGS", language_strings::B_NUM_LANGUAGE_STRINGS, "") +.export_values(); + +py::enum_(m, "other_locale_strings", "") +.value("B_OTHER_STRINGS_BASE", other_locale_strings::B_OTHER_STRINGS_BASE, "") +.value("B_CODESET", other_locale_strings::B_CODESET, "") +.value("B_ERA", other_locale_strings::B_ERA, "") +.value("B_ERA_DATE_FORMAT", other_locale_strings::B_ERA_DATE_FORMAT, "") +.value("B_ERA_DATE_TIME_FORMAT", other_locale_strings::B_ERA_DATE_TIME_FORMAT, "") +.value("B_ERA_TIME_FORMAT", other_locale_strings::B_ERA_TIME_FORMAT, "") +.value("B_ALT_DIGITS", other_locale_strings::B_ALT_DIGITS, "") +.export_values(); + + +} diff --git a/bindings/locale/NumberFormat.cpp b/bindings/locale/NumberFormat.cpp new file mode 100644 index 0000000..0a3a5e4 --- /dev/null +++ b/bindings/locale/NumberFormat.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_NumberFormat(py::module_& m) +{ +py::enum_(m, "BNumberElement", "") +.value("B_DECIMAL_SEPARATOR", BNumberElement::B_DECIMAL_SEPARATOR, "") +.value("B_GROUPING_SEPARATOR", BNumberElement::B_GROUPING_SEPARATOR, "") +.export_values(); + +py::class_(m, "BNumberFormat") +.def(py::init(), "") +.def(py::init(), "", py::arg("locale")) +.def("Format", py::overload_cast(&BNumberFormat::Format), "", py::arg("string"), py::arg("maxSize"), py::arg("value")) +.def("Format", [](BNumberFormat& self,const double value) { + BString string; + status_t r = self.Format(string, value); + return std::make_tuple(r,string); +} +, "", py::arg("value")) +.def("Format", py::overload_cast(&BNumberFormat::Format), "", py::arg("string"), py::arg("maxSize"), py::arg("value")) +.def("Format", [](BNumberFormat& self,int value) { + BString string; + status_t r = self.Format(string, value); + return std::make_tuple(r,string); +} +, "", py::arg("value")) +.def("FormatMonetary", py::overload_cast(&BNumberFormat::FormatMonetary), "", py::arg("string"), py::arg("maxSize"), py::arg("value")) +.def("FormatMonetary", [](BNumberFormat& self,const double value) { + BString string; + status_t r = self.FormatMonetary(string, value); + return std::make_tuple(r,string); +} +, "", py::arg("value")) +.def("FormatPercent", py::overload_cast(&BNumberFormat::FormatPercent), "", py::arg("string"), py::arg("maxSize"), py::arg("value")) +.def("FormatPercent", [](BNumberFormat& self,const double value) { + BString string; + status_t r = self.FormatPercent(string, value); + return std::make_tuple(r,string); +} +, "", py::arg("value")) +.def("Parse", [](BNumberFormat& self,const BString & string) { + double value; + status_t r = self.Parse(string, value); + return std::make_tuple(r,value); +} +, "", py::arg("string")) +.def("GetSeparator", &BNumberFormat::GetSeparator, "", py::arg("element")) +; + + +} diff --git a/bindings/locale/RelativeDateTimeFormat.cpp b/bindings/locale/RelativeDateTimeFormat.cpp new file mode 100644 index 0000000..b918e1d --- /dev/null +++ b/bindings/locale/RelativeDateTimeFormat.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +void define_RelativeDateTimeFormat(py::module_& m) +{ +m.attr("GregorianCalendar") = py::cast(GregorianCalendar); + +m.attr("RelativeDateTimeFormatter") = py::cast(RelativeDateTimeFormatter); + +py::class_(m, "BRelativeDateTimeFormat") +.def(py::init(), "") +.def(py::init(), "", py::arg("language"), py::arg("conventions")) +.def(py::init(), "", py::arg("other")) +.def("Format", [](BRelativeDateTimeFormat& self,const time_t timeValue) { + BString string; + status_t r = self.Format(string, timeValue); + return std::make_tuple(r,string); +} +, "", py::arg("timeValue")) +; + + +} diff --git a/bindings/locale/StringFormat.cpp b/bindings/locale/StringFormat.cpp new file mode 100644 index 0000000..67bcafc --- /dev/null +++ b/bindings/locale/StringFormat.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +void define_StringFormat(py::module_& m) +{ +m.attr("MessageFormat") = py::cast(MessageFormat); + +m.attr("UnicodeString") = py::cast(UnicodeString); + +py::class_(m, "BStringFormat") +.def(py::init(), "", py::arg("language"), py::arg("pattern")) +.def(py::init(), "", py::arg("pattern")) +.def("InitCheck", &BStringFormat::InitCheck, "") +.def("Format", [](BStringFormat& self,int64_t arg) { + BString buffer; + status_t r = self.Format(buffer, arg); + return std::make_tuple(r,buffer); +} +, "", py::arg("arg")) +; + + +} diff --git a/bindings/locale/TextEncoding.cpp b/bindings/locale/TextEncoding.cpp new file mode 100644 index 0000000..9c5e52b --- /dev/null +++ b/bindings/locale/TextEncoding.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; + +void define_TextEncoding(py::module_& m) +{ +py::class_(m, "BTextEncoding") +.def(py::init(), "", py::arg("name")) +.def(py::init(), "", py::arg("data"), py::arg("length")) +.def("InitCheck", &BTextEncoding::InitCheck, "") +.def("GetName", &BTextEncoding::GetName, "") +.def("Encode", [](BTextEncoding& self,const char * input,char * output) { + size_t inputLength; +size_t outputLength; + status_t r = self.Encode(input, inputLength, output, outputLength); + return std::make_tuple(r,inputLength,outputLength); +} +, "", py::arg("input"), py::arg("output")) +.def("Decode", [](BTextEncoding& self,const char * input,char * output) { + size_t inputLength; +size_t outputLength; + status_t r = self.Decode(input, inputLength, output, outputLength); + return std::make_tuple(r,inputLength,outputLength); +} +, "", py::arg("input"), py::arg("output")) +.def("Flush", [](BTextEncoding& self,char * output) { + size_t outputLength; + status_t r = self.Flush(output, outputLength); + return std::make_tuple(r,outputLength); +} +, "", py::arg("output")) +; + + +} diff --git a/bindings/locale/TimeFormat.cpp b/bindings/locale/TimeFormat.cpp new file mode 100644 index 0000000..ad6a2f4 --- /dev/null +++ b/bindings/locale/TimeFormat.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; + +PYBIND11_MODULE(TimeFormat, m) +{ +//m.attr("BTime") = py::cast(BTime); +//m.attr("BTime") = py::cast(BPrivate::BTime); + +py::class_(m, "BTimeFormat") +.def(py::init(), "") +.def(py::init(), "", py::arg("language"), py::arg("conventions")) +.def(py::init(), "", py::arg("other")) +.def("SetTimeFormat", &BTimeFormat::SetTimeFormat, "", py::arg("style"), py::arg("format")) +.def("Format", py::overload_cast(&BTimeFormat::Format, py::const_), "", py::arg("string"), py::arg("maxSize"), py::arg("time"), py::arg("style")) +//.def("Format", py::overload_cast(&BTimeFormat::Format, py::const_), "", py::arg("string"), py::arg("time"), py::arg("style"), py::arg("timeZone")=NULL) +//.def("Format", py::overload_cast(&BTimeFormat::Format, py::const_), "", py::arg("string"), py::arg("fieldPositions"), py::arg("fieldCount"), py::arg("time"), py::arg("style")) +.def("Format", [](BTimeFormat& self,const time_t time,const BTimeFormatStyle style,const BTimeZone * timeZone=NULL) { + BString string; + status_t r = self.Format(string, time, style, timeZone); + return std::make_tuple(r,string); +} +, "", py::arg("time"), py::arg("style"), py::arg("timeZone")=NULL) +.def("Format", [](BTimeFormat& self,time_t time,BTimeFormatStyle style) { + BString string; +int * fieldPositions; +int fieldCount; + status_t r = self.Format(string, fieldPositions, fieldCount, time, style); + return std::make_tuple(r,string,fieldPositions,fieldCount); +} +, "", py::arg("time"), py::arg("style")) +.def("GetTimeFields", [](BTimeFormat& self,BTimeFormatStyle style) { + BDateElement * fields; +int fieldCount; + status_t r = self.GetTimeFields(fields, fieldCount, style); + return std::make_tuple(r,fields,fieldCount); +} +, "", py::arg("style")) +.def("Parse", [](BTimeFormat& self,BString source,BTimeFormatStyle style) { + BPrivate::BTime output; + status_t r = self.Parse(source, style, output); + return std::make_tuple(r,output); +} +, "", py::arg("source"), py::arg("style")) +; + + +} diff --git a/bindings/locale/TimeUnitFormat.cpp b/bindings/locale/TimeUnitFormat.cpp new file mode 100644 index 0000000..63761a8 --- /dev/null +++ b/bindings/locale/TimeUnitFormat.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(TimeUnitFormat, m) +{ +py::enum_(m, "time_unit_style", "") +.value("B_TIME_UNIT_ABBREVIATED", time_unit_style::B_TIME_UNIT_ABBREVIATED, "") +.value("B_TIME_UNIT_FULL", time_unit_style::B_TIME_UNIT_FULL, "") +.export_values(); + +py::enum_(m, "time_unit_element", "") +.value("B_TIME_UNIT_YEAR", time_unit_element::B_TIME_UNIT_YEAR, "") +.value("B_TIME_UNIT_MONTH", time_unit_element::B_TIME_UNIT_MONTH, "") +.value("B_TIME_UNIT_WEEK", time_unit_element::B_TIME_UNIT_WEEK, "") +.value("B_TIME_UNIT_DAY", time_unit_element::B_TIME_UNIT_DAY, "") +.value("B_TIME_UNIT_HOUR", time_unit_element::B_TIME_UNIT_HOUR, "") +.value("B_TIME_UNIT_MINUTE", time_unit_element::B_TIME_UNIT_MINUTE, "") +.value("B_TIME_UNIT_SECOND", time_unit_element::B_TIME_UNIT_SECOND, "") +.value("B_TIME_UNIT_LAST", time_unit_element::B_TIME_UNIT_LAST, "") +.export_values(); + +//m.attr("TimeUnitFormat") = py::cast(TimeUnitFormat); TODO try to fix this, it's in ICU + +py::class_(m, "BTimeUnitFormat") +.def(py::init(), "", py::arg("style")=B_TIME_UNIT_FULL) +.def(py::init(), "", py::arg("language"), py::arg("conventions"), py::arg("style")=B_TIME_UNIT_FULL) +.def(py::init(), "", py::arg("other")) +.def("Format", [](BTimeUnitFormat& self,int value,const time_unit_element unit) { + BString buffer; + status_t r = self.Format(buffer, value, unit); + return std::make_tuple(r,buffer); +} +, "", py::arg("value"), py::arg("unit")) +; + + +} diff --git a/bindings/locale/TimeZone.cpp b/bindings/locale/TimeZone.cpp new file mode 100644 index 0000000..9154869 --- /dev/null +++ b/bindings/locale/TimeZone.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +void define_TimeZone(py::module_& m) +{ +m.attr("Locale") = py::cast(Locale); + +m.attr("TimeZone") = py::cast(TimeZone); + +py::class_(m, "BTimeZone") +.def(py::init(), "", py::arg("zoneID")=NULL, py::arg("language")=NULL) +.def(py::init(), "", py::arg("other")) +.def("operator=", &BTimeZone::operator=, "", py::arg("source")) +.def("ID", &BTimeZone::ID, "") +.def("Name", &BTimeZone::Name, "") +.def("DaylightSavingName", &BTimeZone::DaylightSavingName, "") +.def("ShortName", &BTimeZone::ShortName, "") +.def("ShortDaylightSavingName", &BTimeZone::ShortDaylightSavingName, "") +.def("OffsetFromGMT", &BTimeZone::OffsetFromGMT, "") +.def("SupportsDaylightSaving", &BTimeZone::SupportsDaylightSaving, "") +.def("InitCheck", &BTimeZone::InitCheck, "") +.def("SetTo", &BTimeZone::SetTo, "", py::arg("zoneID"), py::arg("language")=NULL) +.def("SetLanguage", &BTimeZone::SetLanguage, "", py::arg("language")) +.def_readwrite("kNameOfGmtZone", &BTimeZone::kNameOfGmtZone, "") +.def_readwrite("Private", &BTimeZone::Private, "") +; + + +} diff --git a/bindings/locale/UnicodeChar.cpp b/bindings/locale/UnicodeChar.cpp new file mode 100644 index 0000000..96341d1 --- /dev/null +++ b/bindings/locale/UnicodeChar.cpp @@ -0,0 +1,348 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +py::str ToUTF8(uint32_t c) { + char buffer[5] = {0}; // Un carattere UTF-8 può essere lungo fino a 4 byte + terminatore null + char* out = buffer; + BUnicodeChar::ToUTF8(c, &out); + return py::str(buffer); +} + +uint32_t FromUTF8(py::buffer in) { + py::buffer_info info = in.request(); + if (info.ndim != 1 || info.itemsize != 1) { + throw std::runtime_error("Buffer must be a 1-dimensional array of bytes"); + } + + const char* data = static_cast(info.ptr); + uint32_t result = BUnicodeChar::FromUTF8(&data); + + return result; +} + +PYBIND11_MODULE(UnicodeChar, m) +{ +py::enum_(m, "unicode_char_category", "") +.value("B_UNICODE_UNASSIGNED", unicode_char_category::B_UNICODE_UNASSIGNED, "") +.value("B_UNICODE_GENERAL_OTHER_TYPES", unicode_char_category::B_UNICODE_GENERAL_OTHER_TYPES, "") +.value("B_UNICODE_UPPERCASE_LETTER", unicode_char_category::B_UNICODE_UPPERCASE_LETTER, "") +.value("B_UNICODE_LOWERCASE_LETTER", unicode_char_category::B_UNICODE_LOWERCASE_LETTER, "") +.value("B_UNICODE_TITLECASE_LETTER", unicode_char_category::B_UNICODE_TITLECASE_LETTER, "") +.value("B_UNICODE_MODIFIER_LETTER", unicode_char_category::B_UNICODE_MODIFIER_LETTER, "") +.value("B_UNICODE_OTHER_LETTER", unicode_char_category::B_UNICODE_OTHER_LETTER, "") +.value("B_UNICODE_NON_SPACING_MARK", unicode_char_category::B_UNICODE_NON_SPACING_MARK, "") +.value("B_UNICODE_ENCLOSING_MARK", unicode_char_category::B_UNICODE_ENCLOSING_MARK, "") +.value("B_UNICODE_COMBINING_SPACING_MARK", unicode_char_category::B_UNICODE_COMBINING_SPACING_MARK, "") +.value("B_UNICODE_DECIMAL_DIGIT_NUMBER", unicode_char_category::B_UNICODE_DECIMAL_DIGIT_NUMBER, "") +.value("B_UNICODE_LETTER_NUMBER", unicode_char_category::B_UNICODE_LETTER_NUMBER, "") +.value("B_UNICODE_OTHER_NUMBER", unicode_char_category::B_UNICODE_OTHER_NUMBER, "") +.value("B_UNICODE_SPACE_SEPARATOR", unicode_char_category::B_UNICODE_SPACE_SEPARATOR, "") +.value("B_UNICODE_LINE_SEPARATOR", unicode_char_category::B_UNICODE_LINE_SEPARATOR, "") +.value("B_UNICODE_PARAGRAPH_SEPARATOR", unicode_char_category::B_UNICODE_PARAGRAPH_SEPARATOR, "") +.value("B_UNICODE_CONTROL_CHAR", unicode_char_category::B_UNICODE_CONTROL_CHAR, "") +.value("B_UNICODE_FORMAT_CHAR", unicode_char_category::B_UNICODE_FORMAT_CHAR, "") +.value("B_UNICODE_PRIVATE_USE_CHAR", unicode_char_category::B_UNICODE_PRIVATE_USE_CHAR, "") +.value("B_UNICODE_SURROGATE", unicode_char_category::B_UNICODE_SURROGATE, "") +.value("B_UNICODE_DASH_PUNCTUATION", unicode_char_category::B_UNICODE_DASH_PUNCTUATION, "") +.value("B_UNICODE_START_PUNCTUATION", unicode_char_category::B_UNICODE_START_PUNCTUATION, "") +.value("B_UNICODE_END_PUNCTUATION", unicode_char_category::B_UNICODE_END_PUNCTUATION, "") +.value("B_UNICODE_CONNECTOR_PUNCTUATION", unicode_char_category::B_UNICODE_CONNECTOR_PUNCTUATION, "") +.value("B_UNICODE_OTHER_PUNCTUATION", unicode_char_category::B_UNICODE_OTHER_PUNCTUATION, "") +.value("B_UNICODE_MATH_SYMBOL", unicode_char_category::B_UNICODE_MATH_SYMBOL, "") +.value("B_UNICODE_CURRENCY_SYMBOL", unicode_char_category::B_UNICODE_CURRENCY_SYMBOL, "") +.value("B_UNICODE_MODIFIER_SYMBOL", unicode_char_category::B_UNICODE_MODIFIER_SYMBOL, "") +.value("B_UNICODE_OTHER_SYMBOL", unicode_char_category::B_UNICODE_OTHER_SYMBOL, "") +.value("B_UNICODE_INITIAL_PUNCTUATION", unicode_char_category::B_UNICODE_INITIAL_PUNCTUATION, "") +.value("B_UNICODE_FINAL_PUNCTUATION", unicode_char_category::B_UNICODE_FINAL_PUNCTUATION, "") +.value("B_UNICODE_CATEGORY_COUNT", unicode_char_category::B_UNICODE_CATEGORY_COUNT, "") +.export_values(); + +py::enum_(m, "unicode_char_direction", "") +.value("B_UNICODE_LEFT_TO_RIGHT", unicode_char_direction::B_UNICODE_LEFT_TO_RIGHT, "") +.value("B_UNICODE_RIGHT_TO_LEFT", unicode_char_direction::B_UNICODE_RIGHT_TO_LEFT, "") +.value("B_UNICODE_EUROPEAN_NUMBER", unicode_char_direction::B_UNICODE_EUROPEAN_NUMBER, "") +.value("B_UNICODE_EUROPEAN_NUMBER_SEPARATOR", unicode_char_direction::B_UNICODE_EUROPEAN_NUMBER_SEPARATOR, "") +.value("B_UNICODE_EUROPEAN_NUMBER_TERMINATOR", unicode_char_direction::B_UNICODE_EUROPEAN_NUMBER_TERMINATOR, "") +.value("B_UNICODE_ARABIC_NUMBER", unicode_char_direction::B_UNICODE_ARABIC_NUMBER, "") +.value("B_UNICODE_COMMON_NUMBER_SEPARATOR", unicode_char_direction::B_UNICODE_COMMON_NUMBER_SEPARATOR, "") +.value("B_UNICODE_BLOCK_SEPARATOR", unicode_char_direction::B_UNICODE_BLOCK_SEPARATOR, "") +.value("B_UNICODE_SEGMENT_SEPARATOR", unicode_char_direction::B_UNICODE_SEGMENT_SEPARATOR, "") +.value("B_UNICODE_WHITE_SPACE_NEUTRAL", unicode_char_direction::B_UNICODE_WHITE_SPACE_NEUTRAL, "") +.value("B_UNICODE_OTHER_NEUTRAL", unicode_char_direction::B_UNICODE_OTHER_NEUTRAL, "") +.value("B_UNICODE_LEFT_TO_RIGHT_EMBEDDING", unicode_char_direction::B_UNICODE_LEFT_TO_RIGHT_EMBEDDING, "") +.value("B_UNICODE_LEFT_TO_RIGHT_OVERRIDE", unicode_char_direction::B_UNICODE_LEFT_TO_RIGHT_OVERRIDE, "") +.value("B_UNICODE_RIGHT_TO_LEFT_ARABIC", unicode_char_direction::B_UNICODE_RIGHT_TO_LEFT_ARABIC, "") +.value("B_UNICODE_RIGHT_TO_LEFT_EMBEDDING", unicode_char_direction::B_UNICODE_RIGHT_TO_LEFT_EMBEDDING, "") +.value("B_UNICODE_RIGHT_TO_LEFT_OVERRIDE", unicode_char_direction::B_UNICODE_RIGHT_TO_LEFT_OVERRIDE, "") +.value("B_UNICODE_POP_DIRECTIONAL_FORMAT", unicode_char_direction::B_UNICODE_POP_DIRECTIONAL_FORMAT, "") +.value("B_UNICODE_DIR_NON_SPACING_MARK", unicode_char_direction::B_UNICODE_DIR_NON_SPACING_MARK, "") +.value("B_UNICODE_BOUNDARY_NEUTRAL", unicode_char_direction::B_UNICODE_BOUNDARY_NEUTRAL, "") +.value("B_UNICODE_DIRECTION_COUNT", unicode_char_direction::B_UNICODE_DIRECTION_COUNT, "") +.export_values(); + +py::enum_(m, "unicode_char_script", "") +.value("B_UNICODE_NO_BLOCK", unicode_char_script::B_UNICODE_NO_BLOCK, "") +.value("B_UNICODE_BASIC_LATIN", unicode_char_script::B_UNICODE_BASIC_LATIN, "") +.value("B_UNICODE_LATIN_1_SUPPLEMENT", unicode_char_script::B_UNICODE_LATIN_1_SUPPLEMENT, "") +.value("B_UNICODE_LATIN_EXTENDED_A", unicode_char_script::B_UNICODE_LATIN_EXTENDED_A, "") +.value("B_UNICODE_LATIN_EXTENDED_B", unicode_char_script::B_UNICODE_LATIN_EXTENDED_B, "") +.value("B_UNICODE_IPA_EXTENSIONS", unicode_char_script::B_UNICODE_IPA_EXTENSIONS, "") +.value("B_UNICODE_SPACING_MODIFIER_LETTERS", unicode_char_script::B_UNICODE_SPACING_MODIFIER_LETTERS, "") +.value("B_UNICODE_COMBINING_DIACRITICAL_MARKS", unicode_char_script::B_UNICODE_COMBINING_DIACRITICAL_MARKS, "") +.value("B_UNICODE_GREEK", unicode_char_script::B_UNICODE_GREEK, "") +.value("B_UNICODE_CYRILLIC", unicode_char_script::B_UNICODE_CYRILLIC, "") +.value("B_UNICODE_ARMENIAN", unicode_char_script::B_UNICODE_ARMENIAN, "") +.value("B_UNICODE_HEBREW", unicode_char_script::B_UNICODE_HEBREW, "") +.value("B_UNICODE_ARABIC", unicode_char_script::B_UNICODE_ARABIC, "") +.value("B_UNICODE_SYRIAC", unicode_char_script::B_UNICODE_SYRIAC, "") +.value("B_UNICODE_THAANA", unicode_char_script::B_UNICODE_THAANA, "") +.value("B_UNICODE_DEVANAGARI", unicode_char_script::B_UNICODE_DEVANAGARI, "") +.value("B_UNICODE_BENGALI", unicode_char_script::B_UNICODE_BENGALI, "") +.value("B_UNICODE_GURMUKHI", unicode_char_script::B_UNICODE_GURMUKHI, "") +.value("B_UNICODE_GUJARATI", unicode_char_script::B_UNICODE_GUJARATI, "") +.value("B_UNICODE_ORIYA", unicode_char_script::B_UNICODE_ORIYA, "") +.value("B_UNICODE_TAMIL", unicode_char_script::B_UNICODE_TAMIL, "") +.value("B_UNICODE_TELUGU", unicode_char_script::B_UNICODE_TELUGU, "") +.value("B_UNICODE_KANNADA", unicode_char_script::B_UNICODE_KANNADA, "") +.value("B_UNICODE_MALAYALAM", unicode_char_script::B_UNICODE_MALAYALAM, "") +.value("B_UNICODE_SINHALA", unicode_char_script::B_UNICODE_SINHALA, "") +.value("B_UNICODE_THAI", unicode_char_script::B_UNICODE_THAI, "") +.value("B_UNICODE_LAO", unicode_char_script::B_UNICODE_LAO, "") +.value("B_UNICODE_TIBETAN", unicode_char_script::B_UNICODE_TIBETAN, "") +.value("B_UNICODE_MYANMAR", unicode_char_script::B_UNICODE_MYANMAR, "") +.value("B_UNICODE_GEORGIAN", unicode_char_script::B_UNICODE_GEORGIAN, "") +.value("B_UNICODE_HANGUL_JAMO", unicode_char_script::B_UNICODE_HANGUL_JAMO, "") +.value("B_UNICODE_ETHIOPIC", unicode_char_script::B_UNICODE_ETHIOPIC, "") +.value("B_UNICODE_CHEROKEE", unicode_char_script::B_UNICODE_CHEROKEE, "") +.value("B_UNICODE_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS", unicode_char_script::B_UNICODE_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, "") +.value("B_UNICODE_OGHAM", unicode_char_script::B_UNICODE_OGHAM, "") +.value("B_UNICODE_RUNIC", unicode_char_script::B_UNICODE_RUNIC, "") +.value("B_UNICODE_KHMER", unicode_char_script::B_UNICODE_KHMER, "") +.value("B_UNICODE_MONGOLIAN", unicode_char_script::B_UNICODE_MONGOLIAN, "") +.value("B_UNICODE_LATIN_EXTENDED_ADDITIONAL", unicode_char_script::B_UNICODE_LATIN_EXTENDED_ADDITIONAL, "") +.value("B_UNICODE_GREEK_EXTENDED", unicode_char_script::B_UNICODE_GREEK_EXTENDED, "") +.value("B_UNICODE_GENERAL_PUNCTUATION", unicode_char_script::B_UNICODE_GENERAL_PUNCTUATION, "") +.value("B_UNICODE_SUPERSCRIPTS_AND_SUBSCRIPTS", unicode_char_script::B_UNICODE_SUPERSCRIPTS_AND_SUBSCRIPTS, "") +.value("B_UNICODE_CURRENCY_SYMBOLS", unicode_char_script::B_UNICODE_CURRENCY_SYMBOLS, "") +.value("B_UNICODE_COMBINING_MARKS_FOR_SYMBOLS", unicode_char_script::B_UNICODE_COMBINING_MARKS_FOR_SYMBOLS, "") +.value("B_UNICODE_LETTERLIKE_SYMBOLS", unicode_char_script::B_UNICODE_LETTERLIKE_SYMBOLS, "") +.value("B_UNICODE_NUMBER_FORMS", unicode_char_script::B_UNICODE_NUMBER_FORMS, "") +.value("B_UNICODE_ARROWS", unicode_char_script::B_UNICODE_ARROWS, "") +.value("B_UNICODE_MATHEMATICAL_OPERATORS", unicode_char_script::B_UNICODE_MATHEMATICAL_OPERATORS, "") +.value("B_UNICODE_MISCELLANEOUS_TECHNICAL", unicode_char_script::B_UNICODE_MISCELLANEOUS_TECHNICAL, "") +.value("B_UNICODE_CONTROL_PICTURES", unicode_char_script::B_UNICODE_CONTROL_PICTURES, "") +.value("B_UNICODE_OPTICAL_CHARACTER_RECOGNITION", unicode_char_script::B_UNICODE_OPTICAL_CHARACTER_RECOGNITION, "") +.value("B_UNICODE_ENCLOSED_ALPHANUMERICS", unicode_char_script::B_UNICODE_ENCLOSED_ALPHANUMERICS, "") +.value("B_UNICODE_BOX_DRAWING", unicode_char_script::B_UNICODE_BOX_DRAWING, "") +.value("B_UNICODE_BLOCK_ELEMENTS", unicode_char_script::B_UNICODE_BLOCK_ELEMENTS, "") +.value("B_UNICODE_GEOMETRIC_SHAPES", unicode_char_script::B_UNICODE_GEOMETRIC_SHAPES, "") +.value("B_UNICODE_MISCELLANEOUS_SYMBOLS", unicode_char_script::B_UNICODE_MISCELLANEOUS_SYMBOLS, "") +.value("B_UNICODE_DINGBATS", unicode_char_script::B_UNICODE_DINGBATS, "") +.value("B_UNICODE_BRAILLE_PATTERNS", unicode_char_script::B_UNICODE_BRAILLE_PATTERNS, "") +.value("B_UNICODE_CJK_RADICALS_SUPPLEMENT", unicode_char_script::B_UNICODE_CJK_RADICALS_SUPPLEMENT, "") +.value("B_UNICODE_KANGXI_RADICALS", unicode_char_script::B_UNICODE_KANGXI_RADICALS, "") +.value("B_UNICODE_IDEOGRAPHIC_DESCRIPTION_CHARACTERS", unicode_char_script::B_UNICODE_IDEOGRAPHIC_DESCRIPTION_CHARACTERS, "") +.value("B_UNICODE_CJK_SYMBOLS_AND_PUNCTUATION", unicode_char_script::B_UNICODE_CJK_SYMBOLS_AND_PUNCTUATION, "") +.value("B_UNICODE_HIRAGANA", unicode_char_script::B_UNICODE_HIRAGANA, "") +.value("B_UNICODE_KATAKANA", unicode_char_script::B_UNICODE_KATAKANA, "") +.value("B_UNICODE_BOPOMOFO", unicode_char_script::B_UNICODE_BOPOMOFO, "") +.value("B_UNICODE_HANGUL_COMPATIBILITY_JAMO", unicode_char_script::B_UNICODE_HANGUL_COMPATIBILITY_JAMO, "") +.value("B_UNICODE_KANBUN", unicode_char_script::B_UNICODE_KANBUN, "") +.value("B_UNICODE_BOPOMOFO_EXTENDED", unicode_char_script::B_UNICODE_BOPOMOFO_EXTENDED, "") +.value("B_UNICODE_ENCLOSED_CJK_LETTERS_AND_MONTHS", unicode_char_script::B_UNICODE_ENCLOSED_CJK_LETTERS_AND_MONTHS, "") +.value("B_UNICODE_CJK_COMPATIBILITY", unicode_char_script::B_UNICODE_CJK_COMPATIBILITY, "") +.value("B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A", unicode_char_script::B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, "") +.value("B_UNICODE_CJK_UNIFIED_IDEOGRAPHS", unicode_char_script::B_UNICODE_CJK_UNIFIED_IDEOGRAPHS, "") +.value("B_UNICODE_YI_SYLLABLES", unicode_char_script::B_UNICODE_YI_SYLLABLES, "") +.value("B_UNICODE_YI_RADICALS", unicode_char_script::B_UNICODE_YI_RADICALS, "") +.value("B_UNICODE_HANGUL_SYLLABLES", unicode_char_script::B_UNICODE_HANGUL_SYLLABLES, "") +.value("B_UNICODE_HIGH_SURROGATES", unicode_char_script::B_UNICODE_HIGH_SURROGATES, "") +.value("B_UNICODE_HIGH_PRIVATE_USE_SURROGATES", unicode_char_script::B_UNICODE_HIGH_PRIVATE_USE_SURROGATES, "") +.value("B_UNICODE_LOW_SURROGATES", unicode_char_script::B_UNICODE_LOW_SURROGATES, "") +.value("B_UNICODE_PRIVATE_USE", unicode_char_script::B_UNICODE_PRIVATE_USE, "") +.value("B_UNICODE_PRIVATE_USE_AREA", unicode_char_script::B_UNICODE_PRIVATE_USE_AREA, "") +.value("B_UNICODE_CJK_COMPATIBILITY_IDEOGRAPHS", unicode_char_script::B_UNICODE_CJK_COMPATIBILITY_IDEOGRAPHS, "") +.value("B_UNICODE_ALPHABETIC_PRESENTATION_FORMS", unicode_char_script::B_UNICODE_ALPHABETIC_PRESENTATION_FORMS, "") +.value("B_UNICODE_ARABIC_PRESENTATION_FORMS_A", unicode_char_script::B_UNICODE_ARABIC_PRESENTATION_FORMS_A, "") +.value("B_UNICODE_COMBINING_HALF_MARKS", unicode_char_script::B_UNICODE_COMBINING_HALF_MARKS, "") +.value("B_UNICODE_CJK_COMPATIBILITY_FORMS", unicode_char_script::B_UNICODE_CJK_COMPATIBILITY_FORMS, "") +.value("B_UNICODE_SMALL_FORM_VARIANTS", unicode_char_script::B_UNICODE_SMALL_FORM_VARIANTS, "") +.value("B_UNICODE_ARABIC_PRESENTATION_FORMS_B", unicode_char_script::B_UNICODE_ARABIC_PRESENTATION_FORMS_B, "") +.value("B_UNICODE_SPECIALS", unicode_char_script::B_UNICODE_SPECIALS, "") +.value("B_UNICODE_HALFWIDTH_AND_FULLWIDTH_FORMS", unicode_char_script::B_UNICODE_HALFWIDTH_AND_FULLWIDTH_FORMS, "") +.value("B_UNICODE_OLD_ITALIC", unicode_char_script::B_UNICODE_OLD_ITALIC, "") +.value("B_UNICODE_GOTHIC", unicode_char_script::B_UNICODE_GOTHIC, "") +.value("B_UNICODE_DESERET", unicode_char_script::B_UNICODE_DESERET, "") +.value("B_UNICODE_BYZANTINE_MUSICAL_SYMBOLS", unicode_char_script::B_UNICODE_BYZANTINE_MUSICAL_SYMBOLS, "") +.value("B_UNICODE_MUSICAL_SYMBOLS", unicode_char_script::B_UNICODE_MUSICAL_SYMBOLS, "") +.value("B_UNICODE_MATHEMATICAL_ALPHANUMERIC_SYMBOLS", unicode_char_script::B_UNICODE_MATHEMATICAL_ALPHANUMERIC_SYMBOLS, "") +.value("B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B", unicode_char_script::B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B, "") +.value("B_UNICODE_CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT", unicode_char_script::B_UNICODE_CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT, "") +.value("B_UNICODE_TAGS", unicode_char_script::B_UNICODE_TAGS, "") +.value("B_UNICODE_CYRILLIC_SUPPLEMENTARY", unicode_char_script::B_UNICODE_CYRILLIC_SUPPLEMENTARY, "") +.value("B_UNICODE_CYRILLIC_SUPPLEMENT", unicode_char_script::B_UNICODE_CYRILLIC_SUPPLEMENT, "") +.value("B_UNICODE_TAGALOG", unicode_char_script::B_UNICODE_TAGALOG, "") +.value("B_UNICODE_HANUNOO", unicode_char_script::B_UNICODE_HANUNOO, "") +.value("B_UNICODE_BUHID", unicode_char_script::B_UNICODE_BUHID, "") +.value("B_UNICODE_TAGBANWA", unicode_char_script::B_UNICODE_TAGBANWA, "") +.value("B_UNICODE_MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A", unicode_char_script::B_UNICODE_MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A, "") +.value("B_UNICODE_SUPPLEMENTAL_ARROWS_A", unicode_char_script::B_UNICODE_SUPPLEMENTAL_ARROWS_A, "") +.value("B_UNICODE_SUPPLEMENTAL_ARROWS_B", unicode_char_script::B_UNICODE_SUPPLEMENTAL_ARROWS_B, "") +.value("B_UNICODE_MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B", unicode_char_script::B_UNICODE_MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B, "") +.value("B_UNICODE_SUPPLEMENTAL_MATHEMATICAL_OPERATORS", unicode_char_script::B_UNICODE_SUPPLEMENTAL_MATHEMATICAL_OPERATORS, "") +.value("B_UNICODE_KATAKANA_PHONETIC_EXTENSIONS", unicode_char_script::B_UNICODE_KATAKANA_PHONETIC_EXTENSIONS, "") +.value("B_UNICODE_VARIATION_SELECTORS", unicode_char_script::B_UNICODE_VARIATION_SELECTORS, "") +.value("B_UNICODE_SUPPLEMENTARY_PRIVATE_USE_AREA_A", unicode_char_script::B_UNICODE_SUPPLEMENTARY_PRIVATE_USE_AREA_A, "") +.value("B_UNICODE_SUPPLEMENTARY_PRIVATE_USE_AREA_B", unicode_char_script::B_UNICODE_SUPPLEMENTARY_PRIVATE_USE_AREA_B, "") +.value("B_UNICODE_LIMBU", unicode_char_script::B_UNICODE_LIMBU, "") +.value("B_UNICODE_TAI_LE", unicode_char_script::B_UNICODE_TAI_LE, "") +.value("B_UNICODE_KHMER_SYMBOLS", unicode_char_script::B_UNICODE_KHMER_SYMBOLS, "") +.value("B_UNICODE_PHONETIC_EXTENSIONS", unicode_char_script::B_UNICODE_PHONETIC_EXTENSIONS, "") +.value("B_UNICODE_MISCELLANEOUS_SYMBOLS_AND_ARROWS", unicode_char_script::B_UNICODE_MISCELLANEOUS_SYMBOLS_AND_ARROWS, "") +.value("B_UNICODE_YIJING_HEXAGRAM_SYMBOLS", unicode_char_script::B_UNICODE_YIJING_HEXAGRAM_SYMBOLS, "") +.value("B_UNICODE_LINEAR_B_SYLLABARY", unicode_char_script::B_UNICODE_LINEAR_B_SYLLABARY, "") +.value("B_UNICODE_LINEAR_B_IDEOGRAMS", unicode_char_script::B_UNICODE_LINEAR_B_IDEOGRAMS, "") +.value("B_UNICODE_AEGEAN_NUMBERS", unicode_char_script::B_UNICODE_AEGEAN_NUMBERS, "") +.value("B_UNICODE_UGARITIC", unicode_char_script::B_UNICODE_UGARITIC, "") +.value("B_UNICODE_SHAVIAN", unicode_char_script::B_UNICODE_SHAVIAN, "") +.value("B_UNICODE_OSMANYA", unicode_char_script::B_UNICODE_OSMANYA, "") +.value("B_UNICODE_CYPRIOT_SYLLABARY", unicode_char_script::B_UNICODE_CYPRIOT_SYLLABARY, "") +.value("B_UNICODE_TAI_XUAN_JING_SYMBOLS", unicode_char_script::B_UNICODE_TAI_XUAN_JING_SYMBOLS, "") +.value("B_UNICODE_VARIATION_SELECTORS_SUPPLEMENT", unicode_char_script::B_UNICODE_VARIATION_SELECTORS_SUPPLEMENT, "") +.value("B_UNICODE_ANCIENT_GREEK_MUSICAL_NOTATION", unicode_char_script::B_UNICODE_ANCIENT_GREEK_MUSICAL_NOTATION, "") +.value("B_UNICODE_ANCIENT_GREEK_NUMBERS", unicode_char_script::B_UNICODE_ANCIENT_GREEK_NUMBERS, "") +.value("B_UNICODE_ARABIC_SUPPLEMENT", unicode_char_script::B_UNICODE_ARABIC_SUPPLEMENT, "") +.value("B_UNICODE_BUGINESE", unicode_char_script::B_UNICODE_BUGINESE, "") +.value("B_UNICODE_CJK_STROKES", unicode_char_script::B_UNICODE_CJK_STROKES, "") +.value("B_UNICODE_COMBINING_DIACRITICAL_MARKS_SUPPLEMENT", unicode_char_script::B_UNICODE_COMBINING_DIACRITICAL_MARKS_SUPPLEMENT, "") +.value("B_UNICODE_COPTIC", unicode_char_script::B_UNICODE_COPTIC, "") +.value("B_UNICODE_ETHIOPIC_EXTENDED", unicode_char_script::B_UNICODE_ETHIOPIC_EXTENDED, "") +.value("B_UNICODE_ETHIOPIC_SUPPLEMENT", unicode_char_script::B_UNICODE_ETHIOPIC_SUPPLEMENT, "") +.value("B_UNICODE_GEORGIAN_SUPPLEMENT", unicode_char_script::B_UNICODE_GEORGIAN_SUPPLEMENT, "") +.value("B_UNICODE_GLAGOLITIC", unicode_char_script::B_UNICODE_GLAGOLITIC, "") +.value("B_UNICODE_KHAROSHTHI", unicode_char_script::B_UNICODE_KHAROSHTHI, "") +.value("B_UNICODE_MODIFIER_TONE_LETTERS", unicode_char_script::B_UNICODE_MODIFIER_TONE_LETTERS, "") +.value("B_UNICODE_NEW_TAI_LUE", unicode_char_script::B_UNICODE_NEW_TAI_LUE, "") +.value("B_UNICODE_OLD_PERSIAN", unicode_char_script::B_UNICODE_OLD_PERSIAN, "") +.value("B_UNICODE_PHONETIC_EXTENSIONS_SUPPLEMENT", unicode_char_script::B_UNICODE_PHONETIC_EXTENSIONS_SUPPLEMENT, "") +.value("B_UNICODE_SUPPLEMENTAL_PUNCTUATION", unicode_char_script::B_UNICODE_SUPPLEMENTAL_PUNCTUATION, "") +.value("B_UNICODE_SYLOTI_NAGRI", unicode_char_script::B_UNICODE_SYLOTI_NAGRI, "") +.value("B_UNICODE_TIFINAGH", unicode_char_script::B_UNICODE_TIFINAGH, "") +.value("B_UNICODE_VERTICAL_FORMS", unicode_char_script::B_UNICODE_VERTICAL_FORMS, "") +.value("B_UNICODE_NKO", unicode_char_script::B_UNICODE_NKO, "") +.value("B_UNICODE_BALINESE", unicode_char_script::B_UNICODE_BALINESE, "") +.value("B_UNICODE_LATIN_EXTENDED_C", unicode_char_script::B_UNICODE_LATIN_EXTENDED_C, "") +.value("B_UNICODE_LATIN_EXTENDED_D", unicode_char_script::B_UNICODE_LATIN_EXTENDED_D, "") +.value("B_UNICODE_PHAGS_PA", unicode_char_script::B_UNICODE_PHAGS_PA, "") +.value("B_UNICODE_PHOENICIAN", unicode_char_script::B_UNICODE_PHOENICIAN, "") +.value("B_UNICODE_CUNEIFORM", unicode_char_script::B_UNICODE_CUNEIFORM, "") +.value("B_UNICODE_CUNEIFORM_NUMBERS_AND_PUNCTUATION", unicode_char_script::B_UNICODE_CUNEIFORM_NUMBERS_AND_PUNCTUATION, "") +.value("B_UNICODE_COUNTING_ROD_NUMERALS", unicode_char_script::B_UNICODE_COUNTING_ROD_NUMERALS, "") +.value("B_UNICODE_SUNDANESE", unicode_char_script::B_UNICODE_SUNDANESE, "") +.value("B_UNICODE_LEPCHA", unicode_char_script::B_UNICODE_LEPCHA, "") +.value("B_UNICODE_OL_CHIKI", unicode_char_script::B_UNICODE_OL_CHIKI, "") +.value("B_UNICODE_CYRILLIC_EXTENDED_A", unicode_char_script::B_UNICODE_CYRILLIC_EXTENDED_A, "") +.value("B_UNICODE_VAI", unicode_char_script::B_UNICODE_VAI, "") +.value("B_UNICODE_CYRILLIC_EXTENDED_B", unicode_char_script::B_UNICODE_CYRILLIC_EXTENDED_B, "") +.value("B_UNICODE_SAURASHTRA", unicode_char_script::B_UNICODE_SAURASHTRA, "") +.value("B_UNICODE_KAYAH_LI", unicode_char_script::B_UNICODE_KAYAH_LI, "") +.value("B_UNICODE_REJANG", unicode_char_script::B_UNICODE_REJANG, "") +.value("B_UNICODE_CHAM", unicode_char_script::B_UNICODE_CHAM, "") +.value("B_UNICODE_ANCIENT_SYMBOLS", unicode_char_script::B_UNICODE_ANCIENT_SYMBOLS, "") +.value("B_UNICODE_PHAISTOS_DISC", unicode_char_script::B_UNICODE_PHAISTOS_DISC, "") +.value("B_UNICODE_LYCIAN", unicode_char_script::B_UNICODE_LYCIAN, "") +.value("B_UNICODE_CARIAN", unicode_char_script::B_UNICODE_CARIAN, "") +.value("B_UNICODE_LYDIAN", unicode_char_script::B_UNICODE_LYDIAN, "") +.value("B_UNICODE_MAHJONG_TILES", unicode_char_script::B_UNICODE_MAHJONG_TILES, "") +.value("B_UNICODE_DOMINO_TILES", unicode_char_script::B_UNICODE_DOMINO_TILES, "") +.value("B_UNICODE_SAMARITAN", unicode_char_script::B_UNICODE_SAMARITAN, "") +.value("B_UNICODE_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS_EXTENDED", unicode_char_script::B_UNICODE_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS_EXTENDED, "") +.value("B_UNICODE_TAI_THAM", unicode_char_script::B_UNICODE_TAI_THAM, "") +.value("B_UNICODE_VEDIC_EXTENSIONS", unicode_char_script::B_UNICODE_VEDIC_EXTENSIONS, "") +.value("B_UNICODE_LISU", unicode_char_script::B_UNICODE_LISU, "") +.value("B_UNICODE_BAMUM", unicode_char_script::B_UNICODE_BAMUM, "") +.value("B_UNICODE_COMMON_INDIC_NUMBER_FORMS", unicode_char_script::B_UNICODE_COMMON_INDIC_NUMBER_FORMS, "") +.value("B_UNICODE_DEVANAGARI_EXTENDED", unicode_char_script::B_UNICODE_DEVANAGARI_EXTENDED, "") +.value("B_UNICODE_HANGUL_JAMO_EXTENDED_A", unicode_char_script::B_UNICODE_HANGUL_JAMO_EXTENDED_A, "") +.value("B_UNICODE_JAVANESE", unicode_char_script::B_UNICODE_JAVANESE, "") +.value("B_UNICODE_MYANMAR_EXTENDED_A", unicode_char_script::B_UNICODE_MYANMAR_EXTENDED_A, "") +.value("B_UNICODE_TAI_VIET", unicode_char_script::B_UNICODE_TAI_VIET, "") +.value("B_UNICODE_MEETEI_MAYEK", unicode_char_script::B_UNICODE_MEETEI_MAYEK, "") +.value("B_UNICODE_HANGUL_JAMO_EXTENDED_B", unicode_char_script::B_UNICODE_HANGUL_JAMO_EXTENDED_B, "") +.value("B_UNICODE_IMPERIAL_ARAMAIC", unicode_char_script::B_UNICODE_IMPERIAL_ARAMAIC, "") +.value("B_UNICODE_OLD_SOUTH_ARABIAN", unicode_char_script::B_UNICODE_OLD_SOUTH_ARABIAN, "") +.value("B_UNICODE_AVESTAN", unicode_char_script::B_UNICODE_AVESTAN, "") +.value("B_UNICODE_INSCRIPTIONAL_PARTHIAN", unicode_char_script::B_UNICODE_INSCRIPTIONAL_PARTHIAN, "") +.value("B_UNICODE_INSCRIPTIONAL_PAHLAVI", unicode_char_script::B_UNICODE_INSCRIPTIONAL_PAHLAVI, "") +.value("B_UNICODE_OLD_TURKIC", unicode_char_script::B_UNICODE_OLD_TURKIC, "") +.value("B_UNICODE_RUMI_NUMERAL_SYMBOLS", unicode_char_script::B_UNICODE_RUMI_NUMERAL_SYMBOLS, "") +.value("B_UNICODE_KAITHI", unicode_char_script::B_UNICODE_KAITHI, "") +.value("B_UNICODE_EGYPTIAN_HIEROGLYPHS", unicode_char_script::B_UNICODE_EGYPTIAN_HIEROGLYPHS, "") +.value("B_UNICODE_ENCLOSED_ALPHANUMERIC_SUPPLEMENT", unicode_char_script::B_UNICODE_ENCLOSED_ALPHANUMERIC_SUPPLEMENT, "") +.value("B_UNICODE_ENCLOSED_IDEOGRAPHIC_SUPPLEMENT", unicode_char_script::B_UNICODE_ENCLOSED_IDEOGRAPHIC_SUPPLEMENT, "") +.value("B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_C", unicode_char_script::B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_C, "") +.value("B_UNICODE_MANDAIC", unicode_char_script::B_UNICODE_MANDAIC, "") +.value("B_UNICODE_BATAK", unicode_char_script::B_UNICODE_BATAK, "") +.value("B_UNICODE_ETHIOPIC_EXTENDED_A", unicode_char_script::B_UNICODE_ETHIOPIC_EXTENDED_A, "") +.value("B_UNICODE_BRAHMI", unicode_char_script::B_UNICODE_BRAHMI, "") +.value("B_UNICODE_BAMUM_SUPPLEMENT", unicode_char_script::B_UNICODE_BAMUM_SUPPLEMENT, "") +.value("B_UNICODE_KANA_SUPPLEMENT", unicode_char_script::B_UNICODE_KANA_SUPPLEMENT, "") +.value("B_UNICODE_PLAYING_CARDS", unicode_char_script::B_UNICODE_PLAYING_CARDS, "") +.value("B_UNICODE_MISCELLANEOUS_SYMBOLS_AND_PICTOGRAPHS", unicode_char_script::B_UNICODE_MISCELLANEOUS_SYMBOLS_AND_PICTOGRAPHS, "") +.value("B_UNICODE_EMOTICONS", unicode_char_script::B_UNICODE_EMOTICONS, "") +.value("B_UNICODE_TRANSPORT_AND_MAP_SYMBOLS", unicode_char_script::B_UNICODE_TRANSPORT_AND_MAP_SYMBOLS, "") +.value("B_UNICODE_ALCHEMICAL_SYMBOLS", unicode_char_script::B_UNICODE_ALCHEMICAL_SYMBOLS, "") +.value("B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_D", unicode_char_script::B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_D, "") +.value("B_UNICODE_SCRIPT_COUNT", unicode_char_script::B_UNICODE_SCRIPT_COUNT, "") +.value("B_UNICODE_NO_SCRIPT", unicode_char_script::B_UNICODE_NO_SCRIPT, "") +.value("B_UNICODE_INVALID_CODE", unicode_char_script::B_UNICODE_INVALID_CODE, "") +.export_values(); + +py::enum_(m, "unicode_east_asian_width", "") +.value("B_UNICODE_EA_NEUTRAL", unicode_east_asian_width::B_UNICODE_EA_NEUTRAL, "") +.value("B_UNICODE_EA_AMBIGUOUS", unicode_east_asian_width::B_UNICODE_EA_AMBIGUOUS, "") +.value("B_UNICODE_EA_HALFWIDTH", unicode_east_asian_width::B_UNICODE_EA_HALFWIDTH, "") +.value("B_UNICODE_EA_FULLWIDTH", unicode_east_asian_width::B_UNICODE_EA_FULLWIDTH, "") +.value("B_UNICODE_EA_NARROW", unicode_east_asian_width::B_UNICODE_EA_NARROW, "") +.value("B_UNICODE_EA_WIDE", unicode_east_asian_width::B_UNICODE_EA_WIDE, "") +.value("B_UNICODE_EA_COUNT", unicode_east_asian_width::B_UNICODE_EA_COUNT, "") +.export_values(); + +py::class_(m, "BUnicodeChar") +.def_static("IsAlpha", &BUnicodeChar::IsAlpha, "", py::arg("c")) +.def_static("IsAlNum", &BUnicodeChar::IsAlNum, "", py::arg("c")) +.def_static("IsDigit", &BUnicodeChar::IsDigit, "", py::arg("c")) +.def_static("IsHexDigit", &BUnicodeChar::IsHexDigit, "", py::arg("c")) +.def_static("IsUpper", &BUnicodeChar::IsUpper, "", py::arg("c")) +.def_static("IsLower", &BUnicodeChar::IsLower, "", py::arg("c")) +.def_static("IsSpace", &BUnicodeChar::IsSpace, "", py::arg("c")) +.def_static("IsWhitespace", &BUnicodeChar::IsWhitespace, "", py::arg("c")) +.def_static("IsControl", &BUnicodeChar::IsControl, "", py::arg("c")) +.def_static("IsPunctuation", &BUnicodeChar::IsPunctuation, "", py::arg("c")) +.def_static("IsPrintable", &BUnicodeChar::IsPrintable, "", py::arg("c")) +.def_static("IsTitle", &BUnicodeChar::IsTitle, "", py::arg("c")) +.def_static("IsDefined", &BUnicodeChar::IsDefined, "", py::arg("c")) +.def_static("IsBase", &BUnicodeChar::IsBase, "", py::arg("c")) +.def_static("Type", &BUnicodeChar::Type, "", py::arg("c")) +.def_static("ToLower", &BUnicodeChar::ToLower, "", py::arg("c")) +.def_static("ToUpper", &BUnicodeChar::ToUpper, "", py::arg("c")) +.def_static("ToTitle", &BUnicodeChar::ToTitle, "", py::arg("c")) +.def_static("DigitValue", &BUnicodeChar::DigitValue, "", py::arg("c")) +.def_static("EastAsianWidth", &BUnicodeChar::EastAsianWidth, "", py::arg("c")) +//.def_static("ToUTF8", &BUnicodeChar::ToUTF8, "", py::arg("c"), py::arg("out")) +.def_static("ToUTF8", &ToUTF8, "wrapper to py::str", py::arg("c")) +//.def_static("FromUTF8", py::overload_cast(&BUnicodeChar::FromUTF8), "", py::arg("in")) +.def_static("FromUTF8Buffer", &FromUTF8, "wrapper from py::buffer", py::arg("in")) +.def_static("FromUTF8", py::overload_cast(&BUnicodeChar::FromUTF8), "", py::arg("in")) +.def_static("UTF8StringLength", py::overload_cast(&BUnicodeChar::UTF8StringLength), "", py::arg("string")) +.def_static("UTF8StringLength", py::overload_cast(&BUnicodeChar::UTF8StringLength), "", py::arg("string"), py::arg("maxLength")) +; + + +} From 85dfd129f155bd125f14ab1775d3936cff9fd082 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 2 Sep 2024 08:48:29 +0200 Subject: [PATCH 049/115] add locale/StringFormat.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/locale/StringFormat.cpp | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Jamfile b/Jamfile index a101d69..fa6c447 100644 --- a/Jamfile +++ b/Jamfile @@ -311,6 +311,7 @@ local sourceFiles = DurationFormat.cpp TimeFormat.cpp UnicodeChar.cpp + StringFormat.cpp ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 216df89..c2f99e2 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -188,6 +188,7 @@ from .DurationFormat import * from .TimeFormat import * from .UnicodeChar import * +from .StringFormat import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/locale/StringFormat.cpp b/bindings/locale/StringFormat.cpp index 67bcafc..cb2def6 100644 --- a/bindings/locale/StringFormat.cpp +++ b/bindings/locale/StringFormat.cpp @@ -8,11 +8,11 @@ namespace py = pybind11; using namespace U_ICU_NAMESPACE; -void define_StringFormat(py::module_& m) +PYBIND11_MODULE(StringFormat, m) { -m.attr("MessageFormat") = py::cast(MessageFormat); +//m.attr("MessageFormat") = py::cast(MessageFormat); -m.attr("UnicodeString") = py::cast(UnicodeString); +//m.attr("UnicodeString") = py::cast(UnicodeString); py::class_(m, "BStringFormat") .def(py::init(), "", py::arg("language"), py::arg("pattern")) From 2a5b04f00fc629886eae9f7804adf48f3c1a26f3 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 2 Sep 2024 17:38:57 +0200 Subject: [PATCH 050/115] Add locale/TextEncoding.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/locale/TextEncoding.cpp | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Jamfile b/Jamfile index fa6c447..5294739 100644 --- a/Jamfile +++ b/Jamfile @@ -312,6 +312,7 @@ local sourceFiles = TimeFormat.cpp UnicodeChar.cpp StringFormat.cpp + TextEncoding.cpp ; diff --git a/bindings/__init__.py b/bindings/__init__.py index c2f99e2..c2ec9e9 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -189,6 +189,7 @@ from .TimeFormat import * from .UnicodeChar import * from .StringFormat import * +from .TextEncoding import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/locale/TextEncoding.cpp b/bindings/locale/TextEncoding.cpp index 9c5e52b..9c9b36b 100644 --- a/bindings/locale/TextEncoding.cpp +++ b/bindings/locale/TextEncoding.cpp @@ -8,7 +8,7 @@ namespace py = pybind11; using namespace BPrivate; -void define_TextEncoding(py::module_& m) +PYBIND11_MODULE(TextEncoding, m) { py::class_(m, "BTextEncoding") .def(py::init(), "", py::arg("name")) From abccbd67c02012dba63dbf28b1725440ef3a285a Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 2 Sep 2024 17:41:36 +0200 Subject: [PATCH 051/115] Add locale/RelativeDateTimeFormat.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/locale/RelativeDateTimeFormat.cpp | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Jamfile b/Jamfile index 5294739..9c862fd 100644 --- a/Jamfile +++ b/Jamfile @@ -313,6 +313,7 @@ local sourceFiles = UnicodeChar.cpp StringFormat.cpp TextEncoding.cpp + RelativeDateTimeFormat.cpp ; diff --git a/bindings/__init__.py b/bindings/__init__.py index c2ec9e9..52e4069 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -190,6 +190,7 @@ from .UnicodeChar import * from .StringFormat import * from .TextEncoding import * +from .RelativeDateTimeFormat import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/locale/RelativeDateTimeFormat.cpp b/bindings/locale/RelativeDateTimeFormat.cpp index b918e1d..28e63cf 100644 --- a/bindings/locale/RelativeDateTimeFormat.cpp +++ b/bindings/locale/RelativeDateTimeFormat.cpp @@ -8,11 +8,11 @@ namespace py = pybind11; using namespace U_ICU_NAMESPACE; -void define_RelativeDateTimeFormat(py::module_& m) +PYBIND11_MODULE(RelativeDateTimeFormat, m) { -m.attr("GregorianCalendar") = py::cast(GregorianCalendar); +//m.attr("GregorianCalendar") = py::cast(GregorianCalendar); -m.attr("RelativeDateTimeFormatter") = py::cast(RelativeDateTimeFormatter); +//m.attr("RelativeDateTimeFormatter") = py::cast(RelativeDateTimeFormatter); py::class_(m, "BRelativeDateTimeFormat") .def(py::init(), "") From 8bb0937bdeb50d84ba50eca93ec03b1dbf34a179 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 2 Sep 2024 17:45:09 +0200 Subject: [PATCH 052/115] Add/update locale/NumberFormat.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/locale/NumberFormat.cpp | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Jamfile b/Jamfile index 9c862fd..4a4210e 100644 --- a/Jamfile +++ b/Jamfile @@ -314,6 +314,7 @@ local sourceFiles = StringFormat.cpp TextEncoding.cpp RelativeDateTimeFormat.cpp + NumberFormat.cpp ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 52e4069..f4bd50e 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -191,6 +191,7 @@ from .StringFormat import * from .TextEncoding import * from .RelativeDateTimeFormat import * +from .NumberFormat import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/locale/NumberFormat.cpp b/bindings/locale/NumberFormat.cpp index 0a3a5e4..b4d0d74 100644 --- a/bindings/locale/NumberFormat.cpp +++ b/bindings/locale/NumberFormat.cpp @@ -4,11 +4,12 @@ #include #include +#include namespace py = pybind11; -void define_NumberFormat(py::module_& m) +PYBIND11_MODULE(NumberFormat, m) { py::enum_(m, "BNumberElement", "") .value("B_DECIMAL_SEPARATOR", BNumberElement::B_DECIMAL_SEPARATOR, "") From 99b2ae679e8e833d5267405dc6e251e673fc0fc0 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 2 Sep 2024 17:47:05 +0200 Subject: [PATCH 053/115] update/add locale/LocaleStrings.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/locale/LocaleStrings.cpp | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Jamfile b/Jamfile index 4a4210e..e54e180 100644 --- a/Jamfile +++ b/Jamfile @@ -315,6 +315,7 @@ local sourceFiles = TextEncoding.cpp RelativeDateTimeFormat.cpp NumberFormat.cpp + LocaleStrings.cpp ; diff --git a/bindings/__init__.py b/bindings/__init__.py index f4bd50e..82fdfc8 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -192,6 +192,7 @@ from .TextEncoding import * from .RelativeDateTimeFormat import * from .NumberFormat import * +from .LocaleStrings import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/locale/LocaleStrings.cpp b/bindings/locale/LocaleStrings.cpp index 925facb..832c3de 100644 --- a/bindings/locale/LocaleStrings.cpp +++ b/bindings/locale/LocaleStrings.cpp @@ -8,7 +8,7 @@ namespace py = pybind11; -void define_LocaleStrings(py::module_& m) +PYBIND11_MODULE(LocaleStrings, m) { py::enum_(m, "country_strings", "") .value("B_COUNTRY_STRINGS_BASE", country_strings::B_COUNTRY_STRINGS_BASE, "") From a451eede9298dd06b8019177f2a28c31df2b4def Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 2 Sep 2024 18:40:35 +0200 Subject: [PATCH 054/115] update/add Collator Locale LocaleRoster --- Jamfile | 6 ++++- bindings/__init__.py | 3 +++ bindings/locale/Collator.cpp | 5 ++-- bindings/locale/Locale.cpp | 7 +++--- bindings/locale/LocaleRoster.cpp | 42 +++++++++++++++++++++++--------- 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/Jamfile b/Jamfile index e54e180..4e0278b 100644 --- a/Jamfile +++ b/Jamfile @@ -316,6 +316,9 @@ local sourceFiles = RelativeDateTimeFormat.cpp NumberFormat.cpp LocaleStrings.cpp + LocaleRoster.cpp + Locale.cpp + Collator.cpp ; @@ -337,7 +340,8 @@ LINKLIBS on Translator.so = $(LINKLIBS) -ltranslation ; LINKLIBS on TranslatorFormats.so = $(LINKLIBS) -ltranslation ; LINKLIBS on BitmapStream.so = $(LINKLIBS) -ltranslation ; -#LINKLIBS on FormattingConventions.so = $(LINKLIBS) -llocalestub ; +LINKLIBS on LocaleRoster.so = $(LINKLIBS) -llocalestub ; + #LINKLIBS on TimeFormat.so = $(LINKLIBS) -lsupport ; LINKLIBS on ScreenSaver.so = $(LINKLIBS) -lscreensaver ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 82fdfc8..0a1b10d 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -193,6 +193,9 @@ from .RelativeDateTimeFormat import * from .NumberFormat import * from .LocaleStrings import * +from .LocaleRoster import * +from .Locale import * +from .Collator import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/locale/Collator.cpp b/bindings/locale/Collator.cpp index 853b687..24bcd67 100644 --- a/bindings/locale/Collator.cpp +++ b/bindings/locale/Collator.cpp @@ -4,11 +4,12 @@ #include #include +#include namespace py = pybind11; using namespace U_ICU_NAMESPACE; -void define_Collator(py::module_& m) +PYBIND11_MODULE(Collator, m) { py::enum_(m, "collator_strengths", "") .value("B_COLLATE_DEFAULT", collator_strengths::B_COLLATE_DEFAULT, "") @@ -19,7 +20,7 @@ py::enum_(m, "collator_strengths", "") .value("B_COLLATE_IDENTICAL", collator_strengths::B_COLLATE_IDENTICAL, "") .export_values(); -m.attr("Collator") = py::cast(Collator); +//m.attr("Collator") = py::cast(Collator); py::class_(m, "BCollator") .def(py::init(), "") diff --git a/bindings/locale/Locale.cpp b/bindings/locale/Locale.cpp index 91ad78c..04b77f7 100644 --- a/bindings/locale/Locale.cpp +++ b/bindings/locale/Locale.cpp @@ -7,8 +7,7 @@ namespace py = pybind11; - -void define_Locale(py::module_& m) +PYBIND11_MODULE(Locale, m) { py::class_(m, "BLocale") .def(py::init(), "", py::arg("language")=NULL, py::arg("conventions")=NULL) @@ -22,8 +21,8 @@ py::class_(m, "BLocale") .def("SetCollator", &BLocale::SetCollator, "", py::arg("newCollator")) .def("SetLanguage", &BLocale::SetLanguage, "", py::arg("newLanguage")) .def("GetString", &BLocale::GetString, "", py::arg("id")) -.def("StringCompare", py::overload_cast(&BLocale::StringCompare), "", py::arg("s1"), py::arg("s2")) -.def("StringCompare", py::overload_cast(&BLocale::StringCompare), "", py::arg("s1"), py::arg("s2")) +.def("StringCompare", py::overload_cast(&BLocale::StringCompare, py::const_), "", py::arg("s1"), py::arg("s2")) +.def("StringCompare", py::overload_cast(&BLocale::StringCompare, py::const_), "", py::arg("s1"), py::arg("s2")) .def("GetSortKey", &BLocale::GetSortKey, "", py::arg("string"), py::arg("sortKey")) ; diff --git a/bindings/locale/LocaleRoster.cpp b/bindings/locale/LocaleRoster.cpp index f7d05f4..12ac73e 100644 --- a/bindings/locale/LocaleRoster.cpp +++ b/bindings/locale/LocaleRoster.cpp @@ -4,20 +4,40 @@ #include #include +#include +#include +#include +#include +#include +#include namespace py = pybind11; using namespace BPrivate; -void define_LocaleRoster(py::module_& m) -{ -m.attr("B_LOCALE_CHANGED") = py::cast(B_LOCALE_CHANGED); -m.attr("LocaleRosterData") = py::cast(LocaleRosterData); +PYBIND11_MODULE(LocaleRoster, m) +{ +//m.attr("LocaleRosterData") = py::cast(LocaleRosterData); py::class_(m, "BLocaleRoster") .def_static("Default", &BLocaleRoster::Default, "") .def("GetDefaultTimeZone", &BLocaleRoster::GetDefaultTimeZone, "", py::arg("timezone")) -.def("GetLanguage", &BLocaleRoster::GetLanguage, "", py::arg("languageCode"), py::arg("_language")) +//.def("GetLanguage", &BLocaleRoster::GetLanguage, "", py::arg("languageCode"), py::arg("_language")) +//.def("GetLanguage", &GetLanguage_wrapper, "", py::arg("languageCode"), py::arg("_language")) +.def("GetLanguage", [](BLocaleRoster& self,const char* languageCode)-> py::tuple { + std::vector _language; + status_t r = self.GetLanguage(languageCode,_language.data()); + /* if you want to return a py::list uncomment this and try it + py::list language; + for (size_t i = 0; i < _language.size(); ++i) { + language.append(py::cast(*_language[i]); + } + for (size_t i = 0; i < _language.size(); ++i) { + delete _language[i]; + } + */ + return py::make_tuple(r,_language); +},"",py::arg("languageCode")) // TODO make a test, try this (returning a std::vector or better a py::list??) .def("GetPreferredLanguages", &BLocaleRoster::GetPreferredLanguages, "", py::arg("message")) .def("GetAvailableLanguages", &BLocaleRoster::GetAvailableLanguages, "", py::arg("message")) .def("GetAvailableCountries", &BLocaleRoster::GetAvailableCountries, "", py::arg("timeZones")) @@ -37,12 +57,12 @@ py::class_(m, "BLocaleRoster") return std::make_tuple(r,localizedFileName); } , "", py::arg("ref"), py::arg("traverse")=false) -.def_readwrite("kCatLangAttr", &BLocaleRoster::kCatLangAttr, "") -.def_readwrite("kCatSigAttr", &BLocaleRoster::kCatSigAttr, "") -.def_readwrite("kCatFingerprintAttr", &BLocaleRoster::kCatFingerprintAttr, "") -.def_readwrite("kEmbeddedCatAttr", &BLocaleRoster::kEmbeddedCatAttr, "") -.def_readwrite("kEmbeddedCatResId", &BLocaleRoster::kEmbeddedCatResId, "") +//.def_readwrite("kCatLangAttr", &BLocaleRoster::kCatLangAttr, "") +//.def_readwrite("kCatSigAttr", &BLocaleRoster::kCatSigAttr, "") +//.def_readwrite("kCatFingerprintAttr", &BLocaleRoster::kCatFingerprintAttr, "") +//.def_readwrite("kEmbeddedCatAttr", &BLocaleRoster::kEmbeddedCatAttr, "") +//.def_readwrite("kEmbeddedCatResId", &BLocaleRoster::kEmbeddedCatResId, "") ; - +m.attr("B_LOCALE_CHANGED") = '_LCC';//py::cast(B_LOCALE_CHANGED); } From efcadd1f3dc0253acb05e39766e73b9a83537978 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 2 Sep 2024 21:13:07 +0200 Subject: [PATCH 055/115] Add Catalog CatalogData --- Jamfile | 3 ++ bindings/__init__.py | 2 + bindings/locale/Catalog.cpp | 12 ++--- bindings/locale/CatalogData.cpp | 80 ++++++++++++++++++++++++++++----- 4 files changed, 81 insertions(+), 16 deletions(-) diff --git a/Jamfile b/Jamfile index 4e0278b..c5726c0 100644 --- a/Jamfile +++ b/Jamfile @@ -319,6 +319,8 @@ local sourceFiles = LocaleRoster.cpp Locale.cpp Collator.cpp + CatalogData.cpp + Catalog.cpp ; @@ -341,6 +343,7 @@ LINKLIBS on TranslatorFormats.so = $(LINKLIBS) -ltranslation ; LINKLIBS on BitmapStream.so = $(LINKLIBS) -ltranslation ; LINKLIBS on LocaleRoster.so = $(LINKLIBS) -llocalestub ; +#LINKLIBS on CatalogData.so = $(LINKLIBS) -llocalestub ; #LINKLIBS on TimeFormat.so = $(LINKLIBS) -lsupport ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 0a1b10d..79e2fd8 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -196,6 +196,8 @@ from .LocaleRoster import * from .Locale import * from .Collator import * +from .CatalogData import * +from .Catalog import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/locale/Catalog.cpp b/bindings/locale/Catalog.cpp index 4d2d4f0..7f87240 100644 --- a/bindings/locale/Catalog.cpp +++ b/bindings/locale/Catalog.cpp @@ -4,24 +4,24 @@ #include #include +#include namespace py = pybind11; - -void define_Catalog(py::module_& m) +PYBIND11_MODULE(Catalog, m) { py::class_(m, "BCatalog") .def(py::init(), "") -.def(py::init(), "", py::arg("catalogOwner"), py::arg("language")=NULL, py::arg("fingerprint")=0) +.def(py::init(), "", py::arg("catalogOwner"), py::arg("language")=NULL, py::arg("fingerprint")=0) .def(py::init(), "", py::arg("signature"), py::arg("language")=NULL) .def("GetString", py::overload_cast(&BCatalog::GetString), "", py::arg("string"), py::arg("context")=NULL, py::arg("comment")=NULL) -.def("GetString", py::overload_cast(&BCatalog::GetString), "", py::arg("id")) +.def("GetString", py::overload_cast(&BCatalog::GetString), "", py::arg("id")) .def("GetData", py::overload_cast(&BCatalog::GetData), "", py::arg("name"), py::arg("msg")) -.def("GetData", py::overload_cast(&BCatalog::GetData), "", py::arg("id"), py::arg("msg")) +.def("GetData", py::overload_cast(&BCatalog::GetData), "", py::arg("id"), py::arg("msg")) .def("GetSignature", &BCatalog::GetSignature, "", py::arg("signature")) .def("GetLanguage", &BCatalog::GetLanguage, "", py::arg("language")) .def("GetFingerprint", &BCatalog::GetFingerprint, "", py::arg("fingerprint")) -.def("SetTo", py::overload_cast(&BCatalog::SetTo), "", py::arg("catalogOwner"), py::arg("language")=NULL, py::arg("fingerprint")=0) +.def("SetTo", py::overload_cast(&BCatalog::SetTo), "", py::arg("catalogOwner"), py::arg("language")=NULL, py::arg("fingerprint")=0) .def("SetTo", py::overload_cast(&BCatalog::SetTo), "", py::arg("signature"), py::arg("language")=NULL) .def("InitCheck", &BCatalog::InitCheck, "") .def("CountItems", &BCatalog::CountItems, "") diff --git a/bindings/locale/CatalogData.cpp b/bindings/locale/CatalogData.cpp index cd6791e..f9d5425 100644 --- a/bindings/locale/CatalogData.cpp +++ b/bindings/locale/CatalogData.cpp @@ -4,28 +4,88 @@ #include #include +#include namespace py = pybind11; +class PyBCatalogData : public BCatalogData{ + public: + using BCatalogData::BCatalogData; + const char* GetString(const char* string, const char* context = NULL, const char* comment = NULL) override { + PYBIND11_OVERLOAD_PURE(const char*, BCatalogData, GetString, string, context, comment); + } + const char* GetString(uint32 id) override { + PYBIND11_OVERLOAD_PURE(const char*, BCatalogData, GetString, id); + } + bool CanHaveData() const override { + PYBIND11_OVERLOAD(bool, BCatalogData, CanHaveData); + } + status_t GetData(const char* name, BMessage* msg) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, GetData, name, msg); + } + status_t GetData(uint32 id, BMessage* msg) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, GetData, id, msg); + } + status_t SetString(const char* string, const char* translated, const char* context = NULL, const char* comment = NULL) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, SetString, string, translated, context, comment); + } + status_t SetString(int32 id, const char* translated) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, SetString, id, translated); + } + bool CanWriteData() const override { + PYBIND11_OVERLOAD(bool, BCatalogData, CanWriteData); + } + status_t SetData(const char* name, BMessage* msg) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, SetData, name, msg); + } + status_t SetData(uint32 id, BMessage* msg) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, SetData, id, msg); + } + status_t ReadFromFile(const char* path = NULL) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, ReadFromFile, path); + } + status_t ReadFromAttribute(const entry_ref& appOrAddOnRef) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, ReadFromAttribute, appOrAddOnRef); + } + status_t ReadFromResource(const entry_ref& appOrAddOnRef) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, ReadFromResource, appOrAddOnRef); + } + status_t WriteToFile(const char* path = NULL) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, WriteToFile, path); + } + status_t WriteToAttribute(const entry_ref& appOrAddOnRef) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, WriteToAttribute, appOrAddOnRef); + } + status_t WriteToResource(const entry_ref& appOrAddOnRef) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, WriteToResource, appOrAddOnRef); + } + void MakeEmpty() override { + PYBIND11_OVERLOAD(void, BCatalogData, MakeEmpty); + } + int32 CountItems() const override { + PYBIND11_OVERLOAD(int32, BCatalogData, CountItems); + } +}; -void define_CatalogData(py::module_& m) +PYBIND11_MODULE(CatalogData, m) { -m.attr("gCatalogAddOnPriority") = py::cast(gCatalogAddOnPriority); +//m.attr("gCatalogAddOnPriority") = py::cast(gCatalogAddOnPriority); +m.attr("gCatalogAddOnPriority") = 99; // from haiku source /add-ons/locale/catalogs/plaintext/Catalog.cpp -py::class_(m, "BCatalogData") -.def(py::init(), "", py::arg("signature"), py::arg("language"), py::arg("fingerprint")) +py::class_(m, "BCatalogData") +.def(py::init(), "", py::arg("signature"), py::arg("language"), py::arg("fingerprint")) .def("GetString", py::overload_cast(&BCatalogData::GetString), "", py::arg("string"), py::arg("context")=NULL, py::arg("comment")=NULL) -.def("GetString", py::overload_cast(&BCatalogData::GetString), "", py::arg("id")) +.def("GetString", py::overload_cast(&BCatalogData::GetString), "", py::arg("id")) .def("InitCheck", &BCatalogData::InitCheck, "") .def("Next", &BCatalogData::Next, "") .def("CanHaveData", &BCatalogData::CanHaveData, "") .def("GetData", py::overload_cast(&BCatalogData::GetData), "", py::arg("name"), py::arg("msg")) -.def("GetData", py::overload_cast(&BCatalogData::GetData), "", py::arg("id"), py::arg("msg")) +.def("GetData", py::overload_cast(&BCatalogData::GetData), "", py::arg("id"), py::arg("msg")) .def("SetString", py::overload_cast(&BCatalogData::SetString), "", py::arg("string"), py::arg("translated"), py::arg("context")=NULL, py::arg("comment")=NULL) -.def("SetString", py::overload_cast(&BCatalogData::SetString), "", py::arg("id"), py::arg("translated")) +.def("SetString", py::overload_cast(&BCatalogData::SetString), "", py::arg("id"), py::arg("translated")) .def("CanWriteData", &BCatalogData::CanWriteData, "") .def("SetData", py::overload_cast(&BCatalogData::SetData), "", py::arg("name"), py::arg("msg")) -.def("SetData", py::overload_cast(&BCatalogData::SetData), "", py::arg("id"), py::arg("msg")) +.def("SetData", py::overload_cast(&BCatalogData::SetData), "", py::arg("id"), py::arg("msg")) .def("ReadFromFile", &BCatalogData::ReadFromFile, "", py::arg("path")=NULL) .def("ReadFromAttribute", &BCatalogData::ReadFromAttribute, "", py::arg("appOrAddOnRef")) .def("ReadFromResource", &BCatalogData::ReadFromResource, "", py::arg("appOrAddOnRef")) @@ -37,8 +97,8 @@ py::class_(m, "BCatalogData") .def("SetNext", &BCatalogData::SetNext, "", py::arg("next")) ; -m.def("instantiate_catalog", &instantiate_catalog, "", py::arg("signature"), py::arg("language"), py::arg("fingerprint")); +//m.def("instantiate_catalog", &instantiate_catalog, "", py::arg("signature"), py::arg("language"), py::arg("fingerprint"));// as below -m.def("create_catalog", &create_catalog, "", py::arg("signature"), py::arg("language")); +//m.def("create_catalog", &create_catalog, "", py::arg("signature"), py::arg("language"));// in src/add-ons/locale/catalogs/plaintext/Catalog.cpp or src/tools/locale/PlainTextCatalog.cpp } From 355266c4c008779075a4541f44d520c920d526db Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 2 Sep 2024 21:22:30 +0200 Subject: [PATCH 056/115] add locale/TimeZone --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/locale/TimeZone.cpp | 13 +++++++------ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Jamfile b/Jamfile index c5726c0..73d6e73 100644 --- a/Jamfile +++ b/Jamfile @@ -321,6 +321,7 @@ local sourceFiles = Collator.cpp CatalogData.cpp Catalog.cpp + TimeZone.cpp ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 79e2fd8..dc3fcb4 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -198,6 +198,7 @@ from .Collator import * from .CatalogData import * from .Catalog import * +from .TimeZone import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/locale/TimeZone.cpp b/bindings/locale/TimeZone.cpp index 9154869..39b4c19 100644 --- a/bindings/locale/TimeZone.cpp +++ b/bindings/locale/TimeZone.cpp @@ -4,15 +4,16 @@ #include #include +#include namespace py = pybind11; using namespace U_ICU_NAMESPACE; -void define_TimeZone(py::module_& m) +PYBIND11_MODULE(TimeZone, m) { -m.attr("Locale") = py::cast(Locale); +//m.attr("Locale") = py::cast(Locale); -m.attr("TimeZone") = py::cast(TimeZone); +//m.attr("TimeZone") = py::cast(TimeZone); py::class_(m, "BTimeZone") .def(py::init(), "", py::arg("zoneID")=NULL, py::arg("language")=NULL) @@ -28,9 +29,9 @@ py::class_(m, "BTimeZone") .def("InitCheck", &BTimeZone::InitCheck, "") .def("SetTo", &BTimeZone::SetTo, "", py::arg("zoneID"), py::arg("language")=NULL) .def("SetLanguage", &BTimeZone::SetLanguage, "", py::arg("language")) -.def_readwrite("kNameOfGmtZone", &BTimeZone::kNameOfGmtZone, "") -.def_readwrite("Private", &BTimeZone::Private, "") +//.def_readwrite("kNameOfGmtZone", &BTimeZone::kNameOfGmtZone, "") +//.def_readwrite("Private", &BTimeZone::Private, "") ; - +m.attr("kNameOfGmtZone") = "GMT"; } From 442f66c6dac6cc0d2eccdd310d52e559a6091063 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 4 Sep 2024 22:14:26 +0200 Subject: [PATCH 057/115] initial commit media modules --- Jamfile | 24 +- bindings/__init__.py | 12 + bindings/media/Buffer.cpp | 54 ++ bindings/media/BufferConsumer.cpp | 25 + bindings/media/BufferGroup.cpp | 58 ++ bindings/media/BufferProducer.cpp | 23 + bindings/media/Controllable.cpp | 22 + bindings/media/FileInterface.cpp | 18 + bindings/media/MediaAddOn.cpp | 149 +++++ bindings/media/MediaDecoder.cpp | 50 ++ bindings/media/MediaDefs.cpp | 925 ++++++++++++++++++++++++++++ bindings/media/MediaEncoder.cpp | 39 ++ bindings/media/MediaEventLooper.cpp | 18 + bindings/media/MediaFile.cpp | 63 ++ bindings/media/MediaFiles.cpp | 30 + bindings/media/MediaFormats.cpp | 199 ++++++ bindings/media/MediaNode.cpp | 140 +++++ bindings/media/MediaRecorder.cpp | 32 + bindings/media/MediaRoster.cpp | 115 ++++ bindings/media/MediaTheme.cpp | 32 + bindings/media/MediaTrack.cpp | 65 ++ bindings/media/ParameterWeb.cpp | 202 ++++++ bindings/media/PlaySound.cpp | 20 + bindings/media/Sound.cpp | 32 + bindings/media/SoundFile.cpp | 54 ++ bindings/media/SoundPlayer.cpp | 75 +++ bindings/media/TimeCode.cpp | 75 +++ bindings/media/TimeSource.cpp | 57 ++ bindings/media/TimedEventQueue.cpp | 57 ++ 29 files changed, 2664 insertions(+), 1 deletion(-) create mode 100644 bindings/media/Buffer.cpp create mode 100644 bindings/media/BufferConsumer.cpp create mode 100644 bindings/media/BufferGroup.cpp create mode 100644 bindings/media/BufferProducer.cpp create mode 100644 bindings/media/Controllable.cpp create mode 100644 bindings/media/FileInterface.cpp create mode 100644 bindings/media/MediaAddOn.cpp create mode 100644 bindings/media/MediaDecoder.cpp create mode 100644 bindings/media/MediaDefs.cpp create mode 100644 bindings/media/MediaEncoder.cpp create mode 100644 bindings/media/MediaEventLooper.cpp create mode 100644 bindings/media/MediaFile.cpp create mode 100644 bindings/media/MediaFiles.cpp create mode 100644 bindings/media/MediaFormats.cpp create mode 100644 bindings/media/MediaNode.cpp create mode 100644 bindings/media/MediaRecorder.cpp create mode 100644 bindings/media/MediaRoster.cpp create mode 100644 bindings/media/MediaTheme.cpp create mode 100644 bindings/media/MediaTrack.cpp create mode 100644 bindings/media/ParameterWeb.cpp create mode 100644 bindings/media/PlaySound.cpp create mode 100644 bindings/media/Sound.cpp create mode 100644 bindings/media/SoundFile.cpp create mode 100644 bindings/media/SoundPlayer.cpp create mode 100644 bindings/media/TimeCode.cpp create mode 100644 bindings/media/TimeSource.cpp create mode 100644 bindings/media/TimedEventQueue.cpp diff --git a/Jamfile b/Jamfile index 73d6e73..af5f768 100644 --- a/Jamfile +++ b/Jamfile @@ -74,7 +74,7 @@ install_location ?= /boot/system/non-packaged/lib/python$(python_version)/site-packages ; # Where to search for .cpp files -SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/storage bindings/kernel bindings/translation bindings/add-ons/screen_saver bindings/add-ons/registrar bindings/add-ons/graphics bindings/add-ons/input_server bindings/add-ons/mail_daemon bindings/add-ons/network_settings bindings/drivers bindings/device bindings/mail bindings/locale ; +SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/storage bindings/kernel bindings/translation bindings/add-ons/screen_saver bindings/add-ons/registrar bindings/add-ons/graphics bindings/add-ons/input_server bindings/add-ons/mail_daemon bindings/add-ons/network_settings bindings/drivers bindings/device bindings/mail bindings/locale bindings/media ; # Where to look for header files SubDirHdrs headers ; @@ -323,6 +323,18 @@ local sourceFiles = Catalog.cpp TimeZone.cpp + #media + Buffer.cpp + MediaNode.cpp + BufferConsumer.cpp + TimeSource.cpp + BufferGroup.cpp + BufferProducer.cpp + Controllable.cpp + MediaAddOn.cpp + MediaDecoder.cpp + MediaDefs.cpp + ; # The .so files can be built from the .cpp files, each .cpp file mapping to @@ -347,6 +359,16 @@ LINKLIBS on LocaleRoster.so = $(LINKLIBS) -llocalestub ; #LINKLIBS on CatalogData.so = $(LINKLIBS) -llocalestub ; #LINKLIBS on TimeFormat.so = $(LINKLIBS) -lsupport ; +LINKLIBS on Buffer.so = $(LINKLIBS) -lmedia ; +LINKLIBS on BufferGroup.so = $(LINKLIBS) -lmedia ; +LINKLIBS on BufferProducer.so = $(LINKLIBS) -lmedia ; +LINKLIBS on Controllable.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaAddOn.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaDecoder.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaDefs.so = $(LINKLIBS) -lmedia ; +#LINKLIBS on BufferConsumer.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaNode.so = $(LINKLIBS) -lmedia ; +LINKLIBS on TimeSource.so = $(LINKLIBS) -lmedia ; LINKLIBS on ScreenSaver.so = $(LINKLIBS) -lscreensaver ; #LINKLIBS on MimeSnifferAddon.so = $(LINKLIBS) -lstoragekit ; diff --git a/bindings/__init__.py b/bindings/__init__.py index dc3fcb4..831aed8 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -200,6 +200,18 @@ from .Catalog import * from .TimeZone import * +#media +from .Buffer import * +from .MediaNode import * +from .BufferConsumer import * +from .TimeSource import * +from .BufferGroup import * +from .BufferProducer import * +from .Controllable import * +from .MediaAddOn import * +from .MediaDecoder import * +from .MediaDefs import * + _BWindow=BWindow _BApplication=BApplication def MessageReceived(self, msg, parent): diff --git a/bindings/media/Buffer.cpp b/bindings/media/Buffer.cpp new file mode 100644 index 0000000..9cf69f9 --- /dev/null +++ b/bindings/media/Buffer.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; + +PYBIND11_MODULE(Buffer, m) +{ +//m.attr("BufferCache") = py::cast(BufferCache); + +//m.attr("SharedBufferList") = py::cast(SharedBufferList); + +py::class_(m, "buffer_clone_info") +.def(py::init(), "") +.def_readwrite("buffer", &buffer_clone_info::buffer, "") +.def_readwrite("area", &buffer_clone_info::area, "") +.def_readwrite("offset", &buffer_clone_info::offset, "") +.def_readwrite("size", &buffer_clone_info::size, "") +.def_readwrite("flags", &buffer_clone_info::flags, "") +; + +py::class_>(m, "BBuffer") +.def("Data", &BBuffer::Data, "") +.def("SizeAvailable", &BBuffer::SizeAvailable, "") +.def("SizeUsed", &BBuffer::SizeUsed, "") +.def("SetSizeUsed", &BBuffer::SetSizeUsed, "", py::arg("used")) +.def("Flags", &BBuffer::Flags, "") +.def("Recycle", &BBuffer::Recycle, "") +.def("CloneInfo", &BBuffer::CloneInfo, "") +.def("ID", &BBuffer::ID, "") +.def("Type", &BBuffer::Type, "") +.def("Header", &BBuffer::Header, "") +.def("AudioHeader", &BBuffer::AudioHeader, "") +.def("VideoHeader", &BBuffer::VideoHeader, "") +.def("Size", &BBuffer::Size, "") +; + +m.attr("B_F1_BUFFER") = 0x1; + +m.attr("B_F2_BUFFER") = 0x2; + +m.attr("B_SMALL_BUFFER") = 0x80000000; + +py::class_(m, "BSmallBuffer") +.def(py::init(), "") +.def_static("SmallBufferSizeLimit", &BSmallBuffer::SmallBufferSizeLimit, "") +; + + +} diff --git a/bindings/media/BufferConsumer.cpp b/bindings/media/BufferConsumer.cpp new file mode 100644 index 0000000..1aa5073 --- /dev/null +++ b/bindings/media/BufferConsumer.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +PYBIND11_MODULE(BufferConsumer, m) +{ +//m.attr("BufferCache") = py::cast(BufferCache); + +//m.attr("BMediaRosterEx") = py::cast(BMediaRosterEx); + +py::class_>(m, "BBufferConsumer") +.def("ConsumerType", &BBufferConsumer::ConsumerType, "") +.def_static("RegionToClipData", &BBufferConsumer::RegionToClipData, "", py::arg("region"), py::arg("format"), py::arg("size"), py::arg("data")) +; + + +} diff --git a/bindings/media/BufferGroup.cpp b/bindings/media/BufferGroup.cpp new file mode 100644 index 0000000..7c012c0 --- /dev/null +++ b/bindings/media/BufferGroup.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; +py::tuple add_buffer_wrapper(BBufferGroup& self, const buffer_clone_info& info) { + BBuffer* buffer = nullptr; + status_t status = self.AddBuffer(info, &buffer); + + return py::make_tuple(status, py::cast(buffer, py::return_value_policy::reference)); +}; + +py::tuple get_buffer_list_wrapper(BBufferGroup& self, int32 buffer_count) { + std::vector buffers(buffer_count, nullptr); + status_t status = self.GetBufferList(buffer_count, buffers.data()); + + /*if (status != 0) { + // Handle error (e.g., raise a Python exception) + throw py::error_already_set(); + }*/ + + // Create a Python list of BBuffer objects + py::list py_buffers; + for (BBuffer* buffer : buffers) { + py_buffers.append(py::cast(buffer, py::return_value_policy::reference)); + } + + return py::make_tuple(status, py_buffers); +}; + +PYBIND11_MODULE(BufferGroup, m) +{ +//m.attr("SharedBufferList") = py::cast(SharedBufferList); +py::class_(m, "BBufferGroup") +.def(py::init(), "", py::arg("size"), py::arg("count")=3, py::arg("placement")=B_ANY_ADDRESS, py::arg("lock")=B_FULL_LOCK) +.def(py::init(), "") +.def(py::init(), "", py::arg("count"), py::arg("buffers")) +.def("InitCheck", &BBufferGroup::InitCheck, "") +//.def("AddBuffer", &BBufferGroup::AddBuffer, "", py::arg("info"), py::arg("_buffer")=NULL) +.def("AddBuffer", &add_buffer_wrapper, "", py::arg("info")) +.def("RequestBuffer", py::overload_cast(&BBufferGroup::RequestBuffer), "", py::arg("size"), py::arg("timeout")=B_INFINITE_TIMEOUT) +.def("RequestBuffer", py::overload_cast(&BBufferGroup::RequestBuffer), "", py::arg("buffer"), py::arg("timeout")=B_INFINITE_TIMEOUT) +.def("RequestError", &BBufferGroup::RequestError, "") +.def("CountBuffers", &BBufferGroup::CountBuffers, "", py::arg("_count")) +//.def("GetBufferList", &BBufferGroup::GetBufferList, "", py::arg("bufferCount"), py::arg("_buffers")) +.def("GetBufferList", &get_buffer_list_wrapper, "", py::arg("bufferCount")) +.def("WaitForBuffers", &BBufferGroup::WaitForBuffers, "") +.def("ReclaimAllBuffers", &BBufferGroup::ReclaimAllBuffers, "") +; + + +} diff --git a/bindings/media/BufferProducer.cpp b/bindings/media/BufferProducer.cpp new file mode 100644 index 0000000..c0ba0ce --- /dev/null +++ b/bindings/media/BufferProducer.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +PYBIND11_MODULE(BufferProducer, m) +{ +//m.attr("BMediaRosterEx") = py::cast(BMediaRosterEx); + +py::class_>(m, "BBufferProducer") +.def_static("ClipDataToRegion", &BBufferProducer::ClipDataToRegion, "", py::arg("format"), py::arg("size"), py::arg("data"), py::arg("region")) +.def("ProducerType", &BBufferProducer::ProducerType, "") +; + + +} diff --git a/bindings/media/Controllable.cpp b/bindings/media/Controllable.cpp new file mode 100644 index 0000000..54b0272 --- /dev/null +++ b/bindings/media/Controllable.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; + +PYBIND11_MODULE(Controllable, m) +{ +py::class_>(m, "BControllable") +.def("Web", &BControllable::Web, "") +.def("LockParameterWeb", &BControllable::LockParameterWeb, "") +.def("UnlockParameterWeb", &BControllable::UnlockParameterWeb, "") +; + + +} diff --git a/bindings/media/FileInterface.cpp b/bindings/media/FileInterface.cpp new file mode 100644 index 0000000..35217be --- /dev/null +++ b/bindings/media/FileInterface.cpp @@ -0,0 +1,18 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +void define_FileInterface(py::module_& m) +{ +py::class_(m, "BFileInterface") +; + + +} diff --git a/bindings/media/MediaAddOn.cpp b/bindings/media/MediaAddOn.cpp new file mode 100644 index 0000000..50cdafd --- /dev/null +++ b/bindings/media/MediaAddOn.cpp @@ -0,0 +1,149 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +std::string get_dormant_node_info_name(const dormant_node_info& self) { + return std::string(self.name); +} + +void set_dormant_node_info_name(dormant_node_info& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), B_MEDIA_NAME_LENGTH - 1); + self.name[B_MEDIA_NAME_LENGTH - 1] = '\0'; +} + +//std::pair InitCheck(BMediaAddOn& self){ +//std::pair> InitCheck_wrapper(BMediaAddOn& self){ +py::tuple InitCheck_wrapper(BMediaAddOn& self){ + /* + const std::vector _failureText; + const char** failureText; + //const char* failureText = nullptr; + //status_t status = self.InitCheck(failureText); + status_t status = self.InitCheck(failureText); + + //return {status, failureText ? std::string(failureText) : ""}; + //return {status, _failureText}; + return py::make_tuple(status,_failureText); + */ + + + const char ** failureText; + std::vector _failureText; + status_t status = self.InitCheck(failureText); + // Assume che la fine dell'array sia segnata da un puntatore nullo + for (size_t i = 0; failureText[i] != nullptr; ++i) { + _failureText.push_back(const_cast(failureText[i])); + } + + return py::make_tuple(status,_failureText); +} + +PYBIND11_MODULE(MediaAddOn, m) +{ +m.attr("B_FLAVOR_IS_GLOBAL") = 0x100000L;//py::cast(B_FLAVOR_IS_GLOBAL); +m.attr("B_FLAVOR_IS_LOCAL") = 0x200000L;//py::cast(B_FLAVOR_IS_LOCAL); + +//m.attr("DormantNodeManager") = py::cast(DormantNodeManager); + +py::class_(m, "dormant_node_info") +.def(py::init(), "") +.def_readwrite("addon", &dormant_node_info::addon, "") +.def_readwrite("flavor_id", &dormant_node_info::flavor_id, "") +//.def_readwrite("name", &dormant_node_info::name, "") +.def_property("name", &get_dormant_node_info_name,&set_dormant_node_info_name,"") +; + +py::class_(m, "flavor_info") +.def_readwrite("name", &flavor_info::name, "") +.def_readwrite("info", &flavor_info::info, "") +.def_readwrite("kinds", &flavor_info::kinds, "") +.def_readwrite("flavor_flags", &flavor_info::flavor_flags, "") +.def_readwrite("internal_id", &flavor_info::internal_id, "") +.def_readwrite("possible_count", &flavor_info::possible_count, "") +.def_readwrite("in_format_count", &flavor_info::in_format_count, "") +.def_readwrite("in_format_flags", &flavor_info::in_format_flags, "") +.def_readwrite("in_formats", &flavor_info::in_formats, "") +.def_readwrite("out_format_count", &flavor_info::out_format_count, "") +.def_readwrite("out_format_flags", &flavor_info::out_format_flags, "") +.def_readwrite("out_formats", &flavor_info::out_formats, "") +//.def_readwrite("_reserved_", &flavor_info::_reserved_, "") +.def_property( + "_reserved_", + [](const flavor_info &info) { + py::array_t result(16); + std::memcpy(result.mutable_data(), &info._reserved_, sizeof(info._reserved_)); + return result; + }, + [](flavor_info &info, py::array_t value) { + if (value.size() != 16) { + throw std::runtime_error("Array must have size 16"); + } + std::memcpy(&info._reserved_, value.data(), sizeof(info._reserved_)); + },"") +; + +py::class_(m, "dormant_flavor_info") +.def(py::init(), "") +.def(py::init(), "", py::arg("other")) +.def("operator=", py::overload_cast(&dormant_flavor_info::operator=), "", py::arg("other")) +.def("operator=", py::overload_cast(&dormant_flavor_info::operator=), "", py::arg("other")) +.def("set_name", &dormant_flavor_info::set_name, "", py::arg("name")) +.def("set_info", &dormant_flavor_info::set_info, "", py::arg("info")) +.def("add_in_format", &dormant_flavor_info::add_in_format, "", py::arg("format")) +.def("add_out_format", &dormant_flavor_info::add_out_format, "", py::arg("format")) +.def("IsFixedSize", &dormant_flavor_info::IsFixedSize, "") +.def("TypeCode", &dormant_flavor_info::TypeCode, "") +.def("FlattenedSize", &dormant_flavor_info::FlattenedSize, "") +.def("Flatten", &dormant_flavor_info::Flatten, "", py::arg("buffer"), py::arg("size")) //TODO: handle buffer +.def("Unflatten", &dormant_flavor_info::Unflatten, "", py::arg("type"), py::arg("buffer"), py::arg("size")) //TODO: handle buffer +.def_readwrite("node_info", &dormant_flavor_info::node_info, "") +; + +py::class_(m, "BMediaAddOn") +.def(py::init(), "", py::arg("image")) +//.def("InitCheck", &BMediaAddOn::InitCheck, "", py::arg("_failureText")) +.def("InitCheck",&InitCheck_wrapper, "") +.def("CountFlavors", &BMediaAddOn::CountFlavors, "") +//.def("GetFlavorAt", &BMediaAddOn::GetFlavorAt, "", py::arg("index"), py::arg("_info")) +.def("GetFlavorAt", [](BMediaAddOn& self, int32 index) { + const flavor_info* _info = nullptr; + status_t result = self.GetFlavorAt(index,&_info); + if (result == B_OK && _info != nullptr) { + return py::make_tuple(result, py::cast(_info, py::return_value_policy::reference)); + } else { + return py::make_tuple(result, py::none()); + } +},"") +.def("InstantiateNodeFor", &BMediaAddOn::InstantiateNodeFor, "", py::arg("info"), py::arg("config"), py::arg("_error")) +.def("GetConfigurationFor", &BMediaAddOn::GetConfigurationFor, "", py::arg("yourNode"), py::arg("intoMessage")) +.def("WantsAutoStart", &BMediaAddOn::WantsAutoStart, "") +//.def("AutoStart", &BMediaAddOn::AutoStart, "", py::arg("index"), py::arg("_node"), py::arg("_internalID"), py::arg("_hasMore")) +.def("AutoStart", [](BMediaAddOn& self, int index) { + BMediaNode* node = nullptr; + int32_t internalID = 0; + bool hasMore = false; + status_t result = self.AutoStart(index, &node, &internalID, &hasMore); + return std::make_tuple(result, node, internalID, hasMore); +},"") +.def("SniffRef", &BMediaAddOn::SniffRef, "", py::arg("file"), py::arg("ioMimeType"), py::arg("_quality"), py::arg("_internalID")) +.def("SniffType", &BMediaAddOn::SniffType, "", py::arg("type"), py::arg("_quality"), py::arg("_internalID")) +.def("GetFileFormatList", &BMediaAddOn::GetFileFormatList, "", py::arg("forNodeFlavorID"), py::arg("_writableFormats"), py::arg("writableFormatsCount"), py::arg("_writableFormatsTotalCount"), py::arg("_readableFormats"), py::arg("readableFormatsCount"), py::arg("_readableFormatsTotalCount"), py::arg("_reserved")) +.def("SniffTypeKind", &BMediaAddOn::SniffTypeKind, "", py::arg("type"), py::arg("kinds"), py::arg("_quality"), py::arg("_internalID"), py::arg("_reserved")) +.def("ImageID", &BMediaAddOn::ImageID, "") +.def("AddonID", &BMediaAddOn::AddonID, "") +; + +//m.def("make_media_addon", &make_media_addon, "", py::arg("yourImage")); //TODO: where is this? cannot find it normally it calls return new MediaAddOn(imageid); that returns a BMediaAddOn* + +} diff --git a/bindings/media/MediaDecoder.cpp b/bindings/media/MediaDecoder.cpp new file mode 100644 index 0000000..268a849 --- /dev/null +++ b/bindings/media/MediaDecoder.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +class PyBMediaDecoder : public BMediaDecoder{ + public: + using BMediaDecoder::BMediaDecoder; + status_t GetNextChunk(const void **chunkData, size_t *chunkLen, media_header *mh) override { + PYBIND11_OVERRIDE_PURE( status_t, BMediaDecoder, GetNextChunk, chunkData, chunkLen, mh ); + } +}; + +PYBIND11_MODULE(MediaDecoder, m) +{ + +//m.attr("Decoder") = py::cast(Decoder); + +//m.attr("Decoder") = py::cast(Decoder); + +//m.attr("DecoderPlugin") = py::cast(DecoderPlugin); + +py::class_(m, "BMediaDecoder") +.def(py::init(), "") +.def(py::init(), "", py::arg("in_format"), py::arg("info")=NULL, py::arg("info_size")=0) +.def(py::init(), "", py::arg("mci")) +.def("InitCheck", &BMediaDecoder::InitCheck, "") +.def("SetTo", py::overload_cast(&BMediaDecoder::SetTo), "", py::arg("in_format"), py::arg("info")=NULL, py::arg("info_size")=0) +.def("SetTo", py::overload_cast(&BMediaDecoder::SetTo), "", py::arg("mci")) +.def("SetInputFormat", &BMediaDecoder::SetInputFormat, "", py::arg("in_format"), py::arg("in_info")=NULL, py::arg("in_size")=0) // TODO +.def("SetOutputFormat", &BMediaDecoder::SetOutputFormat, "", py::arg("output_format")) +.def("Decode", &BMediaDecoder::Decode, "", py::arg("out_buffer"), py::arg("out_frameCount"), py::arg("out_mh"), py::arg("info")) // TODO out_buffer +.def("GetDecoderInfo", &BMediaDecoder::GetDecoderInfo, "", py::arg("out_info")) +; + +py::class_(m, "BMediaBufferDecoder") +.def(py::init(), "") +.def(py::init(), "", py::arg("in_format"), py::arg("info")=NULL, py::arg("info_size")=0) +.def(py::init(), "", py::arg("mci")) +.def("DecodeBuffer", &BMediaBufferDecoder::DecodeBuffer, "", py::arg("input_buffer"), py::arg("input_size"), py::arg("out_buffer"), py::arg("out_frameCount"), py::arg("out_mh"), py::arg("info")=NULL) // TODO handle buffers +; + + +} diff --git a/bindings/media/MediaDefs.cpp b/bindings/media/MediaDefs.cpp new file mode 100644 index 0000000..9154964 --- /dev/null +++ b/bindings/media/MediaDefs.cpp @@ -0,0 +1,925 @@ +#include +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; + +PYBIND11_MODULE(MediaDefs, m) +{ +/* +m.attr("B_MEDIA_WILDCARD") = py::cast(B_MEDIA_WILDCARD); +m.attr("B_MEDIA_NODE_CREATED") = py::cast(B_MEDIA_NODE_CREATED); +m.attr("B_MEDIA_NODE_DELETED") = py::cast(B_MEDIA_NODE_DELETED); +m.attr("B_MEDIA_CONNECTION_MADE") = py::cast(B_MEDIA_CONNECTION_MADE); +m.attr("B_MEDIA_CONNECTION_BROKEN") = py::cast(B_MEDIA_CONNECTION_BROKEN); +m.attr("B_MEDIA_BUFFER_CREATED") = py::cast(B_MEDIA_BUFFER_CREATED); +m.attr("B_MEDIA_BUFFER_DELETED") = py::cast(B_MEDIA_BUFFER_DELETED); +m.attr("B_MEDIA_TRANSPORT_STATE") = py::cast(B_MEDIA_TRANSPORT_STATE); +m.attr("B_MEDIA_PARAMETER_CHANGED") = py::cast(B_MEDIA_PARAMETER_CHANGED); +m.attr("B_MEDIA_FORMAT_CHANGED") = py::cast(B_MEDIA_FORMAT_CHANGED); +m.attr("B_MEDIA_WEB_CHANGED") = py::cast(B_MEDIA_WEB_CHANGED); +m.attr("B_MEDIA_DEFAULT_CHANGED") = py::cast(B_MEDIA_DEFAULT_CHANGED); +m.attr("B_MEDIA_NEW_PARAMETER_VALUE") = py::cast(B_MEDIA_NEW_PARAMETER_VALUE); +m.attr("B_MEDIA_NODE_STOPPED") = py::cast(B_MEDIA_NODE_STOPPED); +m.attr("B_MEDIA_FLAVORS_CHANGED") = py::cast(B_MEDIA_FLAVORS_CHANGED); +m.attr("B_MEDIA_SERVER_STARTED") = py::cast(B_MEDIA_SERVER_STARTED); +m.attr("B_MEDIA_SERVER_QUIT") = py::cast(B_MEDIA_SERVER_QUIT); +*/ + +m.attr("B_MEDIA_WILDCARD") = 'TRWC'; +m.attr("B_MEDIA_NODE_CREATED") = 'TRIA'; +m.attr("B_MEDIA_NODE_DELETED") = 'TRIB'; +m.attr("B_MEDIA_CONNECTION_MADE") = 'TRIC'; +m.attr("B_MEDIA_CONNECTION_BROKEN") = 'TRID'; +m.attr("B_MEDIA_BUFFER_CREATED") = 'TRIE'; +m.attr("B_MEDIA_BUFFER_DELETED") = 'TRIF'; +m.attr("B_MEDIA_TRANSPORT_STATE") = 'TRIG'; +m.attr("B_MEDIA_PARAMETER_CHANGED") = 'TRIH'; +m.attr("B_MEDIA_FORMAT_CHANGED") = 'TRII'; +m.attr("B_MEDIA_WEB_CHANGED") = 'TRIJ'; +m.attr("B_MEDIA_DEFAULT_CHANGED") = 'TRIK'; +m.attr("B_MEDIA_NEW_PARAMETER_VALUE") = 'TRIL'; +m.attr("B_MEDIA_NODE_STOPPED") = 'TRIM'; +m.attr("B_MEDIA_FLAVORS_CHANGED") = 'TRIN'; +m.attr("B_MEDIA_SERVER_STARTED") = 'TRIO'; +m.attr("B_MEDIA_SERVER_QUIT") = 'TRIP'; + +/* +B_MEDIA_WILDCARD = 'TRWC', // 0x54525743 = 1415073475 +B_MEDIA_NODE_CREATED = 'TRIA', // 0x54524941 = 1415073441 +B_MEDIA_NODE_DELETED = 'TRIA' + 1, // 1415073442 +B_MEDIA_CONNECTION_MADE = 'TRIA' + 2, // 1415073443 +B_MEDIA_CONNECTION_BROKEN = 'TRIA' + 3, // 1415073444 +B_MEDIA_BUFFER_CREATED = 'TRIA' + 4, // 1415073445 +B_MEDIA_BUFFER_DELETED = 'TRIA' + 5, // 1415073446 +B_MEDIA_TRANSPORT_STATE = 'TRIA' + 6, // 1415073447 +B_MEDIA_PARAMETER_CHANGED = 'TRIA' + 7, // 1415073448 +B_MEDIA_FORMAT_CHANGED = 'TRIA' + 8, // 1415073449 +B_MEDIA_WEB_CHANGED = 'TRIA' + 9, // 1415073450 +B_MEDIA_DEFAULT_CHANGED = 'TRIA' + 10, // 1415073451 +B_MEDIA_NEW_PARAMETER_VALUE = 'TRIA' + 11, // 1415073452 +B_MEDIA_NODE_STOPPED = 'TRIA' + 12, // 1415073453 +B_MEDIA_FLAVORS_CHANGED = 'TRIA' + 13, // 1415073454 +B_MEDIA_SERVER_STARTED = 'TRIA' + 14, // 1415073455 +B_MEDIA_SERVER_QUIT = 'TRIA' + 15, // 1415073456 +*/ + +py::enum_(m, "media_type", "") +.value("B_MEDIA_NO_TYPE", media_type::B_MEDIA_NO_TYPE, "") +.value("B_MEDIA_UNKNOWN_TYPE", media_type::B_MEDIA_UNKNOWN_TYPE, "") +.value("B_MEDIA_RAW_AUDIO", media_type::B_MEDIA_RAW_AUDIO, "") +.value("B_MEDIA_RAW_VIDEO", media_type::B_MEDIA_RAW_VIDEO, "") +.value("B_MEDIA_VBL", media_type::B_MEDIA_VBL, "") +.value("B_MEDIA_TIMECODE", media_type::B_MEDIA_TIMECODE, "") +.value("B_MEDIA_MIDI", media_type::B_MEDIA_MIDI, "") +.value("B_MEDIA_TEXT", media_type::B_MEDIA_TEXT, "") +.value("B_MEDIA_HTML", media_type::B_MEDIA_HTML, "") +.value("B_MEDIA_MULTISTREAM", media_type::B_MEDIA_MULTISTREAM, "") +.value("B_MEDIA_PARAMETERS", media_type::B_MEDIA_PARAMETERS, "") +.value("B_MEDIA_ENCODED_AUDIO", media_type::B_MEDIA_ENCODED_AUDIO, "") +.value("B_MEDIA_ENCODED_VIDEO", media_type::B_MEDIA_ENCODED_VIDEO, "") +.value("B_MEDIA_PRIVATE", media_type::B_MEDIA_PRIVATE, "") +.value("B_MEDIA_FIRST_USER_TYPE", media_type::B_MEDIA_FIRST_USER_TYPE, "") +.export_values(); + +py::enum_(m, "node_kind", "") +.value("B_BUFFER_PRODUCER", node_kind::B_BUFFER_PRODUCER, "") +.value("B_BUFFER_CONSUMER", node_kind::B_BUFFER_CONSUMER, "") +.value("B_TIME_SOURCE", node_kind::B_TIME_SOURCE, "") +.value("B_CONTROLLABLE", node_kind::B_CONTROLLABLE, "") +.value("B_FILE_INTERFACE", node_kind::B_FILE_INTERFACE, "") +.value("B_ENTITY_INTERFACE", node_kind::B_ENTITY_INTERFACE, "") +.value("B_PHYSICAL_INPUT", node_kind::B_PHYSICAL_INPUT, "") +.value("B_PHYSICAL_OUTPUT", node_kind::B_PHYSICAL_OUTPUT, "") +.value("B_SYSTEM_MIXER", node_kind::B_SYSTEM_MIXER, "") +.export_values(); + +py::enum_(m, "video_orientation", "") +.value("B_VIDEO_TOP_LEFT_RIGHT", video_orientation::B_VIDEO_TOP_LEFT_RIGHT, "") +.value("B_VIDEO_BOTTOM_LEFT_RIGHT", video_orientation::B_VIDEO_BOTTOM_LEFT_RIGHT, "") +.export_values(); + +py::enum_(m, "media_flags", "") +.value("B_MEDIA_FLAGS_VERSION", media_flags::B_MEDIA_FLAGS_VERSION, "") +.value("B_MEDIA_FLAGS_PRIVATE", media_flags::B_MEDIA_FLAGS_PRIVATE, "") +.export_values(); + +py::enum_(m, "media_producer_status", "") +.value("B_DATA_NOT_AVAILABLE", media_producer_status::B_DATA_NOT_AVAILABLE, "") +.value("B_DATA_AVAILABLE", media_producer_status::B_DATA_AVAILABLE, "") +.value("B_PRODUCER_STOPPED", media_producer_status::B_PRODUCER_STOPPED, "") +.export_values(); + +py::enum_(m, "media_realtime_flags", "") +.value("B_MEDIA_REALTIME_ALLOCATOR", media_realtime_flags::B_MEDIA_REALTIME_ALLOCATOR, "") +.value("B_MEDIA_REALTIME_AUDIO", media_realtime_flags::B_MEDIA_REALTIME_AUDIO, "") +.value("B_MEDIA_REALTIME_VIDEO", media_realtime_flags::B_MEDIA_REALTIME_VIDEO, "") +.value("B_MEDIA_REALTIME_ANYKIND", media_realtime_flags::B_MEDIA_REALTIME_ANYKIND, "") +.export_values(); + +py::enum_(m, "media_frame_flags", "") +.value("B_MEDIA_KEY_FRAME", media_frame_flags::B_MEDIA_KEY_FRAME, "") +.export_values(); + +py::enum_(m, "media_multi_channels", "") +.value("B_CHANNEL_LEFT", media_multi_channels::B_CHANNEL_LEFT, "") +.value("B_CHANNEL_RIGHT", media_multi_channels::B_CHANNEL_RIGHT, "") +.value("B_CHANNEL_CENTER", media_multi_channels::B_CHANNEL_CENTER, "") +.value("B_CHANNEL_SUB", media_multi_channels::B_CHANNEL_SUB, "") +.value("B_CHANNEL_REARLEFT", media_multi_channels::B_CHANNEL_REARLEFT, "") +.value("B_CHANNEL_REARRIGHT", media_multi_channels::B_CHANNEL_REARRIGHT, "") +.value("B_CHANNEL_FRONT_LEFT_CENTER", media_multi_channels::B_CHANNEL_FRONT_LEFT_CENTER, "") +.value("B_CHANNEL_FRONT_RIGHT_CENTER", media_multi_channels::B_CHANNEL_FRONT_RIGHT_CENTER, "") +.value("B_CHANNEL_BACK_CENTER", media_multi_channels::B_CHANNEL_BACK_CENTER, "") +.value("B_CHANNEL_SIDE_LEFT", media_multi_channels::B_CHANNEL_SIDE_LEFT, "") +.value("B_CHANNEL_SIDE_RIGHT", media_multi_channels::B_CHANNEL_SIDE_RIGHT, "") +.value("B_CHANNEL_TOP_CENTER", media_multi_channels::B_CHANNEL_TOP_CENTER, "") +.value("B_CHANNEL_TOP_FRONT_LEFT", media_multi_channels::B_CHANNEL_TOP_FRONT_LEFT, "") +.value("B_CHANNEL_TOP_FRONT_CENTER", media_multi_channels::B_CHANNEL_TOP_FRONT_CENTER, "") +.value("B_CHANNEL_TOP_FRONT_RIGHT", media_multi_channels::B_CHANNEL_TOP_FRONT_RIGHT, "") +.value("B_CHANNEL_TOP_BACK_LEFT", media_multi_channels::B_CHANNEL_TOP_BACK_LEFT, "") +.value("B_CHANNEL_TOP_BACK_CENTER", media_multi_channels::B_CHANNEL_TOP_BACK_CENTER, "") +.value("B_CHANNEL_TOP_BACK_RIGHT", media_multi_channels::B_CHANNEL_TOP_BACK_RIGHT, "") +.export_values(); + +py::enum_(m, "media_multi_matrix", "") +.value("B_MATRIX_PROLOGIC_LR", media_multi_matrix::B_MATRIX_PROLOGIC_LR, "") +.value("B_MATRIX_AMBISONIC_WXYZ", media_multi_matrix::B_MATRIX_AMBISONIC_WXYZ, "") +.export_values(); + +py::enum_(m, "media_display_flags", "") +.value("B_F1_DOMINANT", media_display_flags::B_F1_DOMINANT, "") +.value("B_F2_DOMINANT", media_display_flags::B_F2_DOMINANT, "") +.value("B_TOP_SCANLINE_F1", media_display_flags::B_TOP_SCANLINE_F1, "") +.value("B_TOP_SCANLINE_F2", media_display_flags::B_TOP_SCANLINE_F2, "") +.export_values(); + +py::enum_(m, "media_format_flags", "") +.value("B_MEDIA_RETAINED_DATA", media_format_flags::B_MEDIA_RETAINED_DATA, "") +.value("B_MEDIA_MULTIPLE_BUFFERS", media_format_flags::B_MEDIA_MULTIPLE_BUFFERS, "") +.value("B_MEDIA_CONTIGUOUS_BUFFER", media_format_flags::B_MEDIA_CONTIGUOUS_BUFFER, "") +.value("B_MEDIA_LINEAR_UPDATES", media_format_flags::B_MEDIA_LINEAR_UPDATES, "") +.value("B_MEDIA_MAUI_UNDEFINED_FLAGS", media_format_flags::B_MEDIA_MAUI_UNDEFINED_FLAGS, "") +.export_values(); + +py::enum_(m, "media_format_family", "") +.value("B_ANY_FORMAT_FAMILY", media_format_family::B_ANY_FORMAT_FAMILY, "") +.value("B_BEOS_FORMAT_FAMILY", media_format_family::B_BEOS_FORMAT_FAMILY, "") +.value("B_QUICKTIME_FORMAT_FAMILY", media_format_family::B_QUICKTIME_FORMAT_FAMILY, "") +.value("B_AVI_FORMAT_FAMILY", media_format_family::B_AVI_FORMAT_FAMILY, "") +.value("B_ASF_FORMAT_FAMILY", media_format_family::B_ASF_FORMAT_FAMILY, "") +.value("B_MPEG_FORMAT_FAMILY", media_format_family::B_MPEG_FORMAT_FAMILY, "") +.value("B_WAV_FORMAT_FAMILY", media_format_family::B_WAV_FORMAT_FAMILY, "") +.value("B_AIFF_FORMAT_FAMILY", media_format_family::B_AIFF_FORMAT_FAMILY, "") +.value("B_AVR_FORMAT_FAMILY", media_format_family::B_AVR_FORMAT_FAMILY, "") +.value("B_MISC_FORMAT_FAMILY", media_format_family::B_MISC_FORMAT_FAMILY, "") +.export_values(); + +m.attr("B_BIG_ENDIAN") = 0;//py::cast(B_BIG_ENDIAN); +m.attr("B_LITTLE_ENDIAN") = 1;//py::cast(B_LITTLE_ENDIAN); + +m.attr("B_UNDEFINED_SAMPLES") = 0;//py::cast(B_UNDEFINED_SAMPLES); +m.attr("B_LINEAR_SAMPLES") = 1;//py::cast(B_LINEAR_SAMPLES); +m.attr("B_FLOAT_SAMPLES") = 2;//py::cast(B_FLOAT_SAMPLES); +m.attr("B_MULAW_SAMPLES") = 3;//py::cast(B_MULAW_SAMPLES); + +m.attr("B_CODEC_TYPE_INFO") = 0x040807b2;//py::cast(B_CODEC_TYPE_INFO); from haiku source kits/media/MediaDefs.cpp + +m.attr("B_MEDIA_MESSAGE_SIZE") = 16384;//py::cast(B_MEDIA_MESSAGE_SIZE); + +m.attr("B_MEDIA_SERVER_SIGNATURE") = "application/x-vnd.Be.media-server";//py::cast(B_MEDIA_SERVER_SIGNATURE); + +py::class_(m, "media_destination") +.def(py::init(), "") +.def(py::init(), "", py::arg(""), py::arg("")) +.def(py::init(), "", py::arg("other")) +.def("operator=", &media_destination::operator=, "", py::arg("other")) +.def_readwrite("port", &media_destination::port, "") +.def_readwrite("id", &media_destination::id, "") +//.def_readwrite("null", &media_destination::null, "") +; + +py::class_(m, "media_source") +.def(py::init(), "") +.def(py::init(), "", py::arg(""), py::arg("")) +.def(py::init(), "", py::arg("other")) +.def("operator=", &media_source::operator=, "", py::arg("other")) +.def_readwrite("port", &media_source::port, "") +.def_readwrite("id", &media_source::id, "") +//.def_readwrite("null", &media_source::null, "") +; + +py::class_(m, "media_raw_audio_format") +.def_readwrite("frame_rate", &media_raw_audio_format::frame_rate, "") +.def_readwrite("channel_count", &media_raw_audio_format::channel_count, "") +.def_readwrite("format", &media_raw_audio_format::format, "") +.def_readwrite("byte_order", &media_raw_audio_format::byte_order, "") +.def_readwrite("buffer_size", &media_raw_audio_format::buffer_size, "") +//.def_readwrite("wildcard", &media_raw_audio_format::wildcard, "") +; + +py::class_(m, "media_audio_header") +//.def_readwrite("_reserved_", &media_audio_header::_reserved_, "") +.def_property( + "_reserved_", + [](const media_audio_header &header) { + py::array_t result(14); + std::memcpy(result.mutable_data(), &header._reserved_, sizeof(header._reserved_)); + return result; + }, + [](media_audio_header &header, py::array_t value) { + if (value.size() != 14) { + throw std::runtime_error("Array must have size 14"); + } + std::memcpy(&header._reserved_, value.data(), sizeof(header._reserved_)); + },"") +.def_readwrite("frame_rate", &media_audio_header::frame_rate, "") +.def_readwrite("channel_count", &media_audio_header::channel_count, "") +; + +py::class_(m, "media_multi_audio_info") +.def_readwrite("channel_mask", &media_multi_audio_info::channel_mask, "") +.def_readwrite("valid_bits", &media_multi_audio_info::valid_bits, "") +.def_readwrite("matrix_mask", &media_multi_audio_info::matrix_mask, "") +//.def_readwrite("_reserved_b", &media_multi_audio_info::_reserved_b, "") +.def_property( + "_reserved_b", + [](const media_multi_audio_info &info) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &info._reserved_b, sizeof(info._reserved_b)); + return result; + }, + [](media_multi_audio_info &info, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&info._reserved_b, value.data(), sizeof(info._reserved_b)); + },"") +; + +py::class_(m, "media_multi_audio_format") +//.def_readwrite("wildcard", &media_multi_audio_format::wildcard, "") +; + +py::class_(m, "media_encoded_audio_format") +.def_readwrite("output", &media_encoded_audio_format::output, "") +.def_readwrite("encoding", &media_encoded_audio_format::encoding, "") +.def_readwrite("bit_rate", &media_encoded_audio_format::bit_rate, "") +.def_readwrite("frame_size", &media_encoded_audio_format::frame_size, "") +.def_readwrite("multi_info", &media_encoded_audio_format::multi_info, "") +//.def_readwrite("_reserved_", &media_encoded_audio_format::_reserved_, "") +.def_property( + "_reserved_", + [](const media_encoded_audio_format &format) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &format._reserved_, sizeof(format._reserved_)); + return result; + }, + [](media_encoded_audio_format &format, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&format._reserved_, value.data(), sizeof(format._reserved_)); + },"") +//.def_readwrite("wildcard", &media_encoded_audio_format::wildcard, "") +; + +py::class_(m, "media_encoded_audio_header") +//.def_readwrite("_reserved_0", &media_encoded_audio_header::_reserved_0, "") +.def_property( + "_reserved_0", + [](const media_encoded_audio_header &header) { + py::array_t result(14); + std::memcpy(result.mutable_data(), &header._reserved_0, sizeof(header._reserved_0)); + return result; + }, + [](media_encoded_audio_header &header, py::array_t value) { + if (value.size() != 14) { + throw std::runtime_error("Array must have size 14"); + } + std::memcpy(&header._reserved_0, value.data(), sizeof(header._reserved_0)); + },"") +.def_readwrite("buffer_flags", &media_encoded_audio_header::buffer_flags, "") +.def_readwrite("unused_mask", &media_encoded_audio_header::unused_mask, "") +//.def_readwrite("_reserved_2", &media_encoded_audio_header::_reserved_2, "") +.def_property( + "_reserved_2", + [](const media_encoded_audio_header &header) { + py::array_t result(2); + std::memcpy(result.mutable_data(), &header._reserved_2, sizeof(header._reserved_2)); + return result; + }, + [](media_encoded_audio_header &header, py::array_t value) { + if (value.size() != 2) { + throw std::runtime_error("Array must have size 2"); + } + std::memcpy(&header._reserved_2, value.data(), sizeof(header._reserved_2)); + },"") +; + +py::class_(m, "media_video_display_info") +.def_readwrite("format", &media_video_display_info::format, "") +.def_readwrite("line_width", &media_video_display_info::line_width, "") +.def_readwrite("line_count", &media_video_display_info::line_count, "") +.def_readwrite("bytes_per_row", &media_video_display_info::bytes_per_row, "") +.def_readwrite("pixel_offset", &media_video_display_info::pixel_offset, "") +.def_readwrite("line_offset", &media_video_display_info::line_offset, "") +.def_readwrite("flags", &media_video_display_info::flags, "") +//.def_readwrite("_reserved_", &media_video_display_info::_reserved_, "") +.def_property( + "_reserved_", + [](const media_video_display_info &info) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &info._reserved_, sizeof(info._reserved_)); + return result; + }, + [](media_video_display_info &info, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&info._reserved_, value.data(), sizeof(info._reserved_)); + },"") +//.def_readwrite("wildcard", &media_video_display_info::wildcard, "") +; + +py::class_(m, "media_raw_video_format") +.def_readwrite("field_rate", &media_raw_video_format::field_rate, "") +.def_readwrite("interlace", &media_raw_video_format::interlace, "") +.def_readwrite("first_active", &media_raw_video_format::first_active, "") +.def_readwrite("last_active", &media_raw_video_format::last_active, "") +.def_readwrite("orientation", &media_raw_video_format::orientation, "") +.def_readwrite("pixel_width_aspect", &media_raw_video_format::pixel_width_aspect, "") +.def_readwrite("pixel_height_aspect", &media_raw_video_format::pixel_height_aspect, "") +.def_readwrite("display", &media_raw_video_format::display, "") +//.def_readwrite("wildcard", &media_raw_video_format::wildcard, "") +; + +py::class_(m, "media_video_header") +//.def_readwrite("_reserved_", &media_video_header::_reserved_, "") +.def_property( + "_reserved_", + [](const media_video_header &header) { + py::array_t result(8); + std::memcpy(result.mutable_data(), &header._reserved_, sizeof(header._reserved_)); + return result; + }, + [](media_video_header &header, py::array_t value) { + if (value.size() != 8) { + throw std::runtime_error("Array must have size 8"); + } + std::memcpy(&header._reserved_, value.data(), sizeof(header._reserved_)); + },"") +.def_readwrite("display_line_width", &media_video_header::display_line_width, "") +.def_readwrite("display_line_count", &media_video_header::display_line_count, "") +.def_readwrite("bytes_per_row", &media_video_header::bytes_per_row, "") +.def_readwrite("pixel_width_aspect", &media_video_header::pixel_width_aspect, "") +.def_readwrite("pixel_height_aspect", &media_video_header::pixel_height_aspect, "") +.def_readwrite("field_gamma", &media_video_header::field_gamma, "") +.def_readwrite("field_sequence", &media_video_header::field_sequence, "") +.def_readwrite("field_number", &media_video_header::field_number, "") +.def_readwrite("pulldown_number", &media_video_header::pulldown_number, "") +.def_readwrite("first_active_line", &media_video_header::first_active_line, "") +.def_readwrite("line_count", &media_video_header::line_count, "") +; + +py::class_(m, "media_encoded_video_format") +.def_readwrite("output", &media_encoded_video_format::output, "") +.def_readwrite("avg_bit_rate", &media_encoded_video_format::avg_bit_rate, "") +.def_readwrite("max_bit_rate", &media_encoded_video_format::max_bit_rate, "") +.def_readwrite("encoding", &media_encoded_video_format::encoding, "") +.def_readwrite("frame_size", &media_encoded_video_format::frame_size, "") +.def_readwrite("forward_history", &media_encoded_video_format::forward_history, "") +.def_readwrite("backward_history", &media_encoded_video_format::backward_history, "") +//.def_readwrite("_reserved_", &media_encoded_video_format::_reserved_, "") +.def_property( + "_reserved_", + [](const media_encoded_video_format &format) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &format._reserved_, sizeof(format._reserved_)); + return result; + }, + [](media_encoded_video_format &format, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&format._reserved_, value.data(), sizeof(format._reserved_)); + },"") +//.def_readwrite("wildcard", &media_encoded_video_format::wildcard, "") +; + +py::class_(m, "media_encoded_video_header") +//.def_readwrite("_reserved_1", &media_encoded_video_header::_reserved_1, "") +.def_property( + "_reserved_1", + [](const media_encoded_video_header &header) { + py::array_t result(9); + std::memcpy(result.mutable_data(), &header._reserved_1, sizeof(header._reserved_1)); + return result; + }, + [](media_encoded_video_header &header, py::array_t value) { + if (value.size() != 9) { + throw std::runtime_error("Array must have size 9"); + } + std::memcpy(&header._reserved_1, value.data(), sizeof(header._reserved_1)); + },"") +.def_readwrite("field_flags", &media_encoded_video_header::field_flags, "") +.def_readwrite("forward_history", &media_encoded_video_header::forward_history, "") +.def_readwrite("backward_history", &media_encoded_video_header::backward_history, "") +.def_readwrite("unused_mask", &media_encoded_video_header::unused_mask, "") +//.def_readwrite("_reserved_2", &media_encoded_video_header::_reserved_2, "") +.def_property( + "_reserved_2", + [](const media_encoded_video_header &header) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &header._reserved_2, sizeof(header._reserved_2)); + return result; + }, + [](media_encoded_video_header &header, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&header._reserved_2, value.data(), sizeof(header._reserved_2)); + },"") +.def_readwrite("field_gamma", &media_encoded_video_header::field_gamma, "") +.def_readwrite("field_sequence", &media_encoded_video_header::field_sequence, "") +.def_readwrite("field_number", &media_encoded_video_header::field_number, "") +.def_readwrite("pulldown_number", &media_encoded_video_header::pulldown_number, "") +.def_readwrite("first_active_line", &media_encoded_video_header::first_active_line, "") +.def_readwrite("line_count", &media_encoded_video_header::line_count, "") +; + +py::class_(m, "media_multistream_format") +.def_readwrite("avg_bit_rate", &media_multistream_format::avg_bit_rate, "") +.def_readwrite("max_bit_rate", &media_multistream_format::max_bit_rate, "") +.def_readwrite("avg_chunk_size", &media_multistream_format::avg_chunk_size, "") +.def_readwrite("max_chunk_size", &media_multistream_format::max_chunk_size, "") +.def_readwrite("flags", &media_multistream_format::flags, "") +.def_readwrite("format", &media_multistream_format::format, "") +//.def_readwrite("_reserved_", &media_multistream_format::_reserved_, "") +.def_property( + "_reserved_", + [](const media_multistream_format &format) { + py::array_t result(2); + std::memcpy(result.mutable_data(), &format._reserved_, sizeof(format._reserved_)); + return result; + }, + [](media_multistream_format &format, py::array_t value) { + if (value.size() != 2) { + throw std::runtime_error("Array must have size 2"); + } + std::memcpy(&format._reserved_, value.data(), sizeof(format._reserved_)); + },"") +.def_readwrite("u", &media_multistream_format::u, "") +//.def_readwrite("wildcard", &media_multistream_format::wildcard, "") +.def_static("wildcard", []() { return media_multistream_format::wildcard; }) +; + +py::class_(m, "vid_info") +.def_readwrite("frame_rate", &media_multistream_format::vid_info::frame_rate, "") +.def_readwrite("width", &media_multistream_format::vid_info::width, "") +.def_readwrite("height", &media_multistream_format::vid_info::height, "") +.def_readwrite("space", &media_multistream_format::vid_info::space, "") +.def_readwrite("sampling_rate", &media_multistream_format::vid_info::sampling_rate, "") +.def_readwrite("sample_format", &media_multistream_format::vid_info::sample_format, "") +.def_readwrite("byte_order", &media_multistream_format::vid_info::byte_order, "") +.def_readwrite("channel_count", &media_multistream_format::vid_info::channel_count, "") +; + +py::class_(m, "avi_info") +.def_readwrite("us_per_frame", &media_multistream_format::avi_info::us_per_frame, "") +.def_readwrite("width", &media_multistream_format::avi_info::width, "") +.def_readwrite("height", &media_multistream_format::avi_info::height, "") +.def_readwrite("_reserved_", &media_multistream_format::avi_info::_reserved_, "") +.def_readwrite("type_count", &media_multistream_format::avi_info::type_count, "") +//.def_readwrite("types", &media_multistream_format::avi_info::types, "") +.def_property( + "types", + [](const media_multistream_format::avi_info &format) { + py::array_t result(5); + std::memcpy(result.mutable_data(), &format.types, sizeof(format.types)); + return result; + }, + [](media_multistream_format::avi_info &format, py::array_t value) { + if (value.size() != 5) { + throw std::runtime_error("Array must have size 5"); + } + std::memcpy(&format.types, value.data(), sizeof(format.types)); + },"") +; + +/*py::class_(m, "union ") +.def_readwrite("vid", &union ::vid, "") +.def_readwrite("avi", &union ::avi, "") +;*/ + +py::class_(m, "media_multistream_header") +//.def_readwrite("_reserved_", &media_multistream_header::_reserved_, "") +.def_property( + "_reserved_", + [](const media_multistream_header &header) { + py::array_t result(14); + std::memcpy(result.mutable_data(), &header._reserved_, sizeof(header._reserved_)); + return result; + }, + [](media_multistream_header &header, py::array_t value) { + if (value.size() != 14) { + throw std::runtime_error("Array must have size 14"); + } + std::memcpy(&header._reserved_, value.data(), sizeof(header._reserved_)); + },"") +.def_readwrite("unused_mask", &media_multistream_header::unused_mask, "") +//.def_readwrite("_reserved_2", &media_multistream_header::_reserved_2, "") +.def_property( + "_reserved_2", + [](const media_multistream_header &header) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &header._reserved_2, sizeof(header._reserved_2)); + return result; + }, + [](media_multistream_header &header, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&header._reserved_2, value.data(), sizeof(header._reserved_2)); + },"") +.def_readwrite("flags", &media_multistream_header::flags, "") +; + +py::class_(m, "media_format") +.def("IsVideo", &media_format::IsVideo, "") +.def("Width", py::overload_cast<>(&media_format::Width), "") +.def("Height", py::overload_cast<>(&media_format::Height), "") +.def("ColorSpace", py::overload_cast<>(&media_format::ColorSpace), "") +.def("Width", py::overload_cast<>(&media_format::Width), "") +.def("Height", py::overload_cast<>(&media_format::Height), "") +.def("ColorSpace", py::overload_cast<>(&media_format::ColorSpace), "") +.def("IsAudio", &media_format::IsAudio, "") +.def("AudioFormat", py::overload_cast<>(&media_format::AudioFormat), "") +.def("AudioFormat", py::overload_cast<>(&media_format::AudioFormat), "") +.def("AudioFrameSize", &media_format::AudioFrameSize, "") +.def("Encoding", &media_format::Encoding, "") +.def("Matches", &media_format::Matches, "", py::arg("other")) +.def("SpecializeTo", &media_format::SpecializeTo, "", py::arg("other")) +.def("SetMetaData", &media_format::SetMetaData, "", py::arg("data"), py::arg("size")) +.def("MetaData", &media_format::MetaData, "") +.def("MetaDataSize", &media_format::MetaDataSize, "") +.def("Unflatten", &media_format::Unflatten, "", py::arg("flatBuffer")) +.def("Clear", &media_format::Clear, "") +.def(py::init(), "") +.def(py::init(), "", py::arg("other")) +.def("operator=", &media_format::operator=, "", py::arg("other")) +.def_readwrite("type", &media_format::type, "") +.def_readwrite("user_data_type", &media_format::user_data_type, "") +//.def_readwrite("user_data", &media_format::user_data, "") +.def_property( + "user_data", + [](const media_format &format) { + py::array_t result(48); + std::memcpy(result.mutable_data(), &format.user_data, sizeof(format.user_data)); + return result; + }, + [](media_format &format, py::array_t value) { + if (value.size() != 48) { + throw std::runtime_error("Array must have size 48"); + } + std::memcpy(&format.user_data, value.data(), sizeof(format.user_data)); + },"") +//.def_readwrite("_reserved_", &media_format::_reserved_, "") +.def_property( + "_reserved_", + [](const media_format &format) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &format._reserved_, sizeof(format._reserved_)); + return result; + }, + [](media_format &format, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&format._reserved_, value.data(), sizeof(format._reserved_)); + },"") +.def_readwrite("require_flags", &media_format::require_flags, "") +.def_readwrite("deny_flags", &media_format::deny_flags, "") +.def_readwrite("u", &media_format::u, "") +; +/* +py::class_(m, "union ") +.def_readwrite("raw_audio", &union ::raw_audio, "") +.def_readwrite("raw_video", &union ::raw_video, "") +.def_readwrite("multistream", &union ::multistream, "") +.def_readwrite("encoded_audio", &union ::encoded_audio, "") +.def_readwrite("encoded_video", &union ::encoded_video, "") +.def_readwrite("_reserved_", &union ::_reserved_, "") +;*/ + +py::class_(m, "media_seek_tag") +//.def_readwrite("data", &media_seek_tag::data, "") +.def_property( + "data", + [](const media_seek_tag &tag) { + py::array_t result(16); + std::memcpy(result.mutable_data(), &tag.data, sizeof(tag.data)); + return result; + }, + [](media_seek_tag &tag, py::array_t value) { + if (value.size() != 16) { + throw std::runtime_error("Array must have size 16"); + } + std::memcpy(&tag.data, value.data(), sizeof(tag.data)); + },"") +; + +py::class_(m, "media_header_time_code") +.def_readwrite("type", &media_header_time_code::type, "") +.def_readwrite("_reserved", &media_header_time_code::_reserved, "") +.def_readwrite("hours", &media_header_time_code::hours, "") +.def_readwrite("minutes", &media_header_time_code::minutes, "") +.def_readwrite("seconds", &media_header_time_code::seconds, "") +.def_readwrite("frames", &media_header_time_code::frames, "") +.def_readwrite("subframes", &media_header_time_code::subframes, "") +; + +py::class_(m, "media_header") +.def_readwrite("type", &media_header::type, "") +.def_readwrite("buffer", &media_header::buffer, "") +.def_readwrite("destination", &media_header::destination, "") +.def_readwrite("time_source", &media_header::time_source, "") +.def_readwrite("_deprecated_", &media_header::_deprecated_, "") +.def_readwrite("size_used", &media_header::size_used, "") +.def_readwrite("start_time", &media_header::start_time, "") +.def_readwrite("owner", &media_header::owner, "") +.def_readwrite("user_data_type", &media_header::user_data_type, "") +//.def_readwrite("user_data", &media_header::user_data, "") +.def_property( + "user_data", + [](const media_header &header) { + py::array_t result(64); + std::memcpy(result.mutable_data(), &header.user_data, sizeof(header.user_data)); + return result; + }, + [](media_header &header, py::array_t value) { + if (value.size() != 64) { + throw std::runtime_error("Array must have size 64"); + } + std::memcpy(&header.user_data, value.data(), sizeof(header.user_data)); + },"") +.def_readwrite("source", &media_header::source, "") +.def_readwrite("source_port", &media_header::source_port, "") +.def_readwrite("file_pos", &media_header::file_pos, "") +.def_readwrite("orig_size", &media_header::orig_size, "") +.def_readwrite("data_offset", &media_header::data_offset, "") +.def_readwrite("u", &media_header::u, "") +; +/* +py::class_(m, "union ") +.def_readwrite("raw_audio", &union ::raw_audio, "") +.def_readwrite("raw_video", &union ::raw_video, "") +.def_readwrite("multistream", &union ::multistream, "") +.def_readwrite("encoded_audio", &union ::encoded_audio, "") +.def_readwrite("encoded_video", &union ::encoded_video, "") +.def_readwrite("_reserved_", &union ::_reserved_, "") +;*/ + +py::class_(m, "media_file_format_id") +.def_readwrite("node", &media_file_format_id::node, "") +.def_readwrite("device", &media_file_format_id::device, "") +.def_readwrite("internal_id", &media_file_format_id::internal_id, "") +; + +py::class_(m, "media_file_format") +/* + B_READABLE = 0x1, + B_WRITABLE = 0x2, + B_PERFECTLY_SEEKABLE = 0x4, + B_IMPERFECTLY_SEEKABLE = 0x8, + B_KNOWS_RAW_VIDEO = 0x10, + B_KNOWS_RAW_AUDIO = 0x20, + B_KNOWS_MIDI = 0x40, + B_KNOWS_ENCODED_VIDEO = 0x80, + B_KNOWS_ENCODED_AUDIO = 0x100, + B_KNOWS_OTHER = 0x1000000, // For example sub-title streams + B_KNOWS_ANYTHING = 0x2000000 + */ +.def_readwrite("capabilities", &media_file_format::capabilities, "") +.def_readwrite("id", &media_file_format::id, "") +.def_readwrite("family", &media_file_format::family, "") +.def_readwrite("version", &media_file_format::version, "") +//.def_readwrite("_reserved_", &media_file_format::_reserved_, "") +.def_property( + "_reserved_", + [](const media_file_format &format) { + py::array_t result(25); + std::memcpy(result.mutable_data(), &format._reserved_, sizeof(format._reserved_)); + return result; + }, + [](media_file_format &format, py::array_t value) { + if (value.size() != 25) { + throw std::runtime_error("Array must have size 25"); + } + std::memcpy(&format._reserved_, value.data(), sizeof(format._reserved_)); + },"") +//.def_readwrite("mime_type", &media_file_format::mime_type, "") +.def_property( + "mime_type", + [](const media_file_format &format) { + py::array_t result(64); + std::memcpy(result.mutable_data(), &format.mime_type, sizeof(format.mime_type)); + return result; + }, + [](media_file_format &format, py::array_t value) { + if (value.size() != 64) { + throw std::runtime_error("Array must have size 64"); + } + std::memcpy(&format.mime_type, value.data(), sizeof(format.mime_type)); + },"") +//.def_readwrite("pretty_name", &media_file_format::pretty_name, "") +.def_property( + "pretty_name", + [](const media_file_format &format) { + py::array_t result(64); + std::memcpy(result.mutable_data(), &format.pretty_name, sizeof(format.pretty_name)); + return result; + }, + [](media_file_format &format, py::array_t value) { + if (value.size() != 64) { + throw std::runtime_error("Array must have size 64"); + } + std::memcpy(&format.pretty_name, value.data(), sizeof(format.pretty_name)); + },"") +//.def_readwrite("short_name", &media_file_format::short_name, "") +.def_property( + "short_name", + [](const media_file_format &format) { + py::array_t result(32); + std::memcpy(result.mutable_data(), &format.short_name, sizeof(format.short_name)); + return result; + }, + [](media_file_format &format, py::array_t value) { + if (value.size() != 32) { + throw std::runtime_error("Array must have size 32"); + } + std::memcpy(&format.short_name, value.data(), sizeof(format.short_name)); + },"") +//.def_readwrite("file_extension", &media_file_format::file_extension, "") +.def_property( + "file_extension", + [](const media_file_format &format) { + py::array_t result(8); + std::memcpy(result.mutable_data(), &format.file_extension, sizeof(format.file_extension)); + return result; + }, + [](media_file_format &format, py::array_t value) { + if (value.size() != 8) { + throw std::runtime_error("Array must have size 8"); + } + std::memcpy(&format.file_extension, value.data(), sizeof(format.file_extension)); + },"") +//.def_readwrite("reserved", &media_file_format::reserved, "") +.def_property( + "reserved", + [](const media_file_format &format) { + py::array_t result(88); + std::memcpy(result.mutable_data(), &format.reserved, sizeof(format.reserved)); + return result; + }, + [](media_file_format &format, py::array_t value) { + if (value.size() != 88) { + throw std::runtime_error("Array must have size 88"); + } + std::memcpy(&format.reserved, value.data(), sizeof(format.reserved)); + },"") +; + +py::class_(m, "media_encode_info") +.def(py::init(), "") +.def_readwrite("flags", &media_encode_info::flags, "") +.def_readwrite("used_data_size", &media_encode_info::used_data_size, "") +.def_readwrite("start_time", &media_encode_info::start_time, "") +.def_readwrite("time_to_encode", &media_encode_info::time_to_encode, "") +//.def_readwrite("_pad", &media_encode_info::_pad, "") +.def_property( + "_pad", + [](const media_encode_info &info) { + py::array_t result(22); + std::memcpy(result.mutable_data(), &info._pad, sizeof(info._pad)); + return result; + }, + [](media_encode_info &info, py::array_t value) { + if (value.size() != 22) { + throw std::runtime_error("Array must have size 22"); + } + std::memcpy(&info._pad, value.data(), sizeof(info._pad)); + },"") +.def_readwrite("file_format_data", &media_encode_info::file_format_data, "") +.def_readwrite("file_format_data_size", &media_encode_info::file_format_data_size, "") +.def_readwrite("codec_data", &media_encode_info::codec_data, "") +.def_readwrite("codec_data_size", &media_encode_info::codec_data_size, "") +; + +py::class_(m, "encode_parameters") +.def_readwrite("quality", &encode_parameters::quality, "") +.def_readwrite("avg_field_size", &encode_parameters::avg_field_size, "") +.def_readwrite("max_field_size", &encode_parameters::max_field_size, "") +//.def_readwrite("_pad", &encode_parameters::_pad, "") +.def_property( + "_pad", + [](const encode_parameters ¶meters) { + py::array_t result(27); + std::memcpy(result.mutable_data(), ¶meters._pad, sizeof(parameters._pad)); + return result; + }, + [](encode_parameters ¶meters, py::array_t value) { + if (value.size() != 27) { + throw std::runtime_error("Array must have size 27"); + } + std::memcpy(¶meters._pad, value.data(), sizeof(parameters._pad)); + },"") +.def_readwrite("user_data", &encode_parameters::user_data, "") +.def_readwrite("user_data_size", &encode_parameters::user_data_size, "") +; + +py::class_(m, "media_decode_info") +.def(py::init(), "") +.def_readwrite("time_to_decode", &media_decode_info::time_to_decode, "") +//.def_readwrite("_pad", &media_decode_info::_pad, "") +.def_property( + "_pad", + [](const media_decode_info &info) { + py::array_t result(26); + std::memcpy(result.mutable_data(), &info._pad, sizeof(info._pad)); + return result; + }, + [](media_decode_info &info, py::array_t value) { + if (value.size() != 26) { + throw std::runtime_error("Array must have size 26"); + } + std::memcpy(&info._pad, value.data(), sizeof(info._pad)); + },"") +.def_readwrite("file_format_data", &media_decode_info::file_format_data, "") +.def_readwrite("file_format_data_size", &media_decode_info::file_format_data_size, "") +.def_readwrite("codec_data", &media_decode_info::codec_data, "") +.def_readwrite("codec_data_size", &media_decode_info::codec_data_size, "") +; + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__ne__", py::overload_cast(&operator!=), "", py::arg("a"), py::arg("b")); + +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__ne__", py::overload_cast(&operator!=), "", py::arg("a"), py::arg("b")); + +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__ne__", py::overload_cast(&operator!=), "", py::arg("a"), py::arg("b")); + +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("format_is_compatible", &format_is_compatible, "", py::arg("a"), py::arg("b")); + +m.def("string_for_format", &string_for_format, "", py::arg("f"), py::arg("buf"), py::arg("size")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); + +m.def("get_next_file_format", &get_next_file_format, "", py::arg("cookie"), py::arg("mfi")); + +m.def("launch_media_server", &launch_media_server, "", py::arg("timeout")=B_INFINITE_TIMEOUT, py::arg("bool(*progress)(intstage,constchar*message,void*cookie)")=NULL, py::arg("cookie")=NULL, py::arg("flags")=0); + +m.def("shutdown_media_server", &shutdown_media_server, "", py::arg("timeout")=B_INFINITE_TIMEOUT, py::arg("bool(*progress)(intstage,constchar*message,void*cookie)")=NULL, py::arg("cookie")=NULL); + +} diff --git a/bindings/media/MediaEncoder.cpp b/bindings/media/MediaEncoder.cpp new file mode 100644 index 0000000..67712e9 --- /dev/null +++ b/bindings/media/MediaEncoder.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +void define_MediaEncoder(py::module_& m) +{ +m.attr("Encoder") = py::cast(Encoder); + +m.attr("EncoderPlugin") = py::cast(EncoderPlugin); + +py::class_(m, "BMediaEncoder") +.def(py::init(), "") +.def(py::init(), "", py::arg("outputFormat")) +.def(py::init(), "", py::arg("info")) +.def("InitCheck", &BMediaEncoder::InitCheck, "") +.def("SetTo", py::overload_cast(&BMediaEncoder::SetTo), "", py::arg("outputFormat")) +.def("SetTo", py::overload_cast(&BMediaEncoder::SetTo), "", py::arg("info")) +.def("SetFormat", &BMediaEncoder::SetFormat, "", py::arg("inputFormat"), py::arg("outputFormat"), py::arg("fileFormat")=NULL) +.def("Encode", &BMediaEncoder::Encode, "", py::arg("buffer"), py::arg("frameCount"), py::arg("info")) +.def("GetEncodeParameters", &BMediaEncoder::GetEncodeParameters, "", py::arg("parameters")) +.def("SetEncodeParameters", &BMediaEncoder::SetEncodeParameters, "", py::arg("parameters")) +; + +py::class_(m, "BMediaBufferEncoder") +.def(py::init(), "") +.def(py::init(), "", py::arg("outputFormat")) +.def(py::init(), "", py::arg("info")) +.def("EncodeToBuffer", &BMediaBufferEncoder::EncodeToBuffer, "", py::arg("outputBuffer"), py::arg("_size"), py::arg("inputBuffer"), py::arg("frameCount"), py::arg("info")) +; + + +} diff --git a/bindings/media/MediaEventLooper.cpp b/bindings/media/MediaEventLooper.cpp new file mode 100644 index 0000000..54443f0 --- /dev/null +++ b/bindings/media/MediaEventLooper.cpp @@ -0,0 +1,18 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +void define_MediaEventLooper(py::module_& m) +{ +py::class_(m, "BMediaEventLooper") +; + + +} diff --git a/bindings/media/MediaFile.cpp b/bindings/media/MediaFile.cpp new file mode 100644 index 0000000..53098bf --- /dev/null +++ b/bindings/media/MediaFile.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +void define_MediaFile(py::module_& m) +{ +m.attr("B_MEDIA_FILE_REPLACE_MODE") = py::cast(B_MEDIA_FILE_REPLACE_MODE); +m.attr("B_MEDIA_FILE_NO_READ_AHEAD") = py::cast(B_MEDIA_FILE_NO_READ_AHEAD); +m.attr("B_MEDIA_FILE_UNBUFFERED") = py::cast(B_MEDIA_FILE_UNBUFFERED); +m.attr("B_MEDIA_FILE_BIG_BUFFERS") = py::cast(B_MEDIA_FILE_BIG_BUFFERS); + +m.attr("MediaExtractor") = py::cast(MediaExtractor); + +m.attr("MediaStreamer") = py::cast(MediaStreamer); + +m.attr("MediaWriter") = py::cast(MediaWriter); + +m.attr("_AddonManager") = py::cast(_AddonManager); + +py::class_(m, "BMediaFile") +.def(py::init(), "", py::arg("ref")) +.def(py::init(), "", py::arg("source")) +.def(py::init(), "", py::arg("ref"), py::arg("flags")) +.def(py::init(), "", py::arg("source"), py::arg("flags")) +.def(py::init(), "", py::arg("ref"), py::arg("mfi"), py::arg("flags")=0) +.def(py::init(), "", py::arg("destination"), py::arg("mfi"), py::arg("flags")=0) +.def(py::init(), "", py::arg("mfi"), py::arg("flags")=0) +.def(py::init(), "", py::arg("url")) +.def(py::init(), "", py::arg("url"), py::arg("flags")) +.def(py::init(), "", py::arg("destination"), py::arg("mfi"), py::arg("flags")=0) +.def("SetTo", py::overload_cast(&BMediaFile::SetTo), "", py::arg("ref")) +.def("SetTo", py::overload_cast(&BMediaFile::SetTo), "", py::arg("destination")) +.def("SetTo", py::overload_cast(&BMediaFile::SetTo), "", py::arg("url")) +.def("InitCheck", &BMediaFile::InitCheck, "") +.def("GetFileFormatInfo", &BMediaFile::GetFileFormatInfo, "", py::arg("mfi")) +.def("GetMetaData", &BMediaFile::GetMetaData, "", py::arg("_data")) +.def("Copyright", &BMediaFile::Copyright, "") +.def("CountTracks", &BMediaFile::CountTracks, "") +.def("TrackAt", &BMediaFile::TrackAt, "", py::arg("index")) +.def("ReleaseTrack", &BMediaFile::ReleaseTrack, "", py::arg("track")) +.def("ReleaseAllTracks", &BMediaFile::ReleaseAllTracks, "") +.def("CreateTrack", py::overload_cast(&BMediaFile::CreateTrack), "", py::arg("mf"), py::arg("mci"), py::arg("flags")=0) +.def("CreateTrack", py::overload_cast(&BMediaFile::CreateTrack), "", py::arg("mf"), py::arg("flags")=0) +.def("AddCopyright", &BMediaFile::AddCopyright, "", py::arg("data")) +.def("AddChunk", &BMediaFile::AddChunk, "", py::arg("type"), py::arg("data"), py::arg("size")) +.def("CommitHeader", &BMediaFile::CommitHeader, "") +.def("CloseFile", &BMediaFile::CloseFile, "") +.def("GetParameterWeb", &BMediaFile::GetParameterWeb, "", py::arg("outWeb")) +.def("GetParameterValue", &BMediaFile::GetParameterValue, "", py::arg("id"), py::arg("value"), py::arg("size")) +.def("SetParameterValue", &BMediaFile::SetParameterValue, "", py::arg("id"), py::arg("value"), py::arg("size")) +.def("GetParameterView", &BMediaFile::GetParameterView, "") +.def("Perform", &BMediaFile::Perform, "", py::arg("selector"), py::arg("data")) +; + + +} diff --git a/bindings/media/MediaFiles.cpp b/bindings/media/MediaFiles.cpp new file mode 100644 index 0000000..6b7ee90 --- /dev/null +++ b/bindings/media/MediaFiles.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +void define_MediaFiles(py::module_& m) +{ +py::class_(m, "BMediaFiles") +.def(py::init(), "") +.def("RewindTypes", &BMediaFiles::RewindTypes, "") +.def("GetNextType", &BMediaFiles::GetNextType, "", py::arg("_type")) +.def("RewindRefs", &BMediaFiles::RewindRefs, "", py::arg("type")) +.def("GetNextRef", &BMediaFiles::GetNextRef, "", py::arg("_type"), py::arg("_ref")=NULL) +.def("GetRefFor", &BMediaFiles::GetRefFor, "", py::arg("type"), py::arg("item"), py::arg("_ref")) +.def("SetRefFor", &BMediaFiles::SetRefFor, "", py::arg("type"), py::arg("item"), py::arg("ref")) +.def("GetAudioGainFor", &BMediaFiles::GetAudioGainFor, "", py::arg("type"), py::arg("item"), py::arg("_gain")) +.def("SetAudioGainFor", &BMediaFiles::SetAudioGainFor, "", py::arg("type"), py::arg("item"), py::arg("gain")) +.def("RemoveRefFor", &BMediaFiles::RemoveRefFor, "", py::arg("type"), py::arg("item"), py::arg("ref")) +.def("RemoveItem", &BMediaFiles::RemoveItem, "", py::arg("type"), py::arg("item")) +.def_readwrite("B_SOUNDS", &BMediaFiles::B_SOUNDS, "") +; + + +} diff --git a/bindings/media/MediaFormats.cpp b/bindings/media/MediaFormats.cpp new file mode 100644 index 0000000..8ea2858 --- /dev/null +++ b/bindings/media/MediaFormats.cpp @@ -0,0 +1,199 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +void define_MediaFormats(py::module_& m) +{ +py::enum_(m, "media_file_accept_format_flags", "") +.value("B_MEDIA_REJECT_WILDCARDS", media_file_accept_format_flags::B_MEDIA_REJECT_WILDCARDS, "") +.export_values(); + +py::enum_(m, "beos_format", "") +.value("B_BEOS_FORMAT_RAW_AUDIO", beos_format::B_BEOS_FORMAT_RAW_AUDIO, "") +.value("B_BEOS_FORMAT_RAW_VIDEO", beos_format::B_BEOS_FORMAT_RAW_VIDEO, "") +.export_values(); + +py::enum_(m, "mpeg_id", "") +.value("B_MPEG_ANY", mpeg_id::B_MPEG_ANY, "") +.value("B_MPEG_1_AUDIO_LAYER_1", mpeg_id::B_MPEG_1_AUDIO_LAYER_1, "") +.value("B_MPEG_1_AUDIO_LAYER_2", mpeg_id::B_MPEG_1_AUDIO_LAYER_2, "") +.value("B_MPEG_1_AUDIO_LAYER_3", mpeg_id::B_MPEG_1_AUDIO_LAYER_3, "") +.value("B_MPEG_1_VIDEO", mpeg_id::B_MPEG_1_VIDEO, "") +.value("B_MPEG_2_AUDIO_LAYER_1", mpeg_id::B_MPEG_2_AUDIO_LAYER_1, "") +.value("B_MPEG_2_AUDIO_LAYER_2", mpeg_id::B_MPEG_2_AUDIO_LAYER_2, "") +.value("B_MPEG_2_AUDIO_LAYER_3", mpeg_id::B_MPEG_2_AUDIO_LAYER_3, "") +.value("B_MPEG_2_VIDEO", mpeg_id::B_MPEG_2_VIDEO, "") +.value("B_MPEG_2_5_AUDIO_LAYER_1", mpeg_id::B_MPEG_2_5_AUDIO_LAYER_1, "") +.value("B_MPEG_2_5_AUDIO_LAYER_2", mpeg_id::B_MPEG_2_5_AUDIO_LAYER_2, "") +.value("B_MPEG_2_5_AUDIO_LAYER_3", mpeg_id::B_MPEG_2_5_AUDIO_LAYER_3, "") +.export_values(); + +py::class_(m, "media_codec_info") +.def_readwrite("pretty_name", &media_codec_info::pretty_name, "") +.def_readwrite("short_name", &media_codec_info::short_name, "") +.def_readwrite("id", &media_codec_info::id, "") +.def_readwrite("sub_id", &media_codec_info::sub_id, "") +.def_readwrite("pad", &media_codec_info::pad, "") +; + +py::class_(m, "GUID") +.def_readwrite("data", &GUID::data, "") +; + +py::class_(m, "media_beos_description") +.def_readwrite("format", &media_beos_description::format, "") +; + +py::class_(m, "media_quicktime_description") +.def_readwrite("codec", &media_quicktime_description::codec, "") +.def_readwrite("vendor", &media_quicktime_description::vendor, "") +; + +py::class_(m, "media_avi_description") +.def_readwrite("codec", &media_avi_description::codec, "") +; + +py::class_(m, "media_avr_description") +.def_readwrite("id", &media_avr_description::id, "") +; + +py::class_(m, "media_asf_description") +.def_readwrite("guid", &media_asf_description::guid, "") +; + +py::class_(m, "media_mpeg_description") +.def_readwrite("id", &media_mpeg_description::id, "") +; + +py::class_(m, "media_wav_description") +.def_readwrite("codec", &media_wav_description::codec, "") +; + +py::class_(m, "media_aiff_description") +.def_readwrite("codec", &media_aiff_description::codec, "") +; + +py::class_(m, "media_misc_description") +.def_readwrite("file_format", &media_misc_description::file_format, "") +.def_readwrite("codec", &media_misc_description::codec, "") +; + +py::class_(m, "union ") +.def_readwrite("beos", &union ::beos, "") +.def_readwrite("quicktime", &union ::quicktime, "") +.def_readwrite("avi", &union ::avi, "") +.def_readwrite("asf", &union ::asf, "") +.def_readwrite("mpeg", &union ::mpeg, "") +.def_readwrite("wav", &union ::wav, "") +.def_readwrite("aiff", &union ::aiff, "") +.def_readwrite("misc", &union ::misc, "") +.def_readwrite("avr", &union ::avr, "") +.def_readwrite("_reserved_", &union ::_reserved_, "") +; + +py::class_(m, "media_format_description") +.def(py::init(), "") +.def(py::init(), "", py::arg("other")) +.def("operator=", &media_format_description::operator=, "", py::arg("other")) +.def_readwrite("family", &media_format_description::family, "") +.def_readwrite("_reserved_", &media_format_description::_reserved_, "") +.def_readwrite("u", &media_format_description::u, "") +; + +py::class_(m, "BMediaFormats") +.def(py::init(), "") +.def("InitCheck", &BMediaFormats::InitCheck, "") +.def("MakeFormatFor", py::overload_cast(&BMediaFormats::MakeFormatFor), "", py::arg("descriptions"), py::arg("descriptionCount"), py::arg("_inOutFormat"), py::arg("flags")=0, py::arg("_reserved")=0) +.def("GetFormatFor", &BMediaFormats::GetFormatFor, "", py::arg("description"), py::arg("_outFormat")) +.def("GetCodeFor", &BMediaFormats::GetCodeFor, "", py::arg("format"), py::arg("family"), py::arg("_outDescription")) +.def("RewindFormats", &BMediaFormats::RewindFormats, "") +.def("GetNextFormat", &BMediaFormats::GetNextFormat, "", py::arg("_outFormat"), py::arg("_outDescription")) +.def("Lock", &BMediaFormats::Lock, "") +.def("Unlock", &BMediaFormats::Unlock, "") +.def_static("GetBeOSFormatFor", &BMediaFormats::GetBeOSFormatFor, "", py::arg("fourcc"), py::arg("_outFormat"), py::arg("type")=B_MEDIA_UNKNOWN_TYPE) +.def_static("GetAVIFormatFor", &BMediaFormats::GetAVIFormatFor, "", py::arg("fourcc"), py::arg("_outFormat"), py::arg("type")=B_MEDIA_UNKNOWN_TYPE) +.def_static("GetQuicktimeFormatFor", &BMediaFormats::GetQuicktimeFormatFor, "", py::arg("vendor"), py::arg("fourcc"), py::arg("_outFormat"), py::arg("type")=B_MEDIA_UNKNOWN_TYPE) +.def("MakeFormatFor", py::overload_cast(&BMediaFormats::MakeFormatFor), "", py::arg("description"), py::arg("inFormat"), py::arg("_outFormat")) +; + +m.def("get_next_encoder", py::overload_cast(&get_next_encoder), + R"ipc_Qu8mg5v7( + /*! \brief Use this to iterate through the available encoders for a given file +format. +\param cookie A pointer to a preallocated cookie, which you need +to initialize to \c 0 before calling this function +the first time. +\param fileFormat A pointer to a valid media_file_format structure +as can be obtained through get_next_file_format(). +\param inputFormat This is the type of data given to the encoder. +\param _outputFormat This is the type of data the encoder will output. +\param _codecInfo Pointer to a preallocated media_codec_info structure, +information about the encoder is placed there. +\return +- \c B_OK: Everything went fine. +- \c B_BAD_INDEX: There are no more encoders. +*/ + )ipc_Qu8mg5v7", py::arg("cookie"), py::arg("fileFormat"), py::arg("inputFormat"), py::arg("_outputFormat"), py::arg("_codecInfo")); + +m.def("get_next_encoder", py::overload_cast(&get_next_encoder), + R"ipc_Qu8mg5v7( + /*! \brief Use this to iterate through the available encoders with +restrictions to the input and output media_format while the +encoders can specialize wildcards in the media_formats. +\param cookie A pointer to a preallocated cookie, which you need +to initialize to \c 0 before calling this function +the first time. +\param fileFormat A pointer to a valid media_file_format structure +as can be obtained through get_next_file_format(). +You can pass \c NULL if you don't care. +\param inputFormat This is the type of data given to the encoder, +wildcards are accepted. +\param outputFormat This is the type of data you want the encoder to +output. Wildcards are accepted. +\param _codecInfo Pointer to a preallocated media_codec_info structure, +information about the encoder is placed there. +\param _acceptedInputFormat This is the type of data that the encoder will +accept as input. Wildcards in \a inFormat will be +specialized here. +\param _acceptedOutputFormat This is the type of data that the encoder will +output. Wildcards in \a _outFormat will be specialized +here. +\return +- \c B_OK: Everything went fine. +- \c B_BAD_INDEX: There are no more encoders. +*/ + )ipc_Qu8mg5v7", py::arg("cookie"), py::arg("fileFormat"), py::arg("inputFormat"), py::arg("outputFormat"), py::arg("_codecInfo"), py::arg("_acceptedInputFormat"), py::arg("_acceptedOutputFormat")); + +m.def("get_next_encoder", py::overload_cast(&get_next_encoder), + R"ipc_Qu8mg5v7( + /*! \brief Iterate over the all the available encoders without media_format +restrictions. +\param cookie A pointer to a preallocated cookie, which you need +to initialize to \c 0 before calling this function +the first time. +\param _codecInfo Pointer to a preallocated media_codec_info structure, +information about the encoder is placed there. +\return +- \c B_OK: Everything went fine. +- \c B_BAD_INDEX: There are no more encoders. +*/ + )ipc_Qu8mg5v7", py::arg("cookie"), py::arg("_codecInfo")); + +m.def("does_file_accept_format", &does_file_accept_format, "", py::arg("fileFormat"), py::arg("format"), py::arg("flags")=0); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); + +} diff --git a/bindings/media/MediaNode.cpp b/bindings/media/MediaNode.cpp new file mode 100644 index 0000000..09d1416 --- /dev/null +++ b/bindings/media/MediaNode.cpp @@ -0,0 +1,140 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +std::string get_live_node_info_name(const live_node_info& self) { + return std::string(self.name); +} + +void set_live_node_info_name(live_node_info& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), B_MEDIA_NAME_LENGTH - 1); + self.name[B_MEDIA_NAME_LENGTH - 1] = '\0'; +} + +std::string get_media_output_name(const media_output& self) { + return std::string(self.name); +} + +void set_media_output_name(media_output& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), B_MEDIA_NAME_LENGTH - 1); + self.name[B_MEDIA_NAME_LENGTH - 1] = '\0'; +} + +std::string get_media_input_name(const media_input& self) { + return std::string(self.name); +} + +void set_media_input_name(media_input& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), B_MEDIA_NAME_LENGTH - 1); + self.name[B_MEDIA_NAME_LENGTH - 1] = '\0'; +} + +PYBIND11_MODULE(MediaNode, m) +{ +//m.attr("TimeSourceObject") = py::cast(TimeSourceObject); + +//m.attr("SystemTimeSourceObject") = py::cast(SystemTimeSourceObject); + +//m.attr("BMediaRosterEx") = py::cast(BMediaRosterEx); + +py::class_(m, "media_node") +.def(py::init(), "") +.def_readwrite("node", &media_node::node, "") +.def_readwrite("port", &media_node::port, "") +.def_readwrite("kind", &media_node::kind, "") +//.def_readwrite("null", &media_node::null, "") +; + +py::class_(m, "media_input") +.def(py::init(), "") +.def_readwrite("node", &media_input::node, "") +.def_readwrite("source", &media_input::source, "") +.def_readwrite("destination", &media_input::destination, "") +.def_readwrite("format", &media_input::format, "") +//.def_readwrite("name", &media_input::name, "") +.def_property("name", &get_media_input_name, &set_media_input_name, "") +; + +py::class_(m, "media_output") +.def(py::init(), "") +.def_readwrite("node", &media_output::node, "") +.def_readwrite("source", &media_output::source, "") +.def_readwrite("destination", &media_output::destination, "") +.def_readwrite("format", &media_output::format, "") +//.def_readwrite("name", &media_output::name, "") +.def_property("name", &get_media_output_name, &set_media_output_name, "") +; + +py::class_(m, "live_node_info") +.def(py::init(), "") +.def_readwrite("node", &live_node_info::node, "") +.def_readwrite("hint_point", &live_node_info::hint_point, "") +//.def_readwrite("name", &live_node_info::name, "") +.def_property("name", &get_live_node_info_name, &set_live_node_info_name, "") +; + +py::class_(m, "media_request_info") +.def_readwrite("what", &media_request_info::what, "") +.def_readwrite("change_tag", &media_request_info::change_tag, "") +.def_readwrite("status", &media_request_info::status, "") +.def_readwrite("cookie", &media_request_info::cookie, "") +.def_readwrite("user_data", &media_request_info::user_data, "") +.def_readwrite("source", &media_request_info::source, "") +.def_readwrite("destination", &media_request_info::destination, "") +.def_readwrite("format", &media_request_info::format, "") +//.def_readwrite("_reserved_", &media_request_info::_reserved_, "") +.def_property( + "_reserved_", + [](const media_request_info &info) { + py::array_t result(32); + std::memcpy(result.mutable_data(), &info._reserved_, sizeof(info._reserved_)); + return result; + }, + [](media_request_info &info, py::array_t value) { + if (value.size() != 32) { + throw std::runtime_error("Array must have size 32"); + } + std::memcpy(&info._reserved_, value.data(), sizeof(info._reserved_)); + },"") +; + +py::class_(m, "media_node_attribute") +.def_readwrite("what", &media_node_attribute::what, "") +.def_readwrite("flags", &media_node_attribute::flags, "") +.def_readwrite("data", &media_node_attribute::data, "") +; + +py::class_>(m, "BMediaNode") +.def("Acquire", &BMediaNode::Acquire, "") +.def("Release", &BMediaNode::Release, "") +.def("Name", &BMediaNode::Name, "") +.def("ID", &BMediaNode::ID, "") +.def("Kinds", &BMediaNode::Kinds, "") +.def("Node", &BMediaNode::Node, "") +.def("RunMode", &BMediaNode::RunMode, "") +.def("TimeSource", &BMediaNode::TimeSource, "") +.def("ControlPort", &BMediaNode::ControlPort, "") +.def("AddOn", &BMediaNode::AddOn, "", py::arg("internalID")) +.def("HandleMessage", &BMediaNode::HandleMessage, "", py::arg("message"), py::arg("data"), py::arg("size")) +.def("HandleBadMessage", &BMediaNode::HandleBadMessage, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +.def("AddNodeKind", &BMediaNode::AddNodeKind, "", py::arg("kind")) +//.def("operatornew", py::overload_cast(&BMediaNode::operatornew), "", py::arg("size")) +//.def("operatornew", py::overload_cast(&BMediaNode::operatornew), "", py::arg("size"), py::arg("&")) +//.def("operatordelete", py::overload_cast(&BMediaNode::operatordelete), "", py::arg("ptr")) +//.def("operatordelete", py::overload_cast(&BMediaNode::operatordelete), "", py::arg("ptr"), py::arg("&")) +.def("GetNodeAttributes", &BMediaNode::GetNodeAttributes, "", py::arg("_attributes"), py::arg("inMaxCount")) +.def("AddTimer", &BMediaNode::AddTimer, "", py::arg("atPerformanceTime"), py::arg("cookie")) +; + + +} diff --git a/bindings/media/MediaRecorder.cpp b/bindings/media/MediaRecorder.cpp new file mode 100644 index 0000000..a5fbe69 --- /dev/null +++ b/bindings/media/MediaRecorder.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +void define_MediaRecorder(py::module_& m) +{ +py::class_(m, "BMediaRecorder") +.def(py::init(), "", py::arg("name"), py::arg("type")=B_MEDIA_UNKNOWN_TYPE) +.def("InitCheck", &BMediaRecorder::InitCheck, "") +.def("SetHooks", &BMediaRecorder::SetHooks, "", py::arg("recordFunc")=NULL, py::arg("notifyFunc")=NULL, py::arg("cookie")=NULL) +.def("SetAcceptedFormat", &BMediaRecorder::SetAcceptedFormat, "", py::arg("format")) +.def("AcceptedFormat", &BMediaRecorder::AcceptedFormat, "") +.def("Start", &BMediaRecorder::Start, "", py::arg("force")=false) +.def("Stop", &BMediaRecorder::Stop, "", py::arg("force")=false) +.def("Connect", py::overload_cast(&BMediaRecorder::Connect), "", py::arg("format")) +.def("Connect", py::overload_cast(&BMediaRecorder::Connect), "", py::arg("dormantInfo"), py::arg("format")) +.def("Connect", py::overload_cast(&BMediaRecorder::Connect), "", py::arg("node"), py::arg("output")=NULL, py::arg("format")=NULL) +.def("Disconnect", &BMediaRecorder::Disconnect, "") +.def("IsConnected", &BMediaRecorder::IsConnected, "") +.def("IsRunning", &BMediaRecorder::IsRunning, "") +.def("Format", &BMediaRecorder::Format, "") +; + + +} diff --git a/bindings/media/MediaRoster.cpp b/bindings/media/MediaRoster.cpp new file mode 100644 index 0000000..a34df59 --- /dev/null +++ b/bindings/media/MediaRoster.cpp @@ -0,0 +1,115 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +void define_MediaRoster(py::module_& m) +{ +py::enum_(m, "bus_type", "//! The BMediaRoster is the main API to the Media Kit.") +.value("B_ISA_BUS", bus_type::B_ISA_BUS, "") +.value("B_PCI_BUS", bus_type::B_PCI_BUS, "") +.value("B_PCMCIA_BUS", bus_type::B_PCMCIA_BUS, "") +.value("B_UNKNOWN_BUS", bus_type::B_UNKNOWN_BUS, "") +.export_values(); + +m.attr("DefaultDeleter") = py::cast(DefaultDeleter); + +m.attr("BMediaRosterEx") = py::cast(BMediaRosterEx); + +py::class_(m, "BMediaRoster") +.def_static("Roster", &BMediaRoster::Roster, "", py::arg("_error")=NULL) +.def_static("CurrentRoster", &BMediaRoster::CurrentRoster, "") +.def_static("IsRunning", &BMediaRoster::IsRunning, "") +.def("GetVideoInput", &BMediaRoster::GetVideoInput, "", py::arg("_node")) +.def("GetAudioInput", &BMediaRoster::GetAudioInput, "", py::arg("_node")) +.def("GetVideoOutput", &BMediaRoster::GetVideoOutput, "", py::arg("_node")) +.def("GetAudioMixer", &BMediaRoster::GetAudioMixer, "", py::arg("_node")) +.def("GetAudioOutput", py::overload_cast(&BMediaRoster::GetAudioOutput), "", py::arg("_node")) +.def("GetAudioOutput", py::overload_cast(&BMediaRoster::GetAudioOutput), "", py::arg("_node"), py::arg("_inputId"), py::arg("_inputName")) +.def("GetTimeSource", &BMediaRoster::GetTimeSource, "", py::arg("_node")) +.def("SetVideoInput", py::overload_cast(&BMediaRoster::SetVideoInput), "", py::arg("producer")) +.def("SetVideoInput", py::overload_cast(&BMediaRoster::SetVideoInput), "", py::arg("producer")) +.def("SetAudioInput", py::overload_cast(&BMediaRoster::SetAudioInput), "", py::arg("producer")) +.def("SetAudioInput", py::overload_cast(&BMediaRoster::SetAudioInput), "", py::arg("producer")) +.def("SetVideoOutput", py::overload_cast(&BMediaRoster::SetVideoOutput), "", py::arg("consumer")) +.def("SetVideoOutput", py::overload_cast(&BMediaRoster::SetVideoOutput), "", py::arg("consumer")) +.def("SetAudioOutput", py::overload_cast(&BMediaRoster::SetAudioOutput), "", py::arg("consumer")) +.def("SetAudioOutput", py::overload_cast(&BMediaRoster::SetAudioOutput), "", py::arg("inputToOutput")) +.def("SetAudioOutput", py::overload_cast(&BMediaRoster::SetAudioOutput), "", py::arg("consumer")) +.def("GetNodeFor", &BMediaRoster::GetNodeFor, "", py::arg("node"), py::arg("clone")) +.def("GetSystemTimeSource", &BMediaRoster::GetSystemTimeSource, "", py::arg("clone")) +.def("ReleaseNode", &BMediaRoster::ReleaseNode, "", py::arg("node")) +.def("MakeTimeSourceFor", &BMediaRoster::MakeTimeSourceFor, "", py::arg("for_node")) +.def("Connect", py::overload_cast(&BMediaRoster::Connect), "", py::arg("from"), py::arg("to"), py::arg("_inOutFormat"), py::arg("_output"), py::arg("_input")) +.def("Connect", py::overload_cast(&BMediaRoster::Connect), "", py::arg("from"), py::arg("to"), py::arg("_inOutFormat"), py::arg("_output"), py::arg("_input"), py::arg("flags"), py::arg("_reserved")=NULL) +.def("Disconnect", py::overload_cast(&BMediaRoster::Disconnect), "", py::arg("sourceNode"), py::arg("source"), py::arg("destinationNode"), py::arg("destination")) +.def("Disconnect", py::overload_cast(&BMediaRoster::Disconnect), "", py::arg("output"), py::arg("input")) +.def("StartNode", &BMediaRoster::StartNode, "", py::arg("node"), py::arg("atPerformanceTime")) +.def("StopNode", &BMediaRoster::StopNode, "", py::arg("node"), py::arg("atPerformanceTime"), py::arg("immediate")=false) +.def("SeekNode", &BMediaRoster::SeekNode, "", py::arg("node"), py::arg("toMediaTime"), py::arg("atPerformanceTime")=0) +.def("StartTimeSource", &BMediaRoster::StartTimeSource, "", py::arg("node"), py::arg("atRealTime")) +.def("StopTimeSource", &BMediaRoster::StopTimeSource, "", py::arg("node"), py::arg("atRealTime"), py::arg("immediate")=false) +.def("SeekTimeSource", &BMediaRoster::SeekTimeSource, "", py::arg("node"), py::arg("toPerformanceTime"), py::arg("atRealTime")) +.def("SyncToNode", &BMediaRoster::SyncToNode, "", py::arg("node"), py::arg("atTime"), py::arg("timeout")=B_INFINITE_TIMEOUT) +.def("SetRunModeNode", &BMediaRoster::SetRunModeNode, "", py::arg("node"), py::arg("mode")) +.def("PrerollNode", &BMediaRoster::PrerollNode, "", py::arg("node")) +.def("RollNode", &BMediaRoster::RollNode, "", py::arg("node"), py::arg("startPerformance"), py::arg("stopPerformance"), py::arg("atMediaTime")=- B_INFINITE_TIMEOUT) +.def("SetProducerRunModeDelay", &BMediaRoster::SetProducerRunModeDelay, "", py::arg("node"), py::arg("delay"), py::arg("mode")=BMediaNode : : B_RECORDING) +.def("SetProducerRate", &BMediaRoster::SetProducerRate, "", py::arg("producer"), py::arg("numer"), py::arg("denom")) +.def("GetLiveNodeInfo", &BMediaRoster::GetLiveNodeInfo, "", py::arg("node"), py::arg("_liveInfo")) +.def("GetLiveNodes", &BMediaRoster::GetLiveNodes, "", py::arg("_liveNodes"), py::arg("inOutTotalCount"), py::arg("hasInput")=NULL, py::arg("hasOutput")=NULL, py::arg("name")=NULL, py::arg("nodeKinds")=0) +.def("GetFreeInputsFor", &BMediaRoster::GetFreeInputsFor, "", py::arg("node"), py::arg("_freeInputsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount"), py::arg("filterType")=B_MEDIA_UNKNOWN_TYPE) +.def("GetConnectedInputsFor", &BMediaRoster::GetConnectedInputsFor, "", py::arg("node"), py::arg("_activeInputsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) +.def("GetAllInputsFor", &BMediaRoster::GetAllInputsFor, "", py::arg("node"), py::arg("_inputsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) +.def("GetFreeOutputsFor", &BMediaRoster::GetFreeOutputsFor, "", py::arg("node"), py::arg("_freeOutputsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount"), py::arg("filterType")=B_MEDIA_UNKNOWN_TYPE) +.def("GetConnectedOutputsFor", &BMediaRoster::GetConnectedOutputsFor, "", py::arg("node"), py::arg("_activeOutputsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) +.def("GetAllOutputsFor", &BMediaRoster::GetAllOutputsFor, "", py::arg("node"), py::arg("_outputsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) +.def("StartWatching", py::overload_cast(&BMediaRoster::StartWatching), "", py::arg("target")) +.def("StartWatching", py::overload_cast(&BMediaRoster::StartWatching), "", py::arg("target"), py::arg("notificationType")) +.def("StartWatching", py::overload_cast(&BMediaRoster::StartWatching), "", py::arg("target"), py::arg("node"), py::arg("notificationType")) +.def("StopWatching", py::overload_cast(&BMediaRoster::StopWatching), "", py::arg("target")) +.def("StopWatching", py::overload_cast(&BMediaRoster::StopWatching), "", py::arg("target"), py::arg("notificationType")) +.def("StopWatching", py::overload_cast(&BMediaRoster::StopWatching), "", py::arg("target"), py::arg("node"), py::arg("notificationType")) +.def("RegisterNode", &BMediaRoster::RegisterNode, "", py::arg("node")) +.def("UnregisterNode", &BMediaRoster::UnregisterNode, "", py::arg("node")) +.def("SetTimeSourceFor", &BMediaRoster::SetTimeSourceFor, "", py::arg("node"), py::arg("timeSource")) +.def("GetParameterWebFor", &BMediaRoster::GetParameterWebFor, "", py::arg("node"), py::arg("_web")) +.def("StartControlPanel", &BMediaRoster::StartControlPanel, "", py::arg("node"), py::arg("_messenger")=NULL) +.def("GetDormantNodes", &BMediaRoster::GetDormantNodes, "", py::arg("_info"), py::arg("_inOutCount"), py::arg("_hasInput")=NULL, py::arg("_hasOutput")=NULL, py::arg("name")=NULL, py::arg("requireKinds")=0, py::arg("denyKinds")=0) +.def("InstantiateDormantNode", py::overload_cast(&BMediaRoster::InstantiateDormantNode), "", py::arg("info"), py::arg("_node"), py::arg("flags")) +.def("InstantiateDormantNode", py::overload_cast(&BMediaRoster::InstantiateDormantNode), "", py::arg("info"), py::arg("_node")) +.def("GetDormantNodeFor", &BMediaRoster::GetDormantNodeFor, "", py::arg("node"), py::arg("_info")) +.def("GetDormantFlavorInfoFor", &BMediaRoster::GetDormantFlavorInfoFor, "", py::arg("info"), py::arg("_flavor")) +.def("GetLatencyFor", &BMediaRoster::GetLatencyFor, "", py::arg("producer"), py::arg("_latency")) +.def("GetInitialLatencyFor", &BMediaRoster::GetInitialLatencyFor, "", py::arg("producer"), py::arg("_latency"), py::arg("_flags")=NULL) +.def("GetStartLatencyFor", &BMediaRoster::GetStartLatencyFor, "", py::arg("timeSource"), py::arg("_latency")) +.def("GetFileFormatsFor", &BMediaRoster::GetFileFormatsFor, "", py::arg("fileInterface"), py::arg("_formatsBuffer"), py::arg("_inOutNumInfos")) +.def("SetRefFor", &BMediaRoster::SetRefFor, "", py::arg("fileInterface"), py::arg("file"), py::arg("createAndTruncate"), py::arg("_length")) +.def("GetRefFor", &BMediaRoster::GetRefFor, "", py::arg("node"), py::arg("_ref"), py::arg("mimeType")=NULL) +.def("SniffRefFor", &BMediaRoster::SniffRefFor, "", py::arg("fileInterface"), py::arg("ref"), py::arg("_mimeType"), py::arg("_capability")) +.def("SniffRef", &BMediaRoster::SniffRef, "", py::arg("ref"), py::arg("requireNodeKinds"), py::arg("_node"), py::arg("_mimeType")=NULL) +.def("GetDormantNodeForType", &BMediaRoster::GetDormantNodeForType, "", py::arg("type"), py::arg("requireNodeKinds"), py::arg("_info")) +.def("GetReadFileFormatsFor", &BMediaRoster::GetReadFileFormatsFor, "", py::arg("node"), py::arg("_readFormatsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) +.def("GetWriteFileFormatsFor", &BMediaRoster::GetWriteFileFormatsFor, "", py::arg("node"), py::arg("_writeFormatsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) +.def("GetFormatFor", py::overload_cast(&BMediaRoster::GetFormatFor), "", py::arg("output"), py::arg("_inOutFormat"), py::arg("flags")=0) +.def("GetFormatFor", py::overload_cast(&BMediaRoster::GetFormatFor), "", py::arg("input"), py::arg("_inOutFormat"), py::arg("flags")=0) +.def("GetFormatFor", py::overload_cast(&BMediaRoster::GetFormatFor), "", py::arg("node"), py::arg("_inOutFormat"), py::arg("quality")=B_MEDIA_ANY_QUALITY) +.def("GetNodeAttributesFor", &BMediaRoster::GetNodeAttributesFor, "", py::arg("node"), py::arg("outArray"), py::arg("inMaxCount")) +.def("NodeIDFor", &BMediaRoster::NodeIDFor, "", py::arg("sourceOrDestinationPort")) +.def("GetInstancesFor", &BMediaRoster::GetInstancesFor, "", py::arg("addon"), py::arg("flavor"), py::arg("_id"), py::arg("_inOutCount")=NULL) +.def("AudioBufferSizeFor", &BMediaRoster::AudioBufferSizeFor, "", py::arg("channelCount"), py::arg("sampleFormat"), py::arg("frameRate"), py::arg("busType")=B_UNKNOWN_BUS) +.def_static("MediaFlags", &BMediaRoster::MediaFlags, "", py::arg("cap"), py::arg("buffer"), py::arg("maxSize")) +.def("MessageReceived", &BMediaRoster::MessageReceived, "", py::arg("message")) +.def("QuitRequested", &BMediaRoster::QuitRequested, "") +.def("ResolveSpecifier", &BMediaRoster::ResolveSpecifier, "", py::arg("message"), py::arg("index"), py::arg("specifier"), py::arg("form"), py::arg("property")) +.def("GetSupportedSuites", &BMediaRoster::GetSupportedSuites, "", py::arg("data")) +; + + +} diff --git a/bindings/media/MediaTheme.cpp b/bindings/media/MediaTheme.cpp new file mode 100644 index 0000000..f036ab0 --- /dev/null +++ b/bindings/media/MediaTheme.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +void define_MediaTheme(py::module_& m) +{ +py::class_(m, "BMediaTheme") +.def("Name", &BMediaTheme::Name, "") +.def("Info", &BMediaTheme::Info, "") +.def("ID", &BMediaTheme::ID, "") +.def("GetRef", &BMediaTheme::GetRef, "", py::arg("ref")) +.def_static("ViewFor", &BMediaTheme::ViewFor, "", py::arg("web"), py::arg("hintRect")=NULL, py::arg("usingTheme")=NULL) +.def_static("SetPreferredTheme", &BMediaTheme::SetPreferredTheme, "", py::arg("defaultTheme")=NULL) +.def_static("PreferredTheme", &BMediaTheme::PreferredTheme, "") +.def("MakeControlFor", &BMediaTheme::MakeControlFor, "", py::arg("control")) +.def("BackgroundBitmapFor", &BMediaTheme::BackgroundBitmapFor, "", py::arg("bg")=B_GENERAL_BG) +.def("BackgroundColorFor", &BMediaTheme::BackgroundColorFor, "", py::arg("bg")=B_GENERAL_BG) +.def("ForegroundColorFor", &BMediaTheme::ForegroundColorFor, "", py::arg("fg")=B_GENERAL_FG) +; + +m.def("make_theme", &make_theme, "", py::arg("id"), py::arg("you")); + +m.def("get_theme_at", &get_theme_at, "", py::arg("index"), py::arg("_name"), py::arg("_info"), py::arg("_id")); + +} diff --git a/bindings/media/MediaTrack.cpp b/bindings/media/MediaTrack.cpp new file mode 100644 index 0000000..47dce3b --- /dev/null +++ b/bindings/media/MediaTrack.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +void define_MediaTrack(py::module_& m) +{ +py::enum_(m, "media_seek_type", "") +.value("B_MEDIA_SEEK_CLOSEST_FORWARD", media_seek_type::B_MEDIA_SEEK_CLOSEST_FORWARD, "") +.value("B_MEDIA_SEEK_CLOSEST_BACKWARD", media_seek_type::B_MEDIA_SEEK_CLOSEST_BACKWARD, "") +.value("B_MEDIA_SEEK_DIRECTION_MASK", media_seek_type::B_MEDIA_SEEK_DIRECTION_MASK, "") +.export_values(); + +m.attr("Decoder") = py::cast(Decoder); + +m.attr("Encoder") = py::cast(Encoder); + +m.attr("MediaExtractor") = py::cast(MediaExtractor); + +m.attr("MediaWriter") = py::cast(MediaWriter); + +py::class_(m, "BMediaTrack") +.def("InitCheck", &BMediaTrack::InitCheck, "") +.def("GetCodecInfo", &BMediaTrack::GetCodecInfo, "", py::arg("_codecInfo")) +.def("EncodedFormat", &BMediaTrack::EncodedFormat, "", py::arg("_format")) +.def("DecodedFormat", &BMediaTrack::DecodedFormat, "", py::arg("_format"), py::arg("flags")=0) +.def("CountFrames", &BMediaTrack::CountFrames, "") +.def("Duration", &BMediaTrack::Duration, "") +.def("GetMetaData", &BMediaTrack::GetMetaData, "", py::arg("_data")) +.def("CurrentFrame", &BMediaTrack::CurrentFrame, "") +.def("CurrentTime", &BMediaTrack::CurrentTime, "") +.def("ReadFrames", py::overload_cast(&BMediaTrack::ReadFrames), "", py::arg("buffer"), py::arg("_frameCount"), py::arg("header")=NULL) +.def("ReadFrames", py::overload_cast(&BMediaTrack::ReadFrames), "", py::arg("buffer"), py::arg("_frameCount"), py::arg("header"), py::arg("info")) +.def("ReplaceFrames", &BMediaTrack::ReplaceFrames, "", py::arg("buffer"), py::arg("_frameCount"), py::arg("header")) +.def("SeekToTime", &BMediaTrack::SeekToTime, "", py::arg("_time"), py::arg("flags")=0) +.def("SeekToFrame", &BMediaTrack::SeekToFrame, "", py::arg("_frame"), py::arg("flags")=0) +.def("FindKeyFrameForTime", &BMediaTrack::FindKeyFrameForTime, "", py::arg("_time"), py::arg("flags")=0) +.def("FindKeyFrameForFrame", &BMediaTrack::FindKeyFrameForFrame, "", py::arg("_frame"), py::arg("flags")=0) +.def("ReadChunk", &BMediaTrack::ReadChunk, "", py::arg("_buffer"), py::arg("_size"), py::arg("_header")=NULL) +.def("AddCopyright", &BMediaTrack::AddCopyright, "", py::arg("copyright")) +.def("AddTrackInfo", &BMediaTrack::AddTrackInfo, "", py::arg("code"), py::arg("data"), py::arg("size"), py::arg("flags")=0) +.def("WriteFrames", py::overload_cast(&BMediaTrack::WriteFrames), "", py::arg("data"), py::arg("frameCount"), py::arg("flags")=0) +.def("WriteFrames", py::overload_cast(&BMediaTrack::WriteFrames), "", py::arg("data"), py::arg("frameCount"), py::arg("info")) +.def("WriteChunk", py::overload_cast(&BMediaTrack::WriteChunk), "", py::arg("data"), py::arg("size"), py::arg("flags")=0) +.def("WriteChunk", py::overload_cast(&BMediaTrack::WriteChunk), "", py::arg("data"), py::arg("size"), py::arg("info")) +.def("Flush", &BMediaTrack::Flush, "") +.def("GetParameterWeb", &BMediaTrack::GetParameterWeb, "", py::arg("_web")) +.def("GetParameterValue", &BMediaTrack::GetParameterValue, "", py::arg("id"), py::arg("value"), py::arg("size")) +.def("SetParameterValue", &BMediaTrack::SetParameterValue, "", py::arg("id"), py::arg("value"), py::arg("size")) +.def("GetParameterView", &BMediaTrack::GetParameterView, "") +.def("GetQuality", &BMediaTrack::GetQuality, "", py::arg("_quality")) +.def("SetQuality", &BMediaTrack::SetQuality, "", py::arg("quality")) +.def("GetEncodeParameters", &BMediaTrack::GetEncodeParameters, "", py::arg("parameters")) +.def("SetEncodeParameters", &BMediaTrack::SetEncodeParameters, "", py::arg("parameters")) +.def("Perform", &BMediaTrack::Perform, "", py::arg("code"), py::arg("data")) +; + + +} diff --git a/bindings/media/ParameterWeb.cpp b/bindings/media/ParameterWeb.cpp new file mode 100644 index 0000000..7e84227 --- /dev/null +++ b/bindings/media/ParameterWeb.cpp @@ -0,0 +1,202 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +void define_ParameterWeb(py::module_& m) +{ +py::enum_(m, "media_parameter_flags", "") +.value("B_HIDDEN_PARAMETER", media_parameter_flags::B_HIDDEN_PARAMETER, "") +.value("B_ADVANCED_PARAMETER", media_parameter_flags::B_ADVANCED_PARAMETER, "") +.export_values(); + +m.attr("B_GENERIC") = py::cast(B_GENERIC); + +m.attr("B_MASTER_GAIN") = py::cast(B_MASTER_GAIN); + +m.attr("B_GAIN") = py::cast(B_GAIN); + +m.attr("B_BALANCE") = py::cast(B_BALANCE); + +m.attr("B_FREQUENCY") = py::cast(B_FREQUENCY); + +m.attr("B_LEVEL") = py::cast(B_LEVEL); + +m.attr("B_SHUTTLE_SPEED") = py::cast(B_SHUTTLE_SPEED); + +m.attr("B_CROSSFADE") = py::cast(B_CROSSFADE); + +m.attr("B_EQUALIZATION") = py::cast(B_EQUALIZATION); + +m.attr("B_COMPRESSION") = py::cast(B_COMPRESSION); + +m.attr("B_QUALITY") = py::cast(B_QUALITY); + +m.attr("B_BITRATE") = py::cast(B_BITRATE); + +m.attr("B_GOP_SIZE") = py::cast(B_GOP_SIZE); + +m.attr("B_MUTE") = py::cast(B_MUTE); + +m.attr("B_ENABLE") = py::cast(B_ENABLE); + +m.attr("B_INPUT_MUX") = py::cast(B_INPUT_MUX); + +m.attr("B_OUTPUT_MUX") = py::cast(B_OUTPUT_MUX); + +m.attr("B_TUNER_CHANNEL") = py::cast(B_TUNER_CHANNEL); + +m.attr("B_TRACK") = py::cast(B_TRACK); + +m.attr("B_RECSTATE") = py::cast(B_RECSTATE); + +m.attr("B_SHUTTLE_MODE") = py::cast(B_SHUTTLE_MODE); + +m.attr("B_RESOLUTION") = py::cast(B_RESOLUTION); + +m.attr("B_COLOR_SPACE") = py::cast(B_COLOR_SPACE); + +m.attr("B_FRAME_RATE") = py::cast(B_FRAME_RATE); + +m.attr("B_VIDEO_FORMAT") = py::cast(B_VIDEO_FORMAT); + +m.attr("B_WEB_PHYSICAL_INPUT") = py::cast(B_WEB_PHYSICAL_INPUT); + +m.attr("B_WEB_PHYSICAL_OUTPUT") = py::cast(B_WEB_PHYSICAL_OUTPUT); + +m.attr("B_WEB_ADC_CONVERTER") = py::cast(B_WEB_ADC_CONVERTER); + +m.attr("B_WEB_DAC_CONVERTER") = py::cast(B_WEB_DAC_CONVERTER); + +m.attr("B_WEB_LOGICAL_INPUT") = py::cast(B_WEB_LOGICAL_INPUT); + +m.attr("B_WEB_LOGICAL_OUTPUT") = py::cast(B_WEB_LOGICAL_OUTPUT); + +m.attr("B_WEB_LOGICAL_BUS") = py::cast(B_WEB_LOGICAL_BUS); + +m.attr("B_WEB_BUFFER_INPUT") = py::cast(B_WEB_BUFFER_INPUT); + +m.attr("B_WEB_BUFFER_OUTPUT") = py::cast(B_WEB_BUFFER_OUTPUT); + +m.attr("B_SIMPLE_TRANSPORT") = py::cast(B_SIMPLE_TRANSPORT); + +m.attr("BContinuousParameter") = py::cast(BContinuousParameter); + +py::class_(m, "BParameterWeb") +.def(py::init(), "") +.def("Node", &BParameterWeb::Node, "") +.def("MakeGroup", &BParameterWeb::MakeGroup, "", py::arg("name")) +.def("CountGroups", &BParameterWeb::CountGroups, "") +.def("GroupAt", &BParameterWeb::GroupAt, "", py::arg("index")) +.def("CountParameters", &BParameterWeb::CountParameters, "") +.def("ParameterAt", &BParameterWeb::ParameterAt, "", py::arg("index")) +.def("IsFixedSize", &BParameterWeb::IsFixedSize, "") +.def("TypeCode", &BParameterWeb::TypeCode, "") +.def("FlattenedSize", &BParameterWeb::FlattenedSize, "") +.def("Flatten", &BParameterWeb::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("AllowsTypeCode", &BParameterWeb::AllowsTypeCode, "", py::arg("code")) +.def("Unflatten", &BParameterWeb::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + +py::class_(m, "BParameterGroup") +.def("Web", &BParameterGroup::Web, "") +.def("Name", &BParameterGroup::Name, "") +.def("SetFlags", &BParameterGroup::SetFlags, "", py::arg("flags")) +.def("Flags", &BParameterGroup::Flags, "") +.def("MakeNullParameter", &BParameterGroup::MakeNullParameter, "", py::arg("id"), py::arg("type"), py::arg("name"), py::arg("kind")) +.def("MakeContinuousParameter", &BParameterGroup::MakeContinuousParameter, "", py::arg("id"), py::arg("type"), py::arg("name"), py::arg("kind"), py::arg("unit"), py::arg("min"), py::arg("max"), py::arg("step")) +.def("MakeDiscreteParameter", &BParameterGroup::MakeDiscreteParameter, "", py::arg("id"), py::arg("type"), py::arg("name"), py::arg("kind")) +.def("MakeTextParameter", &BParameterGroup::MakeTextParameter, "", py::arg("id"), py::arg("type"), py::arg("name"), py::arg("kind"), py::arg("maxBytes")) +.def("MakeGroup", &BParameterGroup::MakeGroup, "", py::arg("name")) +.def("CountParameters", &BParameterGroup::CountParameters, "") +.def("ParameterAt", &BParameterGroup::ParameterAt, "", py::arg("index")) +.def("CountGroups", &BParameterGroup::CountGroups, "") +.def("GroupAt", &BParameterGroup::GroupAt, "", py::arg("index")) +.def("IsFixedSize", &BParameterGroup::IsFixedSize, "") +.def("TypeCode", &BParameterGroup::TypeCode, "") +.def("FlattenedSize", &BParameterGroup::FlattenedSize, "") +.def("Flatten", &BParameterGroup::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("AllowsTypeCode", &BParameterGroup::AllowsTypeCode, "", py::arg("code")) +.def("Unflatten", &BParameterGroup::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + +py::class_(m, "BParameter") +.def("Type", &BParameter::Type, "") +.def("Web", &BParameter::Web, "") +.def("Group", &BParameter::Group, "") +.def("Name", &BParameter::Name, "") +.def("Kind", &BParameter::Kind, "") +.def("Unit", &BParameter::Unit, "") +.def("ID", &BParameter::ID, "") +.def("SetFlags", &BParameter::SetFlags, "", py::arg("flags")) +.def("Flags", &BParameter::Flags, "") +.def("ValueType", &BParameter::ValueType, "") +.def("GetValue", &BParameter::GetValue, "", py::arg("buffer"), py::arg("_size"), py::arg("_when")) +.def("SetValue", &BParameter::SetValue, "", py::arg("buffer"), py::arg("size"), py::arg("when")) +.def("CountChannels", &BParameter::CountChannels, "") +.def("SetChannelCount", &BParameter::SetChannelCount, "", py::arg("count")) +.def("MediaType", &BParameter::MediaType, "") +.def("SetMediaType", &BParameter::SetMediaType, "", py::arg("type")) +.def("CountInputs", &BParameter::CountInputs, "") +.def("InputAt", &BParameter::InputAt, "", py::arg("index")) +.def("AddInput", &BParameter::AddInput, "", py::arg("input")) +.def("CountOutputs", &BParameter::CountOutputs, "") +.def("OutputAt", &BParameter::OutputAt, "", py::arg("index")) +.def("AddOutput", &BParameter::AddOutput, "", py::arg("output")) +.def("IsFixedSize", &BParameter::IsFixedSize, "") +.def("TypeCode", &BParameter::TypeCode, "") +.def("FlattenedSize", &BParameter::FlattenedSize, "") +.def("Flatten", &BParameter::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("AllowsTypeCode", &BParameter::AllowsTypeCode, "", py::arg("code")) +.def("Unflatten", &BParameter::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + +py::class_(m, "BContinuousParameter") +.def("ValueType", &BContinuousParameter::ValueType, "") +.def("MinValue", &BContinuousParameter::MinValue, "") +.def("MaxValue", &BContinuousParameter::MaxValue, "") +.def("ValueStep", &BContinuousParameter::ValueStep, "") +.def("SetResponse", &BContinuousParameter::SetResponse, "", py::arg("response"), py::arg("factor"), py::arg("offset")) +.def("GetResponse", &BContinuousParameter::GetResponse, "", py::arg("_response"), py::arg("factor"), py::arg("offset")) +.def("FlattenedSize", &BContinuousParameter::FlattenedSize, "") +.def("Flatten", &BContinuousParameter::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("Unflatten", &BContinuousParameter::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + +py::class_(m, "BDiscreteParameter") +.def("ValueType", &BDiscreteParameter::ValueType, "") +.def("CountItems", &BDiscreteParameter::CountItems, "") +.def("ItemNameAt", &BDiscreteParameter::ItemNameAt, "", py::arg("index")) +.def("ItemValueAt", &BDiscreteParameter::ItemValueAt, "", py::arg("index")) +.def("AddItem", &BDiscreteParameter::AddItem, "", py::arg("value"), py::arg("name")) +.def("MakeItemsFromInputs", &BDiscreteParameter::MakeItemsFromInputs, "") +.def("MakeItemsFromOutputs", &BDiscreteParameter::MakeItemsFromOutputs, "") +.def("MakeEmpty", &BDiscreteParameter::MakeEmpty, "") +.def("FlattenedSize", &BDiscreteParameter::FlattenedSize, "") +.def("Flatten", &BDiscreteParameter::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("Unflatten", &BDiscreteParameter::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + +py::class_(m, "BTextParameter") +.def("ValueType", &BTextParameter::ValueType, "") +.def("MaxBytes", &BTextParameter::MaxBytes, "") +.def("FlattenedSize", &BTextParameter::FlattenedSize, "") +.def("Flatten", &BTextParameter::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("Unflatten", &BTextParameter::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + +py::class_(m, "BNullParameter") +.def("ValueType", &BNullParameter::ValueType, "") +.def("FlattenedSize", &BNullParameter::FlattenedSize, "") +.def("Flatten", &BNullParameter::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("Unflatten", &BNullParameter::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + + +} diff --git a/bindings/media/PlaySound.cpp b/bindings/media/PlaySound.cpp new file mode 100644 index 0000000..f047e41 --- /dev/null +++ b/bindings/media/PlaySound.cpp @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +void define_PlaySound(py::module_& m) +{ +m.def("play_sound", &play_sound, "", py::arg("soundRef"), py::arg("mix"), py::arg("queue"), py::arg("background")); + +m.def("stop_sound", &stop_sound, "", py::arg("handle")); + +m.def("wait_for_sound", &wait_for_sound, "", py::arg("handle")); + +} diff --git a/bindings/media/Sound.cpp b/bindings/media/Sound.cpp new file mode 100644 index 0000000..7a0145e --- /dev/null +++ b/bindings/media/Sound.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; + +void define_Sound(py::module_& m) +{ +m.attr("BTrackReader") = py::cast(BTrackReader); + +py::class_(m, "BSound") +.def(py::init(), "", py::arg("data"), py::arg("size"), py::arg("format"), py::arg("freeWhenDone")=false) +.def(py::init(), "", py::arg("soundFile"), py::arg("loadIntoMemory")=false) +.def("InitCheck", &BSound::InitCheck, "") +.def("AcquireRef", &BSound::AcquireRef, "") +.def("ReleaseRef", &BSound::ReleaseRef, "") +.def("RefCount", &BSound::RefCount, "") +.def("Duration", &BSound::Duration, "") +.def("Format", &BSound::Format, "") +.def("Data", &BSound::Data, "") +.def("Size", &BSound::Size, "") +.def("GetDataAt", &BSound::GetDataAt, "", py::arg("offset"), py::arg("intoBuffer"), py::arg("bufferSize"), py::arg("outUsed")) +.def("BindTo", &BSound::BindTo, "", py::arg("player"), py::arg("format")) +.def("UnbindFrom", &BSound::UnbindFrom, "", py::arg("player")) +; + + +} diff --git a/bindings/media/SoundFile.cpp b/bindings/media/SoundFile.cpp new file mode 100644 index 0000000..6806f6a --- /dev/null +++ b/bindings/media/SoundFile.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; + +void define_SoundFile(py::module_& m) +{ +m.attr("B_UNKNOWN_FILE") = py::cast(B_UNKNOWN_FILE); +m.attr("B_AIFF_FILE") = py::cast(B_AIFF_FILE); +m.attr("B_WAVE_FILE") = py::cast(B_WAVE_FILE); +m.attr("B_UNIX_FILE") = py::cast(B_UNIX_FILE); + +py::class_(m, "BSoundFile") +.def(py::init(), "") +.def(py::init(), "", py::arg("ref"), py::arg("openMode")) +.def("InitCheck", &BSoundFile::InitCheck, "") +.def("SetTo", &BSoundFile::SetTo, "", py::arg("ref"), py::arg("openMode")) +.def("FileFormat", &BSoundFile::FileFormat, "") +.def("SamplingRate", &BSoundFile::SamplingRate, "") +.def("CountChannels", &BSoundFile::CountChannels, "") +.def("SampleSize", &BSoundFile::SampleSize, "") +.def("ByteOrder", &BSoundFile::ByteOrder, "") +.def("SampleFormat", &BSoundFile::SampleFormat, "") +.def("FrameSize", &BSoundFile::FrameSize, "") +.def("CountFrames", &BSoundFile::CountFrames, "") +.def("IsCompressed", &BSoundFile::IsCompressed, "") +.def("CompressionType", &BSoundFile::CompressionType, "") +.def("CompressionName", &BSoundFile::CompressionName, "") +.def("SetFileFormat", &BSoundFile::SetFileFormat, "", py::arg("format")) +.def("SetSamplingRate", &BSoundFile::SetSamplingRate, "", py::arg("fps")) +.def("SetChannelCount", &BSoundFile::SetChannelCount, "", py::arg("samplesPerFrame")) +.def("SetSampleSize", &BSoundFile::SetSampleSize, "", py::arg("bytesPerSample")) +.def("SetByteOrder", &BSoundFile::SetByteOrder, "", py::arg("byteOrder")) +.def("SetSampleFormat", &BSoundFile::SetSampleFormat, "", py::arg("format")) +.def("SetCompressionType", &BSoundFile::SetCompressionType, "", py::arg("type")) +.def("SetCompressionName", &BSoundFile::SetCompressionName, "", py::arg("name")) +.def("SetIsCompressed", &BSoundFile::SetIsCompressed, "", py::arg("compressed")) +.def("SetDataLocation", &BSoundFile::SetDataLocation, "", py::arg("offset")) +.def("SetFrameCount", &BSoundFile::SetFrameCount, "", py::arg("count")) +.def("ReadFrames", &BSoundFile::ReadFrames, "", py::arg("buffer"), py::arg("count")) +.def("WriteFrames", &BSoundFile::WriteFrames, "", py::arg("buffer"), py::arg("count")) +.def("SeekToFrame", &BSoundFile::SeekToFrame, "", py::arg("index")) +.def("FrameIndex", &BSoundFile::FrameIndex, "") +.def("FramesRemaining", &BSoundFile::FramesRemaining, "") +.def_readwrite("fSoundFile", &BSoundFile::fSoundFile, "") +; + + +} diff --git a/bindings/media/SoundPlayer.cpp b/bindings/media/SoundPlayer.cpp new file mode 100644 index 0000000..b91a2e5 --- /dev/null +++ b/bindings/media/SoundPlayer.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; + +void define_SoundPlayer(py::module_& m) +{ +m.attr("SoundPlayNode") = py::cast(SoundPlayNode); + +py::class_(m, "sound_error") +.def(py::init(), "", py::arg("string")) +.def("what", &sound_error::what, "") +; + +py::class_(m, "BSoundPlayer") +.def(py::init(), "", py::arg("name")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL) +.def(py::init(), "", py::arg("format"), py::arg("name")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL) +.def(py::init(), "", py::arg("toNode"), py::arg("format")=NULL, py::arg("name")=NULL, py::arg("input")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL) +.def("InitCheck", &BSoundPlayer::InitCheck, "") +.def("Format", &BSoundPlayer::Format, "") +.def("Start", &BSoundPlayer::Start, "") +.def("Stop", &BSoundPlayer::Stop, "", py::arg("block")=true, py::arg("flush")=true) +.def("BufferPlayer", &BSoundPlayer::BufferPlayer, "") +.def("SetBufferPlayer", &BSoundPlayer::SetBufferPlayer, "", py::arg("")) +.def("EventNotifier", &BSoundPlayer::EventNotifier, "") +.def("SetNotifier", &BSoundPlayer::SetNotifier, "", py::arg("eventNotifierFunction")) +.def("Cookie", &BSoundPlayer::Cookie, "") +.def("SetCookie", &BSoundPlayer::SetCookie, "", py::arg("cookie")) +.def("SetCallbacks", &BSoundPlayer::SetCallbacks, "", py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL) +.def("CurrentTime", &BSoundPlayer::CurrentTime, "") +.def("PerformanceTime", &BSoundPlayer::PerformanceTime, "") +.def("Preroll", &BSoundPlayer::Preroll, "") +.def("StartPlaying", py::overload_cast(&BSoundPlayer::StartPlaying), "", py::arg("sound"), py::arg("atTime")=0) +.def("StartPlaying", py::overload_cast(&BSoundPlayer::StartPlaying), "", py::arg("sound"), py::arg("atTime"), py::arg("withVolume")) +.def("SetSoundVolume", &BSoundPlayer::SetSoundVolume, "", py::arg("sound"), py::arg("newVolume")) +.def("IsPlaying", &BSoundPlayer::IsPlaying, "", py::arg("id")) +.def("StopPlaying", &BSoundPlayer::StopPlaying, "", py::arg("id")) +.def("WaitForSound", &BSoundPlayer::WaitForSound, "", py::arg("id")) +.def("Volume", &BSoundPlayer::Volume, "") +.def("SetVolume", &BSoundPlayer::SetVolume, "", py::arg("volume")) +.def("VolumeDB", &BSoundPlayer::VolumeDB, "", py::arg("forcePoll")=false) +.def("SetVolumeDB", &BSoundPlayer::SetVolumeDB, "", py::arg("dB")) +.def("GetVolumeInfo", &BSoundPlayer::GetVolumeInfo, "", py::arg("_node"), py::arg("_parameterID"), py::arg("_minDB"), py::arg("_maxDB")) +.def("Latency", &BSoundPlayer::Latency, "") +.def("HasData", &BSoundPlayer::HasData, "") +.def("SetHasData", &BSoundPlayer::SetHasData, "", py::arg("hasData")) +; + +py::class_(m, "playing_sound") +.def_readwrite("next", &playing_sound::next, "") +.def_readwrite("current_offset", &playing_sound::current_offset, "") +.def_readwrite("sound", &playing_sound::sound, "") +.def_readwrite("id", &playing_sound::id, "") +.def_readwrite("delta", &playing_sound::delta, "") +.def_readwrite("rate", &playing_sound::rate, "") +.def_readwrite("wait_sem", &playing_sound::wait_sem, "") +.def_readwrite("volume", &playing_sound::volume, "") +; + +py::class_(m, "waiting_sound") +.def_readwrite("next", &waiting_sound::next, "") +.def_readwrite("start_time", &waiting_sound::start_time, "") +.def_readwrite("sound", &waiting_sound::sound, "") +.def_readwrite("id", &waiting_sound::id, "") +.def_readwrite("rate", &waiting_sound::rate, "") +.def_readwrite("volume", &waiting_sound::volume, "") +; + + +} diff --git a/bindings/media/TimeCode.cpp b/bindings/media/TimeCode.cpp new file mode 100644 index 0000000..a2f9a40 --- /dev/null +++ b/bindings/media/TimeCode.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_TimeCode(py::module_& m) +{ +py::enum_(m, "timecode_type", "") +.value("B_TIMECODE_DEFAULT", timecode_type::B_TIMECODE_DEFAULT, "") +.value("B_TIMECODE_100", timecode_type::B_TIMECODE_100, "") +.value("B_TIMECODE_75", timecode_type::B_TIMECODE_75, "") +.value("B_TIMECODE_30", timecode_type::B_TIMECODE_30, "") +.value("B_TIMECODE_30_DROP_2", timecode_type::B_TIMECODE_30_DROP_2, "") +.value("B_TIMECODE_30_DROP_4", timecode_type::B_TIMECODE_30_DROP_4, "") +.value("B_TIMECODE_25", timecode_type::B_TIMECODE_25, "") +.value("B_TIMECODE_24", timecode_type::B_TIMECODE_24, "") +.value("B_TIMECODE_18", timecode_type::B_TIMECODE_18, "") +.export_values(); + +py::class_(m, "timecode_info") +.def_readwrite("type", &timecode_info::type, "") +.def_readwrite("drop_frames", &timecode_info::drop_frames, "") +.def_readwrite("every_nth", &timecode_info::every_nth, "") +.def_readwrite("except_nth", &timecode_info::except_nth, "") +.def_readwrite("fps_div", &timecode_info::fps_div, "") +.def_readwrite("name", &timecode_info::name, "") +.def_readwrite("format", &timecode_info::format, "") +.def_readwrite("_reserved_", &timecode_info::_reserved_, "") +; + +py::class_(m, "BTimeCode") +.def(py::init(), "") +.def(py::init(), "", py::arg("microSeconds"), py::arg("type")=B_TIMECODE_DEFAULT) +.def(py::init(), "", py::arg("other")) +.def(py::init(), "", py::arg("hours"), py::arg("minutes"), py::arg("seconds"), py::arg("frames"), py::arg("type")=B_TIMECODE_DEFAULT) +.def("SetData", &BTimeCode::SetData, "", py::arg("hours"), py::arg("minutes"), py::arg("seconds"), py::arg("frames")) +.def("SetType", &BTimeCode::SetType, "", py::arg("type")) +.def("SetMicroseconds", &BTimeCode::SetMicroseconds, "", py::arg("microSeconds")) +.def("SetLinearFrames", &BTimeCode::SetLinearFrames, "", py::arg("linearFrames")) +.def("operator=", &BTimeCode::operator=, "", py::arg("other")) +.def("__eq__", &BTimeCode::operator==, "", py::arg("other")) +.def("__lt__", &BTimeCode::operator<, "", py::arg("other")) +.def("__iadd__", &BTimeCode::operator+=, "", py::arg("other")) +.def("__isub__", &BTimeCode::operator-=, "", py::arg("other")) +.def("__add__", &BTimeCode::operator+, "", py::arg("other")) +.def("operator-", &BTimeCode::operator-, "", py::arg("other")) +.def("Hours", &BTimeCode::Hours, "") +.def("Minutes", &BTimeCode::Minutes, "") +.def("Seconds", &BTimeCode::Seconds, "") +.def("Frames", &BTimeCode::Frames, "") +.def("Type", &BTimeCode::Type, "") +.def("GetData", &BTimeCode::GetData, "", py::arg("_hours"), py::arg("_minutes"), py::arg("_seconds"), py::arg("_frames"), py::arg("_type")=NULL) +.def("Microseconds", &BTimeCode::Microseconds, "") +.def("LinearFrames", &BTimeCode::LinearFrames, "") +.def("GetString", &BTimeCode::GetString, "", py::arg("string")) +; + +m.def("us_to_timecode", &us_to_timecode, "", py::arg("micros"), py::arg("hours"), py::arg("minutes"), py::arg("seconds"), py::arg("frames"), py::arg("code")=NULL); + +m.def("timecode_to_us", &timecode_to_us, "", py::arg("hours"), py::arg("minutes"), py::arg("seconds"), py::arg("frames"), py::arg("micros"), py::arg("code")=NULL); + +m.def("frames_to_timecode", &frames_to_timecode, "", py::arg("l_frames"), py::arg("hours"), py::arg("minutes"), py::arg("seconds"), py::arg("frames"), py::arg("code")=NULL); + +m.def("timecode_to_frames", &timecode_to_frames, "", py::arg("hours"), py::arg("minutes"), py::arg("seconds"), py::arg("frames"), py::arg("lFrames"), py::arg("code")=NULL); + +m.def("get_timecode_description", &get_timecode_description, "", py::arg("type"), py::arg("_timecode")); + +m.def("count_timecodes", &count_timecodes, ""); + +} diff --git a/bindings/media/TimeSource.cpp b/bindings/media/TimeSource.cpp new file mode 100644 index 0000000..09e33aa --- /dev/null +++ b/bindings/media/TimeSource.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +PYBIND11_MODULE(TimeSource, m) +{ +//m.attr("BMediaRosterEx") = py::cast(BMediaRosterEx); + +//m.attr("TimeSourceObject") = py::cast(TimeSourceObject); + +//m.attr("SystemTimeSourceObject") = py::cast(SystemTimeSourceObject); + +//m.attr("SlaveNodes") = py::cast(SlaveNodes); + +//m.attr("TimeSourceTransmit") = py::cast(TimeSourceTransmit); + +py::class_>(m, "BTimeSource") +.def("SnoozeUntil", &BTimeSource::SnoozeUntil, "", py::arg("performanceTime"), py::arg("withLatency")=0, py::arg("retrySignals")=false) +.def("Now", &BTimeSource::Now, "") +.def("PerformanceTimeFor", &BTimeSource::PerformanceTimeFor, "", py::arg("realTime")) +.def("RealTimeFor", &BTimeSource::RealTimeFor, "", py::arg("performanceTime"), py::arg("withLatency")) +.def("IsRunning", &BTimeSource::IsRunning, "") +.def("GetTime", &BTimeSource::GetTime, "", py::arg("_performanceTime"), py::arg("_realTime"), py::arg("_drift")) +.def("GetStartLatency", &BTimeSource::GetStartLatency, "", py::arg("_latency")) +.def_static("RealTime", &BTimeSource::RealTime, "") +; +/* +py::class_(m, "time_source_op_info") +.def_readwrite("op", &time_source_op_info::op, "") +.def_readwrite("_reserved1", &time_source_op_info::_reserved1, "") +.def_readwrite("real_time", &time_source_op_info::real_time, "") +.def_readwrite("performance_time", &time_source_op_info::performance_time, "") +//.def_readwrite("_reserved2", &time_source_op_info::_reserved2, "") +.def_property( + "_reserved2", + [](const time_source_op_info &info) { + py::array_t result(6); + std::memcpy(result.mutable_data(), &info._reserved_, sizeof(info._reserved_)); + return result; + }, + [](time_source_op_info &info, py::array_t value) { + if (value.size() != 6) { + throw std::runtime_error("Array must have size 6"); + } + std::memcpy(&info._reserved_, value.data(), sizeof(info._reserved_)); + }, "") +;*/ + + +} diff --git a/bindings/media/TimedEventQueue.cpp b/bindings/media/TimedEventQueue.cpp new file mode 100644 index 0000000..91abaa7 --- /dev/null +++ b/bindings/media/TimedEventQueue.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_TimedEventQueue(py::module_& m) +{ +py::class_(m, "media_timed_event") +.def(py::init(), "") +.def(py::init(), "", py::arg("inTime"), py::arg("inType")) +.def(py::init(), "", py::arg("inTime"), py::arg("inType"), py::arg("inPointer"), py::arg("inCleanup")) +.def(py::init(), "", py::arg("inTime"), py::arg("inType"), py::arg("inPointer"), py::arg("inCleanup"), py::arg("inData"), py::arg("inBigdata"), py::arg("inUserData"), py::arg("dataSize")=0) +.def(py::init(), "", py::arg("other")) +.def("operator=", &media_timed_event::operator=, "", py::arg("other")) +.def_readwrite("event_time", &media_timed_event::event_time, "") +.def_readwrite("type", &media_timed_event::type, "") +.def_readwrite("pointer", &media_timed_event::pointer, "") +.def_readwrite("cleanup", &media_timed_event::cleanup, "") +.def_readwrite("data", &media_timed_event::data, "") +.def_readwrite("bigdata", &media_timed_event::bigdata, "") +.def_readwrite("user_data", &media_timed_event::user_data, "") +.def_readwrite("_reserved_media_timed_event_", &media_timed_event::_reserved_media_timed_event_, "") +; + +py::class_(m, "BTimedEventQueue") +.def("operatornew", &BTimedEventQueue::operatornew, "", py::arg("size")) +.def("operatordelete", &BTimedEventQueue::operatordelete, "", py::arg("ptr"), py::arg("size")) +.def(py::init(), "") +.def("AddEvent", &BTimedEventQueue::AddEvent, "", py::arg("event")) +.def("RemoveEvent", &BTimedEventQueue::RemoveEvent, "", py::arg("event")) +.def("RemoveFirstEvent", &BTimedEventQueue::RemoveFirstEvent, "", py::arg("_event")=NULL) +.def("HasEvents", &BTimedEventQueue::HasEvents, "") +.def("EventCount", &BTimedEventQueue::EventCount, "") +.def("FirstEvent", &BTimedEventQueue::FirstEvent, "") +.def("FirstEventTime", &BTimedEventQueue::FirstEventTime, "") +.def("LastEvent", &BTimedEventQueue::LastEvent, "") +.def("LastEventTime", &BTimedEventQueue::LastEventTime, "") +.def("FindFirstMatch", &BTimedEventQueue::FindFirstMatch, "", py::arg("eventTime"), py::arg("direction"), py::arg("inclusive")=true, py::arg("eventType")=B_ANY_EVENT) +.def("DoForEach", &BTimedEventQueue::DoForEach, "", py::arg("hook"), py::arg("context"), py::arg("eventTime")=0, py::arg("direction")=B_ALWAYS, py::arg("inclusive")=true, py::arg("eventType")=B_ANY_EVENT) +.def("SetCleanupHook", &BTimedEventQueue::SetCleanupHook, "", py::arg("hook"), py::arg("context")) +.def("FlushEvents", &BTimedEventQueue::FlushEvents, "", py::arg("eventTime"), py::arg("direction"), py::arg("inclusive")=true, py::arg("eventType")=B_ANY_EVENT) +; + +m.def("__eq__", &operator==, "", py::arg("a"), py::arg("b")); + +m.def("__ne__", &operator!=, "", py::arg("a"), py::arg("b")); + +m.def("__lt__", &operator<, "", py::arg("a"), py::arg("b")); + +m.def("__gt__", &operator>, "", py::arg("a"), py::arg("b")); + +} From 143ee3df8c9af6f3af7ac040791c183666895619 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 4 Sep 2024 22:24:31 +0200 Subject: [PATCH 058/115] update MediaEncoder --- Jamfile | 2 ++ bindings/__init__.py | 1 + bindings/media/MediaEncoder.cpp | 23 +++++++++++++++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Jamfile b/Jamfile index af5f768..44ba20e 100644 --- a/Jamfile +++ b/Jamfile @@ -334,6 +334,7 @@ local sourceFiles = MediaAddOn.cpp MediaDecoder.cpp MediaDefs.cpp + MediaEncoder.cpp ; @@ -366,6 +367,7 @@ LINKLIBS on Controllable.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaAddOn.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaDecoder.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaDefs.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaEncoder.so = $(LINKLIBS) -lmedia ; #LINKLIBS on BufferConsumer.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaNode.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimeSource.so = $(LINKLIBS) -lmedia ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 831aed8..9d3e109 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -211,6 +211,7 @@ from .MediaAddOn import * from .MediaDecoder import * from .MediaDefs import * +from .MediaEncoder import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/media/MediaEncoder.cpp b/bindings/media/MediaEncoder.cpp index 67712e9..974222a 100644 --- a/bindings/media/MediaEncoder.cpp +++ b/bindings/media/MediaEncoder.cpp @@ -9,13 +9,24 @@ namespace py = pybind11; using namespace BPrivate; using namespace BPrivate::media; -void define_MediaEncoder(py::module_& m) +class PyBMediaEncoder : public BMediaEncoder{ + public: + using BMediaEncoder::BMediaEncoder; + status_t WriteChunk(const void* buffer, size_t size, media_encode_info* info) override { + PYBIND11_OVERRIDE_PURE( status_t, BMediaEncoder, WriteChunk, buffer, size, info ); + } + status_t AddTrackInfo(uint32 code, const char* data, size_t size) override { + PYBIND11_OVERRIDE( status_t, BMediaEncoder, AddTrackInfo, code, data, size ); + } +}; + +PYBIND11_MODULE(MediaEncoder, m) { -m.attr("Encoder") = py::cast(Encoder); +//m.attr("Encoder") = py::cast(Encoder); -m.attr("EncoderPlugin") = py::cast(EncoderPlugin); +//m.attr("EncoderPlugin") = py::cast(EncoderPlugin); -py::class_(m, "BMediaEncoder") +py::class_(m, "BMediaEncoder") .def(py::init(), "") .def(py::init(), "", py::arg("outputFormat")) .def(py::init(), "", py::arg("info")) @@ -23,7 +34,7 @@ py::class_(m, "BMediaEncoder") .def("SetTo", py::overload_cast(&BMediaEncoder::SetTo), "", py::arg("outputFormat")) .def("SetTo", py::overload_cast(&BMediaEncoder::SetTo), "", py::arg("info")) .def("SetFormat", &BMediaEncoder::SetFormat, "", py::arg("inputFormat"), py::arg("outputFormat"), py::arg("fileFormat")=NULL) -.def("Encode", &BMediaEncoder::Encode, "", py::arg("buffer"), py::arg("frameCount"), py::arg("info")) +.def("Encode", &BMediaEncoder::Encode, "", py::arg("buffer"), py::arg("frameCount"), py::arg("info")) // TODO convert void to py::buffer? py::bytes?? .def("GetEncodeParameters", &BMediaEncoder::GetEncodeParameters, "", py::arg("parameters")) .def("SetEncodeParameters", &BMediaEncoder::SetEncodeParameters, "", py::arg("parameters")) ; @@ -32,7 +43,7 @@ py::class_(m, "BMediaBufferEncoder") .def(py::init(), "") .def(py::init(), "", py::arg("outputFormat")) .def(py::init(), "", py::arg("info")) -.def("EncodeToBuffer", &BMediaBufferEncoder::EncodeToBuffer, "", py::arg("outputBuffer"), py::arg("_size"), py::arg("inputBuffer"), py::arg("frameCount"), py::arg("info")) +.def("EncodeToBuffer", &BMediaBufferEncoder::EncodeToBuffer, "", py::arg("outputBuffer"), py::arg("_size"), py::arg("inputBuffer"), py::arg("frameCount"), py::arg("info")) // TODO void ; From 5066e755a354aaa12583031436788cba3f81ab77 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 5 Sep 2024 13:38:28 +0200 Subject: [PATCH 059/115] update MediaFile MediaTrack ParameterWeb --- Jamfile | 6 ++ bindings/__init__.py | 3 + bindings/media/MediaFile.cpp | 33 ++++++--- bindings/media/MediaTrack.cpp | 40 +++++++--- bindings/media/ParameterWeb.cpp | 126 ++++++++++++++++++++------------ 5 files changed, 140 insertions(+), 68 deletions(-) diff --git a/Jamfile b/Jamfile index 44ba20e..62d4450 100644 --- a/Jamfile +++ b/Jamfile @@ -335,6 +335,9 @@ local sourceFiles = MediaDecoder.cpp MediaDefs.cpp MediaEncoder.cpp + ParameterWeb.cpp + MediaTrack.cpp + MediaFile.cpp ; @@ -368,6 +371,9 @@ LINKLIBS on MediaAddOn.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaDecoder.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaDefs.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaEncoder.so = $(LINKLIBS) -lmedia ; +LINKLIBS on ParameterWeb.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaTrack.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaFile.so = $(LINKLIBS) -lmedia ; #LINKLIBS on BufferConsumer.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaNode.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimeSource.so = $(LINKLIBS) -lmedia ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 9d3e109..d793bad 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -212,6 +212,9 @@ from .MediaDecoder import * from .MediaDefs import * from .MediaEncoder import * +from .ParameterWeb import * +from .MediaTrack import * +from .MediaFile import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/media/MediaFile.cpp b/bindings/media/MediaFile.cpp index 53098bf..6f1fec6 100644 --- a/bindings/media/MediaFile.cpp +++ b/bindings/media/MediaFile.cpp @@ -4,26 +4,30 @@ #include #include +#include +#include +#include +#include namespace py = pybind11; using namespace BPrivate; -using namespace BPrivate::media; +//using namespace BPrivate::media; -void define_MediaFile(py::module_& m) +PYBIND11_MODULE(MediaFile, m) { -m.attr("B_MEDIA_FILE_REPLACE_MODE") = py::cast(B_MEDIA_FILE_REPLACE_MODE); -m.attr("B_MEDIA_FILE_NO_READ_AHEAD") = py::cast(B_MEDIA_FILE_NO_READ_AHEAD); -m.attr("B_MEDIA_FILE_UNBUFFERED") = py::cast(B_MEDIA_FILE_UNBUFFERED); -m.attr("B_MEDIA_FILE_BIG_BUFFERS") = py::cast(B_MEDIA_FILE_BIG_BUFFERS); +m.attr("B_MEDIA_FILE_REPLACE_MODE") = 0x00000001;//py::cast(B_MEDIA_FILE_REPLACE_MODE); +m.attr("B_MEDIA_FILE_NO_READ_AHEAD") = 0x00000002;//py::cast(B_MEDIA_FILE_NO_READ_AHEAD); +m.attr("B_MEDIA_FILE_UNBUFFERED") = 0x00000006;//py::cast(B_MEDIA_FILE_UNBUFFERED); +m.attr("B_MEDIA_FILE_BIG_BUFFERS") = 0x00000008;//py::cast(B_MEDIA_FILE_BIG_BUFFERS); -m.attr("MediaExtractor") = py::cast(MediaExtractor); +//m.attr("MediaExtractor") = py::cast(MediaExtractor); -m.attr("MediaStreamer") = py::cast(MediaStreamer); +//m.attr("MediaStreamer") = py::cast(MediaStreamer); -m.attr("MediaWriter") = py::cast(MediaWriter); - -m.attr("_AddonManager") = py::cast(_AddonManager); +//m.attr("MediaWriter") = py::cast(MediaWriter); +//m.attr("_AddonManager") = py::cast(_AddonManager); +//TODO gestre dati void py::class_(m, "BMediaFile") .def(py::init(), "", py::arg("ref")) .def(py::init(), "", py::arg("source")) @@ -52,7 +56,12 @@ py::class_(m, "BMediaFile") .def("AddChunk", &BMediaFile::AddChunk, "", py::arg("type"), py::arg("data"), py::arg("size")) .def("CommitHeader", &BMediaFile::CommitHeader, "") .def("CloseFile", &BMediaFile::CloseFile, "") -.def("GetParameterWeb", &BMediaFile::GetParameterWeb, "", py::arg("outWeb")) +//.def("GetParameterWeb", &BMediaFile::GetParameterWeb, "", py::arg("outWeb")) +.def("GetParameterWeb", [](BMediaFile &self) { + BParameterWeb* web = nullptr; + status_t status = self.GetParameterWeb(&web); + return std::make_tuple(status, web); + },"") .def("GetParameterValue", &BMediaFile::GetParameterValue, "", py::arg("id"), py::arg("value"), py::arg("size")) .def("SetParameterValue", &BMediaFile::SetParameterValue, "", py::arg("id"), py::arg("value"), py::arg("size")) .def("GetParameterView", &BMediaFile::GetParameterView, "") diff --git a/bindings/media/MediaTrack.cpp b/bindings/media/MediaTrack.cpp index 47dce3b..49d6737 100644 --- a/bindings/media/MediaTrack.cpp +++ b/bindings/media/MediaTrack.cpp @@ -4,12 +4,14 @@ #include #include +#include +#include namespace py = pybind11; using namespace BPrivate; -using namespace BPrivate::media; +//using namespace BPrivate::media; -void define_MediaTrack(py::module_& m) +PYBIND11_MODULE(MediaTrack, m) { py::enum_(m, "media_seek_type", "") .value("B_MEDIA_SEEK_CLOSEST_FORWARD", media_seek_type::B_MEDIA_SEEK_CLOSEST_FORWARD, "") @@ -17,15 +19,15 @@ py::enum_(m, "media_seek_type", "") .value("B_MEDIA_SEEK_DIRECTION_MASK", media_seek_type::B_MEDIA_SEEK_DIRECTION_MASK, "") .export_values(); -m.attr("Decoder") = py::cast(Decoder); +//m.attr("Decoder") = py::cast(Decoder); -m.attr("Encoder") = py::cast(Encoder); +//m.attr("Encoder") = py::cast(Encoder); -m.attr("MediaExtractor") = py::cast(MediaExtractor); +//m.attr("MediaExtractor") = py::cast(MediaExtractor); -m.attr("MediaWriter") = py::cast(MediaWriter); +//m.attr("MediaWriter") = py::cast(MediaWriter); -py::class_(m, "BMediaTrack") +py::class_>(m, "BMediaTrack") .def("InitCheck", &BMediaTrack::InitCheck, "") .def("GetCodecInfo", &BMediaTrack::GetCodecInfo, "", py::arg("_codecInfo")) .def("EncodedFormat", &BMediaTrack::EncodedFormat, "", py::arg("_format")) @@ -35,14 +37,25 @@ py::class_(m, "BMediaTrack") .def("GetMetaData", &BMediaTrack::GetMetaData, "", py::arg("_data")) .def("CurrentFrame", &BMediaTrack::CurrentFrame, "") .def("CurrentTime", &BMediaTrack::CurrentTime, "") -.def("ReadFrames", py::overload_cast(&BMediaTrack::ReadFrames), "", py::arg("buffer"), py::arg("_frameCount"), py::arg("header")=NULL) -.def("ReadFrames", py::overload_cast(&BMediaTrack::ReadFrames), "", py::arg("buffer"), py::arg("_frameCount"), py::arg("header"), py::arg("info")) +.def("ReadFrames", py::overload_cast(&BMediaTrack::ReadFrames), "", py::arg("buffer"), py::arg("_frameCount"), py::arg("header")=NULL) +.def("ReadFrames", py::overload_cast(&BMediaTrack::ReadFrames), "", py::arg("buffer"), py::arg("_frameCount"), py::arg("header"), py::arg("info")) .def("ReplaceFrames", &BMediaTrack::ReplaceFrames, "", py::arg("buffer"), py::arg("_frameCount"), py::arg("header")) .def("SeekToTime", &BMediaTrack::SeekToTime, "", py::arg("_time"), py::arg("flags")=0) .def("SeekToFrame", &BMediaTrack::SeekToFrame, "", py::arg("_frame"), py::arg("flags")=0) .def("FindKeyFrameForTime", &BMediaTrack::FindKeyFrameForTime, "", py::arg("_time"), py::arg("flags")=0) .def("FindKeyFrameForFrame", &BMediaTrack::FindKeyFrameForFrame, "", py::arg("_frame"), py::arg("flags")=0) -.def("ReadChunk", &BMediaTrack::ReadChunk, "", py::arg("_buffer"), py::arg("_size"), py::arg("_header")=NULL) +//.def("ReadChunk", &BMediaTrack::ReadChunk, "", py::arg("_buffer"), py::arg("_size"), py::arg("_header")=NULL) +.def("ReadChunk", [](BMediaTrack &self) { + char* buffer = nullptr; + int32 size = 0; + status_t status = self.ReadChunk(&buffer, &size, nullptr); + if (status == B_OK) { + return std::make_tuple(status, py::bytes(buffer, size)); + } + else { + return std::make_tuple(status, py::bytes()); + } +},"") .def("AddCopyright", &BMediaTrack::AddCopyright, "", py::arg("copyright")) .def("AddTrackInfo", &BMediaTrack::AddTrackInfo, "", py::arg("code"), py::arg("data"), py::arg("size"), py::arg("flags")=0) .def("WriteFrames", py::overload_cast(&BMediaTrack::WriteFrames), "", py::arg("data"), py::arg("frameCount"), py::arg("flags")=0) @@ -50,7 +63,12 @@ py::class_(m, "BMediaTrack") .def("WriteChunk", py::overload_cast(&BMediaTrack::WriteChunk), "", py::arg("data"), py::arg("size"), py::arg("flags")=0) .def("WriteChunk", py::overload_cast(&BMediaTrack::WriteChunk), "", py::arg("data"), py::arg("size"), py::arg("info")) .def("Flush", &BMediaTrack::Flush, "") -.def("GetParameterWeb", &BMediaTrack::GetParameterWeb, "", py::arg("_web")) +//.def("GetParameterWeb", &BMediaTrack::GetParameterWeb, "", py::arg("_web")) +.def("GetParameterWeb", [](BMediaTrack &self) { + BParameterWeb* web = nullptr; + status_t status = self.GetParameterWeb(&web); + return std::make_tuple(status, web); +},"") .def("GetParameterValue", &BMediaTrack::GetParameterValue, "", py::arg("id"), py::arg("value"), py::arg("size")) .def("SetParameterValue", &BMediaTrack::SetParameterValue, "", py::arg("id"), py::arg("value"), py::arg("size")) .def("GetParameterView", &BMediaTrack::GetParameterView, "") diff --git a/bindings/media/ParameterWeb.cpp b/bindings/media/ParameterWeb.cpp index 7e84227..4771948 100644 --- a/bindings/media/ParameterWeb.cpp +++ b/bindings/media/ParameterWeb.cpp @@ -9,86 +9,122 @@ namespace py = pybind11; using namespace BPrivate; using namespace BPrivate::media; -void define_ParameterWeb(py::module_& m) + +PYBIND11_MODULE(ParameterWeb, m) { py::enum_(m, "media_parameter_flags", "") .value("B_HIDDEN_PARAMETER", media_parameter_flags::B_HIDDEN_PARAMETER, "") .value("B_ADVANCED_PARAMETER", media_parameter_flags::B_ADVANCED_PARAMETER, "") .export_values(); +/*from ParameterWeb.cpp media kit source +const char * const B_GENERIC = ""; +const char * const B_MASTER_GAIN = "Master"; +const char * const B_GAIN = "Gain"; +const char * const B_BALANCE = "Balance"; +const char * const B_FREQUENCY = "Frequency"; +const char * const B_LEVEL = "Level"; +const char * const B_SHUTTLE_SPEED = "Speed"; +const char * const B_CROSSFADE = "XFade"; +const char * const B_EQUALIZATION = "EQ"; +const char * const B_COMPRESSION = "Compression"; +const char * const B_QUALITY = "Quality"; +const char * const B_BITRATE = "Bitrate"; +const char * const B_GOP_SIZE = "GOPSize"; +const char * const B_MUTE = "Mute"; +const char * const B_ENABLE = "Enable"; +const char * const B_INPUT_MUX = "Input"; +const char * const B_OUTPUT_MUX = "Output"; +const char * const B_TUNER_CHANNEL = "Channel"; +const char * const B_TRACK = "Track"; +const char * const B_RECSTATE = "RecState"; +const char * const B_SHUTTLE_MODE = "Shuttle"; +const char * const B_RESOLUTION = "Resolution"; +const char * const B_COLOR_SPACE = "Colorspace"; +const char * const B_FRAME_RATE = "FrameRate"; +const char * const B_VIDEO_FORMAT = "VideoFormat"; +const char * const B_WEB_PHYSICAL_INPUT = "PhysInput"; +const char * const B_WEB_PHYSICAL_OUTPUT = "PhysOutput"; +const char * const B_WEB_ADC_CONVERTER = "ADC"; +const char * const B_WEB_DAC_CONVERTER = "DAC"; +const char * const B_WEB_LOGICAL_INPUT = "LogInput"; +const char * const B_WEB_LOGICAL_OUTPUT = "LogOutput"; +const char * const B_WEB_LOGICAL_BUS = "LogBus"; +const char * const B_WEB_BUFFER_INPUT = "DataInput"; +const char * const B_WEB_BUFFER_OUTPUT = "DataOutput"; +const char * const B_SIMPLE_TRANSPORT = "SimpleTransport";*/ +m.attr("B_GENERIC") = "";//py::cast(B_GENERIC); -m.attr("B_GENERIC") = py::cast(B_GENERIC); - -m.attr("B_MASTER_GAIN") = py::cast(B_MASTER_GAIN); +m.attr("B_MASTER_GAIN") = "Master";//py::cast(B_MASTER_GAIN); -m.attr("B_GAIN") = py::cast(B_GAIN); +m.attr("B_GAIN") = "Gain";//py::cast(B_GAIN); -m.attr("B_BALANCE") = py::cast(B_BALANCE); +m.attr("B_BALANCE") = "Balance";//py::cast(B_BALANCE); -m.attr("B_FREQUENCY") = py::cast(B_FREQUENCY); +m.attr("B_FREQUENCY") = "Frequency";//py::cast(B_FREQUENCY); -m.attr("B_LEVEL") = py::cast(B_LEVEL); +m.attr("B_LEVEL") = "Level";//py::cast(B_LEVEL); -m.attr("B_SHUTTLE_SPEED") = py::cast(B_SHUTTLE_SPEED); +m.attr("B_SHUTTLE_SPEED") = "Speed";//py::cast(B_SHUTTLE_SPEED); -m.attr("B_CROSSFADE") = py::cast(B_CROSSFADE); +m.attr("B_CROSSFADE") = "XFade";//py::cast(B_CROSSFADE); -m.attr("B_EQUALIZATION") = py::cast(B_EQUALIZATION); +m.attr("B_EQUALIZATION") = "EQ";//py::cast(B_EQUALIZATION); -m.attr("B_COMPRESSION") = py::cast(B_COMPRESSION); +m.attr("B_COMPRESSION") = "Compression";//py::cast(B_COMPRESSION); -m.attr("B_QUALITY") = py::cast(B_QUALITY); +m.attr("B_QUALITY") = "Quality";//py::cast(B_QUALITY); -m.attr("B_BITRATE") = py::cast(B_BITRATE); +m.attr("B_BITRATE") = "Bitrate";//py::cast(B_BITRATE); -m.attr("B_GOP_SIZE") = py::cast(B_GOP_SIZE); +m.attr("B_GOP_SIZE") = "GOPSize";//py::cast(B_GOP_SIZE); -m.attr("B_MUTE") = py::cast(B_MUTE); +m.attr("B_MUTE") = "Mute";//py::cast(B_MUTE); -m.attr("B_ENABLE") = py::cast(B_ENABLE); +m.attr("B_ENABLE") = "Enable";//py::cast(B_ENABLE); -m.attr("B_INPUT_MUX") = py::cast(B_INPUT_MUX); +m.attr("B_INPUT_MUX") = "Input";//py::cast(B_INPUT_MUX); -m.attr("B_OUTPUT_MUX") = py::cast(B_OUTPUT_MUX); +m.attr("B_OUTPUT_MUX") = "Output";//py::cast(B_OUTPUT_MUX); -m.attr("B_TUNER_CHANNEL") = py::cast(B_TUNER_CHANNEL); +m.attr("B_TUNER_CHANNEL") = "Channel";//py::cast(B_TUNER_CHANNEL); -m.attr("B_TRACK") = py::cast(B_TRACK); +m.attr("B_TRACK") = "Track";//py::cast(B_TRACK); -m.attr("B_RECSTATE") = py::cast(B_RECSTATE); +m.attr("B_RECSTATE") = "RecState";//py::cast(B_RECSTATE); -m.attr("B_SHUTTLE_MODE") = py::cast(B_SHUTTLE_MODE); +m.attr("B_SHUTTLE_MODE") = "Shuttle";//py::cast(B_SHUTTLE_MODE); -m.attr("B_RESOLUTION") = py::cast(B_RESOLUTION); +m.attr("B_RESOLUTION") = "Resolution";//py::cast(B_RESOLUTION); -m.attr("B_COLOR_SPACE") = py::cast(B_COLOR_SPACE); +m.attr("B_COLOR_SPACE") = "Colorspace";//py::cast(B_COLOR_SPACE); -m.attr("B_FRAME_RATE") = py::cast(B_FRAME_RATE); +m.attr("B_FRAME_RATE") = "FrameRate";//py::cast(B_FRAME_RATE); -m.attr("B_VIDEO_FORMAT") = py::cast(B_VIDEO_FORMAT); +m.attr("B_VIDEO_FORMAT") = "VideoFormat";//py::cast(B_VIDEO_FORMAT); -m.attr("B_WEB_PHYSICAL_INPUT") = py::cast(B_WEB_PHYSICAL_INPUT); +m.attr("B_WEB_PHYSICAL_INPUT") = "PhysInput";//py::cast(B_WEB_PHYSICAL_INPUT); -m.attr("B_WEB_PHYSICAL_OUTPUT") = py::cast(B_WEB_PHYSICAL_OUTPUT); +m.attr("B_WEB_PHYSICAL_OUTPUT") = "PhysOutput";//py::cast(B_WEB_PHYSICAL_OUTPUT); -m.attr("B_WEB_ADC_CONVERTER") = py::cast(B_WEB_ADC_CONVERTER); +m.attr("B_WEB_ADC_CONVERTER") = "ADC";//py::cast(B_WEB_ADC_CONVERTER); -m.attr("B_WEB_DAC_CONVERTER") = py::cast(B_WEB_DAC_CONVERTER); +m.attr("B_WEB_DAC_CONVERTER") = "DAC";//py::cast(B_WEB_DAC_CONVERTER); -m.attr("B_WEB_LOGICAL_INPUT") = py::cast(B_WEB_LOGICAL_INPUT); +m.attr("B_WEB_LOGICAL_INPUT") = "LogInput";//py::cast(B_WEB_LOGICAL_INPUT); -m.attr("B_WEB_LOGICAL_OUTPUT") = py::cast(B_WEB_LOGICAL_OUTPUT); +m.attr("B_WEB_LOGICAL_OUTPUT") = "LogOutput";//py::cast(B_WEB_LOGICAL_OUTPUT); -m.attr("B_WEB_LOGICAL_BUS") = py::cast(B_WEB_LOGICAL_BUS); +m.attr("B_WEB_LOGICAL_BUS") = "LogBus";//py::cast(B_WEB_LOGICAL_BUS); -m.attr("B_WEB_BUFFER_INPUT") = py::cast(B_WEB_BUFFER_INPUT); +m.attr("B_WEB_BUFFER_INPUT") = "DataInput";//py::cast(B_WEB_BUFFER_INPUT); -m.attr("B_WEB_BUFFER_OUTPUT") = py::cast(B_WEB_BUFFER_OUTPUT); +m.attr("B_WEB_BUFFER_OUTPUT") = "DataOutput";//py::cast(B_WEB_BUFFER_OUTPUT); -m.attr("B_SIMPLE_TRANSPORT") = py::cast(B_SIMPLE_TRANSPORT); +m.attr("B_SIMPLE_TRANSPORT") = "SimpleTransport";//py::cast(B_SIMPLE_TRANSPORT); -m.attr("BContinuousParameter") = py::cast(BContinuousParameter); +//m.attr("BContinuousParameter") = py::cast(BContinuousParameter); -py::class_(m, "BParameterWeb") +py::class_>(m, "BParameterWeb") .def(py::init(), "") .def("Node", &BParameterWeb::Node, "") .def("MakeGroup", &BParameterWeb::MakeGroup, "", py::arg("name")) @@ -104,7 +140,7 @@ py::class_(m, "BParameterWeb") .def("Unflatten", &BParameterWeb::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) ; -py::class_(m, "BParameterGroup") +py::class_>(m, "BParameterGroup") .def("Web", &BParameterGroup::Web, "") .def("Name", &BParameterGroup::Name, "") .def("SetFlags", &BParameterGroup::SetFlags, "", py::arg("flags")) @@ -126,7 +162,7 @@ py::class_(m, "BParameterGroup") .def("Unflatten", &BParameterGroup::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) ; -py::class_(m, "BParameter") +py::class_>(m, "BParameter") .def("Type", &BParameter::Type, "") .def("Web", &BParameter::Web, "") .def("Group", &BParameter::Group, "") @@ -157,7 +193,7 @@ py::class_(m, "BParameter") .def("Unflatten", &BParameter::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) ; -py::class_(m, "BContinuousParameter") +py::class_>(m, "BContinuousParameter") .def("ValueType", &BContinuousParameter::ValueType, "") .def("MinValue", &BContinuousParameter::MinValue, "") .def("MaxValue", &BContinuousParameter::MaxValue, "") @@ -169,7 +205,7 @@ py::class_(m, "BContinuousParameter") .def("Unflatten", &BContinuousParameter::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) ; -py::class_(m, "BDiscreteParameter") +py::class_>(m, "BDiscreteParameter") .def("ValueType", &BDiscreteParameter::ValueType, "") .def("CountItems", &BDiscreteParameter::CountItems, "") .def("ItemNameAt", &BDiscreteParameter::ItemNameAt, "", py::arg("index")) @@ -183,7 +219,7 @@ py::class_(m, "BDiscreteParameter") .def("Unflatten", &BDiscreteParameter::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) ; -py::class_(m, "BTextParameter") +py::class_>(m, "BTextParameter") .def("ValueType", &BTextParameter::ValueType, "") .def("MaxBytes", &BTextParameter::MaxBytes, "") .def("FlattenedSize", &BTextParameter::FlattenedSize, "") @@ -191,7 +227,7 @@ py::class_(m, "BTextParameter") .def("Unflatten", &BTextParameter::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) ; -py::class_(m, "BNullParameter") +py::class_>(m, "BNullParameter") .def("ValueType", &BNullParameter::ValueType, "") .def("FlattenedSize", &BNullParameter::FlattenedSize, "") .def("Flatten", &BNullParameter::Flatten, "", py::arg("buffer"), py::arg("size")) From 10b7ca541b241e58279e63a8ff736e2c0e1c86ed Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 5 Sep 2024 13:51:43 +0200 Subject: [PATCH 060/115] update MediaFiles MediaFormats --- Jamfile | 4 ++++ bindings/__init__.py | 2 ++ bindings/media/MediaFiles.cpp | 7 ++++--- bindings/media/MediaFormats.cpp | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Jamfile b/Jamfile index 62d4450..c7ff1ea 100644 --- a/Jamfile +++ b/Jamfile @@ -338,6 +338,8 @@ local sourceFiles = ParameterWeb.cpp MediaTrack.cpp MediaFile.cpp + MediaFiles.cpp + MediaFormats.cpp ; @@ -374,6 +376,8 @@ LINKLIBS on MediaEncoder.so = $(LINKLIBS) -lmedia ; LINKLIBS on ParameterWeb.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaTrack.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaFile.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaFiles.so = $(LINKLIBS) -lmedia ; +#LINKLIBS on MediaFormats.so = $(LINKLIBS) -lmedia ; #LINKLIBS on BufferConsumer.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaNode.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimeSource.so = $(LINKLIBS) -lmedia ; diff --git a/bindings/__init__.py b/bindings/__init__.py index d793bad..fc0abdb 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -215,6 +215,8 @@ from .ParameterWeb import * from .MediaTrack import * from .MediaFile import * +from .MediaFiles import * +from .MediaFormats import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/media/MediaFiles.cpp b/bindings/media/MediaFiles.cpp index 6b7ee90..2d77348 100644 --- a/bindings/media/MediaFiles.cpp +++ b/bindings/media/MediaFiles.cpp @@ -7,9 +7,9 @@ namespace py = pybind11; using namespace BPrivate; -using namespace BPrivate::media; +//using namespace BPrivate::media; -void define_MediaFiles(py::module_& m) +PYBIND11_MODULE(MediaFiles, m) { py::class_(m, "BMediaFiles") .def(py::init(), "") @@ -23,7 +23,8 @@ py::class_(m, "BMediaFiles") .def("SetAudioGainFor", &BMediaFiles::SetAudioGainFor, "", py::arg("type"), py::arg("item"), py::arg("gain")) .def("RemoveRefFor", &BMediaFiles::RemoveRefFor, "", py::arg("type"), py::arg("item"), py::arg("ref")) .def("RemoveItem", &BMediaFiles::RemoveItem, "", py::arg("type"), py::arg("item")) -.def_readwrite("B_SOUNDS", &BMediaFiles::B_SOUNDS, "") +//.def_readwrite("B_SOUNDS", &BMediaFiles::B_SOUNDS, "") //from media kit source const char BMediaFiles::B_SOUNDS[] = "Sounds"; +.def_static("B_SOUNDS", [](){return "Sounds";},"") ; diff --git a/bindings/media/MediaFormats.cpp b/bindings/media/MediaFormats.cpp index 8ea2858..1095a8e 100644 --- a/bindings/media/MediaFormats.cpp +++ b/bindings/media/MediaFormats.cpp @@ -7,9 +7,9 @@ namespace py = pybind11; using namespace BPrivate; -using namespace BPrivate::media; +//using namespace BPrivate::media; -void define_MediaFormats(py::module_& m) +PYBIND11_MODULE(MediaFormats, m) { py::enum_(m, "media_file_accept_format_flags", "") .value("B_MEDIA_REJECT_WILDCARDS", media_file_accept_format_flags::B_MEDIA_REJECT_WILDCARDS, "") From 20ef9f2c365eefdee9554ec7a97c351a9150e46f Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 5 Sep 2024 16:46:39 +0200 Subject: [PATCH 061/115] update MediaFormats --- Jamfile | 2 +- bindings/media/MediaFormats.cpp | 162 ++++++++++++++++++++++++++++---- 2 files changed, 143 insertions(+), 21 deletions(-) diff --git a/Jamfile b/Jamfile index c7ff1ea..e196627 100644 --- a/Jamfile +++ b/Jamfile @@ -377,7 +377,7 @@ LINKLIBS on ParameterWeb.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaTrack.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaFile.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaFiles.so = $(LINKLIBS) -lmedia ; -#LINKLIBS on MediaFormats.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaFormats.so = $(LINKLIBS) -lmedia ; #LINKLIBS on BufferConsumer.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaNode.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimeSource.so = $(LINKLIBS) -lmedia ; diff --git a/bindings/media/MediaFormats.cpp b/bindings/media/MediaFormats.cpp index 1095a8e..9769af7 100644 --- a/bindings/media/MediaFormats.cpp +++ b/bindings/media/MediaFormats.cpp @@ -2,12 +2,85 @@ #include #include #include +#include #include namespace py = pybind11; using namespace BPrivate; //using namespace BPrivate::media; +media_beos_description& get_beos(media_format_description& desc) { + return desc.u.beos; +} +media_quicktime_description& get_quicktime(media_format_description& desc) { + return desc.u.quicktime; +} +media_avi_description& get_avi(media_format_description& desc) { + return desc.u.avi; +} +media_asf_description& get_asf(media_format_description& desc) { + return desc.u.asf; +} +media_mpeg_description& get_mpeg(media_format_description& desc) { + return desc.u.mpeg; +} +media_wav_description& get_wav(media_format_description& desc) { + return desc.u.wav; +} +media_aiff_description& get_aiff(media_format_description& desc) { + return desc.u.aiff; +} +media_misc_description& get_misc(media_format_description& desc) { + return desc.u.misc; +} +media_avr_description& get_avr(media_format_description& desc) { + return desc.u.avr; +} +//******************* +void set_beos(media_format_description& desc, const media_beos_description& value) { + desc.u.beos = value; +} +void set_quicktime(media_format_description& desc, const media_quicktime_description& value) { + desc.u.quicktime = value; +} +void set_avi(media_format_description& desc, const media_avi_description& value) { + desc.u.avi = value; +} +void set_asf(media_format_description& desc, const media_asf_description& value) { + desc.u.asf = value; +} +void set_mpeg(media_format_description& desc, const media_mpeg_description& value) { + desc.u.mpeg = value; +} +void set_wav(media_format_description& desc, const media_wav_description& value) { + desc.u.wav = value; +} +void set_aiff(media_format_description& desc, const media_aiff_description& value) { + desc.u.aiff = value; +} +void set_misc(media_format_description& desc, const media_misc_description& value) { + desc.u.misc = value; +} +void set_avr(media_format_description& desc, const media_avr_description& value) { + desc.u.avr = value; +} +//******** +std::string get_media_codec_info_pretty_name(const media_codec_info& self) { + return std::string(self.pretty_name); +} + +void set_media_codec_info_pretty_name(media_codec_info& self, const std::string& pretty_name) { + std::strncpy(self.pretty_name, pretty_name.c_str(), 95); + self.pretty_name[95] = '\0'; +} +std::string get_media_codec_info_short_name(const media_codec_info& self) { + return std::string(self.short_name); +} + +void set_media_codec_info_short_name(media_codec_info& self, const std::string& short_name) { + std::strncpy(self.short_name, short_name.c_str(), 31); + self.short_name[31] = '\0'; +} PYBIND11_MODULE(MediaFormats, m) { @@ -36,15 +109,41 @@ py::enum_(m, "mpeg_id", "") .export_values(); py::class_(m, "media_codec_info") -.def_readwrite("pretty_name", &media_codec_info::pretty_name, "") -.def_readwrite("short_name", &media_codec_info::short_name, "") +//.def_readwrite("pretty_name", &media_codec_info::pretty_name, "") +.def_property("pretty_name", &get_media_codec_info_pretty_name, &set_media_codec_info_pretty_name, "") +//.def_readwrite("short_name", &media_codec_info::short_name, "") +.def_property("short_name", &get_media_codec_info_short_name, &set_media_codec_info_short_name, "") .def_readwrite("id", &media_codec_info::id, "") .def_readwrite("sub_id", &media_codec_info::sub_id, "") -.def_readwrite("pad", &media_codec_info::pad, "") +//.def_readwrite("pad", &media_codec_info::pad, "") +.def_property("pad", + [](const media_codec_info &info) { + py::array_t result(63); + std::memcpy(result.mutable_data(), &info.pad, sizeof(info.pad)); + return result; + }, + [](media_codec_info &info, py::array_t value) { + if (value.size() != 63) { + throw std::runtime_error("Array must have size 63"); + } + std::memcpy(&info.pad, value.data(), sizeof(info.pad)); + },"") ; py::class_(m, "GUID") -.def_readwrite("data", &GUID::data, "") +//.def_readwrite("data", &GUID::data, "") +.def_property("data", + [](const GUID &guid) { + py::array_t result(16); + std::memcpy(result.mutable_data(), &guid.data, sizeof(guid.data)); + return result; + }, + [](GUID &guid, py::array_t value) { + if (value.size() != 16) { + throw std::runtime_error("Array must have size 16"); + } + std::memcpy(&guid.data, value.data(), sizeof(guid.data)); + },"") ; py::class_(m, "media_beos_description") @@ -85,26 +184,49 @@ py::class_(m, "media_misc_description") .def_readwrite("codec", &media_misc_description::codec, "") ; -py::class_(m, "union ") -.def_readwrite("beos", &union ::beos, "") -.def_readwrite("quicktime", &union ::quicktime, "") -.def_readwrite("avi", &union ::avi, "") -.def_readwrite("asf", &union ::asf, "") -.def_readwrite("mpeg", &union ::mpeg, "") -.def_readwrite("wav", &union ::wav, "") -.def_readwrite("aiff", &union ::aiff, "") -.def_readwrite("misc", &union ::misc, "") -.def_readwrite("avr", &union ::avr, "") -.def_readwrite("_reserved_", &union ::_reserved_, "") -; py::class_(m, "media_format_description") .def(py::init(), "") .def(py::init(), "", py::arg("other")) .def("operator=", &media_format_description::operator=, "", py::arg("other")) .def_readwrite("family", &media_format_description::family, "") -.def_readwrite("_reserved_", &media_format_description::_reserved_, "") +//.def_readwrite("_reserved_", &media_format_description::_reserved_, "") +.def_property( + "_reserved_", + [](const media_format_description &desc) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &desc._reserved_, sizeof(desc._reserved_)); + return result; + }, + [](media_format_description &desc, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&desc._reserved_, value.data(), sizeof(desc._reserved_)); + },"") .def_readwrite("u", &media_format_description::u, "") +.def_property("beos", &get_beos, &set_beos) +.def_property("quicktime", &get_quicktime, &set_quicktime) +.def_property("avi", &get_avi, &set_avi) +.def_property("asf", &get_asf, &set_asf) +.def_property("mpeg", &get_mpeg, &set_mpeg) +.def_property("wav", &get_wav, &set_wav) +.def_property("aiff", &get_aiff, &set_aiff) +.def_property("misc", &get_misc, &set_misc) +.def_property("avr", &get_avr, &set_avr) +.def_property( + "u_reserved_", + [](const media_format_description &desc) { + py::array_t result(12); + std::memcpy(result.mutable_data(), &desc.u._reserved_, sizeof(desc.u._reserved_)); + return result; + }, + [](media_format_description &desc, py::array_t value) { + if (value.size() != 12) { + throw std::runtime_error("Array must have size 12"); + } + std::memcpy(&desc.u._reserved_, value.data(), sizeof(desc.u._reserved_)); + },"") ; py::class_(m, "BMediaFormats") @@ -123,7 +245,7 @@ py::class_(m, "BMediaFormats") .def("MakeFormatFor", py::overload_cast(&BMediaFormats::MakeFormatFor), "", py::arg("description"), py::arg("inFormat"), py::arg("_outFormat")) ; -m.def("get_next_encoder", py::overload_cast(&get_next_encoder), +m.def("get_next_encoder", py::overload_cast(&get_next_encoder), R"ipc_Qu8mg5v7( /*! \brief Use this to iterate through the available encoders for a given file format. @@ -142,7 +264,7 @@ information about the encoder is placed there. */ )ipc_Qu8mg5v7", py::arg("cookie"), py::arg("fileFormat"), py::arg("inputFormat"), py::arg("_outputFormat"), py::arg("_codecInfo")); -m.def("get_next_encoder", py::overload_cast(&get_next_encoder), +m.def("get_next_encoder", py::overload_cast(&get_next_encoder), R"ipc_Qu8mg5v7( /*! \brief Use this to iterate through the available encoders with restrictions to the input and output media_format while the @@ -171,7 +293,7 @@ here. */ )ipc_Qu8mg5v7", py::arg("cookie"), py::arg("fileFormat"), py::arg("inputFormat"), py::arg("outputFormat"), py::arg("_codecInfo"), py::arg("_acceptedInputFormat"), py::arg("_acceptedOutputFormat")); -m.def("get_next_encoder", py::overload_cast(&get_next_encoder), +m.def("get_next_encoder", py::overload_cast(&get_next_encoder), R"ipc_Qu8mg5v7( /*! \brief Iterate over the all the available encoders without media_format restrictions. From f68fe6996576878e05e14bfeb101d87d80be8cf2 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 5 Sep 2024 17:44:12 +0200 Subject: [PATCH 062/115] update MediaNode MediaRecorder MediaRoster --- Jamfile | 6 ++++- bindings/__init__.py | 2 ++ bindings/media/MediaNode.cpp | 8 +++++++ bindings/media/MediaRecorder.cpp | 10 +++++++- bindings/media/MediaRoster.cpp | 40 +++++++++++++++++++++----------- 5 files changed, 50 insertions(+), 16 deletions(-) diff --git a/Jamfile b/Jamfile index e196627..2ea66ec 100644 --- a/Jamfile +++ b/Jamfile @@ -340,6 +340,8 @@ local sourceFiles = MediaFile.cpp MediaFiles.cpp MediaFormats.cpp + MediaRecorder.cpp + MediaRoster.cpp ; @@ -378,9 +380,11 @@ LINKLIBS on MediaTrack.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaFile.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaFiles.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaFormats.so = $(LINKLIBS) -lmedia ; -#LINKLIBS on BufferConsumer.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaNode.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaRecorder.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaRoster.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimeSource.so = $(LINKLIBS) -lmedia ; +#LINKLIBS on BufferConsumer.so = $(LINKLIBS) -lmedia ; LINKLIBS on ScreenSaver.so = $(LINKLIBS) -lscreensaver ; #LINKLIBS on MimeSnifferAddon.so = $(LINKLIBS) -lstoragekit ; diff --git a/bindings/__init__.py b/bindings/__init__.py index fc0abdb..dc33467 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -217,6 +217,8 @@ from .MediaFile import * from .MediaFiles import * from .MediaFormats import * +from .MediaRecorder import * +from .MediaRoster import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/media/MediaNode.cpp b/bindings/media/MediaNode.cpp index 09d1416..559c824 100644 --- a/bindings/media/MediaNode.cpp +++ b/bindings/media/MediaNode.cpp @@ -114,6 +114,14 @@ py::class_(m, "media_node_attribute") .def_readwrite("data", &media_node_attribute::data, "") ; +py::enum_(m, "run_mode", "") +.value("B_OFFLINE", BMediaNode::run_mode::B_OFFLINE, "") +.value("B_DECREASE_PRECISION", BMediaNode::run_mode::B_DECREASE_PRECISION, "") +.value("B_INCREASE_LATENCY", BMediaNode::run_mode::B_INCREASE_LATENCY, "") +.value("B_DROP_DATA", BMediaNode::run_mode::B_DROP_DATA, "") +.value("B_RECORDING", BMediaNode::run_mode::B_RECORDING, "") +.export_values(); + py::class_>(m, "BMediaNode") .def("Acquire", &BMediaNode::Acquire, "") .def("Release", &BMediaNode::Release, "") diff --git a/bindings/media/MediaRecorder.cpp b/bindings/media/MediaRecorder.cpp index a5fbe69..cbc86cc 100644 --- a/bindings/media/MediaRecorder.cpp +++ b/bindings/media/MediaRecorder.cpp @@ -4,13 +4,21 @@ #include #include +#include namespace py = pybind11; using namespace BPrivate; using namespace BPrivate::media; -void define_MediaRecorder(py::module_& m) +PYBIND11_MODULE(MediaRecorder, m) { +py::enum_(m, "notification", "") +.value("B_WILL_START", BMediaRecorder::notification::B_WILL_START, "") +.value("B_WILL_STOP", BMediaRecorder::notification::B_WILL_STOP, "") +.value("B_WILL_SEEK", BMediaRecorder::notification::B_WILL_SEEK, "") +.value("B_WILL_TIMEWARP", BMediaRecorder::notification::B_WILL_TIMEWARP, "") +.export_values(); + py::class_(m, "BMediaRecorder") .def(py::init(), "", py::arg("name"), py::arg("type")=B_MEDIA_UNKNOWN_TYPE) .def("InitCheck", &BMediaRecorder::InitCheck, "") diff --git a/bindings/media/MediaRoster.cpp b/bindings/media/MediaRoster.cpp index a34df59..7b6c628 100644 --- a/bindings/media/MediaRoster.cpp +++ b/bindings/media/MediaRoster.cpp @@ -4,12 +4,19 @@ #include #include +#include +#include +#include +#include +#include +#include +#include namespace py = pybind11; using namespace BPrivate; using namespace BPrivate::media; -void define_MediaRoster(py::module_& m) +PYBIND11_MODULE(MediaRoster, m) { py::enum_(m, "bus_type", "//! The BMediaRoster is the main API to the Media Kit.") .value("B_ISA_BUS", bus_type::B_ISA_BUS, "") @@ -18,9 +25,9 @@ py::enum_(m, "bus_type", "//! The BMediaRoster is the main API to the .value("B_UNKNOWN_BUS", bus_type::B_UNKNOWN_BUS, "") .export_values(); -m.attr("DefaultDeleter") = py::cast(DefaultDeleter); +//m.attr("DefaultDeleter") = py::cast(DefaultDeleter); -m.attr("BMediaRosterEx") = py::cast(BMediaRosterEx); +//m.attr("BMediaRosterEx") = py::cast(BMediaRosterEx); py::class_(m, "BMediaRoster") .def_static("Roster", &BMediaRoster::Roster, "", py::arg("_error")=NULL) @@ -31,7 +38,7 @@ py::class_(m, "BMediaRoster") .def("GetVideoOutput", &BMediaRoster::GetVideoOutput, "", py::arg("_node")) .def("GetAudioMixer", &BMediaRoster::GetAudioMixer, "", py::arg("_node")) .def("GetAudioOutput", py::overload_cast(&BMediaRoster::GetAudioOutput), "", py::arg("_node")) -.def("GetAudioOutput", py::overload_cast(&BMediaRoster::GetAudioOutput), "", py::arg("_node"), py::arg("_inputId"), py::arg("_inputName")) +.def("GetAudioOutput", py::overload_cast(&BMediaRoster::GetAudioOutput), "", py::arg("_node"), py::arg("_inputId"), py::arg("_inputName")) .def("GetTimeSource", &BMediaRoster::GetTimeSource, "", py::arg("_node")) .def("SetVideoInput", py::overload_cast(&BMediaRoster::SetVideoInput), "", py::arg("producer")) .def("SetVideoInput", py::overload_cast(&BMediaRoster::SetVideoInput), "", py::arg("producer")) @@ -47,7 +54,7 @@ py::class_(m, "BMediaRoster") .def("ReleaseNode", &BMediaRoster::ReleaseNode, "", py::arg("node")) .def("MakeTimeSourceFor", &BMediaRoster::MakeTimeSourceFor, "", py::arg("for_node")) .def("Connect", py::overload_cast(&BMediaRoster::Connect), "", py::arg("from"), py::arg("to"), py::arg("_inOutFormat"), py::arg("_output"), py::arg("_input")) -.def("Connect", py::overload_cast(&BMediaRoster::Connect), "", py::arg("from"), py::arg("to"), py::arg("_inOutFormat"), py::arg("_output"), py::arg("_input"), py::arg("flags"), py::arg("_reserved")=NULL) +.def("Connect", py::overload_cast(&BMediaRoster::Connect), "", py::arg("from"), py::arg("to"), py::arg("_inOutFormat"), py::arg("_output"), py::arg("_input"), py::arg("flags"), py::arg("_reserved")=NULL) .def("Disconnect", py::overload_cast(&BMediaRoster::Disconnect), "", py::arg("sourceNode"), py::arg("source"), py::arg("destinationNode"), py::arg("destination")) .def("Disconnect", py::overload_cast(&BMediaRoster::Disconnect), "", py::arg("output"), py::arg("input")) .def("StartNode", &BMediaRoster::StartNode, "", py::arg("node"), py::arg("atPerformanceTime")) @@ -60,7 +67,7 @@ py::class_(m, "BMediaRoster") .def("SetRunModeNode", &BMediaRoster::SetRunModeNode, "", py::arg("node"), py::arg("mode")) .def("PrerollNode", &BMediaRoster::PrerollNode, "", py::arg("node")) .def("RollNode", &BMediaRoster::RollNode, "", py::arg("node"), py::arg("startPerformance"), py::arg("stopPerformance"), py::arg("atMediaTime")=- B_INFINITE_TIMEOUT) -.def("SetProducerRunModeDelay", &BMediaRoster::SetProducerRunModeDelay, "", py::arg("node"), py::arg("delay"), py::arg("mode")=BMediaNode : : B_RECORDING) +.def("SetProducerRunModeDelay", &BMediaRoster::SetProducerRunModeDelay, "", py::arg("node"), py::arg("delay"), py::arg("mode")=BMediaNode::run_mode::B_RECORDING) .def("SetProducerRate", &BMediaRoster::SetProducerRate, "", py::arg("producer"), py::arg("numer"), py::arg("denom")) .def("GetLiveNodeInfo", &BMediaRoster::GetLiveNodeInfo, "", py::arg("node"), py::arg("_liveInfo")) .def("GetLiveNodes", &BMediaRoster::GetLiveNodes, "", py::arg("_liveNodes"), py::arg("inOutTotalCount"), py::arg("hasInput")=NULL, py::arg("hasOutput")=NULL, py::arg("name")=NULL, py::arg("nodeKinds")=0) @@ -71,18 +78,23 @@ py::class_(m, "BMediaRoster") .def("GetConnectedOutputsFor", &BMediaRoster::GetConnectedOutputsFor, "", py::arg("node"), py::arg("_activeOutputsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) .def("GetAllOutputsFor", &BMediaRoster::GetAllOutputsFor, "", py::arg("node"), py::arg("_outputsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) .def("StartWatching", py::overload_cast(&BMediaRoster::StartWatching), "", py::arg("target")) -.def("StartWatching", py::overload_cast(&BMediaRoster::StartWatching), "", py::arg("target"), py::arg("notificationType")) -.def("StartWatching", py::overload_cast(&BMediaRoster::StartWatching), "", py::arg("target"), py::arg("node"), py::arg("notificationType")) +.def("StartWatching", py::overload_cast(&BMediaRoster::StartWatching), "", py::arg("target"), py::arg("notificationType")) +.def("StartWatching", py::overload_cast(&BMediaRoster::StartWatching), "", py::arg("target"), py::arg("node"), py::arg("notificationType")) .def("StopWatching", py::overload_cast(&BMediaRoster::StopWatching), "", py::arg("target")) -.def("StopWatching", py::overload_cast(&BMediaRoster::StopWatching), "", py::arg("target"), py::arg("notificationType")) -.def("StopWatching", py::overload_cast(&BMediaRoster::StopWatching), "", py::arg("target"), py::arg("node"), py::arg("notificationType")) +.def("StopWatching", py::overload_cast(&BMediaRoster::StopWatching), "", py::arg("target"), py::arg("notificationType")) +.def("StopWatching", py::overload_cast(&BMediaRoster::StopWatching), "", py::arg("target"), py::arg("node"), py::arg("notificationType")) .def("RegisterNode", &BMediaRoster::RegisterNode, "", py::arg("node")) .def("UnregisterNode", &BMediaRoster::UnregisterNode, "", py::arg("node")) .def("SetTimeSourceFor", &BMediaRoster::SetTimeSourceFor, "", py::arg("node"), py::arg("timeSource")) -.def("GetParameterWebFor", &BMediaRoster::GetParameterWebFor, "", py::arg("node"), py::arg("_web")) +//.def("GetParameterWebFor", &BMediaRoster::GetParameterWebFor, "", py::arg("node"), py::arg("_web")) +.def("GetParameterWebFor",[](BMediaRoster& self, const media_node& node) { + BParameterWeb* web = nullptr; + status_t status =self.GetParameterWebFor(node, &web); + return std::make_tuple(status, web); +}, "", py::arg("node")) .def("StartControlPanel", &BMediaRoster::StartControlPanel, "", py::arg("node"), py::arg("_messenger")=NULL) .def("GetDormantNodes", &BMediaRoster::GetDormantNodes, "", py::arg("_info"), py::arg("_inOutCount"), py::arg("_hasInput")=NULL, py::arg("_hasOutput")=NULL, py::arg("name")=NULL, py::arg("requireKinds")=0, py::arg("denyKinds")=0) -.def("InstantiateDormantNode", py::overload_cast(&BMediaRoster::InstantiateDormantNode), "", py::arg("info"), py::arg("_node"), py::arg("flags")) +.def("InstantiateDormantNode", py::overload_cast(&BMediaRoster::InstantiateDormantNode), "", py::arg("info"), py::arg("_node"), py::arg("flags")) .def("InstantiateDormantNode", py::overload_cast(&BMediaRoster::InstantiateDormantNode), "", py::arg("info"), py::arg("_node")) .def("GetDormantNodeFor", &BMediaRoster::GetDormantNodeFor, "", py::arg("node"), py::arg("_info")) .def("GetDormantFlavorInfoFor", &BMediaRoster::GetDormantFlavorInfoFor, "", py::arg("info"), py::arg("_flavor")) @@ -97,8 +109,8 @@ py::class_(m, "BMediaRoster") .def("GetDormantNodeForType", &BMediaRoster::GetDormantNodeForType, "", py::arg("type"), py::arg("requireNodeKinds"), py::arg("_info")) .def("GetReadFileFormatsFor", &BMediaRoster::GetReadFileFormatsFor, "", py::arg("node"), py::arg("_readFormatsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) .def("GetWriteFileFormatsFor", &BMediaRoster::GetWriteFileFormatsFor, "", py::arg("node"), py::arg("_writeFormatsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) -.def("GetFormatFor", py::overload_cast(&BMediaRoster::GetFormatFor), "", py::arg("output"), py::arg("_inOutFormat"), py::arg("flags")=0) -.def("GetFormatFor", py::overload_cast(&BMediaRoster::GetFormatFor), "", py::arg("input"), py::arg("_inOutFormat"), py::arg("flags")=0) +.def("GetFormatFor", py::overload_cast(&BMediaRoster::GetFormatFor), "", py::arg("output"), py::arg("_inOutFormat"), py::arg("flags")=0) +.def("GetFormatFor", py::overload_cast(&BMediaRoster::GetFormatFor), "", py::arg("input"), py::arg("_inOutFormat"), py::arg("flags")=0) .def("GetFormatFor", py::overload_cast(&BMediaRoster::GetFormatFor), "", py::arg("node"), py::arg("_inOutFormat"), py::arg("quality")=B_MEDIA_ANY_QUALITY) .def("GetNodeAttributesFor", &BMediaRoster::GetNodeAttributesFor, "", py::arg("node"), py::arg("outArray"), py::arg("inMaxCount")) .def("NodeIDFor", &BMediaRoster::NodeIDFor, "", py::arg("sourceOrDestinationPort")) From 0a663570d3de37aa598223ce036875adfbbf6bc9 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 5 Sep 2024 19:45:39 +0200 Subject: [PATCH 063/115] update MediaTheme fix smart_holder MediaRoster --- Jamfile | 2 ++ bindings/__init__.py | 1 + bindings/media/MediaRoster.cpp | 5 ++++- bindings/media/MediaTheme.cpp | 34 +++++++++++++++++++++++++++------- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Jamfile b/Jamfile index 2ea66ec..89307f7 100644 --- a/Jamfile +++ b/Jamfile @@ -342,6 +342,7 @@ local sourceFiles = MediaFormats.cpp MediaRecorder.cpp MediaRoster.cpp + MediaTheme.cpp ; @@ -383,6 +384,7 @@ LINKLIBS on MediaFormats.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaNode.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaRecorder.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaRoster.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaTheme.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimeSource.so = $(LINKLIBS) -lmedia ; #LINKLIBS on BufferConsumer.so = $(LINKLIBS) -lmedia ; diff --git a/bindings/__init__.py b/bindings/__init__.py index dc33467..7e85bc8 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -219,6 +219,7 @@ from .MediaFormats import * from .MediaRecorder import * from .MediaRoster import * +from .MediaTheme import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/media/MediaRoster.cpp b/bindings/media/MediaRoster.cpp index 7b6c628..4ea8b6b 100644 --- a/bindings/media/MediaRoster.cpp +++ b/bindings/media/MediaRoster.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -16,6 +17,8 @@ namespace py = pybind11; using namespace BPrivate; using namespace BPrivate::media; +PYBIND11_SMART_HOLDER_TYPE_CASTERS(BMediaRoster); + PYBIND11_MODULE(MediaRoster, m) { py::enum_(m, "bus_type", "//! The BMediaRoster is the main API to the Media Kit.") @@ -29,7 +32,7 @@ py::enum_(m, "bus_type", "//! The BMediaRoster is the main API to the //m.attr("BMediaRosterEx") = py::cast(BMediaRosterEx); -py::class_(m, "BMediaRoster") +py::class_(m, "BMediaRoster") .def_static("Roster", &BMediaRoster::Roster, "", py::arg("_error")=NULL) .def_static("CurrentRoster", &BMediaRoster::CurrentRoster, "") .def_static("IsRunning", &BMediaRoster::IsRunning, "") diff --git a/bindings/media/MediaTheme.cpp b/bindings/media/MediaTheme.cpp index f036ab0..9fc15c7 100644 --- a/bindings/media/MediaTheme.cpp +++ b/bindings/media/MediaTheme.cpp @@ -4,13 +4,33 @@ #include #include +#include +#include +#include +#include namespace py = pybind11; using namespace BPrivate; -using namespace BPrivate::media; +//using namespace BPrivate::media; -void define_MediaTheme(py::module_& m) +PYBIND11_MODULE(MediaTheme, m) { +py::enum_(m, "bg_kind", "") +.value("B_GENERAL_BG", BMediaTheme::bg_kind::B_GENERAL_BG, "") +.value("B_SETTINGS_BG", BMediaTheme::bg_kind::B_SETTINGS_BG, "") +.value("B_PRESENTATION_BG", BMediaTheme::bg_kind::B_PRESENTATION_BG, "") +.value("B_EDIT_BG", BMediaTheme::bg_kind::B_EDIT_BG, "") +.value("B_CONTROL_BG", BMediaTheme::bg_kind::B_CONTROL_BG, "") +.value("B_HILITE_BG", BMediaTheme::bg_kind::B_HILITE_BG, "") +.export_values(); +py::enum_(m, "fg_kind", "") +.value("B_GENERAL_FG", BMediaTheme::fg_kind::B_GENERAL_FG, "") +.value("B_SETTINGS_FG", BMediaTheme::fg_kind::B_SETTINGS_FG, "") +.value("B_PRESENTATION_FG", BMediaTheme::fg_kind::B_PRESENTATION_FG, "") +.value("B_EDIT_FG", BMediaTheme::fg_kind::B_EDIT_FG, "") +.value("B_CONTROL_FG", BMediaTheme::fg_kind::B_CONTROL_FG, "") +.value("B_HILITE_FG", BMediaTheme::fg_kind::B_HILITE_FG, "") +.export_values(); py::class_(m, "BMediaTheme") .def("Name", &BMediaTheme::Name, "") .def("Info", &BMediaTheme::Info, "") @@ -20,13 +40,13 @@ py::class_(m, "BMediaTheme") .def_static("SetPreferredTheme", &BMediaTheme::SetPreferredTheme, "", py::arg("defaultTheme")=NULL) .def_static("PreferredTheme", &BMediaTheme::PreferredTheme, "") .def("MakeControlFor", &BMediaTheme::MakeControlFor, "", py::arg("control")) -.def("BackgroundBitmapFor", &BMediaTheme::BackgroundBitmapFor, "", py::arg("bg")=B_GENERAL_BG) -.def("BackgroundColorFor", &BMediaTheme::BackgroundColorFor, "", py::arg("bg")=B_GENERAL_BG) -.def("ForegroundColorFor", &BMediaTheme::ForegroundColorFor, "", py::arg("fg")=B_GENERAL_FG) +.def("BackgroundBitmapFor", &BMediaTheme::BackgroundBitmapFor, "", py::arg("bg")=BMediaTheme::bg_kind::B_GENERAL_BG) +.def("BackgroundColorFor", &BMediaTheme::BackgroundColorFor, "", py::arg("bg")=BMediaTheme::bg_kind::B_GENERAL_BG) +.def("ForegroundColorFor", &BMediaTheme::ForegroundColorFor, "", py::arg("fg")=BMediaTheme::fg_kind::B_GENERAL_FG) ; -m.def("make_theme", &make_theme, "", py::arg("id"), py::arg("you")); +//m.def("make_theme", &make_theme, "", py::arg("id"), py::arg("you")); //where are these? -m.def("get_theme_at", &get_theme_at, "", py::arg("index"), py::arg("_name"), py::arg("_info"), py::arg("_id")); +//m.def("get_theme_at", &get_theme_at, "", py::arg("index"), py::arg("_name"), py::arg("_info"), py::arg("_id")); } From 1bfb99126c218b4597b139ef6d5ffb5daeca28b4 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 5 Sep 2024 20:07:35 +0200 Subject: [PATCH 064/115] Update PlaySound Sound SoundFile and modify header SoundFile.h in headers/media --- Jamfile | 6 +++ bindings/__init__.py | 3 ++ bindings/media/PlaySound.cpp | 6 +-- bindings/media/Sound.cpp | 9 ++-- bindings/media/SoundFile.cpp | 14 ++--- headers/media/SoundFile.h | 101 +++++++++++++++++++++++++++++++++++ 6 files changed, 127 insertions(+), 12 deletions(-) create mode 100644 headers/media/SoundFile.h diff --git a/Jamfile b/Jamfile index 89307f7..59878b8 100644 --- a/Jamfile +++ b/Jamfile @@ -343,6 +343,9 @@ local sourceFiles = MediaRecorder.cpp MediaRoster.cpp MediaTheme.cpp + PlaySound.cpp + Sound.cpp + SoundFile.cpp ; @@ -385,6 +388,9 @@ LINKLIBS on MediaNode.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaRecorder.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaRoster.so = $(LINKLIBS) -lmedia ; LINKLIBS on MediaTheme.so = $(LINKLIBS) -lmedia ; +LINKLIBS on PlaySound.so = $(LINKLIBS) -lmedia ; +LINKLIBS on Sound.so = $(LINKLIBS) -lmedia ; +LINKLIBS on SoundFile.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimeSource.so = $(LINKLIBS) -lmedia ; #LINKLIBS on BufferConsumer.so = $(LINKLIBS) -lmedia ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 7e85bc8..b04786d 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -220,6 +220,9 @@ from .MediaRecorder import * from .MediaRoster import * from .MediaTheme import * +from .PlaySound import * +from .Sound import * +from .SoundFile import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/media/PlaySound.cpp b/bindings/media/PlaySound.cpp index f047e41..5601c80 100644 --- a/bindings/media/PlaySound.cpp +++ b/bindings/media/PlaySound.cpp @@ -6,10 +6,10 @@ #include namespace py = pybind11; -using namespace BPrivate; -using namespace BPrivate::media; +//using namespace BPrivate; +//using namespace BPrivate::media; -void define_PlaySound(py::module_& m) +PYBIND11_MODULE(PlaySound, m) { m.def("play_sound", &play_sound, "", py::arg("soundRef"), py::arg("mix"), py::arg("queue"), py::arg("background")); diff --git a/bindings/media/Sound.cpp b/bindings/media/Sound.cpp index 7a0145e..93da60d 100644 --- a/bindings/media/Sound.cpp +++ b/bindings/media/Sound.cpp @@ -4,15 +4,18 @@ #include #include +#include +//#include +//#include namespace py = pybind11; using namespace BPrivate; -void define_Sound(py::module_& m) +PYBIND11_MODULE(Sound, m) { -m.attr("BTrackReader") = py::cast(BTrackReader); +//m.attr("BTrackReader") = py::cast(BTrackReader); -py::class_(m, "BSound") +py::class_>(m, "BSound") .def(py::init(), "", py::arg("data"), py::arg("size"), py::arg("format"), py::arg("freeWhenDone")=false) .def(py::init(), "", py::arg("soundFile"), py::arg("loadIntoMemory")=false) .def("InitCheck", &BSound::InitCheck, "") diff --git a/bindings/media/SoundFile.cpp b/bindings/media/SoundFile.cpp index 6806f6a..53374c6 100644 --- a/bindings/media/SoundFile.cpp +++ b/bindings/media/SoundFile.cpp @@ -4,20 +4,22 @@ #include #include +#include +#include namespace py = pybind11; using namespace BPrivate; -void define_SoundFile(py::module_& m) +PYBIND11_MODULE(SoundFile, m) { -m.attr("B_UNKNOWN_FILE") = py::cast(B_UNKNOWN_FILE); -m.attr("B_AIFF_FILE") = py::cast(B_AIFF_FILE); -m.attr("B_WAVE_FILE") = py::cast(B_WAVE_FILE); -m.attr("B_UNIX_FILE") = py::cast(B_UNIX_FILE); +m.attr("B_UNKNOWN_FILE") = 0;//py::cast(B_UNKNOWN_FILE); +m.attr("B_AIFF_FILE") = 1;//py::cast(B_AIFF_FILE); +m.attr("B_WAVE_FILE") = 2;//py::cast(B_WAVE_FILE); +m.attr("B_UNIX_FILE") = 3;//py::cast(B_UNIX_FILE); py::class_(m, "BSoundFile") .def(py::init(), "") -.def(py::init(), "", py::arg("ref"), py::arg("openMode")) +.def(py::init(), "", py::arg("ref"), py::arg("openMode")) .def("InitCheck", &BSoundFile::InitCheck, "") .def("SetTo", &BSoundFile::SetTo, "", py::arg("ref"), py::arg("openMode")) .def("FileFormat", &BSoundFile::FileFormat, "") diff --git a/headers/media/SoundFile.h b/headers/media/SoundFile.h new file mode 100644 index 0000000..6195c5b --- /dev/null +++ b/headers/media/SoundFile.h @@ -0,0 +1,101 @@ +/* + * Copyright 2009, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _SOUND_FILE_H +#define _SOUND_FILE_H + + +#include +#include +#include +#include +#include + + +// file formats +enum { + B_UNKNOWN_FILE, + B_AIFF_FILE, + B_WAVE_FILE, + B_UNIX_FILE +}; + + +class BSoundFile { +public: + BSoundFile(); + BSoundFile(const entry_ref* ref, + uint32 openMode); + virtual ~BSoundFile(); + + status_t InitCheck() const; + + status_t SetTo(const entry_ref* ref, uint32 openMode); + + int32 FileFormat() const; + int32 SamplingRate() const; + int32 CountChannels() const; + int32 SampleSize() const; + int32 ByteOrder() const; + int32 SampleFormat() const; + int32 FrameSize() const; + off_t CountFrames() const; + + bool IsCompressed() const; + int32 CompressionType() const; + char* CompressionName() const; + + virtual int32 SetFileFormat(int32 format); + virtual int32 SetSamplingRate(int32 fps); + virtual int32 SetChannelCount(int32 samplesPerFrame); + virtual int32 SetSampleSize(int32 bytesPerSample); + virtual int32 SetByteOrder(int32 byteOrder); + virtual int32 SetSampleFormat(int32 format); + virtual int32 SetCompressionType(int32 type); + virtual char* SetCompressionName(char* name); + virtual bool SetIsCompressed(bool compressed); + virtual off_t SetDataLocation(off_t offset); + virtual off_t SetFrameCount(off_t count); + + size_t ReadFrames(char* buffer, size_t count); + size_t WriteFrames(char* buffer, size_t count); + virtual off_t SeekToFrame(off_t index); + off_t FrameIndex() const; + off_t FramesRemaining() const; + + BFile* fSoundFile; + +private: + + virtual void _ReservedSoundFile1(); + virtual void _ReservedSoundFile2(); + virtual void _ReservedSoundFile3(); + + void _init_raw_stats(); + status_t _ref_to_file(const entry_ref* ref); + + int32 fFileFormat; + int32 fSamplingRate; + int32 fChannelCount; + int32 fSampleSize; + int32 fByteOrder; + int32 fSampleFormat; + + off_t fByteOffset; + // offset to first sample + + off_t fFrameCount; + off_t fFrameIndex; + + bool fIsCompressed; + int32 fCompressionType; + char* fCompressionName; + status_t fCStatus; + BMediaFile* fMediaFile; + BMediaTrack* fMediaTrack; + + uint32 _reserved[2]; +}; + +#endif // _SOUND_FILE_H From 4f792604a023893d7a55a9b7d6f41bf2abecfaae Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 5 Sep 2024 21:18:50 +0200 Subject: [PATCH 065/115] update TimeCode.cpp --- Jamfile | 5 +++++ bindings/__init__.py | 2 ++ bindings/media/TimeCode.cpp | 41 +++++++++++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/Jamfile b/Jamfile index 59878b8..62de883 100644 --- a/Jamfile +++ b/Jamfile @@ -346,6 +346,9 @@ local sourceFiles = PlaySound.cpp Sound.cpp SoundFile.cpp + #SoundPlayer.cpp + TimeCode.cpp + ; @@ -391,6 +394,8 @@ LINKLIBS on MediaTheme.so = $(LINKLIBS) -lmedia ; LINKLIBS on PlaySound.so = $(LINKLIBS) -lmedia ; LINKLIBS on Sound.so = $(LINKLIBS) -lmedia ; LINKLIBS on SoundFile.so = $(LINKLIBS) -lmedia ; +#LINKLIBS on SoundPlayer.so = $(LINKLIBS) -lmedia ; +LINKLIBS on TimeCode.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimeSource.so = $(LINKLIBS) -lmedia ; #LINKLIBS on BufferConsumer.so = $(LINKLIBS) -lmedia ; diff --git a/bindings/__init__.py b/bindings/__init__.py index b04786d..8635ee3 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -223,6 +223,8 @@ from .PlaySound import * from .Sound import * from .SoundFile import * +#from .SoundPlayer import * +from .TimeCode import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/media/TimeCode.cpp b/bindings/media/TimeCode.cpp index a2f9a40..072478d 100644 --- a/bindings/media/TimeCode.cpp +++ b/bindings/media/TimeCode.cpp @@ -2,13 +2,31 @@ #include #include #include +#include #include namespace py = pybind11; +std::string get_timecode_info_name(const timecode_info& self) { + return std::string(self.name); +} + +void set_timecode_info_name(timecode_info& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), 32 - 1); + self.name[32 - 1] = '\0'; +} + +std::string get_timecode_info_format(const timecode_info& self) { + return std::string(self.format); +} + +void set_timecode_info_format(timecode_info& self, const std::string& format) { + std::strncpy(self.format, format.c_str(), 32 - 1); + self.name[32 - 1] = '\0'; +} -void define_TimeCode(py::module_& m) +PYBIND11_MODULE(TimeCode, m) { py::enum_(m, "timecode_type", "") .value("B_TIMECODE_DEFAULT", timecode_type::B_TIMECODE_DEFAULT, "") @@ -28,9 +46,24 @@ py::class_(m, "timecode_info") .def_readwrite("every_nth", &timecode_info::every_nth, "") .def_readwrite("except_nth", &timecode_info::except_nth, "") .def_readwrite("fps_div", &timecode_info::fps_div, "") -.def_readwrite("name", &timecode_info::name, "") -.def_readwrite("format", &timecode_info::format, "") -.def_readwrite("_reserved_", &timecode_info::_reserved_, "") +//.def_readwrite("name", &timecode_info::name, "") +.def_property("name", &get_timecode_info_name,&set_timecode_info_name,"") +//.def_readwrite("format", &timecode_info::format, "") +.def_property("format", &get_timecode_info_format,&set_timecode_info_format,"") +//.def_readwrite("_reserved_", &timecode_info::_reserved_, "") +.def_property( + "_reserved_", + [](const timecode_info &info) { + py::array_t result(64); + std::memcpy(result.mutable_data(), &info._reserved_, sizeof(info._reserved_)); + return result; + }, + [](timecode_info &info, py::array_t value) { + if (value.size() != 64) { + throw std::runtime_error("Array must have size 64"); + } + std::memcpy(&info._reserved_, value.data(), sizeof(info._reserved_)); + },"") ; py::class_(m, "BTimeCode") From 9c615be02a2168516d47a5b0b2c86fcd48ce7558 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 5 Sep 2024 21:57:05 +0200 Subject: [PATCH 066/115] Update TimedEventQueue.cpp --- Jamfile | 3 +- bindings/__init__.py | 1 + bindings/media/TimedEventQueue.cpp | 86 ++++++++++++++++++++++++------ 3 files changed, 74 insertions(+), 16 deletions(-) diff --git a/Jamfile b/Jamfile index 62de883..6ebd040 100644 --- a/Jamfile +++ b/Jamfile @@ -348,7 +348,7 @@ local sourceFiles = SoundFile.cpp #SoundPlayer.cpp TimeCode.cpp - + TimedEventQueue.cpp ; @@ -397,6 +397,7 @@ LINKLIBS on SoundFile.so = $(LINKLIBS) -lmedia ; #LINKLIBS on SoundPlayer.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimeCode.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimeSource.so = $(LINKLIBS) -lmedia ; +LINKLIBS on TimedEventQueue.so = $(LINKLIBS) -lmedia ; #LINKLIBS on BufferConsumer.so = $(LINKLIBS) -lmedia ; LINKLIBS on ScreenSaver.so = $(LINKLIBS) -lscreensaver ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 8635ee3..9edb008 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -225,6 +225,7 @@ from .SoundFile import * #from .SoundPlayer import * from .TimeCode import * +from .TimedEventQueue import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/media/TimedEventQueue.cpp b/bindings/media/TimedEventQueue.cpp index 91abaa7..9682a92 100644 --- a/bindings/media/TimedEventQueue.cpp +++ b/bindings/media/TimedEventQueue.cpp @@ -2,19 +2,28 @@ #include #include #include +#include #include namespace py = pybind11; +std::string get_media_timed_event_user_data(const media_timed_event& self) { + return std::string(self.user_data); +} + +void set_media_timed_event_user_data(media_timed_event& self, const std::string& user_data) { + std::strncpy(self.user_data, user_data.c_str(), 64 - 1); + self.user_data[64 - 1] = '\0'; +} -void define_TimedEventQueue(py::module_& m) +PYBIND11_MODULE(TimedEventQueue, m) { py::class_(m, "media_timed_event") .def(py::init(), "") -.def(py::init(), "", py::arg("inTime"), py::arg("inType")) -.def(py::init(), "", py::arg("inTime"), py::arg("inType"), py::arg("inPointer"), py::arg("inCleanup")) -.def(py::init(), "", py::arg("inTime"), py::arg("inType"), py::arg("inPointer"), py::arg("inCleanup"), py::arg("inData"), py::arg("inBigdata"), py::arg("inUserData"), py::arg("dataSize")=0) +.def(py::init(), "", py::arg("inTime"), py::arg("inType")) +.def(py::init(), "", py::arg("inTime"), py::arg("inType"), py::arg("inPointer"), py::arg("inCleanup")) +.def(py::init(), "", py::arg("inTime"), py::arg("inType"), py::arg("inPointer"), py::arg("inCleanup"), py::arg("inData"), py::arg("inBigdata"), py::arg("inUserData"), py::arg("dataSize")=0) .def(py::init(), "", py::arg("other")) .def("operator=", &media_timed_event::operator=, "", py::arg("other")) .def_readwrite("event_time", &media_timed_event::event_time, "") @@ -23,13 +32,56 @@ py::class_(m, "media_timed_event") .def_readwrite("cleanup", &media_timed_event::cleanup, "") .def_readwrite("data", &media_timed_event::data, "") .def_readwrite("bigdata", &media_timed_event::bigdata, "") -.def_readwrite("user_data", &media_timed_event::user_data, "") -.def_readwrite("_reserved_media_timed_event_", &media_timed_event::_reserved_media_timed_event_, "") +//.def_readwrite("user_data", &media_timed_event::user_data, "") +.def_property("user_data", &get_media_timed_event_user_data,&set_media_timed_event_user_data,"") +//.def_readwrite("_reserved_media_timed_event_", &media_timed_event::_reserved_media_timed_event_, "") +.def_property( + "_reserved_media_timed_event_", + [](const media_timed_event &event) { + py::array_t result(8); + std::memcpy(result.mutable_data(), &event._reserved_media_timed_event_, sizeof(event._reserved_media_timed_event_)); + return result; + }, + [](media_timed_event &event, py::array_t value) { + if (value.size() != 8) { + throw std::runtime_error("Array must have size 8"); + } + std::memcpy(&event._reserved_media_timed_event_, value.data(), sizeof(event._reserved_media_timed_event_)); + },"") ; +py::enum_(m, "event_type", "") +.value("B_NO_EVENT", BTimedEventQueue::event_type::B_NO_EVENT, "") +.value("B_ANY_EVENT", BTimedEventQueue::event_type::B_ANY_EVENT, "") +.value("B_START", BTimedEventQueue::event_type::B_START, "") +.value("B_STOP", BTimedEventQueue::event_type::B_STOP, "") +.value("B_SEEK", BTimedEventQueue::event_type::B_SEEK, "") +.value("B_WARP", BTimedEventQueue::event_type::B_WARP, "") +.value("B_TIMER", BTimedEventQueue::event_type::B_TIMER, "") +.value("B_HANDLE_BUFFER", BTimedEventQueue::event_type::B_HANDLE_BUFFER, "") +.value("B_DATA_STATUS", BTimedEventQueue::event_type::B_DATA_STATUS, "") +.value("B_HARDWARE", BTimedEventQueue::event_type::B_HARDWARE, "") +.value("B_PARAMETER", BTimedEventQueue::event_type::B_PARAMETER, "") +.value("B_USER_EVENT", BTimedEventQueue::event_type::B_USER_EVENT, "") +.export_values(); + +py::enum_(m, "cleanup_flag", "") +.value("B_NO_CLEANUP", BTimedEventQueue::cleanup_flag::B_NO_CLEANUP, "") +.value("B_RECYCLE_BUFFER", BTimedEventQueue::cleanup_flag::B_RECYCLE_BUFFER, "") +.value("B_EXPIRE_TIMER", BTimedEventQueue::cleanup_flag::B_EXPIRE_TIMER, "") +.value("B_USER_CLEANUP", BTimedEventQueue::cleanup_flag::B_USER_CLEANUP, "") +.export_values(); + +py::enum_(m, "time_direction", "") +.value("B_ALWAYS", BTimedEventQueue::time_direction::B_ALWAYS, "") +.value("B_BEFORE_TIME", BTimedEventQueue::time_direction::B_BEFORE_TIME, "") +.value("B_AT_TIME", BTimedEventQueue::time_direction::B_AT_TIME, "") +.value("B_AFTER_TIME", BTimedEventQueue::time_direction::B_AFTER_TIME, "") +.export_values(); + py::class_(m, "BTimedEventQueue") -.def("operatornew", &BTimedEventQueue::operatornew, "", py::arg("size")) -.def("operatordelete", &BTimedEventQueue::operatordelete, "", py::arg("ptr"), py::arg("size")) +//.def("operatornew", &BTimedEventQueue::operatornew, "", py::arg("size")) +//.def("operatordelete", &BTimedEventQueue::operatordelete, "", py::arg("ptr"), py::arg("size")) .def(py::init(), "") .def("AddEvent", &BTimedEventQueue::AddEvent, "", py::arg("event")) .def("RemoveEvent", &BTimedEventQueue::RemoveEvent, "", py::arg("event")) @@ -40,18 +92,22 @@ py::class_(m, "BTimedEventQueue") .def("FirstEventTime", &BTimedEventQueue::FirstEventTime, "") .def("LastEvent", &BTimedEventQueue::LastEvent, "") .def("LastEventTime", &BTimedEventQueue::LastEventTime, "") -.def("FindFirstMatch", &BTimedEventQueue::FindFirstMatch, "", py::arg("eventTime"), py::arg("direction"), py::arg("inclusive")=true, py::arg("eventType")=B_ANY_EVENT) -.def("DoForEach", &BTimedEventQueue::DoForEach, "", py::arg("hook"), py::arg("context"), py::arg("eventTime")=0, py::arg("direction")=B_ALWAYS, py::arg("inclusive")=true, py::arg("eventType")=B_ANY_EVENT) +.def("FindFirstMatch", &BTimedEventQueue::FindFirstMatch, "", py::arg("eventTime"), py::arg("direction"), py::arg("inclusive")=true, py::arg("eventType")=BTimedEventQueue::event_type::B_ANY_EVENT) +.def("DoForEach", &BTimedEventQueue::DoForEach, "", py::arg("hook"), py::arg("context"), py::arg("eventTime")=0, py::arg("direction")=BTimedEventQueue::time_direction::B_ALWAYS, py::arg("inclusive")=true, py::arg("eventType")=BTimedEventQueue::event_type::B_ANY_EVENT) .def("SetCleanupHook", &BTimedEventQueue::SetCleanupHook, "", py::arg("hook"), py::arg("context")) -.def("FlushEvents", &BTimedEventQueue::FlushEvents, "", py::arg("eventTime"), py::arg("direction"), py::arg("inclusive")=true, py::arg("eventType")=B_ANY_EVENT) +.def("FlushEvents", &BTimedEventQueue::FlushEvents, "", py::arg("eventTime"), py::arg("direction"), py::arg("inclusive")=true, py::arg("eventType")=BTimedEventQueue::event_type::B_ANY_EVENT) ; -m.def("__eq__", &operator==, "", py::arg("a"), py::arg("b")); +//m.def("__eq__", &operator==, "", py::arg("a"), py::arg("b")); +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); -m.def("__ne__", &operator!=, "", py::arg("a"), py::arg("b")); +//m.def("__ne__", &operator!=, "", py::arg("a"), py::arg("b")); +m.def("__ne__", py::overload_cast(&operator!=), "", py::arg("a"), py::arg("b")); -m.def("__lt__", &operator<, "", py::arg("a"), py::arg("b")); +//m.def("__lt__", &operator<, "", py::arg("a"), py::arg("b")); +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); -m.def("__gt__", &operator>, "", py::arg("a"), py::arg("b")); +//m.def("__gt__", &operator>, "", py::arg("a"), py::arg("b")); +m.def("__gt__", py::overload_cast(&operator>), "", py::arg("a"), py::arg("b")); } From bf44a04e17d2ed942710b3d36104d9285b3f1928 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 5 Sep 2024 22:57:56 +0200 Subject: [PATCH 067/115] use py::bytes for interoperability --- bindings/support/Flattenable.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bindings/support/Flattenable.cpp b/bindings/support/Flattenable.cpp index 6f35893..8920d94 100644 --- a/bindings/support/Flattenable.cpp +++ b/bindings/support/Flattenable.cpp @@ -14,9 +14,23 @@ py::class_(m, "BFlattenable") .def("IsFixedSize", &BFlattenable::IsFixedSize, "") .def("TypeCode", &BFlattenable::TypeCode, "") .def("FlattenedSize", &BFlattenable::FlattenedSize, "") -.def("Flatten", &BFlattenable::Flatten, "", py::arg("buffer"), py::arg("size")) +//.def("Flatten", &BFlattenable::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("Flatten", [](const BFlattenable& self) { + ssize_t size = self.FlattenedSize(); + std::vector buffer(size); + status_t status = self.Flatten(buffer.data(), size); + //if (status != B_OK) { throw std::runtime_error("Flatten failed with status: " + std::to_string(status)); } + return std::make_tuple(status,py::bytes(buffer.data(), size)); +},"") .def("AllowsTypeCode", &BFlattenable::AllowsTypeCode, "", py::arg("code")) -.def("Unflatten", &BFlattenable::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +//.def("Unflatten", &BFlattenable::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +.def("Unflatten", [](BFlattenable& self, type_code code, py::bytes data) { + // Convert py::bytes to a void* buffer + std::string buffer = data; // py::bytes can be directly assigned to std::string + ssize_t size = buffer.size(); + status_t status = self.Unflatten(code, buffer.data(), size); + //if (status != B_OK) { throw std::runtime_error("Unflatten failed with status: " + std::to_string(status)); } + return status; },"",py::arg("code"),py::arg("data")) ; From bedab13847719aea4a7048ef5b9da9d883c30183 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 6 Sep 2024 09:51:45 +0200 Subject: [PATCH 068/115] update GridLayoutBuilder and InterfaceDefs --- bindings/interface/GridLayoutBuilder.cpp | 18 ++++++++--- bindings/interface/InterfaceDefs.cpp | 38 ++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/bindings/interface/GridLayoutBuilder.cpp b/bindings/interface/GridLayoutBuilder.cpp index 0af86d3..413e0b2 100644 --- a/bindings/interface/GridLayoutBuilder.cpp +++ b/bindings/interface/GridLayoutBuilder.cpp @@ -12,14 +12,24 @@ namespace py = pybind11; PYBIND11_MODULE(GridLayoutBuilder,m) { py::class_(m, "BGridLayoutBuilder") -//.def(py::init(), "", py::arg("horizontal")=B_USE_DEFAULT_SPACING, py::arg("vertical")=B_USE_DEFAULT_SPACING) -.def(py::init(), "", py::arg("horizontal")=-1002, py::arg("vertical")=-1002) +.def(py::init(), "", py::arg("horizontal")=B_USE_DEFAULT_SPACING, py::arg("vertical")=B_USE_DEFAULT_SPACING) +//.def(py::init(), "", py::arg("horizontal")=-1002, py::arg("vertical")=-1002) .def(py::init(), "", py::arg("layout")) .def(py::init(), "", py::arg("view")) .def("GridLayout", &BGridLayoutBuilder::GridLayout, "") -//.def("GetGridLayout", &BGridLayoutBuilder::GetGridLayout, "", py::arg("_layout")) //TODO +//.def("GetGridLayout", &BGridLayoutBuilder::GetGridLayout, "", py::arg("_layout")) //TODO check this +.def("GetGridLayout", [](BGridLayoutBuilder &self) { + BGridLayout* layout = nullptr; + self.GetGridLayout(&layout); + return std::make_tuple(std::ref(self), layout); + },"") .def("View", &BGridLayoutBuilder::View, "") -//.def("GetView", &BGridLayoutBuilder::GetView, "", py::arg("_view")) // TODO +//.def("GetView", &BGridLayoutBuilder::GetView, "", py::arg("_view")) // TODO check this +.def("GetView", [](BGridLayoutBuilder &self) { + BView* view = nullptr; + self.GetView(&view); + return std::make_tuple(std::ref(self), view); + },"") .def("Add", py::overload_cast(&BGridLayoutBuilder::Add), "", py::arg("view"), py::arg("column"), py::arg("row"), py::arg("columnCount")=1, py::arg("rowCount")=1) .def("Add", py::overload_cast(&BGridLayoutBuilder::Add), "", py::arg("item"), py::arg("column"), py::arg("row"), py::arg("columnCount")=1, py::arg("rowCount")=1) .def("SetColumnWeight", &BGridLayoutBuilder::SetColumnWeight, "", py::arg("column"), py::arg("weight")) diff --git a/bindings/interface/InterfaceDefs.cpp b/bindings/interface/InterfaceDefs.cpp index 88b0033..4121527 100644 --- a/bindings/interface/InterfaceDefs.cpp +++ b/bindings/interface/InterfaceDefs.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -170,7 +171,7 @@ m.attr("B_USE_BIG_INSETS") = "B_USE_BIG_SPACING"; m.attr("B_USE_BORDER_SPACING") = "- 1009"; m.attr("B_USE_BORDER_INSETS") = "B_USE_BORDER_SPACING"; */ - +/* m.attr("B_USE_DEFAULT_SPACING") = -1002; m.attr("B_USE_ITEM_SPACING") = -1003; m.attr("B_USE_ITEM_INSETS") = -1003; @@ -186,6 +187,25 @@ m.attr("B_USE_BIG_SPACING") = -1008; m.attr("B_USE_BIG_INSETS") = -1008; m.attr("B_USE_BORDER_SPACING") = -1009; m.attr("B_USE_BORDER_INSETS") = -1009; +*/ +py::enum_(m, "BSpacing", "") +.value("B_USE_DEFAULT_SPACING", BSpacing::B_USE_DEFAULT_SPACING, "") +.value("B_USE_ITEM_SPACING", BSpacing::B_USE_ITEM_SPACING, "") +.value("B_USE_ITEM_INSETS", BSpacing::B_USE_ITEM_INSETS, "") +.value("B_USE_HALF_ITEM_SPACING", BSpacing::B_USE_HALF_ITEM_SPACING, "") +.value("B_USE_HALF_ITEM_INSETS", BSpacing::B_USE_HALF_ITEM_INSETS, "") +.value("B_USE_WINDOW_SPACING", BSpacing::B_USE_WINDOW_SPACING, "") +.value("B_USE_WINDOW_INSETS", BSpacing::B_USE_WINDOW_INSETS, "") +.value("B_USE_SMALL_SPACING", BSpacing::B_USE_SMALL_SPACING, "") +.value("B_USE_SMALL_INSETS", BSpacing::B_USE_SMALL_INSETS, "") +.value("B_USE_CORNER_SPACING", BSpacing::B_USE_CORNER_SPACING, "") +.value("B_USE_CORNER_INSETS", BSpacing::B_USE_CORNER_INSETS, "") +.value("B_USE_BIG_SPACING", BSpacing::B_USE_BIG_SPACING, "") +.value("B_USE_BIG_INSETS", BSpacing::B_USE_BIG_INSETS, "") +.value("B_USE_BORDER_SPACING", BSpacing::B_USE_BORDER_SPACING, "") +.value("B_USE_BORDER_INSETS", BSpacing::B_USE_BORDER_INSETS, "") +.export_values(); + py::enum_(m, "join_mode", "") .value("B_ROUND_JOIN", join_mode::B_ROUND_JOIN, "") @@ -326,7 +346,7 @@ py::class_(m, "key_map") .def_readwrite("right_option_key", &key_map::right_option_key, "") .def_readwrite("menu_key", &key_map::menu_key, "") .def_readwrite("lock_settings", &key_map::lock_settings, "") -// TODO are these read-only? +// TODO are these read-only? //If no, look down at mouse_map and try that .def_readonly("control_map", &key_map::control_map, "") .def_readonly("option_caps_shift_map", &key_map::option_caps_shift_map, "") .def_readonly("option_caps_map", &key_map::option_caps_map, "") @@ -349,7 +369,19 @@ py::class_(m, "key_map") ; py::class_(m, "mouse_map") -.def_readonly("button", &mouse_map::button, "") +//.def_readonly("button", &mouse_map::button, "") +.def_property("button", + [](const mouse_map &mappa) { + py::array_t result(16);//B_MAX_MOUSE_BUTTONS = 16 + std::memcpy(result.mutable_data(), &mappa.button, sizeof(mappa.button)); + return result; + }, + [](mouse_map &mappa, py::array_t value) { + if (value.size() != 16) { + throw std::runtime_error("Array must have size 16"); + } + std::memcpy(&mappa.button, value.data(), sizeof(mappa.button)); + },"") ; py::class_(m, "scroll_bar_info") From 43a97e46442439017bdc84e5862eb923fd8b0d31 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 6 Sep 2024 15:26:02 +0200 Subject: [PATCH 069/115] Update Layout.cpp, avoid hardcoded values on GridView init --- Jamfile | 1 + bindings/interface/GridView.cpp | 8 +-- bindings/interface/Layout.cpp | 109 +++++++++++++++++++++++++++++++- 3 files changed, 113 insertions(+), 5 deletions(-) diff --git a/Jamfile b/Jamfile index 6ebd040..e03d449 100644 --- a/Jamfile +++ b/Jamfile @@ -374,6 +374,7 @@ LINKLIBS on LocaleRoster.so = $(LINKLIBS) -llocalestub ; #LINKLIBS on CatalogData.so = $(LINKLIBS) -llocalestub ; #LINKLIBS on TimeFormat.so = $(LINKLIBS) -lsupport ; + LINKLIBS on Buffer.so = $(LINKLIBS) -lmedia ; LINKLIBS on BufferGroup.so = $(LINKLIBS) -lmedia ; LINKLIBS on BufferProducer.so = $(LINKLIBS) -lmedia ; diff --git a/bindings/interface/GridView.cpp b/bindings/interface/GridView.cpp index 7456965..7027f56 100644 --- a/bindings/interface/GridView.cpp +++ b/bindings/interface/GridView.cpp @@ -24,10 +24,10 @@ class PyBGridView : public BGridView{ PYBIND11_MODULE(GridView,m) { py::class_(m, "BGridView") -//.def(py::init(), "", py::arg("horizontal")=B_USE_DEFAULT_SPACING, py::arg("vertical")=B_USE_DEFAULT_SPACING) -.def(py::init(), "", py::arg("horizontal")=-1002, py::arg("vertical")=-1002) -//.def(py::init(), "", py::arg("name"), py::arg("horizontal")=B_USE_DEFAULT_SPACING, py::arg("vertical")=B_USE_DEFAULT_SPACING) -.def(py::init(), "", py::arg("name"), py::arg("horizontal")=-1002, py::arg("vertical")=-1002) +.def(py::init(), "", py::arg("horizontal")=B_USE_DEFAULT_SPACING, py::arg("vertical")=B_USE_DEFAULT_SPACING) +//.def(py::init(), "", py::arg("horizontal")=-1002, py::arg("vertical")=-1002) +.def(py::init(), "", py::arg("name"), py::arg("horizontal")=B_USE_DEFAULT_SPACING, py::arg("vertical")=B_USE_DEFAULT_SPACING) +//.def(py::init(), "", py::arg("name"), py::arg("horizontal")=-1002, py::arg("vertical")=-1002) .def(py::init(), "", py::arg("from")) .def("SetLayout", &BGridView::SetLayout, "", py::arg("layout")) .def("GridLayout", &BGridView::GridLayout, "") diff --git a/bindings/interface/Layout.cpp b/bindings/interface/Layout.cpp index d32b861..1fc1c6c 100644 --- a/bindings/interface/Layout.cpp +++ b/bindings/interface/Layout.cpp @@ -14,8 +14,115 @@ namespace py = pybind11; +class PyBLayout : public BLayout{ + public: + using BLayout::BLayout; + BView* View() override { + PYBIND11_OVERLOAD(BView*, BLayout, View); + } + BLayoutItem* AddView(BView* child) override { + PYBIND11_OVERLOAD(BLayoutItem*, BLayout, AddView, child); + } + BLayoutItem* AddView(int32 index, BView* child) override { + PYBIND11_OVERLOAD(BLayoutItem*, BLayout, AddView, index, child); + } + bool AddItem(BLayoutItem* item) override { + PYBIND11_OVERLOAD(bool, BLayout, AddItem, item); + } + bool AddItem(int32 index, BLayoutItem* item) override { + PYBIND11_OVERLOAD(bool, BLayout, AddItem, index, item); + } + bool RemoveView(BView* child) override { + PYBIND11_OVERLOAD(bool, BLayout, RemoveView, child); + } + bool RemoveItem(BLayoutItem* item) override { + PYBIND11_OVERLOAD(bool, BLayout, RemoveItem, item); + } + BLayoutItem* RemoveItem(int32 index) override { + PYBIND11_OVERLOAD(BLayoutItem*, BLayout, RemoveItem, index); + } + void InvalidateLayout(bool children = false) override { + PYBIND11_OVERLOAD(void, BLayout, InvalidateLayout, children); + } + void Relayout(bool immediate = false) override { + PYBIND11_OVERLOAD(void, BLayout, Relayout, immediate); + } + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BLayout, Archive, into, deep); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BLayout, Perform, d, arg); + } + BSize MinSize() override { + PYBIND11_OVERLOAD_PURE(BSize, BLayout, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD_PURE(BSize, BLayout, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD_PURE(BSize, BLayout, PreferredSize); + } + BAlignment Alignment() override { + PYBIND11_OVERLOAD_PURE(BAlignment, BLayout, Alignment); + } + void SetExplicitMinSize(BSize size) override { + PYBIND11_OVERLOAD_PURE(void, BLayout, SetExplicitMinSize, size); + } + void SetExplicitMaxSize(BSize size) override { + PYBIND11_OVERLOAD_PURE(void, BLayout, SetExplicitMaxSize, size); + } + void SetExplicitPreferredSize(BSize size) override { + PYBIND11_OVERLOAD_PURE(void, BLayout, SetExplicitPreferredSize, size); + } + void SetExplicitAlignment(BAlignment alignment) override { + PYBIND11_OVERLOAD_PURE(void, BLayout, SetExplicitAlignment, alignment); + } + bool IsVisible() override { + PYBIND11_OVERLOAD_PURE(bool, BLayout, IsVisible); + } + void SetVisible(bool visible) override { + PYBIND11_OVERLOAD_PURE(void, BLayout, SetVisible, visible); + } + BRect Frame() override { + PYBIND11_OVERLOAD_PURE(BRect, BLayout, Frame); + } + void SetFrame(BRect frame) override { + PYBIND11_OVERLOAD_PURE(void, BLayout, SetFrame, frame); + } + void DoLayout() override { + PYBIND11_OVERLOAD_PURE(void, BLayout, DoLayout); + } +}; PYBIND11_MODULE(Layout,m) { -py::class_(m, "BLayout"); +py::class_(m, "BLayout") +.def(py::init(), "") +.def(py::init(), "", py::arg("archive")) +.def("Owner", &BLayout::Owner, "") +.def("TargetView", &BLayout::TargetView, "") +.def("View", &BLayout::View, "") +.def("AddView", py::overload_cast(&BLayout::AddView), "", py::arg("child")) +.def("AddView", py::overload_cast(&BLayout::AddView), "", py::arg("index"), py::arg("child")) +.def("AddItem", py::overload_cast(&BLayout::AddItem), "", py::arg("item")) +.def("AddItem", py::overload_cast(&BLayout::AddItem), "", py::arg("index"), py::arg("item")) +.def("RemoveView", &BLayout::RemoveView, "", py::arg("child")) +.def("RemoveItem", py::overload_cast(&BLayout::RemoveItem), "", py::arg("item")) +.def("RemoveItem", py::overload_cast(&BLayout::RemoveItem), "", py::arg("index")) +.def("ItemAt", &BLayout::ItemAt, "", py::arg("index")) +.def("CountItems", &BLayout::CountItems, "") +.def("IndexOfItem", &BLayout::IndexOfItem, "", py::arg("item")) +.def("IndexOfView", &BLayout::IndexOfView, "", py::arg("child")) +.def("AncestorsVisible", &BLayout::AncestorsVisible, "") +.def("InvalidateLayout", &BLayout::InvalidateLayout, "", py::arg("children")=false) +.def("Relayout", &BLayout::Relayout, "", py::arg("immediate")=false) +.def("RequireLayout", &BLayout::RequireLayout, "") +.def("IsValid", &BLayout::IsValid, "") +.def("EnableLayoutInvalidation", &BLayout::EnableLayoutInvalidation, "") +.def("DisableLayoutInvalidation", &BLayout::DisableLayoutInvalidation, "") +.def("LayoutItems", &BLayout::LayoutItems, "", py::arg("force")=false) +.def("LayoutArea", &BLayout::LayoutArea, "") +.def("LayoutContext", &BLayout::LayoutContext, "") +.def("Archive", &BLayout::Archive, "", py::arg("into"), py::arg("deep")=true) +.def("Perform", &BLayout::Perform, "", py::arg("d"), py::arg("arg")); } From 1335741c910c8a54ca704d798f42856060eef4f3 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 6 Sep 2024 15:40:06 +0200 Subject: [PATCH 070/115] avoid hardoded value for B_USE_DEFAULT_SPACING --- bindings/interface/GridLayout.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindings/interface/GridLayout.cpp b/bindings/interface/GridLayout.cpp index 60453f9..99208fe 100644 --- a/bindings/interface/GridLayout.cpp +++ b/bindings/interface/GridLayout.cpp @@ -44,7 +44,8 @@ PYBIND11_MODULE(GridLayout,m) { py::class_>(m, "BGridLayout") // ImportError: arg(): could not convert default argument 'horizontal: ._anon_253' in method '.__init__' into a Python object (type not registered yet?) -.def(py::init(), "", py::arg("horizontal")=py::int_(-1002), py::arg("vertical")=py::int_(-1002)) +//.def(py::init(), "", py::arg("horizontal")=py::int_(-1002), py::arg("vertical")=py::int_(-1002)) +.def(py::init(), "", py::arg("horizontal")=B_USE_DEFAULT_SPACING, py::arg("vertical")=B_USE_DEFAULT_SPACING) .def(py::init(), "", py::arg("from")) .def("CountColumns", &BGridLayout::CountColumns, "") .def("CountRows", &BGridLayout::CountRows, "") From ea781217648b2f8519f94a2c4d4cd9940c8889d0 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 6 Sep 2024 16:15:38 +0200 Subject: [PATCH 071/115] update AbstractLayout TwoDimensionalLayout and overrides abstract-classes --- bindings/interface/AbstractLayout.cpp | 25 ++++++++- bindings/interface/TwoDimensionalLayout.cpp | 62 ++++++++++++++++++++- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/bindings/interface/AbstractLayout.cpp b/bindings/interface/AbstractLayout.cpp index 7a26d6e..c95a416 100644 --- a/bindings/interface/AbstractLayout.cpp +++ b/bindings/interface/AbstractLayout.cpp @@ -67,9 +67,32 @@ class PyBAbstractLayout : public BAbstractLayout{ status_t Perform(perform_code d, void* arg) override { PYBIND11_OVERLOAD(status_t, BAbstractLayout, Perform, d, arg); } + void DoLayout() override { + PYBIND11_OVERLOAD_PURE(void, BAbstractLayout, DoLayout); + } }; PYBIND11_MODULE(AbstractLayout,m) { -py::class_(m, "BAbstractLayout"); +py::class_(m, "BAbstractLayout") +.def(py::init(), "") +.def(py::init(), "", py::arg("from")) +.def("MinSize", &BAbstractLayout::MinSize, "") +.def("MaxSize", &BAbstractLayout::MaxSize, "") +.def("PreferredSize", &BAbstractLayout::PreferredSize, "") +.def("Alignment", &BAbstractLayout::Alignment, "") +.def("SetExplicitMinSize", &BAbstractLayout::SetExplicitMinSize, "", py::arg("size")) +.def("SetExplicitMaxSize", &BAbstractLayout::SetExplicitMaxSize, "", py::arg("size")) +.def("SetExplicitPreferredSize", &BAbstractLayout::SetExplicitPreferredSize, "", py::arg("size")) +.def("SetExplicitAlignment", &BAbstractLayout::SetExplicitAlignment, "", py::arg("alignment")) +.def("BaseMinSize", &BAbstractLayout::BaseMinSize, "") +.def("BaseMaxSize", &BAbstractLayout::BaseMaxSize, "") +.def("BasePreferredSize", &BAbstractLayout::BasePreferredSize, "") +.def("BaseAlignment", &BAbstractLayout::BaseAlignment, "") +.def("Frame", &BAbstractLayout::Frame, "") +.def("SetFrame", &BAbstractLayout::SetFrame, "", py::arg("frame")) +.def("IsVisible", &BAbstractLayout::IsVisible, "") +.def("SetVisible", &BAbstractLayout::SetVisible, "", py::arg("visible")) +.def("Archive", &BAbstractLayout::Archive, "", py::arg("into"), py::arg("deep")=true) +.def("Perform", &BAbstractLayout::Perform, "", py::arg("d"), py::arg("arg")); } diff --git a/bindings/interface/TwoDimensionalLayout.cpp b/bindings/interface/TwoDimensionalLayout.cpp index 7476e90..d99d086 100644 --- a/bindings/interface/TwoDimensionalLayout.cpp +++ b/bindings/interface/TwoDimensionalLayout.cpp @@ -8,8 +8,68 @@ namespace py = pybind11; +class PyBTwoDimensionalLayout : public BTwoDimensionalLayout{ + public: + using BTwoDimensionalLayout::BTwoDimensionalLayout; + BSize BaseMinSize() override { + PYBIND11_OVERLOAD(BSize, BTwoDimensionalLayout, BaseMinSize); + } + BSize BaseMaxSize() override { + PYBIND11_OVERLOAD(BSize, BTwoDimensionalLayout, BaseMaxSize); + } + BSize BasePreferredSize() override { + PYBIND11_OVERLOAD(BSize, BTwoDimensionalLayout, BasePreferredSize); + } + BAlignment BaseAlignment() override { + PYBIND11_OVERLOAD(BAlignment, BTwoDimensionalLayout, BaseAlignment); + } + bool HasHeightForWidth() override { + PYBIND11_OVERLOAD(bool, BTwoDimensionalLayout, HasHeightForWidth); + } + void GetHeightForWidth(float width, float* min, float* max, float* preferred) override { + PYBIND11_OVERLOAD(void, BTwoDimensionalLayout, GetHeightForWidth, width, min, max, preferred); + } + void SetFrame(BRect frame) override { + PYBIND11_OVERLOAD(void, BTwoDimensionalLayout, SetFrame, frame); + } + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BTwoDimensionalLayout, Archive, into, deep); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BTwoDimensionalLayout, Perform, d, arg); + } + int32 InternalCountColumns() override { + PYBIND11_OVERLOAD_PURE(int32, BTwoDimensionalLayout, InternalCountColumns); + } + int32 InternalCountRows() override { + PYBIND11_OVERLOAD_PURE(int32, BTwoDimensionalLayout, InternalCountRows); + } + void GetColumnRowConstraints(orientation orientation, int32 index, ColumnRowConstraints* constraints) override { + PYBIND11_OVERLOAD_PURE(void, BTwoDimensionalLayout, GetColumnRowConstraints, orientation, index, constraints); + } + void GetItemDimensions(BLayoutItem* item, Dimensions* dimensions) override { + PYBIND11_OVERLOAD_PURE(void, BTwoDimensionalLayout, GetItemDimensions, item, dimensions); + } +}; PYBIND11_MODULE(TwoDimensionalLayout,m) { -py::class_(m, "BTwoDimensionalLayout"); +py::class_(m, "BTwoDimensionalLayout") +.def(py::init(), "") +.def(py::init(), "", py::arg("from")) +.def("SetInsets", py::overload_cast(&BTwoDimensionalLayout::SetInsets), "", py::arg("left"), py::arg("top"), py::arg("right"), py::arg("bottom")) +.def("SetInsets", py::overload_cast(&BTwoDimensionalLayout::SetInsets), "", py::arg("horizontal"), py::arg("vertical")) +.def("SetInsets", py::overload_cast(&BTwoDimensionalLayout::SetInsets), "", py::arg("insets")) +.def("GetInsets", &BTwoDimensionalLayout::GetInsets, "", py::arg("left"), py::arg("top"), py::arg("right"), py::arg("bottom")) +.def("AlignLayoutWith", &BTwoDimensionalLayout::AlignLayoutWith, "", py::arg("other"), py::arg("orientation")) +.def("BaseMinSize", &BTwoDimensionalLayout::BaseMinSize, "") +.def("BaseMaxSize", &BTwoDimensionalLayout::BaseMaxSize, "") +.def("BasePreferredSize", &BTwoDimensionalLayout::BasePreferredSize, "") +.def("BaseAlignment", &BTwoDimensionalLayout::BaseAlignment, "") +.def("HasHeightForWidth", &BTwoDimensionalLayout::HasHeightForWidth, "") +.def("GetHeightForWidth", &BTwoDimensionalLayout::GetHeightForWidth, "", py::arg("width"), py::arg("min"), py::arg("max"), py::arg("preferred")) +.def("SetFrame", &BTwoDimensionalLayout::SetFrame, "", py::arg("frame")) +.def("Archive", &BTwoDimensionalLayout::Archive, "", py::arg("into"), py::arg("deep")=true) +.def("Perform", &BTwoDimensionalLayout::Perform, "", py::arg("d"), py::arg("arg")) +; } From 26f20f9c29effaf15e687199f8ca6f4ade965473 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 6 Sep 2024 16:27:25 +0200 Subject: [PATCH 072/115] update LayoutItem and overrides --- bindings/interface/LayoutItem.cpp | 91 ++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/bindings/interface/LayoutItem.cpp b/bindings/interface/LayoutItem.cpp index d886c57..83f68c6 100644 --- a/bindings/interface/LayoutItem.cpp +++ b/bindings/interface/LayoutItem.cpp @@ -13,8 +13,97 @@ namespace py = pybind11; +class PyBLayoutItem : public BLayoutItem{ + public: + using BLayoutItem::BLayoutItem; + BSize MinSize() override { + PYBIND11_OVERLOAD_PURE(BSize, BLayoutItem, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD_PURE(BSize, BLayoutItem, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD_PURE(BSize, BLayoutItem, PreferredSize); + } + BAlignment Alignment() override { + PYBIND11_OVERLOAD_PURE(BAlignment, BLayoutItem, Alignment); + } + void SetExplicitMinSize(BSize size) override { + PYBIND11_OVERLOAD_PURE(void, BLayoutItem, SetExplicitMinSize, size); + } + void SetExplicitMaxSize(BSize size) override { + PYBIND11_OVERLOAD_PURE(void, BLayoutItem, SetExplicitMaxSize, size); + } + void SetExplicitPreferredSize(BSize size) override { + PYBIND11_OVERLOAD_PURE(void, BLayoutItem, SetExplicitPreferredSize, size); + } + void SetExplicitAlignment(BAlignment alignment) override { + PYBIND11_OVERLOAD_PURE(void, BLayoutItem, SetExplicitAlignment, alignment); + } + bool IsVisible() override { + PYBIND11_OVERLOAD_PURE(bool, BLayoutItem, IsVisible); + } + void SetVisible(bool visible) override { + PYBIND11_OVERLOAD_PURE(void, BLayoutItem, SetVisible, visible); + } + BRect Frame() override { + PYBIND11_OVERLOAD_PURE(BRect, BLayoutItem, Frame); + } + void SetFrame(BRect frame) override { + PYBIND11_OVERLOAD_PURE(void, BLayoutItem, SetFrame, frame); + } + bool HasHeightForWidth() override { + PYBIND11_OVERLOAD(bool, BLayoutItem, HasHeightForWidth); + } + void GetHeightForWidth(float width, float* min, float* max, float* preferred) override { + PYBIND11_OVERLOAD(void, BLayoutItem, GetHeightForWidth, width, min, max, preferred); + } + BView* View() override { + PYBIND11_OVERLOAD(BView*, BLayoutItem, View); + } + void InvalidateLayout(bool children = false) override { + PYBIND11_OVERLOAD(void, BLayoutItem, InvalidateLayout, children); + } + void Relayout(bool immediate = false) override { + PYBIND11_OVERLOAD(void, BLayoutItem, Relayout, immediate); + } + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BLayoutItem, Archive, into, deep); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BLayoutItem, Perform, d, arg); + } +}; PYBIND11_MODULE(LayoutItem,m) { -py::class_>(m, "BLayoutItem"); +py::class_>(m, "BLayoutItem") +.def(py::init(), "") +.def(py::init(), "", py::arg("from")) +.def("Layout", &BLayoutItem::Layout, "") +.def("RemoveSelf", &BLayoutItem::RemoveSelf, "") +.def("MinSize", &BLayoutItem::MinSize, "") +.def("MaxSize", &BLayoutItem::MaxSize, "") +.def("PreferredSize", &BLayoutItem::PreferredSize, "") +.def("Alignment", &BLayoutItem::Alignment, "") +.def("SetExplicitMinSize", &BLayoutItem::SetExplicitMinSize, "", py::arg("size")) +.def("SetExplicitMaxSize", &BLayoutItem::SetExplicitMaxSize, "", py::arg("size")) +.def("SetExplicitPreferredSize", &BLayoutItem::SetExplicitPreferredSize, "", py::arg("size")) +.def("SetExplicitSize", &BLayoutItem::SetExplicitSize, "", py::arg("size")) +.def("SetExplicitAlignment", &BLayoutItem::SetExplicitAlignment, "", py::arg("alignment")) +.def("IsVisible", &BLayoutItem::IsVisible, "") +.def("SetVisible", &BLayoutItem::SetVisible, "", py::arg("visible")) +.def("Frame", &BLayoutItem::Frame, "") +.def("SetFrame", &BLayoutItem::SetFrame, "", py::arg("frame")) +.def("HasHeightForWidth", &BLayoutItem::HasHeightForWidth, "") +.def("GetHeightForWidth", &BLayoutItem::GetHeightForWidth, "", py::arg("width"), py::arg("min"), py::arg("max"), py::arg("preferred")) +.def("View", &BLayoutItem::View, "") +.def("InvalidateLayout", &BLayoutItem::InvalidateLayout, "", py::arg("children")=false) +.def("Relayout", &BLayoutItem::Relayout, "", py::arg("immediate")=false) +.def("LayoutData", &BLayoutItem::LayoutData, "") +.def("SetLayoutData", &BLayoutItem::SetLayoutData, "", py::arg("data")) +.def("AlignInFrame", &BLayoutItem::AlignInFrame, "", py::arg("frame")) +.def("Archive", &BLayoutItem::Archive, "", py::arg("into"), py::arg("deep")=true) +.def("Perform", &BLayoutItem::Perform, "", py::arg("d"), py::arg("arg")) +; } From 07dca4278590f93cedb370ee9d6c265a0a024ac5 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 6 Sep 2024 16:31:33 +0200 Subject: [PATCH 073/115] update LayoutContext.cpp --- bindings/interface/LayoutContext.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/interface/LayoutContext.cpp b/bindings/interface/LayoutContext.cpp index 220d56b..a46ab28 100644 --- a/bindings/interface/LayoutContext.cpp +++ b/bindings/interface/LayoutContext.cpp @@ -20,9 +20,9 @@ class PyBLayoutContextListener : public BLayoutContextListener { PYBIND11_MODULE(LayoutContext,m) { -py::class_(m, "BLayoutContextListener") -//.def(py::init(), "") -//.def("LayoutContextLeft", &BLayoutContextListener::LayoutContextLeft, "", py::arg("context")) +py::class_(m, "BLayoutContextListener") +.def(py::init(), "") +.def("LayoutContextLeft", &BLayoutContextListener::LayoutContextLeft, "", py::arg("context")) ; py::class_(m, "BLayoutContext") From 6af46b35e17d26b05afa22bf7827eaa00e8eedfb Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 6 Sep 2024 16:42:56 +0200 Subject: [PATCH 074/115] fix and update GroupLayoutBuilder.cpp --- bindings/interface/GroupLayoutBuilder.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/bindings/interface/GroupLayoutBuilder.cpp b/bindings/interface/GroupLayoutBuilder.cpp index 6825f28..dbfe39a 100644 --- a/bindings/interface/GroupLayoutBuilder.cpp +++ b/bindings/interface/GroupLayoutBuilder.cpp @@ -14,21 +14,31 @@ namespace py = pybind11; PYBIND11_MODULE(GroupLayoutBuilder,m) { py::class_(m, "BGroupLayoutBuilder") -//.def(py::init(), "", py::arg("orientation")=B_HORIZONTAL, py::arg("spacing")=B_USE_DEFAULT_SPACING) -.def(py::init(), "", py::arg("orientation")=B_HORIZONTAL, py::arg("spacing")=-1002) +.def(py::init(), "", py::arg("orientation")=B_HORIZONTAL, py::arg("spacing")=B_USE_DEFAULT_SPACING) +//.def(py::init(), "", py::arg("orientation")=B_HORIZONTAL, py::arg("spacing")=-1002) .def(py::init(), "", py::arg("layout")) .def(py::init(), "", py::arg("view")) .def("RootLayout", &BGroupLayoutBuilder::RootLayout, "") .def("TopLayout", &BGroupLayoutBuilder::TopLayout, "") //.def("GetTopLayout", &BGroupLayoutBuilder::GetTopLayout, "", py::arg("_layout")) //TODO +.def("GetTopLayout", [](BGroupLayoutBuilder &self){ + BGroupLayout* layout = nullptr; + self.GetTopLayout(&layout); + return std::make_tuple(std::ref(self), layout); +},"") .def("TopView", &BGroupLayoutBuilder::TopView, "") //.def("GetTopView", &BGroupLayoutBuilder::GetTopView, "", py::arg("_view")) //TODO +.def("GetTopView", [](BGroupLayoutBuilder &self) { + BView* view = nullptr; + self.GetTopView(&view); + return std::make_tuple(std::ref(self), view); + },"") .def("Add", py::overload_cast(&BGroupLayoutBuilder::Add), "", py::arg("view")) .def("Add", py::overload_cast(&BGroupLayoutBuilder::Add), "", py::arg("view"), py::arg("weight")) .def("Add", py::overload_cast(&BGroupLayoutBuilder::Add), "", py::arg("item")) .def("Add", py::overload_cast(&BGroupLayoutBuilder::Add), "", py::arg("item"), py::arg("weight")) -//.def("AddGroup", &BGroupLayoutBuilder::AddGroup, "", py::arg("orientation"), py::arg("spacing")=B_USE_DEFAULT_SPACING, py::arg("weight")=1.0 f) -.def("AddGroup", &BGroupLayoutBuilder::AddGroup, "", py::arg("orientation"), py::arg("spacing")=-1002, py::arg("weight")=1.0f) +.def("AddGroup", &BGroupLayoutBuilder::AddGroup, "", py::arg("orientation"), py::arg("spacing")=B_USE_DEFAULT_SPACING, py::arg("weight")=1.0f) +//.def("AddGroup", &BGroupLayoutBuilder::AddGroup, "", py::arg("orientation"), py::arg("spacing")=-1002, py::arg("weight")=1.0f) .def("End", &BGroupLayoutBuilder::End, "") .def("AddGlue", &BGroupLayoutBuilder::AddGlue, "", py::arg("weight")=1.0f) .def("AddStrut", &BGroupLayoutBuilder::AddStrut, "", py::arg("size")) From 1d8bbbb7a11813bb0152457be406c8c7f38a8cf9 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 6 Sep 2024 20:17:32 +0200 Subject: [PATCH 075/115] Add wildcards --- bindings/media/MediaDefs.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bindings/media/MediaDefs.cpp b/bindings/media/MediaDefs.cpp index 9154964..acaf890 100644 --- a/bindings/media/MediaDefs.cpp +++ b/bindings/media/MediaDefs.cpp @@ -223,6 +223,7 @@ py::class_(m, "media_raw_audio_format") .def_readwrite("byte_order", &media_raw_audio_format::byte_order, "") .def_readwrite("buffer_size", &media_raw_audio_format::buffer_size, "") //.def_readwrite("wildcard", &media_raw_audio_format::wildcard, "") +.def_static("wildcard", []() { return media_raw_audio_format::wildcard; }) ; py::class_(m, "media_audio_header") @@ -266,6 +267,7 @@ py::class_(m, "media_multi_audio_info") py::class_(m, "media_multi_audio_format") //.def_readwrite("wildcard", &media_multi_audio_format::wildcard, "") +.def_static("wildcard", []() { return media_multi_audio_format::wildcard; }) ; py::class_(m, "media_encoded_audio_format") @@ -289,6 +291,7 @@ py::class_(m, "media_encoded_audio_format") std::memcpy(&format._reserved_, value.data(), sizeof(format._reserved_)); },"") //.def_readwrite("wildcard", &media_encoded_audio_format::wildcard, "") +.def_static("wildcard", []() { return media_encoded_audio_format::wildcard; }) ; py::class_(m, "media_encoded_audio_header") @@ -347,6 +350,7 @@ py::class_(m, "media_video_display_info") std::memcpy(&info._reserved_, value.data(), sizeof(info._reserved_)); },"") //.def_readwrite("wildcard", &media_video_display_info::wildcard, "") +.def_static("wildcard", []() { return media_video_display_info::wildcard; }) ; py::class_(m, "media_raw_video_format") @@ -359,6 +363,7 @@ py::class_(m, "media_raw_video_format") .def_readwrite("pixel_height_aspect", &media_raw_video_format::pixel_height_aspect, "") .def_readwrite("display", &media_raw_video_format::display, "") //.def_readwrite("wildcard", &media_raw_video_format::wildcard, "") +.def_static("wildcard", []() { return media_raw_video_format::wildcard; }) ; py::class_(m, "media_video_header") @@ -412,6 +417,7 @@ py::class_(m, "media_encoded_video_format") std::memcpy(&format._reserved_, value.data(), sizeof(format._reserved_)); },"") //.def_readwrite("wildcard", &media_encoded_video_format::wildcard, "") +.def_static("wildcard", []() { return media_encoded_video_format::wildcard; }) ; py::class_(m, "media_encoded_video_header") From 259e6f360482afcef1cd180f0704001bda9cf005 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 6 Sep 2024 21:47:35 +0200 Subject: [PATCH 076/115] update SoundPlayer.cpp, Fix init, exception --- Jamfile | 4 +-- bindings/__init__.py | 2 +- bindings/media/SoundPlayer.cpp | 59 +++++++++++++++++++++++++++------- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/Jamfile b/Jamfile index e03d449..0d47197 100644 --- a/Jamfile +++ b/Jamfile @@ -346,7 +346,7 @@ local sourceFiles = PlaySound.cpp Sound.cpp SoundFile.cpp - #SoundPlayer.cpp + SoundPlayer.cpp TimeCode.cpp TimedEventQueue.cpp @@ -395,7 +395,7 @@ LINKLIBS on MediaTheme.so = $(LINKLIBS) -lmedia ; LINKLIBS on PlaySound.so = $(LINKLIBS) -lmedia ; LINKLIBS on Sound.so = $(LINKLIBS) -lmedia ; LINKLIBS on SoundFile.so = $(LINKLIBS) -lmedia ; -#LINKLIBS on SoundPlayer.so = $(LINKLIBS) -lmedia ; +LINKLIBS on SoundPlayer.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimeCode.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimeSource.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimedEventQueue.so = $(LINKLIBS) -lmedia ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 9edb008..765785d 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -223,7 +223,7 @@ from .PlaySound import * from .Sound import * from .SoundFile import * -#from .SoundPlayer import * +from .SoundPlayer import * from .TimeCode import * from .TimedEventQueue import * diff --git a/bindings/media/SoundPlayer.cpp b/bindings/media/SoundPlayer.cpp index b91a2e5..1b18885 100644 --- a/bindings/media/SoundPlayer.cpp +++ b/bindings/media/SoundPlayer.cpp @@ -1,33 +1,70 @@ #include +#include #include #include #include #include +#include namespace py = pybind11; using namespace BPrivate; -void define_SoundPlayer(py::module_& m) +PYBIND11_MODULE(SoundPlayer, m) { -m.attr("SoundPlayNode") = py::cast(SoundPlayNode); +//m.attr("SoundPlayNode") = py::cast(SoundPlayNode); -py::class_(m, "sound_error") +/*py::class_(m, "sound_error") .def(py::init(), "", py::arg("string")) .def("what", &sound_error::what, "") -; +;*/ + +py::register_exception(m, "sound_error"); +class sound_error : public std::exception { + public: + explicit sound_error(const char* msg) : message(msg) {} + const char* what() const noexcept override { + return message; + } + private: const char* message; +}; +/* In python you can write: except sound_player.sound_error as e: print(f"Caught sound_error: {e.what()}")*/ + +py::enum_(m, "sound_player_notification", "") +.value("B_STARTED", BSoundPlayer::sound_player_notification::B_STARTED, "") +.value("B_STOPPED", BSoundPlayer::sound_player_notification::B_STOPPED, "") +.value("B_SOUND_DONE", BSoundPlayer::sound_player_notification::B_SOUND_DONE, "") +.export_values(); py::class_(m, "BSoundPlayer") -.def(py::init(), "", py::arg("name")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL) -.def(py::init(), "", py::arg("format"), py::arg("name")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL) -.def(py::init(), "", py::arg("toNode"), py::arg("format")=NULL, py::arg("name")=NULL, py::arg("input")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL) +//.def(py::init(), "", py::arg("name")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL) +//.def(py::init(), "", py::arg("format"), py::arg("name")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL) +//.def(py::init(), "", py::arg("toNode"), py::arg("format")=NULL, py::arg("name")=NULL, py::arg("input")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL) + +.def(py::init(), py::arg("name") = nullptr, py::arg("playerFunction") = nullptr, py::arg("eventNotifierFunction") = nullptr, py::arg("cookie") = nullptr) +.def(py::init(), py::arg("format"), py::arg("name") = nullptr, py::arg("playerFunction") = nullptr, py::arg("eventNotifierFunction") = nullptr, py::arg("cookie") = nullptr) +.def(py::init(), py::arg("toNode"), py::arg("format") = nullptr, py::arg("name") = nullptr, py::arg("input") = nullptr, py::arg("playerFunction") = nullptr, py::arg("eventNotifierFunction") = nullptr, py::arg("cookie") = nullptr) + .def("InitCheck", &BSoundPlayer::InitCheck, "") .def("Format", &BSoundPlayer::Format, "") .def("Start", &BSoundPlayer::Start, "") .def("Stop", &BSoundPlayer::Stop, "", py::arg("block")=true, py::arg("flush")=true) -.def("BufferPlayer", &BSoundPlayer::BufferPlayer, "") +//.def("BufferPlayer", &BSoundPlayer::BufferPlayer, "") +//attempt1 +//.def("BufferPlayer", [](const BSoundPlayer& self) { return self.BufferPlayer(); },"") +//attempt2 +.def("BufferPlayer", [](const BSoundPlayer& self) -> std::function { + BSoundPlayer::BufferPlayerFunc playerFunc = self.BufferPlayer(); + return [playerFunc](void* cookie, void* buffer, size_t size, const media_raw_audio_format& format) { if (playerFunc) { playerFunc(cookie, buffer, size, format); } }; },"") //TODO test this .def("SetBufferPlayer", &BSoundPlayer::SetBufferPlayer, "", py::arg("")) -.def("EventNotifier", &BSoundPlayer::EventNotifier, "") +//.def("EventNotifier", &BSoundPlayer::EventNotifier, "") +//attempt variadic impossible +/*.def("EventNotifier", [](const BSoundPlayer& self) -> std::function { + BSoundPlayer::EventNotifierFunc notifierFunc = self.EventNotifier(); + return [notifierFunc](void* cookie, BSoundPlayer::sound_player_notification what, ...) { if (notifierFunc) { notifierFunc(cookie, what); } }; },"")*/ +.def("EventNotifier", [](const BSoundPlayer& self) -> std::function { + BSoundPlayer::EventNotifierFunc notifierFunc = self.EventNotifier(); + return [notifierFunc](void* cookie, BSoundPlayer::sound_player_notification what) { if (notifierFunc) { notifierFunc(cookie, what); } }; },"") //TODO test this .def("SetNotifier", &BSoundPlayer::SetNotifier, "", py::arg("eventNotifierFunction")) .def("Cookie", &BSoundPlayer::Cookie, "") .def("SetCookie", &BSoundPlayer::SetCookie, "", py::arg("cookie")) @@ -50,7 +87,7 @@ py::class_(m, "BSoundPlayer") .def("HasData", &BSoundPlayer::HasData, "") .def("SetHasData", &BSoundPlayer::SetHasData, "", py::arg("hasData")) ; - +/* py::class_(m, "playing_sound") .def_readwrite("next", &playing_sound::next, "") .def_readwrite("current_offset", &playing_sound::current_offset, "") @@ -69,7 +106,7 @@ py::class_(m, "waiting_sound") .def_readwrite("id", &waiting_sound::id, "") .def_readwrite("rate", &waiting_sound::rate, "") .def_readwrite("volume", &waiting_sound::volume, "") -; +;*/ } From 83e588d12959a715a01c4c701f135fdbe5884a93 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 6 Sep 2024 21:51:03 +0200 Subject: [PATCH 077/115] comment unneeded headers --- bindings/media/SoundFile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/media/SoundFile.cpp b/bindings/media/SoundFile.cpp index 53374c6..329b523 100644 --- a/bindings/media/SoundFile.cpp +++ b/bindings/media/SoundFile.cpp @@ -4,8 +4,8 @@ #include #include -#include -#include +//#include +//#include namespace py = pybind11; using namespace BPrivate; From bee81620ef5b4033e3d85d474b99305c1fde2461 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 6 Sep 2024 21:56:58 +0200 Subject: [PATCH 078/115] Update/add IconUtils.cpp --- Jamfile | 2 +- bindings/__init__.py | 2 +- bindings/interface/IconUtils.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Jamfile b/Jamfile index 0d47197..28df85d 100644 --- a/Jamfile +++ b/Jamfile @@ -194,7 +194,7 @@ local sourceFiles = GradientRadialFocus.cpp GridView.cpp Dragger.cpp - #IconUtils.cpp + IconUtils.cpp Input.cpp PrintJob.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 765785d..5d2ac66 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -87,7 +87,7 @@ from .GradientRadialFocus import * from .GridView import * from .Dragger import * -#from .IconUtils import * +from .IconUtils import * from .Input import * from .PrintJob import * diff --git a/bindings/interface/IconUtils.cpp b/bindings/interface/IconUtils.cpp index 5e70fa9..0cbcf75 100644 --- a/bindings/interface/IconUtils.cpp +++ b/bindings/interface/IconUtils.cpp @@ -12,7 +12,7 @@ namespace py = pybind11; PYBIND11_MODULE(IconUtils,m) { -py::class_(m, "BIconUtils") +py::class_>(m, "BIconUtils") .def_static("GetIcon", &BIconUtils::GetIcon, "", py::arg("node"), py::arg("vectorIconAttrName"), py::arg("smallIconAttrName"), py::arg("largeIconAttrName"), py::arg("size"), py::arg("result")) .def_static("GetVectorIcon", py::overload_cast(&BIconUtils::GetVectorIcon), "", py::arg("node"), py::arg("attrName"), py::arg("result")) .def_static("GetVectorIcon", py::overload_cast(&BIconUtils::GetVectorIcon), "", py::arg("buffer"), py::arg("size"), py::arg("result")) From c6f64d5131b9104a9e22a517538692a72d22b0eb Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 6 Sep 2024 23:11:26 +0200 Subject: [PATCH 079/115] add DiskDeviceDefs --- Jamfile | 2 +- bindings/__init__.py | 2 +- bindings/storage/DiskDeviceDefs.cpp | 174 ++++++++++++++-------------- 3 files changed, 89 insertions(+), 89 deletions(-) diff --git a/Jamfile b/Jamfile index 28df85d..4a99166 100644 --- a/Jamfile +++ b/Jamfile @@ -247,7 +247,7 @@ local sourceFiles = NodeMonitor.cpp NodeInfo.cpp AppFileInfo.cpp - #DiskDeviceDefs.cpp + DiskDeviceDefs.cpp FilePanel.cpp # TranslationKit diff --git a/bindings/__init__.py b/bindings/__init__.py index 5d2ac66..cca6df7 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -136,7 +136,7 @@ from .Query import * from .NodeMonitor import * from .NodeInfo import * -#from .DiskDeviceDefs import * +from .DiskDeviceDefs import * from .FilePanel import * from .TranslationDefs import * diff --git a/bindings/storage/DiskDeviceDefs.cpp b/bindings/storage/DiskDeviceDefs.cpp index bbddcc8..3d3f51b 100644 --- a/bindings/storage/DiskDeviceDefs.cpp +++ b/bindings/storage/DiskDeviceDefs.cpp @@ -8,100 +8,100 @@ namespace py = pybind11; -void define_DiskDeviceDefs(py::module_& m) +PYBIND11_MODULE(DiskDeviceDefs,m) { -m.attr("B_PARTITION_IS_DEVICE") = py::cast(B_PARTITION_IS_DEVICE); -m.attr("B_PARTITION_FILE_SYSTEM") = py::cast(B_PARTITION_FILE_SYSTEM); -m.attr("B_PARTITION_PARTITIONING_SYSTEM") = py::cast(B_PARTITION_PARTITIONING_SYSTEM); -m.attr("B_PARTITION_READ_ONLY") = py::cast(B_PARTITION_READ_ONLY); -m.attr("B_PARTITION_MOUNTED") = py::cast(B_PARTITION_MOUNTED); -m.attr("B_PARTITION_BUSY") = py::cast(B_PARTITION_BUSY); +m.attr("B_PARTITION_IS_DEVICE") = 0x01;//py::cast(B_PARTITION_IS_DEVICE); +m.attr("B_PARTITION_FILE_SYSTEM") = 0x02;//py::cast(B_PARTITION_FILE_SYSTEM); +m.attr("B_PARTITION_PARTITIONING_SYSTEM") = 0x04;//py::cast(B_PARTITION_PARTITIONING_SYSTEM); +m.attr("B_PARTITION_READ_ONLY") = 0x08;//py::cast(B_PARTITION_READ_ONLY); +m.attr("B_PARTITION_MOUNTED") = 0x10;//py::cast(B_PARTITION_MOUNTED); +m.attr("B_PARTITION_BUSY") = 0x20;//py::cast(B_PARTITION_BUSY); -m.attr("B_PARTITION_VALID") = py::cast(B_PARTITION_VALID); -m.attr("B_PARTITION_CORRUPT") = py::cast(B_PARTITION_CORRUPT); -m.attr("B_PARTITION_UNRECOGNIZED") = py::cast(B_PARTITION_UNRECOGNIZED); -m.attr("B_PARTITION_UNINITIALIZED") = py::cast(B_PARTITION_UNINITIALIZED); +m.attr("B_PARTITION_VALID") = 0;//py::cast(B_PARTITION_VALID); +m.attr("B_PARTITION_CORRUPT") = 1;//py::cast(B_PARTITION_CORRUPT); +m.attr("B_PARTITION_UNRECOGNIZED") = 2;//py::cast(B_PARTITION_UNRECOGNIZED); +m.attr("B_PARTITION_UNINITIALIZED") = 3;//py::cast(B_PARTITION_UNINITIALIZED); -m.attr("B_PARTITION_CHANGED_OFFSET") = py::cast(B_PARTITION_CHANGED_OFFSET); -m.attr("B_PARTITION_CHANGED_SIZE") = py::cast(B_PARTITION_CHANGED_SIZE); -m.attr("B_PARTITION_CHANGED_CONTENT_SIZE") = py::cast(B_PARTITION_CHANGED_CONTENT_SIZE); -m.attr("B_PARTITION_CHANGED_BLOCK_SIZE") = py::cast(B_PARTITION_CHANGED_BLOCK_SIZE); -m.attr("B_PARTITION_CHANGED_STATUS") = py::cast(B_PARTITION_CHANGED_STATUS); -m.attr("B_PARTITION_CHANGED_FLAGS") = py::cast(B_PARTITION_CHANGED_FLAGS); -m.attr("B_PARTITION_CHANGED_VOLUME") = py::cast(B_PARTITION_CHANGED_VOLUME); -m.attr("B_PARTITION_CHANGED_NAME") = py::cast(B_PARTITION_CHANGED_NAME); -m.attr("B_PARTITION_CHANGED_CONTENT_NAME") = py::cast(B_PARTITION_CHANGED_CONTENT_NAME); -m.attr("B_PARTITION_CHANGED_TYPE") = py::cast(B_PARTITION_CHANGED_TYPE); -m.attr("B_PARTITION_CHANGED_CONTENT_TYPE") = py::cast(B_PARTITION_CHANGED_CONTENT_TYPE); -m.attr("B_PARTITION_CHANGED_PARAMETERS") = py::cast(B_PARTITION_CHANGED_PARAMETERS); -m.attr("B_PARTITION_CHANGED_CONTENT_PARAMETERS") = py::cast(B_PARTITION_CHANGED_CONTENT_PARAMETERS); -m.attr("B_PARTITION_CHANGED_CHILDREN") = py::cast(B_PARTITION_CHANGED_CHILDREN); -m.attr("B_PARTITION_CHANGED_DESCENDANTS") = py::cast(B_PARTITION_CHANGED_DESCENDANTS); -m.attr("B_PARTITION_CHANGED_DEFRAGMENTATION") = py::cast(B_PARTITION_CHANGED_DEFRAGMENTATION); -m.attr("B_PARTITION_CHANGED_CHECK") = py::cast(B_PARTITION_CHANGED_CHECK); -m.attr("B_PARTITION_CHANGED_REPAIR") = py::cast(B_PARTITION_CHANGED_REPAIR); -m.attr("B_PARTITION_CHANGED_INITIALIZATION") = py::cast(B_PARTITION_CHANGED_INITIALIZATION); +m.attr("B_PARTITION_CHANGED_OFFSET") = 0x000001;//py::cast(B_PARTITION_CHANGED_OFFSET); +m.attr("B_PARTITION_CHANGED_SIZE") = 0x000002;//py::cast(B_PARTITION_CHANGED_SIZE); +m.attr("B_PARTITION_CHANGED_CONTENT_SIZE") = 0x000004;//py::cast(B_PARTITION_CHANGED_CONTENT_SIZE); +m.attr("B_PARTITION_CHANGED_BLOCK_SIZE") = 0x000008;//py::cast(B_PARTITION_CHANGED_BLOCK_SIZE); +m.attr("B_PARTITION_CHANGED_STATUS") = 0x000010;//py::cast(B_PARTITION_CHANGED_STATUS); +m.attr("B_PARTITION_CHANGED_FLAGS") = 0x000020;//py::cast(B_PARTITION_CHANGED_FLAGS); +m.attr("B_PARTITION_CHANGED_VOLUME") = 0x000040;//py::cast(B_PARTITION_CHANGED_VOLUME); +m.attr("B_PARTITION_CHANGED_NAME") = 0x000080;//py::cast(B_PARTITION_CHANGED_NAME); +m.attr("B_PARTITION_CHANGED_CONTENT_NAME") = 0x000100;//py::cast(B_PARTITION_CHANGED_CONTENT_NAME); +m.attr("B_PARTITION_CHANGED_TYPE") = 0x000200;//py::cast(B_PARTITION_CHANGED_TYPE); +m.attr("B_PARTITION_CHANGED_CONTENT_TYPE") = 0x000400;//py::cast(B_PARTITION_CHANGED_CONTENT_TYPE); +m.attr("B_PARTITION_CHANGED_PARAMETERS") = 0x000800;//py::cast(B_PARTITION_CHANGED_PARAMETERS); +m.attr("B_PARTITION_CHANGED_CONTENT_PARAMETERS") = 0x001000;//py::cast(B_PARTITION_CHANGED_CONTENT_PARAMETERS); +m.attr("B_PARTITION_CHANGED_CHILDREN") = 0x002000;//py::cast(B_PARTITION_CHANGED_CHILDREN); +m.attr("B_PARTITION_CHANGED_DESCENDANTS") = 0x004000;//py::cast(B_PARTITION_CHANGED_DESCENDANTS); +m.attr("B_PARTITION_CHANGED_DEFRAGMENTATION") = 0x008000;//py::cast(B_PARTITION_CHANGED_DEFRAGMENTATION); +m.attr("B_PARTITION_CHANGED_CHECK") = 0x010000;//py::cast(B_PARTITION_CHANGED_CHECK); +m.attr("B_PARTITION_CHANGED_REPAIR") = 0x020000;//py::cast(B_PARTITION_CHANGED_REPAIR); +m.attr("B_PARTITION_CHANGED_INITIALIZATION") = 0x040000;//py::cast(B_PARTITION_CHANGED_INITIALIZATION); -m.attr("B_DISK_DEVICE_REMOVABLE") = py::cast(B_DISK_DEVICE_REMOVABLE); -m.attr("B_DISK_DEVICE_HAS_MEDIA") = py::cast(B_DISK_DEVICE_HAS_MEDIA); -m.attr("B_DISK_DEVICE_READ_ONLY") = py::cast(B_DISK_DEVICE_READ_ONLY); -m.attr("B_DISK_DEVICE_WRITE_ONCE") = py::cast(B_DISK_DEVICE_WRITE_ONCE); -m.attr("B_DISK_DEVICE_IS_FILE") = py::cast(B_DISK_DEVICE_IS_FILE); +m.attr("B_DISK_DEVICE_REMOVABLE") = 0x01;//py::cast(B_DISK_DEVICE_REMOVABLE); +m.attr("B_DISK_DEVICE_HAS_MEDIA") = 0x02;//py::cast(B_DISK_DEVICE_HAS_MEDIA); +m.attr("B_DISK_DEVICE_READ_ONLY") = 0x04;//py::cast(B_DISK_DEVICE_READ_ONLY); +m.attr("B_DISK_DEVICE_WRITE_ONCE") = 0x08;//py::cast(B_DISK_DEVICE_WRITE_ONCE); +m.attr("B_DISK_DEVICE_IS_FILE") = 0x10;//py::cast(B_DISK_DEVICE_IS_FILE); -m.attr("B_DISK_SYSTEM_IS_FILE_SYSTEM") = py::cast(B_DISK_SYSTEM_IS_FILE_SYSTEM); -m.attr("B_DISK_SYSTEM_SUPPORTS_CHECKING") = py::cast(B_DISK_SYSTEM_SUPPORTS_CHECKING); -m.attr("B_DISK_SYSTEM_SUPPORTS_REPAIRING") = py::cast(B_DISK_SYSTEM_SUPPORTS_REPAIRING); -m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING") = py::cast(B_DISK_SYSTEM_SUPPORTS_RESIZING); -m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING") = py::cast(B_DISK_SYSTEM_SUPPORTS_MOVING); -m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME") = py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME); -m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS") = py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS); -m.attr("B_DISK_SYSTEM_SUPPORTS_INITIALIZING") = py::cast(B_DISK_SYSTEM_SUPPORTS_INITIALIZING); -m.attr("B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME") = py::cast(B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME); -m.attr("B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING") = py::cast(B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING); -m.attr("B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED") = py::cast(B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED); -m.attr("B_DISK_SYSTEM_SUPPORTS_CHECKING_WHILE_MOUNTED") = py::cast(B_DISK_SYSTEM_SUPPORTS_CHECKING_WHILE_MOUNTED); -m.attr("B_DISK_SYSTEM_SUPPORTS_REPAIRING_WHILE_MOUNTED") = py::cast(B_DISK_SYSTEM_SUPPORTS_REPAIRING_WHILE_MOUNTED); -m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED") = py::cast(B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED); -m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED") = py::cast(B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED); -m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED") = py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED); -m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED") = py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED); -m.attr("B_DISK_SYSTEM_SUPPORTS_WRITING") = py::cast(B_DISK_SYSTEM_SUPPORTS_WRITING); -m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD") = py::cast(B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD); -m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD") = py::cast(B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD); -m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_NAME") = py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_NAME); -m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE") = py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE); -m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS") = py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS); -m.attr("B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD") = py::cast(B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD); -m.attr("B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD") = py::cast(B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD); -m.attr("B_DISK_SYSTEM_SUPPORTS_NAME") = py::cast(B_DISK_SYSTEM_SUPPORTS_NAME); +m.attr("B_DISK_SYSTEM_IS_FILE_SYSTEM") = 0x000001;//py::cast(B_DISK_SYSTEM_IS_FILE_SYSTEM); +m.attr("B_DISK_SYSTEM_SUPPORTS_CHECKING") = 0x000002;//py::cast(B_DISK_SYSTEM_SUPPORTS_CHECKING); +m.attr("B_DISK_SYSTEM_SUPPORTS_REPAIRING") = 0x000004;//py::cast(B_DISK_SYSTEM_SUPPORTS_REPAIRING); +m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING") = 0x000008;//py::cast(B_DISK_SYSTEM_SUPPORTS_RESIZING); +m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING") = 0x000010;//py::cast(B_DISK_SYSTEM_SUPPORTS_MOVING); +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME") = 0x000020;//py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME); +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS") = 0x000040;//py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS); +m.attr("B_DISK_SYSTEM_SUPPORTS_INITIALIZING") = 0x000080;//py::cast(B_DISK_SYSTEM_SUPPORTS_INITIALIZING); +m.attr("B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME") = 0x000100;//py::cast(B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME); +m.attr("B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING") = 0x001000;//py::cast(B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING); +m.attr("B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED") = 0x002000;//py::cast(B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED); +m.attr("B_DISK_SYSTEM_SUPPORTS_CHECKING_WHILE_MOUNTED") = 0x004000;//py::cast(B_DISK_SYSTEM_SUPPORTS_CHECKING_WHILE_MOUNTED); +m.attr("B_DISK_SYSTEM_SUPPORTS_REPAIRING_WHILE_MOUNTED") = 0x008000;//py::cast(B_DISK_SYSTEM_SUPPORTS_REPAIRING_WHILE_MOUNTED); +m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED") = 0x010000;//py::cast(B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED); +m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED") = 0x020000;//py::cast(B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED); +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED") = 0x040000;//py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED); +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED") = 0x080000;//py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED); +m.attr("B_DISK_SYSTEM_SUPPORTS_WRITING") = 0x100000;//py::cast(B_DISK_SYSTEM_SUPPORTS_WRITING); +m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD") = 0x001000;//py::cast(B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD); +m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD") = 0x002000;//py::cast(B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD); +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_NAME") = 0x004000;//py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_NAME); +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE") = 0x008000;//py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE); +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS") = 0x010000;//py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS); +m.attr("B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD") = 0x020000;//py::cast(B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD); +m.attr("B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD") = 0x040000;//py::cast(B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD); +m.attr("B_DISK_SYSTEM_SUPPORTS_NAME") = 0x080000;//py::cast(B_DISK_SYSTEM_SUPPORTS_NAME); -m.attr("B_DISK_DEVICE_JOB_BAD_TYPE") = py::cast(B_DISK_DEVICE_JOB_BAD_TYPE); -m.attr("B_DISK_DEVICE_JOB_DEFRAGMENT") = py::cast(B_DISK_DEVICE_JOB_DEFRAGMENT); -m.attr("B_DISK_DEVICE_JOB_REPAIR") = py::cast(B_DISK_DEVICE_JOB_REPAIR); -m.attr("B_DISK_DEVICE_JOB_RESIZE") = py::cast(B_DISK_DEVICE_JOB_RESIZE); -m.attr("B_DISK_DEVICE_JOB_MOVE") = py::cast(B_DISK_DEVICE_JOB_MOVE); -m.attr("B_DISK_DEVICE_JOB_SET_NAME") = py::cast(B_DISK_DEVICE_JOB_SET_NAME); -m.attr("B_DISK_DEVICE_JOB_SET_CONTENT_NAME") = py::cast(B_DISK_DEVICE_JOB_SET_CONTENT_NAME); -m.attr("B_DISK_DEVICE_JOB_SET_TYPE") = py::cast(B_DISK_DEVICE_JOB_SET_TYPE); -m.attr("B_DISK_DEVICE_JOB_SET_PARAMETERS") = py::cast(B_DISK_DEVICE_JOB_SET_PARAMETERS); -m.attr("B_DISK_DEVICE_JOB_SET_CONTENT_PARAMETERS") = py::cast(B_DISK_DEVICE_JOB_SET_CONTENT_PARAMETERS); -m.attr("B_DISK_DEVICE_JOB_INITIALIZE") = py::cast(B_DISK_DEVICE_JOB_INITIALIZE); -m.attr("B_DISK_DEVICE_JOB_UNINITIALIZE") = py::cast(B_DISK_DEVICE_JOB_UNINITIALIZE); -m.attr("B_DISK_DEVICE_JOB_CREATE") = py::cast(B_DISK_DEVICE_JOB_CREATE); -m.attr("B_DISK_DEVICE_JOB_DELETE") = py::cast(B_DISK_DEVICE_JOB_DELETE); -m.attr("B_DISK_DEVICE_JOB_SCAN") = py::cast(B_DISK_DEVICE_JOB_SCAN); +m.attr("B_DISK_DEVICE_JOB_BAD_TYPE") = 0;//py::cast(B_DISK_DEVICE_JOB_BAD_TYPE); +m.attr("B_DISK_DEVICE_JOB_DEFRAGMENT") = 1;//py::cast(B_DISK_DEVICE_JOB_DEFRAGMENT); +m.attr("B_DISK_DEVICE_JOB_REPAIR") = 2;//py::cast(B_DISK_DEVICE_JOB_REPAIR); +m.attr("B_DISK_DEVICE_JOB_RESIZE") = 3;//py::cast(B_DISK_DEVICE_JOB_RESIZE); +m.attr("B_DISK_DEVICE_JOB_MOVE") = 4;//py::cast(B_DISK_DEVICE_JOB_MOVE); +m.attr("B_DISK_DEVICE_JOB_SET_NAME") = 5;//py::cast(B_DISK_DEVICE_JOB_SET_NAME); +m.attr("B_DISK_DEVICE_JOB_SET_CONTENT_NAME") = 6;//py::cast(B_DISK_DEVICE_JOB_SET_CONTENT_NAME); +m.attr("B_DISK_DEVICE_JOB_SET_TYPE") = 7;//py::cast(B_DISK_DEVICE_JOB_SET_TYPE); +m.attr("B_DISK_DEVICE_JOB_SET_PARAMETERS") = 8;//py::cast(B_DISK_DEVICE_JOB_SET_PARAMETERS); +m.attr("B_DISK_DEVICE_JOB_SET_CONTENT_PARAMETERS") = 9;//py::cast(B_DISK_DEVICE_JOB_SET_CONTENT_PARAMETERS); +m.attr("B_DISK_DEVICE_JOB_INITIALIZE") = 10;//py::cast(B_DISK_DEVICE_JOB_INITIALIZE); +m.attr("B_DISK_DEVICE_JOB_UNINITIALIZE") = 11;//py::cast(B_DISK_DEVICE_JOB_UNINITIALIZE); +m.attr("B_DISK_DEVICE_JOB_CREATE") = 12;//py::cast(B_DISK_DEVICE_JOB_CREATE); +m.attr("B_DISK_DEVICE_JOB_DELETE") = 13;//py::cast(B_DISK_DEVICE_JOB_DELETE); +m.attr("B_DISK_DEVICE_JOB_SCAN") = 14;//py::cast(B_DISK_DEVICE_JOB_SCAN); -m.attr("B_DISK_DEVICE_JOB_UNINITIALIZED") = py::cast(B_DISK_DEVICE_JOB_UNINITIALIZED); -m.attr("B_DISK_DEVICE_JOB_SCHEDULED") = py::cast(B_DISK_DEVICE_JOB_SCHEDULED); -m.attr("B_DISK_DEVICE_JOB_IN_PROGRESS") = py::cast(B_DISK_DEVICE_JOB_IN_PROGRESS); -m.attr("B_DISK_DEVICE_JOB_SUCCEEDED") = py::cast(B_DISK_DEVICE_JOB_SUCCEEDED); -m.attr("B_DISK_DEVICE_JOB_FAILED") = py::cast(B_DISK_DEVICE_JOB_FAILED); -m.attr("B_DISK_DEVICE_JOB_CANCELED") = py::cast(B_DISK_DEVICE_JOB_CANCELED); +m.attr("B_DISK_DEVICE_JOB_UNINITIALIZED") = 0;//py::cast(B_DISK_DEVICE_JOB_UNINITIALIZED); +m.attr("B_DISK_DEVICE_JOB_SCHEDULED") = 1;//py::cast(B_DISK_DEVICE_JOB_SCHEDULED); +m.attr("B_DISK_DEVICE_JOB_IN_PROGRESS") = 2;//py::cast(B_DISK_DEVICE_JOB_IN_PROGRESS); +m.attr("B_DISK_DEVICE_JOB_SUCCEEDED") = 3;//py::cast(B_DISK_DEVICE_JOB_SUCCEEDED); +m.attr("B_DISK_DEVICE_JOB_FAILED") = 4;//py::cast(B_DISK_DEVICE_JOB_FAILED); +m.attr("B_DISK_DEVICE_JOB_CANCELED") = 5;//py::cast(B_DISK_DEVICE_JOB_CANCELED); -m.attr("B_DISK_DEVICE_JOB_CAN_CANCEL") = py::cast(B_DISK_DEVICE_JOB_CAN_CANCEL); -m.attr("B_DISK_DEVICE_JOB_STOP_ON_CANCEL") = py::cast(B_DISK_DEVICE_JOB_STOP_ON_CANCEL); -m.attr("B_DISK_DEVICE_JOB_REVERSE_ON_CANCEL") = py::cast(B_DISK_DEVICE_JOB_REVERSE_ON_CANCEL); -m.attr("B_DISK_DEVICE_JOB_CAN_PAUSE") = py::cast(B_DISK_DEVICE_JOB_CAN_PAUSE); +m.attr("B_DISK_DEVICE_JOB_CAN_CANCEL") = 0x01;//py::cast(B_DISK_DEVICE_JOB_CAN_CANCEL); +m.attr("B_DISK_DEVICE_JOB_STOP_ON_CANCEL") = 0x02;//py::cast(B_DISK_DEVICE_JOB_STOP_ON_CANCEL); +m.attr("B_DISK_DEVICE_JOB_REVERSE_ON_CANCEL") = 0x04;//py::cast(B_DISK_DEVICE_JOB_REVERSE_ON_CANCEL); +m.attr("B_DISK_DEVICE_JOB_CAN_PAUSE") = 0x08;//py::cast(B_DISK_DEVICE_JOB_CAN_PAUSE); py::enum_(m, "B_PARAMETER_EDITOR_TYPE", "") .value("B_CREATE_PARAMETER_EDITOR", B_PARAMETER_EDITOR_TYPE::B_CREATE_PARAMETER_EDITOR, "") @@ -116,7 +116,7 @@ py::class_(m, "disk_device_job_progress_info") .def_readwrite("task_count", &disk_device_job_progress_info::task_count, "") .def_readwrite("completed_tasks", &disk_device_job_progress_info::completed_tasks, "") .def_readwrite("current_task_progress", &disk_device_job_progress_info::current_task_progress, "") -.def_readwrite("current_task_description", &disk_device_job_progress_info::current_task_description, "") +.def_readonly("current_task_description", &disk_device_job_progress_info::current_task_description, "") //todo: should this be writable? ; From c8ad6038b2179ad540b72762d3e6647646729fc1 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 9 Sep 2024 01:54:26 +0200 Subject: [PATCH 080/115] update DataIO --- bindings/support/DataIO.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/bindings/support/DataIO.cpp b/bindings/support/DataIO.cpp index 1fe9a17..0f6adbd 100644 --- a/bindings/support/DataIO.cpp +++ b/bindings/support/DataIO.cpp @@ -20,7 +20,7 @@ class PyBDataIO : public BDataIO { } }; -/* + class PyBPositionIO : public BPositionIO { public: using BPositionIO::Seek; @@ -33,16 +33,16 @@ class PyBPositionIO : public BPositionIO { PYBIND11_OVERLOAD(ssize_t, BPositionIO, Write, buffer, size); } ssize_t ReadAt(off_t position, void* buffer, size_t size) override { - PYBIND11_OVERLOAD(ssize_t, BPositionIO, ReadAt, position, buffer, size); + PYBIND11_OVERLOAD_PURE(ssize_t, BPositionIO, ReadAt, position, buffer, size); } ssize_t WriteAt(off_t position, const void* buffer, size_t size) override { - PYBIND11_OVERLOAD(ssize_t, BPositionIO, WriteAt, position, buffer, size); + PYBIND11_OVERLOAD_PURE(ssize_t, BPositionIO, WriteAt, position, buffer, size); } off_t Seek(off_t position, uint32 seekMode) override { - PYBIND11_OVERLOAD(off_t, BPositionIO, Seek, position, seekMode); + PYBIND11_OVERLOAD_PURE(off_t, BPositionIO, Seek, position, seekMode); } off_t Position() const override { - PYBIND11_OVERLOAD(off_t, BPositionIO, Position); + PYBIND11_OVERLOAD_PURE(off_t, BPositionIO, Position); } status_t SetSize(off_t size) override { PYBIND11_OVERLOAD(status_t, BPositionIO, SetSize, size); @@ -88,7 +88,7 @@ class PyBMallocIO : public BMallocIO { status_t SetSize(off_t size) override { PYBIND11_OVERLOAD(status_t, BMallocIO, SetSize, size); } -};*/ +}; PYBIND11_MODULE(DataIO, m) @@ -102,13 +102,13 @@ py::class_(m, "BDataIO") .def("WriteExactly", &BDataIO::WriteExactly, "", py::arg("buffer"), py::arg("size"), py::arg("_bytesWritten")=NULL) ; - -py::class_(m, "BPositionIO"); -py::class_(m, "BMemoryIO"); -py::class_(m, "BMallocIO"); /* -//py::class_(m, "BPositionIO") -py::class_>(m, "BPositionIO") +py::class_(m, "BPositionIO"); +py::class_(m, "BMemoryIO"); +py::class_(m, "BMallocIO"); +*/ +py::class_(m, "BPositionIO") +//py::class_>(m, "BPositionIO") .def(py::init(), "") .def("Read", &BPositionIO::Read, "", py::arg("buffer"), py::arg("size")) .def("Write", &BPositionIO::Write, "", py::arg("buffer"), py::arg("size")) @@ -122,8 +122,8 @@ py::class_>(m, "BPositionIO") .def("GetSize", &BPositionIO::GetSize, "", py::arg("size")) ; -//py::class_(m, "BMemoryIO") -py::class_>(m, "BMemoryIO") +py::class_(m, "BMemoryIO") +//py::class_>(m, "BMemoryIO") //.def(py::init(), "", py::arg("data"), py::arg("length")) //.def(py::init(), "", py::arg("data"), py::arg("length")) .def("ReadAt", &BMemoryIO::ReadAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) @@ -133,8 +133,8 @@ py::class_>(m, "BMemoryIO") .def("SetSize", &BMemoryIO::SetSize, "", py::arg("size")) ; -py::class_(m, "BMallocIO") -//.def(py::init(), "") +py::class_(m, "BMallocIO") +.def(py::init(), "") .def("ReadAt", &BMallocIO::ReadAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) .def("WriteAt", &BMallocIO::WriteAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) .def("Seek", &BMallocIO::Seek, "", py::arg("position"), py::arg("seekMode")) @@ -144,6 +144,5 @@ py::class_(m, "BMallocIO") .def("Buffer", &BMallocIO::Buffer, "") .def("BufferLength", &BMallocIO::BufferLength, "") ; -*/ } From a3e972e8232632f143630ce9d9065782041f4286 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 9 Sep 2024 01:59:31 +0200 Subject: [PATCH 081/115] refine DataIO --- bindings/support/DataIO.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bindings/support/DataIO.cpp b/bindings/support/DataIO.cpp index 0f6adbd..1013be6 100644 --- a/bindings/support/DataIO.cpp +++ b/bindings/support/DataIO.cpp @@ -9,6 +9,7 @@ namespace py = pybind11; class PyBDataIO : public BDataIO { public: + using BDataIO::BDataIO; ssize_t Read(void* buffer, size_t size) override { PYBIND11_OVERLOAD(ssize_t, BDataIO, Read, buffer, size); } @@ -23,8 +24,8 @@ class PyBDataIO : public BDataIO { class PyBPositionIO : public BPositionIO { public: - using BPositionIO::Seek; - using BPositionIO::Position; +// using BPositionIO::Seek; +// using BPositionIO::Position; using BPositionIO::BPositionIO; ssize_t Read(void* buffer, size_t size) override { PYBIND11_OVERLOAD(ssize_t, BPositionIO, Read, buffer, size); @@ -54,6 +55,7 @@ class PyBPositionIO : public BPositionIO { class PyBMemoryIO : public BMemoryIO { public: + using BMemoryIO::BMemoryIO; ssize_t ReadAt(off_t position, void* buffer, size_t size) override { PYBIND11_OVERLOAD(ssize_t, BMemoryIO, ReadAt, position, buffer, size); } @@ -73,6 +75,7 @@ class PyBMemoryIO : public BMemoryIO { class PyBMallocIO : public BMallocIO { public: + using BMallocIO::BMallocIO; ssize_t ReadAt(off_t position, void* buffer, size_t size) override { PYBIND11_OVERLOAD(ssize_t, BMallocIO, ReadAt, position, buffer, size); } @@ -108,7 +111,6 @@ py::class_(m, "BMemoryIO"); py::class_(m, "BMallocIO"); */ py::class_(m, "BPositionIO") -//py::class_>(m, "BPositionIO") .def(py::init(), "") .def("Read", &BPositionIO::Read, "", py::arg("buffer"), py::arg("size")) .def("Write", &BPositionIO::Write, "", py::arg("buffer"), py::arg("size")) @@ -123,7 +125,6 @@ py::class_(m, "BPositionIO") ; py::class_(m, "BMemoryIO") -//py::class_>(m, "BMemoryIO") //.def(py::init(), "", py::arg("data"), py::arg("length")) //.def(py::init(), "", py::arg("data"), py::arg("length")) .def("ReadAt", &BMemoryIO::ReadAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) From 6b433cc625830ee6e9bf5893ce01de9709846747 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 9 Sep 2024 02:01:04 +0200 Subject: [PATCH 082/115] init BMemoryIO in DataIO --- bindings/support/DataIO.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/support/DataIO.cpp b/bindings/support/DataIO.cpp index 1013be6..4af613b 100644 --- a/bindings/support/DataIO.cpp +++ b/bindings/support/DataIO.cpp @@ -125,8 +125,8 @@ py::class_(m, "BPositionIO") ; py::class_(m, "BMemoryIO") -//.def(py::init(), "", py::arg("data"), py::arg("length")) -//.def(py::init(), "", py::arg("data"), py::arg("length")) +.def(py::init(), "", py::arg("data"), py::arg("length")) +.def(py::init(), "", py::arg("data"), py::arg("length")) .def("ReadAt", &BMemoryIO::ReadAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) .def("WriteAt", &BMemoryIO::WriteAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) .def("Seek", &BMemoryIO::Seek, "", py::arg("position"), py::arg("seekMode")) From 0d8f934ec113f9bf3dc243e1210d0ad9658f81ee Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 9 Sep 2024 09:21:09 +0200 Subject: [PATCH 083/115] add BufferIO --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/support/BufferIO.cpp | 63 ++++++++++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/Jamfile b/Jamfile index 4a99166..991858f 100644 --- a/Jamfile +++ b/Jamfile @@ -215,6 +215,7 @@ local sourceFiles = Flattenable.cpp StringList.cpp DataIO.cpp + BufferIO.cpp BufferedDataIO.cpp Url.cpp UTF8.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index cca6df7..2ca4c66 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -105,6 +105,7 @@ from .AffineTransform import * from .StringList import * from .DataIO import * +from .BufferIO import * from .BufferedDataIO import * from .Url import * from .UTF8 import * diff --git a/bindings/support/BufferIO.cpp b/bindings/support/BufferIO.cpp index e6069c6..9ee9e41 100644 --- a/bindings/support/BufferIO.cpp +++ b/bindings/support/BufferIO.cpp @@ -7,13 +7,66 @@ namespace py = pybind11; +class PyBBufferIO : public BBufferIO{ + public: + using BBufferIO::BBufferIO; + ssize_t ReadAt(off_t pos, void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BBufferIO, ReadAt, pos, buffer, size); + } + ssize_t WriteAt(off_t pos, const void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BBufferIO, WriteAt, pos, buffer, size); + } + off_t Seek(off_t position, uint32 seekMode) override { + PYBIND11_OVERLOAD(off_t, BBufferIO, Seek, position, seekMode); + } + off_t Position() const override { + PYBIND11_OVERLOAD(off_t, BBufferIO, Position); + } + status_t SetSize(off_t size) override { + PYBIND11_OVERLOAD(status_t, BBufferIO, SetSize, size); + } + status_t Flush() override { + PYBIND11_OVERLOAD(status_t, BBufferIO, Flush); + } +}; -void define_BufferIO(py::module_& m) + +ssize_t ReadAtWrapper(BBufferIO& self, off_t pos, py::buffer buffer) { + py::buffer_info info = buffer.request(); + + if (info.ndim != 1) { + throw std::runtime_error("Buffer should be one-dimensional"); + } + + if (info.itemsize != 1) { + throw std::runtime_error("Buffer elements should be of size 1 byte"); + } + + return self.ReadAt(pos, info.ptr, info.size); +}; + +ssize_t WriteAtWrapper(BBufferIO& self, off_t pos, py::buffer buffer) { + py::buffer_info info = buffer.request(); + + if (info.ndim != 1) { + throw std::runtime_error("Buffer should be one-dimensional"); + } + + if (info.itemsize != 1) { + throw std::runtime_error("Buffer elements should be of size 1 byte"); + } + + return self.WriteAt(pos, info.ptr, info.size); +}; + +PYBIND11_MODULE(BufferIO, m) { -py::class_(m, "BBufferIO") -.def(py::init(), "", py::arg("stream"), py::arg("bufferSize")=65536 L, py::arg("ownsStream")=true) -.def("ReadAt", &BBufferIO::ReadAt, "", py::arg("pos"), py::arg("buffer"), py::arg("size")) -.def("WriteAt", &BBufferIO::WriteAt, "", py::arg("pos"), py::arg("buffer"), py::arg("size")) +py::class_(m, "BBufferIO") +.def(py::init(), "", py::arg("stream"), py::arg("bufferSize")=65536L, py::arg("ownsStream")=true) +//.def("ReadAt", &BBufferIO::ReadAt, "", py::arg("pos"), py::arg("buffer"), py::arg("size")) +.def("ReadAt", &ReadAtWrapper, "", py::arg("pos"), py::arg("buffer")) +//.def("WriteAt", &BBufferIO::WriteAt, "", py::arg("pos"), py::arg("buffer"), py::arg("size")) +.def("WriteAt", &WriteAtWrapper, "", py::arg("pos"), py::arg("buffer")) .def("Seek", &BBufferIO::Seek, "", py::arg("position"), py::arg("seekMode")) .def("Position", &BBufferIO::Position, "") .def("SetSize", &BBufferIO::SetSize, "", py::arg("size")) From c07422d717f5172f0d93b49291584a5cdd29a2a4 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 9 Sep 2024 09:49:25 +0200 Subject: [PATCH 084/115] Add ByteOrder.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/support/ByteOrder.cpp | 41 +++++++++++++++++++++++++++++----- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Jamfile b/Jamfile index 991858f..71dd920 100644 --- a/Jamfile +++ b/Jamfile @@ -199,6 +199,7 @@ local sourceFiles = PrintJob.cpp #SupportKit + ByteOrder.cpp StopWatch.cpp Beep.cpp Locker.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 2ca4c66..b583838 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -91,6 +91,7 @@ from .Input import * from .PrintJob import * +from .ByteOrder import * from .StopWatch import * from .Beep import * from .Architecture import * diff --git a/bindings/support/ByteOrder.cpp b/bindings/support/ByteOrder.cpp index d5e5840..fce11f8 100644 --- a/bindings/support/ByteOrder.cpp +++ b/bindings/support/ByteOrder.cpp @@ -6,9 +6,33 @@ #include namespace py = pybind11; +/* +uint64 sw_int64(uint64 arg){ + #if __GNUC__ >= 4 + return __builtin_bswap64(arg); + #else + return __swap_int64(arg); +}*/ +#if __GNUC__ >= 4 + uint64 swap_int64(uint64 arg) { + return __builtin_bswap64(arg); + } + uint32 swap_int32(uint32 arg) { + return __builtin_bswap32(arg); + } + uint16 swap_int16(uint16 arg) { + return __builtin_bswap16(arg); + } +#else + extern uint64 __swap_int64(uint64 arg); + extern uint32 __swap_int32(uint32 arg); + extern uint16 __swap_int16(uint16 arg); +#endif -void define_ByteOrder(py::module_& m) + + +PYBIND11_MODULE(ByteOrder, m) { py::enum_(m, "swap_action", "") .value("B_SWAP_HOST_TO_LENDIAN", swap_action::B_SWAP_HOST_TO_LENDIAN, "") @@ -25,11 +49,18 @@ m.def("is_type_swapped", &is_type_swapped, "", py::arg("type")); m.def("__swap_double", &__swap_double, "", py::arg("arg")); m.def("__swap_float", &__swap_float, "", py::arg("arg")); - +/* m.def("__swap_int64", &__swap_int64, "", py::arg("arg")); - m.def("__swap_int32", &__swap_int32, "", py::arg("arg")); - m.def("__swap_int16", &__swap_int16, "", py::arg("arg")); - +*/ +#if __GNUC__ >= 4 +m.def("__swap_int64", &swap_int64, "Swap bytes of a 64-bit integer"); +m.def("__swap_int32", &swap_int32, "Swap bytes of a 32-bit integer"); +m.def("__swap_int16", &swap_int16, "Swap bytes of a 16-bit integer"); +#else +m.def("__swap_int64", &__swap_int64, "", py::arg("arg")); +m.def("__swap_int32", &__swap_int32, "", py::arg("arg")); +m.def("__swap_int16", &__swap_int16, "", py::arg("arg")); +#endif } From 267e21f5d0be2cee753dcc76803a486e50313fc9 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 9 Sep 2024 09:57:07 +0200 Subject: [PATCH 085/115] add Job.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/support/Job.cpp | 18 +++++++++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Jamfile b/Jamfile index 71dd920..15c8cb1 100644 --- a/Jamfile +++ b/Jamfile @@ -221,6 +221,7 @@ local sourceFiles = Url.cpp UTF8.cpp TLS.cpp + Job.cpp #Kernel fs_attr.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index b583838..c085d34 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -111,6 +111,7 @@ from .Url import * from .UTF8 import * from .TLS import * +from .Job import * from .fs_attr import * from .OS import * diff --git a/bindings/support/Job.cpp b/bindings/support/Job.cpp index a62effd..6a6e58d 100644 --- a/bindings/support/Job.cpp +++ b/bindings/support/Job.cpp @@ -8,7 +8,19 @@ namespace py = pybind11; using namespace BSupportKit; -void define_Job(py::module_& m) +class PyBJob : public BJob{ + public: + using BJob::BJob; + status_t Run() override { + PYBIND11_OVERLOAD(status_t, BJob, Run); + } + status_t Execute() override { + PYBIND11_OVERLOAD_PURE(status_t, BJob, Execute); + } +}; + + +PYBIND11_MODULE(Job, m) { py::enum_(m, "BJobState", "") .value("B_JOB_STATE_WAITING_TO_RUN", BJobState::B_JOB_STATE_WAITING_TO_RUN, "") @@ -27,7 +39,7 @@ py::class_(m, "BJobStateListener") .def("JobAborted", &BJobStateListener::JobAborted, "", py::arg("job")) ; -py::class_(m, "BJob") +py::class_(m, "BJob") .def(py::init(), "", py::arg("title")) .def("InitCheck", &BJob::InitCheck, "") .def("Run", &BJob::Run, "") @@ -43,7 +55,7 @@ py::class_(m, "BJob") .def("RemoveDependency", &BJob::RemoveDependency, "", py::arg("job")) .def("CountDependencies", &BJob::CountDependencies, "") .def("DependantJobAt", &BJob::DependantJobAt, "", py::arg("index")) -.def_readwrite("Private", &BJob::Private, "") +//.def_readwrite("Private", &BJob::Private, "") ; From b82abfe86a745839a20937cecc2ca84a788fac35 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 9 Sep 2024 10:35:54 +0200 Subject: [PATCH 086/115] update unused USBKit --- bindings/device/USBKit.cpp | 41 +++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/bindings/device/USBKit.cpp b/bindings/device/USBKit.cpp index f61c528..94b9c48 100644 --- a/bindings/device/USBKit.cpp +++ b/bindings/device/USBKit.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -48,7 +49,13 @@ py::class_(m, "BUSBDevice") .def("Descriptor", &BUSBDevice::Descriptor, "") .def("GetStringDescriptor", &BUSBDevice::GetStringDescriptor, "", py::arg("index"), py::arg("descriptor"), py::arg("length")) .def("DecodeStringDescriptor", &BUSBDevice::DecodeStringDescriptor, "", py::arg("index")) -.def("GetDescriptor", &BUSBDevice::GetDescriptor, "", py::arg("type"), py::arg("index"), py::arg("languageID"), py::arg("data"), py::arg("length")) +//.def("GetDescriptor", &BUSBDevice::GetDescriptor, "", py::arg("type"), py::arg("index"), py::arg("languageID"), py::arg("data"), py::arg("length")) //todo: void *data -> in py::bytes +.def("GetDescriptor", [](const BUSBDevice& self, uint8 type, uint8 index, uint16 languageID, py::bytes data) { + size_t length = py::len(data); + std::vector buffer(length); + size_t resultLength = self.GetDescriptor(type, index, languageID, buffer.data(), length); + return py::bytes(reinterpret_cast(buffer.data()), resultLength); +},"", py::arg("type"), py::arg("index"), py::arg("languageID"), py::arg("data")) .def("CountConfigurations", &BUSBDevice::CountConfigurations, "") .def("ConfigurationAt", &BUSBDevice::ConfigurationAt, "", py::arg("index")) .def("ActiveConfiguration", &BUSBDevice::ActiveConfiguration, "") @@ -98,10 +105,34 @@ py::class_>(m, "BUSBEnd .def("MaxPacketSize", &BUSBEndpoint::MaxPacketSize, "") .def("Interval", &BUSBEndpoint::Interval, "") .def("Descriptor", &BUSBEndpoint::Descriptor, "") -.def("ControlTransfer", &BUSBEndpoint::ControlTransfer, "", py::arg("requestType"), py::arg("request"), py::arg("value"), py::arg("index"), py::arg("length"), py::arg("data")) -.def("InterruptTransfer", &BUSBEndpoint::InterruptTransfer, "", py::arg("data"), py::arg("length")) -.def("BulkTransfer", &BUSBEndpoint::BulkTransfer, "", py::arg("data"), py::arg("length")) -.def("IsochronousTransfer", &BUSBEndpoint::IsochronousTransfer, "", py::arg("data"), py::arg("length"), py::arg("packetDescriptors"), py::arg("packetCount")) +//.def("ControlTransfer", &BUSBEndpoint::ControlTransfer, "", py::arg("requestType"), py::arg("request"), py::arg("value"), py::arg("index"), py::arg("length"), py::arg("data")) +.def("ControlTransfer", [](const BUSBEndpoint& self, uint8 requestType, uint8 request, uint16 value, uint16 index, uint16 length, py::bytes data) { + size_t dataLength = py::len(data); + std::vector buffer(dataLength); + ssize_t result = self.ControlTransfer(requestType, request, value, index, length, buffer.data()); + return py::bytes(reinterpret_cast(buffer.data()), result); +},"", py::arg("requestType"), py::arg("request"), py::arg("value"), py::arg("index"), py::arg("length"), py::arg("data")) .def("InterruptTransfer", [](const MyDevice& self, py::bytes data) { size_t dataLength = py::len(data); std::vector buffer(dataLength); ssize_t result = self.InterruptTransfer(buffer.data(), dataLength); return py::bytes(reinterpret_cast(buffer.data()), result); }, py::arg("data")) .def("BulkTransfer", [](const MyDevice& self, py::bytes data) { size_t dataLength = py::len(data); std::vector buffer(dataLength); ssize_t result = self.BulkTransfer(buffer.data(), dataLength); return py::bytes(reinterpret_cast(buffer.data()), result); }, py::arg("data")) .def("IsochronousTransfer", [](const MyDevice& self, py::bytes data, py::list packetDescriptors) { size_t dataLength = py::len(data); std::vector buffer(dataLength); // Converti packetDescriptors da lista Python a un array C++ std::vector descriptors; for (auto item : packetDescriptors) { descriptors.push_back(item.cast()); } ssize_t result = self.IsochronousTransfer(buffer.data(), dataLength, descriptors.data(), descriptors.size()); return py::bytes(reinterpret_cast(buffer.data()), result); }, py::arg("data"), py::arg("packetDescriptors")) +//.def("InterruptTransfer", &BUSBEndpoint::InterruptTransfer, "", py::arg("data"), py::arg("length")) +.def("InterruptTransfer", [](const BUSBEndpoint& self, py::bytes data) { + size_t dataLength = py::len(data); + std::vector buffer(dataLength); + ssize_t result = self.InterruptTransfer(buffer.data(), dataLength); + return py::bytes(reinterpret_cast(buffer.data()), result); +},"", py::arg("data")) +//.def("BulkTransfer", &BUSBEndpoint::BulkTransfer, "", py::arg("data"), py::arg("length")) +.def("BulkTransfer", [](const BUSBEndpoint& self, py::bytes data) { + size_t dataLength = py::len(data); + std::vector buffer(dataLength); + ssize_t result = self.BulkTransfer(buffer.data(), dataLength); + return py::bytes(reinterpret_cast(buffer.data()), result); +},"", py::arg("data")) +//.def("IsochronousTransfer", &BUSBEndpoint::IsochronousTransfer, "", py::arg("data"), py::arg("length"), py::arg("packetDescriptors"), py::arg("packetCount")) +.def("IsochronousTransfer", [](const BUSBEndpoint& self, py::bytes data, usb_iso_packet_descriptor *packetDescriptors, uint32 packetCount) { + size_t dataLength = py::len(data); + std::vector buffer(dataLength); + ssize_t result = self.IsochronousTransfer(buffer.data(), dataLength,packetDescriptors,packetCount); + return py::bytes(reinterpret_cast(buffer.data()), result); +},"", py::arg("data")) .def("IsStalled", &BUSBEndpoint::IsStalled, "") .def("ClearStall", &BUSBEndpoint::ClearStall, "") ; From 096861aead8abe627d101c1e2d201e02d7462541 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 9 Sep 2024 11:25:29 +0200 Subject: [PATCH 087/115] update unused USBKit and SerialPort --- bindings/device/SerialPort.cpp | 21 +++++++++++++++++++-- bindings/device/USBKit.cpp | 4 ++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/bindings/device/SerialPort.cpp b/bindings/device/SerialPort.cpp index 040e7cd..74ebe3e 100644 --- a/bindings/device/SerialPort.cpp +++ b/bindings/device/SerialPort.cpp @@ -56,8 +56,25 @@ py::class_(m, "BSerialPort") .def(py::init(), "") .def("Open", &BSerialPort::Open, "", py::arg("portName")) .def("Close", &BSerialPort::Close, "") -.def("Read", &BSerialPort::Read, "", py::arg("buf"), py::arg("count")) -.def("Write", &BSerialPort::Write, "", py::arg("buf"), py::arg("count")) +//.def("Read", &BSerialPort::Read, "", py::arg("buf"), py::arg("count")) +.def("Read", [](BSerialPort& self, size_t count) { + std::vector buffer(count); + ssize_t result = self.Read(buffer.data(), count); + if (result > 0) { + return py::bytes(reinterpret_cast(buffer.data()), result); + } + return py::bytes(); + }, "", py::arg("count")) +//.def("Write", &BSerialPort::Write, "", py::arg("buf"), py::arg("count")) +.def("Write", [](BSerialPort& self, py::buffer data){ + /*std::string buffer = data; + const void* buf =buffer.data(); + size_t count = buffer.size();*/ + py::buffer_info info = data.request(); + size_t count = info.size; + const void* buffer = info.ptr; + return self.Write(buffer,count); +},"",py::arg("data")) .def("SetBlocking", &BSerialPort::SetBlocking, "", py::arg("blocking")) .def("SetTimeout", &BSerialPort::SetTimeout, "", py::arg("microSeconds")) .def("SetDataRate", &BSerialPort::SetDataRate, "", py::arg("bitsPerSecond")) diff --git a/bindings/device/USBKit.cpp b/bindings/device/USBKit.cpp index 94b9c48..ea3be3c 100644 --- a/bindings/device/USBKit.cpp +++ b/bindings/device/USBKit.cpp @@ -111,7 +111,7 @@ py::class_>(m, "BUSBEnd std::vector buffer(dataLength); ssize_t result = self.ControlTransfer(requestType, request, value, index, length, buffer.data()); return py::bytes(reinterpret_cast(buffer.data()), result); -},"", py::arg("requestType"), py::arg("request"), py::arg("value"), py::arg("index"), py::arg("length"), py::arg("data")) .def("InterruptTransfer", [](const MyDevice& self, py::bytes data) { size_t dataLength = py::len(data); std::vector buffer(dataLength); ssize_t result = self.InterruptTransfer(buffer.data(), dataLength); return py::bytes(reinterpret_cast(buffer.data()), result); }, py::arg("data")) .def("BulkTransfer", [](const MyDevice& self, py::bytes data) { size_t dataLength = py::len(data); std::vector buffer(dataLength); ssize_t result = self.BulkTransfer(buffer.data(), dataLength); return py::bytes(reinterpret_cast(buffer.data()), result); }, py::arg("data")) .def("IsochronousTransfer", [](const MyDevice& self, py::bytes data, py::list packetDescriptors) { size_t dataLength = py::len(data); std::vector buffer(dataLength); // Converti packetDescriptors da lista Python a un array C++ std::vector descriptors; for (auto item : packetDescriptors) { descriptors.push_back(item.cast()); } ssize_t result = self.IsochronousTransfer(buffer.data(), dataLength, descriptors.data(), descriptors.size()); return py::bytes(reinterpret_cast(buffer.data()), result); }, py::arg("data"), py::arg("packetDescriptors")) +},"", py::arg("requestType"), py::arg("request"), py::arg("value"), py::arg("index"), py::arg("length"), py::arg("data")) //.def("InterruptTransfer", &BUSBEndpoint::InterruptTransfer, "", py::arg("data"), py::arg("length")) .def("InterruptTransfer", [](const BUSBEndpoint& self, py::bytes data) { size_t dataLength = py::len(data); @@ -132,7 +132,7 @@ py::class_>(m, "BUSBEnd std::vector buffer(dataLength); ssize_t result = self.IsochronousTransfer(buffer.data(), dataLength,packetDescriptors,packetCount); return py::bytes(reinterpret_cast(buffer.data()), result); -},"", py::arg("data")) +},"", py::arg("data"),py::arg("packetDescriptors"),py::arg("packetCount")) .def("IsStalled", &BUSBEndpoint::IsStalled, "") .def("ClearStall", &BUSBEndpoint::ClearStall, "") ; From 51a1e6ac7bc7cca62e43632b86492a7d3c6ca5de Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 9 Sep 2024 13:01:52 +0200 Subject: [PATCH 088/115] update AddEnclosure in Email.cpp --- bindings/mail/Email.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bindings/mail/Email.cpp b/bindings/mail/Email.cpp index b96ec50..44646ae 100644 --- a/bindings/mail/Email.cpp +++ b/bindings/mail/Email.cpp @@ -53,6 +53,13 @@ void set_reply_to(mail_pop_account& self, const std::string& name) { self.reply_to[128 - 1] = '\0'; } +status_t AddEnclosure_wrapper(BMailMessage& self, const char* MIME_type, py::buffer data, int32 len, bool clobber = false) { + py::buffer_info info = data.request(); + void* buffer = info.ptr; + return self.AddEnclosure(MIME_type, buffer, len, clobber); +} + + PYBIND11_MODULE(Email, m) { py::enum_(m, "read_flags", "") @@ -95,7 +102,8 @@ py::class_(m, "BMailMessage") .def("AddContent", py::overload_cast(&BMailMessage::AddContent), "", py::arg("text"), py::arg("length"), py::arg("encoding"), py::arg("clobber")=false) .def("AddEnclosure", py::overload_cast(&BMailMessage::AddEnclosure), "", py::arg("ref"), py::arg("clobber")=false) .def("AddEnclosure", py::overload_cast(&BMailMessage::AddEnclosure), "", py::arg("path"), py::arg("clobber")=false) -.def("AddEnclosure", py::overload_cast(&BMailMessage::AddEnclosure), "", py::arg("MIME_type"), py::arg("data"), py::arg("len"), py::arg("clobber")=false) +//.def("AddEnclosure", py::overload_cast(&BMailMessage::AddEnclosure), "", py::arg("MIME_type"), py::arg("data"), py::arg("len"), py::arg("clobber")=false) +.def("AddEnclosure", &AddEnclosure_wrapper, "", py::arg("MIME_type"), py::arg("data"), py::arg("len"), py::arg("clobber")=false) .def("AddHeaderField", py::overload_cast(&BMailMessage::AddHeaderField), "", py::arg("encoding"), py::arg("field_name"), py::arg("str"), py::arg("clobber")=false) .def("AddHeaderField", py::overload_cast(&BMailMessage::AddHeaderField), "", py::arg("field_name"), py::arg("str"), py::arg("clobber")=false) .def("Send", &BMailMessage::Send, "", py::arg("sendNow")=false, py::arg("removeAfterSending")=false) From 76fa25b9be454e5fa305c40f2b9ea2b61d6ebfc7 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 9 Sep 2024 13:15:10 +0200 Subject: [PATCH 089/115] add todo comment --- bindings/support/ByteOrder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/support/ByteOrder.cpp b/bindings/support/ByteOrder.cpp index fce11f8..4117130 100644 --- a/bindings/support/ByteOrder.cpp +++ b/bindings/support/ByteOrder.cpp @@ -42,7 +42,7 @@ py::enum_(m, "swap_action", "") .value("B_SWAP_ALWAYS", swap_action::B_SWAP_ALWAYS, "") .export_values(); -m.def("swap_data", &swap_data, "", py::arg("type"), py::arg("data"), py::arg("length"), py::arg("action")); +m.def("swap_data", &swap_data, "", py::arg("type"), py::arg("data"), py::arg("length"), py::arg("action")); //todo data is a void* convert to py::buffer or py::bytes m.def("is_type_swapped", &is_type_swapped, "", py::arg("type")); From c8a4f06cb9f0377fdf421c29fa770f0f1376348e Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 9 Sep 2024 13:16:01 +0200 Subject: [PATCH 090/115] add todo comment --- bindings/support/TLS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/support/TLS.cpp b/bindings/support/TLS.cpp index 6169125..23a0852 100644 --- a/bindings/support/TLS.cpp +++ b/bindings/support/TLS.cpp @@ -15,6 +15,6 @@ m.def("tls_get", &tls_get, "", py::arg("index")); m.def("tls_address", &tls_address, "", py::arg("index")); -m.def("tls_set", &tls_set, "", py::arg("index"), py::arg("value")); +m.def("tls_set", &tls_set, "", py::arg("index"), py::arg("value")); //todo value is a void* } From 5d619110892d1d1517fe0637eab88274f5bc9459 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 9 Sep 2024 14:05:22 +0200 Subject: [PATCH 091/115] return bytes not void* from Get --- bindings/support/BlockCache.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/bindings/support/BlockCache.cpp b/bindings/support/BlockCache.cpp index fccb5cf..20f5b32 100644 --- a/bindings/support/BlockCache.cpp +++ b/bindings/support/BlockCache.cpp @@ -7,6 +7,25 @@ namespace py = pybind11; +/* +py::bytes Get_wrapper(size_t blockSize) { + void* data = Get(blockSize); + py::buffer buffer; + + if (data == nullptr) { + throw std::runtime_error("Failed to get data"); + } + return py::bytes(static_cast(data), blockSize); +}*/ +py::bytes Get_wrapper2(BBlockCache& self, size_t blockSize) { + void* data = self.Get(blockSize); + if (data == nullptr) { + throw std::runtime_error("Failed to get data"); + } + py::buffer_info buf_info(static_cast(data), sizeof(char), py::format_descriptor::format(), 1, {blockSize}, {sizeof(char)} ); + //return py::array(buf_info); + return py::bytes(static_cast(buf_info.ptr), buf_info.size * buf_info.itemsize); //convert py::buffer to py::bytes +}; PYBIND11_MODULE(BlockCache, m) { @@ -15,8 +34,9 @@ m.attr("B_MALLOC_CACHE") = 1;//py::cast(B_MALLOC_CACHE); py::class_(m, "BBlockCache") .def(py::init(), "", py::arg("blockCount"), py::arg("blockSize"), py::arg("allocationType")) -.def("Get", &BBlockCache::Get, "", py::arg("blockSize")) -.def("Save", &BBlockCache::Save, "", py::arg("pointer"), py::arg("blockSize")) +//.def("Get", &BBlockCache::Get, "", py::arg("blockSize"))//TODO this returns a void * -- let's return a py::bytes or a py::buffer +.def("Get", &Get_wrapper2, "", py::arg("blockSize")) +.def("Save", &BBlockCache::Save, "", py::arg("pointer"), py::arg("blockSize"))//TODO: pointer is a void * -> python can't use void * ; From f0f01ae48c7adda003ae0a68c42ac59e0b2487e8 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 9 Sep 2024 15:24:49 +0200 Subject: [PATCH 092/115] test purpose,revert please --- bindings/support/BlockCache.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/bindings/support/BlockCache.cpp b/bindings/support/BlockCache.cpp index 20f5b32..d569edc 100644 --- a/bindings/support/BlockCache.cpp +++ b/bindings/support/BlockCache.cpp @@ -36,7 +36,32 @@ py::class_(m, "BBlockCache") .def(py::init(), "", py::arg("blockCount"), py::arg("blockSize"), py::arg("allocationType")) //.def("Get", &BBlockCache::Get, "", py::arg("blockSize"))//TODO this returns a void * -- let's return a py::bytes or a py::buffer .def("Get", &Get_wrapper2, "", py::arg("blockSize")) -.def("Save", &BBlockCache::Save, "", py::arg("pointer"), py::arg("blockSize"))//TODO: pointer is a void * -> python can't use void * +.def("Get2", [](BBlockCache& self, size_t blockSize)->py::tuple{ + std::vectorbuffer(blockSize); + void* data = self.Get(blockSize); + if (data != nullptr) { + std::memcpy(buffer.data(), data, blockSize); + } + py::bytes pyBytes(buffer.data(),blockSize); + return py::make_tuple(pyBytes, blockSize); +},"",py::arg("blockSize")) +//.def("Save", &BBlockCache::Save, "", py::arg("pointer"), py::arg("blockSize"))//TODO: pointer is a void * -> python can't use void * +.def("Save", [](BBlockCache& self, py::bytes data) {//if we pass a py::bytes we already pass the size along with data right? +/* std::string byt = py::str(data); + void* pointer = static_cast(const_cast(byt.data())); + self.Save(pointer, byt.size());*/ + char* pointer; + ssize_t size; + PYBIND11_BYTES_AS_STRING_AND_SIZE(data.ptr(), &pointer, &size); + self.Save(static_cast(pointer), static_cast(size)); + },"", py::arg("data")) +.def("Save_from_buffer", [](BBlockCache& self, py::buffer py_buffer){ + py::buffer_info buf_info = py_buffer.request(); + void* pointer = buf_info.ptr; + //size_t blockSize = buf_info.size * buf_info.itemsize; + size_t blockSize = buf_info.size; + self.Save(pointer, blockSize); +},"",py::arg("py_buffer")) ; From 90889c75806f1847e35ea6f10d3908223e558525 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 14 Sep 2024 00:36:21 +0200 Subject: [PATCH 093/115] Attempt to fix text_run_array style --- bindings/interface/TextView.cpp | 52 ++++++++++++++++++++++++++++++++- tmtest.py | 25 ++++++++-------- 2 files changed, 64 insertions(+), 13 deletions(-) diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index d61d22d..11ac2a9 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -15,6 +15,20 @@ namespace py = pybind11; using namespace BPrivate; +/* +struct text_run { + int32_t offset; + BFont font; + rgb_color color; +}; + +struct text_run_array { + int32_t count; + std::vector runs; + text_run_array(int32_t count) : count(count), runs(count) {} +}; +*/ + class PyBTextView : public BTextView{ public: using BTextView::BTextView; @@ -131,6 +145,7 @@ py::class_(m, "text_run_array") .def(py::init<>()) .def_readwrite("count", &text_run_array::count, "") //.def_readonly("runs", &text_run_array::runs, "") +/*first attempt .def_property("runs",[](const text_run_array& self){ return std::vector(self.runs, self.runs + self.text_run_array::count); },[](text_run_array& self, const std::vector& new_values) { @@ -139,8 +154,43 @@ py::class_(m, "text_run_array") } std::copy(new_values.begin(),new_values.end(),self.runs); }) +;*/ +/* +.def_property("runs",[](const text_run_array& self){ + return std::vector(self.runs, self.runs + self.text_run_array::count); + },[](text_run_array& self, const std::vector& new_values) { + if (new_values.size() != self.count){ + throw std::runtime_error("Invalid buffer size or dimensions"); + } + std::memcpy(self.runs, new_values.data(), new_values.size() * sizeof(text_run)); + //std::copy(new_values.begin(),new_values.end(),self.runs); + }) +;*/ +.def_property("runs",[](const text_run_array& self){ + return std::vector(self.runs, self.runs + self.text_run_array::count); + },[](text_run_array& self, const py::list &new_values) { + std::vector newruns; + for (auto item : new_values) { + newruns.push_back(item.cast()); + } + std::memcpy(self.runs, newruns.data(), newruns.size() * sizeof(text_run)); + }) ; - +/* look at this +/*suggested attempt +py::class_(m, "text_run_array") +.def(py::init(), py::arg("count") = 1) +.def_readwrite("count", &text_run_array::count) +.def_property("runs", [](const text_run_array& self) { + return self.runs; + }, + [](text_run_array& self, const std::vector& new_values) { + if (new_values.size() != self.count) { + throw std::runtime_error("Invalid buffer size or dimensions"); + } + self.runs = new_values; + }) +;*/ /* py::class_(m, "text_run_array") .def_readwrite("count", &text_run_array::count, "") diff --git a/tmtest.py b/tmtest.py index 27a4de6..426bdb5 100644 --- a/tmtest.py +++ b/tmtest.py @@ -14,7 +14,9 @@ from Be import BEntry from Be.Entry import entry_ref from Be.Entry import get_ref_for_path - +from Be.TextView import text_run,text_run_array +from Be.View import set_font_mask +B_FONT_ALL = set_font_mask.B_FONT_ALL class PBox(BBox): def __init__(self,frame,name,immagine): @@ -317,9 +319,6 @@ def __init__(self): self.typtap.SetText(stuff,None)#, [(0, be_plain_font, (0, 0, 0, 0)), (n, be_bold_font, (0, 150, 0, 0)), (n + 14, be_plain_font, (0, 0, 0, 0)),(m,be_plain_font,(100,150,0,0))]) self.AddChild(self.bckgnd,None) tra=self.typtap.RunArray(0,len(self.typtap.Text())) - #print("runarray count",tra.count) - #print("tra.runs è\n",tra.runs) - #print(tra.runs[0].offset,tra.runs[0].font,tra.runs[0].color) self.panel.AddChild(self.list.topview(),None) pittura=rgb_color() pittura.red=255 @@ -331,21 +330,23 @@ def __init__(self): pictura.green=255 pictura.blue=0 pictura.alpha=255 - from Be.TextView import text_run + tr1=text_run() tr1.offset=0 - tr1.font=be_plain_font + tr1.font=BFont(be_plain_font) tr1.color=pittura tr2=text_run() - tr2.offset=10 - tr2.font=be_bold_font + tr2.offset=20 + tr2.font=BFont(be_bold_font) tr2.color=pictura mytralist=[tr1,tr2] - #this is the way to write text_run_arrays - tra.count=2 #increase the count - #print("ora tra.count è 2") - #print("e ora tra.runs è\n",tra.runs) #now you have 2 text_runs + tra.count=2 #now you have 2 text_runs tra.runs[1] = tr2 #assign the second one + self.typtap.SetRunArray(0,len(self.typtap.Text()),tra) #this doesn't work + trb=text_run_array() + trb.count=2 + trb.runs=mytralist + self.typtap.SetRunArray(0,len(self.typtap.Text()),trb) #this works, why error exiting and why does trb need tra (or it won't work) #print(tra.runs[1].color.green) ###################### add other text_runs ###### Example handling refs / BEntry ##### From 67fd2de94a1c47c13d9dda7eb02208dac1b38505 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 14 Sep 2024 10:21:02 +0200 Subject: [PATCH 094/115] update tmtest.py for BTextView run_array tests --- tmtest.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tmtest.py b/tmtest.py index 426bdb5..3724b7d 100644 --- a/tmtest.py +++ b/tmtest.py @@ -316,10 +316,10 @@ def __init__(self): stuff = '\n\t\t\t\t\t\tHello Haiku!\n\n\t\t\t\t\t\t\t\tA simple test program\n\t\t\t\t\t\t\t\tfor Haiku, version 1.0\n\t\t\t\t\t\t\t\tsample code included!\n\n\t\t\t\t\t\t\t\tby Fabio Tomat aka TmTFx\n\t\t\t\t\t\t\t\tand others\n\t\t\t\t\t\t\t\t\t\t\t\n\n\t\t\t\t\t\t\t\tspecial thanks to:\n\t\t\t\t\t\t\t\tZardshard and coolcoder613' #n = stuff.find('Bulletin Gator') #m = stuff.find('This') - self.typtap.SetText(stuff,None)#, [(0, be_plain_font, (0, 0, 0, 0)), (n, be_bold_font, (0, 150, 0, 0)), (n + 14, be_plain_font, (0, 0, 0, 0)),(m,be_plain_font,(100,150,0,0))]) + #self.typtap.SetText(stuff,None)#, [(0, be_plain_font, (0, 0, 0, 0)), (n, be_bold_font, (0, 150, 0, 0)), (n + 14, be_plain_font, (0, 0, 0, 0)),(m,be_plain_font,(100,150,0,0))]) self.AddChild(self.bckgnd,None) - tra=self.typtap.RunArray(0,len(self.typtap.Text())) self.panel.AddChild(self.list.topview(),None) + ##self.tra=self.typtap.RunArray(0,len(self.typtap.Text())) pittura=rgb_color() pittura.red=255 pittura.green=0 @@ -340,14 +340,18 @@ def __init__(self): tr2.font=BFont(be_bold_font) tr2.color=pictura mytralist=[tr1,tr2] - tra.count=2 #now you have 2 text_runs - tra.runs[1] = tr2 #assign the second one - self.typtap.SetRunArray(0,len(self.typtap.Text()),tra) #this doesn't work - trb=text_run_array() - trb.count=2 - trb.runs=mytralist - self.typtap.SetRunArray(0,len(self.typtap.Text()),trb) #this works, why error exiting and why does trb need tra (or it won't work) + ##tra.count=2 #now you have 2 text_runs + ##tra.runs[1] = tr2 #assign the second one + ##print("tra runs modified",tra.runs) + ##self.typtap.SetRunArray(0,len(self.typtap.Text()),tra) #this doesn't work + self.trb=text_run_array() + #trb=self.typtap.RunArray(0,len(self.typtap.Text()))#this crashes + self.trb.count=2 + self.trb.runs=mytralist + self.typtap.SetText(stuff,self.trb) + #self.typtap.SetRunArray(0,len(self.typtap.Text()),trb) #this works, why error exiting and why does trb need tra (or it won't work) #print(tra.runs[1].color.green) + #self.typtap.SetText(stuff,trb) ###################### add other text_runs ###### Example handling refs / BEntry ##### a=entry_ref() From 59bb0996a9f5524523a08cc3abbc4b9870998ca2 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 14 Sep 2024 10:22:13 +0200 Subject: [PATCH 095/115] todo comments --- bindings/interface/TextView.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index 11ac2a9..7db2114 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -303,8 +303,8 @@ py::class_ Date: Sat, 14 Sep 2024 11:35:21 +0200 Subject: [PATCH 096/115] link BufferConsumer to lmedia --- Jamfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jamfile b/Jamfile index 15c8cb1..30196e6 100644 --- a/Jamfile +++ b/Jamfile @@ -402,7 +402,7 @@ LINKLIBS on SoundPlayer.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimeCode.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimeSource.so = $(LINKLIBS) -lmedia ; LINKLIBS on TimedEventQueue.so = $(LINKLIBS) -lmedia ; -#LINKLIBS on BufferConsumer.so = $(LINKLIBS) -lmedia ; +LINKLIBS on BufferConsumer.so = $(LINKLIBS) -lmedia ; LINKLIBS on ScreenSaver.so = $(LINKLIBS) -lscreensaver ; #LINKLIBS on MimeSnifferAddon.so = $(LINKLIBS) -lstoragekit ; From 27cca92b563b923deb3fcedd6784e5dcdf34903d Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 15 Sep 2024 20:43:54 +0200 Subject: [PATCH 097/115] update Accelerant.cpp --- bindings/__init__.py | 2 +- bindings/add-ons/graphics/Accelerant.cpp | 120 +++++++++++------------ 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/bindings/__init__.py b/bindings/__init__.py index c085d34..5e1d4b6 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -152,7 +152,7 @@ #from .ScreenSaver import * #from .MimeSnifferAddon import * -#from .Accelerant import * +from .Accelerant import * #from .GraphicsCard import * #from .InputServerDevice import * #from .InputServerFilter import * diff --git a/bindings/add-ons/graphics/Accelerant.cpp b/bindings/add-ons/graphics/Accelerant.cpp index 4315f5c..e32b487 100644 --- a/bindings/add-ons/graphics/Accelerant.cpp +++ b/bindings/add-ons/graphics/Accelerant.cpp @@ -17,69 +17,69 @@ enum production { PYBIND11_MODULE(Accelerant, m) { -m.attr("B_INIT_ACCELERANT") = py::cast(B_INIT_ACCELERANT); -m.attr("B_ACCELERANT_CLONE_INFO_SIZE") = py::cast(B_ACCELERANT_CLONE_INFO_SIZE); -m.attr("B_GET_ACCELERANT_CLONE_INFO") = py::cast(B_GET_ACCELERANT_CLONE_INFO); -m.attr("B_CLONE_ACCELERANT") = py::cast(B_CLONE_ACCELERANT); -m.attr("B_UNINIT_ACCELERANT") = py::cast(B_UNINIT_ACCELERANT); -m.attr("B_GET_ACCELERANT_DEVICE_INFO") = py::cast(B_GET_ACCELERANT_DEVICE_INFO); -m.attr("B_ACCELERANT_RETRACE_SEMAPHORE") = py::cast(B_ACCELERANT_RETRACE_SEMAPHORE); -m.attr("B_ACCELERANT_MODE_COUNT") = py::cast(B_ACCELERANT_MODE_COUNT); -m.attr("B_GET_MODE_LIST") = py::cast(B_GET_MODE_LIST); -m.attr("B_PROPOSE_DISPLAY_MODE") = py::cast(B_PROPOSE_DISPLAY_MODE); -m.attr("B_SET_DISPLAY_MODE") = py::cast(B_SET_DISPLAY_MODE); -m.attr("B_GET_DISPLAY_MODE") = py::cast(B_GET_DISPLAY_MODE); -m.attr("B_GET_FRAME_BUFFER_CONFIG") = py::cast(B_GET_FRAME_BUFFER_CONFIG); -m.attr("B_GET_PIXEL_CLOCK_LIMITS") = py::cast(B_GET_PIXEL_CLOCK_LIMITS); -m.attr("B_GET_TIMING_CONSTRAINTS") = py::cast(B_GET_TIMING_CONSTRAINTS); -m.attr("B_MOVE_DISPLAY") = py::cast(B_MOVE_DISPLAY); -m.attr("B_SET_INDEXED_COLORS") = py::cast(B_SET_INDEXED_COLORS); -m.attr("B_DPMS_CAPABILITIES") = py::cast(B_DPMS_CAPABILITIES); -m.attr("B_DPMS_MODE") = py::cast(B_DPMS_MODE); -m.attr("B_SET_DPMS_MODE") = py::cast(B_SET_DPMS_MODE); -m.attr("B_GET_PREFERRED_DISPLAY_MODE") = py::cast(B_GET_PREFERRED_DISPLAY_MODE); -m.attr("B_GET_MONITOR_INFO") = py::cast(B_GET_MONITOR_INFO); -m.attr("B_GET_EDID_INFO") = py::cast(B_GET_EDID_INFO); -m.attr("B_SET_BRIGHTNESS") = py::cast(B_SET_BRIGHTNESS); -m.attr("B_GET_BRIGHTNESS") = py::cast(B_GET_BRIGHTNESS); -m.attr("B_MOVE_CURSOR") = py::cast(B_MOVE_CURSOR); -m.attr("B_SET_CURSOR_SHAPE") = py::cast(B_SET_CURSOR_SHAPE); -m.attr("B_SHOW_CURSOR") = py::cast(B_SHOW_CURSOR); -m.attr("B_SET_CURSOR_BITMAP") = py::cast(B_SET_CURSOR_BITMAP); -m.attr("B_ACCELERANT_ENGINE_COUNT") = py::cast(B_ACCELERANT_ENGINE_COUNT); -m.attr("B_ACQUIRE_ENGINE") = py::cast(B_ACQUIRE_ENGINE); -m.attr("B_RELEASE_ENGINE") = py::cast(B_RELEASE_ENGINE); -m.attr("B_WAIT_ENGINE_IDLE") = py::cast(B_WAIT_ENGINE_IDLE); -m.attr("B_GET_SYNC_TOKEN") = py::cast(B_GET_SYNC_TOKEN); -m.attr("B_SYNC_TO_TOKEN") = py::cast(B_SYNC_TO_TOKEN); -m.attr("B_SCREEN_TO_SCREEN_BLIT") = py::cast(B_SCREEN_TO_SCREEN_BLIT); -m.attr("B_FILL_RECTANGLE") = py::cast(B_FILL_RECTANGLE); -m.attr("B_INVERT_RECTANGLE") = py::cast(B_INVERT_RECTANGLE); -m.attr("B_FILL_SPAN") = py::cast(B_FILL_SPAN); -m.attr("B_SCREEN_TO_SCREEN_TRANSPARENT_BLIT") = py::cast(B_SCREEN_TO_SCREEN_TRANSPARENT_BLIT); -m.attr("B_SCREEN_TO_SCREEN_SCALED_FILTERED_BLIT") = py::cast(B_SCREEN_TO_SCREEN_SCALED_FILTERED_BLIT); -m.attr("B_ACCELERANT_PRIVATE_START") = py::cast(B_ACCELERANT_PRIVATE_START); +m.attr("B_INIT_ACCELERANT") = 0;//py::cast(B_INIT_ACCELERANT); +m.attr("B_ACCELERANT_CLONE_INFO_SIZE") = 1;//py::cast(B_ACCELERANT_CLONE_INFO_SIZE); +m.attr("B_GET_ACCELERANT_CLONE_INFO") = 2;//py::cast(B_GET_ACCELERANT_CLONE_INFO); +m.attr("B_CLONE_ACCELERANT") = 3;//py::cast(B_CLONE_ACCELERANT); +m.attr("B_UNINIT_ACCELERANT") = 4;//py::cast(B_UNINIT_ACCELERANT); +m.attr("B_GET_ACCELERANT_DEVICE_INFO") = 5;//py::cast(B_GET_ACCELERANT_DEVICE_INFO); +m.attr("B_ACCELERANT_RETRACE_SEMAPHORE") = 6;//py::cast(B_ACCELERANT_RETRACE_SEMAPHORE); +m.attr("B_ACCELERANT_MODE_COUNT") = 0x100;//py::cast(B_ACCELERANT_MODE_COUNT); +m.attr("B_GET_MODE_LIST") = 0x101;//py::cast(B_GET_MODE_LIST); +m.attr("B_PROPOSE_DISPLAY_MODE") = 0x102;//py::cast(B_PROPOSE_DISPLAY_MODE); +m.attr("B_SET_DISPLAY_MODE") = 0x103;//py::cast(B_SET_DISPLAY_MODE); +m.attr("B_GET_DISPLAY_MODE") = 0x104;//py::cast(B_GET_DISPLAY_MODE); +m.attr("B_GET_FRAME_BUFFER_CONFIG") = 0x105;//py::cast(B_GET_FRAME_BUFFER_CONFIG); +m.attr("B_GET_PIXEL_CLOCK_LIMITS") = 0x106;//py::cast(B_GET_PIXEL_CLOCK_LIMITS); +m.attr("B_GET_TIMING_CONSTRAINTS") = 0x107;//py::cast(B_GET_TIMING_CONSTRAINTS); +m.attr("B_MOVE_DISPLAY") = 0x108;//py::cast(B_MOVE_DISPLAY); +m.attr("B_SET_INDEXED_COLORS") = 0x109;//py::cast(B_SET_INDEXED_COLORS); +m.attr("B_DPMS_CAPABILITIES") = 0x10A;//py::cast(B_DPMS_CAPABILITIES); +m.attr("B_DPMS_MODE") = 0x10B;//py::cast(B_DPMS_MODE); +m.attr("B_SET_DPMS_MODE") = 0x10C;//py::cast(B_SET_DPMS_MODE); +m.attr("B_GET_PREFERRED_DISPLAY_MODE") = 0x10D;//py::cast(B_GET_PREFERRED_DISPLAY_MODE); +m.attr("B_GET_MONITOR_INFO") = 0x10E;//py::cast(B_GET_MONITOR_INFO); +m.attr("B_GET_EDID_INFO") = 0x10F;//py::cast(B_GET_EDID_INFO); +m.attr("B_SET_BRIGHTNESS") = 0x110;//py::cast(B_SET_BRIGHTNESS); +m.attr("B_GET_BRIGHTNESS") = 0x111;//py::cast(B_GET_BRIGHTNESS); +m.attr("B_MOVE_CURSOR") = 0x200;//py::cast(B_MOVE_CURSOR); +m.attr("B_SET_CURSOR_SHAPE") = 0x201;//py::cast(B_SET_CURSOR_SHAPE); +m.attr("B_SHOW_CURSOR") = 0x202;//py::cast(B_SHOW_CURSOR); +m.attr("B_SET_CURSOR_BITMAP") = 0x203;//py::cast(B_SET_CURSOR_BITMAP); +m.attr("B_ACCELERANT_ENGINE_COUNT") = 0x300;//py::cast(B_ACCELERANT_ENGINE_COUNT); +m.attr("B_ACQUIRE_ENGINE") = 0x301;//py::cast(B_ACQUIRE_ENGINE); +m.attr("B_RELEASE_ENGINE") = 0x302;//py::cast(B_RELEASE_ENGINE); +m.attr("B_WAIT_ENGINE_IDLE") = 0x303;//py::cast(B_WAIT_ENGINE_IDLE); +m.attr("B_GET_SYNC_TOKEN") = 0x304;//py::cast(B_GET_SYNC_TOKEN); +m.attr("B_SYNC_TO_TOKEN") = 0x305;//py::cast(B_SYNC_TO_TOKEN); +m.attr("B_SCREEN_TO_SCREEN_BLIT") = 0x400;//py::cast(B_SCREEN_TO_SCREEN_BLIT); +m.attr("B_FILL_RECTANGLE") = 0x401;//py::cast(B_FILL_RECTANGLE); +m.attr("B_INVERT_RECTANGLE") = 0x402;//py::cast(B_INVERT_RECTANGLE); +m.attr("B_FILL_SPAN") = 0x403;//py::cast(B_FILL_SPAN); +m.attr("B_SCREEN_TO_SCREEN_TRANSPARENT_BLIT") = 0x404;//py::cast(B_SCREEN_TO_SCREEN_TRANSPARENT_BLIT); +m.attr("B_SCREEN_TO_SCREEN_SCALED_FILTERED_BLIT") = 0x405;//py::cast(B_SCREEN_TO_SCREEN_SCALED_FILTERED_BLIT); +m.attr("B_ACCELERANT_PRIVATE_START") = (int)0x80000000;//py::cast(B_ACCELERANT_PRIVATE_START); -m.attr("B_SCROLL") = py::cast(B_SCROLL); -m.attr("B_8_BIT_DAC") = py::cast(B_8_BIT_DAC); -m.attr("B_HARDWARE_CURSOR") = py::cast(B_HARDWARE_CURSOR); -m.attr("B_PARALLEL_ACCESS") = py::cast(B_PARALLEL_ACCESS); -m.attr("B_DPMS") = py::cast(B_DPMS); -m.attr("B_IO_FB_NA") = py::cast(B_IO_FB_NA); +m.attr("B_SCROLL") = 1 << 0;//py::cast(B_SCROLL); +m.attr("B_8_BIT_DAC") = 1 << 1;//py::cast(B_8_BIT_DAC); +m.attr("B_HARDWARE_CURSOR") = 1 << 2;//py::cast(B_HARDWARE_CURSOR); +m.attr("B_PARALLEL_ACCESS") = 1 << 3;//py::cast(B_PARALLEL_ACCESS); +m.attr("B_DPMS") = 1 << 4;//py::cast(B_DPMS); +m.attr("B_IO_FB_NA") = 1 << 5;//py::cast(B_IO_FB_NA); -m.attr("B_DPMS_ON") = py::cast(B_DPMS_ON); -m.attr("B_DPMS_STAND_BY") = py::cast(B_DPMS_STAND_BY); -m.attr("B_DPMS_SUSPEND") = py::cast(B_DPMS_SUSPEND); -m.attr("B_DPMS_OFF") = py::cast(B_DPMS_OFF); +m.attr("B_DPMS_ON") = 1 << 0;//py::cast(B_DPMS_ON); +m.attr("B_DPMS_STAND_BY") = 1 << 1;//py::cast(B_DPMS_STAND_BY); +m.attr("B_DPMS_SUSPEND") = 1 << 2;//py::cast(B_DPMS_SUSPEND); +m.attr("B_DPMS_OFF") = 1 << 3;//py::cast(B_DPMS_OFF); -m.attr("B_BLANK_PEDESTAL") = py::cast(B_BLANK_PEDESTAL); -m.attr("B_TIMING_INTERLACED") = py::cast(B_TIMING_INTERLACED); -m.attr("B_POSITIVE_HSYNC") = py::cast(B_POSITIVE_HSYNC); -m.attr("B_POSITIVE_VSYNC") = py::cast(B_POSITIVE_VSYNC); -m.attr("B_SYNC_ON_GREEN") = py::cast(B_SYNC_ON_GREEN); +m.attr("B_BLANK_PEDESTAL") = 1 << 27;//py::cast(B_BLANK_PEDESTAL); +m.attr("B_TIMING_INTERLACED") = 1 << 28;//py::cast(B_TIMING_INTERLACED); +m.attr("B_POSITIVE_HSYNC") = 1 << 29;//py::cast(B_POSITIVE_HSYNC); +m.attr("B_POSITIVE_VSYNC") = 1 << 30;//py::cast(B_POSITIVE_VSYNC); +m.attr("B_SYNC_ON_GREEN") = 1 << 31;//py::cast(B_SYNC_ON_GREEN); -m.attr("B_2D_ACCELERATION") = py::cast(B_2D_ACCELERATION); -m.attr("B_3D_ACCELERATION") = py::cast(B_3D_ACCELERATION); +m.attr("B_2D_ACCELERATION") = 1 << 0;//py::cast(B_2D_ACCELERATION); +m.attr("B_3D_ACCELERATION") = 1 << 1;//py::cast(B_3D_ACCELERATION); py::class_(m, "accelerant_device_info") .def_readwrite("version", &accelerant_device_info::version, "") @@ -294,6 +294,6 @@ py::class_(m, "sync_token") , "") ; -m.def("get_accelerant_hook", &get_accelerant_hook, "", py::arg("feature"), py::arg("data")); +//m.def("get_accelerant_hook", &get_accelerant_hook, "", py::arg("feature"), py::arg("data")); } From 526d889e155fdba1ac32323780ee1610905d092a Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 15 Sep 2024 20:50:04 +0200 Subject: [PATCH 098/115] update Accelerant.cpp implement inits --- bindings/add-ons/graphics/Accelerant.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bindings/add-ons/graphics/Accelerant.cpp b/bindings/add-ons/graphics/Accelerant.cpp index e32b487..2800905 100644 --- a/bindings/add-ons/graphics/Accelerant.cpp +++ b/bindings/add-ons/graphics/Accelerant.cpp @@ -82,6 +82,7 @@ m.attr("B_2D_ACCELERATION") = 1 << 0;//py::cast(B_2D_ACCELERATION); m.attr("B_3D_ACCELERATION") = 1 << 1;//py::cast(B_3D_ACCELERATION); py::class_(m, "accelerant_device_info") +.def(py::init(), "") .def_readwrite("version", &accelerant_device_info::version, "") //.def_readwrite("name", &accelerant_device_info::name, "") //.def_readwrite("chipset", &accelerant_device_info::chipset, "") @@ -133,6 +134,7 @@ py::class_(m, "accelerant_device_info") ; py::class_(m, "display_timing") +.def(py::init(), "") .def_readwrite("pixel_clock", &display_timing::pixel_clock, "") .def_readwrite("h_display", &display_timing::h_display, "") .def_readwrite("h_sync_start", &display_timing::h_sync_start, "") @@ -146,6 +148,7 @@ py::class_(m, "display_timing") ; py::class_(m, "display_mode") +.def(py::init(), "") .def_readwrite("timing", &display_mode::timing, "") .def_readwrite("space", &display_mode::space, "") .def_readwrite("virtual_width", &display_mode::virtual_width, "") @@ -156,12 +159,14 @@ py::class_(m, "display_mode") ; py::class_(m, "frame_buffer_config") +.def(py::init(), "") .def_readwrite("frame_buffer", &frame_buffer_config::frame_buffer, "") .def_readwrite("frame_buffer_dma", &frame_buffer_config::frame_buffer_dma, "") .def_readwrite("bytes_per_row", &frame_buffer_config::bytes_per_row, "") ; py::class_(m, "display_timing_constraints") +.def(py::init(), "") .def_readwrite("h_res", &display_timing_constraints::h_res, "") .def_readwrite("h_sync_min", &display_timing_constraints::h_sync_min, "") .def_readwrite("h_sync_max", &display_timing_constraints::h_sync_max, "") @@ -184,6 +189,7 @@ py::enum_(m, "production") //; py::class_(m, "monitor_info") +.def(py::init(), "") .def_readwrite("version", &monitor_info::version, "") //.def_readwrite("vendor", &monitor_info::vendor, "") .def_property( @@ -242,6 +248,7 @@ py::class_(m, "monitor_info") ; py::class_(m, "blit_params") +.def(py::init(), "") .def_readwrite("src_left", &blit_params::src_left, "") .def_readwrite("src_top", &blit_params::src_top, "") .def_readwrite("dest_left", &blit_params::dest_left, "") @@ -251,6 +258,7 @@ py::class_(m, "blit_params") ; py::class_(m, "scaled_blit_params") +.def(py::init(), "") .def_readwrite("src_left", &scaled_blit_params::src_left, "") .def_readwrite("src_top", &scaled_blit_params::src_top, "") .def_readwrite("src_width", &scaled_blit_params::src_width, "") @@ -262,6 +270,7 @@ py::class_(m, "scaled_blit_params") ; py::class_(m, "fill_rect_params") +.def(py::init(), "") .def_readwrite("left", &fill_rect_params::left, "") .def_readwrite("top", &fill_rect_params::top, "") .def_readwrite("right", &fill_rect_params::right, "") @@ -269,12 +278,14 @@ py::class_(m, "fill_rect_params") ; py::class_(m, "engine_token") +.def(py::init(), "") .def_readwrite("engine_id", &engine_token::engine_id, "") .def_readwrite("capability_mask", &engine_token::capability_mask, "") .def_readwrite("opaque", &engine_token::opaque, "") ; py::class_(m, "sync_token") +.def(py::init(), "") .def_readwrite("counter", &sync_token::counter, "") .def_readwrite("engine_id", &sync_token::engine_id, "") //.def_readwrite("opaque", &sync_token::opaque, "") From 0c8064c5a84d82f700db4c0e95ae7c9f2dca5b11 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 17 Sep 2024 14:33:52 +0200 Subject: [PATCH 099/115] update PointAt to return tuple(BPoint,float) --- bindings/interface/TextView.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index 7db2114..3267f8d 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -254,7 +254,12 @@ py::class_(&BTextView::LineAt,py::const_), "", py::arg("offset")) .def("LineAt", py::overload_cast(&BTextView::LineAt,py::const_), "", py::arg("point")) -.def("PointAt", &BTextView::PointAt, "", py::arg("offset"), py::arg("_height")=NULL) +//.def("PointAt", &BTextView::PointAt, "", py::arg("offset"), py::arg("_height")=NULL) +.def("PointAt", [](BTextView& self, int32 offset) -> std::tuple { + float height; + BPoint ret = self.PointAt(offset,&height); + return std::make_tuple(ret,height); +},"",py::arg("offset")) .def("OffsetAt", py::overload_cast(&BTextView::OffsetAt,py::const_), "", py::arg("point")) .def("OffsetAt", py::overload_cast(&BTextView::OffsetAt,py::const_), "", py::arg("line")) .def("FindWord", &BTextView::FindWord, "", py::arg("offset"), py::arg("_fromOffset"), py::arg("_toOffset")) From f168f577973a80b9a502b20cba49da1be6e23426 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 18 Sep 2024 09:07:20 +0200 Subject: [PATCH 100/115] Add tab_side enum to TabView --- bindings/interface/TabView.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bindings/interface/TabView.cpp b/bindings/interface/TabView.cpp index 5771e59..5062c3a 100644 --- a/bindings/interface/TabView.cpp +++ b/bindings/interface/TabView.cpp @@ -252,6 +252,14 @@ py::class_>( .def("ViewForTab", &BTabView::ViewForTab, "", py::arg("tabIndex")) .def("IndexOf", &BTabView::IndexOf, "", py::arg("tab")) ; - - +py::enum_(m, "tab_side", "") +// kLeftSide = 1 << 0, +// kRightSide = 1 << 1, +// kTopSide = 1 << 2, +// kBottomSide = 1 << 3 +.value("kLeftSide", BTabView::tab_side::kLeftSide, "") +.value("kRightSide", BTabView::tab_side::kRightSide, "") +.value("kTopSide", BTabView::tab_side::kTopSide, "") +.value("kBottomSide", BTabView::tab_side::kBottomSide, "") +.export_values(); } From 936661dd88d853fc1e3c98b7a2f9182838675377 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 19 Sep 2024 23:15:36 +0200 Subject: [PATCH 101/115] GetSelection returns tuple of int32 --- bindings/interface/TextView.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index 3267f8d..524c166 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -243,7 +243,13 @@ py::class_ std::tuple{ + int32 start; + int32 end; + self.GetSelection(&start,&end); + return std::make_tuple(start,end); +}, "") //.def("SetFontAndColor", static_cast(&BTextView::SetFontAndColor), "", py::arg("font"), py::arg("mode")=B_FONT_ALL, py::arg("color")=NULL) .def("SetFontAndColor", py::overload_cast(&BTextView::SetFontAndColor), "", py::arg("font"), py::arg("mode")=B_FONT_ALL, py::arg("color")=NULL) //.def("SetFontAndColor", static_cast(&BTextView::SetFontAndColor), "", py::arg("startOffset"), py::arg("endOffset"), py::arg("font"), py::arg("mode")=B_FONT_ALL, py::arg("color")=NULL) From 82a54a66cf5ffa9250c8681345a42f0b197c025b Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 20 Sep 2024 13:02:48 +0200 Subject: [PATCH 102/115] Fix FindWord returning tuple of int32,int32 --- bindings/interface/TextView.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index 524c166..9f52d4a 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -268,7 +268,13 @@ py::class_(&BTextView::OffsetAt,py::const_), "", py::arg("point")) .def("OffsetAt", py::overload_cast(&BTextView::OffsetAt,py::const_), "", py::arg("line")) -.def("FindWord", &BTextView::FindWord, "", py::arg("offset"), py::arg("_fromOffset"), py::arg("_toOffset")) +//.def("FindWord", &BTextView::FindWord, "", py::arg("offset"), py::arg("_fromOffset"), py::arg("_toOffset")) +.def("FindWord", [](BTextView& self, int32 offset) -> std::tuple{ + int32 _fromOffset; + int32 _toOffset; + self.FindWord(offset,&_fromOffset,&_toOffset); + return std::make_tuple(_fromOffset,_toOffset); +},"", py::arg("offset")) .def("CanEndLine", &BTextView::CanEndLine, "", py::arg("offset")) .def("LineWidth", &BTextView::LineWidth, "", py::arg("lineNumber")=0) .def("LineHeight", &BTextView::LineHeight, "", py::arg("lineNumber")=0) From ec60680fc2e85b02f14ee436c6c18ae0975eafc5 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 24 Sep 2024 01:21:35 +0200 Subject: [PATCH 103/115] add def for settext(text,pythonlist) --- bindings/interface/TextView.cpp | 85 +++++++++++++-------------------- tmtest.py | 21 ++++++-- 2 files changed, 49 insertions(+), 57 deletions(-) diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index 9f52d4a..6d6002b 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -15,20 +15,6 @@ namespace py = pybind11; using namespace BPrivate; -/* -struct text_run { - int32_t offset; - BFont font; - rgb_color color; -}; - -struct text_run_array { - int32_t count; - std::vector runs; - text_run_array(int32_t count) : count(count), runs(count) {} -}; -*/ - class PyBTextView : public BTextView{ public: using BTextView::BTextView; @@ -140,33 +126,18 @@ py::class_(m, "text_run") .def_readwrite("font", &text_run::font, "") .def_readwrite("color", &text_run::color, "") ; +//tentativo di creare text_run gestito da python, produce lo stesso errori +/*m.def("create_text_run", []() { return new text_run(); // Python prende proprietà +}, py::return_value_policy::take_ownership);*/ py::class_(m, "text_run_array") -.def(py::init<>()) +//.def(py::init<>()) +/*init has been commented out because it's safer creating a text_run_array with +AllocRunArray static function*/ .def_readwrite("count", &text_run_array::count, "") //.def_readonly("runs", &text_run_array::runs, "") -/*first attempt -.def_property("runs",[](const text_run_array& self){ - return std::vector(self.runs, self.runs + self.text_run_array::count); - },[](text_run_array& self, const std::vector& new_values) { - if (new_values.size() != self.count){ - throw std::runtime_error("Invalid buffer size or dimensions"); - } - std::copy(new_values.begin(),new_values.end(),self.runs); - }) -;*/ -/* -.def_property("runs",[](const text_run_array& self){ - return std::vector(self.runs, self.runs + self.text_run_array::count); - },[](text_run_array& self, const std::vector& new_values) { - if (new_values.size() != self.count){ - throw std::runtime_error("Invalid buffer size or dimensions"); - } - std::memcpy(self.runs, new_values.data(), new_values.size() * sizeof(text_run)); - //std::copy(new_values.begin(),new_values.end(),self.runs); - }) -;*/ -.def_property("runs",[](const text_run_array& self){ +//this method works but gives error on delete(rewrite draw?) +/*.def_property("runs",[](const text_run_array& self){ return std::vector(self.runs, self.runs + self.text_run_array::count); },[](text_run_array& self, const py::list &new_values) { std::vector newruns; @@ -174,23 +145,19 @@ py::class_(m, "text_run_array") newruns.push_back(item.cast()); } std::memcpy(self.runs, newruns.data(), newruns.size() * sizeof(text_run)); - }) + })*/ +//also this one works but gives errors as above +.def_property("runs", [](const text_run_array& self) -> py::list { + py::list result; for (int i = 0; i < self.count; ++i) { + result.append(self.runs[i]); + } return result; +}, [](text_run_array& self, const py::list& new_values) { + int i = 0; for (auto item : new_values) { + if (i >= self.count) break; // Evita overflow + self.runs[i] = item.cast(); ++i; + } +}) ; -/* look at this -/*suggested attempt -py::class_(m, "text_run_array") -.def(py::init(), py::arg("count") = 1) -.def_readwrite("count", &text_run_array::count) -.def_property("runs", [](const text_run_array& self) { - return self.runs; - }, - [](text_run_array& self, const std::vector& new_values) { - if (new_values.size() != self.count) { - throw std::runtime_error("Invalid buffer size or dimensions"); - } - self.runs = new_values; - }) -;*/ /* py::class_(m, "text_run_array") .def_readwrite("count", &text_run_array::count, "") @@ -223,6 +190,18 @@ py::class_(&BTextView::SetText), "", py::arg("text"), py::arg("runs")=NULL) .def("SetText", py::overload_cast(&BTextView::SetText), "", py::arg("text"), py::arg("length"), py::arg("runs")=NULL) .def("SetText", py::overload_cast(&BTextView::SetText), "", py::arg("file"), py::arg("offset"), py::arg("length"), py::arg("runs")=NULL) +.def("SetText", [](BTextView& self, const char* text, const py::list& runs){//&SetTextWrapper, "", py::arg("text"), py::arg("runs")=NULL) + if (!runs.is_none()) { + auto len = runs.size(); + text_run_array* tra = BTextView::AllocRunArray(len); + int i = 0; for (auto item : runs) { + if (i >= len) break; // Evita overflow + tra->runs[i] = item.cast(); ++i; + } + self.SetText(text, tra); + BTextView::FreeRunArray(tra); + } +}, "", py::arg("text"), py::arg("runs")) .def("Insert", py::overload_cast(&BTextView::Insert), "", py::arg("text"), py::arg("runs")=NULL) .def("Insert", py::overload_cast(&BTextView::Insert), "", py::arg("text"), py::arg("length"), py::arg("runs")=NULL) .def("Insert", py::overload_cast(&BTextView::Insert), "", py::arg("offset"), py::arg("text"), py::arg("length"), py::arg("runs")=NULL) diff --git a/tmtest.py b/tmtest.py index 3724b7d..a36a6e8 100644 --- a/tmtest.py +++ b/tmtest.py @@ -340,15 +340,16 @@ def __init__(self): tr2.font=BFont(be_bold_font) tr2.color=pictura mytralist=[tr1,tr2] + self.typtap.SetText(stuff,mytralist) ##tra.count=2 #now you have 2 text_runs ##tra.runs[1] = tr2 #assign the second one ##print("tra runs modified",tra.runs) ##self.typtap.SetRunArray(0,len(self.typtap.Text()),tra) #this doesn't work - self.trb=text_run_array() +# self.trb=text_run_array() #trb=self.typtap.RunArray(0,len(self.typtap.Text()))#this crashes - self.trb.count=2 - self.trb.runs=mytralist - self.typtap.SetText(stuff,self.trb) +# self.trb.count=2 +# self.trb.runs=mytralist +# self.typtap.SetText(stuff,self.trb) #self.typtap.SetRunArray(0,len(self.typtap.Text()),trb) #this works, why error exiting and why does trb need tra (or it won't work) #print(tra.runs[1].color.green) #self.typtap.SetText(stuff,trb) @@ -420,7 +421,19 @@ def __init__(self): def MessageReceived(self, msg): if msg.what == 1: self.startimer.SetValue(not(self.startimer.Value())) + + elif msg.what == 2: + tr1=text_run() + tr1.offset=0 + tr1.font=be_bold_font + tr1.color=rgb_color() + tr2=text_run() + tr2.offset=2 + tr2.font=be_plain_font + tr2.color=rgb_color() + tr2.color.blue=255 + self.typtap.SetText("Ciao",[tr1,tr2]) x=round(self.statbar.CurrentValue()) if x<100: outtxt=str(x+1)+"%" From 40cf710ede51b7dc81b5fd23e86e26c71e7d98fb Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 24 Sep 2024 10:54:29 +0200 Subject: [PATCH 104/115] add all SetText funcs to use python lists for text_run_array --- bindings/interface/TextView.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index 6d6002b..4b53da0 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -202,6 +202,30 @@ py::class_= len) break; // Evita overflow + tra->runs[i] = item.cast(); ++i; + } + self.SetText(text, length, tra); + BTextView::FreeRunArray(tra); + } +}, "", py::arg("text"), py::arg("length"), py::arg("runs")) +.def("SetText", [](BTextView& self, BFile* file, int32 offset, int32 length, const py::list& runs){//&SetTextWrapper, "", py::arg("text"), py::arg("runs")=NULL) + if (!runs.is_none()) { + auto len = runs.size(); + text_run_array* tra = BTextView::AllocRunArray(len); + int i = 0; for (auto item : runs) { + if (i >= len) break; // Evita overflow + tra->runs[i] = item.cast(); ++i; + } + self.SetText(file, offset, length, tra); + BTextView::FreeRunArray(tra); + } +}, "", py::arg("file"), py::arg("offset"), py::arg("length"), py::arg("runs")) .def("Insert", py::overload_cast(&BTextView::Insert), "", py::arg("text"), py::arg("runs")=NULL) .def("Insert", py::overload_cast(&BTextView::Insert), "", py::arg("text"), py::arg("length"), py::arg("runs")=NULL) .def("Insert", py::overload_cast(&BTextView::Insert), "", py::arg("offset"), py::arg("text"), py::arg("length"), py::arg("runs")=NULL) From 06846f8aa684490798db34c00b10168620e860c0 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 24 Sep 2024 20:58:15 +0200 Subject: [PATCH 105/115] comment out BlockCache --- Jamfile | 2 +- bindings/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Jamfile b/Jamfile index 30196e6..ae4ed2d 100644 --- a/Jamfile +++ b/Jamfile @@ -204,7 +204,7 @@ local sourceFiles = Beep.cpp Locker.cpp Autolock.cpp - BlockCache.cpp + #BlockCache.cpp SupportDefs.cpp Archivable.cpp TypeConstants.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 5e1d4b6..4656067 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -96,7 +96,7 @@ from .Beep import * from .Architecture import * from .Locker import * -from .BlockCache import * +#from .BlockCache import * from .Autolock import * from .DateTime import * from .parsedate import * From 2055d63b81417dc67d30842a056b9685054ebd72 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 27 Sep 2024 08:03:04 +0200 Subject: [PATCH 106/115] Fix add SetRunArray to use py::list --- bindings/__init__.py | 2 +- bindings/interface/TextView.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bindings/__init__.py b/bindings/__init__.py index 4656067..e62d6ff 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -7,7 +7,7 @@ from .Key import * from .KeyStore import * from .Looper import * -from .Application import * # has to be after looper +from .Application import * # should to be loaded after looper from .Message import * from .MessageFilter import * from .MessageQueue import * diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index 4b53da0..f80cfb4 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -260,6 +260,18 @@ py::class_(&BTextView::GetFontAndColor,py::const_), "", py::arg("offset"), py::arg("_font"), py::arg("_color")=NULL) .def("GetFontAndColor", py::overload_cast(&BTextView::GetFontAndColor,py::const_), "", py::arg("_font"), py::arg("_mode"), py::arg("_color")=NULL, py::arg("_sameColor")=NULL) .def("SetRunArray", &BTextView::SetRunArray, "", py::arg("startOffset"), py::arg("endOffset"), py::arg("runs")) +.def("SetRunArray", [](BTextView& self, int32 startOffset, int32 endOffset, const py::list& runs) { + if (!runs.is_none()) { + auto len = runs.size(); + text_run_array* tra = BTextView::AllocRunArray(len); + int i = 0; for (auto item : runs) { + if (i >= len) break; // Evita overflow + tra->runs[i] = item.cast(); ++i; + } + self.SetRunArray(startOffset, endOffset, tra); + BTextView::FreeRunArray(tra); + } +},"",py::arg("startOffset"),py::arg("endOffset"),py::arg("runs")) .def("RunArray", &BTextView::RunArray, "", py::arg("startOffset"), py::arg("endOffset"), py::arg("_size")=NULL) .def("LineAt", py::overload_cast(&BTextView::LineAt,py::const_), "", py::arg("offset")) .def("LineAt", py::overload_cast(&BTextView::LineAt,py::const_), "", py::arg("point")) From e3c84648f5a8b70efbb4f2445c637b7230ae52ee Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 29 Sep 2024 18:48:11 +0200 Subject: [PATCH 107/115] comment out unused modules --- Jamfile | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Jamfile b/Jamfile index ae4ed2d..32cd1cb 100644 --- a/Jamfile +++ b/Jamfile @@ -266,19 +266,19 @@ local sourceFiles = stat.cpp #add-ons - ScreenSaver.cpp - MimeSnifferAddon.cpp + #ScreenSaver.cpp + #MimeSnifferAddon.cpp Accelerant.cpp - GraphicsCard.cpp - InputServerDevice.cpp - InputServerFilter.cpp - InputServerMethod.cpp - MailProtocol.cpp - MailFilter.cpp + #GraphicsCard.cpp + #InputServerDevice.cpp + #InputServerFilter.cpp + #InputServerMethod.cpp + #MailProtocol.cpp + #MailFilter.cpp MailSettingsView.cpp - NetworkProfile.cpp + #NetworkProfile.cpp NetworkSettings.cpp - NetworkSettingsAddOn.cpp + #NetworkSettingsAddOn.cpp #drivers #bios.cpp @@ -286,12 +286,12 @@ local sourceFiles = #bus_manager.cpp #device - SerialPort.cpp - Joystick.cpp - USBKit.cpp - A2D.cpp - D2A.cpp - DigitalPort.cpp + #SerialPort.cpp + #Joystick.cpp + #USBKit.cpp + #A2D.cpp + #D2A.cpp + #DigitalPort.cpp #mail Email.cpp From a78fa452264395371db34e7f5c17e014d5a5d4b0 Mon Sep 17 00:00:00 2001 From: Zardshard <0azrune6@zard.anonaddy.com> Date: Mon, 30 Sep 2024 10:45:35 -0400 Subject: [PATCH 108/115] Fix build on 32 bit --- bindings/add-ons/network_settings/NetworkSettings.cpp | 4 ++-- bindings/interface/Layout.cpp | 6 +++--- bindings/locale/NumberFormat.cpp | 8 ++++---- bindings/mail/MailContainer.cpp | 4 ++-- bindings/mail/MailMessage.cpp | 4 ++-- bindings/media/MediaAddOn.cpp | 2 +- bindings/media/MediaFile.cpp | 4 ++-- bindings/media/MediaFormats.cpp | 2 +- bindings/media/MediaTrack.cpp | 4 ++-- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/bindings/add-ons/network_settings/NetworkSettings.cpp b/bindings/add-ons/network_settings/NetworkSettings.cpp index a93efc1..2db9dc8 100644 --- a/bindings/add-ons/network_settings/NetworkSettings.cpp +++ b/bindings/add-ons/network_settings/NetworkSettings.cpp @@ -130,8 +130,8 @@ py::class_(m, "BNetworkInterfaceSettings") .def("Metric", &BNetworkInterfaceSettings::Metric, "") .def("SetMetric", &BNetworkInterfaceSettings::SetMetric, "", py::arg("metric")) .def("CountAddresses", &BNetworkInterfaceSettings::CountAddresses, "") -.def("AddressAt", py::overload_cast(&BNetworkInterfaceSettings::AddressAt), "", py::arg("index")) -.def("AddressAt", py::overload_cast(&BNetworkInterfaceSettings::AddressAt), "", py::arg("index")) +.def("AddressAt", py::overload_cast(&BNetworkInterfaceSettings::AddressAt), "", py::arg("index")) +.def("AddressAt", py::overload_cast(&BNetworkInterfaceSettings::AddressAt), "", py::arg("index")) .def("FindFirstAddress", &BNetworkInterfaceSettings::FindFirstAddress, "", py::arg("family")) .def("AddAddress", &BNetworkInterfaceSettings::AddAddress, "", py::arg("address")) .def("RemoveAddress", &BNetworkInterfaceSettings::RemoveAddress, "", py::arg("index")) diff --git a/bindings/interface/Layout.cpp b/bindings/interface/Layout.cpp index 1fc1c6c..9d67689 100644 --- a/bindings/interface/Layout.cpp +++ b/bindings/interface/Layout.cpp @@ -103,12 +103,12 @@ py::class_(m, "BLayout") .def("TargetView", &BLayout::TargetView, "") .def("View", &BLayout::View, "") .def("AddView", py::overload_cast(&BLayout::AddView), "", py::arg("child")) -.def("AddView", py::overload_cast(&BLayout::AddView), "", py::arg("index"), py::arg("child")) +.def("AddView", py::overload_cast(&BLayout::AddView), "", py::arg("index"), py::arg("child")) .def("AddItem", py::overload_cast(&BLayout::AddItem), "", py::arg("item")) -.def("AddItem", py::overload_cast(&BLayout::AddItem), "", py::arg("index"), py::arg("item")) +.def("AddItem", py::overload_cast(&BLayout::AddItem), "", py::arg("index"), py::arg("item")) .def("RemoveView", &BLayout::RemoveView, "", py::arg("child")) .def("RemoveItem", py::overload_cast(&BLayout::RemoveItem), "", py::arg("item")) -.def("RemoveItem", py::overload_cast(&BLayout::RemoveItem), "", py::arg("index")) +.def("RemoveItem", py::overload_cast(&BLayout::RemoveItem), "", py::arg("index")) .def("ItemAt", &BLayout::ItemAt, "", py::arg("index")) .def("CountItems", &BLayout::CountItems, "") .def("IndexOfItem", &BLayout::IndexOfItem, "", py::arg("item")) diff --git a/bindings/locale/NumberFormat.cpp b/bindings/locale/NumberFormat.cpp index b4d0d74..c9e1506 100644 --- a/bindings/locale/NumberFormat.cpp +++ b/bindings/locale/NumberFormat.cpp @@ -21,14 +21,14 @@ py::class_(m, "BNumberFormat") .def(py::init(), "", py::arg("locale")) .def("Format", py::overload_cast(&BNumberFormat::Format), "", py::arg("string"), py::arg("maxSize"), py::arg("value")) .def("Format", [](BNumberFormat& self,const double value) { - BString string; + BString string; status_t r = self.Format(string, value); return std::make_tuple(r,string); } , "", py::arg("value")) -.def("Format", py::overload_cast(&BNumberFormat::Format), "", py::arg("string"), py::arg("maxSize"), py::arg("value")) -.def("Format", [](BNumberFormat& self,int value) { - BString string; +.def("Format", py::overload_cast(&BNumberFormat::Format), "", py::arg("string"), py::arg("maxSize"), py::arg("value")) +.def("Format", [](BNumberFormat& self, int32 value) { + BString string; status_t r = self.Format(string, value); return std::make_tuple(r,string); } diff --git a/bindings/mail/MailContainer.cpp b/bindings/mail/MailContainer.cpp index 7cc1624..a30fcf6 100644 --- a/bindings/mail/MailContainer.cpp +++ b/bindings/mail/MailContainer.cpp @@ -65,7 +65,7 @@ py::class_(m, "BMailContainer" .def(py::init(), "", py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) .def("AddComponent", &BMailContainer::AddComponent, "", py::arg("component")) .def("RemoveComponent", py::overload_cast(&BMailContainer::RemoveComponent), "", py::arg("component")) -.def("RemoveComponent", py::overload_cast(&BMailContainer::RemoveComponent), "", py::arg("index")) +.def("RemoveComponent", py::overload_cast(&BMailContainer::RemoveComponent), "", py::arg("index")) .def("GetComponent", &BMailContainer::GetComponent, "", py::arg("index"), py::arg("parse_now")=false) .def("CountComponents", &BMailContainer::CountComponents, "") ; @@ -77,7 +77,7 @@ py::class_(&BMIMEMultipartMailContainer::RemoveComponent), "", py::arg("component")) -.def("RemoveComponent", py::overload_cast(&BMIMEMultipartMailContainer::RemoveComponent), "", py::arg("index")) +.def("RemoveComponent", py::overload_cast(&BMIMEMultipartMailContainer::RemoveComponent), "", py::arg("index")) .def("GetComponent", &BMIMEMultipartMailContainer::GetComponent, "", py::arg("index"), py::arg("parse_now")=false) .def("CountComponents", &BMIMEMultipartMailContainer::CountComponents, "") .def("GetDecodedData", &BMIMEMultipartMailContainer::GetDecodedData, "", py::arg("data")) diff --git a/bindings/mail/MailMessage.cpp b/bindings/mail/MailMessage.cpp index a89bc95..914206d 100644 --- a/bindings/mail/MailMessage.cpp +++ b/bindings/mail/MailMessage.cpp @@ -67,7 +67,7 @@ py::class_(m, "BEmailMessage") .def("GetName", py::overload_cast(&BEmailMessage::GetName,py::const_), "", py::arg("name")) .def("SendViaAccountFrom", &BEmailMessage::SendViaAccountFrom, "", py::arg("message")) .def("SendViaAccount", py::overload_cast(&BEmailMessage::SendViaAccount), "", py::arg("accountName")) -.def("SendViaAccount", py::overload_cast(&BEmailMessage::SendViaAccount), "", py::arg("account")) +.def("SendViaAccount", py::overload_cast(&BEmailMessage::SendViaAccount), "", py::arg("account")) .def("Account", &BEmailMessage::Account, "") .def("GetAccountName", [](BEmailMessage& self) { BString accountName; @@ -77,7 +77,7 @@ py::class_(m, "BEmailMessage") , "") .def("AddComponent", &BEmailMessage::AddComponent, "", py::arg("component")) .def("RemoveComponent", py::overload_cast(&BEmailMessage::RemoveComponent), "", py::arg("component")) -.def("RemoveComponent", py::overload_cast(&BEmailMessage::RemoveComponent), "", py::arg("index")) +.def("RemoveComponent", py::overload_cast(&BEmailMessage::RemoveComponent), "", py::arg("index")) .def("GetComponent", &BEmailMessage::GetComponent, "", py::arg("index"), py::arg("parseNow")=false) .def("CountComponents", &BEmailMessage::CountComponents, "") .def("Attach", &BEmailMessage::Attach, "", py::arg("ref"), py::arg("includeAttributes")=true) diff --git a/bindings/media/MediaAddOn.cpp b/bindings/media/MediaAddOn.cpp index 50cdafd..d5ffeb0 100644 --- a/bindings/media/MediaAddOn.cpp +++ b/bindings/media/MediaAddOn.cpp @@ -131,7 +131,7 @@ py::class_(m, "BMediaAddOn") //.def("AutoStart", &BMediaAddOn::AutoStart, "", py::arg("index"), py::arg("_node"), py::arg("_internalID"), py::arg("_hasMore")) .def("AutoStart", [](BMediaAddOn& self, int index) { BMediaNode* node = nullptr; - int32_t internalID = 0; + int32 internalID = 0; bool hasMore = false; status_t result = self.AutoStart(index, &node, &internalID, &hasMore); return std::make_tuple(result, node, internalID, hasMore); diff --git a/bindings/media/MediaFile.cpp b/bindings/media/MediaFile.cpp index 6f1fec6..637ddaa 100644 --- a/bindings/media/MediaFile.cpp +++ b/bindings/media/MediaFile.cpp @@ -50,8 +50,8 @@ py::class_(m, "BMediaFile") .def("TrackAt", &BMediaFile::TrackAt, "", py::arg("index")) .def("ReleaseTrack", &BMediaFile::ReleaseTrack, "", py::arg("track")) .def("ReleaseAllTracks", &BMediaFile::ReleaseAllTracks, "") -.def("CreateTrack", py::overload_cast(&BMediaFile::CreateTrack), "", py::arg("mf"), py::arg("mci"), py::arg("flags")=0) -.def("CreateTrack", py::overload_cast(&BMediaFile::CreateTrack), "", py::arg("mf"), py::arg("flags")=0) +.def("CreateTrack", py::overload_cast(&BMediaFile::CreateTrack), "", py::arg("mf"), py::arg("mci"), py::arg("flags")=0) +.def("CreateTrack", py::overload_cast(&BMediaFile::CreateTrack), "", py::arg("mf"), py::arg("flags")=0) .def("AddCopyright", &BMediaFile::AddCopyright, "", py::arg("data")) .def("AddChunk", &BMediaFile::AddChunk, "", py::arg("type"), py::arg("data"), py::arg("size")) .def("CommitHeader", &BMediaFile::CommitHeader, "") diff --git a/bindings/media/MediaFormats.cpp b/bindings/media/MediaFormats.cpp index 9769af7..092dc0a 100644 --- a/bindings/media/MediaFormats.cpp +++ b/bindings/media/MediaFormats.cpp @@ -232,7 +232,7 @@ py::class_(m, "media_format_description") py::class_(m, "BMediaFormats") .def(py::init(), "") .def("InitCheck", &BMediaFormats::InitCheck, "") -.def("MakeFormatFor", py::overload_cast(&BMediaFormats::MakeFormatFor), "", py::arg("descriptions"), py::arg("descriptionCount"), py::arg("_inOutFormat"), py::arg("flags")=0, py::arg("_reserved")=0) +.def("MakeFormatFor", py::overload_cast(&BMediaFormats::MakeFormatFor), "", py::arg("descriptions"), py::arg("descriptionCount"), py::arg("_inOutFormat"), py::arg("flags")=0, py::arg("_reserved")=0) .def("GetFormatFor", &BMediaFormats::GetFormatFor, "", py::arg("description"), py::arg("_outFormat")) .def("GetCodeFor", &BMediaFormats::GetCodeFor, "", py::arg("format"), py::arg("family"), py::arg("_outDescription")) .def("RewindFormats", &BMediaFormats::RewindFormats, "") diff --git a/bindings/media/MediaTrack.cpp b/bindings/media/MediaTrack.cpp index 49d6737..45eb8a1 100644 --- a/bindings/media/MediaTrack.cpp +++ b/bindings/media/MediaTrack.cpp @@ -58,9 +58,9 @@ py::class_>(m, "BMediaTra },"") .def("AddCopyright", &BMediaTrack::AddCopyright, "", py::arg("copyright")) .def("AddTrackInfo", &BMediaTrack::AddTrackInfo, "", py::arg("code"), py::arg("data"), py::arg("size"), py::arg("flags")=0) -.def("WriteFrames", py::overload_cast(&BMediaTrack::WriteFrames), "", py::arg("data"), py::arg("frameCount"), py::arg("flags")=0) +.def("WriteFrames", py::overload_cast(&BMediaTrack::WriteFrames), "", py::arg("data"), py::arg("frameCount"), py::arg("flags")=0) .def("WriteFrames", py::overload_cast(&BMediaTrack::WriteFrames), "", py::arg("data"), py::arg("frameCount"), py::arg("info")) -.def("WriteChunk", py::overload_cast(&BMediaTrack::WriteChunk), "", py::arg("data"), py::arg("size"), py::arg("flags")=0) +.def("WriteChunk", py::overload_cast(&BMediaTrack::WriteChunk), "", py::arg("data"), py::arg("size"), py::arg("flags")=0) .def("WriteChunk", py::overload_cast(&BMediaTrack::WriteChunk), "", py::arg("data"), py::arg("size"), py::arg("info")) .def("Flush", &BMediaTrack::Flush, "") //.def("GetParameterWeb", &BMediaTrack::GetParameterWeb, "", py::arg("_web")) From b7c96942d59c8a9a1fbd2e926b515446dba8c2d7 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 4 Oct 2024 19:48:35 +0200 Subject: [PATCH 109/115] make GetText return string --- bindings/interface/TextView.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index f80cfb4..04e2efa 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -233,7 +233,12 @@ py::class_(&BTextView::Delete), "", py::arg("startOffset"), py::arg("endOffset")) .def("Text", &BTextView::Text, "") .def("TextLength", &BTextView::TextLength, "") -.def("GetText", &BTextView::GetText, "", py::arg("offset"), py::arg("length"), py::arg("buffer")) +//.def("GetText", &BTextView::GetText, "", py::arg("offset"), py::arg("length"), py::arg("buffer")) +.def("GetText", [](BTextView& self,int32 offset,int32 length) { + std::vector buffer(length); + self.GetText(offset, length, buffer.data()); + return std::string(buffer.data(), length); +}, "", py::arg("offset"), py::arg("length")) .def("ByteAt", &BTextView::ByteAt, "", py::arg("offset")) .def("CountLines", &BTextView::CountLines, "") .def("CurrentLine", &BTextView::CurrentLine, "") From 482dd4edd447ec2558b186650e30493356c2f721 Mon Sep 17 00:00:00 2001 From: coolcoder613eb <96163908+coolcoder613eb@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:37:21 +1100 Subject: [PATCH 110/115] Update build instructions in README.md --- README.md | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e0bdfbd..41f750e 100644 --- a/README.md +++ b/README.md @@ -22,30 +22,38 @@ this, you can expect memory leaks, as little work has been done on getting memory freed correctly once it is no longer needed. ## Installing - +### From HaikuPorts Installation on Haiku is easy, just run - -`pkgman install haiku_pyapi_python310` - +``` +pkgman install haiku_pyapi_python310 +``` or - -`pkgman install haiku_pyapi_python39` - +``` +pkgman install haiku_pyapi_python39 +``` If you need the latest widgets and bugfixes, then you should compile from source, see below. -## Compiling - -First, install the appropriate version of pybind11 for your CPU architecture and version of Python. For example, to install pybind11 for x86 and python3.10, run +### From source -`pkgman install pybind11_x86_python310` +First, clone the source code, with submodules: +``` +git clone https://github.com/coolcder613eb/Haiku-PyAPI --recursive +``` The basic build command to build using all CPU cores is +``` +jam -j$(nproc) +``` +Extra build parameters can be specified, as discussed below. -`jam -j$(nproc)` +Finally, to install, simply run +``` +jam install +``` +Haiku-PyAPI should now be installed and ready to use. -Extra build parameters can be specified, as discussed below. -### Build parameters +## Build parameters The build parameters can be used to change how the build is done. This can be used to, for example, specify a different verson of python to build for. To From 118f940f0b8c90612607970704fe98c32f3fa8d7 Mon Sep 17 00:00:00 2001 From: Zardshard <0azrune6@zard.anonaddy.com> Date: Tue, 15 Oct 2024 18:15:23 -0400 Subject: [PATCH 111/115] Cleanup --- Jamfile | 19 ++++++++++++++++++- bindings/app/Application.cpp | 5 +++++ bindings/app/Looper.cpp | 14 ++++++++------ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Jamfile b/Jamfile index 32cd1cb..e8feece 100644 --- a/Jamfile +++ b/Jamfile @@ -74,7 +74,24 @@ install_location ?= /boot/system/non-packaged/lib/python$(python_version)/site-packages ; # Where to search for .cpp files -SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/storage bindings/kernel bindings/translation bindings/add-ons/screen_saver bindings/add-ons/registrar bindings/add-ons/graphics bindings/add-ons/input_server bindings/add-ons/mail_daemon bindings/add-ons/network_settings bindings/drivers bindings/device bindings/mail bindings/locale bindings/media ; +SEARCH_SOURCE += + bindings/interface + bindings/app + bindings/support + bindings/storage + bindings/kernel + bindings/translation + bindings/add-ons/screen_saver + bindings/add-ons/registrar + bindings/add-ons/graphics + bindings/add-ons/input_server + bindings/add-ons/mail_daemon + bindings/add-ons/network_settings + bindings/drivers + bindings/device + bindings/mail + bindings/locale + bindings/media ; # Where to look for header files SubDirHdrs headers ; diff --git a/bindings/app/Application.cpp b/bindings/app/Application.cpp index ddd008a..1e6eca5 100644 --- a/bindings/app/Application.cpp +++ b/bindings/app/Application.cpp @@ -50,6 +50,11 @@ class PyBApplication : public BApplication{ PYBIND11_OVERLOAD(status_t, BApplication, Archive, data, deep); } thread_id Run() override { + // There is no need to release the GIL here like RunWrapper. Here, + // the GIL starts off unacquired, whereas in RunWrapper, the GIL + // starts off acquired. Here, only if pybind sees that there + // is a Python function overriding Run that needs to be run will + // it acquire the GIL. Otherwise, it stays unacquired. PYBIND11_OVERLOAD(thread_id, BApplication, Run); } void Quit() override { diff --git a/bindings/app/Looper.cpp b/bindings/app/Looper.cpp index d9679dd..475a85f 100644 --- a/bindings/app/Looper.cpp +++ b/bindings/app/Looper.cpp @@ -55,13 +55,15 @@ class PyBLooper : public BLooper{ PYBIND11_OVERLOAD(thread_id, BLooper, Run); } void Quit() override { - py::gil_scoped_acquire acquire; + { + py::gil_scoped_acquire acquire; - // Not sure if it's actually necessary to release the reference - // to ourselves, since we will delete ourselves anyway. - // FIXME: What if the Python overload never actually calls - // BLooper::Quit? - do_not_delete.release(); + // Not sure if it's actually necessary to release the reference + // to ourselves, since we will delete ourselves anyway. + // FIXME: What if the Python overload never actually calls + // BLooper::Quit? + do_not_delete.release(); + } PYBIND11_OVERLOAD(void, BLooper, Quit); } From 9e3315c0cf15fd2092ab54137012685ead9953e4 Mon Sep 17 00:00:00 2001 From: coolcoder613eb <96163908+coolcoder613eb@users.noreply.github.com> Date: Sun, 20 Oct 2024 09:48:00 +0000 Subject: [PATCH 112/115] Add rgb_color methods --- bindings/interface/GraphicsDefs.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bindings/interface/GraphicsDefs.cpp b/bindings/interface/GraphicsDefs.cpp index 8b57444..e239444 100644 --- a/bindings/interface/GraphicsDefs.cpp +++ b/bindings/interface/GraphicsDefs.cpp @@ -166,6 +166,8 @@ py::class_(m, "rgb_color") .def(py::init<>(), "") .def("set_to", &rgb_color::set_to, "", py::arg("r"), py::arg("g"), py::arg("b"), py::arg("a")=255) .def("Brightness", &rgb_color::Brightness, "") +.def("IsDark", &rgb_color::IsDark, "") +.def("IsLight", &rgb_color::IsLight, "") .def("__eq__", &rgb_color::operator==, "", py::arg("other")) .def("__ne__", &rgb_color::operator!=, "", py::arg("other")) .def("operator=", &rgb_color::operator=, "", py::arg("other")) From 575696f18245cc0447a97e07e668b6f34d046e65 Mon Sep 17 00:00:00 2001 From: coolcoder613eb <96163908+coolcoder613eb@users.noreply.github.com> Date: Fri, 15 Nov 2024 08:54:38 +1100 Subject: [PATCH 113/115] Update README.md with more example projects --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 41f750e..bf84834 100644 --- a/README.md +++ b/README.md @@ -70,5 +70,11 @@ specify a build parameter, add `-sPARAMETER=VALUE` to the build command line. ## Example projects This repository contains `test.py`, which is a simple "Hello world" program. -The matching game [BeMatched](https://github.com/coolcoder613eb/BeMatched) -provides another example of the library in use. +Other examples: +- https://github.com/coolcoder613eb/Bemini +- https://github.com/coolcoder613eb/BeMatched +- https://github.com/tmtfx/HaiQR +- https://github.com/tmtfx/FeedGator +- https://github.com/tmtfx/HTPBZ2 +- https://github.com/tmtfx/HaikuPO +- https://github.com/robante15/Haiku-PyAPI_Examples From 19f56f093d7cb524af3d0a4ff36f48f97f6bb32d Mon Sep 17 00:00:00 2001 From: Zardshard <0azrune6@zard.anonaddy.com> Date: Thu, 21 Nov 2024 09:18:05 -0500 Subject: [PATCH 114/115] Update README --- README.md | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index bf84834..1537fd1 100644 --- a/README.md +++ b/README.md @@ -9,28 +9,24 @@ where we have had to deviate from the C++ API, however. ## Current status -Currently, Haiku-PyAPI is best suited to scripts and small, simple -applications. +Virtually everything from Haiku's API is available. It is likely that you will +run into some bugs if you try to make an application. Please report them! Also, +there's a good chance we can give you a workaround to use until it is fixed. -Almost everything in the app and interface kits have been ported. The storage -kit has mostly been ported. The support kit has only partially been ported. -The other kits haven't been ported yet. - -Of the kits that have been ported, many of the functions haven't been tested -yet. You should, therefore, expect to encounter problems occasionally. Besides -this, you can expect memory leaks, as little work has been done on getting -memory freed correctly once it is no longer needed. +Probably, the biggest bug is memory leaks. Unless memory management for a class +was simple for us to do, it is likely that we opted to never free the memory +so that we could worry about memory management later! ## Installing + ### From HaikuPorts + Installation on Haiku is easy, just run + ``` pkgman install haiku_pyapi_python310 ``` -or -``` -pkgman install haiku_pyapi_python39 -``` + If you need the latest widgets and bugfixes, then you should compile from source, see below. ### From source From f1b5a1f74a15c65a93cfff82677b038eab3ed444 Mon Sep 17 00:00:00 2001 From: Zardshard <0azrune6@zard.anonaddy.com> Date: Thu, 21 Nov 2024 13:14:16 -0500 Subject: [PATCH 115/115] Improve example program * Rename test.py to example.py * Rewrite it Also move and rename tmtest.py and fstest.py --- README.md | 2 +- example.py | 50 ++++++++++++++++++++++++++++++ test.py | 36 --------------------- fstest.py => tests/filesystem.py | 0 tmtest.py => tests/interfaceKit.py | 0 5 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 example.py delete mode 100644 test.py rename fstest.py => tests/filesystem.py (100%) rename tmtest.py => tests/interfaceKit.py (100%) diff --git a/README.md b/README.md index 1537fd1..5f821c0 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ specify a build parameter, add `-sPARAMETER=VALUE` to the build command line. ## Example projects -This repository contains `test.py`, which is a simple "Hello world" program. +This repository contains `example.py`, which is a simple "Hello world" program. Other examples: - https://github.com/coolcoder613eb/Bemini - https://github.com/coolcoder613eb/BeMatched diff --git a/example.py b/example.py new file mode 100644 index 0000000..3c109ed --- /dev/null +++ b/example.py @@ -0,0 +1,50 @@ +# There two ways to import Haiku-PyAPI +# First, you can import only the things you need +from Be import BApplication, BWindow, BRect, BMessage, BView, BButton, window_type, B_NOT_RESIZABLE, B_QUIT_ON_WINDOW_CLOSE, int32, B_WILL_DRAW, B_FOLLOW_NONE +# Or import everything! +#from Be import * + +# Usage of the API is extremely similar to how it is used in C++ + +class App(BApplication): + def __init__(self): + BApplication.__init__( + self, # Any call to a constructor requires self as the first parameter + "application/x-vnd.pyapi_test") # Application signature + + def ReadyToRun(self): + # Display the main window + window = MainWindow() + window.Show() + +class MainWindow(BWindow): + def __init__(self): + BWindow.__init__( + self, # Any call to a constructor requires self as the first parameter + BRect(100,100,200,150), # Window size + "Hello Haiku!", # Window title + window_type.B_TITLED_WINDOW, # Window type + B_NOT_RESIZABLE | B_QUIT_ON_WINDOW_CLOSE) # Flags + + # The "Say Hello!" button's message code + self.MSG_SAY_HI = int32(b"syhi") + + # The "Say Hello!" button + self.button = BButton( + self.Bounds(), # Button size + "hi", # Internal name of button + "Say Hello!", # Button text + BMessage(self.MSG_SAY_HI)) # Message to send when button is pressed + self.AddChild(self.button, None) + + def MessageReceived(self, msg): + if msg.what == self.MSG_SAY_HI: + # The "Say Hello!" button has been pressed! + print("Hello World!") + else: + # We don't know what to do with this message. Pass it on to BWindow + BWindow.MessageReceived(self, msg) + +# Let's launch the application! +app = App() +app.Run() diff --git a/test.py b/test.py deleted file mode 100644 index 22502cf..0000000 --- a/test.py +++ /dev/null @@ -1,36 +0,0 @@ -from Be import BApplication, BWindow, BRect, BMessage, BView, BButton, window_type, B_NOT_RESIZABLE, B_QUIT_ON_WINDOW_CLOSE - -class Window(BWindow): - def __init__(self): - BWindow.__init__(self, BRect(100,100,200,150), "Hello Haiku!", window_type.B_TITLED_WINDOW, B_NOT_RESIZABLE | B_QUIT_ON_WINDOW_CLOSE) - self.say_hi = BMessage(1) - self.panel = BView(self.Bounds(), "panel", 8, 20000000) - self.button = BButton(self.panel.Bounds(), "hi", "Say Hello!", self.say_hi) #BRect(10,10,100,50) - self.panel.AddChild(self.button, None) - self.AddChild(self.panel, None) - - def MessageReceived(self, msg): - if msg.what == self.say_hi.what: - print("Hello World!") - else: - BWindow.MessageReceived(self, msg) - - def QuitRequested(self): - print("PyQUIT") - return True - -class App(BApplication): - def __init__(self): - BApplication.__init__(self, "application/x-python") - def ReadyToRun(self): - self.window = Window() - self.window.Show() - -def main(): - global be_app - be_app = App() - be_app.Run() - print('Ran') - -if __name__ == "__main__": - main() diff --git a/fstest.py b/tests/filesystem.py similarity index 100% rename from fstest.py rename to tests/filesystem.py diff --git a/tmtest.py b/tests/interfaceKit.py similarity index 100% rename from tmtest.py rename to tests/interfaceKit.py