openplacos 0.0.1
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.
- data/VERSION +1 -0
- data/lib/openplacos/libclient.rb +104 -0
- data/lib/openplacos/libdriver.rb +123 -0
- data/lib/openplacos/libplugin.rb +72 -0
- data/lib/openplacos.rb +21 -0
- data/openplacos.gemspec +21 -0
- metadata +87 -0
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# This file is part of Openplacos.
|
2
|
+
#
|
3
|
+
# Openplacos is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# Openplacos is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Openplacos. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
|
17
|
+
module Openplacos
|
18
|
+
class Client # client for openplacos server
|
19
|
+
attr_accessor :config, :objects, :service, :sensors, :actuators, :rooms
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
|
23
|
+
if(ENV['DEBUG_OPOS'] ) ## Stand for debug
|
24
|
+
@bus = DBus::session_bus
|
25
|
+
else
|
26
|
+
@bus = DBus::system_bus
|
27
|
+
end
|
28
|
+
if @bus.service("org.openplacos.server").exists?
|
29
|
+
@service = @bus.service("org.openplacos.server")
|
30
|
+
@service.introspect
|
31
|
+
#@server_mutex = Mutex.new
|
32
|
+
#discover all objects of server
|
33
|
+
@objects = get_objects(@service.root)
|
34
|
+
@rooms = get_rooms(@service.root)
|
35
|
+
|
36
|
+
#get sensors and actuators
|
37
|
+
@sensors = get_sensors
|
38
|
+
@actuators = get_actuators
|
39
|
+
else
|
40
|
+
puts "Can't find OpenplacOS server"
|
41
|
+
Process.exit 1
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_rooms(nod)
|
48
|
+
room = Array.new
|
49
|
+
nod.each_pair{ |key,value|
|
50
|
+
if not(key=="Debug" or key=="server") #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
|
61
|
+
obj = Hash.new
|
62
|
+
nod.each_pair{ |key,value|
|
63
|
+
if not(key=="Debug" or key=="server") #ignore debug objects
|
64
|
+
if not value.object.nil?
|
65
|
+
obj[value.object.path] = value.object
|
66
|
+
else
|
67
|
+
obj.merge!(get_objects(value))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
}
|
71
|
+
obj
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_config_from_objects(objects) #contact config methods for all objects
|
75
|
+
cfg = Hash.new
|
76
|
+
objects.each_pair{ |key, obj|
|
77
|
+
if not(obj["org.openplacos.server.config"]==nil)
|
78
|
+
cfg[key] = obj["org.openplacos.server.config"].getConfig[0]
|
79
|
+
end
|
80
|
+
}
|
81
|
+
cfg
|
82
|
+
end
|
83
|
+
|
84
|
+
def get_sensors
|
85
|
+
sensors = Hash.new
|
86
|
+
@objects.each_pair{ |key, value|
|
87
|
+
if value.has_iface?('org.openplacos.server.measure')
|
88
|
+
sensors[key] = value['org.openplacos.server.measure']
|
89
|
+
end
|
90
|
+
}
|
91
|
+
sensors
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_actuators
|
95
|
+
actuators = Hash.new
|
96
|
+
@objects.each_pair{ |key, value|
|
97
|
+
if value.has_iface?('org.openplacos.server.actuator')
|
98
|
+
actuators[key] = value['org.openplacos.server.actuator']
|
99
|
+
end
|
100
|
+
}
|
101
|
+
actuators
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# This file is part of Openplacos.
|
2
|
+
#
|
3
|
+
# Openplacos is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# Openplacos is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Openplacos. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
#
|
16
|
+
module Openplacos
|
17
|
+
module Driver
|
18
|
+
|
19
|
+
class GenericPin < DBus::Object
|
20
|
+
|
21
|
+
def set_off(iface_req_)
|
22
|
+
if (@init != iface_req_) # Iface changed, turn off previous one
|
23
|
+
if(self.methods.include?("exit_"+@init))
|
24
|
+
eval("exit_"+@init+"()")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def write(iface_, value_, option_)
|
31
|
+
|
32
|
+
set_off(iface_)
|
33
|
+
if (@input == 1)# Set output
|
34
|
+
if(self.methods.include?("set_output"))
|
35
|
+
self.set_output()
|
36
|
+
end
|
37
|
+
@input = 0;
|
38
|
+
end
|
39
|
+
|
40
|
+
if (@init != iface_) # If the iface needs to be init
|
41
|
+
if(self.methods.include?("init_"+iface_))
|
42
|
+
eval("init_#{iface_}()")
|
43
|
+
end
|
44
|
+
@init = iface_
|
45
|
+
end
|
46
|
+
eval("write_#{iface_}(value_, option_)")
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_write(iface_)
|
51
|
+
dbusdef = "dbus_interface 'org.openplacos.driver.#{iface_}' do
|
52
|
+
dbus_method :write, 'out return:v, in value:v, in option:a{sv}' do |value, option|
|
53
|
+
return self.write( \"#{iface_}\", value,option)
|
54
|
+
end
|
55
|
+
end"
|
56
|
+
|
57
|
+
self.singleton_class.instance_eval(dbusdef)
|
58
|
+
end
|
59
|
+
|
60
|
+
def read(iface_, option_)
|
61
|
+
set_off(iface_)
|
62
|
+
if (@input == 0)# Set input
|
63
|
+
if(self.methods.include?("set_input"))
|
64
|
+
self.set_input()
|
65
|
+
end
|
66
|
+
@input = 1;
|
67
|
+
end
|
68
|
+
|
69
|
+
eval("read_#{iface_}( option_)")
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
def add_read(iface_)
|
75
|
+
dbusdef = "dbus_interface 'org.openplacos.driver.#{iface_}' do
|
76
|
+
dbus_method :read, 'out return:v, in option:a{sv}' do |option|
|
77
|
+
return self.read(\"#{iface_}\", option)
|
78
|
+
end
|
79
|
+
end"
|
80
|
+
self.singleton_class.instance_eval(dbusdef)
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_read_and_write(iface_) # dbus do not merge methods in interface if they are not define in the same time
|
84
|
+
dbusdef = "dbus_interface 'org.openplacos.driver.#{iface_}' do
|
85
|
+
dbus_method :read, 'out return:v, in option:a{sv}' do |option|
|
86
|
+
return self.read(\"#{iface_}\",option)
|
87
|
+
end
|
88
|
+
dbus_method :write, 'out return:v, in value:v, in option:a{sv}' do |value, option|
|
89
|
+
return self.write(\"#{iface_}\", value,option)
|
90
|
+
end
|
91
|
+
end"
|
92
|
+
|
93
|
+
self.singleton_class.instance_eval(dbusdef)
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
def initialize(path_, write_intfs_, read_intfs_) # path name , an array of string of interface wich write methods, an array of
|
98
|
+
@init = ""
|
99
|
+
|
100
|
+
(write_intfs_ & read_intfs_).each { |iface|
|
101
|
+
self.add_read_and_write(iface)
|
102
|
+
self.instance_eval("self.extend(Module_write_#{iface})")
|
103
|
+
self.instance_eval("self.extend(Module_read_#{iface})")
|
104
|
+
write_intfs_.delete(iface)
|
105
|
+
read_intfs_.delete(iface)
|
106
|
+
}
|
107
|
+
|
108
|
+
write_intfs_.each{ |iface|
|
109
|
+
self.add_write(iface)
|
110
|
+
self.instance_eval("self.extend(Module_write_#{iface})")
|
111
|
+
}
|
112
|
+
|
113
|
+
read_intfs_.each{ |iface|
|
114
|
+
self.add_read(iface)
|
115
|
+
self.instance_eval("self.extend(Module_read_#{iface})")
|
116
|
+
}
|
117
|
+
super(path_)
|
118
|
+
self.extend(Other_common_fonctions)
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# This file is part of Openplacos.
|
2
|
+
#
|
3
|
+
# Openplacos is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# Openplacos is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Openplacos. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
|
17
|
+
module Openplacos
|
18
|
+
|
19
|
+
class Plugin
|
20
|
+
attr_reader :name, :opos ,:main
|
21
|
+
def initialize(name_)
|
22
|
+
@server_ready_queue = Queue.new
|
23
|
+
@name = name_
|
24
|
+
#DBus
|
25
|
+
if(ENV['DEBUG_OPOS'] ) ## Stand for debug
|
26
|
+
@clientbus = DBus::SessionBus.instance
|
27
|
+
else
|
28
|
+
@clientbus = DBus::SystemBus.instance
|
29
|
+
end
|
30
|
+
|
31
|
+
server = @clientbus.service("org.openplacos.server")
|
32
|
+
|
33
|
+
@opos = server.object("/plugins")
|
34
|
+
@opos.introspect
|
35
|
+
@opos.default_iface = "org.openplacos.plugins"
|
36
|
+
|
37
|
+
@opos.on_signal("quit") do
|
38
|
+
self.quit
|
39
|
+
end
|
40
|
+
|
41
|
+
@opos.on_signal("ready") do
|
42
|
+
@server_ready_queue.push "Go"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def run
|
48
|
+
@main = DBus::Main.new
|
49
|
+
@main << @clientbus
|
50
|
+
@opos.plugin_is_ready(@name)
|
51
|
+
@main.run
|
52
|
+
end
|
53
|
+
|
54
|
+
def quit
|
55
|
+
@main.quit
|
56
|
+
Process.exit(0)
|
57
|
+
end
|
58
|
+
|
59
|
+
def nonblock_run
|
60
|
+
@mainthread = Thread.new{
|
61
|
+
@main = DBus::Main.new
|
62
|
+
@main << @clientbus
|
63
|
+
@opos.plugin_is_ready(@name)
|
64
|
+
@main.run
|
65
|
+
}
|
66
|
+
@server_ready_queue.pop
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
end
|
data/lib/openplacos.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file is part of Openplacos.
|
2
|
+
#
|
3
|
+
# Openplacos is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# Openplacos is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Openplacos. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
#
|
16
|
+
require 'dbus'
|
17
|
+
ENV["DBUS_THREADED_ACCESS"] = "1" #activate threaded dbus
|
18
|
+
|
19
|
+
require 'openplacos/libplugin'
|
20
|
+
require 'openplacos/libclient'
|
21
|
+
require 'openplacos/libdriver'
|
data/openplacos.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
require "rubygems"
|
3
|
+
require "rake"
|
4
|
+
|
5
|
+
GEMSPEC = Gem::Specification.new do |s|
|
6
|
+
s.name = "openplacos"
|
7
|
+
# s.rubyforge_project = nil
|
8
|
+
s.summary = "Openplacos libraries : Libclient, LibPlugin, LibDriver"
|
9
|
+
s.description = <<-EOF
|
10
|
+
Openplacos Gem is a set of libraries for openplacos software
|
11
|
+
these libraries allow an easier coding of openplacos client, plugin or driver in ruby.
|
12
|
+
EOF
|
13
|
+
s.version = File.read("VERSION").strip
|
14
|
+
s.author = "Openplacos Team"
|
15
|
+
s.email = "openplacos-general@lists.sourceforge.net"
|
16
|
+
s.homepage = "http://openplacos.sourceforge.net/"
|
17
|
+
s.files = FileList["{lib}/**/*", "openplacos.gemspec", "VERSION"].to_a.sort
|
18
|
+
s.require_path = "lib"
|
19
|
+
s.has_rdoc = false
|
20
|
+
s.add_dependency('ruby-dbus', '>= 0.6.0')
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openplacos
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Openplacos Team
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-15 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: ruby-dbus
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 6
|
33
|
+
- 0
|
34
|
+
version: 0.6.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: " Openplacos Gem is a set of libraries for openplacos software\n these libraries allow an easier coding of openplacos client, plugin or driver in ruby.\n"
|
38
|
+
email: openplacos-general@lists.sourceforge.net
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- VERSION
|
47
|
+
- lib/openplacos.rb
|
48
|
+
- lib/openplacos/libclient.rb
|
49
|
+
- lib/openplacos/libdriver.rb
|
50
|
+
- lib/openplacos/libplugin.rb
|
51
|
+
- openplacos.gemspec
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://openplacos.sourceforge.net/
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.4.1
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: "Openplacos libraries : Libclient, LibPlugin, LibDriver"
|
86
|
+
test_files: []
|
87
|
+
|