Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Schore <mike.schore@gmail.com>
  • Loading branch information
goaway committed Aug 5, 2019
1 parent bd628b8 commit e778006
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 39 deletions.
2 changes: 1 addition & 1 deletion bazel/swift_static_framework.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def swift_static_framework(
if objc_includes:
locations = ["$(location {})".format(x) for x in objc_includes]
for location in locations:
copts = copts + ["-import-objc-header", location]
copts = copts + ["-import-objc-header", location]
swiftc_inputs = swiftc_inputs + objc_includes

swift_library(
Expand Down
14 changes: 7 additions & 7 deletions library/objective-c/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ exports_files([
objc_library(
name = "envoy_engine_objc_lib",
srcs = [
"EnvoyEngineImpl.m",
"EnvoyHttpStream.m",
"EnvoyEngine.h",
"EnvoyEngineImpl.h",
"EnvoyEngineImpl.m",
"EnvoyHttpStream.h",
"EnvoyHttpStream.m",
"EnvoyTypes.h",
],
],
hdrs = [
# "EnvoyEngine.h",
# "EnvoyEngineImpl.h",
# "EnvoyHttpStream.h",
# "EnvoyTypes.h",
# "EnvoyEngine.h",
# "EnvoyEngineImpl.h",
# "EnvoyHttpStream.h",
# "EnvoyTypes.h",
],
visibility = ["//visibility:public"],
deps = ["//library/common:envoy_main_interface_lib"],
Expand Down
3 changes: 1 addition & 2 deletions library/objective-c/EnvoyEngineImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ + (EnvoyStatus)runWithConfig:(NSString *)config logLevel:(NSString *)logLevel {
return (EnvoyStatus)run_engine(config.UTF8String, logLevel.UTF8String);
} @catch (...) {
NSLog(@"Envoy exception caught.");
[NSNotificationCenter.defaultCenter postNotificationName:@"EnvoyException"
object:self];
[NSNotificationCenter.defaultCenter postNotificationName:@"EnvoyException" object:self];
return EnvoyStatusFailure;
}
}
Expand Down
44 changes: 17 additions & 27 deletions library/objective-c/EnvoyHttpStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
// return envoy_nodata;
// }

static void ios_free_native_data(void *context) {
free(context);
}
static void ios_free_native_data(void *context) { free(context); }

// static void ios_release_native_data(void *context) {
// // TODO: implement me
Expand All @@ -28,7 +26,7 @@ static envoy_data toManagedNativeString(NSString *s) {
size_t length = s.length;
uint8_t *native_string = (uint8_t *)malloc(sizeof(uint8_t) * length);
memcpy(native_string, s.UTF8String, length);
envoy_data ret = { length, native_string, ios_free_native_data, native_string };
envoy_data ret = {length, native_string, ios_free_native_data, native_string};
return ret;
}

Expand All @@ -42,25 +40,24 @@ static envoy_headers toNativeHeaders(EnvoyHeaders *headers) {
for (id headerKey in headers) {
NSArray *headerList = headers[headerKey];
for (id headerValue in headerList) {
envoy_header new_header = {
toManagedNativeString(headerKey),
toManagedNativeString(headerValue)
};
envoy_header new_header = {toManagedNativeString(headerKey),
toManagedNativeString(headerValue)};
header_array[header_index++] = new_header;
}
}
// ASSERT(header_index == length);
envoy_headers ret = { length, header_array };
envoy_headers ret = {length, header_array};
return ret;
}

static NSData * to_ios_data(envoy_data data) {
static NSData *to_ios_data(envoy_data data) {
// TODO: investigate buffer ownership
// Possibly extend/subclass NSData to call envoy_data.release on dealloc and have release drain the underlying Envoy buffer instance
// Possibly extend/subclass NSData to call envoy_data.release on dealloc and have release drain
// the underlying Envoy buffer instance
return [NSData dataWithBytes:(void *)data.bytes length:data.length];
}

static EnvoyHeaders * to_ios_headers(envoy_headers headers) {
static EnvoyHeaders *to_ios_headers(envoy_headers headers) {
NSMutableDictionary *headerDict = [NSMutableDictionary new];
for (envoy_header_size_t i = 0; i < headers.length; i++) {
envoy_header header = headers.headers[i];
Expand All @@ -81,7 +78,7 @@ static envoy_headers toNativeHeaders(EnvoyHeaders *headers) {
}

#pragma mark - c callbacks
static void ios_on_headers(envoy_headers headers, bool end_stream, void* context) {
static void ios_on_headers(envoy_headers headers, bool end_stream, void *context) {
ios_context *c = (ios_context *)context;
EnvoyObserver *observer = c->observer;
dispatch_async(observer.dispatchQueue, ^{
Expand All @@ -92,7 +89,7 @@ static void ios_on_headers(envoy_headers headers, bool end_stream, void* context
});
}

static void ios_on_data(envoy_data data, bool end_stream, void* context) {
static void ios_on_data(envoy_data data, bool end_stream, void *context) {
ios_context *c = (ios_context *)context;
EnvoyObserver *observer = c->observer;
dispatch_async(observer.dispatchQueue, ^{
Expand All @@ -104,7 +101,7 @@ static void ios_on_data(envoy_data data, bool end_stream, void* context) {
});
}

static void ios_on_metadata(envoy_headers metadata, void* context) {
static void ios_on_metadata(envoy_headers metadata, void *context) {
ios_context *c = (ios_context *)context;
EnvoyObserver *observer = c->observer;
dispatch_async(observer.dispatchQueue, ^{
Expand Down Expand Up @@ -160,7 +157,6 @@ static void ios_on_error(envoy_error error, void *context) {
});
}


@implementation EnvoyHttpStream {
EnvoyHttpStream *_strongSelf;
EnvoyObserver *_platformObserver;
Expand All @@ -185,15 +181,8 @@ - (instancetype)initWithObserver:(EnvoyObserver *)observer {

// Create native observer
envoy_observer *native_obs = (envoy_observer *)malloc(sizeof(envoy_observer));
envoy_observer native_init = {
ios_on_headers,
ios_on_data,
ios_on_trailers,
ios_on_metadata,
ios_on_complete,
ios_on_error,
context
};
envoy_observer native_init = {ios_on_headers, ios_on_data, ios_on_trailers, ios_on_metadata,
ios_on_complete, ios_on_error, context};
memcpy(native_obs, &native_init, sizeof(envoy_observer));
_nativeObserver = native_obs;

Expand Down Expand Up @@ -222,7 +211,7 @@ - (void)sendHeaders:(EnvoyHeaders *)headers close:(BOOL)close {

- (void)sendData:(NSData *)data close:(BOOL)close {
// TODO: implement
//send_data(_nativeStream, toNativeData(data), close);
// send_data(_nativeStream, toNativeData(data), close);
}

- (void)sendMetadata:(EnvoyHeaders *)metadata {
Expand All @@ -235,7 +224,8 @@ - (void)sendTrailers:(EnvoyHeaders *)trailers {

- (EnvoyStatus)cancel {
ios_context *context = _nativeObserver->context;
// Step 1: atomically and synchronously prevent the execution of further callbacks other than on_cancel.
// Step 1: atomically and synchronously prevent the execution of further callbacks other than
// on_cancel.
if (!atomic_exchange(context->canceled, YES)) {
// Step 2: directly fire the cancel callback.
ios_on_cancel(context);
Expand Down
4 changes: 2 additions & 2 deletions library/swift/src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ swift_static_framework(
],
module_name = "Envoy",
objc_includes = [
"//library/objective-c:EnvoyEngine.h",
"//library/objective-c:EnvoyEngineImpl.h",
"//library/objective-c:EnvoyEngine.h",
"//library/objective-c:EnvoyEngineImpl.h",
],
visibility = ["//visibility:public"],
deps = ["//library/objective-c:envoy_engine_objc_lib"],
Expand Down

0 comments on commit e778006

Please sign in to comment.