Skip to content

Commit

Permalink
- add OCSignal* family of classes to Xcode project
Browse files Browse the repository at this point in the history
- port over OCSignal integration for OCSyncRecord, OCCore+SyncEngine and OCEvent from feature/sync-ng (#76)
- completely remove OCSyncRecord.resultHandler and replace it with OCSignalUUID
- remove OCSyncRecord.resultHandler save/recovery code from OCDatabase
- add OCCodableDict and OCMutableCodableDict types
  • Loading branch information
felix-schwarz committed Apr 29, 2024
1 parent 0aa308b commit dc6644b
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 33 deletions.
52 changes: 52 additions & 0 deletions ownCloudSDK.xcodeproj/project.pbxproj
Expand Up @@ -204,6 +204,15 @@
DC30955F2057D18100189B9A /* fake-demo_owncloud_org.cer in Resources */ = {isa = PBXBuildFile; fileRef = DC30955E2057D18100189B9A /* fake-demo_owncloud_org.cer */; };
DC30956220580D5F00189B9A /* OCCertificateViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = DC30956020580D5F00189B9A /* OCCertificateViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
DC30956320580D5F00189B9A /* OCCertificateViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DC30956120580D5F00189B9A /* OCCertificateViewController.m */; };
DC3181652BDF882500E70392 /* OCSignalManager.h in Headers */ = {isa = PBXBuildFile; fileRef = DC31815A2BDF882500E70392 /* OCSignalManager.h */; };
DC3181662BDF882500E70392 /* OCSignalManager.m in Sources */ = {isa = PBXBuildFile; fileRef = DC31815B2BDF882500E70392 /* OCSignalManager.m */; };
DC3181672BDF882500E70392 /* OCSignalRecord.h in Headers */ = {isa = PBXBuildFile; fileRef = DC31815C2BDF882500E70392 /* OCSignalRecord.h */; };
DC3181682BDF882500E70392 /* OCSignalRecord.m in Sources */ = {isa = PBXBuildFile; fileRef = DC31815D2BDF882500E70392 /* OCSignalRecord.m */; };
DC3181692BDF882500E70392 /* OCSignal.h in Headers */ = {isa = PBXBuildFile; fileRef = DC31815F2BDF882500E70392 /* OCSignal.h */; settings = {ATTRIBUTES = (Public, ); }; };
DC31816A2BDF882500E70392 /* OCSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DC3181602BDF882500E70392 /* OCSignal.m */; };
DC31816B2BDF882500E70392 /* OCSignalConsumer.h in Headers */ = {isa = PBXBuildFile; fileRef = DC3181612BDF882500E70392 /* OCSignalConsumer.h */; };
DC31816C2BDF882500E70392 /* OCSignalConsumer.m in Sources */ = {isa = PBXBuildFile; fileRef = DC3181622BDF882500E70392 /* OCSignalConsumer.m */; };
DC31816D2BDF882500E70392 /* Signal Handling.md in Resources */ = {isa = PBXBuildFile; fileRef = DC3181632BDF882500E70392 /* Signal Handling.md */; };
DC31BAE22A82445200BFF393 /* OpenSSL.LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = DC31BAE12A82445200BFF393 /* OpenSSL.LICENSE */; };
DC34227A217CAA0B00705508 /* OCIPNotificationCenter.h in Headers */ = {isa = PBXBuildFile; fileRef = DC342278217CAA0B00705508 /* OCIPNotificationCenter.h */; settings = {ATTRIBUTES = (Public, ); }; };
DC34227B217CAA0B00705508 /* OCIPNotificationCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = DC342279217CAA0B00705508 /* OCIPNotificationCenter.m */; };
Expand Down Expand Up @@ -1245,6 +1254,15 @@
DC30955E2057D18100189B9A /* fake-demo_owncloud_org.cer */ = {isa = PBXFileReference; lastKnownFileType = file; path = "fake-demo_owncloud_org.cer"; sourceTree = "<group>"; };
DC30956020580D5F00189B9A /* OCCertificateViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCCertificateViewController.h; sourceTree = "<group>"; };
DC30956120580D5F00189B9A /* OCCertificateViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OCCertificateViewController.m; sourceTree = "<group>"; };
DC31815A2BDF882500E70392 /* OCSignalManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCSignalManager.h; sourceTree = "<group>"; };
DC31815B2BDF882500E70392 /* OCSignalManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCSignalManager.m; sourceTree = "<group>"; };
DC31815C2BDF882500E70392 /* OCSignalRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCSignalRecord.h; sourceTree = "<group>"; };
DC31815D2BDF882500E70392 /* OCSignalRecord.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCSignalRecord.m; sourceTree = "<group>"; };
DC31815F2BDF882500E70392 /* OCSignal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCSignal.h; sourceTree = "<group>"; };
DC3181602BDF882500E70392 /* OCSignal.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCSignal.m; sourceTree = "<group>"; };
DC3181612BDF882500E70392 /* OCSignalConsumer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCSignalConsumer.h; sourceTree = "<group>"; };
DC3181622BDF882500E70392 /* OCSignalConsumer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCSignalConsumer.m; sourceTree = "<group>"; };
DC3181632BDF882500E70392 /* Signal Handling.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = "Signal Handling.md"; sourceTree = "<group>"; };
DC31BAE12A82445200BFF393 /* OpenSSL.LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = OpenSSL.LICENSE; sourceTree = "<group>"; };
DC342278217CAA0B00705508 /* OCIPNotificationCenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCIPNotificationCenter.h; sourceTree = "<group>"; };
DC342279217CAA0B00705508 /* OCIPNotificationCenter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OCIPNotificationCenter.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2553,6 +2571,30 @@
path = ownCloudUI;
sourceTree = "<group>";
};
DC31815E2BDF882500E70392 /* Manager */ = {
isa = PBXGroup;
children = (
DC31815B2BDF882500E70392 /* OCSignalManager.m */,
DC31815A2BDF882500E70392 /* OCSignalManager.h */,
DC31815D2BDF882500E70392 /* OCSignalRecord.m */,
DC31815C2BDF882500E70392 /* OCSignalRecord.h */,
);
path = Manager;
sourceTree = "<group>";
};
DC3181642BDF882500E70392 /* Signals */ = {
isa = PBXGroup;
children = (
DC3181632BDF882500E70392 /* Signal Handling.md */,
DC31815E2BDF882500E70392 /* Manager */,
DC3181602BDF882500E70392 /* OCSignal.m */,
DC31815F2BDF882500E70392 /* OCSignal.h */,
DC3181622BDF882500E70392 /* OCSignalConsumer.m */,
DC3181612BDF882500E70392 /* OCSignalConsumer.h */,
);
path = Signals;
sourceTree = "<group>";
};
DC31BADE2A82443200BFF393 /* OpenSSL license */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3918,6 +3960,7 @@
DC85570D204FEAC500189B9A /* Events */,
DC85570E204FEAE900189B9A /* Vaults */,
DC855704204FE9E900189B9A /* Activity */,
DC3181642BDF882500E70392 /* Signals */,
DC855702204FE9CA00189B9A /* Core */,
DC826661281A9E5B00F91F7D /* VFS */,
DC3CE0382429FA6800AB8B88 /* Message Queue */,
Expand Down Expand Up @@ -4428,6 +4471,7 @@
DC41C7DC25EA62CD0074F23B /* OCResourceSourceAvatars.h in Headers */,
DC07C296212450DC00B815A4 /* OCExtensionLocation.h in Headers */,
DC446C85206B8DB500189B9A /* OCRunLoopThread.h in Headers */,
DC3181672BDF882500E70392 /* OCSignalRecord.h in Headers */,
DC9219DF2964CB4500F538EE /* GAEntity.h in Headers */,
DC72E4292063D61F00189B9A /* OCClassSettingsFlatSource.h in Headers */,
DCC8F9FF20285C1500EB6701 /* OCAuthenticationMethodOAuth2.h in Headers */,
Expand Down Expand Up @@ -4562,6 +4606,7 @@
DCE784FC2232748100733F01 /* OCHTTPResponse+DAVError.h in Headers */,
DC47E4E327A5820D0020E8EF /* GADriveItem.h in Headers */,
DC0BE5B828F80DBF00CE2101 /* OCSymbol.h in Headers */,
DC31816B2BDF882500E70392 /* OCSignalConsumer.h in Headers */,
DCE227D822D612EC000BE0A5 /* OCCore+ItemPolicies.h in Headers */,
DC70147F220B0650009D4FD9 /* OCHTTPResponse.h in Headers */,
DCC8F9F6202855A200EB6701 /* OCShare.h in Headers */,
Expand Down Expand Up @@ -4680,6 +4725,7 @@
DCC4F3EA27D74DE300ABF4C9 /* OCDataSource.h in Headers */,
DC166E9E2428FD9A00347714 /* OCItemPolicyProcessorVersionUpdates.h in Headers */,
DC41C7A625EA61D70074F23B /* OCResourceTypes.h in Headers */,
DC3181692BDF882500E70392 /* OCSignal.h in Headers */,
DC971BEE20D15D4400428EF1 /* OCSQLiteQueryCondition.h in Headers */,
DC47E4F027A7E2050020E8EF /* OCDrive.h in Headers */,
DC0364FB20AAD75700F62732 /* OCCore+SyncEngine.h in Headers */,
Expand Down Expand Up @@ -4712,6 +4758,7 @@
DCDD9B2B22312ED80052A001 /* OCRateLimiter.h in Headers */,
DC6ABF7925365CB100689C7B /* OCHostSimulator+BuiltIn.h in Headers */,
DC9219F72964CB6000F538EE /* GATagAssignment.h in Headers */,
DC3181652BDF882500E70392 /* OCSignalManager.h in Headers */,
DC3CE0482429FCDF00AB8B88 /* OCMessageQueue.h in Headers */,
DCC6567420CA695600110A97 /* OCCoreManager.h in Headers */,
DC826669281AC5B000F91F7D /* OCVFSNode.h in Headers */,
Expand Down Expand Up @@ -5029,6 +5076,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DC31816D2BDF882500E70392 /* Signal Handling.md in Resources */,
DCC8F9CA202853B300EB6701 /* LICENSE in Resources */,
DC3F2B4D204AED1900189B9A /* Localizable.strings in Resources */,
DC446C8A206B8FBF00189B9A /* ISRunLoopThread.LICENSE in Resources */,
Expand Down Expand Up @@ -5174,6 +5222,7 @@
DC302AEF221EAC55003218C6 /* OCProxyProgress.m in Sources */,
DC9C19F3278EE7230021222E /* OCResourceRequestImage.m in Sources */,
DC4B1172220830F20062BCDD /* OCHTTPPipelineBackend.m in Sources */,
DC31816A2BDF882500E70392 /* OCSignal.m in Sources */,
DCE26621211348B00001FB2C /* OCCore+CommandLocalImport.m in Sources */,
DCF1C6732631BFD5004D8B0F /* OCMeasurement.m in Sources */,
DC2565F62260C86A00828AA5 /* OCCertificateRuleChecker.m in Sources */,
Expand All @@ -5193,6 +5242,7 @@
DC9A116927CFCC1300D90BA4 /* GAPermission.m in Sources */,
DCC8FA042029BA7A00EB6701 /* OCVault.m in Sources */,
DC39DC5A204215A800189B9A /* NSProgress+OCEvent.m in Sources */,
DC3181682BDF882500E70392 /* OCSignalRecord.m in Sources */,
DC47E4C527A5820D0020E8EF /* GAItemReference.m in Sources */,
DCADC0402072774200DB8E83 /* OCQuery+Internal.m in Sources */,
DC0CE17C28C5DDE8009ABDFB /* OCAppProvider.m in Sources */,
Expand Down Expand Up @@ -5318,6 +5368,7 @@
DC9219E72964CB4500F538EE /* GAEntity.m in Sources */,
DCE370952099D18100114981 /* OCDatabaseConsistentOperation.m in Sources */,
DCC8FA30202B405F00EB6701 /* OCEvent.m in Sources */,
DC31816C2BDF882500E70392 /* OCSignalConsumer.m in Sources */,
DCC8FA22202B218100EB6701 /* OCAppIdentity.m in Sources */,
DCE227CF22D60CF5000BE0A5 /* OCCore+AvailableOffline.m in Sources */,
DC9C19E7278488360021222E /* OCResourceManagerJob.m in Sources */,
Expand Down Expand Up @@ -5508,6 +5559,7 @@
DC2D646621C3D63000EB26FD /* OCCore+Thumbnails.m in Sources */,
DC188998218B09CC00CFB3F9 /* OCLogFileSource.m in Sources */,
DC72E42F2063DBF900189B9A /* OCClassSettingsFlatSourceManagedConfiguration.m in Sources */,
DC3181662BDF882500E70392 /* OCSignalManager.m in Sources */,
DC0CE18C28C63B2E009ABDFB /* OCAppProviderFileType.m in Sources */,
DC66C6B520540DBD00189B9A /* NSDate+OCDateParser.m in Sources */,
DC6DEEB224C5990D00E3772E /* OCHTTPPolicy+PipelinePolicyHandler.m in Sources */,
Expand Down
5 changes: 5 additions & 0 deletions ownCloudSDK/Core/OCCore.h
Expand Up @@ -52,6 +52,7 @@
@class OCRecipientSearchController;
@class OCCoreQuery;
@class OCItemPolicyProcessor;
@class OCSignalManager;

@class OCCoreConnectionStatusSignalProvider;
@class OCCoreServerStatusSignalProvider;
Expand Down Expand Up @@ -225,6 +226,8 @@ typedef id<NSObject> OCCoreItemTracking;
BOOL _availableOfflineCacheValid;
NSMapTable <OCClaimIdentifier, NSObject *> *_claimTokensByClaimIdentifier;

OCSignalManager *_signalManager;

OCCache<OCFileID,OCItemThumbnail *> *_thumbnailCache;
NSMutableDictionary <NSString *, NSMutableArray<OCCoreThumbnailRetrieveHandler> *> *_pendingThumbnailRequests;

Expand Down Expand Up @@ -314,6 +317,8 @@ typedef id<NSObject> OCCoreItemTracking;
@property(readonly,nonatomic) OCCoreConnectionStatusSignal connectionStatusSignals; //!< Mask of current connection status signals
@property(readonly,strong,nullable) NSString *connectionStatusShortDescription; //!< Short description of the current connection status.

@property(readonly,strong) OCSignalManager *signalManager;

@property(readonly,strong) OCActivityManager *activityManager;

@property(readonly,strong) OCEventHandlerIdentifier eventHandlerIdentifier;
Expand Down
5 changes: 5 additions & 0 deletions ownCloudSDK/Core/OCCore.m
Expand Up @@ -70,6 +70,7 @@
#import "OCVault+Internal.h"
#import "OCLocale+SystemLanguage.h"
#import "OCCore+DataSources.h"
#import "OCSignalManager.h"

@interface OCCore ()
{
Expand Down Expand Up @@ -102,6 +103,8 @@ @implementation OCCore
@synthesize connectionStatusSignals = _connectionStatusSignals;
@synthesize connectionStatusShortDescription = _connectionStatusShortDescription;

@synthesize signalManager = _signalManager;

@synthesize activityManager = _activityManager;

@synthesize eventHandlerIdentifier = _eventHandlerIdentifier;
Expand Down Expand Up @@ -327,6 +330,8 @@ - (instancetype)initWithBookmark:(OCBookmark *)bookmark
_queue = dispatch_queue_create("OCCore work queue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL);
_connectivityQueue = dispatch_queue_create("OCCore connectivity queue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL);

_signalManager = [[OCSignalManager alloc] initWithKeyValueStore:_vault.keyValueStore deliveryQueue:_queue];

[OCEvent registerEventHandler:self forIdentifier:_eventHandlerIdentifier];

_warnedCertificates = [NSMutableArray new];
Expand Down
27 changes: 26 additions & 1 deletion ownCloudSDK/Core/Sync/OCCore+SyncEngine.m
Expand Up @@ -39,6 +39,7 @@
#import "OCEventQueue.h"
#import "OCSQLiteTransaction.h"
#import "OCBackgroundManager.h"
#import "OCSignalManager.h"

OCIPCNotificationName OCIPCNotificationNameProcessSyncRecordsBase = @"org.owncloud.process-sync-records";
OCIPCNotificationName OCIPCNotificationNameUpdateSyncRecordsBase = @"org.owncloud.update-sync-records";
Expand Down Expand Up @@ -72,6 +73,8 @@ - (void)setupSyncEngine
_remoteSyncEngineTriggerAcknowledgements = [NSMutableDictionary new];
_remoteSyncEngineTimedOutSyncRecordIDs = [NSMutableSet new];

[self.signalManager removeConsumersWithComponentIdentifier:OCAppIdentity.sharedAppIdentity.componentIdentifier];

_syncResetRateLimiter = [[OCRateLimiter alloc] initWithMinimumTime:2.0];

[self renewActiveProcessCoreRegistration];
Expand Down Expand Up @@ -116,6 +119,8 @@ - (void)shutdownSyncEngine
}

[_remoteSyncEngineTriggerAcknowledgements removeAllObjects];

[self.signalManager removeConsumersWithComponentIdentifier:OCAppIdentity.sharedAppIdentity.componentIdentifier];
}

#pragma mark - Sync Anchor
Expand Down Expand Up @@ -281,7 +286,27 @@ - (NSProgress *)_enqueueSyncRecordWithAction:(OCSyncAction *)action cancellable:

if (action != nil)
{
syncRecord = [[OCSyncRecord alloc] initWithAction:action resultHandler:resultHandler];
OCSignalUUID resultSignalUUID = nil;

resultHandler = [resultHandler copy];

if (resultHandler != nil)
{
OCSignalManager *signalManager;

if ((signalManager = self.signalManager) != nil)
{
resultSignalUUID = OCSignal.generateUUID;

__weak OCCore *weakCore = self;

[signalManager addConsumer:[[OCSignalConsumer alloc] initWithSignalUUID:resultSignalUUID runIdentifier:self.runIdentifier handler:^(OCSignalConsumer * _Nonnull consumer, OCSignal * _Nonnull signal) {
resultHandler((NSError *)signal.payload[@"error"], weakCore, (OCItem *)signal.payload[@"item"], signal.payload[@"parameter"]);
}]];
}
}

syncRecord = [[OCSyncRecord alloc] initWithAction:action resultSignalUUID:resultSignalUUID];

if (syncRecord.progress == nil)
{
Expand Down
7 changes: 4 additions & 3 deletions ownCloudSDK/Core/Sync/Record/OCSyncRecord.h
Expand Up @@ -23,6 +23,7 @@
#import "OCCore.h"
#import "OCLogger.h"
#import "OCActivity.h"
#import "OCSignal.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -57,7 +58,7 @@ typedef NS_ENUM(NSInteger, OCSyncRecordState)

NSMutableArray <OCWaitCondition *> *_newWaitConditions;

OCCoreActionResultHandler _resultHandler;
OCSignalUUID _resultSignalUUID;
}

#pragma mark - Database ID
Expand Down Expand Up @@ -86,13 +87,13 @@ typedef NS_ENUM(NSInteger, OCSyncRecordState)

#pragma mark - Result, cancel and progress handling
@property(assign) BOOL isProcessIndependent; //!< Indicates that this action can be run on any process, not only .originProcessSession
@property(copy,nullable) OCCoreActionResultHandler resultHandler; //!< Result handler to call after the sync record has been processed. Execution not guaranteed. (ephermal)
@property(strong,nullable) OCSignalUUID resultSignalUUID; //!< Result signal to post after the sync record has been processed.
@property(strong,nonatomic,nullable) OCProgress *progress; //!< Progress object tracking the progress of the action described in the sync record.

+ (OCActivityIdentifier)activityIdentifierForSyncRecordID:(OCSyncRecordID)recordID;

#pragma mark - Instantiation
- (instancetype)initWithAction:(OCSyncAction *)action resultHandler:(OCCoreActionResultHandler)resultHandler;
- (instancetype)initWithAction:(OCSyncAction *)action resultSignalUUID:(OCSignalUUID)resultSignalUUID;

#pragma mark - Serialization / Deserialization
+ (instancetype)syncRecordFromSerializedData:(NSData *)serializedData;
Expand Down

0 comments on commit dc6644b

Please sign in to comment.