2017-09-21 15:34:44 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2017-11-08 11:50:36 +00:00
|
|
|
#include <functional>
|
2017-09-21 15:34:44 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include <cxxreact/JSModulesUnbundle.h>
|
2017-09-22 16:56:50 +00:00
|
|
|
#include <jschelpers/noncopyable.h>
|
|
|
|
|
|
|
|
#ifndef RN_EXPORT
|
|
|
|
#define RN_EXPORT __attribute__((visibility("default")))
|
|
|
|
#endif
|
2017-09-21 15:34:44 +00:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
2017-09-22 16:56:50 +00:00
|
|
|
class RN_EXPORT RAMBundleRegistry : noncopyable {
|
2017-09-21 15:34:44 +00:00
|
|
|
public:
|
2017-11-08 11:50:36 +00:00
|
|
|
using unique_ram_bundle = std::unique_ptr<JSModulesUnbundle>;
|
2017-11-09 19:55:37 +00:00
|
|
|
using bundle_path = std::string;
|
2017-09-21 15:34:44 +00:00
|
|
|
constexpr static uint32_t MAIN_BUNDLE_ID = 0;
|
|
|
|
|
2017-11-08 11:50:36 +00:00
|
|
|
static std::unique_ptr<RAMBundleRegistry> singleBundleRegistry(unique_ram_bundle mainBundle);
|
2017-11-09 19:55:37 +00:00
|
|
|
static std::unique_ptr<RAMBundleRegistry> multipleBundlesRegistry(unique_ram_bundle mainBundle, std::function<unique_ram_bundle(bundle_path)> factory);
|
2017-11-08 11:50:36 +00:00
|
|
|
|
2017-09-22 16:56:50 +00:00
|
|
|
RAMBundleRegistry(RAMBundleRegistry&&) = default;
|
|
|
|
RAMBundleRegistry& operator=(RAMBundleRegistry&&) = default;
|
|
|
|
|
2017-11-09 19:55:37 +00:00
|
|
|
void registerBundle(uint32_t bundleId, bundle_path bundlePath);
|
2017-09-21 15:34:44 +00:00
|
|
|
JSModulesUnbundle::Module getModule(uint32_t bundleId, uint32_t moduleId);
|
2017-09-22 16:56:50 +00:00
|
|
|
virtual ~RAMBundleRegistry() {};
|
2017-09-21 15:34:44 +00:00
|
|
|
private:
|
2017-11-09 19:55:37 +00:00
|
|
|
explicit RAMBundleRegistry(unique_ram_bundle mainBundle, std::function<unique_ram_bundle(bundle_path)> factory = {});
|
2017-09-21 15:34:44 +00:00
|
|
|
JSModulesUnbundle *getBundle(uint32_t bundleId) const;
|
|
|
|
|
2017-11-09 19:55:37 +00:00
|
|
|
std::function<unique_ram_bundle(bundle_path)> m_factory;
|
|
|
|
std::unordered_map<uint32_t, bundle_path> m_bundlePaths;
|
2017-11-08 11:50:36 +00:00
|
|
|
std::unordered_map<uint32_t, unique_ram_bundle> m_bundles;
|
2017-09-21 15:34:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|