Add FBProcessOutput -> FBDataConsumer bridging
Summary: This is important for device output handling. By moving this to a protocol we can separate the adaptation concerns and at the same time bridge everything appropriately Reviewed By: zeyadsalloum Differential Revision: D14301378 fbshipit-source-id: f17979facb717cda5cdcc17dad404fad9a880890
This commit is contained in:
Родитель
003167bc73
Коммит
56da425bf4
|
@ -66,6 +66,28 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@end
|
||||
|
||||
/**
|
||||
Process Output that can be provided through a file.
|
||||
*/
|
||||
@protocol FBProcessOutput <NSObject>
|
||||
|
||||
/**
|
||||
Allows the reciever to be written to via a file instead of via a file handle.
|
||||
This is desirable to use when interacting with an API that doesn't support writing to a file handle.
|
||||
|
||||
@return A Future wrapping a FBProcessFileOutput instance.
|
||||
*/
|
||||
- (FBFuture<id<FBProcessFileOutput>> *)providedThroughFile;
|
||||
|
||||
/**
|
||||
Allows the reciever to be written to via a Data Consumer.
|
||||
|
||||
@return A Future wrapping a FBDataConsumer instance.
|
||||
*/
|
||||
- (FBFuture<id<FBDataConsumer>> *)providedThroughConsumer;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
The Termination Handle Type for Process Output.
|
||||
*/
|
||||
|
@ -74,7 +96,7 @@ extern FBiOSTargetFutureType const FBiOSTargetFutureTypeProcessOutput;
|
|||
/**
|
||||
A container object for the output of a process.
|
||||
*/
|
||||
@interface FBProcessOutput<WrappedType> : NSObject <FBStandardStream>
|
||||
@interface FBProcessOutput<WrappedType> : NSObject <FBStandardStream, FBProcessOutput>
|
||||
|
||||
#pragma mark Initializers
|
||||
|
||||
|
@ -141,16 +163,6 @@ extern FBiOSTargetFutureType const FBiOSTargetFutureTypeProcessOutput;
|
|||
*/
|
||||
@property (nonatomic, strong, readonly) WrappedType contents;
|
||||
|
||||
#pragma mark Public Methods
|
||||
|
||||
/**
|
||||
Allows the reciever to be written to via a file instead of via a file handle.
|
||||
This is desirable to use when interacting with an API that doesn't support writing to a file handle.
|
||||
|
||||
@return A Future wrapping a FBProcessFileOutput instance.
|
||||
*/
|
||||
- (FBFuture<id<FBProcessFileOutput>> *)providedThroughFile;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
|
|
|
@ -377,6 +377,20 @@ FBiOSTargetFutureType const FBiOSTargetFutureTypeProcessOutput = @"process_outpu
|
|||
return nil;
|
||||
}
|
||||
|
||||
- (FBFuture<NSNull *> *)detach
|
||||
{
|
||||
NSAssert(NO, @"-[%@ %@] is abstract and should be overridden", NSStringFromClass(self.class), NSStringFromSelector(_cmd));
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id)contents
|
||||
{
|
||||
NSAssert(NO, @"-[%@ %@] is abstract and should be overridden", NSStringFromClass(self.class), NSStringFromSelector(_cmd));
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark FBProcessOutput implementation
|
||||
|
||||
- (FBFuture<id<FBProcessFileOutput>> *)providedThroughFile
|
||||
{
|
||||
return [[self
|
||||
|
@ -386,13 +400,7 @@ FBiOSTargetFutureType const FBiOSTargetFutureTypeProcessOutput = @"process_outpu
|
|||
}];
|
||||
}
|
||||
|
||||
- (FBFuture<NSNull *> *)detach
|
||||
{
|
||||
NSAssert(NO, @"-[%@ %@] is abstract and should be overridden", NSStringFromClass(self.class), NSStringFromSelector(_cmd));
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id)contents
|
||||
- (FBFuture<id<FBDataConsumer>> *)providedThroughConsumer
|
||||
{
|
||||
NSAssert(NO, @"-[%@ %@] is abstract and should be overridden", NSStringFromClass(self.class), NSStringFromSelector(_cmd));
|
||||
return nil;
|
||||
|
@ -428,11 +436,6 @@ FBiOSTargetFutureType const FBiOSTargetFutureTypeProcessOutput = @"process_outpu
|
|||
return [self attachToFileHandle];
|
||||
}
|
||||
|
||||
- (FBFuture<id<FBProcessFileOutput>> *)providedThroughFile
|
||||
{
|
||||
return [FBFuture futureWithResult:[[FBProcessFileOutput_DirectToFile alloc] initWithFilePath:@"/dev/null"]];
|
||||
}
|
||||
|
||||
- (FBFuture<NSNull *> *)detach
|
||||
{
|
||||
return [FBFuture futureWithResult:NSNull.null];
|
||||
|
@ -443,6 +446,18 @@ FBiOSTargetFutureType const FBiOSTargetFutureTypeProcessOutput = @"process_outpu
|
|||
return NSNull.null;
|
||||
}
|
||||
|
||||
#pragma mark FBProcessOutput Implementation
|
||||
|
||||
- (FBFuture<id<FBProcessFileOutput>> *)providedThroughFile
|
||||
{
|
||||
return [FBFuture futureWithResult:[[FBProcessFileOutput_DirectToFile alloc] initWithFilePath:@"/dev/null"]];
|
||||
}
|
||||
|
||||
- (FBFuture<id<FBDataConsumer>> *)providedThroughConsumer
|
||||
{
|
||||
return [FBFuture futureWithResult:FBNullDataConsumer.new];
|
||||
}
|
||||
|
||||
#pragma mark NSObject
|
||||
|
||||
- (NSString *)description
|
||||
|
@ -499,16 +514,6 @@ FBiOSTargetFutureType const FBiOSTargetFutureTypeProcessOutput = @"process_outpu
|
|||
}];
|
||||
}
|
||||
|
||||
- (FBFuture<id<FBProcessFileOutput>> *)providedThroughFile
|
||||
{
|
||||
return [[[self
|
||||
makeFifoOutput]
|
||||
onQueue:self.workQueue map:^ id<FBProcessFileOutput> (NSString *fifoPath) {
|
||||
return [[FBProcessFileOutput_Consumer alloc] initWithConsumer:self.consumer filePath:fifoPath queue:FBProcessOutput.createWorkQueue];
|
||||
}]
|
||||
nameFormat:@"Relay %@ to file", self.description];
|
||||
}
|
||||
|
||||
- (FBFuture<NSNull *> *)detach
|
||||
{
|
||||
return [[[[self.reader.finishedReading
|
||||
|
@ -532,6 +537,23 @@ FBiOSTargetFutureType const FBiOSTargetFutureTypeProcessOutput = @"process_outpu
|
|||
return self.consumer;
|
||||
}
|
||||
|
||||
#pragma mark FBProcessOutput Implementation
|
||||
|
||||
- (FBFuture<id<FBProcessFileOutput>> *)providedThroughFile
|
||||
{
|
||||
return [[[self
|
||||
makeFifoOutput]
|
||||
onQueue:self.workQueue map:^ id<FBProcessFileOutput> (NSString *fifoPath) {
|
||||
return [[FBProcessFileOutput_Consumer alloc] initWithConsumer:self.consumer filePath:fifoPath queue:FBProcessOutput.createWorkQueue];
|
||||
}]
|
||||
nameFormat:@"Relay %@ to file", self.description];
|
||||
}
|
||||
|
||||
- (FBFuture<id<FBDataConsumer>> *)providedThroughConsumer
|
||||
{
|
||||
return [FBFuture futureWithResult:self.consumer];
|
||||
}
|
||||
|
||||
#pragma mark NSObject
|
||||
|
||||
- (NSString *)description
|
||||
|
@ -638,14 +660,21 @@ FBiOSTargetFutureType const FBiOSTargetFutureTypeProcessOutput = @"process_outpu
|
|||
nameFormat:@"Detach from %@", self.description];
|
||||
}
|
||||
|
||||
- (NSString *)contents
|
||||
{
|
||||
return self.filePath;
|
||||
}
|
||||
|
||||
#pragma mark FBProcessOutput Implementation
|
||||
|
||||
- (FBFuture<id<FBProcessFileOutput>> *)providedThroughFile
|
||||
{
|
||||
return [FBFuture futureWithResult:[[FBProcessFileOutput_DirectToFile alloc] initWithFilePath:self.filePath]];
|
||||
}
|
||||
|
||||
- (NSString *)contents
|
||||
- (FBFuture<id<FBDataConsumer>> *)providedThroughConsumer
|
||||
{
|
||||
return self.filePath;
|
||||
return (FBFuture<id<FBDataConsumer>> *) [FBFileWriter asyncWriterForFilePath:self.filePath];
|
||||
}
|
||||
|
||||
#pragma mark NSObject
|
||||
|
|
Загрузка…
Ссылка в новой задаче