forked from I2P_Developers/i2p.i2p
Mac OS X Launcher: more cleanup and some bugfixes.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#import "I2PLauncher-Swift.h"
|
||||
#include "AppDelegate.h"
|
||||
#endif
|
||||
|
||||
#include "include/PidWatcher.h"
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
@@ -52,23 +53,13 @@
|
||||
[stdoutFileHandle waitForDataInBackgroundAndNotify];
|
||||
|
||||
[self.routerTask setTerminationHandler:^(NSTask* task) {
|
||||
// Cleanup
|
||||
NSLog(@"termHandler triggered!");
|
||||
auto swiftRouterStatus = [[RouterProcessStatus alloc] init];
|
||||
[swiftRouterStatus setRouterStatus: true];
|
||||
[swiftRouterStatus setRouterStatus: false];
|
||||
[swiftRouterStatus setRouterRanByUs: false];
|
||||
sendUserNotification(APP_IDSTR, @"I2P Router has stopped");
|
||||
// Cleanup
|
||||
//self.isRouterRunning = NO;
|
||||
}];
|
||||
/*
|
||||
self.readLogHandle = [self.processPipe fileHandleForReading];
|
||||
NSData *inData = nil;
|
||||
self.totalLogData = [[[NSMutableData alloc] init] autorelease];
|
||||
|
||||
while ((inData = [self.readLogHandle availableData]) &&
|
||||
[inData length]) {
|
||||
[self.totalLogData appendData:inData];
|
||||
}
|
||||
*/
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -91,63 +82,25 @@
|
||||
- (int) execute
|
||||
{
|
||||
@try {
|
||||
[self.routerTask launch];
|
||||
watchPid([self.routerTask processIdentifier]);
|
||||
self.isRouterRunning = YES;
|
||||
return 1;
|
||||
[self.routerTask launch];
|
||||
watchPid([self.routerTask processIdentifier]);
|
||||
self.isRouterRunning = YES;
|
||||
return 1;
|
||||
}
|
||||
@catch (NSException *e)
|
||||
{
|
||||
NSLog(@"Expection occurred %@", [e reason]);
|
||||
return 0;
|
||||
auto swiftRouterStatus = [[RouterProcessStatus alloc] init];
|
||||
[swiftRouterStatus setRouterStatus: false];
|
||||
[swiftRouterStatus setRouterRanByUs: false];
|
||||
sendUserNotification(@"An error occured, can't start the I2P Router", [e reason]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
- (int) getPID
|
||||
{
|
||||
return [self.routerTask processIdentifier];
|
||||
return [self.routerTask processIdentifier];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
JavaRunner::JavaRunner(std::string& javaBin, std::string& arguments, std::string& i2pBaseDir, const fp_proc_t& execFn, const fp_t& cb)
|
||||
: javaBinaryPath(javaBin), javaRouterArgs(arguments), _i2pBaseDir(i2pBaseDir), executingFn(execFn), exitCallbackFn(cb)
|
||||
{
|
||||
execLine = javaBinaryPath;
|
||||
execLine += " " + std::string(javaRouterArgs.c_str());
|
||||
printf("CLI: %s\n",execLine.c_str());
|
||||
javaProcess = std::shared_ptr<Popen>(new Popen(execLine, environment{{
|
||||
{"I2PBASE", _i2pBaseDir},
|
||||
{"JAVA_OPTS", getenv("JAVA_OPTS")}
|
||||
}}, defer_spawn{true}));
|
||||
}
|
||||
|
||||
void JavaRunner::requestRouterShutdown()
|
||||
{
|
||||
// SIGHUP
|
||||
javaProcess->kill(1);
|
||||
}
|
||||
|
||||
std::future<int> JavaRunner::execute()
|
||||
{
|
||||
try {
|
||||
auto executingFn = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{
|
||||
this->executingFn(this);
|
||||
});
|
||||
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), executingFn);
|
||||
dispatch_block_wait(executingFn, DISPATCH_TIME_FOREVER);
|
||||
|
||||
// Here, the process is done executing.
|
||||
|
||||
printf("Finished executingFn - Runs callbackFn\n");
|
||||
this->exitCallbackFn();
|
||||
return std::async(std::launch::async, []{ return 0; });
|
||||
} catch (std::exception* ex) {
|
||||
printf("ERROR: %s\n", ex->what());
|
||||
return std::async(std::launch::async, []{ return 1; });
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user