-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhsms_server.rb
46 lines (40 loc) · 957 Bytes
/
hsms_server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require "rubygems"
require "eventmachine"
require "hsms_factory"
require "hsms_state"
class HSMSServer < EM::Connection
def initialize
@factory = HSMSFactory.new
@state = HSMSState.new
puts @state.to_s
end
def post_init
@state.connected
puts @state.to_s
end
def unbind
@state.disconnected
puts @state.to_s
end
def receive_data(data)
@factory.feed(data)
@factory.each { |message|
receive_message(message)
}
@factory.clear
end
def receive_message(message)
case message.s_type
when SType::DATA_MESSAGE
send_data(HSMSMessage.empty_data(SType::DATA_MESSAGE))
when SType::SELECT_REQ
send_data(HSMSMessage.empty_data(SType::SELECT_RSP))
@state.selected
puts @state.to_s
when SType::DESELECT_REQ, SType::SEPARATE_REQ
send_data(HSMSMessage.empty_data(SType::DESELECT_RSP))
@state.deselected
puts @state.to_s
end
end
end