Class: FSR::Listener::Outbound

Inherits:
EventMachine::Protocols::HeaderAndContentProtocol
  • Object
show all
Includes:
App
Defined in:
lib/fsr/listener/outbound.rb

Constant Summary collapse

SENDMSG_METHOD_DEFINITION =

Redefine the FSR::App methods to wrap sendmsg around them

"def %s(*args, &block); sendmsg super; end"

Constants included from App

App::APPLICATIONS, App::LOAD_PATH, App::REGISTER_CODE

Instance Method Summary collapse

Methods included from App

#applications, list, load_all, load_application, register

Instance Method Details

#post_initObject



18
19
20
21
22
# File 'lib/fsr/listener/outbound.rb', line 18

def post_init
  @session = nil # holds the session object
  send_data("connect\n\n")
  FSR::Log.debug "Accepting connections."
end

#receive_reply(session) ⇒ Object



43
44
45
# File 'lib/fsr/listener/outbound.rb', line 43

def receive_reply(session)
  session
end

#receive_request(header, content) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fsr/listener/outbound.rb', line 24

def receive_request(header, content)
  hash_header = headers_2_hash(header)
  hash_content = headers_2_hash(content)
  session = HeaderAndContentResponse.new({:headers => hash_header, :content => hash_content})
  if @session.nil?
    @session = self
    session_initiated(session) 
  else
    receive_reply(session)
  end
end

#sendmsg(message) ⇒ Object

sendmsg sends data to the EM app socket via #send_data, or returns the string it would send if #send_data is not defined. It expects an object which responds to either #sendmsg or #to_s, which should return a EM Outbound Event Socket formatted instruction



52
53
54
55
56
57
# File 'lib/fsr/listener/outbound.rb', line 52

def sendmsg(message)
  text = message.respond_to?(:sendmsg) ? message.sendmsg : message.to_s
  FSR::Log.debug "sending #{text}"
  message = "sendmsg\n%s\n" % text
  self.respond_to?(:send_data) ? send_data(message) : message
end

#session_initiated(session) ⇒ Object

Received data dispatches the data received by the EM socket, Either as a Session, a continuation of a Session, or as a Session’s last CommandReply



39
40
41
# File 'lib/fsr/listener/outbound.rb', line 39

def session_initiated(session)
  session
end