moduleManager.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. //g.AudioLibRegister() //work in progress
  46. g.ZipLibRegister()
  47. //Only register ffmpeg lib if host OS have ffmpeg installed
  48. ffmpegExists, _ := apt.PackageExists("ffmpeg")
  49. if ffmpegExists {
  50. g.FFmpegLibRegister()
  51. } else {
  52. log.Println("[AGI] ffmpeg not installed on host OS. Bypassing module.")
  53. }
  54. }