moduleManager.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package agi
  2. import (
  3. "errors"
  4. "log"
  5. "imuslab.com/arozos/mod/agi/static"
  6. apt "imuslab.com/arozos/mod/apt"
  7. )
  8. /*
  9. AGI Module Manager
  10. This interface handles the agi function module registartions
  11. and make sure the structures of all modules fits the pre-defined
  12. interface to be used by ArozOS Core system
  13. */
  14. // Lib interface, require vm, user, target system file handler and the vpath of the running script
  15. // This interface is called during injection (in user's term, require / import)
  16. // When called, the required agi function module will be injected into the virtual machine
  17. // which provide the function required for the vm code to interact with the real-systems
  18. type AgiLibInjectionIntergface func(*static.AgiLibInjectionPayload)
  19. type AgiLibInterface interface {
  20. GetLibraryID() string //Get the module unique name for import
  21. GetInjectFunction() AgiLibInjectionIntergface //Get the module injection point
  22. }
  23. // Register a library's identification name and its injection interface to the VM environment
  24. func (g *Gateway) RegisterLib(libname string, entryPoint AgiLibInjectionIntergface) error {
  25. _, ok := g.LoadedAGILibrary[libname]
  26. if ok {
  27. //This lib already registered. Return error
  28. return errors.New("This library name already registered")
  29. } else {
  30. g.LoadedAGILibrary[libname] = entryPoint
  31. }
  32. return nil
  33. }
  34. /*
  35. AGI Library Register List
  36. Add more library here if required
  37. */
  38. func (g *Gateway) LoadAllFunctionalModules() {
  39. g.ImageLibRegister()
  40. g.FileLibRegister()
  41. g.HTTPLibRegister()
  42. g.ShareLibRegister()
  43. g.IoTLibRegister()
  44. g.AppdataLibRegister()
  45. //Only register ffmpeg lib if host OS have ffmpeg installed
  46. ffmpegExists, _ := apt.PackageExists("ffmpeg")
  47. if ffmpegExists {
  48. g.FFmpegLibRegister()
  49. } else {
  50. log.Println("[AGI] ffmpeg not installed on host OS. Bypassing module.")
  51. }
  52. }