diff --git a/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogClock.h b/GoogleDataLogger/GoogleDataLogger/Classes/GDLClock.h similarity index 97% rename from GoogleDataLogger/GoogleDataLogger/Classes/GDLLogClock.h rename to GoogleDataLogger/GoogleDataLogger/Classes/GDLClock.h index 107b4a8a4db..9e42e5e3883 100644 --- a/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogClock.h +++ b/GoogleDataLogger/GoogleDataLogger/Classes/GDLClock.h @@ -31,7 +31,7 @@ typedef struct { } GDLLogClockSnapshot; /** This class manages the device clock and produces snapshots of the current time. */ -@interface GDLLogClock : NSObject +@interface GDLClock : NSObject // TODO(mikehaney24): - (GDLLogClockSnapshot)snapshot; diff --git a/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogClock.m b/GoogleDataLogger/GoogleDataLogger/Classes/GDLClock.m similarity index 92% rename from GoogleDataLogger/GoogleDataLogger/Classes/GDLLogClock.m rename to GoogleDataLogger/GoogleDataLogger/Classes/GDLClock.m index 0935d8ba841..224f14f3455 100644 --- a/GoogleDataLogger/GoogleDataLogger/Classes/GDLLogClock.m +++ b/GoogleDataLogger/GoogleDataLogger/Classes/GDLClock.m @@ -14,8 +14,8 @@ * limitations under the License. */ -#import "GDLLogClock.h" +#import "GDLClock.h" -@implementation GDLLogClock +@implementation GDLClock @end diff --git a/GoogleDataLogger/GoogleDataLogger/Classes/GDLRegistrar.m b/GoogleDataLogger/GoogleDataLogger/Classes/GDLRegistrar.m new file mode 100644 index 00000000000..8520dbfd17f --- /dev/null +++ b/GoogleDataLogger/GoogleDataLogger/Classes/GDLRegistrar.m @@ -0,0 +1,39 @@ +/* + * Copyright 2018 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "GDLRegistrar.h" + +@implementation GDLRegistrar + ++ (instancetype)sharedInstance { + static GDLRegistrar *sharedInstance; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstance = [[GDLRegistrar alloc] init]; + }); + return sharedInstance; +} + +- (void)registerBackend:(id)backend forLogTarget:(NSInteger)logTarget { + // TODO +} + +- (void)registerLogPrioritizer:(id)prioritizer + forLogTarget:(NSInteger)logTarget { + // TODO +} + +@end diff --git a/GoogleDataLogger/GoogleDataLogger/Classes/Private/GDLLogEvent_Private.h b/GoogleDataLogger/GoogleDataLogger/Classes/Private/GDLLogEvent_Private.h index 1df364bcb58..ad1b1ee07d9 100644 --- a/GoogleDataLogger/GoogleDataLogger/Classes/Private/GDLLogEvent_Private.h +++ b/GoogleDataLogger/GoogleDataLogger/Classes/Private/GDLLogEvent_Private.h @@ -16,7 +16,7 @@ #import "GDLLogEvent.h" -#import "GDLLogClock.h" +#import "GDLClock.h" NS_ASSUME_NONNULL_BEGIN diff --git a/GoogleDataLogger/GoogleDataLogger/Classes/Private/GDLRegistrar_Private.h b/GoogleDataLogger/GoogleDataLogger/Classes/Private/GDLRegistrar_Private.h new file mode 100644 index 00000000000..0ee36e16a61 --- /dev/null +++ b/GoogleDataLogger/GoogleDataLogger/Classes/Private/GDLRegistrar_Private.h @@ -0,0 +1,27 @@ +/* + * Copyright 2018 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@interface GDLRegistrar () + +/** A map of logTargets to backend implementations. */ +@property(nonatomic) NSDictionary> *logTargetToBackend; + +/** A map of logTargets to prioritizer implementations. */ +@property(nonatomic) NSDictionary> *logTargetToPrioritizer; + +@end diff --git a/GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogBackend.h b/GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogBackend.h new file mode 100644 index 00000000000..8c17ec57a65 --- /dev/null +++ b/GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogBackend.h @@ -0,0 +1,39 @@ +/* + * Copyright 2018 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +/** A convenient typedef to define the block to be called upon completion of an upload to the + * backend. + */ +typedef void (^GDLBackendCompletionBlock)(NSSet *successfulUploads, + NSSet *unsuccessfulUploads); + +/** This protocol defines the common interface for logging backend implementations. */ +@protocol GDLLogBackend + +@required + +/** Uploads logs to the backend using this specific backend's chosen format. + * + * @param logFiles The set of log files to upload. + * @param onComplete A block to invoke upon completing the upload. Has two arguments: + * - successfulUploads: The set of filenames uploaded successfully. + * - unsuccessfulUploads: The set of filenames not uploaded successfully. + */ +- (void)uploadLogs:(NSSet *)logFiles onComplete:(GDLBackendCompletionBlock)onComplete; + +@end diff --git a/GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogPrioritizer.h b/GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogPrioritizer.h new file mode 100644 index 00000000000..1cb547479ad --- /dev/null +++ b/GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogPrioritizer.h @@ -0,0 +1,47 @@ +/* + * Copyright 2018 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@class GDLLogEvent; + +/** This protocol defines the common interface of a log prioritization. Log prioritizers are + * stateful objects that prioritize logs upon insertion into storage and remain prepared to return a + * set of log filenames to the storage system. + */ +@protocol GDLLogPrioritizer + +@required + +/** Accepts a logEvent and uses the log metadata to make choices on how to prioritize the log. This + * method exists as a way to help prioritize which logs should be sent, which is dependent on the + * request proto structure of your backend. + * + * @note Three things: 1. the logEvent cannot be retained for longer than the execution time of + * this method. 2. The extension should be nil by this point and should not be used to prioritize + * logs. 3. You should retain the logEvent hashes, because those are returned in logsForNextUpload. + * + * @param logEvent The log event to prioritize. + */ +- (void)prioritizeLog:(GDLLogEvent *)logEvent; + +/** Returns a set of logs based on the logic of the prioritizer. + * + * @return A set of log hashes to upload, presumably based on the logs' priority. + */ +- (NSSet *)logsForNextUpload; + +@end diff --git a/GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLRegistrar.h b/GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLRegistrar.h new file mode 100644 index 00000000000..d16e47714dc --- /dev/null +++ b/GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLRegistrar.h @@ -0,0 +1,49 @@ +/* + * Copyright 2018 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +/** Manages the registration of log targets with the logging SDK. */ +@interface GDLRegistrar : NSObject + +/** Creates and/or returns the singleton instance. + * + * @return The singleton instance of this class. + */ ++ (instancetype)sharedInstance; + +/** Registers a backend implementation with the GoogleDataLogger infrastructure. + * + * @param backend The backend object to register. + * @param logTarget The logTarget this backend object will be responsible for. + */ +- (void)registerBackend:(id)backend forLogTarget:(NSInteger)logTarget; + +/** Registers a log prioritizer implementation with the GoogleDataLogger infrastructure. + * + * @param prioritizer The prioritizer object to register. + * @param logTarget The logTarget this prioritizer object will be responsible for. + */ +- (void)registerLogPrioritizer:(id)prioritizer forLogTarget:(NSInteger)logTarget; + +@end + +NS_ASSUME_NONNULL_END diff --git a/GoogleDataLogger/Tests/GDLRegistrarTest.m b/GoogleDataLogger/Tests/GDLRegistrarTest.m new file mode 100644 index 00000000000..d2f5727f67d --- /dev/null +++ b/GoogleDataLogger/Tests/GDLRegistrarTest.m @@ -0,0 +1,32 @@ +/* + * Copyright 2018 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import + +@interface GDLRegistrarTest : XCTestCase + +@end + +@implementation GDLRegistrarTest + +/** Tests the default initializer. */ +- (void)testInit { + XCTAssertNotNil([[GDLRegistrarTest alloc] init]); +} + +@end