Revision e82a264b
Added by Marc Dequènes over 14 years ago
- ID e82a264b9c5f51c4eb0d1cfffb37d5628c41bc88
lib/cyborghood/cyborg/server.rb | ||
---|---|---|
@split_data_mode = false
|
||
@split_data_cmd = nil
|
||
@split_data = []
|
||
@session = Session.new
|
||
end
|
||
|
||
def send_line(msg)
|
||
... | ... | |
|
||
def receive_command(cmd, data = nil)
|
||
logger.debug "Executing command '#{cmd}' [#{identifier}]"
|
||
send_line @interface.call(cmd, data)
|
||
send_line @interface.call(@session, cmd, data)
|
||
end
|
||
|
||
def receive_error(msg)
|
||
... | ... | |
|
||
def unbind
|
||
logger.debug "Conversation finished with #{identifier}"
|
||
@session.clear
|
||
end
|
||
|
||
protected
|
||
... | ... | |
EmptyInterface.instance
|
||
end
|
||
end
|
||
|
||
class Session
|
||
attr_reader :store
|
||
|
||
def initialize
|
||
@store = Store.new
|
||
end
|
||
|
||
def clear
|
||
@store.values.each do |obj|
|
||
obj.__destroy if obj.respond_to? :__destroy
|
||
end
|
||
@store.clear
|
||
end
|
||
|
||
class Store < Hash
|
||
def get(key)
|
||
obj = self[key]
|
||
if obj.nil? and block_given?
|
||
obj = yield
|
||
self[key] = obj
|
||
end
|
||
obj
|
||
end
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
[evol] added session management to the cyborg server (refs #31)