Add an untested non-Apple ExternalCommitHelper implementation
This commit is contained in:
parent
4c195c92e0
commit
178c562f2c
|
@ -0,0 +1,46 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright 2015 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 "external_commit_helper.hpp"
|
||||||
|
|
||||||
|
#include "realm_coordinator.hpp"
|
||||||
|
|
||||||
|
#include <realm/commit_log.hpp>
|
||||||
|
#include <realm/replication.hpp>
|
||||||
|
|
||||||
|
using namespace realm;
|
||||||
|
using namespace realm::_impl;
|
||||||
|
|
||||||
|
ExternalCommitHelper::ExternalCommitHelper(RealmCoordinator& parent)
|
||||||
|
: m_parent(parent)
|
||||||
|
, m_history(realm::make_client_history(parent.get_path(), parent.get_encryption_key().data()))
|
||||||
|
, m_sg(*m_history, parent.is_in_memory() ? SharedGroup::durability_MemOnly : SharedGroup::durability_Full,
|
||||||
|
parent.get_encryption_key().data())
|
||||||
|
, m_thread(std::async(std::launch::async, [=] {
|
||||||
|
while (m_sg.wait_for_change()) {
|
||||||
|
m_parent.on_change();
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ExternalCommitHelper::~ExternalCommitHelper()
|
||||||
|
{
|
||||||
|
m_sg.wait_for_change_release();
|
||||||
|
m_thread.wait(); // Wait for the thread to exit
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright 2015 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_EXTERNAL_COMMIT_HELPER_HPP
|
||||||
|
#define REALM_EXTERNAL_COMMIT_HELPER_HPP
|
||||||
|
|
||||||
|
#include <realm/group_shared.hpp>
|
||||||
|
|
||||||
|
#include <future>
|
||||||
|
|
||||||
|
namespace realm {
|
||||||
|
class ClientHistory;
|
||||||
|
|
||||||
|
namespace _impl {
|
||||||
|
class RealmCoordinator;
|
||||||
|
|
||||||
|
class ExternalCommitHelper {
|
||||||
|
public:
|
||||||
|
ExternalCommitHelper(RealmCoordinator& parent);
|
||||||
|
~ExternalCommitHelper();
|
||||||
|
|
||||||
|
// A no-op in this version, but needed for the Apple version
|
||||||
|
void notify_others() { }
|
||||||
|
|
||||||
|
private:
|
||||||
|
RealmCoordinator& m_parent;
|
||||||
|
|
||||||
|
// The listener thread
|
||||||
|
std::future<void> m_thread;
|
||||||
|
|
||||||
|
// A shared group used to listen for changes
|
||||||
|
std::unique_ptr<ClientHistory> m_history;
|
||||||
|
SharedGroup m_sg;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace _impl
|
||||||
|
} // namespace realm
|
||||||
|
|
||||||
|
#endif /* REALM_EXTERNAL_COMMIT_HELPER_HPP */
|
|
@ -45,6 +45,8 @@ public:
|
||||||
const Schema* get_schema() const noexcept;
|
const Schema* get_schema() const noexcept;
|
||||||
uint64_t get_schema_version() const noexcept { return m_config.schema_version; }
|
uint64_t get_schema_version() const noexcept { return m_config.schema_version; }
|
||||||
const std::string& get_path() const noexcept { return m_config.path; }
|
const std::string& get_path() const noexcept { return m_config.path; }
|
||||||
|
const std::vector<char>& get_encryption_key() const noexcept { return m_config.encryption_key; }
|
||||||
|
bool is_in_memory() const noexcept { return m_config.in_memory; }
|
||||||
|
|
||||||
// Asyncronously call notify() on every Realm instance for this coordinator's
|
// Asyncronously call notify() on every Realm instance for this coordinator's
|
||||||
// path, including those in other processes
|
// path, including those in other processes
|
||||||
|
|
Loading…
Reference in New Issue