Merge pull request #11 from realm/kd-rename-delegate-to-bindingcontext
Rename RealmDelegate to BindingContext
This commit is contained in:
commit
271432bd1c
|
@ -16,8 +16,8 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef REALM_DELEGATE_HPP
|
||||
#define REALM_DELEGATE_HPP
|
||||
#ifndef BINDING_CONTEXT_HPP
|
||||
#define BINDING_CONTEXT_HPP
|
||||
|
||||
#include "index_set.hpp"
|
||||
|
||||
|
@ -25,15 +25,15 @@
|
|||
#include <vector>
|
||||
|
||||
namespace realm {
|
||||
// RealmDelegate is the extension point for adding binding-specific behavior to
|
||||
// BindingContext is the extension point for adding binding-specific behavior to
|
||||
// a SharedRealm. It can be used to store additonal data associated with the
|
||||
// Realm which is needed by the binding, and there are several methods which
|
||||
// can be overridden to receive notifications of state changes within the Realm.
|
||||
//
|
||||
// A simple delegate implementation which lets the user register functions to be
|
||||
// A simple implementation which lets the user register functions to be
|
||||
// called on refresh could look like the following:
|
||||
//
|
||||
// class DelegateImplementation : public RealmDelegate {
|
||||
// class BindingContextImplementation : public BindingContext {
|
||||
// public:
|
||||
// // A token returned from add_notification that can be used to remove the
|
||||
// // notification later
|
||||
|
@ -66,9 +66,9 @@ namespace realm {
|
|||
// private:
|
||||
// std::list<std::function<void ()>> m_registered_notifications;
|
||||
// };
|
||||
class RealmDelegate {
|
||||
class BindingContext {
|
||||
public:
|
||||
virtual ~RealmDelegate() = default;
|
||||
virtual ~BindingContext() = default;
|
||||
|
||||
// Called by the Realm when a write transaction is committed to the file by
|
||||
// a different Realm instance (possibly in a different process)
|
||||
|
@ -147,8 +147,8 @@ public:
|
|||
};
|
||||
};
|
||||
|
||||
inline void RealmDelegate::will_change(std::vector<ObserverState> const&, std::vector<void*> const&) { }
|
||||
inline void RealmDelegate::did_change(std::vector<ObserverState> const&, std::vector<void*> const&) { }
|
||||
inline void BindingContext::will_change(std::vector<ObserverState> const&, std::vector<void*> const&) { }
|
||||
inline void BindingContext::did_change(std::vector<ObserverState> const&, std::vector<void*> const&) { }
|
||||
} // namespace realm
|
||||
|
||||
#endif /* REALM_DELEGATE_HPP */
|
||||
#endif /* BINDING_CONTEXT_HPP */
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
#include "transact_log_handler.hpp"
|
||||
|
||||
#include "realm_delegate.hpp"
|
||||
#include "../realm_binding_context.hpp"
|
||||
|
||||
#include <realm/commit_log.hpp>
|
||||
#include <realm/group_shared.hpp>
|
||||
|
@ -28,15 +28,15 @@ using namespace realm;
|
|||
|
||||
namespace {
|
||||
class TransactLogHandler {
|
||||
using ColumnInfo = RealmDelegate::ColumnInfo;
|
||||
using ObserverState = RealmDelegate::ObserverState;
|
||||
using ColumnInfo = RealmBindingContext::ColumnInfo;
|
||||
using ObserverState = RealmBindingContext::ObserverState;
|
||||
|
||||
// Observed table rows which need change information
|
||||
std::vector<ObserverState> m_observers;
|
||||
// Userdata pointers for rows which have been deleted
|
||||
std::vector<void *> invalidated;
|
||||
// Delegate to send change information to
|
||||
RealmDelegate* m_delegate;
|
||||
RealmBindingContext* m_binding_context;
|
||||
|
||||
// Index of currently selected table
|
||||
size_t m_current_table = 0;
|
||||
|
@ -84,33 +84,33 @@ class TransactLogHandler {
|
|||
|
||||
public:
|
||||
template<typename Func>
|
||||
TransactLogHandler(RealmDelegate* delegate, SharedGroup& sg, Func&& func)
|
||||
: m_delegate(delegate)
|
||||
TransactLogHandler(RealmBindingContext* binding_context, SharedGroup& sg, Func&& func)
|
||||
: m_binding_context(binding_context)
|
||||
{
|
||||
if (!delegate) {
|
||||
if (!binding_context) {
|
||||
func();
|
||||
return;
|
||||
}
|
||||
|
||||
m_observers = delegate->get_observed_rows();
|
||||
m_observers = binding_context->get_observed_rows();
|
||||
if (m_observers.empty()) {
|
||||
auto old_version = sg.get_version_of_current_transaction();
|
||||
func();
|
||||
if (old_version != sg.get_version_of_current_transaction()) {
|
||||
delegate->did_change({}, {});
|
||||
binding_context->did_change({}, {});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
func(*this);
|
||||
delegate->did_change(m_observers, invalidated);
|
||||
binding_context->did_change(m_observers, invalidated);
|
||||
}
|
||||
|
||||
// Called at the end of the transaction log immediately before the version
|
||||
// is advanced
|
||||
void parse_complete()
|
||||
{
|
||||
m_delegate->will_change(m_observers, invalidated);
|
||||
m_binding_context->will_change(m_observers, invalidated);
|
||||
}
|
||||
|
||||
// These would require having an observer before schema init
|
||||
|
@ -318,28 +318,28 @@ public:
|
|||
namespace realm {
|
||||
namespace _impl {
|
||||
namespace transaction {
|
||||
void advance(SharedGroup& sg, ClientHistory& history, RealmDelegate* delegate) {
|
||||
TransactLogHandler(delegate, sg, [&](auto&&... args) {
|
||||
void advance(SharedGroup& sg, ClientHistory& history, RealmBindingContext* binding_context) {
|
||||
TransactLogHandler(binding_context, sg, [&](auto&&... args) {
|
||||
LangBindHelper::advance_read(sg, history, std::move(args)...);
|
||||
});
|
||||
}
|
||||
|
||||
void begin(SharedGroup& sg, ClientHistory& history, RealmDelegate* delegate) {
|
||||
TransactLogHandler(delegate, sg, [&](auto&&... args) {
|
||||
void begin(SharedGroup& sg, ClientHistory& history, RealmBindingContext* binding_context) {
|
||||
TransactLogHandler(binding_context, sg, [&](auto&&... args) {
|
||||
LangBindHelper::promote_to_write(sg, history, std::move(args)...);
|
||||
});
|
||||
}
|
||||
|
||||
void commit(SharedGroup& sg, ClientHistory&, RealmDelegate* delegate) {
|
||||
void commit(SharedGroup& sg, ClientHistory&, RealmBindingContext* binding_context) {
|
||||
LangBindHelper::commit_and_continue_as_read(sg);
|
||||
|
||||
if (delegate) {
|
||||
delegate->did_change({}, {});
|
||||
if (binding_context) {
|
||||
binding_context->did_change({}, {});
|
||||
}
|
||||
}
|
||||
|
||||
void cancel(SharedGroup& sg, ClientHistory& history, RealmDelegate* delegate) {
|
||||
TransactLogHandler(delegate, sg, [&](auto&&... args) {
|
||||
void cancel(SharedGroup& sg, ClientHistory& history, RealmBindingContext* binding_context) {
|
||||
TransactLogHandler(binding_context, sg, [&](auto&&... args) {
|
||||
LangBindHelper::rollback_and_continue_as_read(sg, history, std::move(args)...);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#define REALM_TRANSACT_LOG_HANDLER_HPP
|
||||
|
||||
namespace realm {
|
||||
class RealmDelegate;
|
||||
class RealmBindingContext;
|
||||
class SharedGroup;
|
||||
class ClientHistory;
|
||||
|
||||
|
@ -28,19 +28,19 @@ namespace _impl {
|
|||
namespace transaction {
|
||||
// Advance the read transaction version, with change notifications sent to delegate
|
||||
// Must not be called from within a write transaction.
|
||||
void advance(SharedGroup& sg, ClientHistory& history, RealmDelegate* delegate);
|
||||
void advance(SharedGroup& sg, ClientHistory& history, RealmBindingContext* binding_context);
|
||||
|
||||
// Begin a write transaction
|
||||
// If the read transaction version is not up to date, will first advance to the
|
||||
// most recent read transaction and sent notifications to delegate
|
||||
void begin(SharedGroup& sg, ClientHistory& history, RealmDelegate* delegate);
|
||||
void begin(SharedGroup& sg, ClientHistory& history, RealmBindingContext* binding_context);
|
||||
|
||||
// Commit a write transaction
|
||||
void commit(SharedGroup& sg, ClientHistory& history, RealmDelegate* delegate);
|
||||
void commit(SharedGroup& sg, ClientHistory& history, RealmBindingContext* binding_context);
|
||||
|
||||
// Cancel a write transaction and roll back all changes, with change notifications
|
||||
// for reverting to the old values sent to delegate
|
||||
void cancel(SharedGroup& sg, ClientHistory& history, RealmDelegate* delegate);
|
||||
void cancel(SharedGroup& sg, ClientHistory& history, RealmBindingContext* binding_context);
|
||||
} // namespace transaction
|
||||
} // namespace _impl
|
||||
} // namespace realm
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "shared_realm.hpp"
|
||||
|
||||
#include "external_commit_helper.hpp"
|
||||
#include "realm_delegate.hpp"
|
||||
#include "binding_context.hpp"
|
||||
#include "schema.hpp"
|
||||
#include "transact_log_handler.hpp"
|
||||
|
||||
|
@ -247,7 +247,7 @@ void Realm::begin_transaction()
|
|||
// make sure we have a read transaction
|
||||
read_group();
|
||||
|
||||
transaction::begin(*m_shared_group, *m_history, m_delegate.get());
|
||||
transaction::begin(*m_shared_group, *m_history, m_binding_context.get());
|
||||
m_in_transaction = true;
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ void Realm::commit_transaction()
|
|||
}
|
||||
|
||||
m_in_transaction = false;
|
||||
transaction::commit(*m_shared_group, *m_history, m_delegate.get());
|
||||
transaction::commit(*m_shared_group, *m_history, m_binding_context.get());
|
||||
m_notifier->notify_others();
|
||||
}
|
||||
|
||||
|
@ -275,7 +275,7 @@ void Realm::cancel_transaction()
|
|||
}
|
||||
|
||||
m_in_transaction = false;
|
||||
transaction::cancel(*m_shared_group, *m_history, m_delegate.get());
|
||||
transaction::cancel(*m_shared_group, *m_history, m_binding_context.get());
|
||||
}
|
||||
|
||||
void Realm::invalidate()
|
||||
|
@ -320,15 +320,15 @@ void Realm::notify()
|
|||
verify_thread();
|
||||
|
||||
if (m_shared_group->has_changed()) { // Throws
|
||||
if (m_delegate) {
|
||||
m_delegate->changes_available();
|
||||
if (m_binding_context) {
|
||||
m_binding_context->changes_available();
|
||||
}
|
||||
if (m_auto_refresh) {
|
||||
if (m_group) {
|
||||
transaction::advance(*m_shared_group, *m_history, m_delegate.get());
|
||||
transaction::advance(*m_shared_group, *m_history, m_binding_context.get());
|
||||
}
|
||||
else if (m_delegate) {
|
||||
m_delegate->did_change({}, {});
|
||||
else if (m_binding_context) {
|
||||
m_binding_context->did_change({}, {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -351,7 +351,7 @@ bool Realm::refresh()
|
|||
}
|
||||
|
||||
if (m_group) {
|
||||
transaction::advance(*m_shared_group, *m_history, m_delegate.get());
|
||||
transaction::advance(*m_shared_group, *m_history, m_binding_context.get());
|
||||
}
|
||||
else {
|
||||
// Create the read transaction
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace realm {
|
|||
class ClientHistory;
|
||||
class Realm;
|
||||
class RealmCache;
|
||||
class RealmDelegate;
|
||||
class BindingContext;
|
||||
typedef std::shared_ptr<Realm> SharedRealm;
|
||||
typedef std::weak_ptr<Realm> WeakRealm;
|
||||
|
||||
|
@ -120,7 +120,7 @@ namespace realm {
|
|||
std::shared_ptr<_impl::ExternalCommitHelper> m_notifier;
|
||||
|
||||
public:
|
||||
std::unique_ptr<RealmDelegate> m_delegate;
|
||||
std::unique_ptr<BindingContext> m_binding_context;
|
||||
|
||||
// FIXME private
|
||||
Group *read_group();
|
||||
|
|
Loading…
Reference in New Issue