2016-08-03 22:58:45 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cxxreact/CxxModule.h>
|
2017-02-15 17:49:07 +00:00
|
|
|
#include <cxxreact/NativeModule.h>
|
2016-08-03 22:58:45 +00:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
class Instance;
|
|
|
|
|
|
|
|
std::function<void(folly::dynamic)> makeCallback(
|
2017-04-25 12:29:45 +00:00
|
|
|
std::weak_ptr<Instance> instance, const folly::dynamic& callbackId);
|
2016-08-03 22:58:45 +00:00
|
|
|
|
|
|
|
class CxxNativeModule : public NativeModule {
|
|
|
|
public:
|
2017-03-17 13:55:37 +00: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 22:58:45 +00:00
|
|
|
|
|
|
|
std::string getName() override;
|
|
|
|
std::vector<MethodDescriptor> getMethods() override;
|
|
|
|
folly::dynamic getConstants() override;
|
2017-04-25 12:29:45 +00:00
|
|
|
void invoke(unsigned int reactMethodId, folly::dynamic&& params) override;
|
|
|
|
MethodCallResult callSerializableNativeHook(unsigned int hookId, folly::dynamic&& args) override;
|
2016-08-03 22:58:45 +00:00
|
|
|
|
|
|
|
private:
|
2017-03-14 22:28:53 +00:00
|
|
|
void lazyInit();
|
|
|
|
|
2016-08-03 22:58:45 +00:00
|
|
|
std::weak_ptr<Instance> instance_;
|
2017-03-14 22:28:53 +00:00
|
|
|
std::string name_;
|
|
|
|
xplat::module::CxxModule::Provider provider_;
|
2017-03-17 13:55:37 +00:00
|
|
|
std::shared_ptr<MessageQueueThread> messageQueueThread_;
|
2016-08-03 22:58:45 +00:00
|
|
|
std::unique_ptr<xplat::module::CxxModule> module_;
|
|
|
|
std::vector<xplat::module::CxxModule::Method> methods_;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|