diff --git a/README.md b/README.md index b197d7b9..d9e4287b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,16 @@ -# Ruby D-Bus +# Ruby D-Bus (with EventMachine support) + +## Note + +This fork works in the same way as [original Ruby D-Bus bindings](https://github.com/mvidner/ruby-dbus) +but it supports [EventMachine](http://rubyeventmachine.com). + +You can bind it to the EM by calling `#eventmachinize`: + + @connection = DBus::SessionBus.instance + @connection.eventmachinize + +## (Original README) [D-Bus](http://dbus.freedesktop.org) is an interprocess communication mechanism for Linux. @@ -48,7 +60,7 @@ via [UPower](http://upower.freedesktop.org/docs/UPower.html#UPower:OnBattery) ## Installation -- `gem install ruby-dbus` +- `gem install em-ruby-dbus` ## Features diff --git a/ruby-dbus.gemspec b/em-ruby-dbus.gemspec similarity index 69% rename from ruby-dbus.gemspec rename to em-ruby-dbus.gemspec index d19afd4a..7df8a625 100644 --- a/ruby-dbus.gemspec +++ b/em-ruby-dbus.gemspec @@ -3,16 +3,16 @@ require "rubygems" require "rake" GEMSPEC = Gem::Specification.new do |s| - s.name = "ruby-dbus" + s.name = "em-ruby-dbus" # s.rubyforge_project = nil - s.summary = "Ruby module for interaction with D-Bus" + s.summary = "Ruby module for interaction with D-Bus (with EventMachine support)" s.description = "Pure Ruby module for interaction with D-Bus IPC system" s.version = File.read("VERSION").strip s.license = "LGPL v2.1" s.author = "Ruby DBus Team" s.email = "ruby-dbus-devel@lists.luon.net" - s.homepage = "https://trac.luon.net/ruby-dbus" - s.files = FileList["{doc,examples,lib,test}/**/*", "COPYING", "NEWS", "Rakefile", "README.md", "ruby-dbus.gemspec", "VERSION"].to_a.sort + s.homepage = "https://github.com/saepia/em-ruby-dbus" + s.files = FileList["{doc,examples,lib,test}/**/*", "COPYING", "NEWS", "Rakefile", "README.md", "em-ruby-dbus.gemspec", "VERSION"].to_a.sort s.require_path = "lib" s.required_ruby_version = ">= 1.9.3" s.add_development_dependency("packaging_rake_tasks") diff --git a/lib/dbus/bus.rb b/lib/dbus/bus.rb index 4e0946af..6c3dc958 100644 --- a/lib/dbus/bus.rb +++ b/lib/dbus/bus.rb @@ -228,6 +228,14 @@ def glibize end end + + def eventmachinize + require File.join(File.dirname(File.expand_path(__FILE__)), "loop-em") + + conn = ::EventMachine.watch(@message_queue.socket, Loop::EventMachine::Reader, self) + conn.notify_readable = true + end + # FIXME: describe the following names, flags and constants. # See DBus spec for definition NAME_FLAG_ALLOW_REPLACEMENT = 0x1 diff --git a/lib/dbus/loop-em.rb b/lib/dbus/loop-em.rb new file mode 100644 index 00000000..223a0443 --- /dev/null +++ b/lib/dbus/loop-em.rb @@ -0,0 +1,19 @@ +require 'eventmachine' + +module DBus + module Loop + module EventMachine + class Reader < ::EventMachine::Connection + def initialize(parent) + @parent = parent + end + + def notify_readable + @parent.dispatch_message_queue + rescue EOFError + detach + end + end + end + end +end \ No newline at end of file