Changeset 14

Show
Ignore:
Timestamp:
02/23/08 15:24:45 (11 months ago)
Author:
mgorbach
Message:

Many, many changes. Moving along

Location:
trunk
Files:
8 added
27 modified

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore set to
      Icon*
      *.moved-aside*
  • trunk/MFClient.h

    r12 r14  
    2121 
    2222+ (MFClient*)sharedClient; 
    23 - (void)fillInitialStatus; 
    24 - (BOOL)establishCommunication; 
     23- (BOOL)setup; 
    2524 
    2625- (NSArray*)filesystems; 
  • trunk/MFClient.m

    r12 r14  
    1313 
    1414@interface MFClient(PrivateAPI) 
    15 - (void)storeFilesystem:(MFClientFS*)fs withUUID:(NSString*)uuid; 
    16 - (void)storePlugin:(MFClientPlugin*)plugin withID:(NSString*)id; 
     15- (void)storeFilesystem:(MFClientFS*)fs; 
     16- (void)storePlugin:(MFClientPlugin*)plugin; 
    1717- (void)removeFilesystem:(MFClientFS*)fs; 
    1818@end 
     
    8585                MFClientPlugin* plugin = [[MFClientPlugin alloc] initWithRemotePlugin:  
    8686                                                                  remotePlugin]; 
    87                 [self storePlugin: plugin 
    88                                    withID: plugin.ID]; 
     87                [self storePlugin: plugin]; 
    8988        } 
    9089         
     
    9695                MFClientFS* fs = [MFClientFS clientFSWithRemoteFS: remoteFS 
    9796                                                                                         clientPlugin: plugin]; 
    98                 [self storeFilesystem: fs 
    99                                          withUUID: fs.uuid]; 
    100         } 
    101          
     97                [self storeFilesystem: fs]; 
     98        } 
    10299} 
    103100 
     
    119116} 
    120117 
     118- (BOOL)setup 
     119{ 
     120        if ([self establishCommunication]) 
     121        { 
     122                [self fillInitialStatus]; 
     123                return YES; 
     124        } 
     125         
     126        return NO; 
     127} 
     128 
    121129#pragma mark Notification handling 
    122130- (void)handleStatusChangedNotification:(NSNotification*)note 
    123131{ 
    124 //      MFLogS(self, @"Status changed in MFClient"); 
    125132        NSDictionary* info = [note userInfo]; 
    126         NSString* uuid = [info objectForKey: kMFFilesystemUUIDKey]; 
    127         MFClientFS* fs = [filesystemsDictionary objectForKey:uuid]; 
    128         if (fs) 
    129         { 
    130                 [fs handleStatusInfoChangedNotification:note]; 
    131         } 
    132          
    133         if ([delegate respondsToSelector:@selector(clientStatusChanged)]) 
    134         { 
    135                 [delegate clientStatusChanged]; 
    136         } 
     133        NSString* uuid = [info objectForKey: KMFFSUUIDParameter]; 
     134        MFClientFS* fs = [self filesystemWithUUID: uuid]; 
     135        [fs handleStatusInfoChangedNotification:note]; 
    137136} 
    138137 
     
    140139{ 
    141140        NSDictionary* info = [note userInfo]; 
    142         NSString* uuid = [info objectForKey: kMFFilesystemUUIDKey]; 
     141        NSString* uuid = [info objectForKey:  KMFFSUUIDParameter]; 
    143142        MFLogS(self, @"Filesystem Added: uuid %@", 
    144143                   uuid); 
     
    151150                 
    152151                 
    153                 [self storeFilesystem:fs 
    154                                          withUUID:uuid]; 
     152                [self storeFilesystem:fs ]; 
    155153        } 
    156154} 
     
    159157{ 
    160158        NSDictionary* info = [note userInfo]; 
    161         NSString* uuid = [info objectForKey: kMFFilesystemUUIDKey]; 
     159        NSString* uuid = [info objectForKey: KMFFSUUIDParameter]; 
    162160        MFLogS(self, @"Filesystem Deleted: uuid %@", 
    163161                   uuid); 
     
    169167- (MFClientFS*)newFilesystemWithPlugin:(MFClientPlugin*)plugin 
    170168{ 
    171         NSAssert(plugin, @"Asked to make new filesystem with nil plugin, MFClient"); 
     169        NSAssert(plugin, @"MFClient asked to make new filesystem with nil plugin"); 
    172170        id newRemoteFS = [server newFilesystemWithPluginName: plugin.ID]; 
    173171        MFClientFS* newFS = [[MFClientFS alloc] initWithRemoteFS: newRemoteFS 
    174172                                                                                                clientPlugin: plugin]; 
    175         [self storeFilesystem:newFS 
    176                                  withUUID:newFS.uuid]; 
     173        [self storeFilesystem:newFS ]; 
    177174        return newFS; 
    178175} 
     
    180177#pragma Accessors and Setters 
    181178 
    182 - (void)storePlugin:(MFClientPlugin*)plugin withID:(NSString*)id 
    183 { 
    184         NSAssert(id, @"ID null when storing plugin in MfClient"); 
    185         [pluginsDictionary setObject: plugin forKey:id]; 
     179- (void)storePlugin:(MFClientPlugin*)plugin 
     180{ 
     181        NSAssert(plugin && plugin.ID, @"plugin or ID null when storing plugin in MfClient"); 
     182        [pluginsDictionary setObject: plugin forKey: plugin.ID ]; 
    186183        if ([plugins indexOfObject: plugin] == NSNotFound) 
    187184        { 
     
    196193} 
    197194 
    198 - (void)storeFilesystem:(MFClientFS*)fs withUUID:(NSString*)uuid 
    199 { 
    200         NSAssert(fs && uuid, @"FS or UUID is nill when storing fs in MFClient"); 
     195- (void)storeFilesystem:(MFClientFS*)fs 
     196{ 
     197        NSAssert(fs && fs.uuid, @"FS or fs.uuid is nil when storing fs in MFClient"); 
    201198        [filesystemsDictionary setObject: fs 
    202                                                           forKey: uuid]; 
     199                                                          forKey: fs.uuid]; 
    203200        if ([filesystems indexOfObject: fs] == NSNotFound) 
    204201        { 
  • trunk/MFClientFS.h

    r12 r14  
    99#import <Cocoa/Cocoa.h> 
    1010#import "MFFilesystem.h" 
     11#import "MFServerFSProtocol.h" 
    1112 
    1213@class MFClientPlugin; 
    1314 
    1415@interface MFClientFS : MFFilesystem { 
    15         id remoteFilesystem; 
     16        id<MFServerFSProtocol> remoteFilesystem; 
    1617        MFClientPlugin* plugin; 
     18        NSDictionary* backupParameters; 
     19        BOOL isEditing; 
    1720} 
    1821 
     
    2932- (void)handleParametersChangedNotification:(NSNotification*)note; 
    3033 
     34// Editing 
     35- (NSError*)endEditingAndCommitChanges:(BOOL)commit; 
     36- (void)beginEditing; 
     37- (NSDictionary*)displayDictionary; 
     38 
    3139@end 
  • trunk/MFClientFS.m

    r13 r14  
    1414- (void)fillInitialData; 
    1515- (void)registerNotifications; 
     16- (void)copyParameters; 
     17- (void)copyStatusInfo; 
    1618@end 
    1719 
     
    2224{ 
    2325        MFClientFS* fs = nil; 
    24         NSBundle* bundle = plugin.bundle; 
    25         NSString* filesystemClassName = [bundle objectForInfoDictionaryKey: 
    26                                                                          @"MFClientFSClassName"]; 
    27         if (filesystemClassName == nil) 
    28         { 
    29                 MFLogS(self, @"Failed to instantiate filesystem with remote fs %@. No Client Filesystem class specified.", 
    30                            remoteFS); 
    31         } 
     26         
     27        fs = [[MFClientFS alloc] initWithRemoteFS: remoteFS 
     28                                                                 clientPlugin: plugin]; 
     29        return fs; 
     30} 
     31 
     32+ (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key 
     33{ 
     34        if ([key isEqualToString: @"displayDictionary"]) 
     35                return [NSSet setWithObjects:  
     36                                KMFStatusDict, kMFParameterDict, nil]; 
    3237        else 
    33         { 
    34                 BOOL success = [bundle load]; 
    35                 if (success) 
    36                 { 
    37                         Class filesystemClass = NSClassFromString(filesystemClassName); 
    38                         if ([filesystemClass isSubclassOfClass: [MFClientFS class]]) 
    39                         { 
    40                                 fs = [[filesystemClass alloc] initWithRemoteFS: remoteFS  
    41                                                                                                   clientPlugin: plugin]; 
    42                         } 
    43                         else 
    44                         { 
    45                                 MFLogS(self, @"Client filesystem class %@ is not a subclass of MFClientFS", 
    46                                            filesystemClass); 
    47                         } 
    48                 } 
    49         } 
    50          
    51         return fs; 
     38                return [super keyPathsForValuesAffectingValueForKey: key]; 
    5239} 
    5340 
     
    6047                remoteFilesystem = remoteFS; 
    6148                plugin = p; 
     49                delegate = [plugin delegate]; 
    6250                [self fillInitialData]; 
    6351                [self registerNotifications]; 
     
    7058- (void)registerNotifications 
    7159{ 
     60        /* 
    7261        [self addObserver:self 
    73                    forKeyPath:@"parameters" 
     62                   forKeyPath:kMFParameterDict 
    7463                          options:NSKeyValueObservingOptionNew 
    7564                          context:nil]; 
     65         */ 
     66} 
     67 
     68- (void)copyStatusInfo 
     69{ 
     70        [self willChangeValueForKey:KMFStatusDict]; 
     71        statusInfo = [[remoteFilesystem statusInfo] mutableCopy]; 
     72        NSAssert(![statusInfo isProxy], @"Status Info from DO is a Proxy. Oh shit."); 
     73        [self didChangeValueForKey:KMFStatusDict]; 
     74} 
     75 
     76- (void)copyParameters 
     77{ 
     78        [self willChangeValueForKey:kMFParameterDict]; 
     79        parameters = [[remoteFilesystem parameters] mutableCopy]; 
     80        NSAssert(![parameters isProxy], @"Parameters from DO is a Proxy. Oh shit."); 
     81        [self didChangeValueForKey:kMFParameterDict]; 
    7682} 
    7783 
    7884- (void)fillInitialData 
    7985{ 
    80         [self willChangeValueForKey:@"parameters"]; 
    81         parameters = [[remoteFilesystem parameters] mutableCopy]; 
    82         [self didChangeValueForKey:@"parameters"]; 
    83         [self willChangeValueForKey:@"statusInfo"]; 
    84         statusInfo = [[remoteFilesystem statusInfo] mutableCopy]; 
    85         [self didChangeValueForKey:@"statusInfo"]; 
     86        [self copyStatusInfo]; 
     87        [self copyParameters]; 
    8688} 
    8789 
     
    9496- (void)handleStatusInfoChangedNotification:(NSNotification*)note 
    9597{ 
    96 //      NSDictionary* info = [note userInfo]; 
    97         [self willChangeValueForKey: @"status"]; 
    98         statusInfo = [[remoteFilesystem statusInfo] mutableCopy]; 
    99         [self didChangeValueForKey: @"status"]; 
     98        [self copyStatusInfo]; 
    10099} 
    101100 
    102101- (void)handleParametersChangedNotification:(NSNotification*)note 
    103102{ 
    104          
     103        [self copyParameters]; 
    105104} 
    106105 
    107 - (void) observeValueForKeyPath:(NSString *)keyPath  
    108                                            ofObject:(id)object  
    109                                                  change:(NSDictionary *)change  
    110                                                 context:(void *)context 
     106- (NSDictionary*)displayDictionary 
    111107{ 
    112         NSLog(@"Change detected on keypath %@, object %@, change %@", 
    113                   keyPath, object, change); 
     108        NSMutableDictionary* dict = [NSMutableDictionary dictionary]; 
     109        [dict addEntriesFromDictionary: parameters]; 
     110        [dict addEntriesFromDictionary: statusInfo]; 
     111        return [dict copy]; 
    114112} 
    115113 
    116 // Hack to make sure we are notified if any parameters change 
    117 - (void)setValue:(id)value  
    118           forKeyPath:(NSString*)keyPath 
    119 { 
    120         if ([keyPath isLike:@"parameters.*"]) 
    121         { 
    122                 [self willChangeValueForKey:@"parameters"]; 
    123         } 
    124         [super setValue:value 
    125                  forKeyPath:keyPath]; 
    126         if ([keyPath isLike:@"parameters.*"]) 
    127         { 
    128                 [self didChangeValueForKey:@"parameters"]; 
    129                 [remoteFilesystem setValue:value 
    130                                                 forKeyPath:keyPath]; 
    131         } 
    132 } 
    133  
     114# pragma mark Action Methods 
    134115- (void)mount 
    135116{ 
     
    142123} 
    143124 
    144 - (NSMutableDictionary*)parameters 
     125 
     126#pragma mark Editing 
     127 
     128- (void)setParameters:(NSMutableDictionary*)p 
    145129{ 
    146         return parameters; 
     130        parameters = p; 
     131} 
     132 
     133- (void)beginEditing 
     134{ 
     135        isEditing = YES; 
     136        backupParameters = [NSDictionary dictionaryWithDictionary:  
     137                                                [self parameters]]; 
     138} 
     139 
     140- (NSError*)endEditingAndCommitChanges:(BOOL)commit 
     141{ 
     142        if (!isEditing) 
     143        { 
     144                [[NSException exceptionWithName:kMFBadAPIUsageException 
     145                                                                 reason:@"endEditing without beginEditing" 
     146                                                           userInfo:nil] raise]; 
     147        } 
     148         
     149        if (commit) 
     150        { 
     151                NSError* result = [remoteFilesystem validateAndSetParameters: parameters]; 
     152                if (result) 
     153                { 
     154                        return result; 
     155                } 
     156                else 
     157                { 
     158                        isEditing = NO; 
     159                        return nil; 
     160                } 
     161        } 
     162        else 
     163        { 
     164                isEditing = NO; 
     165                [self setParameters: [backupParameters mutableCopy] ]; 
     166        } 
     167         
     168        return nil; 
     169} 
     170 
     171- (void)willChangeValueForKey:(NSString*)key 
     172{ 
     173        if ([key isLike:@"parameters.*"] && !isEditing) 
     174        { 
     175                [[NSException exceptionWithName:@"MFBadAPIUsage" 
     176                                                                reason:@"Trying to modify parameters without beginEditing" 
     177                                                          userInfo:nil] raise]; 
     178        } 
     179         
     180        [super willChangeValueForKey:key]; 
    147181} 
    148182 
  • trunk/MFCommunicationServer.m

    r12 r14  
    9393                                                context:(void *)context 
    9494{ 
    95         MFLogS(self, @"Observe triggered on keypath %@, object %@ change %@", keyPath, object, change); 
     95//      MFLogS(self, @"Observe triggered on keypath %@, object %@", keyPath, object); 
    9696         
    9797        // TODO: This observation method will not be called on objects added to filesystems after registerNotifications is called 
     
    103103                MFFilesystem* fs = (MFFilesystem*)object; 
    104104                NSDictionary* userInfoDict = [NSDictionary dictionaryWithObjectsAndKeys:  
    105                                                                           fs.uuid, kMFFilesystemUUIDKey, 
    106                                                                           fs.status, kMFFilesystemStatusKey, 
     105                                                                          fs.uuid, KMFFSUUIDParameter, 
     106                                                                          fs.status, kMFSTStatusKey, 
    107107                                                                          nil]; 
    108108                [dnc postNotificationName:kMFStatusChangedNotification 
     
    128128 
    129129                                NSDictionary* userInfoDict = [NSDictionary dictionaryWithObject: [fs uuid] 
    130                                                                                                                                                  forKey: kMFFilesystemUUIDKey]; 
     130                                                                                                                                                 forKey: KMFFSUUIDParameter]; 
    131131                                [dnc postNotificationName:kMFFilesystemAddedNotification 
    132132                                                                   object:kMFDNCObject 
     
    171171- (MFServerFS*)newFilesystemWithPluginName:(NSString*)pluginName 
    172172{ 
     173        NSAssert(pluginName, @"MFCommunicationServer: Asked for new filesystem with nil plugin name"); 
    173174        MFServerPlugin* plugin = [[[MFPluginController sharedController] pluginsDictionary] 
    174175                                                objectForKey:pluginName]; 
    175         if (plugin) 
    176         { 
    177                 MFServerFS* fs = [[MFFilesystemController sharedController]  
     176        NSAssert(plugin, @"MFCommunicationServer: Asked for FS with invalid plugin name"); 
     177        MFServerFS* fs = [[MFFilesystemController sharedController]  
    178178                                                  newFilesystemWithPlugin: plugin]; 
    179                 return fs; 
    180         } 
    181         else 
    182         { 
    183                 MFLogS(self, @"Request failed to create new filesystem. Now plugin named %@",  
    184                            pluginName); 
    185                 return nil; 
    186         } 
     179        return fs; 
    187180} 
    188181                                  
     
    190183{ 
    191184        NSAssert(uuid, @"Filesystem requested with nil uuid in server"); 
    192         return [[MFFilesystemController sharedController]  
    193                         filesystemWithUUID:uuid]; 
     185        return [[MFFilesystemController sharedController] filesystemWithUUID:uuid]; 
    194186} 
    195187                                  
  • trunk/MFConstants.h

    r12 r14  
    99 
    1010// Status values for filesystems 
     11/* 
    1112extern NSString* kMFStatusFSMounted; 
    1213extern NSString* kMFStatusFSUnmounted; 
     
    2728extern NSString* kMFFilesystemUUIDKey; 
    2829extern NSString* kMFFilesystemStatusKey; 
     30*/ 
     31  
     32// Status 
     33#define kMFStatusFSMounted @"Mounted" 
     34#define kMFStatusFSUnmounted @"Unmounted" 
     35#define kMFStatusFSWaiting @"Waiting to Mount" 
     36#define kMFStatusFSFailed @"Failed to Mount" 
     37 
     38// IPC Distribution Notifications 
     39#define kMFStatusChangedNotification @"org.mgorbach.macfusion.notifications.statusChanged" 
     40#define kMFFilesystemAddedNotification @"org.mgorbach.macfusion.notifications.fsAdded" 
     41#define kMFFilesystemRemovedNotification @"org.mgorbach.macfusion.notifications.fsRemoved" 
     42 
     43// IPC Object Names 
     44#define kMFDNCObject @"org.mgorbach.macfusion" 
     45#define kMFDistributedObjectName @"org.mgorbach.macfusion.do" 
     46 
     47// Keys for Notifications 
     48#define kMFFilesystemNameKey @"Name" 
     49#define kMFFilesystemStatusKey @"Status" 
     50 
     51// Parameters Common to All FUSE Filesystems 
     52#define kMFFSNameParameter @"Name" 
     53#define kMFFSTypeParameter @"Type" 
     54#define kMFFSVolumeNameParameter @"Volume Name" 
     55#define kMFFSVolumeIconPathParameter @"Icon Path" 
     56#define kMFFSMountPathParameter @"Mount Path" 
     57#define KMFFSUUIDParameter @"UUID" 
     58#define kMFFSFilePathParameter @"File Path" 
     59#define kMFFSPersistentParameter @"Is Persistent" 
     60 
     61// Status keys 
     62#define KMFStatusDict @"statusInfo" 
     63#define kMFParameterDict @"parameters" 
     64 
     65#define kMFSTErrorKey @"error" 
     66#define kMFSTStatusKey @"status" 
     67#define kMFSTOutputKey @"output" 
    2968 
    3069// More key Names 
    3170#define kMFPluginShortNameKey @"MFPluginShortName" 
    3271#define kMFPluginLongNameKey @"MFPluginLongName" 
     72 
     73// Error handling 
     74#define kMFErrorDomain @"org.mgorbach.macfusion.errordomain" 
     75enum macfusionErrorCodes { 
     76        kMFErrorCodeInvalidPath, 
     77        kMFErrorCodeDataCannotBeRead, 
     78        kMFErrorCodeMissingParameter, 
     79        kMFErrorInvalidParameterValue 
     80}; 
     81 
     82#define kMFErrorParameterKey @"parameter" 
     83#define kMFErrorFilesystemKey @"filesystem" 
     84#define KMFErrorPluginKey @"plugin" 
     85#define kMFErrorValueKey @"value" 
     86 
     87// Exceptions 
     88#define kMFBadAPIUsageException @"Bad API Usage In Macfusion" 
     89 
     90 
  • trunk/MFConstants.m

    r12 r14  
    99#import "MFConstants.h" 
    1010 
     11/* 
    1112NSString* kMFStatusFSMounted = @"Mounted"; 
    1213NSString* kMFStatusFSUnmounted = @"Unmounted"; 
     
    2627NSString* kMFFilesystemStatusKey = @"status"; 
    2728NSString* kMFFilesystemUUIDKey = @"status"; 
     29 
     30*/ 
  • trunk/MFFSDelegateProtocol.h

    r12 r14  
    1313- (NSArray*)taskArgumentsForParameters:(NSDictionary*)parameters; 
    1414 
     15- (NSArray*)parameterList; 
    1516- (NSDictionary*)defaultParameterDictionary; 
    1617 
  • trunk/MFFilesystem.h

    r12 r14  
    88 
    99#import <Cocoa/Cocoa.h> 
     10#import "MFFSDelegateProtocol.h" 
     11 
    1012@class MFPlugin; 
    1113 
     
    1315        NSMutableDictionary* parameters; 
    1416        NSMutableDictionary* statusInfo; 
     17        id <MFFSDelegateProtocol> delegate; 
    1518} 
    1619 
     
    2427- (BOOL)isWaiting; 
    2528- (BOOL)isUnmounted; 
     29- (BOOL)isFailedToMount; 
     30- (BOOL)isPersistent; 
     31 
     32- (NSMutableDictionary*)parametersWithImpliedValues; 
     33- (NSArray*)parameterList; 
     34- (id)valueForParameterNamed:(NSString*)paramName; 
     35- (NSMutableDictionary*)fillParametersWithImpliedValues:(NSDictionary*)params; 
    2636 
    27</