Browse Source

notification

works_for_me
Volker Birk 2 years ago
parent
commit
d00d76ba7c
6 changed files with 62 additions and 40 deletions
  1. +4
    -2
      pEpMacOSAdapter.xcodeproj/project.pbxproj
  2. +11
    -0
      pEpMacOSAdapter/Subscriber.h
  3. +3
    -16
      pEpMacOSAdapter/main.m
  4. +15
    -5
      pEpMacOSAdapter/pEpMacOSAdapter.m
  5. +8
    -10
      pEpMacOSAdapter/pEpUpdater.h
  6. +21
    -7
      pEpMacOSAdapter/pEpUpdater.mm

+ 4
- 2
pEpMacOSAdapter.xcodeproj/project.pbxproj View File

@ -80,6 +80,7 @@
35380AE8247C784E004A08A6 /* pEpUpdater.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = pEpUpdater.h; sourceTree = "<group>"; };
35380AE9247C784E004A08A6 /* pEpUpdater.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = pEpUpdater.mm; sourceTree = "<group>"; };
35942FBB2482A12A00DCBD65 /* test.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = test.plist; sourceTree = "<group>"; };
35942FBE2482CAFF00DCBD65 /* Subscriber.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Subscriber.h; sourceTree = "<group>"; };
35DC18D2244DA19100FB2002 /* pEpMacOSAdapter.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; path = pEpMacOSAdapter.xpc; sourceTree = BUILT_PRODUCTS_DIR; };
35DC18D5244DA19100FB2002 /* pEpMacOSAdapterProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = pEpMacOSAdapterProtocol.h; sourceTree = "<group>"; };
35DC18D6244DA19100FB2002 /* pEpMacOSAdapter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = pEpMacOSAdapter.h; sourceTree = "<group>"; };
@ -173,10 +174,11 @@
3527B2EC24806A18007A6276 /* pEpMacOSAdapterSubscriberProtocol.h */,
35DC18D6244DA19100FB2002 /* pEpMacOSAdapter.h */,
35DC18D7244DA19100FB2002 /* pEpMacOSAdapter.m */,
35DC18D9244DA19100FB2002 /* main.m */,
35DC18DB244DA19100FB2002 /* Info.plist */,
35380AE8247C784E004A08A6 /* pEpUpdater.h */,
35380AE9247C784E004A08A6 /* pEpUpdater.mm */,
35942FBE2482CAFF00DCBD65 /* Subscriber.h */,
35DC18D9244DA19100FB2002 /* main.m */,
35DC18DB244DA19100FB2002 /* Info.plist */,
);
path = pEpMacOSAdapter;
sourceTree = "<group>";


+ 11
- 0
pEpMacOSAdapter/Subscriber.h View File

@ -0,0 +1,11 @@
//
// Subscriber.h
// pEpMacOSAdapter
//
// Created by Volker Birk on 30.05.20.
// Copyright © 2020 pp foundation. All rights reserved.
// This file is under GNU General Public License 3.0
//
@interface Subscriber : NSObject<pEpMacOSAdapterSubscriberProtocol>
@end

+ 3
- 16
pEpMacOSAdapter/main.m View File

@ -9,18 +9,14 @@
#import <Foundation/Foundation.h>
#import "pEpMacOSAdapter.h"
#import "pEpUpdater.h"
@interface ServiceDelegate : NSObject <NSXPCListenerDelegate, pEpMacOSAdapterSubscriberProtocol>
@interface ServiceDelegate : NSObject <NSXPCListenerDelegate>
@end
@implementation ServiceDelegate
NSMutableArray* _subscribers;
- (id)init{
self = [super init];
_subscribers = [NSMutableArray new];
return self;
}
@ -34,7 +30,7 @@ NSMutableArray* _subscribers;
// Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object.
pEpMacOSAdapter *exportedObject = [pEpMacOSAdapter new];
newConnection.exportedObject = exportedObject;
// Resuming the connection allows the system to deliver more incoming messages.
[newConnection resume];
@ -42,11 +38,6 @@ NSMutableArray* _subscribers;
return YES;
}
- (void)notifyDownloadArrived:(NSString *)download
{
}
@end
int main(int argc, const char *argv[])
@ -57,11 +48,7 @@ int main(int argc, const char *argv[])
// Set up the one NSXPCListener for this service. It will handle all incoming connections.
NSXPCListener *listener = [NSXPCListener serviceListener];
listener.delegate = delegate;
// start pEpUpdater
pEpUpdater* updater = [pEpUpdater new];
[updater scheduleUpdates];
// Resuming the serviceListener starts this service. This method does not return.
[listener resume];
return 0;


+ 15
- 5
pEpMacOSAdapter/pEpMacOSAdapter.m View File

@ -8,23 +8,33 @@
//
#import "pEpMacOSAdapter.h"
#import "pEpUpdater.h"
static pEpUpdater* _updater = nil;
@implementation pEpMacOSAdapter
void (^_subscriber)(NSString *) = nil;
void (^_notificationTarget)(NSString *) = nil;
// begin pEpMacOSAdapterProtocol
- (void)subscribeForUpdate:(void (^)(NSString *))downloadArrived
{
if (downloadArrived) {
_subscriber = downloadArrived;
if (!_updater) {
_updater = [[pEpUpdater alloc] initWithSubscriber:(Subscriber*)self];
[_updater scheduleUpdates];
}
else {
[_updater setNewSubscriber:(Subscriber*)self];
}
_notificationTarget = downloadArrived;
}
}
- (void)unsubscribeForUpdate
{
_subscriber = nil;
_notificationTarget = nil;
}
// end pEpMacOSAdapterProtocol
@ -33,8 +43,8 @@ void (^_subscriber)(NSString *) = nil;
- (void)notifyDownloadArrived:(nonnull NSString *)download
{
if (_subscriber) {
_subscriber(download);
if (_notificationTarget) {
_notificationTarget(download);
}
}


+ 8
- 10
pEpMacOSAdapter/pEpUpdater.h View File

@ -8,21 +8,19 @@
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
#import "pEpMacOSAdapterSubscriberProtocol.h"
#import "Subscriber.h"
@interface pEpUpdater : NSObject
@property double cycle;
@property NSString* configPath;
@property NSUserNotificationCenter* nc;
-(id)init;
-(void)scheduleUpdates;
-(void)updateAll:(NSTimer*)timer;
-(void)updateWithFile:(nonnull NSString*)configFile;
-(void)update:(nonnull NSString*)name usingUrl:(nonnull NSString*)url;
- (id)initWithSubscriber:(Subscriber*)subscriber;
- (void)setNewSubscriber:(Subscriber*)subscriber;
- (void)scheduleUpdates;
- (void)updateAll:(NSTimer*)timer;
- (void)updateWithFile:(NSString*)configFile;
- (void)update:(NSString*)name usingUrl:(NSString*)url;
@end
NS_ASSUME_NONNULL_END

+ 21
- 7
pEpMacOSAdapter/pEpUpdater.mm View File

@ -8,26 +8,36 @@
//
#import "pEpUpdater.h"
#import "Subscriber.h"
#include "../../downloadclient/downloadclient.hh"
static const double CYCLE = 7200.0; // 7200 seconds = 2 hours
@implementation pEpUpdater
static const double CYCLE = 7200.0; // 7200 seconds = 2 hours
__weak Subscriber* _subscriber = nil;
-(id)init
- (id)initWithSubscriber:(Subscriber*)subscriber
{
self = [super init];
self.cycle = CYCLE;
self.configPath = @"/Library/Application Support/pEp/Updater";
_subscriber = subscriber;
return self;
}
-(void)scheduleUpdates
- (void)setNewSubscriber:(Subscriber*)subscriber
{
_subscriber = subscriber;
}
- (void)scheduleUpdates
{
[NSTimer scheduledTimerWithTimeInterval:self.cycle target:self selector:@selector(updateAll:) userInfo:nil repeats:YES];
}
-(void)updateAll:(NSTimer*)timer
- (void)updateAll:(NSTimer*)timer
{
// update all registered products
@ -42,7 +52,7 @@ static const double CYCLE = 7200.0; // 7200 seconds = 2 hours
}
}
-(void)updateWithFile:(nonnull NSString*)configFile
- (void)updateWithFile:(NSString*)configFile
{
NSInputStream *is = [NSInputStream inputStreamWithFileAtPath:configFile];
NSError* err = nil;
@ -59,7 +69,7 @@ static const double CYCLE = 7200.0; // 7200 seconds = 2 hours
}
}
-(void)update:(nonnull NSString*)name usingUrl:(nonnull NSString*)url
- (void)update:(NSString*)name usingUrl:(NSString*)url
{
pEp::UpdateClient::product p = { name.UTF8String, url.UTF8String };
@ -79,7 +89,11 @@ static const double CYCLE = 7200.0; // 7200 seconds = 2 hours
NSString* download = [NSString stringWithFormat:@"%@/%@", tmp, filename];
[localFileManager changeCurrentDirectoryPath:cwd];
NSLog(@"pEpMacOSAdapter: download %@", download);
NSLog(@"pEpMacOSAdapter: download arrived %@", download);
if (_subscriber) {
[_subscriber notifyDownloadArrived:download];
}
}
catch (std::exception& e) {
NSLog(@"pEpMacOSAdapter: %s", e.what());


Loading…
Cancel
Save