compiles
This commit is contained in:
parent
12f397ed2b
commit
57ce9d2e38
@ -4,8 +4,8 @@ require "./event"
|
|||||||
require "./connection"
|
require "./connection"
|
||||||
|
|
||||||
class IPC::Context
|
class IPC::Context
|
||||||
property base_timer : Float64 = 0.0
|
property base_timer : UInt32 = 0
|
||||||
property timer : Float64 = 0.0
|
property timer : UInt32 = 0
|
||||||
getter context : LibIPC::Ctx
|
getter context : LibIPC::Ctx
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@ -69,7 +69,7 @@ class IPC::Context
|
|||||||
when LibIPC::EventType::NotSet
|
when LibIPC::EventType::NotSet
|
||||||
return Exception.new "'Event type: not set"
|
return Exception.new "'Event type: not set"
|
||||||
when LibIPC::EventType::Error
|
when LibIPC::EventType::Error
|
||||||
return IPC::Event::Error.new event.index, event.origin
|
return IPC::Event::Error.new event.origin, event.index
|
||||||
when LibIPC::EventType::ExtraSocket # Message received from a non IPC socket.
|
when LibIPC::EventType::ExtraSocket # Message received from a non IPC socket.
|
||||||
return IPC::Event::ExtraSocket.new event.origin, event.index
|
return IPC::Event::ExtraSocket.new event.origin, event.index
|
||||||
when LibIPC::EventType::Switch # Message to send to a corresponding fd.
|
when LibIPC::EventType::Switch # Message to send to a corresponding fd.
|
||||||
@ -79,8 +79,9 @@ class IPC::Context
|
|||||||
when LibIPC::EventType::Disconnection # User disconnected.
|
when LibIPC::EventType::Disconnection # User disconnected.
|
||||||
return IPC::Event::Disconnection.new event.origin, event.index
|
return IPC::Event::Disconnection.new event.origin, event.index
|
||||||
when LibIPC::EventType::Message # New message.
|
when LibIPC::EventType::Message # New message.
|
||||||
message = event.message.unsafe_as(Pointer(LibIPC::Message))
|
lowlevel_message = event.message.unsafe_as(Pointer(LibIPC::Message))
|
||||||
return IPC::Event::MessageReceived.new event.origin, event.index, message
|
ipc_message = IPC::Message.new lowlevel_message
|
||||||
|
return IPC::Event::MessageReceived.new event.origin, event.index, ipc_message
|
||||||
when LibIPC::EventType::LookUp # Client asking for a service through ipcd.
|
when LibIPC::EventType::LookUp # Client asking for a service through ipcd.
|
||||||
# for now, the libipc does not provide lookup events
|
# for now, the libipc does not provide lookup events
|
||||||
# ipcd uses a simple LibIPC::EventType::Message
|
# ipcd uses a simple LibIPC::EventType::Message
|
||||||
@ -88,10 +89,10 @@ class IPC::Context
|
|||||||
when LibIPC::EventType::Timer # Timeout in the poll(2) function.
|
when LibIPC::EventType::Timer # Timeout in the poll(2) function.
|
||||||
return IPC::Event::Timer.new
|
return IPC::Event::Timer.new
|
||||||
when LibIPC::EventType::Tx # Message sent.
|
when LibIPC::EventType::Tx # Message sent.
|
||||||
return IPC::Event::Tx.new event.origin, event.index
|
return IPC::Event::MessageSent.new event.origin, event.index
|
||||||
end
|
end
|
||||||
|
|
||||||
yield Exception.new "Cannot understand the event type: #{eventtype}"
|
return Exception.new "Cannot understand the event type: #{eventtype}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def loop(&block : Proc(IPC::Event::Events|Exception, Nil))
|
def loop(&block : Proc(IPC::Event::Events|Exception, Nil))
|
||||||
@ -122,8 +123,8 @@ class IPC::Context
|
|||||||
send(fd, utype, Bytes.new(payload.to_unsafe, payload.bytesize))
|
send(fd, utype, Bytes.new(payload.to_unsafe, payload.bytesize))
|
||||||
end
|
end
|
||||||
|
|
||||||
def send(fd : Int32, message : IPC::Message)
|
def send(message : IPC::Message)
|
||||||
send(fd, message.utype, message.payload)
|
send(message.fd, message.utype, message.payload)
|
||||||
end
|
end
|
||||||
|
|
||||||
def read(index : UInt32)
|
def read(index : UInt32)
|
||||||
|
@ -35,9 +35,9 @@ class IPC::Service < IPC::Context
|
|||||||
@service_info.fd
|
@service_info.fd
|
||||||
end
|
end
|
||||||
|
|
||||||
def loop(&block : Proc(IPC::Event::Events|Exception, Nil))
|
# def loop(&block : Proc(IPC::Event::Events|Exception, Nil))
|
||||||
super(@service_info, &block)
|
# super(@service_info, &block)
|
||||||
end
|
# end
|
||||||
|
|
||||||
def close
|
def close
|
||||||
@service_info.close
|
@service_info.close
|
||||||
|
Reference in New Issue
Block a user