Skip to content

Commit

Permalink
Merge pull request yagiz#27 from abarisain/carrier_delegate
Browse files Browse the repository at this point in the history
Add support for a BagelCarrier delegate
  • Loading branch information
yagiz authored Feb 27, 2019
2 parents d350aca + b52c216 commit 5a8283b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions iOS/Bagel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
3760A47321F1383F004D1E07 /* BagelURLConnectionInjector.m in Sources */ = {isa = PBXBuildFile; fileRef = 3760A45921F1383F004D1E07 /* BagelURLConnectionInjector.m */; };
3760A47421F1383F004D1E07 /* BagelBaseModel.h in Headers */ = {isa = PBXBuildFile; fileRef = 3760A45A21F1383F004D1E07 /* BagelBaseModel.h */; settings = {ATTRIBUTES = (Public, ); }; };
3760A47B21F13A47004D1E07 /* CocoaAsyncSocket.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3760A47A21F13A47004D1E07 /* CocoaAsyncSocket.framework */; };
51102CE2220B87290067EB63 /* BagelCarrierDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 51102CE1220B857E0067EB63 /* BagelCarrierDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -66,6 +67,7 @@
3760A45A21F1383F004D1E07 /* BagelBaseModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BagelBaseModel.h; sourceTree = "<group>"; };
3760A47521F13872004D1E07 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; };
3760A47A21F13A47004D1E07 /* CocoaAsyncSocket.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CocoaAsyncSocket.framework; path = Carthage/Build/iOS/CocoaAsyncSocket.framework; sourceTree = SOURCE_ROOT; };
51102CE1220B857E0067EB63 /* BagelCarrierDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BagelCarrierDelegate.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -107,6 +109,7 @@
3760A44A21F1383F004D1E07 /* BagelBaseModel.m */,
3760A45821F1383F004D1E07 /* BagelBrowser.h */,
3760A44C21F1383F004D1E07 /* BagelBrowser.m */,
51102CE1220B857E0067EB63 /* BagelCarrierDelegate.h */,
3760A44621F1383F004D1E07 /* BagelConfiguration.h */,
3760A45621F1383F004D1E07 /* BagelConfiguration.m */,
3760A44321F1383F004D1E07 /* BagelController.h */,
Expand Down Expand Up @@ -147,6 +150,7 @@
buildActionMask = 2147483647;
files = (
3760A46F21F1383F004D1E07 /* Bagel.h in Headers */,
51102CE2220B87290067EB63 /* BagelCarrierDelegate.h in Headers */,
3760A45D21F1383F004D1E07 /* BagelController.h in Headers */,
3760A47221F1383F004D1E07 /* BagelBrowser.h in Headers */,
3760A46021F1383F004D1E07 /* BagelConfiguration.h in Headers */,
Expand Down
36 changes: 36 additions & 0 deletions iOS/Source/BagelCarrierDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Copyright (c) 2018 Bagel (https://github.com/yagiz/Bagel)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import "BagelRequestPacket.h"

@protocol BagelCarrierDelegate <NSObject>

@optional

/**
Called right before Bagel sends a request packet to the Mac app.
Allows your delegate to modify the packet on the fly, or abort the operation.
Return a modified request packet, or nil if you want to filter it out.
*/
- (nullable BagelRequestPacket*)bagelCarrierWillSendRequest:(nonnull BagelRequestPacket*)request;

@end
3 changes: 3 additions & 0 deletions iOS/Source/BagelConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// THE SOFTWARE.

#import <Foundation/Foundation.h>
#import "BagelCarrierDelegate.h"
#import "BagelProjectModel.h"
#import "BagelDeviceModel.h"
#import "BagelUtility.h"
Expand All @@ -29,6 +30,8 @@
@property (nonatomic, strong) BagelProjectModel* project;
@property (nonatomic, strong) BagelDeviceModel* device;

@property (nonatomic, weak) id<BagelCarrierDelegate> carrierDelegate;

@property (nonatomic) uint16_t netservicePort;
@property (nonatomic, strong) NSString* netserviceType;
@property (nonatomic, strong) NSString* netserviceDomain;
Expand Down
9 changes: 9 additions & 0 deletions iOS/Source/BagelController.m
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ - (void)sendCarrier:(BagelRequestCarrier*)carrier
packet.project = self.configuration.project;
packet.device = self.configuration.device;

id<BagelCarrierDelegate> carrierDelegate = self.configuration.carrierDelegate;
if ([carrierDelegate respondsToSelector:@selector(bagelCarrierWillSendRequest:)]) {
packet = [carrierDelegate bagelCarrierWillSendRequest:packet];

if (packet == nil) {
return;
}
}

[self.browser sendPacket:packet];
}

Expand Down

0 comments on commit 5a8283b

Please sign in to comment.