Ignore:
Timestamp:
Sep 30, 2018 9:40:43 AM (2 years ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
b5497ef
Parents:
36b758f
Message:

Mac OSX Launcher:

  • Update readme about event manager
  • RouterTask? can now detect a running router by scanning processes&arguments for i2p.jar
  • The logger will log to OSX's default: ~/Library/Logs?/I2P/[whatever].log
File:
1 edited

Legend:

Unmodified
Added
Removed
  • launchers/macosx/SBridge.mm

    r36b758f r2233f7f  
    2121#import <AppKit/AppKit.h>
    2222#import "I2PLauncher-Swift.h"
     23#include "LoggerWorker.hpp"
     24#include "Logger.h"
     25#include "logger_c.h"
    2326
    2427#include "AppDelegate.h"
     
    2932std::future<int> startupRouter(NSString* javaBin, NSArray<NSString*>* arguments, NSString* i2pBaseDir, RouterProcessStatus* routerStatus) {
    3033  @try {
    31     RTaskOptions* options = [RTaskOptions alloc];
    32     options.binPath = javaBin;
    33     options.arguments = arguments;
    34     options.i2pBaseDir = i2pBaseDir;
    35     auto instance = [[I2PRouterTask alloc] initWithOptions: options];
    36    
    37     [[SBridge sharedInstance] setCurrentRouterInstance:instance];
    38     [instance execute];
    39     sendUserNotification(APP_IDSTR, @"The I2P router is starting up.");
    40     auto pid = [instance getPID];
    41     NSLog(@"Got pid: %d", pid);
    42     if (routerStatus != nil) {
    43       [routerStatus setRouterStatus: true];
    44       [routerStatus setRouterRanByUs: true];
    45       [routerStatus triggerEventWithEn:@"router_start" details:@"normal start"];
    46       [routerStatus triggerEventWithEn:@"router_pid" details:[NSString stringWithFormat:@"%d", pid]];
     34    IIProcessInfo* processInfoObj = [[IIProcessInfo alloc] init];
     35    [processInfoObj obtainFreshProcessList];
     36    auto anyRouterLookingProcs = [processInfoObj findProcessWithStringInNameOrArguments:@"i2p.jar"];
     37    if (anyRouterLookingProcs) {
     38      auto errMessage = @"Seems i2p is already running - I've detected another process with i2p.jar in it's arguments.";
     39      NSLog(@"%@", errMessage);
     40      sendUserNotification(APP_IDSTR, errMessage);
     41      [routerStatus triggerEventWithEn:@"router_already_running" details:@"won't start - another router is running"];
     42      return std::async(std::launch::async, []{
     43        return -1;
     44      });
     45    } else {
     46      RTaskOptions* options = [RTaskOptions alloc];
     47      options.binPath = javaBin;
     48      options.arguments = arguments;
     49      options.i2pBaseDir = i2pBaseDir;
     50      auto instance = [[I2PRouterTask alloc] initWithOptions: options];
     51     
     52      [[SBridge sharedInstance] setCurrentRouterInstance:instance];
     53      [instance execute];
     54      sendUserNotification(APP_IDSTR, @"The I2P router is starting up.");
     55      auto pid = [instance getPID];
     56      NSLog(@"Got pid: %d", pid);
     57      if (routerStatus != nil) {
     58        // TODO: Merge events router_start and router_pid ?
     59        [routerStatus triggerEventWithEn:@"router_start" details:@"normal start"];
     60        [routerStatus triggerEventWithEn:@"router_pid" details:[NSString stringWithFormat:@"%d", pid]];
     61      }
     62     
     63      return std::async(std::launch::async, [&pid]{
     64        return pid;
     65      });
    4766    }
    48    
    49     return std::async(std::launch::async, [&pid]{
    50       return pid;
    51     });
    5267  }
    5368  @catch (NSException *e)
     
    93108  auto jarList = buildClassPathForObjC(basePath);
    94109  const char * classpath = jarList.c_str();
    95   NSLog(@"Classpath from ObjC = %s", classpath);
     110  MLog(0, @"Classpath from ObjC = %s", classpath);
    96111  return [[NSString alloc] initWithUTF8String:classpath];
    97112}
     
    106121 
    107122  RouterProcessStatus* routerStatus = [[RouterProcessStatus alloc] init];
     123 
     124  NSString *confDir = [NSString stringWithFormat:@"%@/Application\\ Support/i2p", NSHomeDirectory()];
     125 
    108126  try {
    109127    std::vector<NSString*> argList = {
     
    111129      @"-Xms128m",
    112130      @"-Djava.awt.headless=true",
    113       @"-Dwrapper.logfile=/tmp/router.log",
     131      [NSString stringWithFormat:@"-Dwrapper.logfile=%@/router.log", [NSString stringWithUTF8String:getDefaultLogDir().c_str()]],
    114132      @"-Dwrapper.logfile.loglevel=DEBUG",
    115       @"-Dwrapper.java.pidfile=/tmp/routerjvm.pid",
     133      [NSString stringWithFormat:@"-Dwrapper.java.pidfile=%@/router.pid", confDir],
    116134      @"-Dwrapper.console.loglevel=DEBUG"
    117135    };
Note: See TracChangeset for help on using the changeset viewer.