Revision 8c18bc9a
Added by Marc Dequènes about 14 years ago
- ID 8c18bc9aff8959ed4d8687094cf72b9b02f9bbd7
lib/cyborghood/cyborg/conversation.rb | ||
---|---|---|
@comm_stop = false
|
||
|
||
@protocol = BotProtocol.new(self)
|
||
|
||
@pending_thread_close = []
|
||
@system_notification_processing = @protocol.system_notification.subscribe do |msg|
|
||
process_system_notification(msg)
|
||
end
|
||
end
|
||
|
||
def post_init
|
||
... | ... | |
|
||
def set_comm_stop(peer_left = false)
|
||
@comm_stop = true
|
||
@protocol.system_notification.unsubscribe(@system_notification_processing)
|
||
yield if block_given?
|
||
peer_left ? close_connection : close_connection_after_writing
|
||
end
|
||
... | ... | |
th = @conv_threads[name] || new_thread(name)
|
||
if block_given?
|
||
yield th
|
||
# TODO: wait for end of chat
|
||
close_thread(name)
|
||
|
||
# wait for end of chat
|
||
@pending_thread_close << name
|
||
else
|
||
th
|
||
end
|
||
... | ... | |
def identifier
|
||
"#{@bot.identifier_prefix}/#{@signature}"
|
||
end
|
||
|
||
def process_system_notification(msg)
|
||
return unless msg[:topic] == 'THREAD IDLE'
|
||
|
||
th_name = msg[:thread]
|
||
close_thread(th_name) if @pending_thread_close.include? th_name
|
||
end
|
||
end
|
||
end
|
lib/cyborghood/cyborg/protocol.rb | ||
---|---|---|
VERSION = "0.1"
|
||
CAPABILITIES = []
|
||
|
||
attr_reader :system_notification
|
||
|
||
@@request_callback = proc do |result|
|
||
protocol = result[:reply_message].conv_thread.conversation.protocol
|
||
protocol.process_request_result(result)
|
||
end
|
||
|
||
# TODO:
|
||
# - check for request/reply couples (reply to wrong of non-existent request)
|
||
|
||
def initialize(conversation)
|
||
@conversation = conversation
|
||
|
||
... | ... | |
@negociation_ok = false
|
||
|
||
@action_followup = {}
|
||
|
||
@system_notification = EventMachine::Channel.new
|
||
end
|
||
|
||
def negociation_ok?
|
||
... | ... | |
method = "receive_" + message.action_code.downcase.tr(" ", "_")
|
||
if respond_to? method
|
||
send(method, message)
|
||
check_thread_idle(message.conv_thread)
|
||
else
|
||
send_error_protocol "unknown action"
|
||
end
|
||
... | ... | |
|
||
cb
|
||
end
|
||
|
||
def check_thread_idle(conv_thread)
|
||
return if @action_followup.has_key? conv_thread.id
|
||
|
||
@system_notification << { :topic => 'THREAD IDLE', :thread => conv_thread.name }
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
[evol] internal notification when thread is idle allowed to mark thread closing pending