Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added EventMachine support #52

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions ruby-dbus.gemspec → em-ruby-dbus.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
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")
Expand Down
8 changes: 8 additions & 0 deletions lib/dbus/bus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions lib/dbus/loop-em.rb
Original file line number Diff line number Diff line change
@@ -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