Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/*
2
 * Copyright 2018 Google
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
 
17
#import <Foundation/Foundation.h>
18
 
19
#import "GoogleDataTransport/GDTCORLibrary/Internal/GDTCORLifecycle.h"
20
#import "GoogleDataTransport/GDTCORLibrary/Internal/GDTCORStorageEventSelector.h"
21
#import "GoogleDataTransport/GDTCORLibrary/Internal/GDTCORStorageProtocol.h"
22
 
23
@class GDTCOREvent;
24
@class GDTCORUploadCoordinator;
25
 
26
NS_ASSUME_NONNULL_BEGIN
27
 
28
/** The event components eventID dictionary key. */
29
FOUNDATION_EXPORT NSString *const kGDTCOREventComponentsEventIDKey;
30
 
31
/** The event components qosTier dictionary key. */
32
FOUNDATION_EXPORT NSString *const kGDTCOREventComponentsQoSTierKey;
33
 
34
/** The event components mappingID dictionary key. */
35
FOUNDATION_EXPORT NSString *const kGDTCOREventComponentsMappingIDKey;
36
 
37
/** The event components expirationDate dictionary key. */
38
FOUNDATION_EXPORT NSString *const kGDTCOREventComponentsExpirationKey;
39
 
40
/** The batch components target dictionary key. */
41
FOUNDATION_EXPORT NSString *const kGDTCORBatchComponentsTargetKey;
42
 
43
/** The batch components batchID dictionary key. */
44
FOUNDATION_EXPORT NSString *const kGDTCORBatchComponentsBatchIDKey;
45
 
46
/** The batch components expiration dictionary key. */
47
FOUNDATION_EXPORT NSString *const kGDTCORBatchComponentsExpirationKey;
48
 
49
/** The maximum allowed disk space taken by the stored data. */
50
FOUNDATION_EXPORT const uint64_t kGDTCORFlatFileStorageSizeLimit;
51
 
52
FOUNDATION_EXPORT NSString *const GDTCORFlatFileStorageErrorDomain;
53
 
54
typedef NS_ENUM(NSInteger, GDTCORFlatFileStorageError) {
55
  GDTCORFlatFileStorageErrorSizeLimitReached = 0
56
};
57
 
58
/** Manages the storage of events. This class is thread-safe.
59
 *
60
 * Event files will be stored as follows:
61
 * <app cache>/google-sdk-events/<classname>/gdt_event_data/<target>/<eventID>.<qosTier>.<mappingID>
62
 *
63
 * Library data will be stored as follows:
64
 * <app cache>/google-sdk-events/<classname>/gdt_library_data/<libraryDataKey>
65
 *
66
 * Batch data will be stored as follows:
67
 * <app
68
 * cache>/google-sdk-events/<classname>/gdt_batch_data/<target>.<batchID>/<eventID>.<qosTier>.<mappingID>
69
 */
70
@interface GDTCORFlatFileStorage : NSObject <GDTCORStorageProtocol, GDTCORLifecycleProtocol>
71
 
72
/** The queue on which all storage work will occur. */
73
@property(nonatomic) dispatch_queue_t storageQueue;
74
 
75
/** The upload coordinator instance used by this storage instance. */
76
@property(nonatomic) GDTCORUploadCoordinator *uploadCoordinator;
77
 
78
/** Creates and/or returns the storage singleton.
79
 *
80
 * @return The storage singleton.
81
 */
82
+ (instancetype)sharedInstance;
83
 
84
/** Returns the base directory under which all events will be stored.
85
 *
86
 * @return The base directory under which all events will be stored.
87
 */
88
+ (NSString *)eventDataStoragePath;
89
 
90
/** Returns the base directory under which all library data will be stored.
91
 *
92
 * @return The base directory under which all library data will be stored.
93
 */
94
+ (NSString *)libraryDataStoragePath;
95
 
96
/** Returns the base directory under which all batch data will be stored.
97
 *
98
 * @return The base directory under which all batch data will be stored.
99
 */
100
+ (NSString *)batchDataStoragePath;
101
 
102
/** */
103
+ (NSString *)batchPathForTarget:(GDTCORTarget)target
104
                         batchID:(NSNumber *)batchID
105
                  expirationDate:(NSDate *)expirationDate;
106
 
107
/** Returns a constructed storage path based on the given values. This path may not exist.
108
 *
109
 * @param target The target, which is necessary to be given a path.
110
 * @param eventID The eventID.
111
 * @param qosTier The qosTier.
112
 * @param expirationDate The expirationDate as a 1970-relative time interval.
113
 * @param mappingID The mappingID.
114
 * @return The path representing the combination of the given parameters.
115
 */
116
+ (NSString *)pathForTarget:(GDTCORTarget)target
117
                    eventID:(NSString *)eventID
118
                    qosTier:(NSNumber *)qosTier
119
             expirationDate:(NSDate *)expirationDate
120
                  mappingID:(NSString *)mappingID;
121
 
122
/** Returns extant paths that match all of the given parameters.
123
 *
124
 * @param eventIDs The list of eventIDs to look for, or nil for any.
125
 * @param qosTiers The list of qosTiers to look for, or nil for any.
126
 * @param mappingIDs The list of mappingIDs to look for, or nil for any.
127
 * @param onComplete The completion to call once the paths have been discovered.
128
 */
129
- (void)pathsForTarget:(GDTCORTarget)target
130
              eventIDs:(nullable NSSet<NSString *> *)eventIDs
131
              qosTiers:(nullable NSSet<NSNumber *> *)qosTiers
132
            mappingIDs:(nullable NSSet<NSString *> *)mappingIDs
133
            onComplete:(void (^)(NSSet<NSString *> *paths))onComplete;
134
 
135
/** Fetches the current batchID counter value from library storage, increments it, and sets the new
136
 * value. Returns nil if a batchID was not able to be created for some reason.
137
 *
138
 * @param onComplete A block to execute when creating the next batchID is complete.
139
 */
140
- (void)nextBatchID:(void (^)(NSNumber *_Nullable batchID))onComplete;
141
 
142
/** Constructs a dictionary of event filename components.
143
 *
144
 * @param fileName The event filename to split.
145
 * @return The dictionary of event component keys to their values.
146
 */
147
- (nullable NSDictionary<NSString *, id> *)eventComponentsFromFilename:(NSString *)fileName;
148
 
149
/** Constructs a dictionary of batch filename components.
150
 *
151
 * @param fileName The batch folder name to split.
152
 * @return The dictionary of batch component keys to their values.
153
 */
154
- (nullable NSDictionary<NSString *, id> *)batchComponentsFromFilename:(NSString *)fileName;
155
 
156
@end
157
 
158
NS_ASSUME_NONNULL_END