Browse Source

...

works_for_me
Volker Birk 2 years ago
parent
commit
40767c2238
6 changed files with 30 additions and 31 deletions
  1. +1
    -2
      pEpMacOSAdapter/main.m
  2. +2
    -1
      pEpMacOSAdapter/pEpMacOSAdapter.h
  3. +10
    -6
      pEpMacOSAdapter/pEpMacOSAdapter.m
  4. +5
    -5
      pEpMacOSAdapter/pEpMacOSAdapterProtocol.h
  5. +3
    -3
      pEpMacOSAdapter/pEpUpdater.h
  6. +9
    -14
      pEpMacOSAdapter/pEpUpdater.mm

+ 1
- 2
pEpMacOSAdapter/main.m View File

@ -34,7 +34,6 @@
// handle. The connection retains the exported object.
pEpMacOSAdapter *exportedObject = [pEpMacOSAdapter new];
newConnection.exportedObject = exportedObject;
exportedObject.connection = newConnection;
if (!newConnection.exportedInterface || !newConnection.exportedObject) {
NSLog(@"failed to allocate object and interface");
@ -71,5 +70,5 @@ int main(int argc, const char *argv[])
[listener resume];
[[NSRunLoop currentRunLoop] run];
return 0;
return EXIT_FAILURE;
}

+ 2
- 1
pEpMacOSAdapter/pEpMacOSAdapter.h View File

@ -13,6 +13,7 @@
/// This object implements the protocol which we have defined. It provides the actual behavior for the service. It is 'exported' by the service to make it available to the process hosting the service over an NSXPCConnection.
@interface pEpMacOSAdapter : NSObject <pEpMacOSAdapterProtocol>
@property (assign) NSXPCConnection* connection;
@property (retain) NSXPCListenerEndpoint* clientEndpoint;
@property (retain) NSXPCConnection* clientConnection;
@end

+ 10
- 6
pEpMacOSAdapter/pEpMacOSAdapter.m View File

@ -16,18 +16,24 @@ static pEpUpdater* _updater = nil;
// begin pEpMacOSAdapterProtocol
- (void)subscribeForUpdate
- (void)subscribeForUpdate:(NSXPCListenerEndpoint*)endpoint
{
NSLog(@"subscribeForUpdate called");
pEpNotification* downloadNotification = [_connection exportedObject];
_clientEndpoint = endpoint;
_clientConnection = [[NSXPCConnection alloc] initWithListenerEndpoint:_clientEndpoint];
_clientConnection.remoteObjectInterface = [NSXPCInterface
interfaceWithProtocol:@protocol(pEpNotificationProtocol)];
[_clientConnection resume];
pEpNotification* downloadNotification = [_clientConnection remoteObjectProxy];
if (downloadNotification) {
if (!_updater) {
_updater = [[pEpUpdater alloc] initWithSubscriber:downloadNotification];
[_updater scheduleUpdates];
}
else {
[_updater setNewSubscriber:downloadNotification];
_updater.subscriber = downloadNotification;
}
}
}
@ -35,14 +41,12 @@ static pEpUpdater* _updater = nil;
- (void)unsubscribeForUpdate
{
NSLog(@"unsubscribeForUpdate called");
[_updater setNewSubscriber :nil];
_updater.subscriber = nil;
}
- (void)updateNow
{
NSLog(@"updateNow called");
if (_updater) {
[_updater updateAll:nil];
}


+ 5
- 5
pEpMacOSAdapter/pEpMacOSAdapterProtocol.h View File

@ -9,14 +9,14 @@
#import <Foundation/Foundation.h>
/// Notification types
typedef enum { ready = 0, downloading, downloadArrived, noDownloadAvailable } DNType;
/// Callback protocol to notify about download events
@protocol pEpNotificationProtocol
/// Notification types
typedef enum { downloading, downloadArrived, noDownloadAvailable } DNType;
/// notification about download events
- (void)notifyDownload:(DNType)type withName:(NSString*)name withFilename:(NSString*)filename;
- (void)notifyDownload:(int)type withName:(NSString*)name withFilename:(NSString*)filename;
@end
@ -33,7 +33,7 @@ typedef enum { downloading, downloadArrived, noDownloadAvailable } DNType;
- Parameter downloading: block to call back when a download is going to happen
- Parameter downloadArrived: block to call back when a download arrived
*/
- (void)subscribeForUpdate;
- (void)subscribeForUpdate:(NSXPCListenerEndpoint*)endpoint;
/// unsubscribe from receiving notifications about downloads arriving
- (void)unsubscribeForUpdate;


+ 3
- 3
pEpMacOSAdapter/pEpUpdater.h View File

@ -19,14 +19,14 @@
/// path with config files
@property (retain) NSString* configPath;
/// subscriber for notifications
@property (strong) pEpNotification* subscriber;
/// initializes the pEpUpdater
///
/// - parameter subscriber: object fulfilling the `pEpMacOSAdapterSubscriberProtocol`.
- (id)initWithSubscriber:(pEpNotification*)subscriber;
/// switches the subscriber
- (void)setNewSubscriber:(pEpNotification*)subscriber;
/// schedules updates each 2 hours
- (void)scheduleUpdates;


+ 9
- 14
pEpMacOSAdapter/pEpUpdater.mm View File

@ -15,21 +15,15 @@ static const double CYCLE = 7200.0; // 7200 seconds = 2 hours
@implementation pEpUpdater
pEpNotification* _subscriber = nil;
- (id)initWithSubscriber:(pEpNotification*)subscriber
{
self = [super init];
self.configPath = @"/Library/Application Support/pEp/Updater";
_subscriber = subscriber;
self.subscriber = subscriber;
[_subscriber notifyDownload:ready withName:@"" withFilename:@""];
return self;
}
- (void)setNewSubscriber:(pEpNotification*)subscriber
{
_subscriber = subscriber;
}
- (void)scheduleUpdates
{
NSLog(@"schedule updates");
@ -101,9 +95,10 @@ pEpNotification* _subscriber = nil;
std::string _filename;
pEp::notifyRead_t notifyRead = [=]()->void{
if (_subscriber) {
[_subscriber notifyDownload:downloading withName:name withFilename:nil];
}
NSLog(@"downloading: %@", name);
// if (_subscriber) {
// [_subscriber notifyDownload:(int)downloading withName:name withFilename:@""];
// }
};
try {
@ -115,14 +110,14 @@ pEpNotification* _subscriber = nil;
[localFileManager changeCurrentDirectoryPath:cwd];
NSLog(@"download arrived %@", download);
if (_subscriber) {
[_subscriber notifyDownload:downloadArrived withName:name withFilename:download];
[_subscriber notifyDownload:(int)downloadArrived withName:name withFilename:download];
}
}
else {
NSLog(@"no download available for %@", name);
if (_subscriber) {
[_subscriber notifyDownload:noDownloadAvailable withName:name withFilename:nil];
[_subscriber notifyDownload:(int)noDownloadAvailable withName:name withFilename:@""];
}
}
}


Loading…
Cancel
Save