api.go 985 B

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