1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
cimport _libkmod_h
from error import KmodError as _KmodError
cimport list as _list
import list as _list
cimport _util
import _util
cdef class Module (object):
"Wrap a struct kmod_module* item"
def __cinit__(self):
self.module = NULL
def __dealloc__(self):
self._cleanup()
def _cleanup(self):
if self.module is not NULL:
_libkmod_h.kmod_module_unref(self.module)
self.module = NULL
cpdef from_mod_list_item(self, _list.ModListItem item):
self._cleanup()
self.module = _libkmod_h.kmod_module_get_module(item.list)
def _name_get(self):
return _util.char_ptr_to_str(
_libkmod_h.kmod_module_get_name(self.module))
name = property(fget=_name_get)
def _path_get(self):
return _util.char_ptr_to_str(
_libkmod_h.kmod_module_get_path(self.module))
path = property(fget=_path_get)
def _options_get(self):
return _util.char_ptr_to_str(
_libkmod_h.kmod_module_get_options(self.module))
options = property(fget=_options_get)
def _install_commands_get(self):
return _util.char_ptr_to_str(
_libkmod_h.kmod_module_get_install_commands(self.module))
install_commands = property(fget=_install_commands_get)
def _remove_commands_get(self):
return _util.char_ptr_to_str(
_libkmod_h.kmod_module_get_remove_commands(self.module))
remove_commands = property(fget=_remove_commands_get)
def _refcnt_get(self):
return _libkmod_h.kmod_module_get_refcnt(self.module)
refcnt = property(fget=_refcnt_get)
def _size_get(self):
return _libkmod_h.kmod_module_get_size(self.module)
size = property(fget=_size_get)
def insert(self, flags=0, extra_options=None, install_callback=None,
data=None, print_action_callback=None):
cdef char *opt = NULL
#cdef _libkmod_h.install_callback_t install = NULL
cdef int (*install)(
_libkmod_h.kmod_module *, _libkmod_h.const_char_ptr, void *)
install = NULL
cdef void *d = NULL
#cdef _libkmod_h.print_action_callback_t print_action = NULL
cdef void (*print_action)(
_libkmod_h.kmod_module *, _libkmod_h.bool,
_libkmod_h.const_char_ptr)
print_action = NULL
if extra_options:
opt = extra_options
# TODO: convert callbacks and data from Python object to C types
err = _libkmod_h.kmod_module_probe_insert_module(
self.module, flags, opt, install, d, print_action)
if err == -_libkmod_h.EEXIST:
raise _KmodError('Module already loaded')
elif err < 0:
raise _KmodError('Could not load module')
def remove(self, flags=0):
err = _libkmod_h.kmod_module_remove_module(self.module, flags)
if err < 0:
raise _KmodError('Could not remove module')
|