Skip to content
Permalink
Browse files

reduce lock/unlock for DICOM Services SCP

git-svn-id: https://svn.code.sf.net/p/osirix/code/osirix@7848 4e9e6e3d-4551-47eb-9dbe-a6127f9400a1
  • Loading branch information...
rossetantoine committed Dec 9, 2010
1 parent 4753837 commit 76e11e057432538c22b6306543156c62a57c8d2a
@@ -131,6 +131,7 @@ extern "C"
+ (BOOL) willExecutePlugin;
+ (BOOL) hasMacOSXSnowLeopard;
+ (BOOL) hasMacOSXLeopard;
+ (void) createDBFoldersIfNecessary;

#pragma mark-
#pragma mark initialization of the main event loop singleton
@@ -12,6 +12,8 @@
PURPOSE.
=========================================================================*/

//diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://1165430`

#import "SystemConfiguration/SCDynamicStoreCopySpecific.h"
#include <CoreFoundation/CoreFoundation.h>
#include <ApplicationServices/ApplicationServices.h>
@@ -2612,6 +2614,46 @@ + (BOOL) willExecutePlugin
return returnValue;
}

+ (void) createDBFoldersIfNecessary
{
// if( [[NSUserDefaults standardUserDefaults] boolForKey: @"UseRAMDisk"] && [[NSUserDefaults standardUserDefaults] boolForKey: @"STORESCP"])
// {
// if( [[NSFileManager defaultManager] fileExistsAtPath: @"/Volumes/OsiriX-RAM-disk"] == NO)
// {
// NSTask *ramDiskTask = [[[NSTask alloc] init] autorelease];
//
// [ramDiskTask setLaunchPath: @"/bin/sh"];
// [ramDiskTask setArguments: [NSArray arrayWithObject: [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"/ramDiskScript.txt"]]];
// [ramDiskTask launch];
// [ramDiskTask waitUntilExit];
// }
//
// // Create symbolic links for TEMP.noindex, DECOMPRESSION.noindex, and INCOMING.noindex
// [[NSFileManager defaultManager] removeItemAtPath: [[[BrowserController currentBrowser] localDocumentsDirectory] stringByAppendingPathComponent: @"/TEMP.noindex"] error: nil];
// [[NSFileManager defaultManager] removeItemAtPath: [[[BrowserController currentBrowser] localDocumentsDirectory] stringByAppendingPathComponent: @"/DECOMPRESSION.noindex"] error: nil];
// [[NSFileManager defaultManager] removeItemAtPath: [[[BrowserController currentBrowser] localDocumentsDirectory] stringByAppendingPathComponent: @"/INCOMING.noindex"] error: nil];
//
// [[NSFileManager defaultManager] removeItemAtPath: @"/Volumes/OsiriX-RAM-disk/TEMP.noindex" error: nil];
// [[NSFileManager defaultManager] removeItemAtPath: @"/Volumes/OsiriX-RAM-disk/DECOMPRESSION.noindex" error: nil];
// [[NSFileManager defaultManager] removeItemAtPath: @"/Volumes/OsiriX-RAM-disk/INCOMING.noindex" error: nil];
//
// [[NSFileManager defaultManager] createDirectoryAtPath: @"/Volumes/OsiriX-RAM-disk/TEMP.noindex" attributes: nil];
// [[NSFileManager defaultManager] createDirectoryAtPath: @"/Volumes/OsiriX-RAM-disk/DECOMPRESSION.noindex" attributes: nil];
// [[NSFileManager defaultManager] createDirectoryAtPath: @"/Volumes/OsiriX-RAM-disk/INCOMING.noindex" attributes: nil];
//
// [[NSFileManager defaultManager] createSymbolicLinkAtPath: [[[BrowserController currentBrowser] localDocumentsDirectory] stringByAppendingPathComponent: @"/TEMP.noindex"] withDestinationPath: @"/Volumes/OsiriX-RAM-disk/TEMP.noindex" error: nil];
// [[NSFileManager defaultManager] createSymbolicLinkAtPath: [[[BrowserController currentBrowser] localDocumentsDirectory] stringByAppendingPathComponent: @"/DECOMPRESSION.noindex"] withDestinationPath: @"/Volumes/OsiriX-RAM-disk/DECOMPRESSION.noindex" error: nil];
// [[NSFileManager defaultManager] createSymbolicLinkAtPath: [[[BrowserController currentBrowser] localDocumentsDirectory] stringByAppendingPathComponent: @"/INCOMING.noindex"] withDestinationPath: @"/Volumes/OsiriX-RAM-disk/INCOMING.noindex" error: nil];
// }
// else
{
// DELETE & CREATE THE TEMP.noindex DIRECTORY...
NSString *tempDirectory = [documentsDirectory() stringByAppendingPathComponent:@"/TEMP.noindex/"];
if ([[NSFileManager defaultManager] fileExistsAtPath:tempDirectory]) [[NSFileManager defaultManager] removeFileAtPath:tempDirectory handler: nil];
if ([[NSFileManager defaultManager] fileExistsAtPath:tempDirectory] == NO) [[NSFileManager defaultManager] createDirectoryAtPath:tempDirectory attributes:nil];
}
}

static BOOL initialized = NO;
+ (void) initialize
{
@@ -2863,10 +2905,7 @@ + (void) initialize
// if ([[NSFileManager defaultManager] fileExistsAtPath:roisDirectory isDirectory: &isDir] == YES && isDir == NO) [[NSFileManager defaultManager] removeFileAtPath: roisDirectory handler: nil];
// if ([[NSFileManager defaultManager] fileExistsAtPath:roisDirectory] == NO) [[NSFileManager defaultManager] createDirectoryAtPath:roisDirectory attributes:nil];

// DELETE & CREATE THE TEMP.noindex DIRECTORY...
NSString *tempDirectory = [documentsDirectory() stringByAppendingPathComponent:@"/TEMP.noindex/"];
if ([[NSFileManager defaultManager] fileExistsAtPath:tempDirectory]) [[NSFileManager defaultManager] removeFileAtPath:tempDirectory handler: nil];
if ([[NSFileManager defaultManager] fileExistsAtPath:tempDirectory] == NO) [[NSFileManager defaultManager] createDirectoryAtPath:tempDirectory attributes:nil];
[AppController createDBFoldersIfNecessary];

NSString *dumpDirectory = [documentsDirectory() stringByAppendingPathComponent:@"/DUMP/"];
if ([[NSFileManager defaultManager] fileExistsAtPath:dumpDirectory] == NO) [[NSFileManager defaultManager] createDirectoryAtPath:dumpDirectory attributes:nil];
@@ -431,7 +431,6 @@ static void getSubOpProgressCallback(void * callbackData,
char outfname[ 4096];

strcpy( outfname, "");

sprintf( outfname, "%s/%s/QR-CGET-%d-%d.dcm", [[BrowserController currentBrowser] cfixedDocumentsDirectory], "TEMP.noindex", seed++, getpid());
unlink( outfname);

@@ -401,7 +401,7 @@ void str_toupper(char *s)

FILE * pFile;
char dir[ 1024], newdir[1024];
sprintf( dir, "%s/%s%s", [[BrowserController currentBrowser] cfixedIncomingDirectory], "TEMP.noindex/store_log_", handle->logUID);
sprintf( dir, "%s/%s%s", [[BrowserController currentBrowser] cfixedTempNoIndexDirectory], "store_log_", handle->logUID);
pFile = fopen (dir,"w+");
if( pFile)
{
@@ -1173,7 +1173,7 @@ void str_toupper(char *s)

FILE * pFile;
char dir[ 1024], newdir[1024];
sprintf( dir, "%s/%s%s", [[BrowserController currentBrowser] cfixedIncomingDirectory], "TEMP.noindex/store_log_", handle->logUID);
sprintf( dir, "%s/%s%s", [[BrowserController currentBrowser] cfixedTempNoIndexDirectory], "store_log_", handle->logUID);
pFile = fopen (dir,"w+");
if( pFile)
{
@@ -1219,9 +1219,7 @@ void str_toupper(char *s)
unsigned seedvalue = seed;
newImageFileName[0] = 0; // return empty string in case of error

char dir[ 4096];
sprintf( dir, "%s/%s", [[BrowserController currentBrowser] cfixedIncomingDirectory], "TEMP.noindex");
if (! fnamecreator.makeFilename(seedvalue, dir, prefix, ".dcm", filename))
if (! fnamecreator.makeFilename(seedvalue, [[BrowserController currentBrowser] cfixedTempNoIndexDirectory], prefix, ".dcm", filename))
{
return DcmQROsiriXDatabaseError;
}
@@ -650,7 +650,7 @@ static void storeCallback(
if (strcmp(imageFileName, NULL_DEVICE_NAME) != 0)
{
char dir[ 1024];
sprintf( dir, "%s/%s/%s", [[BrowserController currentBrowser] cfixedIncomingDirectory], "INCOMING.noindex", last( imageFileName, '/'));
sprintf( dir, "%s/%s", [[BrowserController currentBrowser] cfixedIncomingNoIndexDirectory], last( imageFileName, '/'));
rename( imageFileName, dir);
}

@@ -1321,8 +1321,7 @@ static void storeCallback(
{
if (options_.verbose_)
{
printf("Association Acknowledged (Max Send PDV: %u)\n",
assoc->sendPDVLength);
printf("Association Acknowledged (Max Send PDV: %u)\n", assoc->sendPDVLength);
if (ASC_countAcceptedPresentationContexts(assoc->params) == 0)
printf(" (but no valid presentation contexts)\n");
if (options_.debug_)
@@ -1333,20 +1332,30 @@ static void storeCallback(
{
NSManagedObjectContext *dbContext = [[BrowserController currentBrowser] localManagedObjectContext];
[dbContext retain];
[dbContext lock];

@try
{
[dbContext save: nil];
}
@catch (NSException * e)
if( [dbContext tryLock])
{
NSLog( @"***** exception in %s: %@", __PRETTY_FUNCTION__, e);
[[[BrowserController currentBrowser] saveDBLock] lock];
@try
{
[dbContext save: nil];
}
@catch (NSException * e)
{
NSLog( @"***** exception in %s: %@", __PRETTY_FUNCTION__, e);
}

[dbContext unlock];
}
else
[[[BrowserController currentBrowser] saveDBLock] lock];

[dbContext release];

@try
{
staticContext = [[BrowserController currentBrowser] defaultManagerObjectContextForceLoading: YES];

[staticContext retain];
@try
{
@@ -1365,8 +1374,7 @@ static void storeCallback(
NSLog( @"***** exception in %s: %@", __PRETTY_FUNCTION__, e);
}

[dbContext unlock];
[dbContext release];
[[[BrowserController currentBrowser] saveDBLock] unlock];

NSString *str = getErrorMessage();

@@ -1378,22 +1386,25 @@ static void storeCallback(
{
if( cond != ASC_SHUTDOWNAPPLICATION)
{


// [[[BrowserController currentBrowser] checkIncomingLock] lock];

NSManagedObjectContext *dbContext = [[BrowserController currentBrowser] localManagedObjectContext];
[dbContext retain];
[dbContext lock];

@try
if( [dbContext tryLock])
{
[dbContext save: nil];
}
@catch (NSException * e)
{
NSLog( @"***** exception in %s: %@", __PRETTY_FUNCTION__, e);
[[[BrowserController currentBrowser] saveDBLock] lock];
@try
{
[dbContext save: nil];
}
@catch (NSException * e)
{
NSLog( @"***** exception in %s: %@", __PRETTY_FUNCTION__, e);
}
[dbContext unlock];
}
else
[[[BrowserController currentBrowser] saveDBLock] lock];

[dbContext release];

staticContext = [[BrowserController currentBrowser] defaultManagerObjectContextForceLoading: YES];
[staticContext retain];
@@ -1446,8 +1457,6 @@ static void storeCallback(
NSString *str = getErrorMessage();
if( str)
[[AppController sharedAppController] performSelectorOnMainThread: @selector( displayListenerError:) withObject: str waitUntilDone: NO];


}
else
{
@@ -1486,14 +1495,15 @@ static void storeCallback(
NSLog( @"***** exception in %s: %@", __PRETTY_FUNCTION__, e);
}

[[[BrowserController currentBrowser] saveDBLock] unlock];

[staticContext reset];
[staticContext unlock];
[staticContext release];
staticContext = nil;

[dbContext unlock];
[dbContext release];
// [dbContext unlock];
// [dbContext release];
// [[[BrowserController currentBrowser] checkIncomingLock] unlock];
}
}
@@ -588,7 +588,9 @@ - (void) subConnectionReceived:(NSFileHandle *)incomingConnection
}

NSError *error = nil;
[[[BrowserController currentBrowser] saveDBLock] lock];
[context save: &error];
[[[BrowserController currentBrowser] saveDBLock] unlock];
[context unlock];
}

@@ -640,7 +642,9 @@ - (void) subConnectionReceived:(NSFileHandle *)incomingConnection
}

NSError *error = nil;
[[[BrowserController currentBrowser] saveDBLock] lock];
[context save: &error];
[[[BrowserController currentBrowser] saveDBLock] unlock];
[context unlock];
}

@@ -724,7 +728,9 @@ - (void) subConnectionReceived:(NSFileHandle *)incomingConnection
}

NSError *error = nil;
[[[BrowserController currentBrowser] saveDBLock] lock];
[context save: &error];
[[[BrowserController currentBrowser] saveDBLock] unlock];
[context unlock];

refreshDB = YES;
@@ -4987,9 +4987,9 @@ - (BOOL)checkROIsForHitAtPoint:(NSPoint)point forEvent:(NSEvent *)event
{
BOOL haveHit = NO;

for( int i = 0; i < [curRoiList count]; i++)
for( ROI *r in curRoiList)
{
if( [[curRoiList objectAtIndex:i] mouseRoiDragged: point :[event modifierFlags] :scaleValue] != NO)
if( [r mouseRoiDragged: point :[event modifierFlags] :scaleValue] != NO)
{
haveHit = YES;
}
@@ -1377,7 +1377,9 @@ - (NSManagedObject *) annotationsSRImage // Comments, Status, Key Images, ...
[[self managedObjectContext] deleteObject: i];
}
}
[[[BrowserController currentBrowser] saveDBLock] lock];
[[self managedObjectContext] save: nil];
[[[BrowserController currentBrowser] saveDBLock] unlock];

[r setValue: [NSNumber numberWithBool: YES] forKeyPath: @"inDatabaseFolder"];
}
@@ -1469,7 +1471,9 @@ - (NSManagedObject *) reportSRSeries
[[self managedObjectContext] deleteObject: i];
}
}
[[[BrowserController currentBrowser] saveDBLock] lock];
[[self managedObjectContext] save: nil];
[[[BrowserController currentBrowser] saveDBLock] unlock];

[r setValue: [NSNumber numberWithBool: YES] forKeyPath: @"inDatabaseFolder"];
}
@@ -1526,7 +1530,9 @@ - (NSManagedObject *)roiSRSeries
[[self managedObjectContext] deleteObject: i];
}
}
[[[BrowserController currentBrowser] saveDBLock] lock];
[[self managedObjectContext] save: nil];
[[[BrowserController currentBrowser] saveDBLock] unlock];

[r setValue: [NSNumber numberWithBool: YES] forKeyPath: @"inDatabaseFolder"];
}
@@ -20,7 +20,7 @@

@interface MPRDCMView : DCMView
{
int viewID;
int viewID, mouseDownTool;
VRView *vrView;
DCMPix *pix;
Camera *camera;
@@ -1220,9 +1220,9 @@ - (void) mouseDown:(NSEvent *)theEvent

if( clickCount == 2)
{
long tool = [self getTool: theEvent];
mouseDownTool = [self getTool: theEvent];

if( tool == tText)
if( mouseDownTool == tText)
{
[[self windowController] roiGetInfo: self];
}
@@ -1296,10 +1296,17 @@ - (void) mouseDown:(NSEvent *)theEvent
}
else
{
long tool = [self getTool: theEvent];
mouseDownTool = [self getTool: theEvent];

if( [self roiTool: currentTool])
{
NSPoint tempPt = [self ConvertFromNSView2GL: [self convertPoint: [theEvent locationInWindow] fromView: nil]];
if( [self clickInROI: tempPt])
mouseDownTool = currentTool;
}

vrView.keep3DRotateCentered = YES;
if( tool == tCamera3D)
if( mouseDownTool == tCamera3D)
{
if( displayCrossLines == NO || frameZoomed == YES)
vrView.keep3DRotateCentered = NO;
@@ -1312,7 +1319,7 @@ - (void) mouseDown:(NSEvent *)theEvent

[self restoreCamera];

if([self is2DTool: tool])
if([self is2DTool: mouseDownTool])
{
[super mouseDown: theEvent];
[windowController propagateWLWW: self];
@@ -1385,14 +1392,12 @@ - (void) mouseUp:(NSEvent *)theEvent
}
else
{
long tool = [self getTool: theEvent];

if([self is2DTool:tool])
if([self is2DTool: mouseDownTool])
{
[super mouseUp: theEvent];
[windowController propagateWLWW: self];

if( tool == tNext)
if( mouseDownTool == tNext)
[windowController updateViewsAccordingToFrame: self];

for( ROI *r in curRoiList)
@@ -1497,9 +1502,7 @@ - (void) mouseDragged:(NSEvent *)theEvent
}
else
{
long tool = [self getTool: theEvent];

if([self is2DTool:tool])
if( [self is2DTool: mouseDownTool])
{
[super mouseDragged: theEvent];
[windowController propagateWLWW: self];
Oops, something went wrong.

0 comments on commit 76e11e0

Please sign in to comment.
You can’t perform that action at this time.