pangdudu-robots 0.2.3 → 0.2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -10
- data/config/start_dbus_session.sh +1 -1
- data/lib/robots.rb +1 -1
- data/lib/robots_agent.rb +31 -51
- data/lib/robots_daemon.rb +23 -0
- data/lib/robots_infrastructure.rb +1 -1
- data/lib/robots_prototype.rb +2 -1
- metadata +22 -1
data/README.rdoc
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
Local messaging with dbus working, need to make service avahi discoverable.
|
4
4
|
|
5
|
-
Well, fork, dbus is not really remote capable right now. Ohh, I so much don't want to write that myself,... ;(...
|
6
|
-
|
7
5
|
Let's try to built a nice easy to use multiagent framework
|
8
6
|
based on all the cool stuff we can get for ruby.
|
9
7
|
|
@@ -11,18 +9,17 @@ rObOts!
|
|
11
9
|
|
12
10
|
== Installation
|
13
11
|
|
14
|
-
#on ubuntu you need stuff like this to build dbus
|
15
|
-
sudo apt-get install avahi-daemon avahi-utils libavahi-client-dev libavahi-common-dev libavahi-compat-libdnssd-dev libnss-mdns libdbus-1-dev libdbus-glib-1-dev
|
16
|
-
#essential gems
|
17
|
-
sudo gem install pangdudu-ruby-dbus --source=http://gems.github.com
|
18
|
-
sudo gem install pangdudu-ruby-dbus-daemon --source=http://gems.github.com
|
19
|
-
sudo gem install pangdudu-rofl --source=http://gems.github.com
|
20
12
|
sudo gem install pangdudu-robots --source=http://gems.github.com
|
21
|
-
#for xml parsing and building
|
22
|
-
sudo gem install hpricot builder
|
23
13
|
|
24
14
|
== Usage
|
25
15
|
|
16
|
+
sorry, this section was actualy missing before.
|
17
|
+
|
18
|
+
oki, if you choose sessiontype 'robots', start the daemon with the 'start_dbus_session.sh'
|
19
|
+
script in 'config/'.
|
20
|
+
|
21
|
+
then start one of the robots from examples or the robots_prototype.
|
22
|
+
|
26
23
|
== Rule the universe!
|
27
24
|
|
28
25
|
Robots are coming!
|
@@ -1,2 +1,2 @@
|
|
1
1
|
#!/bin/bash
|
2
|
-
dbus-daemon --config-file=$HOME/.robots/config/remote.session.dbus.conf
|
2
|
+
dbus-daemon --print-address --config-file=$HOME/.robots/config/remote.session.dbus.conf
|
data/lib/robots.rb
CHANGED
data/lib/robots_agent.rb
CHANGED
@@ -1,35 +1,38 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'dbus' #gem install pangdudu-ruby-dbus --source=http://gems.github.com
|
3
|
-
require 'dbus-daemon' #gem install pangdudu-ruby-dbus-daemon --source=http://gems.github.com
|
4
3
|
require 'rofl' #gem install pangdudu-rofl --source=http://gems.github.com
|
5
4
|
#local requires, actually don't need them, just to let you know whats going on
|
6
5
|
require 'robots_infrastructure'
|
7
6
|
|
8
7
|
class Robot
|
9
|
-
attr_accessor :dbusdaemon #in case we use a custom dbus-daemon
|
10
8
|
attr_accessor :avahi #for mdns service discovery
|
11
9
|
attr_accessor :emitters,:infrastructure,:listeners #stuff a robot needs
|
12
|
-
attr_accessor :
|
10
|
+
attr_accessor :config #hash with lots of config magic inside
|
13
11
|
|
14
12
|
def initialize
|
15
13
|
dlog "new Robot initialized."
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@remote = false #if you want to connect remotely, change this value
|
19
|
-
@sessiontype = "robots" #could be session,system or robots (use robots, if you want it to work over multiple hosts)
|
20
|
-
@daemonconfig = "~/.robots/config/remote.session.dbus.conf" #listens on tcp
|
21
|
-
@robots_socket_name = "tcp:host=#{@daemonhost},port=2687,family=ipv4" #look at: ~/.robots/config/remote.session.dbus.conf
|
22
|
-
@robotsservice = "org.robots.Service"
|
23
|
-
@emitterpath = "/org/robots/Service/Emitter"
|
24
|
-
@emitterinterface = "org.robots.Service.EmitterInterface"
|
25
|
-
@coreservice, @dbussession, @dbusdaemon = nil,nil,nil
|
14
|
+
@config = get_default_config
|
15
|
+
@coreservice, @dbussession = nil,nil
|
26
16
|
@listeners,@emitters,@infrastructure = [],{},{}
|
27
17
|
@servicetypes = fill_servicetypes #refer to robots_infrastructure.rb
|
28
18
|
end
|
29
19
|
|
20
|
+
def get_default_config
|
21
|
+
config = {}
|
22
|
+
config[:localhost] = Socket.gethostname
|
23
|
+
config[:daemonhost] = "127.0.0.1"
|
24
|
+
config[:daemonport] = "2687"
|
25
|
+
config[:remote] = false #if you want to connect remotely, change this value
|
26
|
+
config[:sessiontype] = "robots" #could be session,system or robots (use robots, if you want it to work over multiple hosts)
|
27
|
+
config[:robots_socket_name] = "tcp:host=#{config[:daemonhost]},port=#{config[:daemonport]},family=ipv4" #look at: ~/.robots/config/remote.session.dbus.conf
|
28
|
+
config[:robotsservice] = "org.robots.Service"
|
29
|
+
config[:emitterpath] = "/org/robots/Service/Emitter"
|
30
|
+
config[:emitterinterface] = "org.robots.Service.EmitterInterface"
|
31
|
+
return config
|
32
|
+
end
|
33
|
+
|
30
34
|
#start the mojo
|
31
35
|
def run
|
32
|
-
check_for_dbus_daemon if @sessiontype.eql? "robots" #will start a dbus-daemon if necessary
|
33
36
|
setup_robots_service
|
34
37
|
register_callbacks
|
35
38
|
#test_messages; #main_loop;
|
@@ -37,11 +40,11 @@ class Robot
|
|
37
40
|
|
38
41
|
#setup the robots service
|
39
42
|
def setup_robots_service
|
40
|
-
robots_running = running? @robotsservice
|
43
|
+
robots_running = running? @config[:robotsservice]
|
41
44
|
dlog "robots service has already been started." if robots_running
|
42
45
|
unless robots_running
|
43
46
|
ilog "will now setup robots service infrastructure."
|
44
|
-
start_core_service @robotsservice
|
47
|
+
start_core_service @config[:robotsservice]
|
45
48
|
init_robots_infrastructure
|
46
49
|
end
|
47
50
|
get_robots_infrastructure
|
@@ -53,45 +56,21 @@ class Robot
|
|
53
56
|
the following methods are only called, if the robots service is not already running
|
54
57
|
=end
|
55
58
|
|
56
|
-
#check if a dbus-daemon suitable for robots is running, otherwise start one
|
57
|
-
def check_for_dbus_daemon
|
58
|
-
unless @remote
|
59
|
-
@daemonconfig = File.expand_path(@daemonconfig) #dbus-daemon won't accept otherwise
|
60
|
-
#ok, no config file, not good!
|
61
|
-
unless File.exist? @daemonconfig
|
62
|
-
wlog "no daemon config: #{@daemonconfig}!"
|
63
|
-
wlog "will sleep for 5 seconds,..."
|
64
|
-
sleep 5 #give the user time to realize
|
65
|
-
end
|
66
|
-
#if the config file is there
|
67
|
-
if File.exist? @daemonconfig
|
68
|
-
@dbusdaemon = DbusDaemon.new @daemonconfig
|
69
|
-
got_twins = @dbusdaemon.got_twin_daemon? #check if a daemon like this is already running
|
70
|
-
ilog "custom dbus-daemon is already running." if got_twins #inform user
|
71
|
-
unless got_twins #no suitable dbus-daemon running, start one
|
72
|
-
@dbusdaemon.start_daemon
|
73
|
-
ilog "custom dbus-daemon started and running, check \"ps x | grep \"dbus-daemon\", if plan a CTRL-C."
|
74
|
-
#@dbusdaemon.stop_daemon #must get called sometimes, super nasty, use " ps x | grep "dbus-daemon" "
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
59
|
#setup the infrastructure objects for communication
|
81
60
|
def init_robots_infrastructure
|
82
|
-
emitter = Emitter.new(
|
61
|
+
emitter = Emitter.new(config[:emitterpath],self)
|
83
62
|
@coreservice.export(emitter)
|
84
63
|
@infrastructure["emitter"] = emitter
|
85
64
|
end
|
86
65
|
|
87
66
|
#get instances of our infrastructure objects
|
88
67
|
def get_robots_infrastructure
|
89
|
-
emitter = get_object_from_service @robotsservice,@emitterpath,@emitterinterface
|
68
|
+
emitter = get_object_from_service @config[:robotsservice],@config[:emitterpath],@config[:emitterinterface]
|
90
69
|
@emitters["robots"] = emitter
|
91
70
|
end
|
92
71
|
|
93
72
|
#start a service
|
94
|
-
def start_core_service service_name=@robotsservice
|
73
|
+
def start_core_service service_name=@config[:robotsservice]
|
95
74
|
bus = get_bus
|
96
75
|
#first of all check if the service we want to launch is already started
|
97
76
|
dlog "skipping service: #{service_name} has already been started." if running? service_name
|
@@ -147,7 +126,7 @@ class Robot
|
|
147
126
|
dlog "registering callback for #{name} on path #{emitter.path}"
|
148
127
|
mr = DBus::MatchRule.new
|
149
128
|
mr.type = "signal"
|
150
|
-
mr.interface =
|
129
|
+
mr.interface = @config[:emitterinterface]
|
151
130
|
mr.path = emitter.path
|
152
131
|
bus.add_match(mr) { |msg| emitter_proxy_callback msg }
|
153
132
|
end
|
@@ -197,6 +176,7 @@ class Robot
|
|
197
176
|
#send
|
198
177
|
def send_msg msg
|
199
178
|
@emitters["robots"].send_message(msg) unless @emitters["robots"].nil?
|
179
|
+
wlog "emitter is nil, can not send message." if @emitters["robots"].nil?
|
200
180
|
end
|
201
181
|
|
202
182
|
#add a listener
|
@@ -215,11 +195,11 @@ class Robot
|
|
215
195
|
#get the bus session, cleaner then creating new sessions all over
|
216
196
|
def get_bus
|
217
197
|
if @dbussession.nil?
|
218
|
-
@dbussession = DBus::SystemBus.instance if @sessiontype.eql? "system"
|
219
|
-
@dbussession = DBus::SessionBus.instance if @sessiontype.eql? "session"
|
220
|
-
if @sessiontype.eql? "robots"
|
221
|
-
DBus.const_set("SessionSocketName", @robots_socket_name) #overwrite the modules constant
|
222
|
-
evil_hack_remote_cookie if @remote #i need not say more,...
|
198
|
+
@dbussession = DBus::SystemBus.instance if @config[:sessiontype].eql? "system"
|
199
|
+
@dbussession = DBus::SessionBus.instance if @config[:sessiontype].eql? "session"
|
200
|
+
if @config[:sessiontype].eql? "robots"
|
201
|
+
DBus.const_set("SessionSocketName", @config[:robots_socket_name]) #overwrite the modules constant
|
202
|
+
evil_hack_remote_cookie if @config[:remote] #i need not say more,...
|
223
203
|
@dbussession = DBus::SessionBus.instance
|
224
204
|
end
|
225
205
|
end
|
@@ -233,8 +213,8 @@ class Robot
|
|
233
213
|
|
234
214
|
#because dbus remote auth still betrays us, we need to hack it
|
235
215
|
def evil_hack_remote_cookie
|
236
|
-
if @robots_socket_name.include? "tcp:"
|
237
|
-
af, port, daemon_name, daemon_addr = (Socket::getaddrinfo(@daemonhost
|
216
|
+
if @config[:robots_socket_name].include? "tcp:"
|
217
|
+
af, port, daemon_name, daemon_addr = (Socket::getaddrinfo(@config[:daemonhost],@config[:daemonhost].to_i)).first
|
238
218
|
ilog "Trying to get/hack remote cookie from: #{daemon_name}."
|
239
219
|
begin
|
240
220
|
cookiepath = "#{ENV['HOME']}/.dbus-keyrings/org_freedesktop_general"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#check if a dbus-daemon suitable for robots is running, otherwise start one
|
2
|
+
def check_for_dbus_daemon
|
3
|
+
unless @remote
|
4
|
+
@daemonconfig = File.expand_path(@daemonconfig) #dbus-daemon won't accept otherwise
|
5
|
+
#ok, no config file, not good!
|
6
|
+
unless File.exist? @daemonconfig
|
7
|
+
wlog "no daemon config: #{@daemonconfig}!"
|
8
|
+
wlog "will sleep for 5 seconds,..."
|
9
|
+
sleep 5 #give the user time to realize
|
10
|
+
end
|
11
|
+
#if the config file is there
|
12
|
+
if File.exist? @daemonconfig
|
13
|
+
@dbusdaemon = DbusDaemon.new @daemonconfig
|
14
|
+
got_twins = @dbusdaemon.got_twin_daemon? #check if a daemon like this is already running
|
15
|
+
ilog "custom dbus-daemon is already running." if got_twins #inform user
|
16
|
+
unless got_twins #no suitable dbus-daemon running, start one
|
17
|
+
@dbusdaemon.start_daemon
|
18
|
+
ilog "custom dbus-daemon started and running, check \"ps x | grep \"dbus-daemon\", if plan a CTRL-C."
|
19
|
+
#@dbusdaemon.stop_daemon #must get called sometimes, super nasty, use " ps x | grep "dbus-daemon" "
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -17,7 +17,7 @@ class Emitter < DBus::Object
|
|
17
17
|
end
|
18
18
|
|
19
19
|
#create an dbus interface
|
20
|
-
dbus_interface "org.
|
20
|
+
dbus_interface "org.robots.Service.EmitterInterface" do
|
21
21
|
#creates a signal in the interface:
|
22
22
|
dbus_signal :newMessage, "msgbody:s"
|
23
23
|
#creates an emit method in the interface:
|
data/lib/robots_prototype.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pangdudu-robots
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.3
|
4
|
+
version: 0.2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pangdudu
|
@@ -42,6 +42,26 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: "0"
|
44
44
|
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: hpricot
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: builder
|
57
|
+
type: :runtime
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
45
65
|
description: robots!
|
46
66
|
email: pangdudu@github
|
47
67
|
executables:
|
@@ -58,6 +78,7 @@ files:
|
|
58
78
|
- lib/robots_infrastructure.rb
|
59
79
|
- lib/robots_xml.rb
|
60
80
|
- lib/robots_prototype.rb
|
81
|
+
- lib/robots_daemon.rb
|
61
82
|
- config/org.robots.service.conf
|
62
83
|
- config/remote.session.dbus.conf
|
63
84
|
- config/start_dbus_session.sh
|