libvirt_ffi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 54cfaffc6e2d9a5efb229e0c47cf0222fd99521ff5fa5ec0af12fdcffe338248
4
+ data.tar.gz: 46b545e97737a7c189a601939d211107a77adc92c197e163f6fa3066930b71a4
5
+ SHA512:
6
+ metadata.gz: e0f41521b95ae1c940b4da9bd2ebc229d86b220afc508b66bb74de8cdc7404a7078559d3f4d3a9fdae9cf30c67c402557e811b353d91fc34f6e4465aeb1eb3cd
7
+ data.tar.gz: 45e726be8f9049df8e87bfb768b60058bbd4dd3be55b1808e0a4a60fb9014188853d4af5f123de6baeded56006e371e863e11e7fe38b9ad3ef4643b27829d0b1
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ /Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.7
6
+ before_install: gem install bundler -v 2.1.4 --no-doc
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at senid231@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in libvirt.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 12.0'
7
+ gem 'minitest', '~> 5.0'
8
+
9
+ group :development do
10
+ gem 'async', '~> 1.24'
11
+ gem 'activesupport'
12
+ gem 'get_process_mem'
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Denis Talakevich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Libvirt
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/libvirt`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'libvirt'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install libvirt
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/libvirt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/libvirt/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Libvirt project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/libvirt/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'libvirt'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/libvirt ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'libvirt'
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'objspace'
4
+ require 'libvirt/ffi/connection'
5
+ require 'libvirt/ffi/domain'
6
+ require 'libvirt/util'
7
+
8
+ module Libvirt
9
+ class Connection
10
+ def initialize(uri)
11
+ @uri = uri
12
+ @conn_ptr = ::FFI::Pointer.new(0)
13
+ @cb_data = {}
14
+ ObjectSpace.define_finalizer(self, proc { |obj_id|
15
+ STDOUT.puts("finalized Libvirt::Connection #{obj_id.to_s(16)}")
16
+ })
17
+ end
18
+
19
+ def open
20
+ @conn_ptr = FFI::Connection.virConnectOpen(@uri)
21
+ raise Error, "Couldn't connect to #{@uri.inspect}" if @conn_ptr.null?
22
+ true
23
+ end
24
+
25
+ def opened?
26
+ !@conn_ptr.null?
27
+ end
28
+
29
+ def to_ptr
30
+ @conn_ptr
31
+ end
32
+
33
+ def version
34
+ check_open!
35
+
36
+ version_ptr = ::FFI::MemoryPointer.new(:ulong)
37
+ result = FFI::Connection.virConnectGetVersion(@conn_ptr, version_ptr)
38
+ raise Error, "Couldn't retrieve connection version" if result < 0
39
+ version_number = version_ptr.get_ulong(0)
40
+ Libvirt::Util::parse_version(version_number)
41
+ end
42
+
43
+ def set_keep_alive(interval, count)
44
+ result = FFI::Connection.virConnectSetKeepAlive(@conn_ptr, interval, count)
45
+ raise Error, "Couldn't set connection keep_alive" if result < 0
46
+ result == 0
47
+ end
48
+
49
+ def to_s
50
+ "#<#{self.class}:0x#{object_id.to_s(16)} @uri=#{@uri.inspect} @conn_ptr=0x#{@conn_ptr.address.to_s(16)}>"
51
+ end
52
+
53
+ def inspect
54
+ to_s
55
+ end
56
+
57
+ def list_all_domains_qty(flags = 0)
58
+ result = FFI::Domain.virConnectListAllDomains(@conn_ptr, nil, flags)
59
+ raise Error, "Couldn't retrieve domains qty with flags #{flags.to_s(16)}" if result < 0
60
+ result
61
+ end
62
+
63
+ def list_all_domains(flags = 0)
64
+ size = list_all_domains_qty(flags)
65
+ domains_ptr = ::FFI::MemoryPointer.new(:pointer, size)
66
+ result = FFI::Domain.virConnectListAllDomains(@conn_ptr, domains_ptr, flags)
67
+ raise Error, "Couldn't retrieve domains list with flags #{flags.to_s(16)}" if result < 0
68
+ ptr = domains_ptr.read_pointer
69
+ ptr.get_array_of_pointer(0, size).map { |dom_ptr| Libvirt::Domain.new(dom_ptr, self) }
70
+ end
71
+
72
+ # @yield conn, dom
73
+ def register_domain_event_callback(event_id, domain = nil, opaque = nil, &block)
74
+ if event_id == Libvirt::DOMAIN_EVENT_ID_LIFECYCLE
75
+ cb = FFI::Domain::domain_event_id_lifecycle_callback(&block)
76
+ else
77
+ raise Error, "not supported event_id #{event_id.inspect}"
78
+ end
79
+
80
+ result = FFI::Domain.virConnectDomainEventRegisterAny(
81
+ @conn_ptr,
82
+ domain&.to_ptr,
83
+ event_id,
84
+ cb,
85
+ opaque&.to_ptr,
86
+ nil # free_opaque
87
+ )
88
+ raise Error, "Couldn't register domain event callback" if result < 0
89
+
90
+ @cb_data[result] = { event_id: event_id, cb: cb, opaque: opaque }
91
+ result
92
+ end
93
+
94
+ def deregister_domain_event_callback(callback_id)
95
+ @cb_data.delete(callback_id)
96
+ result = FFI::Domain.virConnectDomainEventDeregisterAny(@conn_ptr, callback_id)
97
+ raise Error, "Couldn't deregister domain event callback" if result < 0
98
+ true
99
+ end
100
+
101
+ private
102
+
103
+ def check_open!
104
+ raise Error, "Connection to #{@uri.inspect} is not open" if @conn_ptr.null?
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'objspace'
4
+ require 'libvirt/ffi/domain'
5
+ require 'libvirt/util'
6
+
7
+ module Libvirt
8
+ class Domain
9
+ def initialize(dom_ptr, conn)
10
+ @dom_ptr = dom_ptr
11
+ @conn = conn
12
+ ObjectSpace.define_finalizer(self, proc { |obj_id|
13
+ STDOUT.puts("finalized Libvirt::Domain #{obj_id.to_s(16)}")
14
+ })
15
+ end
16
+
17
+ def get_state
18
+ state = ::FFI::MemoryPointer.new(:int)
19
+ reason = ::FFI::MemoryPointer.new(:int)
20
+ result = FFI::Domain.virDomainGetState(@dom_ptr, state, reason, 0)
21
+ raise Error, "Couldn't get domain state" if result < 0
22
+ [state.read_int, reason.read_int]
23
+ end
24
+
25
+ def to_ptr
26
+ @dom_ptr
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Libvirt
4
+ class Error < StandardError
5
+ end
6
+ end
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+ require 'forwardable'
5
+ require 'libvirt/ffi/event'
6
+
7
+ module Libvirt
8
+ class Event
9
+ include Singleton
10
+ extend Forwardable
11
+ extend SingleForwardable
12
+
13
+ single_delegate [:register, :unregister, :registered?] => :instance
14
+
15
+ Opaque = Struct.new(:cb, :opaque, :ff)
16
+
17
+ class << self
18
+ def invoke_handle_callback(watch, fd, events, opaque)
19
+ cb = opaque.cb
20
+ op = opaque.opaque
21
+ Util.log(:debug) { "Libvirt::Event INVOKE_HANDLE_CALLBACK watch=#{watch} fd=#{fd} events=#{events} op=#{op}" }
22
+ cb.call(watch, fd, events, op)
23
+ end
24
+
25
+ def invoke_timeout_callback(timer, opaque)
26
+ cb = opaque.cb
27
+ op = opaque.opaque
28
+ Util.log(:debug) { "Libvirt::Event INVOKE_TIMEOUT_CALLBACK timer=#{timer} op=#{op}" }
29
+ cb.call(timer, op)
30
+ end
31
+ end
32
+
33
+ def registered?
34
+ @registered || false
35
+ end
36
+
37
+ def unregister
38
+ @add_handle_cb = nil
39
+ @update_handle_cb = nil
40
+ @remove_handle_cb = nil
41
+ @add_timer_cb = nil
42
+ @update_timer_cb = nil
43
+ @remove_timer_cb = nil
44
+ @add_handle = nil
45
+ @update_handle = nil
46
+ @remove_handle = nil
47
+ @add_timer = nil
48
+ @update_timer = nil
49
+ @remove_timer = nil
50
+
51
+ @registered = false
52
+ true
53
+ end
54
+
55
+ def register(add_handle:, update_handle:, remove_handle:, add_timer:, update_timer:, remove_timer:)
56
+ @add_handle = add_handle
57
+ @update_handle = update_handle
58
+ @remove_handle = remove_handle
59
+ @add_timer = add_timer
60
+ @update_timer = update_timer
61
+ @remove_timer = remove_timer
62
+
63
+ @add_handle_cb = FFI::Event.event_add_handle_func(&method(:_add_handle).to_proc)
64
+ @update_handle_cb = ::FFI::Function.new(:void, [:int, :int], &method(:_update_handle).to_proc)
65
+ @remove_handle_cb = ::FFI::Function.new(:int, [:int], &method(:_remove_handle).to_proc)
66
+ @add_timer_cb = FFI::Event.event_add_timeout_func(&method(:_add_timer).to_proc)
67
+ @update_timer_cb = ::FFI::Function.new(:void, [:int, :int], &method(:_update_timer).to_proc)
68
+ @remove_timer_cb = ::FFI::Function.new(:int, [:int], &method(:_remove_timer).to_proc)
69
+
70
+ FFI::Event.virEventRegisterImpl(
71
+ @add_handle_cb,
72
+ @update_handle_cb,
73
+ @remove_handle_cb,
74
+ @add_timer_cb,
75
+ @update_timer_cb,
76
+ @remove_timer_cb
77
+ )
78
+ @registered = true
79
+ end
80
+
81
+ private
82
+
83
+ def _add_handle(fd, event, cb, opaque, ff)
84
+ Util.log(:debug) { "Libvirt::Event ADD_HANDLE fd=#{fd}, #{event}=event, cb=#{cb}, opaque=#{opaque}, ff=#{ff}" }
85
+ op = Opaque.new(cb, opaque, ff)
86
+ @add_handle.call(fd, event, op)
87
+ end
88
+
89
+ def _update_handle(watch, event)
90
+ Util.log(:debug) { "Libvirt::Event UPDATE_HANDLE watch=#{watch}, event=#{event}" }
91
+ @update_handle.call(watch, event)
92
+ end
93
+
94
+ def _remove_handle(watch)
95
+ Util.log(:debug) { "Libvirt::Event REMOVE_HANDLE watch=#{watch}" }
96
+ op = @remove_handle.call(watch)
97
+ free_func = op.ff
98
+ opaque = op.opaque
99
+ free_func.call(opaque) unless free_func.null?
100
+ 0
101
+ end
102
+
103
+ def _add_timer(timeout, cb, opaque, ff)
104
+ Util.log(:debug) { "Libvirt::Event ADD_TIMER timeout=#{timeout}, cb=#{cb}, opaque=#{opaque}, ff=#{ff}" }
105
+ op = Opaque.new(cb, opaque, ff)
106
+ @add_timer.call(timeout, op)
107
+ end
108
+
109
+ def _update_timer(timer, timeout)
110
+ Util.log(:debug) { "Libvirt::Event UPDATE_TIMER timer=#{timer}, timeout=#{timeout}" }
111
+ @update_timer.call(timer, timeout)
112
+ end
113
+
114
+ def _remove_timer(timer)
115
+ Util.log(:debug) { "Libvirt::Event REMOVE_TIMER timer=#{timer}" }
116
+ op = @remove_timer.call(timer)
117
+ free_func = op.ff
118
+ opaque = op.opaque
119
+ free_func.call(opaque) unless free_func.null?
120
+ 0
121
+ end
122
+
123
+ end
124
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Libvirt
4
+ module FFI
5
+ module Common
6
+ extend ::FFI::Library
7
+ ffi_lib Util.library_path
8
+
9
+ # typedef void (*virFreeCallback) (
10
+ # void * opaque
11
+ # )
12
+ FREE_CALLBACK = callback :virFreeCallback, [:pointer], :void
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ffi'
4
+ require 'libvirt/util'
5
+
6
+ module Libvirt
7
+ module FFI
8
+ module Connection
9
+ extend ::FFI::Library
10
+ ffi_lib Util.library_path
11
+
12
+ # virConnectPtr virConnectOpen (const char * name)
13
+ attach_function :virConnectOpen, [:string], :pointer
14
+
15
+ # int virConnectGetVersion (virConnectPtr conn, unsigned long *hvVer)
16
+ attach_function :virConnectGetVersion, [:pointer, :pointer], :int
17
+
18
+ # int virConnectSetKeepAlive (
19
+ # virConnectPtr conn,
20
+ # int interval,
21
+ # unsigned int count
22
+ # )
23
+ attach_function :virConnectSetKeepAlive, [:pointer, :int, :uint], :int
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ffi'
4
+ require 'libvirt/util'
5
+ require 'libvirt/ffi/common'
6
+
7
+ module Libvirt
8
+ module FFI
9
+ module Domain
10
+ extend ::FFI::Library
11
+ ffi_lib Util.library_path
12
+
13
+ # int virConnectDomainEventRegisterAny(
14
+ # virConnectPtr conn,
15
+ # virDomainPtr dom,
16
+ # int eventID,
17
+ # virConnectDomainEventGenericCallback cb,
18
+ # void * opaque,
19
+ # virFreeCallback freecb
20
+ # )
21
+ attach_function :virConnectDomainEventRegisterAny, [
22
+ :pointer,
23
+ :pointer,
24
+ :int,
25
+ :pointer,
26
+ :pointer,
27
+ :pointer
28
+ ], :int
29
+
30
+ # int virConnectListAllDomains (
31
+ # virConnectPtr conn,
32
+ # virDomainPtr **domains,
33
+ # unsigned int flags
34
+ # )
35
+ attach_function :virConnectListAllDomains, [:pointer, :pointer, :uint], :int
36
+
37
+ # enum virDomainState {
38
+ # VIR_DOMAIN_NOSTATE = 0 (0x0)
39
+ # no state
40
+ # VIR_DOMAIN_RUNNING = 1 (0x1)
41
+ # the domain is running
42
+ # VIR_DOMAIN_BLOCKED = 2 (0x2)
43
+ # the domain is blocked on resource
44
+ # VIR_DOMAIN_PAUSED = 3 (0x3)
45
+ # the domain is paused by user
46
+ # VIR_DOMAIN_SHUTDOWN = 4 (0x4)
47
+ # the domain is being shut down
48
+ # VIR_DOMAIN_SHUTOFF = 5 (0x5)
49
+ # the domain is shut off
50
+ # VIR_DOMAIN_CRASHED = 6 (0x6)
51
+ # the domain is crashed
52
+ # VIR_DOMAIN_PMSUSPENDED = 7 (0x7)
53
+ # the domain is suspended by guest power management
54
+ # VIR_DOMAIN_LAST = 8 (0x8)
55
+ # NB: this enum value will increase over time as new events are added to the libvirt API.
56
+ # It reflects the last state supported by this version of the libvirt API.
57
+ # }
58
+ enum :states, [
59
+ :no_state, 0x0,
60
+ :running, 0x1,
61
+ :blocked, 0x2,
62
+ :paused, 0x3,
63
+ :shutdown, 0x4,
64
+ :shutoff, 0x5,
65
+ :crashed, 0x6,
66
+ :pm_suspended, 0x7,
67
+ :last, 0x8
68
+ ]
69
+
70
+ # int virDomainGetState (
71
+ # virDomainPtr domain,
72
+ # int *state,
73
+ # int *reason,
74
+ # unsigned int flags
75
+ # )
76
+ attach_function :virDomainGetState, [:pointer, :pointer, :pointer, :uint], :int
77
+
78
+ # typedef int (*virConnectDomainEventCallback) (
79
+ # virConnectPtr conn,
80
+ # virDomainPtr dom,
81
+ # int event,
82
+ # int detail,
83
+ # void * opaque
84
+ # )
85
+ def self.domain_event_id_lifecycle_callback(&block)
86
+ ::FFI::Function.new(:int, [:pointer, :pointer, :int, :int]) do |_conn, dom, event, detail, op|
87
+ Util.log(:debug) { "DOMAIN_EVENT_CALLBACK LIFECYCLE dom=#{dom}, event=#{event}, detail=#{detail}, op=#{op}" }
88
+ block.call(dom, event, detail, op)
89
+ 0
90
+ end
91
+ end
92
+
93
+ end
94
+ end
95
+ end