<commit_before>////////////////////////////////////////////////////////////////////////////
//
// 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_OBJECT_STORE_GLOBAL_NOTIFIER_HPP
#define REALM_OBJECT_STORE_GLOBAL_NOTIFIER_HPP

#include "admin_realm.hpp"
#include "results.hpp"
#include "shared_realm.hpp"
#include "sync/sync_config.hpp"

#include <realm/version_id.hpp>

#include <condition_variable>
#include <mutex>
#include <queue>
#include <unordered_map>

namespace realm {
namespace util {
    template<typename> class EventLoopSignal;
}

class SyncUser;
class SyncSession;

/// Used to listen for changes across all, or a subset of all Realms on a
/// particular sync server.
class GlobalNotifier : public std::enable_shared_from_this<GlobalNotifier>  {
public:
    class Callback;

    static std::shared_ptr<GlobalNotifier> shared_notifier(std::unique_ptr<Callback> callback, std::string local_root_dir,
                                                           std::string server_base_url, std::shared_ptr<SyncUser> user,
                                                           std::shared_ptr<ChangesetTransformer> transformer = nullptr);
    ~GlobalNotifier();

    // Start listening. No callbacks will be called until this function is
    // called. Must be called on the thread which notifications should be
    // delivered on.
    void start();

    // Stop calling callbacks until resume() is called. Must be called on the
    // notification thread.
    void pause();
    // Resume calling callbacks after a call to pause(). Must be called on the
    // notification thread.
    void resume();

    // Returns true if there are any Realms with calculated changes waiting to
    // be delivered.<commit_msg>update realm-js<commit_after>////////////////////////////////////////////////////////////////////////////
//
// 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_OBJECT_STORE_GLOBAL_NOTIFIER_HPP
#define REALM_OBJECT_STORE_GLOBAL_NOTIFIER_HPP

#include "admin_realm.hpp"
#include "results.hpp"
#include "shared_realm.hpp"
#include "sync/sync_config.hpp"

#include <realm/version_id.hpp>

#include <condition_variable>
#include <mutex>
#include <queue>
#include <unordered_map>

namespace realm {
namespace util {
    template<typename> class EventLoopSignal;
}

class SyncUser;
class SyncSession;

/// Used to listen for changes across all, or a subset of all Realms on a
/// particular sync server.
class GlobalNotifier : public std::enable_shared_from_this<GlobalNotifier>  {
public:
    class Callback;

    using ChangesetTransformer = sync::SyncHistory::ChangesetCooker;
    static std::shared_ptr<GlobalNotifier> shared_notifier(std::unique_ptr<Callback> callback, std::string local_root_dir,
                                                           std::string server_base_url, std::shared_ptr<SyncUser> user,
                                                           std::shared_ptr<ChangesetTransformer> transformer = nullptr);
    ~GlobalNotifier();

    // Start listening. No callbacks will be called until this function is
    // called. Must be called on the thread which notifications should be
    // delivered on.
    void start();

    // Stop calling callbacks until resume() is called. Must be called on the
    // notification thread.
    void pause();
    // Resume calling callbacks after a call to pause(). Must be called on the
    // notification thread.
    void resume();

    // Returns true if there are any Realms with calculated changes waiting to
    // be delivered.
{'fraction_non_alphanumeric': 0.144051850303157, 'fraction_numerical': 0.00334518084883964, 'mean_word_length': 2.4442044636429086, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7196708', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1170, 'n_words': 459}