pangdudu-robots 0.2.3.1 → 0.2.3.2

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.
@@ -1,2 +1,2 @@
1
1
  #!/bin/bash
2
- dbus-daemon --print-address --config-file=$HOME/.robots/config/remote.session.dbus.conf
2
+ dbus-daemon --print-address --config-file=remote.session.dbus.conf
@@ -71,9 +71,20 @@ class MemoryAgent
71
71
 
72
72
  def initialize
73
73
  @roboname = "Active Memory" #name used in alive messages
74
+ configure #configure the robot
74
75
  ilog "#{@roboname} initialized"
75
76
  end
76
77
 
78
+ #configure the robot using a default config
79
+ def configure
80
+ @config = get_default_config #get the default config from the module
81
+ #config values
82
+ @config[:sessiontype] = "robots" #could be session,system or robots (use robots, if you want it to work over multiple hosts)
83
+ @config[:daemonhost] = "localhost"
84
+ @config[:daemonport] = "2687"
85
+ @config[:sshcookie] = false #if you want to connect remotely, you need to get the daemon cookie over ssh
86
+ end
87
+
77
88
  #process an incoming memory message
78
89
  def process_memory_msg xml_msg
79
90
  memories = get_memories xml_msg
@@ -16,9 +16,20 @@ class MemoryGeneratorAgent
16
16
 
17
17
  def initialize
18
18
  @roboname = "Memory Generator" #name used in alive messages
19
+ configure #configure the robot
19
20
  ilog "#{@roboname} initialized"
20
21
  end
21
22
 
23
+ #configure the robot using a default config
24
+ def configure
25
+ @config = get_default_config #get the default config from the module
26
+ #config values
27
+ @config[:sessiontype] = "robots" #could be session,system or robots (use robots, if you want it to work over multiple hosts)
28
+ @config[:daemonhost] = "localhost"
29
+ @config[:daemonport] = "2687"
30
+ @config[:sshcookie] = false #if you want to connect remotely, you need to get the daemon cookie over ssh
31
+ end
32
+
22
33
  #ROBOTS message parsing stuff
23
34
 
24
35
  #method that gets called when a new message arrives
@@ -18,9 +18,20 @@ class SwiftAgent
18
18
 
19
19
  def initialize
20
20
  @roboname = "Swift Talker" #name used in alive messages
21
+ configure #configure the robot
21
22
  ilog "#{@roboname} initialized"
22
23
  end
23
24
 
25
+ #configure the robot using a default config
26
+ def configure
27
+ @config = get_default_config #get the default config from the module
28
+ #config values
29
+ @config[:sessiontype] = "robots" #could be session,system or robots (use robots, if you want it to work over multiple hosts)
30
+ @config[:daemonhost] = "localhost"
31
+ @config[:daemonport] = "2687"
32
+ @config[:sshcookie] = false #if you want to connect remotely, you need to get the daemon cookie over ssh
33
+ end
34
+
24
35
  #method that gets called when a new message arrives
25
36
  def receive_msg msg
26
37
  check_for_interests msg
@@ -16,7 +16,18 @@ class TextGenerator
16
16
 
17
17
  def initialize
18
18
  @roboname = "Text Generator" #name used in alive messages
19
- ilog "#{@roboname} initialized"
19
+ configure #configure the robot
20
+ ilog "#{@roboname} initialized"
21
+ end
22
+
23
+ #configure the robot using a default config
24
+ def configure
25
+ @config = get_default_config #get the default config from the module
26
+ #config values
27
+ @config[:sessiontype] = "robots" #could be session,system or robots (use robots, if you want it to work over multiple hosts)
28
+ @config[:daemonhost] = "localhost"
29
+ @config[:daemonport] = "2687"
30
+ @config[:sshcookie] = false #if you want to connect remotely, you need to get the daemon cookie over ssh
20
31
  end
21
32
 
22
33
  #method that gets called when a new message arrives
@@ -14,10 +14,21 @@ class VisualizerAgent
14
14
 
15
15
  def initialize argv
16
16
  @roboname = "Visualizer" #name used in alive messages
17
- ilog "#{@roboname} initialized"
18
17
  @width, @height = 800,600
19
18
  @app = Qt::Application.new(argv)
20
19
  @agents = {} #thats where we register the agents in
20
+ configure #configure the robot
21
+ ilog "#{@roboname} initialized"
22
+ end
23
+
24
+ #configure the robot using a default config
25
+ def configure
26
+ @config = get_default_config #get the default config from the module
27
+ #config values
28
+ @config[:sessiontype] = "robots" #could be session,system or robots (use robots, if you want it to work over multiple hosts)
29
+ @config[:daemonhost] = "localhost"
30
+ @config[:daemonport] = "2687"
31
+ @config[:sshcookie] = false #if you want to connect remotely, you need to get the daemon cookie over ssh
21
32
  end
22
33
 
23
34
  #process an info message
@@ -6,11 +6,19 @@ require 'robots_agent'
6
6
 
7
7
  module Robots
8
8
 
9
- attr_accessor :robotsagent,:haz_robots,:hostname
9
+ attr_accessor :robotsagent,:hostname,:config
10
10
 
11
11
  #release the robots
12
12
  def release_robots
13
13
  check_robotsagent
14
+ @hostname = @config[:localhost]
15
+ socket_name = "tcp:host=#{@config[:daemonhost]},port=#{@config[:daemonport]},family=ipv4"
16
+ @config[:robots_socket_name] = socket_name #look at: config/remote.session.dbus.conf
17
+ #the final steps, to make the robot ready
18
+ @robotsagent.config = @config
19
+ @robotsagent.run
20
+ @robotsagent.add_listener self
21
+ @robots_running = true
14
22
  end
15
23
 
16
24
  #receives messages from the robots, should be overwritten in the implementing class
@@ -20,7 +28,11 @@ module Robots
20
28
 
21
29
  #sends messages to the robots, should be overwritten in the implementing class
22
30
  def send_msg msg
23
- @robotsagent.send_msg msg if @haz_robots
31
+ if @robots_running
32
+ @robotsagent.send_msg msg
33
+ else
34
+ wlog "Robot not yet running, can't send message."
35
+ end
24
36
  end
25
37
 
26
38
  #check if robots are set up
@@ -28,11 +40,25 @@ module Robots
28
40
  @haz_robots = @robotsagent.nil?
29
41
  if @haz_robots
30
42
  @robotsagent = Robot.new
31
- @hostname = @robotsagent.config[:hostname]
32
- @robotsagent.run
33
- @robotsagent.add_listener self
43
+ end
44
+ if @config.nil?
45
+ wlog "No config supplied! Will use default config."
46
+ @config = get_default_config
34
47
  end
35
48
  return @haz_robots
36
49
  end
37
50
 
51
+ #this is the default config, you can modify the values, than pass it to the agent
52
+ def get_default_config
53
+ config = {}
54
+ config[:localhost] = Socket.gethostname
55
+ config[:daemonhost] = "localhost"
56
+ config[:daemonport] = "2687"
57
+ config[:sshcookie] = false #if you want to connect remotely, change this value
58
+ config[:sessiontype] = "robots" #could be session,system or robots (use robots, if you want it to work over multiple hosts)
59
+ config[:robotsservice] = "org.robots.Service"
60
+ config[:emitterpath] = "/org/robots/Service/Emitter"
61
+ config[:emitterinterface] = "org.robots.Service.EmitterInterface"
62
+ return config
63
+ end
38
64
  end
@@ -11,28 +11,17 @@ class Robot
11
11
 
12
12
  def initialize
13
13
  dlog "new Robot initialized."
14
- @config = get_default_config
15
14
  @coreservice, @dbussession = nil,nil
16
15
  @listeners,@emitters,@infrastructure = [],{},{}
17
16
  @servicetypes = fill_servicetypes #refer to robots_infrastructure.rb
18
17
  end
19
18
 
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
-
34
19
  #start the mojo
35
20
  def run
21
+ if @config.nil?
22
+ elog "Agent not configured, exiting!"
23
+ exit(0)
24
+ end
36
25
  setup_robots_service
37
26
  register_callbacks
38
27
  #test_messages; #main_loop;
@@ -199,7 +188,7 @@ class Robot
199
188
  @dbussession = DBus::SessionBus.instance if @config[:sessiontype].eql? "session"
200
189
  if @config[:sessiontype].eql? "robots"
201
190
  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,...
191
+ get_remote_cookie if @config[:sshcookie] #i need not say more,...
203
192
  @dbussession = DBus::SessionBus.instance
204
193
  end
205
194
  end
@@ -212,7 +201,7 @@ class Robot
212
201
  end
213
202
 
214
203
  #because dbus remote auth still betrays us, we need to hack it
215
- def evil_hack_remote_cookie
204
+ def get_remote_cookie
216
205
  if @config[:robots_socket_name].include? "tcp:"
217
206
  af, port, daemon_name, daemon_addr = (Socket::getaddrinfo(@config[:daemonhost],@config[:daemonhost].to_i)).first
218
207
  ilog "Trying to get/hack remote cookie from: #{daemon_name}."
@@ -12,11 +12,22 @@ class RobotsProto
12
12
  include Robots
13
13
  include RobotsXml
14
14
 
15
- attr_accessor :roboname
15
+ attr_accessor :roboname,:config
16
16
 
17
17
  def initialize
18
18
  @roboname = "Robots Prototype" #name used in alive messages
19
- ilog "RobotsProto initialized"
19
+ configure #configure the robot
20
+ ilog "#{@roboname} initialized"
21
+ end
22
+
23
+ #configure the robot using a default config
24
+ def configure
25
+ @config = get_default_config #get the default config from the module
26
+ #config values
27
+ @config[:sessiontype] = "robots" #could be session,system or robots (use robots, if you want it to work over multiple hosts)
28
+ @config[:daemonhost] = "localhost"
29
+ @config[:daemonport] = "2687"
30
+ @config[:sshcookie] = false #if you want to connect remotely, you need to get the daemon cookie over ssh
20
31
  end
21
32
 
22
33
  #method that gets called when a new message arrives
@@ -29,9 +40,6 @@ class RobotsProto
29
40
  #message filter callback looks like this now
30
41
  info = parse_xml_msg xml_msg,"//info"
31
42
  dlog info unless info.empty?
32
- #and one that doesn't work, unless you add this tag to the xml
33
- notfound = parse_xml_msg xml_msg,"//thereisnosuchtag"
34
- dlog notfound unless notfound.empty?
35
43
  end
36
44
 
37
45
  end
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.1
4
+ version: 0.2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pangdudu
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-27 00:00:00 -07:00
12
+ date: 2009-07-31 00:00:00 -07:00
13
13
  default_executable: robots
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency