Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ before_script:
script:
- cd ./Testing/Xcode-desktop
- pod update
- xctool -workspace YapDatabaseTesting.xcworkspace -scheme YapDatabaseTesting -sdk macosx -arch x86_64 test
- xctool -workspace YapDatabaseTesting.xcworkspace -scheme YapDatabaseTesting -sdk macosx -arch x86_64 run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ - (id)initWithIdentifier:(NSString *)identifier {
self = [super init];
if (self) {
self.identifier = identifier;
notifyToken = NOTIFY_TOKEN_INVALID;
}
return self;
}
Expand All @@ -80,6 +81,7 @@ - (void)start {
__weak YapDatabaseCrossProcessNotification* wSelf = self;

notify_register_dispatch(name, &notifyToken, dispatch_get_main_queue(), ^(int token) {

uint64_t fromPid;
notify_get_state(token, &fromPid);
BOOL isExternal = fromPid != currentPid();
Expand All @@ -96,7 +98,7 @@ - (void)stop {
if (notify_is_valid_token(notifyToken))
{
notify_cancel(notifyToken);
notifyToken = 0;
notifyToken = NOTIFY_TOKEN_INVALID;
}
}

Expand All @@ -110,10 +112,24 @@ - (void)stop {
* This method is invoked within the writeQueue.
* So either don't do anything expensive/time-consuming in this method, or dispatch_async to do it in another queue.
**/
- (void)didRegisterExtension
- (void)didRegisterExtension {
// only start dispatching notifications once the extension is registered to a database
[self start];
}

- (void)noteCommittedChangeset:(NSDictionary *)changeset registeredName:(NSString *)extName
{
// only start dispatching notifications once the extension is registered to a database
[self start];
NSDictionary *ext_changeset = [[changeset objectForKey:YapDatabaseExtensionsKey] objectForKey:extName];
if (ext_changeset)
{
[self processChangeset:ext_changeset];
}

NSNotification *notification = changeset[YapDatabaseNotificationKey];
if ([notification.name isEqualToString:YapDatabaseModifiedNotification])
{
[self notifyChanged];
}
}

- (YapDatabaseExtensionConnection *)newConnection:(YapDatabaseConnection *)databaseConnection
Expand All @@ -122,6 +138,9 @@ - (YapDatabaseExtensionConnection *)newConnection:(YapDatabaseConnection *)datab
}

- (void)notifyChanged {
if (!notify_is_valid_token(notifyToken)) {
[self start];
}

const char* name = [[self channel] cStringUsingEncoding:NSUTF8StringEncoding];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ @interface YapDatabaseCrossProcessNotificationTransaction ()

@property (nonatomic, strong) YapDatabaseCrossProcessNotificationConnection* parentConnection;
@property (nonatomic, strong) YapDatabaseReadTransaction* databaseTransaction;
@property (nonatomic, assign) BOOL anyChange;

@end

Expand All @@ -37,7 +36,6 @@ - (id)initWithParentConnection:(YapDatabaseCrossProcessNotificationConnection *)
{
if ((self = [super init]))
{
self.anyChange = NO;
self.parentConnection = inParentConnection;
self.databaseTransaction = inDatabaseTransaction;
}
Expand Down Expand Up @@ -104,14 +102,6 @@ - (YapDatabaseExtensionConnection *)extensionConnection
**/
- (void)didCommitTransaction
{
if (self.anyChange)
{
YapDatabaseCrossProcessNotification *ext =
(YapDatabaseCrossProcessNotification *)self.parentConnection.extension;

[ext notifyChanged];
}

// An extensionTransaction is only valid within the scope of its encompassing databaseTransaction.
// I imagine this may occasionally be misunderstood, and developers may attempt to store the extension in an ivar,
// and then use it outside the context of the database transaction block.
Expand All @@ -126,7 +116,6 @@ - (void)didCommitTransaction
**/
- (void)didRollbackTransaction
{
self.anyChange = NO;
// An extensionTransaction is only valid within the scope of its encompassing databaseTransaction.
// I imagine this may occasionally be misunderstood, and developers may attempt to store the extension in an ivar,
// and then use it outside the context of the database transaction block.
Expand All @@ -149,7 +138,7 @@ - (void)didInsertObject:(id)object
withMetadata:(id)metadata
rowid:(int64_t)rowid
{
self.anyChange = YES;

}

/**
Expand All @@ -161,7 +150,7 @@ - (void)didUpdateObject:(id)object
withMetadata:(id)metadata
rowid:(int64_t)rowid
{
self.anyChange = YES;

}

/**
Expand All @@ -170,7 +159,7 @@ - (void)didUpdateObject:(id)object
**/
- (void)didReplaceObject:(id)object forCollectionKey:(YapCollectionKey *)collectionKey withRowid:(int64_t)rowid
{
self.anyChange = YES;

}

/**
Expand All @@ -179,7 +168,7 @@ - (void)didReplaceObject:(id)object forCollectionKey:(YapCollectionKey *)collect
**/
- (void)didReplaceMetadata:(id)metadata forCollectionKey:(YapCollectionKey *)collectionKey withRowid:(int64_t)rowid
{
self.anyChange = YES;

}

/**
Expand All @@ -188,7 +177,7 @@ - (void)didReplaceMetadata:(id)metadata forCollectionKey:(YapCollectionKey *)col
**/
- (void)didTouchObjectForCollectionKey:(YapCollectionKey __unused *)collectionKey withRowid:(int64_t __unused)rowid
{
self.anyChange = YES;

}

/**
Expand All @@ -197,7 +186,7 @@ - (void)didTouchObjectForCollectionKey:(YapCollectionKey __unused *)collectionKe
**/
- (void)didTouchMetadataForCollectionKey:(YapCollectionKey __unused *)collectionKey withRowid:(int64_t __unused)rowid
{
self.anyChange = YES;

}

/**
Expand All @@ -206,7 +195,7 @@ - (void)didTouchMetadataForCollectionKey:(YapCollectionKey __unused *)collection
**/
- (void)didTouchRowForCollectionKey:(YapCollectionKey *)collectionKey withRowid:(int64_t)rowid
{
self.anyChange = YES;

}

/**
Expand All @@ -215,7 +204,7 @@ - (void)didTouchRowForCollectionKey:(YapCollectionKey *)collectionKey withRowid:
**/
- (void)didRemoveObjectForCollectionKey:(YapCollectionKey *)collectionKey withRowid:(int64_t)rowid
{
self.anyChange = YES;

}

/**
Expand All @@ -224,7 +213,7 @@ - (void)didRemoveObjectForCollectionKey:(YapCollectionKey *)collectionKey withRo
**/
- (void)didRemoveObjectsForKeys:(NSArray __unused *)keys inCollection:(NSString *)collection withRowids:(NSArray *)rowids
{
self.anyChange = YES;

}

/**
Expand All @@ -233,7 +222,7 @@ - (void)didRemoveObjectsForKeys:(NSArray __unused *)keys inCollection:(NSString
**/
- (void)didRemoveAllObjectsInAllCollections
{
self.anyChange = YES;

}

@end