summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--macosx/Controller.h4
-rw-r--r--macosx/Controller.m42
-rw-r--r--macosx/HBQueueController.h1
-rw-r--r--macosx/HBQueueController.mm7
4 files changed, 39 insertions, 15 deletions
diff --git a/macosx/Controller.h b/macosx/Controller.h
index 662563e7f..b8cebbbee 100644
--- a/macosx/Controller.h
+++ b/macosx/Controller.h
@@ -265,7 +265,8 @@ BOOL fIsDragging;
hb_handle_t * fHandle;
/* Queue variables */
- hb_handle_t * fQueueEncodeLibhb; // libhb for HB Encoding
+ int hbInstanceNum; //stores the number of HandBrake instances currently running
+ hb_handle_t * fQueueEncodeLibhb; // libhb for HB Encoding
hb_title_t * fTitle;
hb_title_t * fQueueEncodeTitle;
int fEncodingQueueItem; // corresponds to the index of fJobGroups encoding item
@@ -291,7 +292,6 @@ BOOL fIsDragging;
double dockIconProgress;
}
-- (int) getThisHBInstancePID;
- (IBAction) showAboutPanel:(id)sender;
- (void) writeToActivityLog:(const char *) format, ...;
diff --git a/macosx/Controller.m b/macosx/Controller.m
index 66d7674a5..d9122b587 100644
--- a/macosx/Controller.m
+++ b/macosx/Controller.m
@@ -86,9 +86,9 @@ static NSString * ChooseSourceIdentifier = @"Choose Source It
[self writeToActivityLog: "%s", [versionStringFull UTF8String]];
/* Get the PID number for this hb instance, used in multi instance encoding */
- pidNum = [self getThisHBInstancePID];
+ //pidNum = [self getThisHBInstancePID];
/* Report this pid to the activity log */
- [self writeToActivityLog: "Pid for this instance:%d", pidNum];
+ //[self writeToActivityLog: "Pid for this instance:%d", pidNum];
return self;
}
@@ -130,6 +130,9 @@ static NSString * ChooseSourceIdentifier = @"Choose Source It
/* Init QueueFile .plist */
[self loadQueueFile];
+ /* Run hbInstances to get any info on other instances as well as set the
+ * pid number for this instance in the case of multi-instance encoding. */
+ hbInstanceNum = [self hbInstances];
/* Call UpdateUI every 1/2 sec */
@@ -177,7 +180,7 @@ static NSString * ChooseSourceIdentifier = @"Choose Source It
/* We check to see if there is already another instance of hb running.
* Note: hbInstances == 1 means we are the only instance of HandBrake.app
*/
- if ([self hbInstances] > 1)
+ if (hbInstanceNum > 1)
{
alertTitle = [NSString stringWithFormat:
NSLocalizedString(@"There is already an instance of HandBrake running.", @"")];
@@ -234,28 +237,45 @@ static NSString * ChooseSourceIdentifier = @"Choose Source It
#pragma mark -
#pragma mark Multiple Instances
+
+/* hbInstances checks to see if other instances of HB are running and also sets the pid for this instance for multi-instance queue encoding */
+
+ /* Note for now since we are in early phases of multi-instance I have put in quite a bit of logging. Can be removed as we see fit. */
- (int) hbInstances
{
/* check to see if another instance of HandBrake.app is running */
NSArray *runningAppDictionaries = [[NSWorkspace sharedWorkspace] launchedApplications];
NSDictionary *runningAppsDictionary;
int hbInstances = 0;
+ NSString * thisInstanceAppPath = [[NSBundle mainBundle] bundlePath];
+ NSString * runningInstanceAppPath;
+ int runningInstancePidNum;
+ [self writeToActivityLog: "hbInstances path to this instance: %s", [thisInstanceAppPath UTF8String]];
for (runningAppsDictionary in runningAppDictionaries)
{
if ([[runningAppsDictionary valueForKey:@"NSApplicationName"] isEqualToString:@"HandBrake"])
{
hbInstances++;
+ /*Report the path to each active instances app path */
+ runningInstancePidNum = [[runningAppsDictionary valueForKey:@"NSApplicationProcessIdentifier"] intValue];
+ runningInstanceAppPath = [runningAppsDictionary valueForKey:@"NSApplicationPath"];
+ [self writeToActivityLog: "hbInstance found instance pidnum:%d at path: %s", runningInstancePidNum, [runningInstanceAppPath UTF8String]];
+ /* see if this is us by comparing the app path */
+ if ([runningInstanceAppPath isEqualToString: thisInstanceAppPath])
+ {
+ /* If so this is our pidnum */
+ [self writeToActivityLog: "hbInstance MATCH FOUND, our pidnum is:%d", runningInstancePidNum];
+ /* Get the PID number for this hb instance, used in multi instance encoding */
+ pidNum = runningInstancePidNum;
+ /* Report this pid to the activity log */
+ [self writeToActivityLog: "Pid for this instance:%d", pidNum];
+ /* Tell fQueueController what our pidNum is */
+ [fQueueController setPidNum:pidNum];
+ }
}
}
return hbInstances;
}
-/* Gets the Process Identifer (PID) for this instance and returns it as an integer */
-- (int) getThisHBInstancePID
-{
- /* Get the PID of this HB instance */
- int hbInstancePID = [[NSRunningApplication currentApplication] processIdentifier];
- return hbInstancePID;
-}
#pragma mark -
@@ -1934,7 +1954,7 @@ static NSString * ChooseSourceIdentifier = @"Choose Source It
else
{
/* ONLY clear out encoded items if we are single instance */
- if ([self hbInstances] == 1)
+ if (hbInstanceNum == 1)
{
[self clearQueueEncodedItems];
}
diff --git a/macosx/HBQueueController.h b/macosx/HBQueueController.h
index 8f1268e53..f08415fc4 100644
--- a/macosx/HBQueueController.h
+++ b/macosx/HBQueueController.h
@@ -107,6 +107,7 @@ BOOL fIsDragging;
#endif
}
+- (void)setPidNum: (int)myPidnum;
- (void)setHandle: (hb_handle_t *)handle;
- (void)setHBController: (HBController *)controller;
diff --git a/macosx/HBQueueController.mm b/macosx/HBQueueController.mm
index 451d96ee0..09719e96d 100644
--- a/macosx/HBQueueController.mm
+++ b/macosx/HBQueueController.mm
@@ -226,8 +226,11 @@ static NSString* HBQueuePauseResumeToolbarIdentifier = @"HBQueuePauseRe
- (void)setHBController: (HBController *)controller
{
fHBController = controller;
- /* Now get this pidnum from HBController */
- pidNum = [fHBController getThisHBInstancePID];
+}
+
+- (void)setPidNum: (int)myPidnum
+{
+ pidNum = myPidnum;
[fHBController writeToActivityLog: "HBQueueController : My Pidnum is %d", pidNum];
}