2016-05-04 02:29:58 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <folly/dynamic.h>
|
|
|
|
|
2016-05-18 19:46:01 +00:00
|
|
|
#include "NativeToJsBridge.h"
|
2016-05-04 02:29:58 +00:00
|
|
|
#include "ModuleRegistry.h"
|
|
|
|
#include "NativeModule.h"
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
class JSExecutorFactory;
|
|
|
|
|
|
|
|
struct InstanceCallback {
|
|
|
|
virtual ~InstanceCallback() {}
|
|
|
|
virtual void onBatchComplete() = 0;
|
|
|
|
virtual void incrementPendingJSCalls() = 0;
|
|
|
|
virtual void decrementPendingJSCalls() = 0;
|
|
|
|
virtual void onNativeException(const std::string& what) = 0;
|
|
|
|
virtual ExecutorToken createExecutorToken() = 0;
|
2016-05-18 19:46:01 +00:00
|
|
|
virtual void onExecutorStopped(ExecutorToken) = 0;
|
2016-05-04 02:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Instance {
|
|
|
|
public:
|
|
|
|
~Instance();
|
|
|
|
void initializeBridge(
|
|
|
|
std::unique_ptr<InstanceCallback> callback,
|
|
|
|
std::shared_ptr<JSExecutorFactory> jsef,
|
|
|
|
std::shared_ptr<MessageQueueThread> jsQueue,
|
|
|
|
std::unique_ptr<MessageQueueThread> nativeQueue,
|
2016-05-11 18:38:47 +00:00
|
|
|
std::shared_ptr<ModuleRegistry> moduleRegistry);
|
2016-05-14 00:15:06 +00:00
|
|
|
void loadScriptFromString(std::unique_ptr<const JSBigString> string, std::string sourceURL);
|
2016-05-04 02:29:58 +00:00
|
|
|
void loadScriptFromFile(const std::string& filename, const std::string& sourceURL);
|
|
|
|
void loadUnbundle(
|
|
|
|
std::unique_ptr<JSModulesUnbundle> unbundle,
|
2016-05-14 00:15:06 +00:00
|
|
|
std::unique_ptr<const JSBigString> startupScript,
|
|
|
|
std::string startupScriptSourceURL);
|
2016-05-04 02:29:58 +00:00
|
|
|
bool supportsProfiling();
|
|
|
|
void startProfiler(const std::string& title);
|
|
|
|
void stopProfiler(const std::string& title, const std::string& filename);
|
2016-05-14 00:15:06 +00:00
|
|
|
void setGlobalVariable(std::string propName, std::unique_ptr<const JSBigString> jsonValue);
|
2016-05-04 02:29:58 +00:00
|
|
|
void callJSFunction(ExecutorToken token, const std::string& module, const std::string& method,
|
|
|
|
folly::dynamic&& params, const std::string& tracingName);
|
|
|
|
void callJSCallback(ExecutorToken token, uint64_t callbackId, folly::dynamic&& params);
|
2016-05-18 19:46:01 +00:00
|
|
|
MethodCallResult callSerializableNativeHook(ExecutorToken token, unsigned int moduleId,
|
|
|
|
unsigned int methodId, folly::dynamic&& args);
|
2016-05-04 02:29:58 +00:00
|
|
|
ExecutorToken getMainExecutorToken();
|
2016-05-26 18:07:41 +00:00
|
|
|
void handleMemoryPressureUiHidden();
|
|
|
|
void handleMemoryPressureModerate();
|
|
|
|
void handleMemoryPressureCritical();
|
2016-05-04 02:29:58 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void callNativeModules(ExecutorToken token, const std::string& calls, bool isEndOfBatch);
|
|
|
|
|
2016-05-18 19:46:01 +00:00
|
|
|
std::shared_ptr<InstanceCallback> callback_;
|
|
|
|
std::unique_ptr<NativeToJsBridge> nativeToJsBridge_;
|
2016-05-04 02:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|