2018-09-11 22:27:47 +00:00
|
|
|
// Copyright (c) Facebook, Inc. and its affiliates.
|
2018-05-31 22:31:03 +00:00
|
|
|
|
|
|
|
// This source code is licensed under the MIT license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree.
|
2016-05-04 02:29:58 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-06-23 23:49:55 +00:00
|
|
|
#include <condition_variable>
|
2016-05-04 02:29:58 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2017-02-15 17:49:07 +00:00
|
|
|
#include <cxxreact/NativeToJsBridge.h>
|
2017-06-23 23:49:55 +00:00
|
|
|
|
2017-06-27 18:15:36 +00:00
|
|
|
#ifndef RN_EXPORT
|
|
|
|
#define RN_EXPORT __attribute__((visibility("default")))
|
|
|
|
#endif
|
|
|
|
|
2017-06-23 23:49:55 +00:00
|
|
|
namespace folly {
|
2017-08-10 17:44:10 +00:00
|
|
|
struct dynamic;
|
2017-06-23 23:49:55 +00:00
|
|
|
}
|
2016-05-04 02:29:58 +00:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
2017-06-23 23:49:55 +00:00
|
|
|
class JSBigString;
|
2016-05-04 02:29:58 +00:00
|
|
|
class JSExecutorFactory;
|
2017-06-23 23:49:55 +00:00
|
|
|
class MessageQueueThread;
|
|
|
|
class ModuleRegistry;
|
2017-09-22 16:56:50 +00:00
|
|
|
class RAMBundleRegistry;
|
2016-05-04 02:29:58 +00:00
|
|
|
|
|
|
|
struct InstanceCallback {
|
|
|
|
virtual ~InstanceCallback() {}
|
2017-09-11 11:24:29 +00:00
|
|
|
virtual void onBatchComplete() {}
|
|
|
|
virtual void incrementPendingJSCalls() {}
|
|
|
|
virtual void decrementPendingJSCalls() {}
|
2016-05-04 02:29:58 +00:00
|
|
|
};
|
|
|
|
|
2017-06-27 18:15:36 +00:00
|
|
|
class RN_EXPORT Instance {
|
2017-08-10 17:44:10 +00:00
|
|
|
public:
|
2016-05-04 02:29:58 +00:00
|
|
|
~Instance();
|
2017-08-10 17:44:10 +00:00
|
|
|
void initializeBridge(std::unique_ptr<InstanceCallback> callback,
|
|
|
|
std::shared_ptr<JSExecutorFactory> jsef,
|
|
|
|
std::shared_ptr<MessageQueueThread> jsQueue,
|
|
|
|
std::shared_ptr<ModuleRegistry> moduleRegistry);
|
2017-01-18 16:55:46 +00:00
|
|
|
|
|
|
|
void setSourceURL(std::string sourceURL);
|
|
|
|
|
2017-08-10 17:44:10 +00:00
|
|
|
void loadScriptFromString(std::unique_ptr<const JSBigString> string,
|
|
|
|
std::string sourceURL, bool loadSynchronously);
|
2017-11-03 12:17:23 +00:00
|
|
|
static bool isIndexedRAMBundle(const char *sourcePath);
|
|
|
|
void loadRAMBundleFromFile(const std::string& sourcePath,
|
|
|
|
const std::string& sourceURL,
|
|
|
|
bool loadSynchronously);
|
2017-09-22 16:56:50 +00:00
|
|
|
void loadRAMBundle(std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
|
|
|
std::unique_ptr<const JSBigString> startupScript,
|
|
|
|
std::string startupScriptSourceURL, bool loadSynchronously);
|
2016-05-04 02:29:58 +00:00
|
|
|
bool supportsProfiling();
|
2017-08-10 17:44:10 +00:00
|
|
|
void setGlobalVariable(std::string propName,
|
|
|
|
std::unique_ptr<const JSBigString> jsonValue);
|
2016-10-26 10:43:05 +00:00
|
|
|
void *getJavaScriptContext();
|
2017-12-18 21:19:37 +00:00
|
|
|
bool isInspectable();
|
2017-08-10 17:44:10 +00:00
|
|
|
void callJSFunction(std::string &&module, std::string &&method,
|
|
|
|
folly::dynamic &¶ms);
|
|
|
|
void callJSCallback(uint64_t callbackId, folly::dynamic &¶ms);
|
2017-06-23 23:49:55 +00:00
|
|
|
|
2017-11-09 19:55:37 +00:00
|
|
|
// This method is experimental, and may be modified or removed.
|
|
|
|
void registerBundle(uint32_t bundleId, const std::string& bundlePath);
|
|
|
|
|
2017-08-10 17:44:10 +00:00
|
|
|
const ModuleRegistry &getModuleRegistry() const;
|
|
|
|
ModuleRegistry &getModuleRegistry();
|
|
|
|
|
2017-06-26 12:48:40 +00:00
|
|
|
void handleMemoryPressure(int pressureLevel);
|
2017-08-10 17:44:10 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void callNativeModules(folly::dynamic &&calls, bool isEndOfBatch);
|
2017-09-22 16:56:50 +00:00
|
|
|
void loadApplication(std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
2017-08-10 17:44:10 +00:00
|
|
|
std::unique_ptr<const JSBigString> startupScript,
|
|
|
|
std::string startupScriptSourceURL);
|
2017-09-22 16:56:50 +00:00
|
|
|
void loadApplicationSync(std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
2017-08-10 17:44:10 +00:00
|
|
|
std::unique_ptr<const JSBigString> startupScript,
|
|
|
|
std::string startupScriptSourceURL);
|
2016-05-04 02:29:58 +00:00
|
|
|
|
2016-05-18 19:46:01 +00:00
|
|
|
std::shared_ptr<InstanceCallback> callback_;
|
|
|
|
std::unique_ptr<NativeToJsBridge> nativeToJsBridge_;
|
2017-06-21 18:56:08 +00:00
|
|
|
std::shared_ptr<ModuleRegistry> moduleRegistry_;
|
2016-09-26 23:01:42 +00:00
|
|
|
|
|
|
|
std::mutex m_syncMutex;
|
|
|
|
std::condition_variable m_syncCV;
|
|
|
|
bool m_syncReady = false;
|
2016-05-04 02:29:58 +00:00
|
|
|
};
|
|
|
|
|
2017-08-10 17:44:10 +00:00
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|