-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wip] library: migrate public/feature layer of iOS library to Swift
Signed-off-by: Mike Schore <[email protected]>
- Loading branch information
Showing
8 changed files
with
87 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
/// Wrapper layer to simplify calling into Envoy's C++ API. | ||
@interface EnvoyEngine : NSObject | ||
|
||
/// Run the Envoy engine with the provided config and log level. This call is synchronous | ||
/// and will not yield. | ||
+ (int)runWithConfig:(NSString *)config logLevel:(NSString *)logLevel; | ||
|
||
/// Run the Envoy engine with the provided config and log level. This call is synchronous | ||
/// and will not yield. | ||
+ (int)runWithConfig:(NSString *)config; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#import "library/objective-c/EnvoyEngine.h" | ||
|
||
#import "library/common/main_interface.h" | ||
|
||
@implementation EnvoyEngine | ||
|
||
+ (int)runWithConfig:(NSString *config) { | ||
return [self runWithConfig:config logLevel:@"info"]; | ||
} | ||
|
||
+ (void)runWithConfig:(NSString *config) logLevel:(NSString *logLevel) { | ||
try { | ||
return run_envoy(config.UTF8String, logLevel.UTF8String); | ||
} catch (NSException *e) { | ||
NSLog(@"Envoy exception: %@", e); | ||
NSDictionary *userInfo = @{ @"exception": e}; | ||
[NSNotificationCenter.defaultCenter postNotificationName:@"EnvoyException" | ||
object:self | ||
userInfo:userInfo]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
licenses(["notice"]) # Apache 2 | ||
|
||
swift_library( | ||
name = "envoy_swift_lib", | ||
srcs = [ | ||
"Envoy.swift", | ||
], | ||
module_name = "Envoy", | ||
visibility = ["//visibility:public"], | ||
deps = ["//library/objective-c:envoy_engine_objc_lib"] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Foundation | ||
import EnvoyEngine | ||
|
||
public class Envoy { | ||
private let runner: EnvoyRunner | ||
|
||
public var isRunning: Bool { | ||
runner.isExecuting() | ||
} | ||
|
||
public var isTerminated: Bool { | ||
runner.isFinished() | ||
} | ||
|
||
public init(config: String, logLevel: String) { | ||
runner = EnvoyRunner(config: config, logLevel: logLevel) | ||
runner.start() | ||
} | ||
|
||
public convenience init(config: String) { | ||
self.init(config: config, logLevel: "info") | ||
} | ||
|
||
private class EnvoyRunner : Thread { | ||
let config: String | ||
let logLevel: String | ||
|
||
init(config: String, logLevel: String) { | ||
self.config = config | ||
self.logLevel = logLevel | ||
} | ||
|
||
func main() { | ||
EngineEngine.run(config: config, logLevel: logLevel) | ||
} | ||
} | ||
} |