Initial commit 🎉

fbshipit-source-id: b6fc29740c6875d2e78953b8a7123890a67930f2
Co-authored-by: Sebastian McKenzie <sebmck@fb.com>
Co-authored-by: John Knox <jknox@fb.com>
Co-authored-by: Emil Sjölander <emilsj@fb.com>
Co-authored-by: Pritesh Nandgaonkar <prit91@fb.com>
This commit is contained in:
Daniel Büchele
2018-04-13 08:38:06 -07:00
committed by Daniel Buchele
commit fbbf8cf16b
659 changed files with 87130 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#import <Sonar/SonarConnection.h>
#import <SonarKit/SonarConnection.h>
/**
SonarCppBridgingConnection is a simple ObjC wrapper around SonarConnection
that forwards messages to the underlying C++ connection. This class allows
pure Objective-C plugins to send messages to the underlying connection.
*/
@interface SonarCppBridgingConnection : NSObject <SonarConnection>
- (instancetype)initWithCppConnection:(std::shared_ptr<facebook::sonar::SonarConnection>)conn;
@end

View File

@@ -0,0 +1,45 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#import "SonarCppBridgingConnection.h"
#import <FBCxxUtils/FBCxxFollyDynamicConvert.h>
#import "SonarCppBridgingResponder.h"
@implementation SonarCppBridgingConnection
{
std::shared_ptr<facebook::sonar::SonarConnection> conn_;
}
- (instancetype)initWithCppConnection:(std::shared_ptr<facebook::sonar::SonarConnection>)conn
{
if (self = [super init]) {
conn_ = conn;
}
return self;
}
#pragma mark - SonarConnection
- (void)send:(NSString *)method withParams:(NSDictionary *)params
{
conn_->send([method UTF8String], facebook::cxxutils::convertIdToFollyDynamic(params));
}
- (void)receive:(NSString *)method withBlock:(SonarReceiver)receiver
{
const auto lambda = [receiver](const folly::dynamic &message,
std::unique_ptr<facebook::sonar::SonarResponder> responder) {
SonarCppBridgingResponder *const objCResponder =
[[SonarCppBridgingResponder alloc] initWithCppResponder:std::move(responder)];
receiver(facebook::cxxutils::convertFollyDynamicToId(message), objCResponder);
};
conn_->receive([method UTF8String], lambda);
}
@end

View File

@@ -0,0 +1,18 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#import <Sonar/SonarResponder.h>
#import <SonarKit/SonarResponder.h>
/**
SonarCppBridgingResponder is a simple ObjC wrapper around SonarResponder
that forwards messages to the underlying C++ responder. This class allows
pure Objective-C plugins to send messages to the underlying responder.
*/
@interface SonarCppBridgingResponder : NSObject <SonarResponder>
- (instancetype)initWithCppResponder:(std::unique_ptr<facebook::sonar::SonarResponder>)responder;
@end

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#import "SonarCppBridgingResponder.h"
#import <FBCxxUtils/FBCxxFollyDynamicConvert.h>
@implementation SonarCppBridgingResponder {
std::unique_ptr<facebook::sonar::SonarResponder> responder_;
}
- (instancetype)initWithCppResponder:(std::unique_ptr<facebook::sonar::SonarResponder>)responder
{
if (!responder) {
return nil;
}
if (self = [super init]) {
responder_ = std::move(responder);
}
return self;
}
#pragma mark - SonarResponder
- (void)success:(NSDictionary *)response { responder_->success(facebook::cxxutils::convertIdToFollyDynamic(response)); }
- (void)error:(NSDictionary *)response { responder_->error(facebook::cxxutils::convertIdToFollyDynamic(response)); }
@end

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#ifndef __OBJC__
#error This header can only be included in .mm (ObjC++) files
#endif
#import <Sonar/SonarPlugin.h>
#import <SonarKit/SonarCppBridgingConnection.h>
#import <SonarKit/SonarPlugin.h>
namespace facebook {
namespace sonar {
using ObjCPlugin = NSObject<SonarPlugin> *;
/**
SonarCppWrapperPlugin is a simple C++ wrapper around Objective-C Sonar plugins
that can be passed to SonarClient. This class allows developers to write pure
Objective-C plugins if they want.
*/
class SonarCppWrapperPlugin final : public facebook::sonar::SonarPlugin {
public:
// Under ARC copying objCPlugin *does* increment its retain count
SonarCppWrapperPlugin(ObjCPlugin objCPlugin) : _objCPlugin(objCPlugin) {}
std::string identifier() const override { return [[_objCPlugin identifier] UTF8String]; }
void didConnect(std::shared_ptr<facebook::sonar::SonarConnection> conn) override
{
SonarCppBridgingConnection *const bridgingConn = [[SonarCppBridgingConnection alloc] initWithCppConnection:conn];
[_objCPlugin didConnect:bridgingConn];
}
void didDisconnect() override { [_objCPlugin didDisconnect]; }
ObjCPlugin getObjCPlugin() { return _objCPlugin; }
private:
ObjCPlugin _objCPlugin;
};
} // namespace sonar
} // namespace facebook