libvirt_ffi 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/libvirt/connection.rb +6 -2
- data/lib/libvirt/domain.rb +8 -0
- data/lib/libvirt/domain_callback_storage.rb +11 -5
- data/lib/libvirt/event.rb +9 -11
- data/lib/libvirt/stream.rb +12 -0
- data/lib/libvirt/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3644f17ca84d47cdb1137cc70206ba1f21e6ff9134cfce63a3e285699da7f209
|
4
|
+
data.tar.gz: 0ed561ac6371b32ec98b1ff0f4ff8baee4896781eeee7e21ac0af83aeb71e5f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 230412ae8c751eda2e21459f86c5fd82588c9e4288061fa5137166f92cc82b41045f66a5d643917a6cca0015b61820084e179318ba2730f3f5fefdee985f1923
|
7
|
+
data.tar.gz: d47c4efedea90cf797e212603da0304250f3a09360e7cde73c7509dd044d91ee36be52ec5f2a86622701e744d85416d8c231c325b0435078c22d2524f9d57688
|
data/lib/libvirt/connection.rb
CHANGED
@@ -96,7 +96,7 @@ module Libvirt
|
|
96
96
|
|
97
97
|
# @yield conn, dom, *args
|
98
98
|
def register_domain_event_callback(event_id, domain = nil, opaque = nil, &block)
|
99
|
-
|
99
|
+
dbg { "#register_domain_event_callback event_id=#{event_id}" }
|
100
100
|
|
101
101
|
enum = FFI::Domain.enum_type(:event_id)
|
102
102
|
event_id, event_id_sym = Util.parse_enum(enum, event_id)
|
@@ -128,7 +128,7 @@ module Libvirt
|
|
128
128
|
end
|
129
129
|
|
130
130
|
def deregister_domain_event_callback(callback_id)
|
131
|
-
|
131
|
+
dbg { "#deregister_domain_event_callback callback_id=#{callback_id}" }
|
132
132
|
|
133
133
|
result = FFI::Domain.virConnectDomainEventDeregisterAny(@conn_ptr, callback_id)
|
134
134
|
raise Error, "Couldn't deregister domain event callback" if result < 0
|
@@ -179,5 +179,9 @@ module Libvirt
|
|
179
179
|
def check_open!
|
180
180
|
raise Error, "Connection to #{@uri.inspect} is not open" if @conn_ptr.null?
|
181
181
|
end
|
182
|
+
|
183
|
+
def dbg(&block)
|
184
|
+
Util.log(:debug, 'Libvirt::Connection', &block)
|
185
|
+
end
|
182
186
|
end
|
183
187
|
end
|
data/lib/libvirt/domain.rb
CHANGED
@@ -68,6 +68,8 @@ module Libvirt
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def screenshot(stream, display = 0)
|
71
|
+
dbg { "#screenshot stream=#{stream}, display=#{display}," }
|
72
|
+
|
71
73
|
mime_type, pointer = FFI::Domain.virDomainScreenshot(@dom_ptr, stream.to_ptr, display, 0)
|
72
74
|
raise Error, "Couldn't attach domain screenshot" if pointer.null?
|
73
75
|
# free pointer required
|
@@ -79,5 +81,11 @@ module Libvirt
|
|
79
81
|
raise Error, "Couldn't free domain" if result < 0
|
80
82
|
@dom_ptr = nil
|
81
83
|
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def dbg(&block)
|
88
|
+
Util.log(:debug, 'Libvirt::Domain', &block)
|
89
|
+
end
|
82
90
|
end
|
83
91
|
end
|
@@ -14,19 +14,19 @@ module Libvirt
|
|
14
14
|
# cb_data [Libvirt::DomainCallbackStorage::CallbackDataStruct],
|
15
15
|
# cb_data_free_func [FFI::Function]
|
16
16
|
def allocate_struct
|
17
|
-
|
17
|
+
dbg { "#allocate_struct" }
|
18
18
|
|
19
19
|
cb_data_ptr = ::FFI::MemoryPointer.new(:char, CallbackDataStruct.size, false)
|
20
20
|
cb_data = CallbackDataStruct.new(cb_data_ptr)
|
21
21
|
cb_data_free_func = ::FFI::Function.new(:void, [:pointer]) do |pointer|
|
22
|
-
|
22
|
+
dbg { "Libvirt::DomainCallbackStorage cb_data_free_func triggered" }
|
23
23
|
remove_struct(pointer: pointer)
|
24
24
|
end
|
25
25
|
[cb_data, cb_data_free_func]
|
26
26
|
end
|
27
27
|
|
28
28
|
def store_struct(cb_data, connection_pointer:, callback_id:, cb:, opaque:)
|
29
|
-
|
29
|
+
dbg { "#store_struct" }
|
30
30
|
|
31
31
|
cb_data[:connection_pointer] = connection_pointer
|
32
32
|
cb_data[:callback_id] = callback_id
|
@@ -34,7 +34,7 @@ module Libvirt
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def remove_struct(pointer: nil, connection_pointer: nil, callback_id: nil)
|
37
|
-
|
37
|
+
dbg { "#remove_struct pointer=#{pointer}, connection_pointer=#{connection_pointer}, callback_id=#{callback_id}," }
|
38
38
|
|
39
39
|
if pointer
|
40
40
|
cb_data_struct = CallbackDataStruct.new(pointer)
|
@@ -53,7 +53,7 @@ module Libvirt
|
|
53
53
|
# @param [::FFI::Pointer]
|
54
54
|
# @return [Array<2>] cb [Proc], opaque [Object]
|
55
55
|
def retrieve_from_pointer(pointer)
|
56
|
-
|
56
|
+
dbg { "#retrieve_from_pointer pointer=#{pointer}," }
|
57
57
|
|
58
58
|
cb_data_struct = CallbackDataStruct.new(pointer)
|
59
59
|
connection_pointer = cb_data_struct[:connection_pointer]
|
@@ -61,5 +61,11 @@ module Libvirt
|
|
61
61
|
cb_data = @inner_storage[connection_pointer.address][callback_id]
|
62
62
|
[cb_data[:cb], cb_data[:opaque]]
|
63
63
|
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def dbg(&block)
|
68
|
+
Util.log(:debug, 'Libvirt::DomainCallbackStorage', &block)
|
69
|
+
end
|
64
70
|
end
|
65
71
|
end
|
data/lib/libvirt/event.rb
CHANGED
@@ -26,14 +26,14 @@ module Libvirt
|
|
26
26
|
def invoke_handle_callback(watch, fd, events, opaque)
|
27
27
|
cb = opaque.cb
|
28
28
|
op = opaque.opaque
|
29
|
-
dbg { "
|
29
|
+
dbg { "INVOKE_HANDLE_CALLBACK watch=#{watch} fd=#{fd} events=#{events} op=#{op}" }
|
30
30
|
cb.call(watch, fd, events, op)
|
31
31
|
end
|
32
32
|
|
33
33
|
def invoke_timeout_callback(timer, opaque)
|
34
34
|
cb = opaque.cb
|
35
35
|
op = opaque.opaque
|
36
|
-
dbg { "
|
36
|
+
dbg { "INVOKE_TIMEOUT_CALLBACK timer=#{timer} op=#{op}" }
|
37
37
|
cb.call(timer, op)
|
38
38
|
end
|
39
39
|
|
@@ -88,18 +88,18 @@ module Libvirt
|
|
88
88
|
private
|
89
89
|
|
90
90
|
def _add_handle(fd, event, cb, opaque, ff)
|
91
|
-
dbg { "
|
91
|
+
dbg { "ADD_HANDLE fd=#{fd}, #{event}=event, cb=#{cb}, opaque=#{opaque}, ff=#{ff}" }
|
92
92
|
op = Opaque.new(cb, opaque, ff)
|
93
93
|
@add_handle.call(fd, event, op)
|
94
94
|
end
|
95
95
|
|
96
96
|
def _update_handle(watch, event)
|
97
|
-
dbg { "
|
97
|
+
dbg { "UPDATE_HANDLE watch=#{watch}, event=#{event}" }
|
98
98
|
@update_handle.call(watch, event)
|
99
99
|
end
|
100
100
|
|
101
101
|
def _remove_handle(watch)
|
102
|
-
dbg { "
|
102
|
+
dbg { "REMOVE_HANDLE watch=#{watch}" }
|
103
103
|
op = @remove_handle.call(watch)
|
104
104
|
free_func = op.ff
|
105
105
|
opaque = op.opaque
|
@@ -108,18 +108,18 @@ module Libvirt
|
|
108
108
|
end
|
109
109
|
|
110
110
|
def _add_timer(timeout, cb, opaque, ff)
|
111
|
-
dbg { "
|
111
|
+
dbg { "ADD_TIMER timeout=#{timeout}, cb=#{cb}, opaque=#{opaque}, ff=#{ff}" }
|
112
112
|
op = Opaque.new(cb, opaque, ff)
|
113
113
|
@add_timer.call(timeout, op)
|
114
114
|
end
|
115
115
|
|
116
116
|
def _update_timer(timer, timeout)
|
117
|
-
dbg { "
|
117
|
+
dbg { "UPDATE_TIMER timer=#{timer}, timeout=#{timeout}" }
|
118
118
|
@update_timer.call(timer, timeout)
|
119
119
|
end
|
120
120
|
|
121
121
|
def _remove_timer(timer)
|
122
|
-
dbg { "
|
122
|
+
dbg { "REMOVE_TIMER timer=#{timer}" }
|
123
123
|
op = @remove_timer.call(timer)
|
124
124
|
free_func = op.ff
|
125
125
|
opaque = op.opaque
|
@@ -128,9 +128,7 @@ module Libvirt
|
|
128
128
|
end
|
129
129
|
|
130
130
|
def dbg(&block)
|
131
|
-
|
132
|
-
|
133
|
-
Util.log(:debug, &block)
|
131
|
+
Util.log(:debug, 'Libvirt::Event', &block)
|
134
132
|
end
|
135
133
|
|
136
134
|
end
|
data/lib/libvirt/stream.rb
CHANGED
@@ -33,6 +33,8 @@ module Libvirt
|
|
33
33
|
# @param opaque [Object]
|
34
34
|
# @yield [Stream]
|
35
35
|
def event_add_callback(events, opaque, &block)
|
36
|
+
dbg { "#event_add_callback events=#{events}, opaque=#{opaque}" }
|
37
|
+
|
36
38
|
raise Error, 'callback already added' unless @cb.nil?
|
37
39
|
|
38
40
|
@opaque = opaque
|
@@ -49,12 +51,16 @@ module Libvirt
|
|
49
51
|
|
50
52
|
# @param events [Integer] bit OR of EVENT_READABLE, EVENT_READABLE
|
51
53
|
def event_update_callback(events)
|
54
|
+
dbg { "#event_update_callback events=#{events}" }
|
55
|
+
|
52
56
|
result = FFI::Stream.virStreamEventUpdateCallback(@stream_ptr, events)
|
53
57
|
raise Error, "Couldn't remove stream event callback" if result < 0
|
54
58
|
true
|
55
59
|
end
|
56
60
|
|
57
61
|
def event_remove_callback
|
62
|
+
dbg { '#event_remove_callback' }
|
63
|
+
|
58
64
|
result = FFI::Stream.virStreamEventRemoveCallback(@stream_ptr)
|
59
65
|
raise Error, "Couldn't remove stream event callback" if result < 0
|
60
66
|
opaque = @opaque
|
@@ -101,5 +107,11 @@ module Libvirt
|
|
101
107
|
raise Error, "Invalid response from virStreamRecv #{result.inspect}"
|
102
108
|
end
|
103
109
|
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def dbg(&block)
|
114
|
+
Util.log(:debug, 'Libvirt::Stream', &block)
|
115
|
+
end
|
104
116
|
end
|
105
117
|
end
|
data/lib/libvirt/version.rb
CHANGED