moduleManager.go 1.6 KB

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