server_interfaces.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package dbus
  2. // Terminator allows a handler to implement a shutdown mechanism that
  3. // is called when the connection terminates.
  4. type Terminator interface {
  5. Terminate()
  6. }
  7. // Handler is the representation of a D-Bus Application.
  8. //
  9. // The Handler must have a way to lookup objects given
  10. // an ObjectPath. The returned object must implement the
  11. // ServerObject interface.
  12. type Handler interface {
  13. LookupObject(path ObjectPath) (ServerObject, bool)
  14. }
  15. // ServerObject is the representation of an D-Bus Object.
  16. //
  17. // Objects are registered at a path for a given Handler.
  18. // The Objects implement D-Bus interfaces. The semantics
  19. // of Interface lookup is up to the implementation of
  20. // the ServerObject. The ServerObject implementation may
  21. // choose to implement empty string as a valid interface
  22. // represeting all methods or not per the D-Bus specification.
  23. type ServerObject interface {
  24. LookupInterface(name string) (Interface, bool)
  25. }
  26. // An Interface is the representation of a D-Bus Interface.
  27. //
  28. // Interfaces are a grouping of methods implemented by the Objects.
  29. // Interfaces are responsible for routing method calls.
  30. type Interface interface {
  31. LookupMethod(name string) (Method, bool)
  32. }
  33. // A Method represents the exposed methods on D-Bus.
  34. type Method interface {
  35. // Call requires that all arguments are decoded before being passed to it.
  36. Call(args ...interface{}) ([]interface{}, error)
  37. NumArguments() int
  38. NumReturns() int
  39. // ArgumentValue returns a representative value for the argument at position
  40. // it should be of the proper type. reflect.Zero would be a good mechanism
  41. // to use for this Value.
  42. ArgumentValue(position int) interface{}
  43. // ReturnValue returns a representative value for the return at position
  44. // it should be of the proper type. reflect.Zero would be a good mechanism
  45. // to use for this Value.
  46. ReturnValue(position int) interface{}
  47. }
  48. // An Argument Decoder can decode arguments using the non-standard mechanism
  49. //
  50. // If a method implements this interface then the non-standard
  51. // decoder will be used.
  52. //
  53. // Method arguments must be decoded from the message.
  54. // The mechanism for doing this will vary based on the
  55. // implementation of the method. A normal approach is provided
  56. // as part of this library, but may be replaced with
  57. // any other decoding scheme.
  58. type ArgumentDecoder interface {
  59. // To decode the arguments of a method the sender and message are
  60. // provided incase the semantics of the implementer provides access
  61. // to these as part of the method invocation.
  62. DecodeArguments(conn *Conn, sender string, msg *Message, args []interface{}) ([]interface{}, error)
  63. }
  64. // A SignalHandler is responsible for delivering a signal.
  65. //
  66. // Signal delivery may be changed from the default channel
  67. // based approach by Handlers implementing the SignalHandler
  68. // interface.
  69. type SignalHandler interface {
  70. DeliverSignal(iface, name string, signal *Signal)
  71. }
  72. // A DBusError is used to convert a generic object to a D-Bus error.
  73. //
  74. // Any custom error mechanism may implement this interface to provide
  75. // a custom encoding of the error on D-Bus. By default if a normal
  76. // error is returned, it will be encoded as the generic
  77. // "org.freedesktop.DBus.Error.Failed" error. By implementing this
  78. // interface as well a custom encoding may be provided.
  79. type DBusError interface {
  80. DBusError() (string, []interface{})
  81. }
  82. // SerialGenerator is responsible for serials generation.
  83. //
  84. // Different approaches for the serial generation can be used,
  85. // maintaining a map guarded with a mutex (the standard way) or
  86. // simply increment an atomic counter.
  87. type SerialGenerator interface {
  88. GetSerial() uint32
  89. RetireSerial(serial uint32)
  90. }