2 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
28 #import <Foundation/Foundation.h>
29 #import <dispatch/queue.h>
33 #import <utilities/debugging.h>
35 #import "SOSCloudKeychainConstants.h"
36 #import "SOSCloudKeychainClient.h"
38 #define XPROXYSCOPE "proxy"
40 @interface UbiqitousKVSProxy
: NSObject
42 id currentiCloudToken
;
43 CloudItemsChangedBlock itemsChangedCallback
;
47 @
property (retain
, nonatomic
) NSDictionary
*keyParameterKeys
;
48 @
property (retain
, nonatomic
) NSDictionary
*circleKeys
;
49 @
property (retain
, nonatomic
) NSDictionary
*messageKeys
;
51 @
property (retain
, nonatomic
) NSMutableSet
*alwaysKeys
;
52 @
property (retain
, nonatomic
) NSMutableSet
*firstUnlockKeys
;
53 @
property (retain
, nonatomic
) NSMutableSet
*unlockedKeys
;
54 @
property (retain
, nonatomic
) NSMutableSet
*pendingKeys
;
55 @
property (retain
, nonatomic
) NSMutableSet
*shadowPendingKeys
;
56 @
property (retain
, nonatomic
) NSString
*dsid
;
58 @
property (atomic
) bool syncWithPeersPending
;
59 @
property (atomic
) bool shadowSyncWithPeersPending
;
60 @
property (atomic
) bool inCallout
;
61 @
property (atomic
) bool oldInCallout
;
62 @
property (atomic
) bool unlockedSinceBoot
;
63 @
property (atomic
) bool isLocked
;
64 @
property (atomic
) bool seenKVSStoreChange
;
65 @
property (atomic
) bool ensurePeerRegistration
;
66 @
property (atomic
) bool shadowEnsurePeerRegistration
;
67 @
property (atomic
) dispatch_time_t nextFreshnessTime
;
69 @
property (atomic
) dispatch_source_t syncTimer
;
70 @
property (atomic
) bool syncTimerScheduled
;
71 @
property (atomic
) dispatch_time_t deadline
;
72 @
property (atomic
) dispatch_time_t lastSyncTime
;
73 @
property (atomic
) dispatch_queue_t calloutQueue
;
74 @
property (atomic
) dispatch_queue_t freshParamsQueue
;
76 + (UbiqitousKVSProxy
*) sharedKVSProxy
;
77 - (NSString
*)description
;
79 - (void)streamEvent
:(xpc_object_t
)notification
;
80 - (void)setItemsChangedBlock
:(CloudItemsChangedBlock
)itemsChangedBlock
;
82 - (void)setObject
:(id
)obj forKey
:(id
)key
;
84 - (NSDictionary
*)getAll
;
85 - (void)requestSynchronization
:(bool)force
;
86 - (void)waitForSynchronization
:(NSArray
*)keys handler
:(void (^)(NSDictionary
*values
, NSError
*err
))handler
;
88 - (void)setObjectsFromDictionary
:(NSDictionary
*)values
;
89 - (void)removeObjectForKey
:(NSString
*)keyToRemove
;
90 - (void)processAllItems
;
91 - (void)requestSyncWithAllPeers
;
92 - (void)requestEnsurePeerRegistration
;
94 - (NSUbiquitousKeyValueStore
*)cloudStore
;
96 -(void)registerAtTimeKeys
:(NSDictionary
*)keyparms
;
98 - (NSSet
*) keysForCurrentLockState
;
99 - (void) intersectWithCurrentLockState
: (NSMutableSet
*) set
;
101 - (NSMutableSet
*) pendKeysAndGetNewlyPended
: (NSSet
*) keysToPend
;
103 - (NSMutableSet
*) pendingKeysForCurrentLockState
;
104 - (NSMutableSet
*) pendKeysAndGetPendingForCurrentLockState
: (NSSet
*) startingSet
;
106 - (void) processPendingKeysForCurrentLockState
;
108 - (void)registerKeys
: (NSDictionary
*)keys
;
110 - (NSDictionary
*)localNotification
:(NSDictionary
*)localNotificationDict outFlags
:(int64_t *)outFlags
;
112 - (void)processKeyChangedEvent
:(NSDictionary
*)keysChangedInCloud
;
113 - (NSMutableDictionary
*)copyValues
:(NSSet
*)keysOfInterest
;
115 - (void) doAfterFlush
: (dispatch_block_t
) block
;
116 - (void) calloutWith
: (void(^)(NSSet
*pending
, bool syncWithPeersPending
, bool ensurePeerRegistration
, dispatch_queue_t queue
, void(^done
)(NSSet
*handledKeys
, bool handledSyncWithPeers
, bool handledEnsurePeerRegistration
))) callout
;
117 - (void) sendKeysCallout
: (NSSet
*(^)(NSSet
* pending
, NSError
**error
)) handleKeys
;