2019-10-16 20:03:47 +03:00
|
|
|
/*
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2017-03-17 16:55:44 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-03-17 16:55:44 +03:00
|
|
|
*/
|
|
|
|
|
2019-02-28 11:49:49 +03:00
|
|
|
#include <glog/logging.h>
|
|
|
|
|
2017-04-11 21:57:06 +03:00
|
|
|
#include <React/RCTLog.h>
|
2017-03-17 16:55:44 +03:00
|
|
|
#include <cxxreact/MessageQueueThread.h>
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
// RCTNativeModule arranges for native methods to be invoked on a queue which
|
|
|
|
// is not the JS thread. C++ modules don't use RCTNativeModule, so this little
|
|
|
|
// adapter does the work.
|
|
|
|
|
|
|
|
class DispatchMessageQueueThread : public MessageQueueThread {
|
2020-03-09 08:58:01 +03:00
|
|
|
public:
|
|
|
|
DispatchMessageQueueThread(RCTModuleData *moduleData) : moduleData_(moduleData) {}
|
2017-03-17 16:55:44 +03:00
|
|
|
|
2020-03-09 08:58:01 +03:00
|
|
|
void runOnQueue(std::function<void()> &&func) override
|
|
|
|
{
|
2017-04-11 21:57:06 +03:00
|
|
|
dispatch_queue_t queue = moduleData_.methodQueue;
|
2020-03-09 08:58:01 +03:00
|
|
|
dispatch_block_t block = [func = std::move(func)] { func(); };
|
2017-04-11 21:57:06 +03:00
|
|
|
RCTAssert(block != nullptr, @"Invalid block generated in call to %@", moduleData_);
|
|
|
|
if (queue && block) {
|
|
|
|
dispatch_async(queue, block);
|
|
|
|
}
|
2017-03-17 16:55:44 +03:00
|
|
|
}
|
2020-03-09 08:58:01 +03:00
|
|
|
void runOnQueueSync(std::function<void()> &&__unused func) override
|
|
|
|
{
|
2017-03-17 16:55:44 +03:00
|
|
|
LOG(FATAL) << "Unsupported operation";
|
|
|
|
}
|
2020-03-09 08:58:01 +03:00
|
|
|
void quitSynchronous() override
|
|
|
|
{
|
2017-03-17 16:55:44 +03:00
|
|
|
LOG(FATAL) << "Unsupported operation";
|
|
|
|
}
|
|
|
|
|
2020-03-09 08:58:01 +03:00
|
|
|
private:
|
2017-03-17 16:55:44 +03:00
|
|
|
RCTModuleData *moduleData_;
|
|
|
|
};
|
|
|
|
|
2020-03-09 08:58:01 +03:00
|
|
|
}
|
|
|
|
}
|