1. Trang chủ
  2. » Luận Văn - Báo Cáo

Thiết kế hệ thống cảnh báo tài xế ngủ gật trên ô tô thi công lắp đặt và thực nghiệm hệ thống

105 1 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC CÔNG NGHỆ TP HỒ CHÍ MINH ĐỒ ÁN TỐT NGHIỆP THIẾT KẾ HỆ THỐNG CẢNH BÁO TÀI XẾ NGỦ GẬT TRÊN Ô TÔ – THI CÔNG, LẮP ĐẶT VÀ THỰC NGHIỆM HỆ THỐNG NGÀNH: CÔNG NGHỆ KỸ THUẬT Ô TÔ GIẢNG VIÊN HƯỚNG DẪN: TS NGUYỄN VĂN NHANH Sinh viên thực hiện: MSSV: Lớp: Nguyễn Trung Hiếu 1711251926 17DOTC3 Cao Gia Bảo 1711251942 17DOTC3 Nguyễn Kế Thức 1711251939 17DOTC3 TP Hồ Chí Minh, tháng năm 2021 BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC CƠNG NGHỆ TP HỒ CHÍ MINH ĐỒ ÁN TỐT NGHIỆP THIẾT KẾ HỆ THỐNG CẢNH BÁO TÀI XẾ NGỦ GẬT TRÊN Ô TÔ – THI CÔNG, LẮP ĐẶT VÀ THỰC NGHIỆM HỆ THỐNG NGÀNH: CÔNG NGHỆ KỸ THUẬT Ô TÔ GIẢNG VIÊN HƯỚNG DẪN: TS NGUYỄN VĂN NHANH Sinh viên thực hiện: MSSV: Lớp: Nguyễn Trung Hiếu 1711251926 17DOTC3 Cao Gia Bảo 1711251942 17DOTC3 Nguyễn Kế Thức 1711251939 17DOTC3 TP Hồ Chí Minh, tháng năm 2021 BM01/QT05/ĐT-KT VIỆN KỸ THUẬT HUTECH PHIẾU ĐĂNG KÝ ĐỀ TÀI ĐỒ ÁN/KHĨA LUẬN TỐT NGHIỆP Hệ: Chính quy (CQ, LT, B2, VLVH) Họ tên sinh viên/ nhóm sinh viên đăng ký đề tài (sĩ số nhóm: 3): (1) Nguyễn Trung Hiếu MSSV: 1711251926 Lớp: 17DOTC3 Điện thoại: 0338183019 Email: nth.3199@gmail.com (2) Cao Gia Bảo MSSV: 1711251942 Lớp: 17DOTC3 Điện thoại: 0388790543 Email: caogiabao4068@gmail.com (3) Nguyễn Kế Thức MSSV: 1711251939 Lớp: 17DOTC3 Điện thoại: 0329686854 Email: nguyenkethuc300699@gmail.com Ngành : Công nghệ Kỹ thuật ô tô Chuyên ngành : Công nghệ Kỹ thuật ô tô Tên đề tài đăng ký: Thiết kế hệ thống cảnh báo tài xế ngủ gật ô tô – Thi công, lắp đặt thực nghiệm hệ thống Sinh viên hiểu rõ yêu cầu đề tài cam kết thực đề tài theo tiến độ hoàn thành thời hạn TP HCM, ngày 12 tháng 04 năm 2021 Giảng viên hướng dẫn Sinh viên đăng ký (Ký ghi rõ họ tên) (Ký ghi rõ họ tên) Nguyễn Văn Nhanh Nguyễn Trung Hiếu Cao Gia Bảo Nguyễn Kế Thức MÃ ĐỀ TÀI: 77 Viện Kỹ thuật Hutech PHIẾU GIAO NHIỆM VỤ THỰC HIỆN ĐỒ ÁN TỐT NGHIỆP Sinh viên thực đề tài Họ tên : Nguyễn Trung Hiếu Điện thoại : 0338183019 Ngành MSSV: 1711251926 Lớp: 17DOTC3 Email: nth.3199@gmail.com : Công nghệ Kỹ thuật ô tô Tên đề tài: Thiết kế hệ thống cảnh báo tài xế ngủ gật ô tô – Thi công, lắp đặt thực nghiệm hệ thống Nhiệm vụ thực đề tài: − Tìm hiểu tổng quát đề tài − Khảo sát lựa chọn phận, cụm chi tiết phù hợp cho mơ hình − Xây dựng quy trình thi cơng, lắp ráp − Thực nghiệm hệ thống xe thực tế − Viết báo cáo đồ án tốt nghiệp − Làm PowerPoint thuyết trình TP HCM, ngày 14 tháng 05 năm 2021 Sinh viên thực Giảng viên hướng dẫn (Ký ghi rõ họ tên) (Ký ghi rõ họ tên) Nguyễn Trung Hiếu Nguyễn Văn Nhanh MÃ ĐỀ TÀI: 77 Viện Kỹ thuật Hutech PHIẾU GIAO NHIỆM VỤ THỰC HIỆN ĐỒ ÁN TỐT NGHIỆP Sinh viên thực đề tài Họ tên : Cao Gia Bảo Điện thoại : 0388790543 Ngành MSSV: 1711251942 Lớp: 17DOTC3 Email: caogiabao4068@gmail.com : Công nghệ Kỹ thuật ô tô Tên đề tài: Thiết kế hệ thống cảnh báo tài xế ngủ gật ô tơ – Lập trình hệ thống Nhiệm vụ thực đề tài: − Tìm hiểu tổng quát đề tài − Lựa chọn phần mềm lập trình − Xây dựng thuật tốn điều khiển − Lập trình hệ thống phần mềm − Thực nghiệm hệ thống xe − Viết báo cáo đồ án tốt nghiệp TP HCM, ngày 14 tháng 05 năm 2021 Sinh viên thực Giảng viên hướng dẫn (Ký ghi rõ họ tên) (Ký ghi rõ họ tên) Cao Gia Bảo Nguyễn Văn Nhanh MÃ ĐỀ TÀI: 77 Viện Kỹ thuật Hutech PHIẾU GIAO NHIỆM VỤ THỰC HIỆN ĐỒ ÁN TỐT NGHIỆP Sinh viên thực đề tài Họ tên : Nguyễn Kế Thức Điện thoại : 0329686854 MSSV: 1711251939 Lớp: 17DOTC3 Email: nguyenkethuc300699@gmail.com : Công nghệ Kỹ thuật ô tô Ngành Tên đề tài: Thiết kế hệ thống cảnh báo tài xế ngủ gật tơ – Tính tốn thiết kế phần khí Nhiệm vụ thực đề tài: − Tìm hiểu tổng quát đề tài − Lựa chọn phương án thiết kế mơ hình tối ưu − Mua thiết bị cho mơ hình − Thực nghiệm hệ thống xe − Viết báo cáo đồ án tốt nghiệp − Làm PowerPoint thuyết trình TP HCM, ngày 14 tháng 05 năm 2021 Sinh viên thực Giảng viên hướng dẫn (Ký ghi rõ họ tên) (Ký ghi rõ họ tên) Nguyễn Kế Thức Nguyễn Văn Nhanh LỜI CAM ĐOAN Tôi xin cam đoan cơng trình nghiên cứu chúng tơi thực hướng dẫn TS Nguyễn Văn Nhanh dựa vào số tài liệu, đề tài trước khơng chép từ tài liệu hay cơng trình có trước Tp Hồ Chí Minh, ngày 25 tháng 09 năm 2021 (Ký tên ghi rõ họ tên) Nguyễn Trung Hiếu Cao Gia Bảo i Nguyễn Kế Thức LỜI CẢM ƠN Trong trình thực báo cáo, gặp nhiều khó khăn, nhờ hướng dẫn tận tình TS Nguyễn Văn Nhanh, nhóm tơi hồn thành báo cáo thời gian quy định Để hồn thành báo cáo này, tơi xin bày tỏ lòng biết ơn sâu sắc TS Nguyễn Văn Nhanh, thầy người tận tâm hết lòng sinh viên, hướng dẫn nhiệt tình cung cấp cho nhóm tơi tài liệu vơ q giá thời gian thực báo cáo Xin chân thành cám ơn tập thể thầy cô giáo trường Đại học Cơng Nghệ TP Hồ Chí Minh, giảng dạy truyền đạt kiến thức cho tôi, giúp học tập nghiên cứu trình học trường Xin chân thành cảm ơn Ban giám hiệu, Viện Kỹ thuật Đại học Cơng Nghệ TP Hồ Chí Minh, giúp đỡ, tạo điều kiện thuận lợi cho trình học tập làm báo cáo trường Xin chân thành cảm ơn anh, chị đồng nghiệp hỗ trợ, giúp đỡ cho tơi q trình thực báo cáo Xin chân thành cảm ơn anh, chị Viện Kỹ thuật đóng góp ý kiến cho tơi q trình thực báo cáo ii MỤC LỤC TRANG LỜI CAM ĐOAN i LỜI CẢM ƠN ii MỤC LỤC iii DANH MỤC CÁC TỪ VIẾT TẮT vi DANH MỤC CÁC BẢNG vii DANH MỤC CÁC HÌNH ẢNH viii LỜI MỞ ĐẦU Chương 1: GIỚI THIỆU ĐỀ TÀI 1.1 Đặt vấn đề 1.2 Mục tiêu đề tài 1.3 Nhiệm vụ đề tài 1.4 Phương pháp nghiên cứu 1.5 Đối tượng nghiên cứu .3 1.6 Ý nghĩa đề tài 1.7 Bố cục đề tài .4 Chương 2: TỔNG QUAN GIẢI PHÁP 2.1 Ưu nhược điểm hệ thống cảnh báo tài xế ngủ gật 2.2 Các phương án thực cảnh báo tài xế ngủ gật ô tô 2.2.1 Phương pháp dựa vào sinh lý người lái xe 2.2.2 Phương pháp dựa vào HĐ phản ứng điều khiển xe người lái xe 2.3 Các hệ thống cảnh báo tài xế ngủ gật .6 2.3.1 Dạng đeo lên tai người lái xe 2.3.2 Dạng lắp đặt xe ô tô 2.4 Hệ thống cảnh báo ngủ gật hãng xe .7 2.4.1 Hãng Mercedes - Benz: thiết bị Attention 2.4.2 Hãng Hyundai: hệ thống chống ngủ gật DDREM cho tài xế iii 2.4.3 Hãng Honda: Hệ thống cảnh báo chống buồn ngủ Driver Attention Monitor .9 2.5 Các nghiên cứu hệ thống cảnh báo tài xế ngủ gật Việt Nam .10 2.5.1 Nghiên cứu thiết kế, chế tạo thiết bị nhúng kiểm soát trạng thái ngủ gật lái xe 10 2.5.2 Thiết kế hệ thống cảnh báo lái xe ngủ gật phương pháp xây dựng ứng dụng với thư viện mã nguồn OpenCV 13 2.6 Hướng phát triển đề tài 16 2.7 Kết luận 16 Chương 3: PHƯƠNG PHÁP GIẢI QUYẾT 17 3.1 Xác định biểu rút trích đặc trưng xác định trạng thái ngủ gật 17 3.2 Xác định thông số kỹ thuật cho thiết bị giám sát trạng thái buồn ngủ lái xe điều kiện giao thông thời tiết Việt Nam 18 3.2.1 Xác định tư đầu dựa vào phát khuôn mặt trường hợp đầu chuyển động 18 3.2.2 Tìm từ khuôn mặt để xác định mắt nhắm hay mở 21 3.2.3 Xác định thông số kỹ thuật cho thiết bị giám sát trạng thái buồn ngủ lái xe 23 3.3 Phần mềm xử lý ảnh .24 3.3.1 Thư viện OpenCV 24 3.3.2 Cách tổ chức thư viện OpenCV .24 3.3.3 Tổng quan phương pháp Haar-like 26 3.4 Kết luận 34 Chương 4: QUY TRÌNH THIẾT KẾ HỆ THỐNG CẢNH BÁO TÀI XẾ NGỦ GẬT 35 4.1 Mơ hình hệ thống cảnh báo ngủ gật tài xế cần thiết kế 35 4.1.1 Yêu cầu mô hình hệ thống 35 4.1.2 Mô tả hệ thống cảnh báo ngủ gật tài xế cần thiết kế 35 iv /* type_register_custom API now removed, but leave a pointer here to not * break ABI */ void *_type_register_custom; gboolean (*gerror_exception_check) (GError **error); PyObject* (*option_group_new) (GOptionGroup *group); GType (* type_from_object_strict) (PyObject *obj, gboolean strict); PyObject *(* newgobj_full)(GObject *obj, gboolean steal, gpointer g_class); PyTypeObject *object_type; int (* value_from_pyobject_with_error)(GValue *value, PyObject *obj); }; /* Deprecated, only available for API compatibility */ #define pyg_threads_enabled TRUE #define pyg_gil_state_ensure PyGILState_Ensure #define pyg_gil_state_release PyGILState_Release #define pyg_begin_allow_threads Py_BEGIN_ALLOW_THREADS #define pyg_end_allow_threads Py_END_ALLOW_THREADS #define pyg_enable_threads() #define pyg_set_thread_block_funcs(a, b) #define pyg_block_threads() #define pyg_unblock_threads() #ifndef _INSIDE_PYGOBJECT_ #if defined(NO_IMPORT) || defined(NO_IMPORT_PYGOBJECT) extern struct _PyGObject_Functions *_PyGObject_API; #else struct _PyGObject_Functions *_PyGObject_API; #endif #define pygobject_register_class (_PyGObject_API->register_class) #define pygobject_register_wrapper (_PyGObject_API->register_wrapper) 75 #define pygobject_lookup_class #define pygobject_new (_PyGObject_API->lookup_class) (_PyGObject_API->newgobj) #define pygobject_new_full (_PyGObject_API->newgobj_full) #define PyGObject_Type (*_PyGObject_API->object_type) #define pyg_closure_new (_PyGObject_API->closure_new) #define pygobject_watch_closure #define (_PyGObject_API->object_watch_closure) pyg_closure_set_exception_handler (_PyGObject_API- >closure_set_exception_handler) #define pyg_destroy_notify (_PyGObject_API->destroy_notify) #define pyg_type_from_object_strict (_PyGObject_API->type_from_object_strict) #define pyg_type_from_object (_PyGObject_API->type_from_object) #define pyg_type_wrapper_new (_PyGObject_API->type_wrapper_new) #define pyg_enum_get_value (_PyGObject_API->enum_get_value) #define pyg_flags_get_value (_PyGObject_API->flags_get_value) #define pyg_register_gtype_custom (_PyGObject_API->register_gtype_custom) #define pyg_value_from_pyobject #define (_PyGObject_API->value_from_pyobject) pyg_value_from_pyobject_with_error (_PyGObject_API- >value_from_pyobject_with_error) #define pyg_value_as_pyobject (_PyGObject_API->value_as_pyobject) #define pyg_register_interface (_PyGObject_API->register_interface) #define PyGBoxed_Type (*_PyGObject_API->boxed_type) #define pyg_register_boxed (_PyGObject_API->register_boxed) #define pyg_boxed_new (_PyGObject_API->boxed_new) #define PyGPointer_Type (*_PyGObject_API->pointer_type) #define pyg_register_pointer (_PyGObject_API->register_pointer) #define pyg_pointer_new (_PyGObject_API->pointer_new) #define pyg_enum_add_constants #define pyg_flags_add_constants (_PyGObject_API->enum_add_constants) (_PyGObject_API->flags_add_constants) #define pyg_constant_strip_prefix (_PyGObject_API->constant_strip_prefix) 76 #define pyg_error_check (_PyGObject_API->error_check) #define PyGParamSpec_Type (*_PyGObject_API->paramspec_type) #define pyg_param_spec_new (_PyGObject_API->paramspec_new) #define pyg_param_spec_from_object (_PyGObject_API->paramspec_get) #define pyg_pyobj_to_unichar_conv (_PyGObject_API->pyobj_to_unichar_conv) #define pyg_parse_constructor_args (_PyGObject_API->parse_constructor_args) #define pyg_param_gvalue_as_pyobject (_PyGObject_API->value_as_pyobject) #define pyg_param_gvalue_from_pyobject (_PyGObject_API- >gvalue_from_param_pyobject) #define PyGEnum_Type #define pyg_enum_add #define pyg_enum_from_gtype #define PyGFlags_Type #define pyg_flags_add #define pyg_flags_from_gtype #define pyg_register_class_init (*_PyGObject_API->enum_type) (_PyGObject_API->enum_add) (_PyGObject_API->enum_from_gtype) (*_PyGObject_API->flags_type) (_PyGObject_API->flags_add) (_PyGObject_API->flags_from_gtype) (_PyGObject_API->register_class_init) #define pyg_register_interface_info (_PyGObject_API->register_interface_info) #define pyg_add_warning_redirection (_PyGObject_API- >add_warning_redirection) #define pyg_disable_warning_redirections (_PyGObject_API- >disable_warning_redirections) #define pyg_gerror_exception_check (_PyGObject_API->gerror_exception_check) #define pyg_option_group_new (_PyGObject_API->option_group_new) /** * pygobject_init: * @req_major: minimum version major number, or -1 * @req_minor: minimum version minor number, or -1 * @req_micro: minimum version micro number, or -1 * 77 * Imports and initializes the 'gobject' python module Can * optionally check for a required minimum version if @req_major, * @req_minor, and @req_micro are all different from -1 * * Returns: a new reference to the gobject module on success, NULL in * case of failure (and raises ImportError) **/ static inline PyObject * pygobject_init(int req_major, int req_minor, int req_micro) { PyObject *gobject, *cobject; gobject = PyImport_ImportModule("gi._gobject"); if (!gobject) { if (PyErr_Occurred()) { PyObject *type, *value, *traceback; PyObject *py_orig_exc; PyErr_Fetch(&type, &value, &traceback); py_orig_exc = PyObject_Repr(value); Py_XDECREF(type); Py_XDECREF(value); Py_XDECREF(traceback); #if PY_VERSION_HEX < 0x03000000 PyErr_Format(PyExc_ImportError, "could not import gobject (error was: %s)", PyString_AsString(py_orig_exc)); #else { 78 /* Can not use PyErr_Format because it doesn't have * a format string for dealing with PyUnicode objects * like PyUnicode_FromFormat has */ PyObject *errmsg = PyUnicode_FromFormat("could not import gobject (error was: %U)", py_orig_exc); if (errmsg) { PyErr_SetObject(PyExc_ImportError, errmsg); Py_DECREF(errmsg); } /* if errmsg is NULL then we might have OOM * PyErr should already be set and trying to * return our own error would be futile */ } #endif Py_DECREF(py_orig_exc); } else { PyErr_SetString(PyExc_ImportError, "could not import gobject (no error given)"); } return NULL; } cobject = PyObject_GetAttrString(gobject, "_PyGObject_API"); if (cobject && PyCapsule_CheckExact(cobject)) { 79 _PyGObject_API = (struct _PyGObject_Functions *) PyCapsule_GetPointer(cobject, "gobject._PyGObject_API"); Py_DECREF (cobject); } else { PyErr_SetString(PyExc_ImportError, "could not import gobject (could not find _PyGObject_API object)"); Py_XDECREF (cobject); Py_DECREF(gobject); return NULL; } if (req_major != -1) { int found_major, found_minor, found_micro; PyObject *version; version = PyObject_GetAttrString(gobject, "pygobject_version"); if (!version) { PyErr_SetString(PyExc_ImportError, "could not import gobject (version too old)"); Py_DECREF(gobject); return NULL; } if (!PyArg_ParseTuple(version, "iii", &found_major, &found_minor, &found_micro)) { PyErr_SetString(PyExc_ImportError, "could not import gobject (version has invalid format)"); Py_DECREF(version); Py_DECREF(gobject); 80 return NULL; } Py_DECREF(version); if (req_major != found_major || req_minor > found_minor || (req_minor == found_minor && req_micro > found_micro)) { PyErr_Format(PyExc_ImportError, "could not import gobject (version mismatch, %d.%d.%d is required, " "found %d.%d.%d)", req_major, req_minor, req_micro, found_major, found_minor, found_micro); Py_DECREF(gobject); return NULL; } } return gobject; } /** * PYLIST_FROMGLIBLIST: * @type: the type of the GLib list e.g #GList or #GSList * @prefix: the prefix of functions that manipulate a list of the type * given by type * * A macro that creates a type specific code block which converts a GLib * list (#GSList or #GList) to a Python list The first two args of the macro * are used to specify the type and list function prefix so that the type * specific macros can be generated * 81 * The rest of the args are for the standard args for the type specific * macro(s) created from this macro */ #define PYLIST_FROMGLIBLIST(type,prefix,py_list,list,item_convert_func,\ list_free,list_item_free) \ G_STMT_START \ {\ gint i, len; \ PyObject *item; \ void (*glib_list_free)(type*) = list_free; \ GFunc glib_list_item_free = (GFunc)list_item_free; \ \ len = prefix##_length(list); \ py_list = PyList_New(len); \ for (i = 0; i < len; i++) { \ gpointer list_item = prefix##_nth_data(list, i); \ \ item = item_convert_func; \ PyList_SetItem(py_list, i, item); \ }\ if (glib_list_item_free != NULL) \ prefix##_foreach(list, glib_list_item_free, NULL); \ if (glib_list_free != NULL) \ glib_list_free(list); \ } G_STMT_END /** * PYLIST_FROMGLIST: * @py_list: the name of the Python list 82 * * @list: the #GList to be converted to a Python list * * @item_convert_func: the function that converts a list item to a Python * object The function must refer to the list item using "@list_item" and * must return a #PyObject* object An example conversion function is: * [[ * PyString_FromString(list_item) * ]] * A more elaborate function is: * [[ * pyg_boxed_new(GTK_TYPE_RECENT_INFO, list_item, TRUE, TRUE) * ]] * @list_free: the name of a function that takes a single arg (the list) and * frees its memory Can be NULL if the list should not be freed An example * is: * [[ * g_list_free * ]] * @list_item_free: the name of a #GFunc function that frees the memory used * by the items in the list or %NULL if the list items not have to be * freed A simple example is: * [[ * g_free * ]] * * A macro that adds code that converts a #GList to a Python list * */ 83 #define PYLIST_FROMGLIST(py_list,list,item_convert_func,list_free,\ list_item_free) \ PYLIST_FROMGLIBLIST(GList,g_list,py_list,list,item_convert_func,\ list_free,list_item_free) /** * PYLIST_FROMGSLIST: * @py_list: the name of the Python list * * @list: the #GSList to be converted to a Python list * * @item_convert_func: the function that converts a list item to a Python * object The function must refer to the list item using "@list_item" and * must return a #PyObject* object An example conversion function is: * [[ * PyString_FromString(list_item) * ]] * A more elaborate function is: * [[ * pyg_boxed_new(GTK_TYPE_RECENT_INFO, list_item, TRUE, TRUE) * ]] * @list_free: the name of a function that takes a single arg (the list) and * frees its memory Can be %NULL if the list should not be freed An example * is: * [[ * g_list_free * ]] * @list_item_free: the name of a #GFunc function that frees the memory used * by the items in the list or %NULL if the list items not have to be * freed A simple example is: 84 * [[ * g_free * ]] * * A macro that adds code that converts a #GSList to a Python list * */ #define PYLIST_FROMGSLIST(py_list,list,item_convert_func,list_free,\ list_item_free) \ PYLIST_FROMGLIBLIST(GSList,g_slist,py_list,list,item_convert_func,\ list_free,list_item_free) /** * PYLIST_ASGLIBLIST * @type: the type of the GLib list e.g GList or GSList * @prefix: the prefix of functions that manipulate a list of the type * given by type e.g g_list or g_slist * * A macro that creates a type specific code block to be used to convert a * Python list to a GLib list (GList or GSList) The first two args of the * macro are used to specify the type and list function prefix so that the * type specific macros can be generated * * The rest of the args are for the standard args for the type specific * macro(s) created from this macro */ #define PYLIST_ASGLIBLIST(type,prefix,py_list,list,check_func,\ convert_func,child_free_func,errormsg,errorreturn) \ G_STMT_START \ {\ 85 Py_ssize_t i, n_list; \ GFunc glib_child_free_func = (GFunc)child_free_func; \ \ if (!(py_list = PySequence_Fast(py_list, ""))) { \ errormsg; \ return errorreturn; \ }\ n_list = PySequence_Fast_GET_SIZE(py_list); \ for (i = 0; i < n_list; i++) { \ PyObject *py_item = PySequence_Fast_GET_ITEM(py_list, i); \ \ if (!check_func) { \ if (glib_child_free_func) \ prefix##_foreach(list, glib_child_free_func, NULL); \ prefix##_free(list); \ Py_DECREF(py_list); \ errormsg; \ return errorreturn; \ }\ list = prefix##_prepend(list, convert_func); \ }; \ Py_DECREF(py_list); \ list = prefix##_reverse(list); \ }\ G_STMT_END /** * PYLIST_ASGLIST * @py_list: the Python list to be converted * @list: the #GList list to be converted 86 * @check_func: the expression that takes a #PyObject* arg (must be named * @py_item) and returns an int value indicating if the Python object matches * the required list item type (0 - %False or - %True) An example is: * [[ * (PyString_Check(py_item)||PyUnicode_Check(py_item)) * ]] * @convert_func: the function that takes a #PyObject* arg (must be named * py_item) and returns a pointer to the converted list object An example * is: * [[ * pygobject_get(py_item) * ]] * @child_free_func: the name of a #GFunc function that frees a GLib list * item or %NULL if the list item does not have to be freed This function is * used to help free the items in a partially created list if there is an * error An example is: * [[ * g_free * ]] * @errormsg: a function that sets up a Python error message An example is: * [[ * PyErr_SetString(PyExc_TypeError, "strings must be a sequence of" "strings * or unicode objects") * ]] * @errorreturn: the value to return if an error occurs, e.g.: * [[ * %NULL * ]] * 87 * A macro that creates code that converts a Python list to a #GList The * returned list must be freed using the appropriate list free function when * it's no longer needed If an error occurs the child_free_func is used to * release the memory used by the list items and then the list memory is * freed */ #define PYLIST_ASGLIST(py_list,list,check_func,convert_func,child_free_func,\ errormsg,errorreturn) \ PYLIST_ASGLIBLIST(GList,g_list,py_list,list,check_func,convert_func,\ child_free_func,errormsg,errorreturn) /** * PYLIST_ASGSLIST * @py_list: the Python list to be converted * @list: the #GSList list to be converted * @check_func: the expression that takes a #PyObject* arg (must be named * @py_item) and returns an int value indicating if the Python object matches * the required list item type (0 - %False or - %True) An example is: * [[ * (PyString_Check(py_item)||PyUnicode_Check(py_item)) * ]] * @convert_func: the function that takes a #PyObject* arg (must be named * py_item) and returns a pointer to the converted list object An example * is: * [[ * pygobject_get(py_item) * ]] * @child_free_func: the name of a #GFunc function that frees a GLib list * item or %NULL if the list item does not have to be freed This function is * used to help free the items in a partially created list if there is an 88 * error An example is: * [[ * g_free * ]] * @errormsg: a function that sets up a Python error message An example is: * [[ * PyErr_SetString(PyExc_TypeError, "strings must be a sequence of" "strings * or unicode objects") * ]] * @errorreturn: the value to return if an error occurs, e.g.: * [[ * %NULL * ]] * * A macro that creates code that converts a Python list to a #GSList The * returned list must be freed using the appropriate list free function when * it's no longer needed If an error occurs the child_free_func is used to * release the memory used by the list items and then the list memory is * freed */ #define PYLIST_ASGSLIST(py_list,list,check_func,convert_func,child_free_func,\ errormsg,errorreturn) \ PYLIST_ASGLIBLIST(GSList,g_slist,py_list,list,check_func,convert_func,\ child_free_func,errormsg,errorreturn) #endif /* !_INSIDE_PYGOBJECT_ */ G_END_DECLS #endif /* !_PYGOBJECT_H_ */ 89

Ngày đăng: 31/08/2023, 08:50

Xem thêm:

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w