Couchbase Lite
Objective-C API for iOS and Mac OS
CBLReplication.h
Go to the documentation of this file.
1 //
2 // CBLReplication.h
3 // CouchbaseLite
4 //
5 // Created by Jens Alfke on 6/22/12.
6 // Copyright (c) 2012-2013 Couchbase, Inc. All rights reserved.
7 //
8 
9 #import "CBLBase.h"
10 @class CBLDatabase, CBLDocument;
11 @protocol CBLAuthenticator;
12 
14 
16 typedef NS_ENUM(unsigned, CBLReplicationStatus) {
17  kCBLReplicationStopped,
18  kCBLReplicationOffline,
19  kCBLReplicationIdle,
20  kCBLReplicationActive
21 } ;
22 
23 
28 typedef void (^CBLAttachmentProgressBlock)(uint64_t bytesRead,
29  uint64_t contentLength,
30  NSError* error);
31 
32 
35 @interface CBLReplication : NSObject
36 
38 @property (nonatomic, readonly) CBLDatabase* localDatabase;
39 
41 @property (nonatomic, readonly) NSURL* remoteURL;
42 
44 @property (nonatomic, readonly) BOOL pull;
45 
46 
47 #pragma mark - OPTIONS:
48 
50 @property (nonatomic) BOOL createTarget;
51 
56 @property (nonatomic) bool continuous;
57 
62 @property (nonatomic, copy, nullable) NSString* filter;
63 
66 @property (nonatomic, copy, nullable) CBLJSONDict* filterParams;
67 
72 @property (nonatomic, copy, nullable) CBLArrayOf(NSString*)* channels;
73 
75 @property (copy, nullable) CBLArrayOf(NSString*) *documentIDs;
76 
80 @property (nonatomic) BOOL downloadsAttachments;
81 
84 @property (nonatomic, copy, nullable) CBLDictOf(NSString*, NSString*)* headers;
85 
90 @property (nonatomic, copy, nullable) NSString* network;
91 
93 @property (nonatomic, copy, nullable) CBLJSONDict* customProperties;
94 
95 
96 #pragma mark - AUTHENTICATION:
97 
101 @property (nonatomic, strong, nullable) id<CBLAuthenticator> authenticator;
102 
106 @property (nonatomic, strong, nullable) NSURLCredential* credential;
107 
109 @property (nonatomic, readonly) NSString* username;
110 
114 @property (nonatomic, copy, nullable) CBLJSONDict* OAuth;
115 
118 @property (readonly, nullable) NSURL* personaOrigin;
119 
131 - (void) setCookieNamed: (NSString*)name
132  withValue: (NSString*)value
133  path: (nullable NSString*)path
134  expirationDate: (nullable NSDate*)expirationDate
135  secure: (BOOL)secure;
136 
138 - (void) deleteCookieNamed: (NSString *)name;
139 
142 - (BOOL) clearAuthenticationStores: (NSError**)outError;
143 
150 + (void) setAnchorCerts: (nullable NSArray*)certs onlyThese: (BOOL)onlyThese;
151 
154 @property (readonly, nullable) SecCertificateRef serverCertificate;
155 
156 #pragma mark - STATUS:
157 
162 - (void) start;
163 
166 - (void) stop;
167 
170 - (void) restart;
171 
177 @property BOOL suspended;
178 
180 @property (nonatomic, readonly) CBLReplicationStatus status;
181 
185 @property (nonatomic, readonly) BOOL running;
186 
188 @property (nonatomic, readonly, strong, nullable) NSError* lastError;
189 
191 @property (nonatomic, readonly) unsigned completedChangesCount;
192 
194 @property (nonatomic, readonly) unsigned changesCount;
195 
196 #pragma mark - PENDING DOCUMENTS (PUSH ONLY):
197 
203 @property (readonly, nullable) NSSet* pendingDocumentIDs;
204 
209 - (BOOL) isDocumentPending: (CBLDocument*)doc;
210 
211 #pragma mark - ATTACHMENT DOWNLOADING (PULL ONLY)
212 
219 - (NSProgress*) downloadAttachment: (CBLAttachment*)attachment;
220 
221 
222 - (instancetype) init NS_UNAVAILABLE;
223 
224 @end
225 
226 
230 extern NSString* const kCBLReplicationChangeNotification;
231 
233 extern NSString* const kCBLProgressErrorKey;
234 
235 
#define NS_ASSUME_NONNULL_BEGIN
Definition: CBLBase.h:20
NSError * lastError
The error status of the replication, or nil if there have not been any errors since it started...
Definition: CBLReplication.h:188
BOOL downloadsAttachments
Should attachments be downloaded automatically along with documents? Defaults to YES; if you set it t...
Definition: CBLReplication.h:80
bool continuous
Should the replication operate continuously? (Defaults to NO).
Definition: CBLReplication.h:56
A CouchbaseLite database.
Definition: CBLDatabase.h:38
void stop()
Stops replication, asynchronously.
CBLJSONDict * customProperties
An optional JSON-compatible dictionary of extra properties for the replicator.
Definition: CBLReplication.h:93
#define nullable
Definition: CBLBase.h:22
unsigned completedChangesCount
The number of completed changes processed, if the task is active, else 0 (observable).
Definition: CBLReplication.h:191
CBLJSONDict * OAuth
OAuth parameters that the replicator should use when authenticating to the remote database...
Definition: CBLReplication.h:114
CBLReplicationStatus status
The replication&#39;s current state, one of {stopped, offline, idle, active}.
Definition: CBLReplication.h:180
NSSet * pendingDocumentIDs
The IDs of documents that have local changes that have not yet been pushed to the server by this repl...
Definition: CBLReplication.h:203
A CouchbaseLite document (as opposed to any specific revision of it.)
Definition: CBLDocument.h:16
void start()
Starts the replication, asynchronously.
NSString * network
Specifies which class of network the replication will operate over.
Definition: CBLReplication.h:90
NSURLCredential * credential
The credential (generally username+password) to use to authenticate to the remote database...
Definition: CBLReplication.h:106
SecCertificateRef serverCertificate
The server&#39;s SSL certificate.
Definition: CBLReplication.h:154
#define NS_ASSUME_NONNULL_END
Definition: CBLBase.h:21
NSURL * personaOrigin
The base URL of the remote server, for use as the "origin" parameter when requesting Persona or Faceb...
Definition: CBLReplication.h:118
BOOL createTarget
Should the target database be created if it doesn&#39;t already exist? (Defaults to NO).
Definition: CBLReplication.h:50
NS_ASSUME_NONNULL_BEGIN typedef NS_ENUM(unsigned, CBLReplicationStatus)
Describes the current status of a replication.
Definition: CBLReplication.h:16
NSString * filter
Name of an optional filter function to run on the source server.
Definition: CBLReplication.h:62
void(^ CBLAttachmentProgressBlock)(uint64_t bytesRead, uint64_t contentLength, NSError *error)
Callback for notifying progress downloading an attachment.
Definition: CBLReplication.h:28
The CBLAuthenticator class provides factory methods for creating authenticator objects, for use with the .authenticator property of a CBLReplication.
Definition: CBLAuthenticator.h:25
NSString * username
The server user name that the authenticator has logged in as, if known.
Definition: CBLReplication.h:109
CBLJSONDict * filterParams
Parameters to pass to the filter function.
Definition: CBLReplication.h:66
NSString *const kCBLProgressErrorKey
NSProgress userInfo key used to report an NSError when an attachment download fails.
void restart()
Restarts a running replication.
BOOL suspended
Suspends/resumes a replication.
Definition: CBLReplication.h:177
NSString *const kCBLReplicationChangeNotification
This notification is posted by a CBLReplication when any of these properties change: {status...
CBLDictOf(NSString *, NSString *) *headers
Extra HTTP headers to send in all requests to the remote server.
instancetype NS_UNAVAILABLE()
CBLDatabase * localDatabase
The local database being replicated to/from.
Definition: CBLReplication.h:38
id< CBLAuthenticator > authenticator
An object that knows how to authenticate with a remote server.
Definition: CBLReplication.h:101
CBLArrayOf(NSString *) *channels
List of Sync Gateway channel names to filter by; a nil value means no filtering, i.e.
A binary attachment to a document revision.
Definition: CBLAttachment.h:18
BOOL running
YES while the replication is running, NO if it&#39;s stopped.
Definition: CBLReplication.h:185
A &#39;push&#39; or &#39;pull&#39; replication between a local and a remote database.
Definition: CBLReplication.h:35
BOOL pull
Does the replication pull from (as opposed to push to) the target?
Definition: CBLReplication.h:44
NSURL * remoteURL
The URL of the remote database.
Definition: CBLReplication.h:41
unsigned changesCount
The total number of changes to be processed, if the task is active, else 0 (observable).
Definition: CBLReplication.h:194