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 @
property (atomic
) dispatch_queue_t ckdkvsproxy_queue
;
77 @
property (atomic
) dispatch_source_t penaltyTimer
;
78 @
property (atomic
) bool penaltyTimerScheduled
;
79 @
property (retain
, atomic
) NSMutableDictionary
*monitor
;
80 @
property (retain
, atomic
) NSDictionary
*queuedMessages
;
82 + (UbiqitousKVSProxy
*) sharedKVSProxy
;
83 - (NSString
*)description
;
85 - (void)streamEvent
:(xpc_object_t
)notification
;
86 - (void)setItemsChangedBlock
:(CloudItemsChangedBlock
)itemsChangedBlock
;
88 - (void)setObject
:(id
)obj forKey
:(id
)key
;
90 - (NSDictionary
*)getAll
;
91 - (void)requestSynchronization
:(bool)force
;
92 - (void)waitForSynchronization
:(NSArray
*)keys handler
:(void (^)(NSDictionary
*values
, NSError
*err
))handler
;
94 - (void)setObjectsFromDictionary
:(NSDictionary
*)values
;
95 - (void)removeObjectForKey
:(NSString
*)keyToRemove
;
96 - (void)processAllItems
;
97 - (void)requestSyncWithAllPeers
;
98 - (void)requestEnsurePeerRegistration
;
100 - (NSUbiquitousKeyValueStore
*)cloudStore
;
102 -(void)registerAtTimeKeys
:(NSDictionary
*)keyparms
;
104 - (NSSet
*) keysForCurrentLockState
;
105 - (void) intersectWithCurrentLockState
: (NSMutableSet
*) set
;
107 - (NSMutableSet
*) pendKeysAndGetNewlyPended
: (NSSet
*) keysToPend
;
109 - (NSMutableSet
*) pendingKeysForCurrentLockState
;
110 - (NSMutableSet
*) pendKeysAndGetPendingForCurrentLockState
: (NSSet
*) startingSet
;
112 - (void) processPendingKeysForCurrentLockState
;
114 - (void)registerKeys
: (NSDictionary
*)keys
;
116 - (NSDictionary
*)localNotification
:(NSDictionary
*)localNotificationDict outFlags
:(int64_t *)outFlags
;
118 - (void)processKeyChangedEvent
:(NSDictionary
*)keysChangedInCloud
;
119 - (NSMutableDictionary
*)copyValues
:(NSSet
*)keysOfInterest
;
121 - (void) doAfterFlush
: (dispatch_block_t
) block
;
122 - (void) calloutWith
: (void(^)(NSSet
*pending
, bool syncWithPeersPending
, bool ensurePeerRegistration
, dispatch_queue_t queue
, void(^done
)(NSSet
*handledKeys
, bool handledSyncWithPeers
, bool handledEnsurePeerRegistration
))) callout
;
123 - (void) sendKeysCallout
: (NSSet
*(^)(NSSet
* pending
, NSError
**error
)) handleKeys
;
125 - (void)recordWriteToKVS
:(NSDictionary
*)values
;
126 - (NSDictionary
*)recordHaltedValuesAndReturnValuesToSafelyWrite
:(NSDictionary
*)values
;