RAMBundleRegistry.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #pragma once
  8. #include <cstdint>
  9. #include <functional>
  10. #include <memory>
  11. #include <unordered_map>
  12. #include <utility>
  13. #include <cxxreact/JSModulesUnbundle.h>
  14. #ifndef RN_EXPORT
  15. #define RN_EXPORT __attribute__((visibility("default")))
  16. #endif
  17. namespace facebook {
  18. namespace react {
  19. class RN_EXPORT RAMBundleRegistry {
  20. public:
  21. constexpr static uint32_t MAIN_BUNDLE_ID = 0;
  22. static std::unique_ptr<RAMBundleRegistry> singleBundleRegistry(
  23. std::unique_ptr<JSModulesUnbundle> mainBundle);
  24. static std::unique_ptr<RAMBundleRegistry> multipleBundlesRegistry(
  25. std::unique_ptr<JSModulesUnbundle> mainBundle,
  26. std::function<std::unique_ptr<JSModulesUnbundle>(std::string)> factory);
  27. explicit RAMBundleRegistry(
  28. std::unique_ptr<JSModulesUnbundle> mainBundle,
  29. std::function<std::unique_ptr<JSModulesUnbundle>(std::string)> factory =
  30. nullptr);
  31. RAMBundleRegistry(RAMBundleRegistry &&) = default;
  32. RAMBundleRegistry &operator=(RAMBundleRegistry &&) = default;
  33. void registerBundle(uint32_t bundleId, std::string bundlePath);
  34. JSModulesUnbundle::Module getModule(uint32_t bundleId, uint32_t moduleId);
  35. virtual ~RAMBundleRegistry(){};
  36. private:
  37. JSModulesUnbundle *getBundle(uint32_t bundleId) const;
  38. std::function<std::unique_ptr<JSModulesUnbundle>(std::string)> m_factory;
  39. std::unordered_map<uint32_t, std::string> m_bundlePaths;
  40. std::unordered_map<uint32_t, std::unique_ptr<JSModulesUnbundle>> m_bundles;
  41. };
  42. } // namespace react
  43. } // namespace facebook