Revision be27f17e
Added by Marc Dequènes about 14 years ago
- ID be27f17e729f333bb133c4e7138e25a2e9ea12f4
bin/mapmaker_client | ||
---|---|---|
if conv
|
||
logger.info "Yo ! Conversation ready with MapMaker (#{conv.peer_name}) !"
|
||
conv.thread("plop") do |conv_thread|
|
||
conv.protocol.send_request_call(conv_thread, "/api_version") do |reply|
|
||
pp reply
|
||
conv_thread.call("/api_version", 2) do |reply|
|
||
case reply[:status]
|
||
when :ok
|
||
puts "Result:"
|
||
pp reply[:result]
|
||
when :decline
|
||
puts "Declined: #{reply[:reason]}"
|
||
when :error
|
||
exception = reply[:exception]
|
||
puts "EXCEPTION: [#{exception.severity} - #{exception.category}] #{exception.message}"
|
||
pp exception.inspect
|
||
else
|
||
puts "???"
|
||
end
|
||
end
|
||
end
|
||
else
|
lib/cyborghood/cyborg/interface.rb | ||
---|---|---|
# preliminary incoming message handling
|
||
def call(session, cmd, data = nil)
|
||
action = find_node_action(session, cmd)
|
||
raise "unknown node" if action.nil?
|
||
raise CyberError.new(:unrecoverable, 'api/cyborghood', "unknown node") if action.nil?
|
||
|
||
data ||= []
|
||
raise "wrong format for arguments" unless data.is_a? Array
|
||
raise CyberError.new(:unrecoverable, 'api/cyborghood', "wrong format for arguments") unless data.is_a? Array
|
||
|
||
begin
|
||
action.call(*data)
|
||
rescue
|
||
logger.debug "node action error message: " + $!
|
||
logger.debug "node action error backtrace: " + $!.backtrace.join("\n")
|
||
raise "method call failed: " + $!
|
||
raise CyberError.new(:unrecoverable, 'api/cyborghood', "method call failed: " + $!)
|
||
end
|
||
end
|
||
end
|
lib/cyborghood/cyborg/protocol.rb | ||
---|---|---|
result[:action_result] = @conversation.bot.interface.call(message.conv_thread.session,
|
||
message.action_parameters[:node],
|
||
message.action_parameters[:parameters])
|
||
rescue CyberError => e
|
||
result[:error] = {
|
||
:category => e.category,
|
||
:severity => e.severity,
|
||
:message => e.message
|
||
}
|
||
rescue
|
||
result[:error] = $!.to_s
|
||
result[:error] = {
|
||
:category => 'unknown',
|
||
:severity => :unrecoverable,
|
||
:message => $!.to_s
|
||
}
|
||
end
|
||
result
|
||
end
|
||
... | ... | |
def receive_error_action(message)
|
||
cb = pop_callback(message)
|
||
if cb
|
||
cb.call({:reply => :error, :reason => message.action_parameters[:error]})
|
||
error = message.action_parameters[:error]
|
||
exception = CyberError.new(error[:severity], error[:category], error[:message])
|
||
cb.call({:status => :error, :exception => exception})
|
||
else
|
||
send_error_protocol("received reply for unknown action")
|
||
end
|
||
... | ... | |
def receive_reply_decline(message)
|
||
cb = pop_callback(message)
|
||
if cb
|
||
cb.call({:reply => :decline, :reason => message.action_parameters[:reason]})
|
||
cb.call({:status => :decline, :reason => message.action_parameters[:reason]})
|
||
else
|
||
send_error_protocol("received reply for unknown action")
|
||
end
|
||
... | ... | |
def receive_reply_result(message)
|
||
cb = pop_callback(message)
|
||
if cb
|
||
cb.call({:reply => :ok, :result => message.action_parameters[:result]})
|
||
cb.call({:status => :ok, :result => message.action_parameters[:result]})
|
||
else
|
||
send_error_protocol("received reply for unknown action")
|
||
end
|
Also available in: Unified diff
[evol] improve a bit how interface errors are transmitted