diff --git a/binding.gyp b/binding.gyp index c98dd836..55075262 100644 --- a/binding.gyp +++ b/binding.gyp @@ -27,11 +27,6 @@ "sources": [ "src/node/node_init.cpp" ] - }], - ["realm_enable_sync", { - "sources": [ - "src/node/node_sync_logger.cpp" - ] }] ] }, diff --git a/src/js_sync.hpp b/src/js_sync.hpp index d859b783..ac50d786 100644 --- a/src/js_sync.hpp +++ b/src/js_sync.hpp @@ -30,10 +30,6 @@ #include "realm/util/logger.hpp" #include "realm/util/uri.hpp" -#if REALM_PLATFORM_NODE -#include "node/node_sync_logger.hpp" -#endif - namespace realm { namespace js { @@ -59,10 +55,6 @@ public: static void set_sync_log_level(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); static void set_verify_servers_ssl_certificate(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); -#if REALM_PLATFORM_NODE - static void set_sync_logger(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); -#endif - // private static void refresh_access_token(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); static void populate_sync_config(ContextType, ObjectType config_object, Realm::Config&); @@ -73,10 +65,7 @@ public: MethodMap const static_methods = { {"refreshAccessToken", wrap}, {"setLogLevel", wrap}, - {"setVerifyServersSslCertificate", wrap}, -#if REALM_PLATFORM_NODE - {"setSyncLogger", wrap}, -#endif + {"setVerifyServersSslCertificate", wrap} }; }; @@ -153,16 +142,6 @@ void SyncClass::set_verify_servers_ssl_certificate(ContextType ctx, ObjectTyp realm::SyncManager::shared().set_client_should_validate_ssl(verify_servers_ssl_certificate); } -#if REALM_PLATFORM_NODE -template -void SyncClass::set_sync_logger(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { - validate_argument_count(argc, 1); - auto callback = Value::validated_to_function(ctx, arguments[0]); - node::SyncLoggerFactory *factory = new node::SyncLoggerFactory(ctx, this_object, callback); // Throws - realm::SyncManager::shared().set_logger_factory(*factory); -} -#endif - template void SyncClass::refresh_access_token(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 2); diff --git a/src/node/node_sync_logger.cpp b/src/node/node_sync_logger.cpp deleted file mode 100644 index 5d66bbc6..00000000 --- a/src/node/node_sync_logger.cpp +++ /dev/null @@ -1,94 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// -// Copyright 2016 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////// - -#include -#include -#include - -#include "node_init.hpp" -#include "node_class.hpp" -#include "js_realm.hpp" -#include "node_types.hpp" -#include "node_sync_logger.hpp" - -namespace realm { -namespace node { - -SyncLoggerQueue::~SyncLoggerQueue() noexcept -{ - m_callback_this_object.Reset(); - m_callback.Reset(); -} - -void SyncLoggerQueue::log_uv_callback() -{ - // This function is always executed by the Node.js event loop - // thread. - Nan::HandleScope scope; - v8::Local this_object = Nan::New(m_callback_this_object); - v8::Local callback = Nan::New(m_callback); - - std::queue popped; - { - std::lock_guard lock(m_mutex); // Throws - popped.swap(m_log_queue); - } - - for (;;) { - if (popped.empty()) - break; - - Nan::TryCatch trycatch; - v8::Local argv[] = { - Nan::New((int)(popped.front().m_level)), - Nan::New(popped.front().m_message).ToLocalChecked() - }; - Nan::MakeCallback(this_object, callback, 2, argv); - if (trycatch.HasCaught()) { - throw node::Exception(m_v8_isolate, trycatch.Exception()); - } - popped.pop(); - } -} - -void SyncLogger::do_log(realm::util::Logger::Level level, std::string message) -{ - std::lock_guard lock(m_mutex); // Throws - m_log_queue.emplace(level, message); - m_log_uv_async.send(); -} - -SyncLoggerFactory::~SyncLoggerFactory() noexcept -{ - m_callback_this_object.Reset(); - m_callback.Reset(); -} - -std::unique_ptr SyncLoggerFactory::make_logger(util::Logger::Level level) -{ - v8::Local this_object = Nan::New(m_callback_this_object); - v8::Local callback = Nan::New(m_callback); - - SyncLogger *logger = new SyncLogger(m_v8_isolate, this_object, callback); // Throws - logger->set_level_threshold(level); - - return std::unique_ptr(logger); -} - -} // namespace node -} // namespace realm diff --git a/src/node/node_sync_logger.hpp b/src/node/node_sync_logger.hpp deleted file mode 100644 index aec87cbd..00000000 --- a/src/node/node_sync_logger.hpp +++ /dev/null @@ -1,89 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// -// Copyright 2016 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////// - -#ifndef REALM_NODE_GLOBAL_LOGGER_HPP -#define REALM_NODE_GLOBAL_LOGGER_HPP - -#include -#include -#include - -#include - -#include "node_uv_async.hpp" - -namespace realm { -namespace node { - - struct SyncLoggerMessage { - std::string m_message; - realm::util::Logger::Level m_level; - SyncLoggerMessage(realm::util::Logger::Level level, std::string message): - m_message(message), - m_level(level) { } - }; - - class SyncLoggerQueue { - public: - SyncLoggerQueue(v8::Isolate* v8_isolate, v8::Local callback_this_object, v8::Local callback) : - m_log_uv_async([this] { log_uv_callback(); }), // Throws - m_v8_isolate(v8_isolate), - m_callback_this_object(callback_this_object), - m_callback(callback) { } - ~SyncLoggerQueue() noexcept; - - protected: - void log_uv_callback(); - std::queue m_log_queue; - std::mutex m_mutex; - UvAsync m_log_uv_async; - - private: - v8::Isolate* m_v8_isolate; - Nan::Persistent m_callback_this_object; - Nan::Persistent m_callback; - }; - - class SyncLogger: public realm::util::RootLogger, public SyncLoggerQueue { - public: - SyncLogger(v8::Isolate* v8_isolate, v8::Local callback_this_object, v8::Local callback) : - SyncLoggerQueue(v8_isolate, callback_this_object, callback) { } - - protected: - void do_log(realm::util::Logger::Level, std::string) override final; - }; - - class SyncLoggerFactory : public realm::SyncLoggerFactory { - public: - SyncLoggerFactory(v8::Isolate* v8_isolate, v8::Local callback_this_object, v8::Local callback) : - m_v8_isolate(v8_isolate), - m_callback_this_object(callback_this_object), - m_callback(callback) { } - ~SyncLoggerFactory() noexcept; - - virtual std::unique_ptr make_logger(util::Logger::Level level); - private: - v8::Isolate* m_v8_isolate; - Nan::Persistent m_callback_this_object; - Nan::Persistent m_callback; - }; - -} // namespace node -} // namespace realm - -#endif // REALM_NODE_GLOBAL_LOGGER_HPP