class Roby::DRoby::Logfile::Writer
A class that marshals DRoby
cycle events into a log file using Ruby's Marshal
facility
Constants
- FORMAT_VERSION
The current log format version
Attributes
buffer_io[R]
event_io[R]
Public Class Methods
find_invalid_marshalling_object(obj, stack = Set.new)
click to toggle source
# File lib/roby/droby/logfile/writer.rb, line 74 def self.find_invalid_marshalling_object(obj, stack = Set.new) if stack.include?(obj) return end stack << obj case obj when Enumerable obj.each do |value| invalid, exception = find_invalid_marshalling_object(value, stack) if invalid return "#{invalid}, []", exception end end end # Generic check for instance variables obj.instance_variables.each do |iv| value = obj.instance_variable_get(iv) invalid, exception = find_invalid_marshalling_object(value, stack) if invalid return "#{invalid}, #{iv}", exception end end begin ::Marshal.dump(obj) nil rescue Exception => e begin return "#{obj} (#{obj.class})", e rescue Exception return "-- cannot display object, #to_s raised -- (#{obj.class})", e end end end
find_invalid_marshalling_object_in_cycle(cycle)
click to toggle source
# File lib/roby/droby/logfile/writer.rb, line 51 def self.find_invalid_marshalling_object_in_cycle(cycle) cycle.each_slice(4) do |m, sec, usec, args| begin ::Marshal.dump(args) rescue Exception => e Roby::DRoby::Logfile.fatal "failed to dump message #{m}: #{e}" args.each do |obj| begin ::Marshal.dump(obj) rescue Exception => e Roby::DRoby::Logfile.fatal "cannot dump #{obj}" Roby::DRoby::Logfile.fatal e.to_s obj, exception = find_invalid_marshalling_object(obj) if obj Roby::DRoby::Logfile.fatal " it seems that #{obj} can't be marshalled" Roby::DRoby::Logfile.fatal " #{exception.class}: #{exception.message}" end end end end end end
new(event_io, options = Hash.new)
click to toggle source
# File lib/roby/droby/logfile/writer.rb, line 15 def initialize(event_io, options = Hash.new) @event_io = event_io @buffer_io = StringIO.new('', 'w') Logfile.write_header(event_io, options) end
open(path, options = Hash.new)
click to toggle source
# File lib/roby/droby/logfile/writer.rb, line 22 def self.open(path, options = Hash.new) event_io = File.open(path, 'w') new(event_io, options) end
Public Instance Methods
close()
click to toggle source
# File lib/roby/droby/logfile/writer.rb, line 27 def close event_io.close end
dump(cycle)
click to toggle source
# File lib/roby/droby/logfile/writer.rb, line 43 def dump(cycle) dump_object(cycle, event_io) rescue self.class.find_invalid_marshalling_object_in_cycle(cycle) raise end
dump_object(object, io)
click to toggle source
# File lib/roby/droby/logfile/writer.rb, line 31 def dump_object(object, io) buffer_io.truncate(0) buffer_io.seek(0) ::Marshal.dump(object, buffer_io) io.write([buffer_io.size].pack("L<")) io.write(buffer_io.string) end
flush()
click to toggle source
# File lib/roby/droby/logfile/writer.rb, line 39 def flush event_io.flush end