subsys.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright (c) 2003-2004, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #ifndef TOR_SUBSYS_T
  6. #define TOR_SUBSYS_T
  7. #include <stdbool.h>
  8. struct dispatch_connector_t;
  9. /**
  10. * A subsystem is a part of Tor that is initialized, shut down, configured,
  11. * and connected to other parts of Tor.
  12. *
  13. * Subsystems
  14. **/
  15. typedef struct subsys_fns_t {
  16. /**
  17. * The name of this subsystem. It should be a programmer-readable
  18. * identifier.
  19. **/
  20. const char *name;
  21. /**
  22. * Whether this subsystem is supported -- that is, whether it is compiled
  23. * into Tor. For most subsystems, this should be true.
  24. **/
  25. bool supported;
  26. /**
  27. * The 'initialization level' for the subsystem. It should run from -100
  28. * through +100. The subsystems are initialized from lowest level to
  29. * highest, and shut down from highest level to lowest.
  30. **/
  31. int level;
  32. /**
  33. * Initialize any global components of this subsystem.
  34. *
  35. * This function MAY rely on any lower-level subsystem being initialized.
  36. *
  37. * This function MUST NOT rely on any runtime configuration information;
  38. * it is only for global state or pre-configuration state.
  39. *
  40. * This function MUST NOT have any parts that can fail.
  41. **/
  42. int (*initialize)(void);
  43. /**
  44. * Connect a subsystem to the message dispatch system.
  45. **/
  46. int (*add_pubsub)(struct dispatch_connector_t *);
  47. /**
  48. * Free all resources held by this subsystem.
  49. *
  50. * This function is not allowed to fail.
  51. **/
  52. void (*shutdown)(void);
  53. } subsys_fns_t;
  54. #define MIN_SUBSYS_LEVEL -100
  55. #define MAX_SUBSYS_LEVEL 100
  56. #endif