Changeset 16 for trunk

Show
Ignore:
Timestamp:
02/27/08 13:53:42 (10 months ago)
Author:
mgorbach
Message:

Error handling and further on the menuling UI

Location:
trunk
Files:
7 added
8 removed
27 modified

Legend:

Unmodified
Added
Removed
  • trunk/MFClient.h

    r15 r16  
    1717        NSMutableDictionary* pluginsDictionary; 
    1818        NSMutableArray* plugins; 
     19        NSMutableArray* recents; 
    1920        id <MFServerProtocol> server; 
    2021        id delegate; 
     
    2425- (BOOL)setup; 
    2526 
    26 - (NSArray*)filesystems; 
    27 - (NSArray*)plugins; 
    28  
    2927// Action methods 
    3028- (MFClientFS*)newFilesystemWithPlugin:(MFClientPlugin*)plugin; 
     29- (MFClientFS*)quickMountFilesystemWithURL:(NSURL*)url 
     30                                                                         error:(NSError**)error; 
    3131 
    3232// Accessors 
     
    3636@property(retain) id delegate; 
    3737 
     38// All filesystems, including temporary ones 
     39@property(readonly) NSArray* filesystems; 
     40 
     41// Only filesystems that are not temporary 
     42@property(readonly) NSArray* persistentFilesystems; 
     43@property(readonly) NSArray* mountedFilesystems; 
     44 
     45// All plugins 
     46@property (readonly) NSArray* plugins; 
     47@property(readonly) NSArray* recents; 
     48 
    3849@end 
  • trunk/MFClient.m

    r14 r16  
    1111#import "MFClientPlugin.h" 
    1212#import "MFConstants.h" 
     13#import "MFClientRecent.h" 
    1314 
    1415@interface MFClient(PrivateAPI) 
     
    1617- (void)storePlugin:(MFClientPlugin*)plugin; 
    1718- (void)removeFilesystem:(MFClientFS*)fs; 
     19 
     20@property(readwrite, retain) NSMutableArray* filesystems; 
     21@property(readwrite, retain) NSMutableArray* plugins; 
     22@property(readwrite, retain) NSMutableArray* recents; 
    1823@end 
    1924 
     
    3338} 
    3439 
     40+ (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key 
     41{ 
     42        if ([key isEqualToString:@"persistentFilesystems"] 
     43                || [key isEqualToString:@"mountedFilesystems"]) 
     44                return [NSSet setWithObject:@"filesystems"]; 
     45        else 
     46                return [super keyPathsForValuesAffectingValueForKey: key]; 
     47} 
     48 
     49 
    3550+ (MFClient*)allocWithZone:(NSZone*)zone 
    3651{ 
     
    5974                        selector:@selector(handleFilesystemRemovedNotification:) 
    6075                                name:kMFFilesystemRemovedNotification  
     76                          object:kMFDNCObject]; 
     77        [dnc addObserver:self 
     78                        selector:@selector(handleRecentsUpdatedNotification:) 
     79                                name:kMFRecentsUpdatedNotification  
    6180                          object:kMFDNCObject]; 
    6281} 
     
    6988                filesystems = [NSMutableArray array]; 
    7089                plugins = [NSMutableArray array]; 
     90                recents = [NSMutableArray array]; 
    7191        } 
    7292        return self; 
     
    97117                [self storeFilesystem: fs]; 
    98118        } 
     119         
     120        // Fill Recents 
     121        NSMutableArray* recentsFromServer = [[server recents] mutableCopy]; 
     122        for (NSDictionary* recent in recentsFromServer) 
     123                [[self mutableArrayValueForKey:@"recents"] addObject: 
     124                 [[MFClientRecent alloc] initWithParameterDictionary: recent]]; 
    99125} 
    100126 
     
    140166        NSDictionary* info = [note userInfo]; 
    141167        NSString* uuid = [info objectForKey:  KMFFSUUIDParameter]; 
    142         MFLogS(self, @"Filesystem Added: uuid %@", 
    143                    uuid); 
     168  
    144169        id remoteFilesystem = [server filesystemWithUUID: uuid]; 
    145170        if (![self filesystemWithUUID:uuid]) 
     
    149174                                                                                         clientPlugin:plugin]; 
    150175                 
    151                  
    152176                [self storeFilesystem:fs ]; 
    153177        } 
     
    158182        NSDictionary* info = [note userInfo]; 
    159183        NSString* uuid = [info objectForKey: KMFFSUUIDParameter]; 
    160         MFLogS(self, @"Filesystem Deleted: uuid %@", 
    161                    uuid); 
    162184        MFClientFS* fs = [self filesystemWithUUID: uuid]; 
    163185        [self removeFilesystem:fs]; 
     
    175197} 
    176198 
    177 #pragma Accessors and Setters 
     199- (MFClientFS*)quickMountFilesystemWithURL:(NSURL*)url 
     200                                                                         error:(NSError**)error 
     201{ 
     202        id remoteFS = [server quickMountWithURL:url]; 
     203        if (!remoteFS) 
     204        { 
     205                NSError* serverError = [server recentError]; 
     206                if (serverError) 
     207                        *error = serverError; 
     208                return nil; 
     209        } 
     210        else 
     211        { 
     212                if ([self filesystemWithUUID:[remoteFS uuid]]) 
     213                { 
     214                        return [self filesystemWithUUID: [remoteFS uuid]]; 
     215                } 
     216                 
     217                MFClientPlugin* plugin = [self pluginWithID: [remoteFS pluginID]]; 
     218                MFClientFS* newFS = [[MFClientFS alloc] initWithRemoteFS: remoteFS 
     219                                                                                                        clientPlugin: plugin ]; 
     220                [self storeFilesystem: newFS]; 
     221                return newFS; 
     222        } 
     223} 
     224 
     225#pragma mark Recents 
     226- (void)handleRecentsUpdatedNotification:(NSNotification*)note 
     227{ 
     228        NSDictionary* recentParameterDict = [[note userInfo] objectForKey: kMFRecentKey ]; 
     229        [[self mutableArrayValueForKey:@"recents"] addObject:  
     230         [[MFClientRecent alloc] initWithParameterDictionary: recentParameterDict ]]; 
     231         
     232        if ([[self recents] count] > 10) 
     233                [[self mutableArrayValueForKey:@"recents"] removeObjectAtIndex: 0]; 
     234} 
     235 
     236#pragma mark Accessors and Setters 
     237 
     238- (NSArray*)persistentFilesystems 
     239{ 
     240        return [self.filesystems filteredArrayUsingPredicate: 
     241                        [NSPredicate predicateWithFormat:@"self.isPersistent == YES"]]; 
     242} 
     243 
     244- (NSArray*)mountedFilesystems 
     245{ 
     246        return [self.filesystems filteredArrayUsingPredicate: 
     247                        [NSPredicate predicateWithFormat:@"self.isMounted == YES"]]; 
     248} 
    178249 
    179250- (void)storePlugin:(MFClientPlugin*)plugin 
     
    183254        if ([plugins indexOfObject: plugin] == NSNotFound) 
    184255        { 
    185                 [self willChange:NSKeyValueChangeInsertion 
    186                  valuesAtIndexes: [NSIndexSet indexSetWithIndex: [plugins count]] 
    187                                   forKey:@"plugins"]; 
    188                 [plugins addObject: plugin]; 
    189                 [self didChange:NSKeyValueChangeInsertion 
    190                  valuesAtIndexes: [NSIndexSet indexSetWithIndex: [plugins count]] 
    191                                   forKey:@"plugins"]; 
     256                [[self mutableArrayValueForKey:@"plugins"] 
     257                 addObject: plugin]; 
    192258        } 
    193259} 
     
    200266        if ([filesystems indexOfObject: fs] == NSNotFound) 
    201267        { 
    202                 [self willChange:NSKeyValueChangeInsertion 
    203                  valuesAtIndexes: [NSIndexSet indexSetWithIndex: [filesystems count]] 
    204                                   forKey:@"filesystems"]; 
    205                 [filesystems addObject: fs]; 
    206                 [self didChange:NSKeyValueChangeInsertion 
    207                  valuesAtIndexes: [NSIndexSet indexSetWithIndex: [filesystems count]] 
    208                                   forKey:@"filesystems"]; 
     268                [[self mutableArrayValueForKey:@"filesystems"] 
     269                 addObject: fs]; 
    209270        } 
    210271} 
     
    216277        if ([filesystems indexOfObject:fs] != NSNotFound) 
    217278        { 
    218                 [self willChange:NSKeyValueChangeRemoval 
    219                  valuesAtIndexes:[NSIndexSet indexSetWithIndex:[filesystems indexOfObject: fs]] 
    220                                   forKey:@"filesystems"]; 
    221                 [filesystems removeObject: fs]; 
    222                 [self didChange:NSKeyValueChangeRemoval 
    223                  valuesAtIndexes:[NSIndexSet indexSetWithIndex:[filesystems indexOfObject: fs]] 
    224                                  forKey:@"filesystems"]; 
     279                [[self mutableArrayValueForKey:@"filesystems"] 
     280                 removeObject: fs]; 
    225281        } 
    226282} 
     
    239295} 
    240296 
    241 - (NSArray*)plugins 
    242 { 
    243         return (NSArray*)plugins; 
    244 } 
    245  
    246 - (NSArray*)filesystems 
    247 { 
    248         return (NSArray*)filesystems; 
    249 } 
    250  
    251 @synthesize delegate; 
     297@synthesize delegate, filesystems, plugins, recents; 
    252298@end 
  • trunk/MFClientFS.m

    r14 r16  
    5858- (void)registerNotifications 
    5959{ 
    60         /* 
    61         [self addObserver:self 
    62                    forKeyPath:kMFParameterDict 
    63                           options:NSKeyValueObservingOptionNew 
    64                           context:nil]; 
    65          */ 
    6660} 
    6761 
     
    9387} 
    9488 
     89#pragma mark Notifications To Clients 
     90- (void)sendNotificationForStatusChangeFrom:(NSString*)previousStatus 
     91                                                                                 to:(NSString*)newStatus 
     92{ 
     93        NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; 
     94        if ([previousStatus isEqualToString: newStatus]) 
     95        { 
     96                // Send No Notification 
     97        } 
     98        if ([previousStatus isEqualToString: kMFStatusFSWaiting] 
     99                && [newStatus isEqualToString: kMFStatusFSMounted]) 
     100        { 
     101                [nc postNotificationName: kMFClientFSMountedNotification 
     102                                                  object:self 
     103                                                userInfo:nil]; 
     104        } 
     105        else if ([previousStatus isEqualToString: kMFStatusFSWaiting] 
     106                         && [newStatus isEqualToString: kMFStatusFSFailed]) 
     107        { 
     108                [nc postNotificationName: kMFClientFSFailedNotification 
     109                                                  object:self 
     110                                                userInfo:nil]; 
     111        } 
     112} 
     113 
    95114#pragma mark Synchronization across IPC 
    96115- (void)handleStatusInfoChangedNotification:(NSNotification*)note 
    97116{ 
     117        NSString* previousStatus = self.status; 
    98118        [self copyStatusInfo]; 
     119        NSString* newStatus = self.status; 
     120        [self sendNotificationForStatusChangeFrom:previousStatus 
     121                                                                                   to:newStatus]; 
    99122} 
    100123 
     
    143166        { 
    144167                [[NSException exceptionWithName:kMFBadAPIUsageException 
    145                                                                  reason:@"endEditing without beginEditing" 
     168                                                                 reason:@"Calling endEditing without previous call to beginEditing" 
    146169                                                           userInfo:nil] raise]; 
    147170        } 
     
    173196        if ([key isLike:@"parameters.*"] && !isEditing) 
    174197        { 
    175                 [[NSException exceptionWithName:@"MFBadAPIUsage" 
     198                [[NSException exceptionWithName:kMFBadAPIUsageException 
    176199                                                                reason:@"Trying to modify parameters without beginEditing" 
    177200                                                          userInfo:nil] raise]; 
  • trunk/MFCommunicationServer.h

    r10 r16  
    1414@interface MFCommunicationServer : NSObject <MFServerProtocol> 
    1515{ 
    16          
     16        NSError* recentError; 
    1717} 
    1818 
     
    2222- (MFPluginController*)pluginController; 
    2323- (void)startServingRunloop; 
     24- (NSError*)recentError; 
    2425 
    2526@end 
  • trunk/MFCommunicationServer.m

    r14 r16  
    6262                                                                                                   options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld 
    6363                                                                                                   context: nil]; 
     64        [[MFFilesystemController sharedController] addObserver: self 
     65                                                                                                forKeyPath: @"recents" 
     66                                                                                                   options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld 
     67                                                                                                   context: nil]; 
    6468} 
    6569 
     
    7983        if ([connection registerName:kMFDistributedObjectName] == YES) 
    8084        { 
    81                 MFLogS(self, @"Now Vending distributed object"); 
    8285        } 
    8386        else 
     
    9396                                                context:(void *)context 
    9497{ 
    95 //      MFLogS(self, @"Observe triggered on keypath %@, object %@", keyPath, object); 
    96          
     98 
    9799        // TODO: This observation method will not be called on objects added to filesystems after registerNotifications is called 
    98100        // We need to observe filesystems itself, and add/remove observations on filesystems as they appear and dissapear 
    99101        NSDistributedNotificationCenter* dnc = [NSDistributedNotificationCenter defaultCenter]; 
     102         
     103        // MFLogS(self, @"Observes: keypath %@ object %@, change %@", keyPath, object, change); 
    100104         
    101105        if ([keyPath isEqualToString:@"status"] && [object isKindOfClass: [MFFilesystem class]]) 
     
    143147                                [fs removeObserver: self 
    144148                                                forKeyPath:@"parameters"]; 
     149                                NSDictionary* userInfoDict = [NSDictionary dictionaryWithObject: [fs uuid] 
     150                                                                                                                                                forKey: KMFFSUUIDParameter ]; 
     151                                [dnc postNotificationName:kMFFilesystemRemovedNotification 
     152                                                                   object:kMFDNCObject 
     153                                                                 userInfo:userInfoDict]; 
    145154                        } 
    146155                } 
    147156        } 
    148157         
    149          
     158        if ([keyPath isEqualToString:@"recents"] && object == [MFFilesystemController sharedController]) 
     159        { 
     160                NSUInteger changeKind = [[change objectForKey: NSKeyValueChangeKindKey] intValue]; 
     161                if (changeKind == NSKeyValueChangeInsertion) 
     162                { 
     163                        NSArray*  newRecent = [change objectForKey:NSKeyValueChangeNewKey]; 
     164                        NSDictionary* userInfoDict = [NSDictionary dictionaryWithObject:[newRecent objectAtIndex:0] 
     165                                                                                                                                         forKey:kMFRecentKey]; 
     166                        [dnc postNotificationName:kMFRecentsUpdatedNotification 
     167                                                           object:kMFDNCObject 
     168                                                         userInfo:userInfoDict ]; 
     169                } 
     170        } 
     171} 
     172 
     173- (NSArray*)recents 
     174{ 
     175        return [[MFFilesystemController sharedController] recents]; 
    150176} 
    151177 
     
    185211        return [[MFFilesystemController sharedController] filesystemWithUUID:uuid]; 
    186212} 
     213 
     214- (MFServerFS*)quickMountWithURL:(NSURL*)url 
     215{ 
     216        NSError* error; 
     217        MFServerFS* fs = [[MFFilesystemController sharedController] quickMountWithURL: url error:&error]; 
     218        if (error) 
     219                recentError = error; 
     220        return fs; 
     221} 
    187222                                  
    188223 
     
    198233} 
    199234 
     235- (NSError*)recentError 
     236{ 
     237        return recentError; 
     238} 
     239 
    200240@end 
  • trunk/MFConstants.h

    r14 r16  
    4040#define kMFFilesystemAddedNotification @"org.mgorbach.macfusion.notifications.fsAdded" 
    4141#define kMFFilesystemRemovedNotification @"org.mgorbach.macfusion.notifications.fsRemoved" 
     42#define kMFRecentsUpdatedNotification @"org.mgorbach.macfusion.notifications.recentsUpdated" 
     43 
     44// Client Notifications (Non-distributed) 
     45#define kMFClientFSMountedNotification @"org.mgorbach.macfusion.mfclient.fsMounted" 
     46#define kMFClientFSUnmountedNotification @"org.mgorbach.macfusion.mfclient.fsUnmounted" 
     47#define kMFClientFSFailedNotification @"org.mgorbach.macfusion.mfclient.fsFailed" 
    4248 
    4349// IPC Object Names 
     
    4854#define kMFFilesystemNameKey @"Name" 
    4955#define kMFFilesystemStatusKey @"Status" 
     56#define kMFRecentKey @"recent" 
    5057 
    5158// Parameters Common to All FUSE Filesystems 
     
    5865#define kMFFSFilePathParameter @"File Path" 
    5966#define kMFFSPersistentParameter @"Is Persistent" 
     67#define kMFFSDescriptionParameter @"Description" 
    6068 
    6169// Status keys 
     
    7785        kMFErrorCodeDataCannotBeRead, 
    7886        kMFErrorCodeMissingParameter, 
    79         kMFErrorInvalidParameterValue 
     87        kMFErrorCodeInvalidParameterValue, 
     88        kMFErrorCodeNoPluginFound, 
     89        kMFErrorCodeMountFaliure 
    8090}; 
    8191 
  • trunk/MFError.h

    r14 r16  
    2020                                                                                        description:(NSString*)description; 
    2121 
     22+ (MFError*)errorWithErrorCode:(NSInteger)code  
     23                                   description:(NSString*)description; 
     24 
    2225@end 
  • trunk/MFError.m

    r15 r16  
    3131                                                           nil]; 
    3232        return [MFError errorWithDomain: kMFErrorDomain 
    33                                                            code:kMFErrorInvalidParameterValue 
     33                                                           code: kMFErrorCodeInvalidParameterValue 
    3434                                                   userInfo: errorDict]; 
    3535} 
     
    4848                                         paramName ]; 
    4949                } 
    50                 if ([self code] == kMFErrorInvalidParameterValue) 
     50                if ([self code] == kMFErrorCodeInvalidParameterValue) 
    5151                { 
    5252                        return [NSString stringWithFormat: @"Invalid value for %@\n%@", 
     
    5959} 
    6060 
     61+ (MFError*)errorWithErrorCode:(NSInteger)code  
     62                                   description:(NSString*)description 
     63{ 
     64        return [MFError errorWithDomain:kMFErrorDomain 
     65                                                           code:code 
     66                                                   userInfo: [NSDictionary dictionaryWithObject: description 
     67                                                                                                                                 forKey: NSLocalizedDescriptionKey ] ]; 
     68} 
     69 
    6170@end 
  • trunk/MFFSDelegateProtocol.h

    r14 r16  
    2929 
    3030- (NSString*)executablePath; 
     31- (NSArray*)urlSchemesHandled; 
    3132  
    3233@optional 
    3334- (NSDictionary*)taskEnvironmentForParameters:(NSDictionary*)parameters; 
    34  
     35- (NSDictionary*)parameterDictionaryForURL:(NSURL*)url 
     36                                                                         error:(NSError**)error; 
     37- (NSError*)errorForParameters:(NSDictionary*)parameters  
     38                                                output:(NSString*)output; 
    3539@end 
  • trunk/MFFilesystem.h

    r14 r16  
    3434- (id)valueForParameterNamed:(NSString*)paramName; 
    3535- (NSMutableDictionary*)fillParametersWithImpliedValues:(NSDictionary*)params; 
     36- (NSError*)error; 
    3637 
    3738@property(readwrite, assign) NSString* status; 
  • trunk/MFFilesystem.m

    r14 r16  
    7878        if (status) 
    7979        { 
    80                 [statusInfo setObject:status 
    81                                            forKey:kMFSTStatusKey]; 
     80                [statusInfo setObject:status forKey:kMFSTStatusKey]; 
    8281        } 
    8382}