Ignore:
Timestamp:
Sep 20, 2018 3:20:39 AM (20 months ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
85ebb2f
Parents:
3c0a8cf
Message:

Mac OS X Launcher: more cleanup and some bugfixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • launchers/macosx/RouterTask.mm

    r3c0a8cf re8decff5  
    1010#include "AppDelegate.h"
    1111#endif
     12
    1213#include "include/PidWatcher.h"
    1314
     
    5354
    5455  [self.routerTask setTerminationHandler:^(NSTask* task) {
     56    // Cleanup
    5557    NSLog(@"termHandler triggered!");
    5658    auto swiftRouterStatus = [[RouterProcessStatus alloc] init];
    57     [swiftRouterStatus setRouterStatus: true];
     59    [swiftRouterStatus setRouterStatus: false];
     60    [swiftRouterStatus setRouterRanByUs: false];
    5861    sendUserNotification(APP_IDSTR, @"I2P Router has stopped");
    59     // Cleanup
    60     //self.isRouterRunning = NO;
    6162  }];
    62 /*
    63     self.readLogHandle = [self.processPipe fileHandleForReading];
    64     NSData *inData = nil;
    65     self.totalLogData = [[[NSMutableData alloc] init] autorelease];
    66 
    67     while ((inData = [self.readLogHandle availableData]) &&
    68         [inData length]) {
    69         [self.totalLogData appendData:inData];
    70     }
    71 */
    7263    return self;
    7364}
     
    9283{
    9384    @try {
    94         [self.routerTask launch];
    95         watchPid([self.routerTask processIdentifier]);
    96         self.isRouterRunning = YES;
    97         return 1;
     85      [self.routerTask launch];
     86      watchPid([self.routerTask processIdentifier]);
     87      self.isRouterRunning = YES;
     88      return 1;
    9889    }
    9990    @catch (NSException *e)
    10091        {
    10192                NSLog(@"Expection occurred %@", [e reason]);
    102         return 0;
     93    auto swiftRouterStatus = [[RouterProcessStatus alloc] init];
     94    [swiftRouterStatus setRouterStatus: false];
     95    [swiftRouterStatus setRouterRanByUs: false];
     96    sendUserNotification(@"An error occured, can't start the I2P Router", [e reason]);
     97    return 0;
    10398        }
    10499}
     
    106101- (int) getPID
    107102{
    108     return [self.routerTask processIdentifier];
     103  return [self.routerTask processIdentifier];
    109104}
    110105
    111106@end
    112 
    113 #ifdef __cplusplus
    114 
    115 JavaRunner::JavaRunner(std::string& javaBin, std::string& arguments, std::string& i2pBaseDir, const fp_proc_t& execFn, const fp_t& cb)
    116   : javaBinaryPath(javaBin), javaRouterArgs(arguments), _i2pBaseDir(i2pBaseDir), executingFn(execFn), exitCallbackFn(cb)
    117 {
    118   execLine = javaBinaryPath;
    119   execLine += " " + std::string(javaRouterArgs.c_str());
    120   printf("CLI: %s\n",execLine.c_str());
    121   javaProcess = std::shared_ptr<Popen>(new Popen(execLine, environment{{
    122             {"I2PBASE", _i2pBaseDir},
    123             {"JAVA_OPTS", getenv("JAVA_OPTS")}
    124         }}, defer_spawn{true}));
    125 }
    126 
    127 void JavaRunner::requestRouterShutdown()
    128 {
    129     // SIGHUP
    130     javaProcess->kill(1);
    131 }
    132 
    133 std::future<int> JavaRunner::execute()
    134 {
    135   try {
    136     auto executingFn = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{
    137       this->executingFn(this);
    138     });
    139     dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), executingFn);
    140     dispatch_block_wait(executingFn, DISPATCH_TIME_FOREVER);
    141 
    142     // Here, the process is done executing.
    143 
    144     printf("Finished executingFn - Runs callbackFn\n");
    145     this->exitCallbackFn();
    146     return std::async(std::launch::async, []{ return 0; });
    147   } catch (std::exception* ex) {
    148     printf("ERROR: %s\n", ex->what());
    149     return std::async(std::launch::async, []{ return 1; });
    150   }
    151 }
    152 
    153 #endif
Note: See TracChangeset for help on using the changeset viewer.