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 1d43c2d..e8feece 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: @@ -68,29 +68,57 @@ 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 ; # 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 + bindings/drivers + bindings/device + bindings/mail + bindings/locale + bindings/media ; # Where to look for header files 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 -# 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 = @@ -183,14 +211,17 @@ local sourceFiles = GradientRadialFocus.cpp GridView.cpp Dragger.cpp - #IconUtils.cpp + IconUtils.cpp Input.cpp PrintJob.cpp #SupportKit + ByteOrder.cpp + StopWatch.cpp Beep.cpp Locker.cpp Autolock.cpp + #BlockCache.cpp SupportDefs.cpp Archivable.cpp TypeConstants.cpp @@ -202,10 +233,16 @@ local sourceFiles = Flattenable.cpp StringList.cpp DataIO.cpp + BufferIO.cpp + BufferedDataIO.cpp Url.cpp + UTF8.cpp + TLS.cpp + Job.cpp #Kernel fs_attr.cpp + OS.cpp #StorageKit StorageDefs.cpp @@ -229,8 +266,8 @@ local sourceFiles = Query.cpp NodeMonitor.cpp NodeInfo.cpp - #AppFileInfo.cpp - #DiskDeviceDefs.cpp + AppFileInfo.cpp + DiskDeviceDefs.cpp FilePanel.cpp # TranslationKit @@ -240,8 +277,99 @@ local sourceFiles = TranslatorRoster.cpp TranslationUtils.cpp Translator.cpp + BitmapStream.cpp + TranslatorFormats.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 + + #drivers + #bios.cpp + #module.cpp + #bus_manager.cpp + + #device + #SerialPort.cpp + #Joystick.cpp + #USBKit.cpp + #A2D.cpp + #D2A.cpp + #DigitalPort.cpp + + #mail + Email.cpp + mail_encoding.cpp + MailDaemon.cpp + MailComponent.cpp + MailContainer.cpp + 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 + StringFormat.cpp + TextEncoding.cpp + RelativeDateTimeFormat.cpp + NumberFormat.cpp + LocaleStrings.cpp + LocaleRoster.cpp + Locale.cpp + Collator.cpp + CatalogData.cpp + 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 + MediaEncoder.cpp + ParameterWeb.cpp + MediaTrack.cpp + MediaFile.cpp + MediaFiles.cpp + MediaFormats.cpp + MediaRecorder.cpp + MediaRoster.cpp + MediaTheme.cpp + PlaySound.cpp + Sound.cpp + SoundFile.cpp + SoundPlayer.cpp + TimeCode.cpp + TimedEventQueue.cpp + ; # The .so files can be built from the .cpp files, each .cpp file mapping to @@ -250,6 +378,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 ; @@ -258,6 +387,58 @@ 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 ; + +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 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 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 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 ; +#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 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 MailContainer.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailMessage.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailSettings.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 diff --git a/README.md b/README.md index c6c1be3..5f821c0 100644 --- a/README.md +++ b/README.md @@ -9,41 +9,47 @@ where we have had to deviate from the C++ API, however. ## Current status -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. +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. -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. +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 -Installation on Haiku is easy, just run - -`pkgman install haiku_pyapi_python310` +### From HaikuPorts -or +Installation on Haiku is easy, just run -`pkgman install haiku_pyapi_python39` +``` +pkgman install haiku_pyapi_python310 +``` If you need the latest widgets and bugfixes, then you should compile from source, see below. -## Compiling +### From source -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 - -`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 @@ -53,10 +59,18 @@ 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 -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. +This repository contains `example.py`, which is a simple "Hello world" program. +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 diff --git a/bindings/__init__.py b/bindings/__init__.py index f301b56..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 * @@ -87,13 +87,16 @@ from .GradientRadialFocus import * from .GridView import * from .Dragger import * -#from .IconUtils import * +from .IconUtils import * from .Input import * from .PrintJob import * +from .ByteOrder import * +from .StopWatch import * from .Beep import * from .Architecture import * from .Locker import * +#from .BlockCache import * from .Autolock import * from .DateTime import * from .parsedate import * @@ -103,9 +106,15 @@ from .AffineTransform import * from .StringList import * from .DataIO import * +from .BufferIO import * +from .BufferedDataIO import * from .Url import * +from .UTF8 import * +from .TLS import * +from .Job import * from .fs_attr import * +from .OS import * from .StorageDefs import * from .Statable import * @@ -121,6 +130,8 @@ from .Mime import * from .MimeType import * +from .NodeInfo import * +from .AppFileInfo import * from .Resources import * from .ResourceStrings import * from .EntryList import * @@ -128,15 +139,97 @@ from .Query import * from .NodeMonitor import * from .NodeInfo import * -#from .DiskDeviceDefs import * +from .DiskDeviceDefs import * from .FilePanel import * from .TranslationDefs import * from .TranslatorRoster import * from .TranslationUtils import * from .Translator import * +from .BitmapStream import * +from .TranslatorFormats 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 * + +#from .bus_manager import * + +#from .SerialPort import * +#from .Joystick import * +#from .USBKit import * +#from .A2D import * +#from .D2A import * +#from .DigitalPort import * +from .Email import * +from .mail_encoding import * +from .MailComponent import * +from .MailDaemon import * +from .MailContainer import * +from .MailMessage import * +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 * +from .StringFormat import * +from .TextEncoding import * +from .RelativeDateTimeFormat import * +from .NumberFormat import * +from .LocaleStrings import * +from .LocaleRoster import * +from .Locale import * +from .Collator import * +from .CatalogData import * +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 * +from .MediaEncoder import * +from .ParameterWeb import * +from .MediaTrack import * +from .MediaFile import * +from .MediaFiles import * +from .MediaFormats import * +from .MediaRecorder import * +from .MediaRoster import * +from .MediaTheme import * +from .PlaySound import * +from .Sound import * +from .SoundFile import * +from .SoundPlayer import * +from .TimeCode import * +from .TimedEventQueue 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..2800905 --- /dev/null +++ b/bindings/add-ons/graphics/Accelerant.cpp @@ -0,0 +1,310 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +class MyClass { +public: +enum production { + week, + year +}; +}; + +PYBIND11_MODULE(Accelerant, m) +{ +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") = 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") = 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") = 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") = 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, "") +//.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(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, "") +.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(py::init(), "") +.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(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, "") +.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(py::init(), "") +.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(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, "") +.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(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, "") +.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(py::init(), "") +.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(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, "") +.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..2db9dc8 --- /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")); + +} diff --git a/bindings/app/Application.cpp b/bindings/app/Application.cpp index 4707368..1e6eca5 100644 --- a/bindings/app/Application.cpp +++ b/bindings/app/Application.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -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; @@ -31,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 { @@ -42,10 +66,23 @@ 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, 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); } @@ -69,30 +106,14 @@ 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); 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")) @@ -106,6 +127,7 @@ py::class_(m, "BApplication") .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, "") 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 38b23ad..475a85f 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,30 @@ 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 +88,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 +102,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/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..74ebe3e --- /dev/null +++ b/bindings/device/SerialPort.cpp @@ -0,0 +1,105 @@ +#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("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")) +.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..ea3be3c --- /dev/null +++ b/bindings/device/USBKit.cpp @@ -0,0 +1,140 @@ +#include +#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")) //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, "") +.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("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", &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"),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/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/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/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) 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")) diff --git a/bindings/interface/GraphicsDefs.cpp b/bindings/interface/GraphicsDefs.cpp index 273b38f..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")) @@ -175,7 +177,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, "") 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, "") 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/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/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")) 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")) diff --git a/bindings/interface/InterfaceDefs.cpp b/bindings/interface/InterfaceDefs.cpp index 5b248aa..4121527 100644 --- a/bindings/interface/InterfaceDefs.cpp +++ b/bindings/interface/InterfaceDefs.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -16,7 +17,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 +38,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; @@ -148,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; @@ -164,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, "") @@ -286,7 +328,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 +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? //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, "") @@ -326,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") @@ -346,29 +401,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")); diff --git a/bindings/interface/Layout.cpp b/bindings/interface/Layout.cpp index d32b861..9d67689 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")); } 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") 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")) +; } diff --git a/bindings/interface/OutlineListView.cpp b/bindings/interface/OutlineListView.cpp index 61bc1fb..de5c157 100644 --- a/bindings/interface/OutlineListView.cpp +++ b/bindings/interface/OutlineListView.cpp @@ -8,10 +8,88 @@ 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") +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")) 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) 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")) 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(); } diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index d61d22d..04e2efa 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -126,21 +126,38 @@ 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, "") -.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 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); - }) + },[](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)); + })*/ +//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; + } +}) ; - /* py::class_(m, "text_run_array") .def_readwrite("count", &text_run_array::count, "") @@ -173,6 +190,42 @@ 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("SetText", [](BTextView& self, const char* text, 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(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) @@ -180,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, "") @@ -193,7 +251,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) @@ -201,13 +265,36 @@ 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")) -.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")) +//.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) @@ -253,8 +340,8 @@ 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")) +; } diff --git a/bindings/interface/Window.cpp b/bindings/interface/Window.cpp index 0bb5eb0..2bef299 100644 --- a/bindings/interface/Window.cpp +++ b/bindings/interface/Window.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -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) { @@ -103,6 +124,8 @@ void QuitWrapper(BWindow& self) { self.Quit(); } +PYBIND11_SMART_HOLDER_TYPE_CASTERS(BWindow); + PYBIND11_MODULE(Window,m) { py::enum_(m, "window_type", "") @@ -163,10 +186,10 @@ 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")) +py::class_(m, "BWindow") +.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, "") diff --git a/bindings/kernel/OS.cpp b/bindings/kernel/OS.cpp new file mode 100644 index 0000000..bdb330e --- /dev/null +++ b/bindings/kernel/OS.cpp @@ -0,0 +1,635 @@ +#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); +} + +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) +{ +/*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_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")); + +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_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")); + +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_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")); + +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_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")); + +//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_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")); + +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")); + +} diff --git a/bindings/locale/Catalog.cpp b/bindings/locale/Catalog.cpp new file mode 100644 index 0000000..7f87240 --- /dev/null +++ b/bindings/locale/Catalog.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + +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("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..f9d5425 --- /dev/null +++ b/bindings/locale/CatalogData.cpp @@ -0,0 +1,104 @@ +#include +#include +#include +#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); + } +}; + +PYBIND11_MODULE(CatalogData, m) +{ +//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")) +.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"));// as below + +//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 + +} diff --git a/bindings/locale/Collator.cpp b/bindings/locale/Collator.cpp new file mode 100644 index 0000000..24bcd67 --- /dev/null +++ b/bindings/locale/Collator.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(Collator, 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..04b77f7 --- /dev/null +++ b/bindings/locale/Locale.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +PYBIND11_MODULE(Locale, 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::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 new file mode 100644 index 0000000..12ac73e --- /dev/null +++ b/bindings/locale/LocaleRoster.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; + + +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", &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")) +.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, "") +; + +m.attr("B_LOCALE_CHANGED") = '_LCC';//py::cast(B_LOCALE_CHANGED); +} diff --git a/bindings/locale/LocaleStrings.cpp b/bindings/locale/LocaleStrings.cpp new file mode 100644 index 0000000..832c3de --- /dev/null +++ b/bindings/locale/LocaleStrings.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(LocaleStrings, 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..c9e1506 --- /dev/null +++ b/bindings/locale/NumberFormat.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(NumberFormat, 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, int32 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..28e63cf --- /dev/null +++ b/bindings/locale/RelativeDateTimeFormat.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(RelativeDateTimeFormat, 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..cb2def6 --- /dev/null +++ b/bindings/locale/StringFormat.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(StringFormat, 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..9c9b36b --- /dev/null +++ b/bindings/locale/TextEncoding.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; + +PYBIND11_MODULE(TextEncoding, 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..39b4c19 --- /dev/null +++ b/bindings/locale/TimeZone.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(TimeZone, 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, "") +; +m.attr("kNameOfGmtZone") = "GMT"; + +} 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")) +; + + +} diff --git a/bindings/mail/Email.cpp b/bindings/mail/Email.cpp new file mode 100644 index 0000000..44646ae --- /dev/null +++ b/bindings/mail/Email.cpp @@ -0,0 +1,118 @@ +#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'; +} + +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", "") +.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("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) +; + +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..479d225 --- /dev/null +++ b/bindings/mail/MailAttachment.cpp @@ -0,0 +1,138 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +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) +{ +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..fa893f2 --- /dev/null +++ b/bindings/mail/MailComponent.cpp @@ -0,0 +1,94 @@ +#include +#include +#include +#include + +#include +#include + +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", "") +.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::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")) +.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..a30fcf6 --- /dev/null +++ b/bindings/mail/MailContainer.cpp @@ -0,0 +1,90 @@ +#include +#include +#include +#include + +#include + +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); + } +}; + +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") +.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..914206d --- /dev/null +++ b/bindings/mail/MailMessage.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include + +#include +#include + +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) +{ +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::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")) +.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..6a2a8c1 --- /dev/null +++ b/bindings/mail/MailSettings.cpp @@ -0,0 +1,162 @@ +#include +#include +#include +#include + +#include +#include + +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) +{ +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")) +//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, "") +; + +py::class_(m, "BMailProtocolSettings") +.def(py::init(), "") +.def("Load", &BMailProtocolSettings::Load, "", py::arg("message")) +//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")) +.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(), "") +//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")) +.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..de13131 --- /dev/null +++ b/bindings/mail/mail_encoding.cpp @@ -0,0 +1,263 @@ +#include +#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; + + 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, "") +.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_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")); + +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")); + +} 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..d5ffeb0 --- /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 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..acaf890 --- /dev/null +++ b/bindings/media/MediaDefs.cpp @@ -0,0 +1,931 @@ +#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, "") +.def_static("wildcard", []() { return 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, "") +.def_static("wildcard", []() { return 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, "") +.def_static("wildcard", []() { return 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, "") +.def_static("wildcard", []() { return 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, "") +.def_static("wildcard", []() { return 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, "") +.def_static("wildcard", []() { return 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..974222a --- /dev/null +++ b/bindings/media/MediaEncoder.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +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("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")) // TODO convert void to py::buffer? py::bytes?? +.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")) // TODO void +; + + +} 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..637ddaa --- /dev/null +++ b/bindings/media/MediaFile.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; + +PYBIND11_MODULE(MediaFile, m) +{ +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("MediaStreamer") = py::cast(MediaStreamer); + +//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")) +.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("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, "") +.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..2d77348 --- /dev/null +++ b/bindings/media/MediaFiles.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; + +PYBIND11_MODULE(MediaFiles, 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, "") //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 new file mode 100644 index 0000000..092dc0a --- /dev/null +++ b/bindings/media/MediaFormats.cpp @@ -0,0 +1,321 @@ +#include +#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) +{ +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_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_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_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") +.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, "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_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") +.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..559c824 --- /dev/null +++ b/bindings/media/MediaNode.cpp @@ -0,0 +1,148 @@ +#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::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, "") +.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..cbc86cc --- /dev/null +++ b/bindings/media/MediaRecorder.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +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, "") +.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..4ea8b6b --- /dev/null +++ b/bindings/media/MediaRoster.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +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.") +.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::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) +.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("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")) +.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..9fc15c7 --- /dev/null +++ b/bindings/media/MediaTheme.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; + +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, "") +.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")=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")); //where are these? + +//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..45eb8a1 --- /dev/null +++ b/bindings/media/MediaTrack.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; + +PYBIND11_MODULE(MediaTrack, 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("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) +.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("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, "") +.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..4771948 --- /dev/null +++ b/bindings/media/ParameterWeb.cpp @@ -0,0 +1,238 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + + +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_MASTER_GAIN") = "Master";//py::cast(B_MASTER_GAIN); + +m.attr("B_GAIN") = "Gain";//py::cast(B_GAIN); + +m.attr("B_BALANCE") = "Balance";//py::cast(B_BALANCE); + +m.attr("B_FREQUENCY") = "Frequency";//py::cast(B_FREQUENCY); + +m.attr("B_LEVEL") = "Level";//py::cast(B_LEVEL); + +m.attr("B_SHUTTLE_SPEED") = "Speed";//py::cast(B_SHUTTLE_SPEED); + +m.attr("B_CROSSFADE") = "XFade";//py::cast(B_CROSSFADE); + +m.attr("B_EQUALIZATION") = "EQ";//py::cast(B_EQUALIZATION); + +m.attr("B_COMPRESSION") = "Compression";//py::cast(B_COMPRESSION); + +m.attr("B_QUALITY") = "Quality";//py::cast(B_QUALITY); + +m.attr("B_BITRATE") = "Bitrate";//py::cast(B_BITRATE); + +m.attr("B_GOP_SIZE") = "GOPSize";//py::cast(B_GOP_SIZE); + +m.attr("B_MUTE") = "Mute";//py::cast(B_MUTE); + +m.attr("B_ENABLE") = "Enable";//py::cast(B_ENABLE); + +m.attr("B_INPUT_MUX") = "Input";//py::cast(B_INPUT_MUX); + +m.attr("B_OUTPUT_MUX") = "Output";//py::cast(B_OUTPUT_MUX); + +m.attr("B_TUNER_CHANNEL") = "Channel";//py::cast(B_TUNER_CHANNEL); + +m.attr("B_TRACK") = "Track";//py::cast(B_TRACK); + +m.attr("B_RECSTATE") = "RecState";//py::cast(B_RECSTATE); + +m.attr("B_SHUTTLE_MODE") = "Shuttle";//py::cast(B_SHUTTLE_MODE); + +m.attr("B_RESOLUTION") = "Resolution";//py::cast(B_RESOLUTION); + +m.attr("B_COLOR_SPACE") = "Colorspace";//py::cast(B_COLOR_SPACE); + +m.attr("B_FRAME_RATE") = "FrameRate";//py::cast(B_FRAME_RATE); + +m.attr("B_VIDEO_FORMAT") = "VideoFormat";//py::cast(B_VIDEO_FORMAT); + +m.attr("B_WEB_PHYSICAL_INPUT") = "PhysInput";//py::cast(B_WEB_PHYSICAL_INPUT); + +m.attr("B_WEB_PHYSICAL_OUTPUT") = "PhysOutput";//py::cast(B_WEB_PHYSICAL_OUTPUT); + +m.attr("B_WEB_ADC_CONVERTER") = "ADC";//py::cast(B_WEB_ADC_CONVERTER); + +m.attr("B_WEB_DAC_CONVERTER") = "DAC";//py::cast(B_WEB_DAC_CONVERTER); + +m.attr("B_WEB_LOGICAL_INPUT") = "LogInput";//py::cast(B_WEB_LOGICAL_INPUT); + +m.attr("B_WEB_LOGICAL_OUTPUT") = "LogOutput";//py::cast(B_WEB_LOGICAL_OUTPUT); + +m.attr("B_WEB_LOGICAL_BUS") = "LogBus";//py::cast(B_WEB_LOGICAL_BUS); + +m.attr("B_WEB_BUFFER_INPUT") = "DataInput";//py::cast(B_WEB_BUFFER_INPUT); + +m.attr("B_WEB_BUFFER_OUTPUT") = "DataOutput";//py::cast(B_WEB_BUFFER_OUTPUT); + +m.attr("B_SIMPLE_TRANSPORT") = "SimpleTransport";//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..5601c80 --- /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; + +PYBIND11_MODULE(PlaySound, 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..93da60d --- /dev/null +++ b/bindings/media/Sound.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +#include +#include +//#include +//#include + +namespace py = pybind11; +using namespace BPrivate; + +PYBIND11_MODULE(Sound, 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..329b523 --- /dev/null +++ b/bindings/media/SoundFile.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +#include +//#include +//#include + +namespace py = pybind11; +using namespace BPrivate; + +PYBIND11_MODULE(SoundFile, m) +{ +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("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..1b18885 --- /dev/null +++ b/bindings/media/SoundPlayer.cpp @@ -0,0 +1,112 @@ +#include +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; + +PYBIND11_MODULE(SoundPlayer, m) +{ +//m.attr("SoundPlayNode") = py::cast(SoundPlayNode); + +/*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") = 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, "") +//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, "") +//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")) +.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..072478d --- /dev/null +++ b/bindings/media/TimeCode.cpp @@ -0,0 +1,108 @@ +#include +#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'; +} + +PYBIND11_MODULE(TimeCode, 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_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") +.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..9682a92 --- /dev/null +++ b/bindings/media/TimedEventQueue.cpp @@ -0,0 +1,113 @@ +#include +#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'; +} + +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("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_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(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")=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")=BTimedEventQueue::event_type::B_ANY_EVENT) +; + +//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__", py::overload_cast(&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__", py::overload_cast(&operator>), "", py::arg("a"), py::arg("b")); + +} diff --git a/bindings/storage/AppFileInfo.cpp b/bindings/storage/AppFileInfo.cpp index fd4be12..8fb2278 100644 --- a/bindings/storage/AppFileInfo.cpp +++ b/bindings/storage/AppFileInfo.cpp @@ -8,6 +8,8 @@ namespace py = pybind11; +/* +// promemoria struct version_info { uint32_t major; uint32_t middle; @@ -16,7 +18,7 @@ struct version_info { uint32_t internal; char short_info[64]; char long_info[256]; -}; +};*/ PYBIND11_MODULE(AppFileInfo, m) { @@ -39,16 +41,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 +49,53 @@ 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, ""); +// 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") .def(py::init(), "") 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? ; 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")) 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: 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; } diff --git a/bindings/support/BlockCache.cpp b/bindings/support/BlockCache.cpp index f49441a..d569edc 100644 --- a/bindings/support/BlockCache.cpp +++ b/bindings/support/BlockCache.cpp @@ -7,16 +7,61 @@ 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 +}; -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("Get", &BBlockCache::Get, "", py::arg("blockSize")) -.def("Save", &BBlockCache::Save, "", py::arg("pointer"), py::arg("blockSize")) +.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("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")) ; 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")) 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)*/ ; diff --git a/bindings/support/ByteOrder.cpp b/bindings/support/ByteOrder.cpp index d5e5840..4117130 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, "") @@ -18,18 +42,25 @@ 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")); 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 } diff --git a/bindings/support/DataIO.cpp b/bindings/support/DataIO.cpp index 17e212e..4af613b 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); } @@ -20,11 +21,11 @@ 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); @@ -33,16 +34,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); @@ -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); } @@ -88,7 +91,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 +105,12 @@ py::class_(m, "BDataIO") .def("WriteExactly", &BDataIO::WriteExactly, "", py::arg("buffer"), py::arg("size"), py::arg("_bytesWritten")=NULL) ; - -py::class_(m, "BLayout"); -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") .def(py::init(), "") .def("Read", &BPositionIO::Read, "", py::arg("buffer"), py::arg("size")) .def("Write", &BPositionIO::Write, "", py::arg("buffer"), py::arg("size")) @@ -122,10 +124,9 @@ py::class_>(m, "BPositionIO") .def("GetSize", &BPositionIO::GetSize, "", py::arg("size")) ; -//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")) +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")) .def("WriteAt", &BMemoryIO::WriteAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) .def("Seek", &BMemoryIO::Seek, "", py::arg("position"), py::arg("seekMode")) @@ -133,8 +134,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 +145,5 @@ py::class_(m, "BMallocIO") .def("Buffer", &BMallocIO::Buffer, "") .def("BufferLength", &BMallocIO::BufferLength, "") ; -*/ } 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")) ; 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, "") ; 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) diff --git a/bindings/support/TLS.cpp b/bindings/support/TLS.cpp index 3ea7907..23a0852 100644 --- a/bindings/support/TLS.cpp +++ b/bindings/support/TLS.cpp @@ -6,16 +6,15 @@ #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")); 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* } 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 } 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()); + } +}) + ; 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, "") 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/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 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/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/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/fstest.py b/tests/filesystem.py similarity index 89% rename from fstest.py rename to tests/filesystem.py index ff46c4e..3ac0e22 100644 --- a/fstest.py +++ b/tests/filesystem.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,20 @@ 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) + #vi.short_info="File system tests" + #bafi.SetVersionInfo(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=[] diff --git a/tmtest.py b/tests/interfaceKit.py similarity index 92% rename from tmtest.py rename to tests/interfaceKit.py index 27a4de6..a36a6e8 100644 --- a/tmtest.py +++ b/tests/interfaceKit.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): @@ -314,13 +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())) - #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) + ##self.tra=self.typtap.RunArray(0,len(self.typtap.Text())) pittura=rgb_color() pittura.red=255 pittura.green=0 @@ -331,22 +330,29 @@ 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.runs[1] = tr2 #assign the second one + 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() + #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() @@ -415,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)+"%" 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.")