Skip to content

Commit

Permalink
[wip] library: migrate public/feature layer of iOS library to Swift
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Schore <[email protected]>
  • Loading branch information
goaway committed Jun 26, 2019
1 parent 84a83f6 commit e8d8ec2
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 88 deletions.
5 changes: 1 addition & 4 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ envoy_package()

ios_static_framework(
name = "ios_framework",
hdrs = [
"//library/objective-c:envoy_framework_headers",
],
bundle_name = "Envoy",
minimum_os_version = "10.0",
visibility = ["//visibility:public"],
deps = ["//library/objective-c:envoy_objc_interface_lib"],
deps = ["//library/swift:envoy_swift_lib"],
)

genrule(
Expand Down
10 changes: 1 addition & 9 deletions library/objective-c/BUILD
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
licenses(["notice"]) # Apache 2

filegroup(
name = "envoy_framework_headers",
srcs = [
"Envoy.h",
],
visibility = ["//visibility:public"],
)

objc_library(
name = "envoy_objc_interface_lib",
name = "envoy_engine_objc_lib",
srcs = [
"Envoy.h",
"Envoy.mm",
Expand Down
19 changes: 0 additions & 19 deletions library/objective-c/Envoy.h

This file was deleted.

56 changes: 0 additions & 56 deletions library/objective-c/Envoy.mm

This file was deleted.

14 changes: 14 additions & 0 deletions library/objective-c/EnvoyEngine.h
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
23 changes: 23 additions & 0 deletions library/objective-c/EnvoyEngine.mm
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
11 changes: 11 additions & 0 deletions library/swift/BUILD
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"]
)
37 changes: 37 additions & 0 deletions library/swift/Envoy.swift
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)
}
}
}

0 comments on commit e8d8ec2

Please sign in to comment.