Run CLANGFORMAT on plugins

Summary:
This diff runs CLANGFORMAT lint on plugins. I have added CLANGFORMAT as the lint engined for objc files in xplat/sonar. Right now the iOS folder is not formatted according to CLANGFORMAT.

Ran `arc lint -a --paths-cmd "find ./iOS/Plugins -type f" --verbose`

Reviewed By: passy

Differential Revision: D19942173

fbshipit-source-id: 8b975b0a344df073b02d69cd1f9ee5629af2799d
This commit is contained in:
Pritesh Nandgaonkar
2020-02-17 10:46:43 -08:00
committed by Facebook Github Bot
parent a19a430eee
commit e8b20d5b15
101 changed files with 3918 additions and 2867 deletions

View File

@@ -13,12 +13,16 @@
#import "SKBufferingPlugin.h"
#import "SKNetworkReporter.h"
@interface FlipperKitNetworkPlugin : SKBufferingPlugin <SKNetworkReporterDelegate>
@interface FlipperKitNetworkPlugin
: SKBufferingPlugin<SKNetworkReporterDelegate>
- (instancetype)initWithNetworkAdapter:(id<SKNetworkAdapterDelegate>)adapter NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithNetworkAdapter:(id<SKNetworkAdapterDelegate>)adapter queue:(dispatch_queue_t)queue; //For test purposes
- (instancetype)initWithNetworkAdapter:(id<SKNetworkAdapterDelegate>)adapter
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithNetworkAdapter:(id<SKNetworkAdapterDelegate>)adapter
queue:(dispatch_queue_t)
queue; // For test purposes
@property (strong, nonatomic) id<SKNetworkAdapterDelegate> adapter;
@property(strong, nonatomic) id<SKNetworkAdapterDelegate> adapter;
@end

View File

@@ -6,14 +6,14 @@
*/
#if FB_SONARKIT_ENABLED
#import <vector>
#import "FlipperKitNetworkPlugin.h"
#import <iostream>
#import <memory>
#import "FlipperKitNetworkPlugin.h"
#import "SKNetworkReporter.h"
#import "SonarKitNetworkPlugin+CPPInitialization.h"
#import <vector>
#import "SKBufferingPlugin+CPPInitialization.h"
#import "SKDispatchQueue.h"
#import "SKNetworkReporter.h"
#import "SonarKitNetworkPlugin+CPPInitialization.h"
@interface FlipperKitNetworkPlugin ()
@@ -27,20 +27,26 @@
}
- (instancetype)init {
if (self = [super initWithQueue:dispatch_queue_create("com.sonarkit.network.buffer", DISPATCH_QUEUE_SERIAL)]) {
if (self = [super initWithQueue:dispatch_queue_create(
"com.sonarkit.network.buffer",
DISPATCH_QUEUE_SERIAL)]) {
}
return self;
}
- (instancetype)initWithNetworkAdapter:(id<SKNetworkAdapterDelegate>)adapter {
if (self = [super initWithQueue:dispatch_queue_create("com.sonarkit.network.buffer", DISPATCH_QUEUE_SERIAL)]) {
if (self = [super initWithQueue:dispatch_queue_create(
"com.sonarkit.network.buffer",
DISPATCH_QUEUE_SERIAL)]) {
adapter.delegate = self;
_adapter = adapter;
}
return self;
}
- (instancetype)initWithNetworkAdapter:(id<SKNetworkAdapterDelegate>)adapter queue:(dispatch_queue_t)queue; {
- (instancetype)initWithNetworkAdapter:(id<SKNetworkAdapterDelegate>)adapter
queue:(dispatch_queue_t)queue;
{
if (self = [super initWithQueue:queue]) {
adapter.delegate = self;
_adapter = adapter;
@@ -50,68 +56,65 @@
#pragma mark - SKNetworkReporterDelegate
- (void)didObserveRequest:(SKRequestInfo *)request
{
NSMutableArray<NSDictionary<NSString *, id> *> *headers = [NSMutableArray new];
for (NSString *key in [request.request.allHTTPHeaderFields allKeys]) {
NSDictionary<NSString *, id> *header = @{
@"key": key,
@"value": request.request.allHTTPHeaderFields[key]
};
[headers addObject: header];
- (void)didObserveRequest:(SKRequestInfo*)request {
NSMutableArray<NSDictionary<NSString*, id>*>* headers = [NSMutableArray new];
for (NSString* key in [request.request.allHTTPHeaderFields allKeys]) {
NSDictionary<NSString*, id>* header =
@{@"key" : key, @"value" : request.request.allHTTPHeaderFields[key]};
[headers addObject:header];
}
NSString *body = request.body;
NSString* body = request.body;
[self send:@"newRequest"
sonarObject:@{
@"id": @(request.identifier),
@"timestamp": @(request.timestamp),
@"method": request.request.HTTPMethod ?: [NSNull null],
@"url": [request.request.URL absoluteString] ?: [NSNull null],
@"headers": headers,
@"data": body ? body : [NSNull null]
}];
sonarObject:@{
@"id" : @(request.identifier),
@"timestamp" : @(request.timestamp),
@"method" : request.request.HTTPMethod ?: [NSNull null],
@"url" : [request.request.URL absoluteString] ?: [NSNull null],
@"headers" : headers,
@"data" : body ? body : [NSNull null]
}];
}
- (void)didObserveResponse:(SKResponseInfo *)response
{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response.response;
- (void)didObserveResponse:(SKResponseInfo*)response {
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response.response;
NSMutableArray<NSDictionary<NSString *, id> *> *headers = [NSMutableArray new];
for (NSString *key in [httpResponse.allHeaderFields allKeys]) {
NSDictionary<NSString *, id> *header = @{
@"key": key,
@"value": httpResponse.allHeaderFields[key]
};
[headers addObject: header];
NSMutableArray<NSDictionary<NSString*, id>*>* headers = [NSMutableArray new];
for (NSString* key in [httpResponse.allHeaderFields allKeys]) {
NSDictionary<NSString*, id>* header =
@{@"key" : key, @"value" : httpResponse.allHeaderFields[key]};
[headers addObject:header];
}
NSString *body = response.body;
NSString* body = response.body;
[self send:@"newResponse"
sonarObject:@{
@"id": @(response.identifier),
@"timestamp": @(response.timestamp),
@"status": @(httpResponse.statusCode),
@"reason": [NSHTTPURLResponse localizedStringForStatusCode: httpResponse.statusCode] ?: [NSNull null],
@"headers": headers,
@"data": body ? body : [NSNull null]
}];
sonarObject:@{
@"id" : @(response.identifier),
@"timestamp" : @(response.timestamp),
@"status" : @(httpResponse.statusCode),
@"reason" : [NSHTTPURLResponse
localizedStringForStatusCode:httpResponse.statusCode]
?: [NSNull null],
@"headers" : headers,
@"data" : body ? body : [NSNull null]
}];
}
@end
@implementation FlipperKitNetworkPlugin (CPPInitialization)
- (instancetype)initWithNetworkAdapter:(id<SKNetworkAdapterDelegate>)adapter dispatchQueue:(std::shared_ptr<facebook::flipper::DispatchQueue>)queue {
if (self = [super initWithDispatchQueue:queue]) {
adapter.delegate = self;
_adapter = adapter;
}
return self;
- (instancetype)initWithNetworkAdapter:(id<SKNetworkAdapterDelegate>)adapter
dispatchQueue:
(std::shared_ptr<facebook::flipper::DispatchQueue>)
queue {
if (self = [super initWithDispatchQueue:queue]) {
adapter.delegate = self;
_adapter = adapter;
}
return self;
}
@end

View File

@@ -8,21 +8,24 @@
#if FB_SONARKIT_ENABLED
#pragma once
#import "SKBufferingPlugin.h"
#import "SKDispatchQueue.h"
#import <iostream>
#import <memory>
#import "SKBufferingPlugin.h"
#import "SKDispatchQueue.h"
struct CachedEvent {
NSString *method;
NSDictionary<NSString *, id> *sonarObject;
NSString* method;
NSDictionary<NSString*, id>* sonarObject;
};
@interface SKBufferingPlugin (CPPInitialization)
@interface SKBufferingPlugin(CPPInitialization)
- (instancetype)initWithVectorEventSize:(NSUInteger)size connectionAccessQueue:(std::shared_ptr<facebook::flipper::DispatchQueue>)connectionAccessQueue;
- (instancetype)initWithDispatchQueue:(std::shared_ptr<facebook::flipper::DispatchQueue>)queue;
- (instancetype)initWithVectorEventSize:(NSUInteger)size
connectionAccessQueue:
(std::shared_ptr<facebook::flipper::DispatchQueue>)
connectionAccessQueue;
- (instancetype)initWithDispatchQueue:
(std::shared_ptr<facebook::flipper::DispatchQueue>)queue;
@end

View File

@@ -15,7 +15,8 @@
- (instancetype)initWithQueue:(dispatch_queue_t)queue NS_DESIGNATED_INITIALIZER;
- (void)send:(NSString *)method sonarObject:(NSDictionary<NSString *, id> *)sonarObject;
- (void)send:(NSString*)method
sonarObject:(NSDictionary<NSString*, id>*)sonarObject;
@end

View File

@@ -9,17 +9,18 @@
#import <vector>
#import "SKBufferingPlugin.h"
#import <FlipperKit/FlipperConnection.h>
#import "SKDispatchQueue.h"
#import "SKBufferingPlugin+CPPInitialization.h"
#import "SKBufferingPlugin.h"
#import "SKDispatchQueue.h"
static const NSUInteger bufferSize = 500;
@interface SKBufferingPlugin()
@interface SKBufferingPlugin ()
@property(assign, nonatomic) std::vector<CachedEvent> ringBuffer;
@property(assign, nonatomic) std::shared_ptr<facebook::flipper::DispatchQueue> connectionAccessQueue;
@property(assign, nonatomic) std::shared_ptr<facebook::flipper::DispatchQueue>
connectionAccessQueue;
@property(strong, nonatomic) id<FlipperConnection> connection;
@end
@@ -35,12 +36,13 @@ static const NSUInteger bufferSize = 500;
- (instancetype)initWithQueue:(dispatch_queue_t)queue {
if (self = [super init]) {
_ringBuffer.reserve(bufferSize);
_connectionAccessQueue = std::make_shared<facebook::flipper::GCDQueue>(queue);
_connectionAccessQueue =
std::make_shared<facebook::flipper::GCDQueue>(queue);
}
return self;
}
- (NSString *)identifier {
- (NSString*)identifier {
// Note: This must match with the javascript pulgin identifier!!
return @"Network";
}
@@ -62,9 +64,8 @@ static const NSUInteger bufferSize = 500;
return YES;
}
- (void)send:(NSString *)method
sonarObject:(NSDictionary<NSString *, id> *)sonarObject {
- (void)send:(NSString*)method
sonarObject:(NSDictionary<NSString*, id>*)sonarObject {
_connectionAccessQueue->async(^{
if (self->_connection) {
[self->_connection send:method withParams:sonarObject];
@@ -72,17 +73,15 @@ static const NSUInteger bufferSize = 500;
if (self->_ringBuffer.size() == bufferSize) {
return;
}
self->_ringBuffer.push_back({
.method = method,
.sonarObject = sonarObject
});
self->_ringBuffer.push_back(
{.method = method, .sonarObject = sonarObject});
}
});
}
- (void)sendBufferedEvents {
NSAssert(_connection, @"connection object cannot be nil");
for (const auto &event : _ringBuffer) {
for (const auto& event : _ringBuffer) {
[_connection send:event.method withParams:event.sonarObject];
}
_ringBuffer.clear();
@@ -90,22 +89,23 @@ static const NSUInteger bufferSize = 500;
@end
@implementation SKBufferingPlugin(CPPInitialization)
@implementation SKBufferingPlugin (CPPInitialization)
- (instancetype)initWithVectorEventSize:(NSUInteger)size connectionAccessQueue:(std::shared_ptr<facebook::flipper::DispatchQueue>)connectionAccessQueue {
if (self = [super init]) {
_ringBuffer.reserve(size);
_connectionAccessQueue = connectionAccessQueue;
}
return self;
- (instancetype)initWithVectorEventSize:(NSUInteger)size
connectionAccessQueue:
(std::shared_ptr<facebook::flipper::DispatchQueue>)
connectionAccessQueue {
if (self = [super init]) {
_ringBuffer.reserve(size);
_connectionAccessQueue = connectionAccessQueue;
}
return self;
}
- (instancetype)initWithDispatchQueue:(std::shared_ptr<facebook::flipper::DispatchQueue>)queue {
return [self initWithVectorEventSize:bufferSize
connectionAccessQueue:queue];
- (instancetype)initWithDispatchQueue:
(std::shared_ptr<facebook::flipper::DispatchQueue>)queue {
return [self initWithVectorEventSize:bufferSize connectionAccessQueue:queue];
}
@end
#endif

View File

@@ -12,31 +12,28 @@
#import <dispatch/dispatch.h>
namespace facebook {
namespace flipper {
class DispatchQueue
{
public:
virtual void async(dispatch_block_t block) = 0;
virtual ~DispatchQueue() { }
};
namespace flipper {
class DispatchQueue {
public:
virtual void async(dispatch_block_t block) = 0;
virtual ~DispatchQueue() {}
};
class GCDQueue: public DispatchQueue
{
public:
GCDQueue(dispatch_queue_t underlyingQueue)
:_underlyingQueue(underlyingQueue) { }
class GCDQueue : public DispatchQueue {
public:
GCDQueue(dispatch_queue_t underlyingQueue)
: _underlyingQueue(underlyingQueue) {}
void async(dispatch_block_t block) override
{
dispatch_async(_underlyingQueue, block);
}
virtual ~GCDQueue() { }
private:
dispatch_queue_t _underlyingQueue;
};
void async(dispatch_block_t block) override {
dispatch_async(_underlyingQueue, block);
}
}
virtual ~GCDQueue() {}
private:
dispatch_queue_t _underlyingQueue;
};
} // namespace flipper
} // namespace facebook
#endif

View File

@@ -11,13 +11,13 @@
@protocol SKNetworkReporterDelegate
- (void)didObserveRequest:(SKRequestInfo *)request;
- (void)didObserveResponse:(SKResponseInfo *)response;
- (void)didObserveRequest:(SKRequestInfo*)request;
- (void)didObserveResponse:(SKResponseInfo*)response;
@end
@protocol SKNetworkAdapterDelegate
@property (weak, nonatomic) id<SKNetworkReporterDelegate> delegate;
@property(weak, nonatomic) id<SKNetworkReporterDelegate> delegate;
@end

View File

@@ -7,13 +7,16 @@
#import <Foundation/Foundation.h>
@interface SKRequestInfo: NSObject
@interface SKRequestInfo : NSObject
@property(assign, readwrite) int64_t identifier;
@property(assign, readwrite) uint64_t timestamp;
@property(strong, nonatomic) NSURLRequest* request;
@property(strong, nonatomic) NSString* body;
- (instancetype)initWithIdentifier:(int64_t)identifier timestamp:(uint64_t)timestamp request:(NSURLRequest*)request data:(NSData *)data;
- (void)setBodyFromData:(NSData * _Nullable)data;
- (instancetype)initWithIdentifier:(int64_t)identifier
timestamp:(uint64_t)timestamp
request:(NSURLRequest*)request
data:(NSData*)data;
- (void)setBodyFromData:(NSData* _Nullable)data;
@end

View File

@@ -13,21 +13,23 @@
@synthesize request = _request;
@synthesize body = _body;
- (instancetype)initWithIdentifier:(int64_t)identifier timestamp:(uint64_t)timestamp request:(NSURLRequest *)request data:(NSData *)data{
if (self = [super init]){
- (instancetype)initWithIdentifier:(int64_t)identifier
timestamp:(uint64_t)timestamp
request:(NSURLRequest*)request
data:(NSData*)data {
if (self = [super init]) {
_identifier = identifier;
_timestamp = timestamp;
_request = request;
_body = data ? [data base64EncodedStringWithOptions: 0]
: [request.HTTPBody base64EncodedStringWithOptions: 0];
_body = data ? [data base64EncodedStringWithOptions:0]
: [request.HTTPBody base64EncodedStringWithOptions:0];
}
return self;
}
- (void)setBodyFromData:(NSData * _Nullable)data {
self.body = data ? [data base64EncodedStringWithOptions: 0]
: [self.request.HTTPBody base64EncodedStringWithOptions: 0];
- (void)setBodyFromData:(NSData* _Nullable)data {
self.body = data ? [data base64EncodedStringWithOptions:0]
: [self.request.HTTPBody base64EncodedStringWithOptions:0];
}
@end

View File

@@ -14,7 +14,10 @@
@property(strong, nonatomic) NSURLResponse* response;
@property(strong, nonatomic) NSString* body;
- (instancetype)initWithIndentifier:(int64_t)identifier timestamp:(uint64_t)timestamp response:(NSURLResponse *)response data:(NSData *)data;
- (void)setBodyFromData:(NSData * _Nullable)data;
- (instancetype)initWithIndentifier:(int64_t)identifier
timestamp:(uint64_t)timestamp
response:(NSURLResponse*)response
data:(NSData*)data;
- (void)setBodyFromData:(NSData* _Nullable)data;
@end

View File

@@ -13,30 +13,37 @@
@synthesize response = _response;
@synthesize body = _body;
- (instancetype)initWithIndentifier:(int64_t)identifier timestamp:(uint64_t)timestamp response:(NSURLResponse *)response data:(NSData *)data {
if(self = [super init]) {
- (instancetype)initWithIndentifier:(int64_t)identifier
timestamp:(uint64_t)timestamp
response:(NSURLResponse*)response
data:(NSData*)data {
if (self = [super init]) {
_identifier = identifier;
_timestamp = timestamp;
_response = response;
_body = [SKResponseInfo shouldStripReponseBodyWithResponse:response] ? nil : [data base64EncodedStringWithOptions: 0];
_body = [SKResponseInfo shouldStripReponseBodyWithResponse:response]
? nil
: [data base64EncodedStringWithOptions:0];
}
return self;
}
+ (BOOL) shouldStripReponseBodyWithResponse:(NSURLResponse *)response {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
NSString *contentType = httpResponse.allHeaderFields[@"content-type"];
+ (BOOL)shouldStripReponseBodyWithResponse:(NSURLResponse*)response {
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
NSString* contentType = httpResponse.allHeaderFields[@"content-type"];
if (!contentType) {
return NO;
}
return [contentType containsString:@"image/"] ||
[contentType containsString:@"video/"] ||
[contentType containsString:@"application/zip"];
[contentType containsString:@"video/"] ||
[contentType containsString:@"application/zip"];
}
- (void)setBodyFromData:(NSData *_Nullable)data {
self.body = [SKResponseInfo shouldStripReponseBodyWithResponse:self.response] ? nil : [data base64EncodedStringWithOptions: 0];
- (void)setBodyFromData:(NSData* _Nullable)data {
self.body = [SKResponseInfo shouldStripReponseBodyWithResponse:self.response]
? nil
: [data base64EncodedStringWithOptions:0];
}
@end

View File

@@ -8,11 +8,14 @@
#if FB_SONARKIT_ENABLED
#pragma once
#import <memory>
#import "FlipperKitNetworkPlugin.h"
#import "SKDispatchQueue.h"
#import <memory>
@interface FlipperKitNetworkPlugin(CPPInitialization)
- (instancetype)initWithNetworkAdapter:(id<SKNetworkAdapterDelegate>)adapter dispatchQueue:(std::shared_ptr<facebook::flipper::DispatchQueue>)queue;
@interface FlipperKitNetworkPlugin (CPPInitialization)
- (instancetype)initWithNetworkAdapter:(id<SKNetworkAdapterDelegate>)adapter
dispatchQueue:
(std::shared_ptr<facebook::flipper::DispatchQueue>)
queue;
@end
#endif