BaseModule.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import ModuleManager from "./ModuleManager";
  2. import { ModuleStatus } from "./types/ModuleStatus";
  3. // type ModuleName = keyof Modules;
  4. export default abstract class BaseModule {
  5. protected moduleManager: ModuleManager;
  6. protected name: string;
  7. protected status: ModuleStatus;
  8. /**
  9. * Base Module
  10. *
  11. * @param {ModuleManager} moduleManager Module manager class
  12. * @param {string} name Module name
  13. */
  14. public constructor(moduleManager: ModuleManager, name: string) {
  15. this.moduleManager = moduleManager;
  16. this.name = name;
  17. this.status = "LOADED";
  18. // console.log(`Module (${this.name}) starting`);
  19. }
  20. /**
  21. * getName - Get module name
  22. *
  23. * @returns {string} name
  24. */
  25. public getName(): string {
  26. return this.name;
  27. }
  28. /**
  29. * getStatus - Get module status
  30. *
  31. * @returns {ModuleStatus} status
  32. */
  33. public getStatus(): ModuleStatus {
  34. return this.status;
  35. }
  36. /**
  37. * setStatus - Set module status
  38. *
  39. * @param {ModuleStatus} status Module status
  40. */
  41. protected setStatus(status: ModuleStatus): void {
  42. this.status = status;
  43. }
  44. /**
  45. * startup - Startup module
  46. */
  47. public startup(): void {
  48. console.log(`Module (${this.name}) starting`);
  49. this.setStatus("STARTING");
  50. }
  51. /**
  52. * started - called with the module has started
  53. */
  54. protected started(): void {
  55. console.log(`Module (${this.name}) started`);
  56. this.setStatus("STARTED");
  57. }
  58. /**
  59. * shutdown - Shutdown module
  60. */
  61. public shutdown(): void {
  62. console.log(`Module (${this.name}) stopping`);
  63. this.setStatus("STOPPING");
  64. }
  65. /**
  66. * stopped - called when the module has stopped
  67. */
  68. protected stopped(): void {
  69. console.log(`Module (${this.name}) stopped`);
  70. this.setStatus("STOPPED");
  71. }
  72. }