Ignore:
Timestamp:
Sep 22, 2018 10:13:40 PM (2 years ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
7a72049
Parents:
829eb665
Message:

Mac OS X Launcher:

  • In general bugfixes
  • Introduced event manager for better control flow
  • Splitted RouterStatusView? to own file
  • Added shell script to setup and produce dmg file
File:
1 edited

Legend:

Unmodified
Added
Removed
  • launchers/macosx/RouterTask.mm

    r829eb665 r3b38f5a  
    3232  self.userRequestedRestart = NO;
    3333  self.isRouterRunning = NO;
    34   self.input = [NSFileHandle fileHandleWithStandardInput];
     34  //self.input = [NSFileHandle fileHandleWithStandardInput];
    3535  self.routerTask = [NSTask new];
    3636  self.processPipe = [NSPipe new];
     
    4545        [self.routerTask setStandardError:self.processPipe];
    4646
    47     NSFileHandle *stdoutFileHandle = [self.processPipe fileHandleForReading];
    48     [[NSNotificationCenter defaultCenter] addObserver:self
    49         selector:@selector(routerStdoutData:)
    50         name:NSFileHandleDataAvailableNotification
    51         object:stdoutFileHandle];
     47  /*
     48  NSFileHandle *stdoutFileHandle = [self.processPipe fileHandleForReading];
     49  dup2([[self.processPipe fileHandleForWriting] fileDescriptor], fileno(stdout));
     50  auto source = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, [stdoutFileHandle fileDescriptor], 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
     51  dispatch_source_set_event_handler(source, ^{
     52    void* data = malloc(4096);
     53    ssize_t readResult = 0;
     54    do
     55    {
     56      errno = 0;
     57      readResult = read([stdoutFileHandle fileDescriptor], data, 4096);
     58    } while (readResult == -1 && errno == EINTR);
     59    if (readResult > 0)
     60    {
     61      //AppKit UI should only be updated from the main thread
     62      dispatch_async(dispatch_get_main_queue(),^{
     63        NSString* stdOutString = [[NSString alloc] initWithBytesNoCopy:data length:readResult encoding:NSUTF8StringEncoding freeWhenDone:YES];
     64        NSAttributedString* stdOutAttributedString = [[NSAttributedString alloc] initWithString:stdOutString];
     65        NSLog(@"Router stdout: %@", stdOutString);
     66        //auto logForwarder = new LogForwarder();
     67        //[logForwarder appendLogViewWithLogLine:stdOutAttributedString];
     68      });
     69    }
     70    else{free(data);}
     71  });
     72  dispatch_resume(source);
     73  */
     74  /*
     75  [[NSNotificationCenter defaultCenter] addObserver:self
     76      selector:@selector(routerStdoutData:)
     77      name:NSFileHandleDataAvailableNotification
     78      object:stdoutFileHandle];
    5279
    5380  [stdoutFileHandle waitForDataInBackgroundAndNotify];
     81  */
    5482
    5583  [self.routerTask setTerminationHandler:^(NSTask* task) {
     
    5987    [swiftRouterStatus setRouterStatus: false];
    6088    [swiftRouterStatus setRouterRanByUs: false];
     89    [swiftRouterStatus triggerEventWithEn:@"router_stop" details:@"normal shutdown"];
     90    [[SBridge sharedInstance] setCurrentRouterInstance:nil];
    6191    sendUserNotification(APP_IDSTR, @"I2P Router has stopped");
    6292  }];
     
    83113{
    84114    @try {
     115      auto swiftRouterStatus = [[RouterProcessStatus alloc] init];
     116      [swiftRouterStatus triggerEventWithEn:@"router_start" details:@"normal start"];
    85117      [self.routerTask launch];
    86       watchPid([self.routerTask processIdentifier]);
    87118      self.isRouterRunning = YES;
    88119      return 1;
     
    92123                NSLog(@"Expection occurred %@", [e reason]);
    93124    auto swiftRouterStatus = [[RouterProcessStatus alloc] init];
     125    self.isRouterRunning = NO;
    94126    [swiftRouterStatus setRouterStatus: false];
    95127    [swiftRouterStatus setRouterRanByUs: false];
     128    [swiftRouterStatus triggerEventWithEn:@"router_stop" details:@"error shutdown"];
     129    [[SBridge sharedInstance] setCurrentRouterInstance:nil];
    96130    sendUserNotification(@"An error occured, can't start the I2P Router", [e reason]);
    97131    return 0;
Note: See TracChangeset for help on using the changeset viewer.