2 * Copyright (c) 2018 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@
25 * Modification History
27 * Oct 1, 2018 Allan Nathanson <ajn@apple.com>
34 os_log_t
SC_LOG_HANDLE(void);
35 #endif //SC_LOG_HANDLE
37 #include "SCDynamicStoreInternal.h"
41 _SCDynamicStoreCacheIsActive(SCDynamicStoreRef store
)
43 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
46 // sorry, you must provide a session
47 _SCErrorSet(kSCStatusNoStoreSession
);
51 return storePrivate
->cache_active
;
56 __SCDynamicStoreCacheRelease(SCDynamicStoreRef store
)
58 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
60 if (storePrivate
->cached_keys
!= NULL
) {
61 CFRelease(storePrivate
->cached_keys
);
62 storePrivate
->cached_keys
= NULL
;
64 if (storePrivate
->cached_set
!= NULL
) {
65 CFRelease(storePrivate
->cached_set
);
66 storePrivate
->cached_set
= NULL
;
68 if (storePrivate
->cached_removals
!= NULL
) {
69 CFRelease(storePrivate
->cached_removals
);
70 storePrivate
->cached_removals
= NULL
;
72 if (storePrivate
->cached_notifys
!= NULL
) {
73 CFRelease(storePrivate
->cached_notifys
);
74 storePrivate
->cached_notifys
= NULL
;
82 _SCDynamicStoreCacheOpen(SCDynamicStoreRef store
)
84 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
87 // sorry, you must provide a session
88 _SCErrorSet(kSCStatusNoStoreSession
);
92 __SCDynamicStoreCacheRelease(store
); // if we are already using the cache, start clean
93 storePrivate
->cache_active
= TRUE
;
100 _SCDynamicStoreCacheCommitChanges(SCDynamicStoreRef store
)
103 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
106 // sorry, you must provide a session
107 _SCErrorSet(kSCStatusNoStoreSession
);
111 if (!storePrivate
->cache_active
) {
112 // if not using the cache
113 _SCErrorSet(kSCStatusFailed
);
117 if ((storePrivate
->cached_set
!= NULL
) ||
118 (storePrivate
->cached_removals
!= NULL
) ||
119 (storePrivate
->cached_notifys
!= NULL
)) {
120 ok
= SCDynamicStoreSetMultiple(store
,
121 storePrivate
->cached_set
,
122 storePrivate
->cached_removals
,
123 storePrivate
->cached_notifys
);
124 __SCDynamicStoreCacheRelease(store
);
132 _SCDynamicStoreCacheClose(SCDynamicStoreRef store
)
134 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
137 // sorry, you must provide a session
138 _SCErrorSet(kSCStatusNoStoreSession
);
142 if (!storePrivate
->cache_active
) {
143 // if not using the cache
144 _SCErrorSet(kSCStatusFailed
);
148 __SCDynamicStoreCacheRelease(store
);
149 storePrivate
->cache_active
= FALSE
;