def report_event(args)
raise TypeError unless args.is_a?(Hash)
valid_keys = %w/source event_id category data event_type/
num_strings = 0
hash = {
'source' => @source,
'event_id' => 0,
'category' => 0,
'data' => 0
}
args.each{ |key, val|
key = key.to_s.downcase
unless valid_keys.include?(key)
raise ArgumentError, "invalid key '#{key}'"
end
hash[key] = val
}
unless hash['event_type']
raise Error, 'no event_type specified'
end
handle = RegisterEventSource(@server, hash['source'])
if handle == 0
error = 'RegisterEventSource() failed: ' + get_last_error
raise Error, error
end
if hash['data'].is_a?(String)
data = hash['data'] << 0.chr
data = [data].pack('p*')
num_strings = 1
else
data = 0
num_strings = 0
end
bool = ReportEvent(
handle,
hash['event_type'],
hash['category'],
hash['event_id'],
0,
num_strings,
0,
data,
0
)
unless bool
error = 'ReportEvent() failed: ' + get_last_error
raise Error, error
end
self
end