// // PSDefines.m // Perforce // // Created by Adam Czubernat on 07.05.2013. // Copyright (c) 2013 Perforce Software, Inc. All rights reserved. // #import "PSDefines.h" #import <ExceptionHandling/ExceptionHandling.h> // Constant strings NSString * const PSException = @"Perforce Exception"; NSString * const PSDomain = @"com.perforce"; // Queue definitions const char * PSDispatchGlobalQueueLabel = "com.perforce.globalQueue"; dispatch_queue_t PSDispatchGlobalQueue = NULL; static dispatch_once_t PSDispatchOnceToken; // Queue invocations count static int PSDispatchGlobalQueueWaiting = 0; static int PSDispatchMainQueueWaiting = 0; void PSDispatchInBackgroundThreadAndWait(dispatch_block_t block); // Logging NSString * const PSDebugLogNotification = @"PSDebugLogNotification"; static NSMutableArray *_PSLogBuffer; static int _PSLogBufferSize = 128; static int _PSLogBufferPointer; static NSMutableDictionary *_PSLogStorage; void _PSDebugLogSave(NSString *path, NSString *header); // Crash handling private void _PSDebugCrash(NSString *description, NSArray *callstack); void _PSDebugExceptionCallback(NSException *exception); void _PSDebugSignalCallback(int signal); #pragma mark - GCD void PSDispatchInBackgroundThread(dispatch_block_t block) { dispatch_once(&PSDispatchOnceToken, ^{ PSDispatchGlobalQueue = dispatch_queue_create(PSDispatchGlobalQueueLabel, NULL); }); dispatch_async(PSDispatchGlobalQueue, block); } void PSDispatchInMainThread(dispatch_block_t block) { PSDispatchMainQueueWaiting++; if (dispatch_get_current_queue() == dispatch_get_main_queue()) { // PSLogf(@"Already in main queue: performing block in-place"); block(); // Already in main queue: performing block in-place } else { if (PSDispatchGlobalQueueWaiting > 0) PSLogf(@"Possible deadlock"); dispatch_sync(dispatch_get_main_queue(), block); } PSDispatchMainQueueWaiting--; } extern void PSDispatchAfter(NSTimeInterval interval, dispatch_block_t block) { dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(interval * NSEC_PER_SEC)); dispatch_after(time, dispatch_get_main_queue(), block); } void PSDispatchInBackgroundThreadAndWait(dispatch_block_t block) { PSDispatchGlobalQueueWaiting++; if (dispatch_get_current_queue() == PSDispatchGlobalQueue) { PSLogf(@"Already in background queue: performing block in-place"); block(); } else { dispatch_once(&PSDispatchOnceToken, ^{ PSDispatchGlobalQueue = dispatch_queue_create(PSDispatchGlobalQueueLabel, NULL); }); if (PSDispatchMainQueueWaiting > 0) PSLogf(@"Possible deadlock"); dispatch_sync(PSDispatchGlobalQueue, block); } PSDispatchGlobalQueueWaiting--; } PSTimeStamp PSTimeStampMake(void) { return CACurrentMediaTime(); } NSTimeInterval PSTimeInterval(PSTimeStamp timestamp) { return CACurrentMediaTime() - timestamp; } #pragma mark - Runtime NSDictionary * PSRuntimeIvarsForClass(Class class) { NSMutableDictionary *ivarsDict = [NSMutableDictionary dictionary]; unsigned int count; Ivar *ivars = class_copyIvarList(class, &count); for(int i=0; i<count; i++) { Ivar ivar = ivars[i]; const char *name = ivar_getName(ivar); const char *typeEncoding = ivar_getTypeEncoding(ivar); [ivarsDict setObject:[NSString stringWithFormat:@"%s", typeEncoding] forKey:[NSString stringWithFormat:@"%s", name]]; } free(ivars); return ivarsDict; } void * PSRuntimeAddressOfInstanceVariable(id object, char * variableName) { Ivar instanceVar = class_getInstanceVariable([object class], variableName); return (__bridge void *)object + ivar_getOffset(instanceVar); } #pragma mark - Debug NSMutableDictionary *PSInstancesDictionary; NSInteger PSInstanceCount(Class classObject) { NSNumber *count = [PSInstancesDictionary objectForKey:NSStringFromClass(classObject)]; return count.integerValue; } void PSInstanceCreated(Class classObject) { if (!PSInstancesDictionary) PSInstancesDictionary = [NSMutableDictionary dictionaryWithCapacity:1024]; NSString *className = NSStringFromClass(classObject); NSInteger count = [[PSInstancesDictionary objectForKey:className] integerValue]; [PSInstancesDictionary setObject:@(count + 1) forKey:className]; } void PSInstanceDeallocated(Class classObject) { NSString *className = NSStringFromClass(classObject); NSInteger count = [[PSInstancesDictionary objectForKey:className] integerValue]; if (count > 0) [PSInstancesDictionary setObject:@(count - 1) forKey:className]; else PSLog(@"PSInstanceDeallocated too many times: %@ %ld", className, count); } void PSInstanceLog(void) { printf("Printing living instances : \n\n"); [PSInstancesDictionary enumerateKeysAndObjectsUsingBlock: ^(NSString *key, NSNumber *count, BOOL *stop) { printf("%6ld | %s\n", count.integerValue, key.UTF8String); }]; printf("\n"); } #pragma mark - Logs void PSLog(NSString *format, ...) { va_list args; va_start(args, format); NSString *string = [[NSString alloc] initWithFormat:format arguments:args]; va_end(args); static FILE *logFile; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ if (isatty(STDERR_FILENO)) { logFile = stderr; // If connected to debug console print to stderr } else { NSURL *libraryURL = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] firstObject]; NSURL *logsURL = [libraryURL URLByAppendingPathComponent:@"Logs" isDirectory:YES]; if (![logsURL checkResourceIsReachableAndReturnError:NULL]) { [[NSFileManager defaultManager] createDirectoryAtURL:logsURL withIntermediateDirectories:YES attributes:nil error:NULL]; } NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:(id)kCFBundleExecutableKey]; NSString *logPath = [logsURL.path stringByAppendingFormat:@"/%@.log", appName]; // Set logging to file logFile = fopen(logPath.fileSystemRepresentation, "wb"); setbuf(logFile, NULL); } }); fprintf(logFile, "%s\n", [string UTF8String]); #ifdef PS_LOGGING if (!_PSLogBuffer) _PSLogBuffer = [NSMutableArray arrayWithCapacity:_PSLogBufferSize]; @synchronized (_PSLogBuffer) { if (_PSLogBuffer.count < _PSLogBufferSize) [_PSLogBuffer insertObject:string atIndex:_PSLogBufferPointer]; else [_PSLogBuffer replaceObjectAtIndex:_PSLogBufferPointer withObject:string]; _PSLogBufferPointer = (_PSLogBufferPointer + 1) % _PSLogBufferSize; dispatch_async(dispatch_get_main_queue(), ^{ [[NSNotificationCenter defaultCenter] postNotificationName:PSDebugLogNotification object:string]; }); } #endif } void PSLogStore(NSString *key, NSString *format, ...) { va_list args; va_start(args, format); NSString *string = [[NSString alloc] initWithFormat:format arguments:args]; va_end(args); PSLog(@"%@ : %@", key, string); #ifdef PS_LOGGING dispatch_async(dispatch_get_main_queue(), ^{ if (!_PSLogStorage) _PSLogStorage = [NSMutableDictionary dictionary]; [_PSLogStorage setObject:string forKey:key]; }); #endif } NSArray * PSDebugLogDump(void) { NSMutableArray *log = [NSMutableArray arrayWithCapacity:_PSLogBufferSize]; NSInteger size = _PSLogBuffer.count; NSInteger start = _PSLogBufferPointer; if (size != _PSLogBufferSize) start = 0; for (NSInteger i=0; i<size; i++) { NSString *entry = [_PSLogBuffer objectAtIndex:(start+i) % size]; [log addObject:entry]; } return log; } void PSDebugLogSave(void) { _PSDebugLogSave(@"P4Log ", nil); } void PSDebugLogClear(void) { _PSLogStorage = nil; [[NSNotificationCenter defaultCenter] postNotificationName:PSDebugLogNotification object:nil]; } void _PSDebugLogSave(NSString *name, NSString *header) { NSMutableString *log = [NSMutableString string]; if (header) [log appendString:header]; [log appendString:@"\n----------------- Log info -----------------\n\n"]; [_PSLogStorage enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) { [log appendFormat:@"%@ : %@\n", key, value]; }]; [log appendString:@"\n----------------- Instances -----------------\n\n"]; [PSInstancesDictionary enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) { [log appendFormat:@"%@ : %@\n", key, value]; }]; [log appendString:@"\n\n----------------- Messages -----------------\n\n"]; [log appendString:[PSDebugLogDump() componentsJoinedByString:@"\n"]]; [log appendString:@"\n\n--------------------------------------------\n\n"]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd' 'HH.mm"]; NSString *path = [NSString stringWithFormat:@"%@/Desktop/%@%@.log", NSHomeDirectory(), name, [formatter stringFromDate:[NSDate date]]]; [log writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:NULL]; } #pragma mark - Crash handling static NSObject *_PSDebugExceptionHandlerInstance; @interface _PSDebugExceptionHandler : NSObject @end @implementation _PSDebugExceptionHandler - (BOOL)exceptionHandler:(NSExceptionHandler *)sender shouldLogException:(NSException *)exception mask:(NSUInteger)aMask { NSString *desc = [NSString stringWithFormat: @"Application crashed with uncaught exception:\n" @"%@", exception.description]; _PSDebugCrash(desc, exception.callStackSymbols ?: [NSThread callStackSymbols]); return YES; } @end void PSDebugInstallCrashHandler(void) { NSExceptionHandler *exceptionHandler = [NSExceptionHandler defaultExceptionHandler]; exceptionHandler.exceptionHandlingMask = NSLogAndHandleEveryExceptionMask; exceptionHandler.delegate = _PSDebugExceptionHandlerInstance = [[_PSDebugExceptionHandler alloc] init]; // NSSetUncaughtExceptionHandler(&_PSDebugExceptionCallback); signal(SIGABRT, _PSDebugSignalCallback); signal(SIGSEGV, _PSDebugSignalCallback); signal(SIGBUS, _PSDebugSignalCallback); } void _PSDebugCrash(NSString *description, NSArray *callstack) { NSMutableString *log = [NSMutableString string]; [log appendString: @"\n---------- File Manager Crash Log ----------\n\n"]; [log appendFormat:@"%@\n\nStack trace: %@\n", description, callstack]; _PSDebugLogSave(@"P4Crash ", log); PSLog(@"%@", log); // Remove crash handlers // NSSetUncaughtExceptionHandler(NULL); signal(SIGABRT, SIG_DFL); signal(SIGSEGV, SIG_DFL); signal(SIGBUS, SIG_DFL); abort(); } //void _PSDebugExceptionCallback(NSException *exception) { // // NSString *desc = [NSString stringWithFormat: // @"Application crashed with uncaught exception:\n" // @"%@", exception.description]; // // _PSDebugCrash(desc, exception.callStackSymbols); //} void _PSDebugSignalCallback(int signal) { char *name = NULL; if (signal == SIGABRT) name = "SIGABRT"; else if (signal == SIGSEGV) name = "EXC_BAD_ACCESS"; else if (signal == SIGBUS) name = "SIGBUS"; NSArray *callStack = [NSThread callStackSymbols]; NSString *desc = [NSString stringWithFormat: @"Application crashed receiving signal %d %s", signal, name]; _PSDebugCrash(desc, callStack); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 16817 | christoph_leithner | "Forking branch Main of perforce-software-piper to christoph_leithner-piper." | ||
//guest/perforce_software/piper/main/mac/R2.0/Perforce/PSDefines.m | |||||
#1 | 16507 | perforce_software | Move to main branch. | ||
//guest/perforce_software/piper/mac/R2.0/Perforce/PSDefines.m | |||||
#1 | 12962 | alan_petersen |
Populate -o //guest/perforce_software/piper/mac/main/... //guest/perforce_software/piper/mac/R2.0/.... |
||
//guest/perforce_software/piper/mac/main/Perforce/PSDefines.m | |||||
#2 | 12961 | alan_petersen |
Piper 2.0 Mega Update New Features/Functionality - Added help menu redirecting to URL. - Added readonly property for creating new workspaces. - Added html hyperlinks for Copy link functionality. - Added functionality for managing Finder Favorite items in sidebar. - Redesigned the way mapping is stored in Piper. - First version of syncing finder sidebar items with workspace mapping. - Small sorting improvements. - Creating Projects directory inside users home folder. - Adding Projects folder to finder sidebar item. - Creating and removing symbolic links accordingly to mapped folders. - Preventing duplicate names in symbolic links. - Refreshing symbolic links on mapping change inside application. - Storing workspace and server details in p4 configuration for other applications to use. - Added contextual menu items for Finder integration. - Added services menu for Adobe Illustrator integration. - Keyboard shortcuts for Illustrator integration. - Code refactoring and fixes for mapping issues. - Added Finder functionality to edit all files in folder. - Added user friendly message when editing a file using Finder outside the workspace. - Implemented hidden automatic login when opening application using Finder integration. - Logging to file in ~/Library/Logs - Unified workspace and all files views to show both local and depot files and folders. - Removed my workspace view references and logic. - Editing unmapped files on server. - First version of adding file to unmapped folders. - Showing opened by and edit actions in column details for all depot files. - Improved mappings functionality. - Enabled same feature options for mapped and unmapped folders and files. - Redesigned from scratch mapping and unmapping procedures for adding and removing files. - Implemented cleaning workspace using new mapping functionality. Removed debug overlay coloring. - Automated workspace creation - Improvements in editing files already mapped to workspace. - Implemented deleting remote files. - Implemented first version of move operation for remote files. - Removing last workspace information when disconnecting from workspace using app menu. - Implemented editing and submitting using symbolic links in project folder. New finder menu service for symbolic links Show in Piper which acts like share link functionality. - New icons for files and folders not tracked in the filesystem. - Improvements in showing file using share link. - Switched to new way of retrieving files in order to show user changes. - Redesigned and implemented new functionality for chaining operations with mapping. - Improvements and redesign of Edit/add actions to use new chaining logic . Fixed issue with file edit. - Improvements in window showing when using services. - Simplified file loading so the local files appears only when remote are also loaded. - Improved deleting of untracked files to avoid mapping and marking for delete. - Enabling simple copy paste and moving of remote and local files. - Added abort for exception handling in order to force crashing application on critical failures - Added custom exception handling for catching runtime errors to log and crash instead of continuing in unstable state. - Changed file copying to use mark for add . - Simplified and fixed responding file representations to mapping changes. Bug Fixes - Fixed crash when synchronizing. - Fixed sync issue when downloading directory without file size information. - Fixed issue with unread list crashing when file is not existing on disk. - Fixed incorrect sync progress calculation. - Removed relative path issues. - Fixed many of case-sensitivity problems. - Fixed deprecated methods and related issues in OS X 10.10. - Fixed folder rename not updating in column view. Revised and fixed many potential problems from implicit casting. - Fixed missing sync button on fast sync completion. - Refreshing mapping on synchronization. Fixed symbolic links not appearing until app is restarted. - Fixed latest crashing of autosync. - Fixed loading indicator issues. - Fixed and redesigned submit dialog to work correctly with Submit All Files option in Finder. - Fixed multiple error messages on network outage. Redesigned showing errors in main window. - Fixed opening random locations when using Finder integration. - Fixed issue when panel was detached from parent window. - Fixed bug when creating new workspace wouldn't store default settings. - Fixed memory issues with network operations. - Fixes in relogging mappings and file listing. - Improvements in editing unmapped files. - Fixed crash when adding file outside workspace. - Fixed breadcrumbs control issue. - Fixed issue with double parent folders when opening unmapped files. - Fixed crashes on sync after mapping new files. - Fixed issue with editing file using Finder -- Merging code and additional fixes in add button functionality. - Fixed unsync not working - Fixed submit panel issue not selecting files with different name case. - Fixed missing revert and sync to workspace actions in some cases. - Fixed issue with Submit and Edit finder actions. Improvements in stability of finder integration. - Fixed issue with unsubmitted folders breaking status of files inside. - Fixed issue with added files not showing correct icon and status. - Fixed bug with file edit resulting in a new directory named exactly like a file. - Fixed issue with reloading of subpath resulting in untracked folders. - Fixed mapping issue when result was always view mapping not relative. - Fixed submit panel showing more than once. - Fixed illustrator services not working. - Fixed userdefaults preferences problem with workspace name being null. - Fixed userdefaults keypath problem of dot-containing workspace names. - Forcing recreating of browser to possibly prevent pre-10.10 errors with automatic workspace selection. - Fixed adding file to depot not presenting correct icon. - Fixed issues with reverting a file that was marked for add. - Presenting error when trying to submit untracked files. - Fixed issue when submit files service crashed when using unmapped files. - Fixed file representation disappearing when removing file. - Fixed issue with symlinks resolving working on 10.10 only. Issue related to workspace selection not showing. - Fixed error panel method calls unavailable in Mac OS versions before 10.10. Issue related to hanging error panels. - Fixed removing a local file resulting in action progress freezing. - Fixed open file not working after edit. - Fixing crash when mapping changed. Issue related to moving local file to unmapped folder and other similar cases. |
||
#1 | 11252 | alan_petersen | Rename/move file(s) | ||
//guest/perforce_software/piper/mac/Perforce/PSDefines.m | |||||
#1 | 10744 | alan_petersen | Rename/move file(s) | ||
//guest/perforce_software/piper/Perforce/PSDefines.m | |||||
#1 | 8919 | Matt Attaway | Initial add of Piper, a lightweight Perforce client for artists and designers. |