Class: Roby::Log::EventMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/app/scripts/generate/bookmarks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEventMatcher

Returns a new instance of EventMatcher.



10
11
12
13
14
# File 'lib/roby/app/scripts/generate/bookmarks.rb', line 10

def initialize
	@remote_ids = Hash.new
	@notifications = Hash.new
	@predicate_id = 0
end

Instance Attribute Details

#notificationsObject (readonly)

Returns the value of attribute notifications.



9
10
11
# File 'lib/roby/app/scripts/generate/bookmarks.rb', line 9

def notifications
  @notifications
end

#predicate_idObject (readonly)

Returns the value of attribute predicate_id.



8
9
10
# File 'lib/roby/app/scripts/generate/bookmarks.rb', line 8

def predicate_id
  @predicate_id
end

#remote_idsObject (readonly)

Returns the value of attribute remote_ids.



7
8
9
# File 'lib/roby/app/scripts/generate/bookmarks.rb', line 7

def remote_ids
  @remote_ids
end

Instance Method Details

#event(m, sec, usec, args) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/roby/app/scripts/generate/bookmarks.rb', line 35

def event(m, sec, usec, args)
	if m == :discovered_tasks || m == :discovered_events
 objects = args[1]
 for object in objects
		for remote_id in object.remote_siblings.values
  remote_ids[remote_id] = object
		end
 end

	elsif m == :finalized_task || m == :finalized_event
 object = args[1]
 remote_ids.delete(object)
	end

	time = nil
	if predicate_set = notifications[m]
 for p, callback in predicate_set
		if p.call(args)
  time ||= Time.at(sec, usec)
  callback.call(time, args)
		end
 end
	end
end

#filter(log) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/roby/app/scripts/generate/bookmarks.rb', line 27

def filter(log)
	while log.has_sample?
 log.read_and_decode.each_slice(4) do |m, sec, usec, args|
		event(m, sec, usec, args)
 end
	end
end

#local_object(remote_id) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/roby/app/scripts/generate/bookmarks.rb', line 16

def local_object(remote_id)
	if remote_id.kind_of?(Roby::Distributed::RemoteID)
 unless obj = remote_ids[remote_id]
		raise "no object for #{remote_id}: #{remote_ids.keys}"
 end
 obj
	else
 remote_id
	end
end

#parse(expr, &block) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/roby/app/scripts/generate/bookmarks.rb', line 60

def parse(expr, &block)
	case expr
	when /^(\w+)\((.*)\)$/
 method = :generator_fired
 task_model = Regexp.new($2)
 symbol = $1.to_sym
 predicate = lambda do |args|
		generator = local_object(args[0])
		if generator.respond_to?(:task) && generator.symbol == symbol
  task = local_object(generator.task)
  Regexp.new(task_model) === local_object(task).model.ancestors[0][0]
		end
 end
	end

	if predicate
 notifications[method] ||= Array.new
 notifications[method] << [predicate, block]
	end
end