22#include < pybind11/stl.h>
33#include < pybind11/iostream.h>
44#include < pybind11/operators.h>
5+ #include < pybind11/numpy.h>
56
67#include < Mime.h>
78#include < Bitmap.h>
89
910namespace py = pybind11;
11+ /*
12+ std::tuple<status_t,py::array_t<uint8>> get_device_icon_py(const char *device) {
13+ uint8 *data = nullptr;
14+ size_t size = 0;
15+ type_code type = B_MINI_ICON_TYPE; // default value
1016
17+ // Chiamata alla funzione C++
18+ status_t result = get_device_icon(device, &data, &size, &type);
19+
20+ //if (result != B_OK) {
21+ // // Gestisci l'errore in qualche modo
22+ // throw std::runtime_error("Errore nella funzione get_device_icon");
23+ //}
24+
25+ // Creazione di un array NumPy dalla memoria ottenuta
26+ auto capsule = py::capsule(data, [](void *d) {
27+ // Implementa la logica per deallocare la memoria
28+ // In questo esempio, si presume che la memoria sia stata allocata con new[]
29+ delete[] static_cast<uint8 *>(d);
30+ });
31+
32+ return std::make_tuple(result,py::array_t<uint8>({static_cast<ssize_t>(size)}, {sizeof(uint8)}, data, capsule));
33+ }*/
1134
1235PYBIND11_MODULE (Mime, m)
1336{
@@ -17,23 +40,48 @@ py::enum_<icon_size>(m, "icon_size", "")
1740.export_values ();
1841
1942m.attr (" B_UPDATE_MIME_INFO_NO_FORCE" ) =0 ;// hardcoded, not reading enum
20- m.attr (" B_UPDATE_MIME_INFO_FORCE_KEEP_TYPE" ) =1 ;
21- m.attr (" B_UPDATE_MIME_INFO_FORCE_UPDATE_ALL" ) =2 ;
43+ m.attr (" B_UPDATE_MIME_INFO_FORCE_KEEP_TYPE" ) =1 ;// hardcoded, not reading enum
44+ m.attr (" B_UPDATE_MIME_INFO_FORCE_UPDATE_ALL" ) =2 ;// hardcoded, not reading enum
2245
2346// m.attr("BBitmap") = py::cast(BBitmap);
2447
2548m.def (" update_mime_info" , &update_mime_info," " ,py::arg (" path" ),py::arg (" recursive" ),py::arg (" synchronous" ),py::arg (" force" ));
2649
2750m.def (" create_app_meta_mime" , &create_app_meta_mime," " ,py::arg (" path" ),py::arg (" recursive" ),py::arg (" synchronous" ),py::arg (" force" ));
2851
29- m.def (" get_device_icon " , py::overload_cast<const char *,void *, int32>(&get_device_icon)," " ,py::arg (" device" ),py::arg (" icon" ),py::arg (" size" ));
52+ m.def (" get_device_icon_toVoid " , py::overload_cast<const char *,void *, int32>(&get_device_icon)," " ,py::arg (" device" ),py::arg (" icon" ),py::arg (" size" ));
3053
31- m.def (" get_device_icon " , py::overload_cast<const char *, BBitmap *, icon_size>(&get_device_icon)," " ,py::arg (" device" ),py::arg (" icon" ),py::arg (" which" ));
54+ m.def (" get_device_icon_toBitmap " , py::overload_cast<const char *, BBitmap *, icon_size>(&get_device_icon)," " ,py::arg (" device" ),py::arg (" icon" ),py::arg (" which" ));
3255
3356// m.def("get_device_icon", py::overload_cast<const char *, unsigned char, size_t *, type_code *>(&get_device_icon), "", py::arg("device"), py::arg("_data"), py::arg("_size"), py::arg("_type"));
57+ m.def (" get_device_icon_toArray" , [](const char * device){
58+ uint8 *data =nullptr ;
59+ size_t size =0 ;
60+ type_code type = B_MINI_ICON_TYPE;// default value
61+ status_t result =get_device_icon (device, &data, &size, &type);
62+ auto capsule =py::capsule (data, [](void *d) {
63+ // Implementa la logica per deallocare la memoria
64+ // In questo esempio, si presume che la memoria sia stata allocata con new[]
65+ delete[] static_cast <uint8 *>(d);
66+ });
67+
68+ return std::make_tuple (result,py::array_t <uint8>({static_cast <ssize_t >(size)}, {sizeof (uint8)}, data, capsule));
69+ }," " ,py::arg (" device" ));
3470// unsigned char ->uint8**
35- m.def (" get_named_icon " , py::overload_cast<const char *, BBitmap *, icon_size>(&get_named_icon)," " ,py::arg (" name" ),py::arg (" icon" ),py::arg (" which" ));
71+ m.def (" get_named_icon_toBitmap " , py::overload_cast<const char *, BBitmap *, icon_size>(&get_named_icon)," " ,py::arg (" name" ),py::arg (" icon" ),py::arg (" which" ));
3672
3773// m.def("get_named_icon", py::overload_cast<const char *, unsigned char, size_t *, type_code *>(&get_named_icon), "", py::arg("name"), py::arg("_data"), py::arg("_size"), py::arg("_type"));
3874// unsigned char ->uint8**
75+ m.def (" get_named_icon_toArray" , [](const char *name,unsigned char iconSize,size_t *size, type_code *iconType) {
76+ uint8 *data =nullptr ;
77+ status_t result =get_named_icon (name, &data, size, iconType);
78+
79+ auto capsule =py::capsule (data, [](void *d) {
80+ // Implementa la logica per deallocare la memoria, se necessario
81+ // In questo esempio, si presume che la memoria sia stata allocata con new[]
82+ delete[] static_cast <uint8 *>(d);
83+ });
84+
85+ return std::make_tuple (result, py::array_t <uint8>({static_cast <ssize_t >(*size)}, {sizeof (uint8)}, data, capsule));
86+ }," " ,py::arg (" name" ),py::arg (" iconSize" ),py::arg (" size" ),py::arg (" iconType" ));
3987}