Files
firebase-ios-sdk/GoogleDataTransport/GDTCORLibrary/GDTCORTransport.m
T
Doudou Nan d69c642277 Delete GDTCORStoredEvent, modify apis and tests (#4880)
* Delete GDTCORStoredEvent, modify apis and tests

* styled

* Delete GDTCORDataFuture

* header changes

* add writeToURL in COREvent

* Remove dataObjectTransportBytes property in COREvent

* Set fileURL in COREvent nullable

* Change method writeToURL private and modify comments

* Modify encoding keys in GDTCORStorage and GDTCORUploadPackage

* comments and headers changes

* testMigration passed without fileURL

* Regression test passed with retrieving fileURL

* styled and added fileURL NOTNIL assert in test

* Modify backwords compatibility of GDTCORStoredEvent decoding

* Comments changes

* Add GDTCOREvent translation mapping in UploadPackage
2020-02-18 16:09:07 -08:00

108 lines
3.7 KiB
Objective-C

/*
* 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 "GDTCORLibrary/Public/GDTCORTransport.h"
#import "GDTCORLibrary/Private/GDTCORTransport_Private.h"
#import <GoogleDataTransport/GDTCORAssert.h>
#import <GoogleDataTransport/GDTCORClock.h>
#import <GoogleDataTransport/GDTCOREvent.h>
#import "GDTCORLibrary/Private/GDTCORTransformer.h"
@implementation GDTCORTransport
- (nullable instancetype)initWithMappingID:(NSString *)mappingID
transformers:
(nullable NSArray<id<GDTCOREventTransformer>> *)transformers
target:(NSInteger)target {
GDTCORAssert(mappingID.length > 0, @"A mapping ID cannot be nil or empty");
GDTCORAssert(target > 0, @"A target cannot be negative or 0");
if (mappingID == nil || mappingID.length == 0 || target <= 0) {
return nil;
}
self = [super init];
if (self) {
_mappingID = mappingID;
_transformers = transformers;
_target = target;
_transformerInstance = [GDTCORTransformer sharedInstance];
}
GDTCORLogDebug("Transport object created. mappingID:%@ transformers:%@ target:%ld", _mappingID,
_transformers, (long)_target);
return self;
}
- (void)sendTelemetryEvent:(GDTCOREvent *)event
onComplete:(void (^)(BOOL wasWritten, NSError *_Nullable error))completion {
event.qosTier = GDTCOREventQoSTelemetry;
[self sendEvent:event
onComplete:^(BOOL wasWritten, NSError *error) {
GDTCORLogDebug("Telemetry event sent: %@", event);
if (completion) {
completion(wasWritten, nil);
}
}];
}
- (void)sendDataEvent:(GDTCOREvent *)event
onComplete:(void (^)(BOOL wasWritten, NSError *_Nullable error))completion {
GDTCORAssert(event.qosTier != GDTCOREventQoSTelemetry, @"Use -sendTelemetryEvent, please.");
[self sendEvent:event
onComplete:^(BOOL wasWritten, NSError *error) {
GDTCORLogDebug("Data event sent: %@", event);
if (completion) {
completion(wasWritten, nil);
}
}];
}
- (void)sendTelemetryEvent:(GDTCOREvent *)event {
[self sendTelemetryEvent:event
onComplete:^(BOOL wasWritten, NSError *_Nullable error){
}];
}
- (void)sendDataEvent:(GDTCOREvent *)event {
[self sendDataEvent:event
onComplete:^(BOOL wasWritten, NSError *_Nullable error){
}];
}
- (GDTCOREvent *)eventForTransport {
return [[GDTCOREvent alloc] initWithMappingID:_mappingID target:_target];
}
#pragma mark - Private helper methods
/** Sends the given event through the transport pipeline.
*
* @param event The event to send.
* @param completion A block that will be called when the event has been written or dropped.
*/
- (void)sendEvent:(GDTCOREvent *)event
onComplete:(void (^)(BOOL wasWritten, NSError *error))completion {
// TODO: Determine if sending an event before registration is allowed.
GDTCORAssert(event, @"You can't send a nil event");
GDTCOREvent *copiedEvent = [event copy];
copiedEvent.clockSnapshot = [GDTCORClock snapshot];
[self.transformerInstance transformEvent:copiedEvent
withTransformers:_transformers
onComplete:completion];
}
@end