pangdudu-ruby-dbus 0.2.4.2 → 0.2.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/README.rdoc +4 -10
  2. data/lib/dbus/introspect.rb +69 -9
  3. data/lib/dbus.rb +1 -0
  4. metadata +11 -1
data/README.rdoc CHANGED
@@ -3,23 +3,17 @@
3
3
  Ruby D-Bus provides an implementation of the D-Bus protocol such that the
4
4
  D-Bus system can be used in the Ruby programming language.
5
5
 
6
+ You can switch between REXML and Hpricot as XML parsers!
6
7
 
7
- This is my personal dev-fork of mvidners upstream.
8
+ Still a little bumpy with multiple threads, but getting there.
8
9
 
9
- If you'd like to contrib to this fork, let me know.
10
10
 
11
+ This is my personal dev-fork of mvidners upstream.
11
12
 
13
+ If you'd like to contrib to this fork, let me know.
12
14
 
13
15
  Most of my work here is actually for another project: http://github.com/pangdudu/robots/tree/master
14
16
 
15
- I might also start writing a less ugly version of: http://github.com/pangdudu/ruby-dbus-daemon/tree/master
16
-
17
- If you know of a nice custom-dbus-daemon let me know. Still thinking about writing
18
- a dbus spec compliant server/daemon implementation in (pure) Ruby, so that I can
19
- play around with the network and authentification more easily.
20
-
21
- Oki, will clean up a little now. :)
22
-
23
17
  Peace.
24
18
 
25
19
  == Requirements
@@ -9,6 +9,7 @@ p# dbus/introspection.rb - module containing a low-level D-Bus introspection imp
9
9
  # See the file "COPYING" for the exact licensing terms.
10
10
 
11
11
  require 'rexml/document'
12
+ require 'hpricot'
12
13
 
13
14
  module DBus
14
15
  # Regular expressions that should match all method names.
@@ -199,21 +200,58 @@ module DBus
199
200
  # Creates a new parser for XML data in string _xml_.
200
201
  def initialize(xml)
201
202
  @xml = xml
203
+ @hpricot = true
202
204
  end
203
205
 
204
206
  # Recursively parses the subnodes, constructing the tree.
205
207
  def parse_subnodes
206
208
  subnodes = Array.new
207
209
  t = Time.now
208
- d = REXML::Document.new(@xml)
209
- d.elements.each("node/node") do |e|
210
- subnodes << e.attributes["name"]
210
+ if @hpricot
211
+ d = Hpricot.XML(@xml)
212
+ (d/"node/node").each { |e| subnodes << e.attributes['name'] }
213
+ return subnodes
214
+ end
215
+ unless @hpricot
216
+ d = REXML::Document.new(@xml)
217
+ d.elements.each("node/node") do |e|
218
+ subnodes << e.attributes["name"]
219
+ end
220
+ return subnodes
211
221
  end
212
- subnodes
213
222
  end
214
-
215
- # Parses the XML, constructing the tree.
223
+
224
+ #make it easy to switch
216
225
  def parse
226
+ parse_rexml unless @hpricot
227
+ parse_hpricot if @hpricot
228
+ end
229
+
230
+ # Parses the XML, constructing the tree, using hpricot
231
+ def parse_hpricot
232
+ ret = Array.new
233
+ subnodes = Array.new
234
+ d = Hpricot.XML(@xml)
235
+ (d/"node/node").each { |e| subnodes << e.attributes['name'] }
236
+ (d/"node/interface").each do |e|
237
+ i = Interface.new(e.attributes['name'])
238
+ (e/"method").each do |me|
239
+ m = Method.new(me.attributes['name'])
240
+ parse_methsig_hpricot(me, m)
241
+ i << m
242
+ end
243
+ (e/"signal").each do |se|
244
+ s = Signal.new(se.attributes['name'])
245
+ parse_methsig_hpricot(se, s)
246
+ i << s
247
+ end
248
+ ret << i
249
+ end
250
+ [ret, subnodes]
251
+ end
252
+
253
+ # Parses the XML, constructing the tree, using rexml
254
+ def parse_rexml
217
255
  ret = Array.new
218
256
  subnodes = Array.new
219
257
  t = Time.now
@@ -225,12 +263,12 @@ module DBus
225
263
  i = Interface.new(e.attributes["name"])
226
264
  e.elements.each("method") do |me|
227
265
  m = Method.new(me.attributes["name"])
228
- parse_methsig(me, m)
266
+ parse_methsig_rexml(me, m)
229
267
  i << m
230
268
  end
231
269
  e.elements.each("signal") do |se|
232
270
  s = Signal.new(se.attributes["name"])
233
- parse_methsig(se, s)
271
+ parse_methsig_rexml(se, s)
234
272
  i << s
235
273
  end
236
274
  ret << i
@@ -247,7 +285,29 @@ module DBus
247
285
 
248
286
  # Parses a method signature XML element _e_ and initialises
249
287
  # method/signal _m_.
250
- def parse_methsig(e, m)
288
+ def parse_methsig_hpricot(e, m)
289
+ (e/"arg").each do |ae|
290
+ name = ae.attributes['name']
291
+ dir = ae.attributes['direction']
292
+ sig = ae.attributes['type']
293
+ if m.is_a?(DBus::Signal)
294
+ m.add_param([name, sig])
295
+ elsif m.is_a?(DBus::Method)
296
+ case dir
297
+ when "in"
298
+ m.add_param([name, sig])
299
+ when "out"
300
+ m.add_return([name, sig])
301
+ end
302
+ else
303
+ raise NotImplementedError, dir
304
+ end
305
+ end
306
+ end
307
+
308
+ # Parses a method signature XML element _e_ and initialises
309
+ # method/signal _m_.
310
+ def parse_methsig_rexml(e, m)
251
311
  e.elements.each("arg") do |ae|
252
312
  name = ae.attributes["name"]
253
313
  dir = ae.attributes["direction"]
data/lib/dbus.rb CHANGED
@@ -9,6 +9,7 @@
9
9
  # See the file "COPYING" for the exact licensing terms.
10
10
  require 'rubygems'
11
11
  require 'rofl' #http://github.com/pangdudu/rofl/tree/master makes the debug/tracing easy
12
+ require 'hpricot' #hope this will speed stuff up a little
12
13
  require 'dbus/type'
13
14
  require 'dbus/introspect'
14
15
  require 'dbus/export'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pangdudu-ruby-dbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4.2
4
+ version: 0.2.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruby DBUS Team, pangdudu
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hpricot
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
25
35
  description: Ruby module for interaction with dbus, panda dev fork.
26
36
  email: pangdudu@github
27
37
  executables: []