Browse Source

APPLEMAIL-33 Add new pep objc adapter interface. Disable pep updates xpc interface.

APPLEMAIL-33
David Alarcon 2 years ago
parent
commit
b2453148ab
8 changed files with 279 additions and 8 deletions
  1. +36
    -0
      pEpMacOSAdapter.xcodeproj/project.pbxproj
  2. +25
    -0
      pEpMacOSAdapter/ObjCAdapterXpcApi/Launchd-plist/foundation.pEp.adapter.macOS.plist
  3. +25
    -0
      pEpMacOSAdapter/ObjCAdapterXpcApi/PEPObjCAdapterXpcApi.h
  4. +92
    -0
      pEpMacOSAdapter/ObjCAdapterXpcApi/PEPObjCAdapterXpcApi.m
  5. +24
    -0
      pEpMacOSAdapter/ObjCAdapterXpcApi/PEPObjCAdapterXpcApiProtocol.h
  6. +22
    -0
      pEpMacOSAdapter/ObjCAdapterXpcApi/PEPObjCAdapterXpcApiResult.h
  7. +42
    -0
      pEpMacOSAdapter/ObjCAdapterXpcApi/PEPObjCAdapterXpcApiResult.m
  8. +13
    -8
      pEpMacOSAdapter/main.m

+ 36
- 0
pEpMacOSAdapter.xcodeproj/project.pbxproj View File

@ -12,6 +12,9 @@
35380AEA247C784E004A08A6 /* pEpUpdater.mm in Sources */ = {isa = PBXBuildFile; fileRef = 35380AE9247C784E004A08A6 /* pEpUpdater.mm */; };
35DC18D8244DA19100FB2002 /* pEpMacOSAdapter.m in Sources */ = {isa = PBXBuildFile; fileRef = 35DC18D7244DA19100FB2002 /* pEpMacOSAdapter.m */; };
35DC18DA244DA19100FB2002 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 35DC18D9244DA19100FB2002 /* main.m */; };
4E49289E25B200BD00A3A47C /* PEPObjCAdapterXpcApi.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E49289D25B200BD00A3A47C /* PEPObjCAdapterXpcApi.m */; };
4E67789725B71680003591E6 /* PEPObjCAdapterXpcApiResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E67789625B71680003591E6 /* PEPObjCAdapterXpcApiResult.m */; };
4E90353025B58FC400F3471A /* foundation.pEp.adapter.macOS.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4E90352F25B58FC400F3471A /* foundation.pEp.adapter.macOS.plist */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -30,6 +33,12 @@
35DC18D7244DA19100FB2002 /* pEpMacOSAdapter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = pEpMacOSAdapter.m; sourceTree = "<group>"; };
35DC18D9244DA19100FB2002 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
35DC18DB244DA19100FB2002 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4E49289C25B200BD00A3A47C /* PEPObjCAdapterXpcApi.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPObjCAdapterXpcApi.h; sourceTree = "<group>"; };
4E49289D25B200BD00A3A47C /* PEPObjCAdapterXpcApi.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPObjCAdapterXpcApi.m; sourceTree = "<group>"; };
4E67789425B71680003591E6 /* PEPObjCAdapterXpcApiProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPObjCAdapterXpcApiProtocol.h; sourceTree = "<group>"; };
4E67789525B71680003591E6 /* PEPObjCAdapterXpcApiResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPObjCAdapterXpcApiResult.h; sourceTree = "<group>"; };
4E67789625B71680003591E6 /* PEPObjCAdapterXpcApiResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPObjCAdapterXpcApiResult.m; sourceTree = "<group>"; };
4E90352F25B58FC400F3471A /* foundation.pEp.adapter.macOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = foundation.pEp.adapter.macOS.plist; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -64,6 +73,7 @@
35DC18D4244DA19100FB2002 /* pEpMacOSAdapter */ = {
isa = PBXGroup;
children = (
4E49289625B1DCB600A3A47C /* ObjCAdapterXpcApi */,
35380AE6247BD13A004A08A6 /* README.md */,
35DC18D5244DA19100FB2002 /* PEPMacOSAdapterProtocol.h */,
35DC18D6244DA19100FB2002 /* pEpMacOSAdapter.h */,
@ -89,6 +99,27 @@
name = Frameworks;
sourceTree = "<group>";
};
4E49289625B1DCB600A3A47C /* ObjCAdapterXpcApi */ = {
isa = PBXGroup;
children = (
4E6778AC25B71DDA003591E6 /* Launchd-plist */,
4E67789425B71680003591E6 /* PEPObjCAdapterXpcApiProtocol.h */,
4E67789525B71680003591E6 /* PEPObjCAdapterXpcApiResult.h */,
4E67789625B71680003591E6 /* PEPObjCAdapterXpcApiResult.m */,
4E49289C25B200BD00A3A47C /* PEPObjCAdapterXpcApi.h */,
4E49289D25B200BD00A3A47C /* PEPObjCAdapterXpcApi.m */,
);
path = ObjCAdapterXpcApi;
sourceTree = "<group>";
};
4E6778AC25B71DDA003591E6 /* Launchd-plist */ = {
isa = PBXGroup;
children = (
4E90352F25B58FC400F3471A /* foundation.pEp.adapter.macOS.plist */,
);
path = "Launchd-plist";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -147,6 +178,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4E90353025B58FC400F3471A /* foundation.pEp.adapter.macOS.plist in Resources */,
35380AE7247BD13A004A08A6 /* README.md in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -181,6 +213,8 @@
files = (
35380AEA247C784E004A08A6 /* pEpUpdater.mm in Sources */,
35DC18DA244DA19100FB2002 /* main.m in Sources */,
4E49289E25B200BD00A3A47C /* PEPObjCAdapterXpcApi.m in Sources */,
4E67789725B71680003591E6 /* PEPObjCAdapterXpcApiResult.m in Sources */,
35DC18D8244DA19100FB2002 /* pEpMacOSAdapter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -317,6 +351,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO;
CODE_SIGN_ENTITLEMENTS = foundation.pEp.adapter.macOS.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
@ -341,6 +376,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO;
CODE_SIGN_ENTITLEMENTS = foundation.pEp.adapter.macOS.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;


+ 25
- 0
pEpMacOSAdapter/ObjCAdapterXpcApi/Launchd-plist/foundation.pEp.adapter.macOS.plist View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>foundation.pEp.adapter.macOS</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Application Support/pEp/pEp.app/Contents/MacOS/foundation.pEp.adapter.macOS</string>
</array>
<key>MachServices</key>
<dict>
<key>foundation.pEp.adapter.pEpObjCXPC_OpenStep</key>
<true/>
</dict>
<key>StandardOutPath</key>
<string>/tmp/foundation.pEp.adapter.macOS.log</string>
<key>StandardErrorPath</key>
<string>/tmp/foundation.pEp.adapter.macOS.log</string>
<key>LimitLoadToSessionType</key>
<string>Aqua</string>
<key>KeepAlive</key>
<true/>
</dict>
</plist>

+ 25
- 0
pEpMacOSAdapter/ObjCAdapterXpcApi/PEPObjCAdapterXpcApi.h View File

@ -0,0 +1,25 @@
//
// PEPObjCAdapterXpcApi.h
// foundation.pEp.adapter.macOS
//
// Created by David Alarcon on 15/1/21.
// Copyright © 2021 pp foundation. All rights reserved.
//
@import Foundation;
#import "PEPObjCAdapterXpcApiProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface PEPObjCAdapterXpcApi : NSObject <NSXPCListenerDelegate, PEPObjCAdapterXpcApiProtocol>
- (id) init;
// Begin listening for incoming XPC connections
- (void) start;
// Stop listening for incoming XPC connections
- (void) stop;
@end
NS_ASSUME_NONNULL_END

+ 92
- 0
pEpMacOSAdapter/ObjCAdapterXpcApi/PEPObjCAdapterXpcApi.m View File

@ -0,0 +1,92 @@
//
// PEPObjCAdapterXpcApi.m
// foundation.pEp.adapter.macOS
//
// Created by David Alarcon on 15/1/21.
// Copyright © 2021 pp foundation. All rights reserved.
//
#import "PEPObjCAdapterXpcApi.h"
#import "PEPObjCAdapterXpcApiResult.h"
@interface PEPObjCAdapterXpcApi ()
@property (nonatomic, strong, readwrite) NSXPCListener *listener;
@property (nonatomic, readwrite) BOOL started;
@end
@implementation PEPObjCAdapterXpcApi
- (id)init {
// Launch daemons must configure their listener with the machServiceName initializer
self.listener = [[NSXPCListener alloc] initWithMachServiceName:daemonLabel];
self.listener.delegate = self;
NSLog(@"initializing ObjC Xpc Api: %@", self.listener);
self.started = NO;
return self;
}
- (void)start {
assert(self.started == NO);
// Begin listening for incoming XPC connections
[self.listener resume];
NSLog(@"starting ObjC Xpc Api: %@", daemonLabel);
self.started = YES;
}
- (void)stop {
assert(self.started == YES);
// Stop listening for incoming XPC connections
[self.listener suspend];
self.started = NO;
}
#pragma mark - PEPObjCAdapterXpcApiProtocol
//- (void)myself:(NSString *)identity resultBlock:(void (^)(PEPObjCAdapterXpcApiResult * _Nonnull))resultCallback {
// PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc] initWithResult:@[@"MySelf"] andError:nil];
//
// resultCallback(result);
//}
- (void)myself:(NSString *)myself withReply:(void (^)(NSString * _Nonnull))replyBlock {
replyBlock(@"myself");
}
#pragma mark - NSXPCListenerDelegate
- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
// Sanity checks
NSLog(@"Accepting connection from: %@", newConnection);
assert(listener == self.listener);
assert(newConnection != nil);
NSLog(@"Accepting connection after asserts from: %@", newConnection);
// Configure the incoming connection
NSXPCInterface *adapterInterface = [NSXPCInterface interfaceWithProtocol:@protocol(PEPObjCAdapterXpcApiProtocol)];
/*[adapterInterface setClasses:[NSSet setWithObject:[PEPObjCAdapterXpcApiResult class]]
forSelector:@selector(myself:resultBlock:)
argumentIndex:0
ofReply:YES];*/
/*[adapterInterface setClasses:[NSSet setWithObject:[NSString class]]
forSelector:@selector(myself:resultBlock:)
argumentIndex:0
ofReply:NO];*/
newConnection.exportedInterface = adapterInterface;
newConnection.exportedObject = self;
// New connections always start in a suspended state
[newConnection resume];
return YES;
}
@end

+ 24
- 0
pEpMacOSAdapter/ObjCAdapterXpcApi/PEPObjCAdapterXpcApiProtocol.h View File

@ -0,0 +1,24 @@
//
// PEPObjCAdapterXpcApi.h
// foundation.pEp.adapter.macOS
//
// Created by David Alarcon on 15/1/21.
// Copyright © 2021 pp foundation. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
//static NSString *daemonLabel = @"foundation.pEp.adapter.PEPObjCAdapterXpcApi_OpenStep";
static NSString *daemonLabel = @"pEp.foundation.pEpXPCAdapter_OpenStep";
@class PEPObjCAdapterXpcApiResult;
@protocol PEPObjCAdapterXpcApiProtocol
//- (void)myself:(NSString *)identity resultBlock:(void (^)(PEPObjCAdapterXpcApiResult *))resultCallback;
- (void)myself:(NSString *)myself withReply:(void (^)(NSString *))replyBlock;
@end
NS_ASSUME_NONNULL_END

+ 22
- 0
pEpMacOSAdapter/ObjCAdapterXpcApi/PEPObjCAdapterXpcApiResult.h View File

@ -0,0 +1,22 @@
//
// PEPObjCAdapterXpcApiResult.h
// foundation.pEp.adapter.macOS
//
// Created by David Alarcon on 15/1/21.
// Copyright © 2021 pp foundation. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface PEPObjCAdapterXpcApiResult : NSObject <NSSecureCoding>
@property (readonly, nonatomic, strong) NSError *error;
@property (readonly, nonatomic, copy) NSArray* result;
- (instancetype)initWithResult:(NSArray* __nullable)result andError:(NSError * __nullable)error;
@end
NS_ASSUME_NONNULL_END

+ 42
- 0
pEpMacOSAdapter/ObjCAdapterXpcApi/PEPObjCAdapterXpcApiResult.m View File

@ -0,0 +1,42 @@
//
// PEPObjCAdapterXpcApiResult.m
// foundation.pEp.adapter.macOS
//
// Created by David Alarcon on 15/1/21.
// Copyright © 2021 pp foundation. All rights reserved.
//
#import "PEPObjCAdapterXpcApiResult.h"
@implementation PEPObjCAdapterXpcApiResult
- (instancetype)initWithResult:(NSArray *)result andError:(NSError *)error {
if (self = [self init]) {
_result = result;
_error = error;
}
return self;
}
- (void)encodeWithCoder:(nonnull NSCoder *)coder {
[coder encodeObject:self.result forKey:@"result"];
[coder encodeObject:self.error forKey:@"error"];
}
- (nullable instancetype)initWithCoder:(nonnull NSCoder *)coder {
if (self = [self init]) {
NSArray<Class> *classes = @[[NSArray class], [NSObject class]];
_result = [coder decodeObjectOfClasses:[NSSet setWithArray:classes] forKey:@"result"];
_error = [coder decodeObjectOfClass:[NSError class] forKey:@"error"];
}
return self;
}
+ (BOOL)supportsSecureCoding {
return YES;
}
@end

+ 13
- 8
pEpMacOSAdapter/main.m View File

@ -12,6 +12,7 @@
#import <AppKit/NSWorkspace.h>
#import "pEpMacOSAdapter.h"
#import "pEpUpdater.h"
#import "PEPObjCAdapterXpcApi.h"
pEpUpdater* updater = nil;
@ -71,20 +72,24 @@ void signal_TERM(int signal)
int main(int argc, const char *argv[])
{
signal(SIGTERM, signal_TERM);
updater = [pEpUpdater new];
//updater = [pEpUpdater new];
// Create an instance of the Objc Xpc Api daemon and start it
PEPObjCAdapterXpcApi *adapter = [[PEPObjCAdapterXpcApi alloc] init];
[adapter start];
// Create the delegate for the service.
ServiceDelegate *delegate = [ServiceDelegate new];
//ServiceDelegate *delegate = [ServiceDelegate new];
// Set up the one NSXPCListener for this service. It will handle all incoming connections.
NSXPCListener *listener = [[NSXPCListener alloc] initWithMachServiceName:@"foundation.pEp.adapter.macOS_OpenStep"];
NSLog(@"starting agent");
listener.delegate = delegate;
[listener resume];
// NSXPCListener *listener = [[NSXPCListener alloc] initWithMachServiceName:@"q.macOS_OpenStep"];
// NSLog(@"starting agent");
// listener.delegate = delegate;
// [listener resume];
// start the GUI helper app
BOOL opened = start_helper();
assert(opened);
// BOOL opened = start_helper();
// assert(opened);
NSLog(@"going into main runLoop");
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];


Loading…
Cancel
Save