-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle change notifications originating from Core #909
Conversation
7105d17
to
34b25f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
@@ -271,7 +270,7 @@ private void UnsubscribeFromNotifications() | |||
{ | |||
Debug.Assert(_notificationToken != null, "_notificationToken must not be null to unsubscribe."); | |||
|
|||
_notificationToken.Dispose(); | |||
_notificationToken?.Dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've just asserted that it wasn't null
above -- is this defensive programming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a Debug.Assert
, meaning it won't run in released apps and just wanted to avoid potential crash in unsubscribing over which users usually have no control.
|
||
static RealmObject() | ||
{ | ||
NativeCommon.register_notify_realm_object_changed(NotifyRealmObjectPropertyChanged); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any advantage to keeping this here rather than in the static Realm
constructor? I get that it's slightly more related to this, but it seems to me that it would be nice to keep static initialization grouped together, if for no other reason then because it makes the execution order deterministic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't have strong feelings about where it should go - as you said, it's slightly more related to object, so I left it here, but I don't mind moving it to Realm
.
- Use property indices instead of column indices - Respect [MapTo] - Add more tests - Fix deadlock on remove
5a08867
to
692aa9d
Compare
{ | ||
var gch = GCHandle.FromIntPtr(realmObjectHandle); | ||
var realmObject = (RealmObject)gch.Target; | ||
var propertyName = realmObject.ObjectSchema.ElementAtOrDefault((int)propertyIndex).PropertyInfo.Name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Realms.Schema.Property.PropertyInfo
will be null for dynamic realms.
Debug.Assert(_notificationsHandle.HasValue, "Notification handle must not be null to unsubscribe"); | ||
|
||
_realm.SharedRealmHandle.RemoveObservedObject(GCHandle.ToIntPtr(_notificationsHandle.Value)); | ||
_notificationsHandle = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are going to have to call GCHandle.Free()
on both handles you create in SubscribeForNotifications
to prevent the handles from being leaked.
auto observer_state = BindingContext::ObserverState(); | ||
observer_state.row_ndx = object.row().get_index(); | ||
observer_state.table_ndx = object.row().get_table()->get_index_in_group(); | ||
observer_state.info = new ObservedObjectDetails(object.get_object_schema(), managed_object_handle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be delete
d later.
observer_state.row_ndx = object.row().get_index(); | ||
observer_state.table_ndx = object.row().get_table()->get_index_in_group(); | ||
observer_state.info = new ObservedObjectDetails(object.get_object_schema(), managed_object_handle); | ||
observed_rows.push_back(observer_state); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use std::move
to prevent a copy.
} | ||
} | ||
|
||
void* CSharpBindingContext::get_managed_realm_handle() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define in header instead so that the getter can be inlined in other translation units.
private: | ||
void* m_managed_realm_handle; | ||
std::vector<BindingContext::ObserverState> observed_rows; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the m_
prefix for fields.
#if __IOS__ | ||
[MonoPInvokeCallback(typeof(NativeCommon.NotifyRealmCallback))] | ||
#endif | ||
private static void NotifyRealmObjectPropertyChanged(IntPtr realmObjectHandle, IntPtr propertyIndex) | ||
public static void NotifyRealmObjectPropertyChanged(IntPtr realmObjectHandle, IntPtr propertyIndex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be internal
bae4500
to
bdf0c5f
Compare
@@ -65,7 +61,7 @@ namespace binding { | |||
|
|||
CSharpBindingContext::CSharpBindingContext(void* managed_realm_handle) : m_managed_realm_handle(managed_realm_handle) | |||
{ | |||
observed_rows = std::vector<ObserverState>(); | |||
m_observed_rows = std::vector<ObserverState>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to initialize this - the compiler will have added the necessary code to invoke the std::vector
constructor in the CSharpBindingContext
constructor.
TODO:
invalidated
vector)NotifyChanges()
at the end of eachset_xxx
method)[MapTo]
Resolves #886