pangdudu-robots 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,6 +4,8 @@ Start your clocks boys and girls, it's weekend coding time!
4
4
 
5
5
  On monday I want: working messaging, data-mapper/mysql memory agent, visualizer agent with agent introspection, slim agent that requests modules,classes over the net and evals them online.
6
6
 
7
+ Local messaging with dbus working, need to make service avahi discoverable.
8
+
7
9
  Let's try to built a nice easy to use multiagent framework
8
10
  based on all the cool stuff we can get for ruby.
9
11
 
@@ -11,11 +13,15 @@ rObOts!
11
13
 
12
14
  == Installation
13
15
 
16
+ #on ubuntu you need stuff like this to build dbus
14
17
  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
15
- sudo gem install dnssd
18
+ #essential gems
16
19
  sudo gem install pangdudu-ruby-dbus --source=http://gems.github.com
17
20
  sudo gem install pangdudu-rofl --source=http://gems.github.com
18
-
21
+ sudo gem install pangdudu-robots --source=http://gems.github.com
22
+ #for xml parsing and building
23
+ sudo gem install hpricot builder
24
+
19
25
  == Usage
20
26
 
21
27
  == Rule the universe!
data/bin/robots CHANGED
@@ -1,2 +1,25 @@
1
1
  #!/usr/bin/ruby
2
- puts "ROBOTS!"
2
+ require 'rubygems'
3
+ require 'rofl' #gem install pangdudu-rofl --source=http://gems.github.com
4
+ require 'robots'
5
+
6
+ class RobotsTest
7
+ include Robots
8
+
9
+ def initialize
10
+ ilog "RobotsTest initialized"
11
+ end
12
+
13
+ def receive_msg msg
14
+ ilog msg
15
+ end
16
+
17
+ end
18
+
19
+ rt = RobotsTest.new
20
+ rt.release_robots
21
+
22
+ loop do
23
+ sleep 1
24
+ rt.send_msg "RobotsTest is working!"
25
+ end
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rofl' #gem install pangdudu-rofl --source=http://gems.github.com
3
+ require 'robots'
4
+ require 'robots_xml'
5
+
6
+ #the RobotsXml module supplies nice methods for xml handling
7
+ #create xml messages like this: xml_msg = create_xml_msg { |b| b.body("test"); b.info("timestamp" => "#{Time.now}") }
8
+ #send them like this: send_msg xml_msg
9
+ #parse them like this: parse_xml_msg xml_msg,xpath
10
+
11
+ class RobotsProto
12
+ include Robots
13
+ include RobotsXml
14
+
15
+ def initialize
16
+ ilog "RobotsProto initialized"
17
+ end
18
+
19
+ #method that gets called when a new message arrives
20
+ def receive_msg msg
21
+ check_for_interests msg
22
+ end
23
+
24
+ #check if this msg interests us
25
+ def check_for_interests xml_msg
26
+ #message filter callback looks like this now
27
+ info = parse_xml_msg xml_msg,"//info"
28
+ dlog info unless info.empty?
29
+ #and one that doesn't work, unless you add this tag to the xml
30
+ notfound = parse_xml_msg xml_msg,"//thereisnosuchtag"
31
+ dlog notfound unless notfound.empty?
32
+ end
33
+
34
+ end
35
+
36
+ #start the app
37
+ rp = RobotsProto.new
38
+ rp.release_robots #start the robot agent module
39
+
40
+ #build you own loop if you need one
41
+ loop do
42
+ sleep 1
43
+ #send an xml message over the system
44
+ rp.send_msg rp.create_xml_msg { |b| b.body("test"); b.info("timestamp" => "#{Time.now}") }
45
+ end
data/lib/robots_xml.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'rofl' #gem install pangdudu-rofl --source=http://gems.github.com
3
+ require 'hpricot' #my favourite xml parser
4
+ require 'builder' #very simple xml builder
5
+
6
+ module RobotsXml
7
+
8
+ #create an xml message
9
+ def create_xml_msg &block
10
+ b = Builder::XmlMarkup.new
11
+ return b.msg &block
12
+ end
13
+
14
+ #parse a xml message
15
+ def parse_xml_msg xml_msg,xpath="//msg"
16
+ begin
17
+ xml = Hpricot.XML(xml_msg)
18
+ msg = (xml/xpath)
19
+ return msg
20
+ rescue
21
+ wlog "message parsing error!"
22
+ return xml = Hpricot.XML("<msg>parsing error</msg>")
23
+ end
24
+ end
25
+ end
26
+
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.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pangdudu
@@ -36,6 +36,8 @@ files:
36
36
  - lib/robots.rb
37
37
  - lib/robots_agent.rb
38
38
  - lib/robots_infrastructure.rb
39
+ - lib/robots_xml.rb
40
+ - lib/robots_prototype.rb
39
41
  - config/org.robots.service.conf
40
42
  has_rdoc: true
41
43
  homepage: http://github.com/pangdudu/robots