api.go 910 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package bus
  2. import "time"
  3. //Channel Dispatch not in event because event and dispatch handler not same one.
  4. type ChnDispResult int
  5. const (
  6. DispatchSingle ChnDispResult = -1 + iota
  7. DispatchNone
  8. DispatchMulti
  9. )
  10. //Dispatch maybe a protocol object
  11. type IBusEvent interface {
  12. OnAttach(chn IChannel)
  13. OnDetach(chn IChannel)
  14. ChannelDispatch(stream []byte, argEvt interface{}) ChnDispResult
  15. }
  16. type IChannel interface {
  17. ID() string
  18. GetChan(id int) chan interface{}
  19. SetTimeout(time.Duration)
  20. SetEvent(evt IBusEvent, evtArgs interface{})
  21. GetEvent() IBusEvent
  22. GetBus() IBus
  23. }
  24. type IBus interface {
  25. Init() error
  26. Uninit()
  27. OpenChannel(chnID interface{}, router []chan interface{}) IChannel
  28. CloseChannel(chn IChannel) error
  29. ResetChannel(chn IChannel)
  30. ScanChannel(stream []byte, conn int) IChannel
  31. Send(chn IChannel, buff interface{}) (int, error)
  32. Recive(chn IChannel, buff interface{}) (int, error)
  33. }