example.idl 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. (def-newtype time_micros_t sint64_t)
  2. -- comments should be haskell style, because we're suing parsec's haskell lexer
  3. -- enums default to 32 bit width if you don't really care
  4. (def-enum mode_t
  5. ((stabilize 0)
  6. (auto 1)))
  7. -- or you can specify a width
  8. (def-enum armed_t
  9. 8
  10. ((disarmed 0)
  11. (armed 1)))
  12. (def-struct heartbeat_t
  13. ((time time_micros_t)
  14. (armed armed_t)))
  15. (def-newtype lat_t sint32_t)
  16. (def-newtype lon_t sint32_t)
  17. -- Todo: allow attaching unit annotations to newtypes. The code generator will
  18. -- provide the units as a human readable comment, and/or in some type/unit
  19. -- system supported by the host language.
  20. -- Todo: allow attaching predicates to newtypes. e.g., lon_t might have some
  21. -- type (degrees * 10e-6), some predicate
  22. -- (lambda (v) (and (gt v -180000000) (lte v 180000000)))
  23. (def-newtype meters_t float_t)
  24. (def-struct coordinate_t
  25. ((lat lat_t)
  26. (lon lon_t)
  27. (alt meters_t)))
  28. (def-newtype waypoint_t coordinate_t)
  29. -- Todo: the following interface syntax and semantics are a strawman.
  30. -- Interfaces have methods that are either streams or attrs.
  31. -- attrs take a parameter for access control.
  32. -- streams take a parameter for their default period in hz (none should default
  33. -- to zero). they also implicitly define an attr $(steamname)-stream-rate,
  34. -- which permits changing the stream rate at runtime.
  35. (def-interface vehicle_i
  36. ((heartbeat (stream 10 heartbeat_t))))
  37. -- Interfaces implement java-style inheritance. No shadowing of inherited method
  38. -- names permitted.
  39. (def-interface controllable_vehicle_i
  40. ((current_waypoint (attr read waypoint_t))
  41. (next_waypoint (attr readwrite waypoint_t)))
  42. (vehicle_i)) -- Inherits from interface vehicle
  43. -- The idea here is that, when negotiating a gidl connection, the client can
  44. -- specify or negotiate what interface is supported.
  45. -- this may be communicated by just sending the string name, or potentially by
  46. -- sending the entire serialized schema. At very least, the client and server
  47. -- should check agreement of their type schemas, probably by having the client
  48. -- send a sha1-hash of the serialized type schema.
  49. -- This allows us to specify various kinds of vehicles might exist without
  50. -- repeating ourselves, and provides a way to
  51. -- manage new functionality without breaking legacy code.