openplacos 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.4
@@ -16,7 +16,7 @@
16
16
 
17
17
  module Openplacos
18
18
  class Client # client for openplacos server
19
- attr_accessor :config, :objects, :service, :sensors, :actuators, :rooms, :reguls
19
+ attr_accessor :config, :objects, :service, :sensors, :actuators, :rooms, :reguls, :initial_room
20
20
 
21
21
  def initialize
22
22
  if(ENV['DEBUG_OPOS'] ) ## Stand for debug
@@ -27,10 +27,11 @@ module Openplacos
27
27
  if @bus.service("org.openplacos.server").exists?
28
28
  @service = @bus.service("org.openplacos.server")
29
29
  @service.introspect
30
- #@server_mutex = Mutex.new
31
30
  #discover all objects of server
32
- @objects = get_objects(@service.root)
33
- @rooms = get_rooms(@service.root)
31
+ @initial_room = Room.new(nil, "/")
32
+ @objects = get_objects(@service.root, @initial_room)
33
+ @rooms = @initial_room.tree
34
+
34
35
 
35
36
  #get sensors and actuators
36
37
  @sensors = get_sensors
@@ -44,27 +45,16 @@ module Openplacos
44
45
 
45
46
  end
46
47
 
47
- def get_rooms(nod)
48
- room = Array.new
49
- nod.each_pair{ |key,value|
50
- if not(key=="Debug" or key=="server" or key=="plugins") #ignore debug objects
51
- if value.object.nil?
52
- room.push(key)
53
- end
54
- end
55
- }
56
- room.uniq
57
- end
58
-
59
-
60
- def get_objects(nod) #get objects from a node, ignore Debug objects
48
+ def get_objects(nod, father_) #get objects from a node, ignore Debug objects
61
49
  obj = Hash.new
62
50
  nod.each_pair{ |key,value|
63
51
  if not(key=="Debug" or key=="server") #ignore debug objects
64
52
  if not value.object.nil?
65
- obj[value.object.path] = value.object
53
+ obj[value.object.path] = value.object
54
+ father_.push_object(value.object)
66
55
  else
67
- obj.merge!(get_objects(value))
56
+ children = father_.push_child(key)
57
+ obj.merge!(get_objects(value, children))
68
58
  end
69
59
  end
70
60
  }
@@ -91,6 +81,29 @@ module Openplacos
91
81
  sensors
92
82
  end
93
83
 
84
+ def is_regul(sensor)
85
+ # get dbus object of sensor
86
+ key = get_sensors.index(sensor)
87
+ if (key == nil)
88
+ return false
89
+ end
90
+
91
+ # Test interface
92
+ if (@objects[key].has_iface?('org.openplacos.server.regul'))
93
+ return true
94
+ else
95
+ return false
96
+ end
97
+ end
98
+
99
+ def get_regul_iface(sensor)
100
+ if (is_regul(sensor)==nil)
101
+ return nil
102
+ end
103
+ key = get_sensors.index(sensor)
104
+ return @objects[key]['org.openplacos.server.regul']
105
+ end
106
+
94
107
  def get_actuators
95
108
  actuators = Hash.new
96
109
  @objects.each_pair{ |key, value|
@@ -112,4 +125,35 @@ module Openplacos
112
125
  end
113
126
 
114
127
  end
128
+
129
+ class Room
130
+ attr_accessor :father, :childs, :path, :objects
131
+
132
+ def initialize(father_, path_)
133
+ @father = father_
134
+ @path = path_
135
+ @childs = Array.new
136
+ @objects = Hash.new
137
+ end
138
+
139
+ def push_child (value_)
140
+ children = Room.new(self, self.path + value_ + "/")
141
+ @childs << children
142
+ return children
143
+ end
144
+
145
+ def push_object(obj_)
146
+ @objects.store(obj_.path, obj_)
147
+ end
148
+
149
+ def tree()
150
+ hash = Hash.new
151
+ hash.store(@path, self)
152
+ @childs.each { |child|
153
+ hash.merge!(child.tree)
154
+ }
155
+ return hash
156
+ end
157
+
158
+ end
115
159
  end
@@ -17,7 +17,7 @@
17
17
  module Openplacos
18
18
 
19
19
  class Plugin
20
- attr_reader :name, :opos ,:main
20
+ attr_reader :name, :opos ,:main ,:config
21
21
  def initialize(name_)
22
22
  @server_ready_queue = Queue.new
23
23
  @name = name_
@@ -34,6 +34,8 @@ module Openplacos
34
34
  @opos.introspect
35
35
  @opos.default_iface = "org.openplacos.plugins"
36
36
 
37
+ @config = @opos.getConfig[0]
38
+
37
39
  @opos.on_signal("quit") do
38
40
  self.quit
39
41
  end
data/lib/openplacos.rb CHANGED
@@ -14,8 +14,7 @@
14
14
  # along with Openplacos. If not, see <http://www.gnu.org/licenses/>.
15
15
  #
16
16
  ENV["DBUS_THREADED_ACCESS"] = "1" #activate threaded dbus
17
- require 'rubygems'
18
- require 'dbus'
17
+ require 'dbus-openplacos'
19
18
  require 'openplacos/libplugin'
20
19
  require 'openplacos/libclient'
21
20
  require 'openplacos/libdriver'
data/openplacos.gemspec CHANGED
@@ -4,18 +4,18 @@ require "rake"
4
4
 
5
5
  GEMSPEC = Gem::Specification.new do |s|
6
6
  s.name = "openplacos"
7
- # s.rubyforge_project = nil
8
7
  s.summary = "Openplacos libraries : Libclient, LibPlugin, LibDriver"
9
8
  s.description = <<-EOF
10
9
  Openplacos Gem is a set of libraries for openplacos software.
11
10
  These libraries allow an easier coding of openplacos clients, plugins or drivers in ruby.
12
11
  EOF
13
12
  s.version = File.read("VERSION").strip
13
+ s.license = 'GPL-3'
14
14
  s.author = "Openplacos Team"
15
15
  s.email = "openplacos-general@lists.sourceforge.net"
16
16
  s.homepage = "http://openplacos.sourceforge.net/"
17
17
  s.files = FileList["{lib}/**/*", "openplacos.gemspec", "VERSION"].to_a.sort
18
18
  s.require_path = "lib"
19
19
  s.has_rdoc = false
20
- s.add_dependency('ruby-dbus', '>= 0.6.0')
20
+ s.add_dependency('ruby-dbus-openplacos', '>= 0.6.0')
21
21
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openplacos
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease:
4
+ hash: 23
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Openplacos Team
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-15 00:00:00 +01:00
18
+ date: 2011-02-26 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: ruby-dbus
22
+ name: ruby-dbus-openplacos
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
@@ -51,8 +51,8 @@ files:
51
51
  - openplacos.gemspec
52
52
  has_rdoc: true
53
53
  homepage: http://openplacos.sourceforge.net/
54
- licenses: []
55
-
54
+ licenses:
55
+ - GPL-3
56
56
  post_install_message:
57
57
  rdoc_options: []
58
58
 
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  requirements: []
80
80
 
81
81
  rubyforge_project:
82
- rubygems_version: 1.4.1
82
+ rubygems_version: 1.3.7
83
83
  signing_key:
84
84
  specification_version: 3
85
85
  summary: "Openplacos libraries : Libclient, LibPlugin, LibDriver"