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-08-03 15:58:45 -07:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cxxreact/CxxModule.h>
|
2017-02-15 09:49:07 -08:00
|
|
|
#include <cxxreact/NativeModule.h>
|
2016-08-03 15:58:45 -07:00
|
|
|
|
2017-06-27 11:15:36 -07:00
|
|
|
#ifndef RN_EXPORT
|
|
|
|
#define RN_EXPORT __attribute__((visibility("default")))
|
|
|
|
#endif
|
|
|
|
|
2016-08-03 15:58:45 -07:00
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
class Instance;
|
2017-06-23 16:49:55 -07:00
|
|
|
class MessageQueueThread;
|
2016-08-03 15:58:45 -07:00
|
|
|
|
|
|
|
std::function<void(folly::dynamic)> makeCallback(
|
2017-04-25 05:29:45 -07:00
|
|
|
std::weak_ptr<Instance> instance, const folly::dynamic& callbackId);
|
2016-08-03 15:58:45 -07:00
|
|
|
|
2017-06-27 11:15:36 -07:00
|
|
|
class RN_EXPORT CxxNativeModule : public NativeModule {
|
2016-08-03 15:58:45 -07:00
|
|
|
public:
|
2017-03-17 06:55:37 -07:00
|
|
|
CxxNativeModule(std::weak_ptr<Instance> instance,
|
|
|
|
std::string name,
|
|
|
|
xplat::module::CxxModule::Provider provider,
|
|
|
|
std::shared_ptr<MessageQueueThread> messageQueueThread)
|
|
|
|
: instance_(instance)
|
|
|
|
, name_(std::move(name))
|
|
|
|
, provider_(provider)
|
|
|
|
, messageQueueThread_(messageQueueThread) {}
|
2016-08-03 15:58:45 -07:00
|
|
|
|
|
|
|
std::string getName() override;
|
|
|
|
std::vector<MethodDescriptor> getMethods() override;
|
|
|
|
folly::dynamic getConstants() override;
|
2017-05-12 17:57:12 -07:00
|
|
|
void invoke(unsigned int reactMethodId, folly::dynamic&& params, int callId) override;
|
2017-04-25 05:29:45 -07:00
|
|
|
MethodCallResult callSerializableNativeHook(unsigned int hookId, folly::dynamic&& args) override;
|
2016-08-03 15:58:45 -07:00
|
|
|
|
|
|
|
private:
|
2017-03-14 15:28:53 -07:00
|
|
|
void lazyInit();
|
|
|
|
|
2016-08-03 15:58:45 -07:00
|
|
|
std::weak_ptr<Instance> instance_;
|
2017-03-14 15:28:53 -07:00
|
|
|
std::string name_;
|
|
|
|
xplat::module::CxxModule::Provider provider_;
|
2017-03-17 06:55:37 -07:00
|
|
|
std::shared_ptr<MessageQueueThread> messageQueueThread_;
|
2016-08-03 15:58:45 -07:00
|
|
|
std::unique_ptr<xplat::module::CxxModule> module_;
|
|
|
|
std::vector<xplat::module::CxxModule::Method> methods_;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|