2016-05-04 02:29:58 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2016-07-11 13:52:06 +00:00
|
|
|
|
2017-06-23 23:49:55 +00:00
|
|
|
#include <cxxreact/NativeModule.h>
|
2016-05-18 19:46:01 +00:00
|
|
|
#include <folly/dynamic.h>
|
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 JSExecutor;
|
2016-10-03 12:07:41 +00:00
|
|
|
class JSModulesUnbundle;
|
2016-05-04 02:29:58 +00:00
|
|
|
class MessageQueueThread;
|
2016-10-03 12:07:41 +00:00
|
|
|
class ModuleRegistry;
|
2016-05-04 02:29:58 +00:00
|
|
|
|
2016-05-18 19:46:01 +00:00
|
|
|
// This interface describes the delegate interface required by
|
|
|
|
// Executor implementations to call from JS into native code.
|
|
|
|
class ExecutorDelegate {
|
|
|
|
public:
|
|
|
|
virtual ~ExecutorDelegate() {}
|
|
|
|
|
2016-10-03 12:07:41 +00:00
|
|
|
virtual std::shared_ptr<ModuleRegistry> getModuleRegistry() = 0;
|
|
|
|
|
2016-05-18 19:46:01 +00:00
|
|
|
virtual void callNativeModules(
|
2016-09-19 11:43:09 +00:00
|
|
|
JSExecutor& executor, folly::dynamic&& calls, bool isEndOfBatch) = 0;
|
2016-05-18 19:46:01 +00:00
|
|
|
virtual MethodCallResult callSerializableNativeHook(
|
|
|
|
JSExecutor& executor, unsigned int moduleId, unsigned int methodId, folly::dynamic&& args) = 0;
|
|
|
|
};
|
|
|
|
|
2016-05-04 02:29:58 +00:00
|
|
|
class JSExecutorFactory {
|
|
|
|
public:
|
|
|
|
virtual std::unique_ptr<JSExecutor> createJSExecutor(
|
2016-05-18 19:46:01 +00:00
|
|
|
std::shared_ptr<ExecutorDelegate> delegate,
|
|
|
|
std::shared_ptr<MessageQueueThread> jsQueue) = 0;
|
|
|
|
virtual ~JSExecutorFactory() {}
|
2016-05-04 02:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class JSExecutor {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Execute an application script bundle in the JS context.
|
|
|
|
*/
|
2016-05-14 00:15:06 +00:00
|
|
|
virtual void loadApplicationScript(std::unique_ptr<const JSBigString> script,
|
|
|
|
std::string sourceURL) = 0;
|
2016-05-04 02:29:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an application "unbundle" file
|
|
|
|
*/
|
|
|
|
virtual void setJSModulesUnbundle(std::unique_ptr<JSModulesUnbundle> bundle) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes BatchedBridge.callFunctionReturnFlushedQueue with the module ID,
|
|
|
|
* method ID and optional additional arguments in JS. The executor is responsible
|
|
|
|
* for using Bridge->callNativeModules to invoke any necessary native modules methods.
|
|
|
|
*/
|
|
|
|
virtual void callFunction(const std::string& moduleId, const std::string& methodId, const folly::dynamic& arguments) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes BatchedBridge.invokeCallbackAndReturnFlushedQueue with the cbID,
|
|
|
|
* and optional additional arguments in JS and returns the next queue. The executor
|
|
|
|
* is responsible for using Bridge->callNativeModules to invoke any necessary
|
|
|
|
* native modules methods.
|
|
|
|
*/
|
|
|
|
virtual void invokeCallback(const double callbackId, const folly::dynamic& arguments) = 0;
|
|
|
|
|
2016-05-14 00:15:06 +00:00
|
|
|
virtual void setGlobalVariable(std::string propName,
|
|
|
|
std::unique_ptr<const JSBigString> jsonValue) = 0;
|
2016-05-04 02:29:58 +00:00
|
|
|
virtual void* getJavaScriptContext() {
|
|
|
|
return nullptr;
|
2016-05-18 19:46:01 +00:00
|
|
|
}
|
2017-06-26 12:48:40 +00:00
|
|
|
|
|
|
|
virtual void handleMemoryPressure(int pressureLevel) {}
|
|
|
|
|
2016-05-18 19:46:01 +00:00
|
|
|
virtual void destroy() {}
|
|
|
|
virtual ~JSExecutor() {}
|
2016-05-04 02:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} }
|