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