From a5440bd52d80ac927fdafedece99d6152674729e Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 31 May 2011 03:39:36 +0000 Subject: [PATCH] Monotone-Parent: 173c16ed57e319da55ef0f43152bfbba829d1119 Monotone-Revision: ea1c783b905b07e028051a8a9d8f7bf4c894b0f2 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-05-31T03:39:36 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 18 +++ OpenChange/GNUmakefile | 1 + OpenChange/MAPIStoreActiveTables.h | 47 +++++++ OpenChange/MAPIStoreActiveTables.m | 198 +++++++++++++++++++++++++++++ OpenChange/MAPIStoreFolder.m | 62 +++------ OpenChange/MAPIStoreObject.h | 2 - OpenChange/MAPIStoreObject.m | 8 -- OpenChange/MAPIStoreSOGo.m | 8 -- OpenChange/MAPIStoreTable.h | 5 +- OpenChange/MAPIStoreTable.m | 20 ++- 10 files changed, 299 insertions(+), 70 deletions(-) create mode 100644 OpenChange/MAPIStoreActiveTables.h create mode 100644 OpenChange/MAPIStoreActiveTables.m diff --git a/ChangeLog b/ChangeLog index f821b20f2..340fa6e9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2011-05-31 Wolfgang Sourdeau + + * OpenChange/MAPIStoreTable.m: (-deactivate): removed obsolete + method, which was part of a hack anyway. + + * OpenChange/MAPIStoreObject.m: (-addActiveTable:) + (-removeActiveTable:) removed obsolete methods. + + * OpenChange/MAPIStoreFolder.m: (-init) removed obsolete ivars + "activeMessageTables", "activeFAIMessageTables" and "activeFolderTables". + (-activeMessageTables, -activeFAIMessageTables) + (-activeFolderTables, _cleanupTableCaches): make use of the new + MAPIStoreActiveTables class. + + * OpenChange/MAPIStoreActiveTables.[hm]: new class module that + provides a facility for keeping track of all the instantiated + tables. + 2011-05-30 Wolfgang Sourdeau * OpenChange/code-MAPIStorePropertySelectors.m diff --git a/OpenChange/GNUmakefile b/OpenChange/GNUmakefile index c7a7efe9b..d7b073764 100644 --- a/OpenChange/GNUmakefile +++ b/OpenChange/GNUmakefile @@ -27,6 +27,7 @@ $(SOGOBACKEND)_PRINCIPAL_CLASS = MAPIApplication $(SOGOBACKEND)_OBJC_FILES += \ MAPIApplication.m \ + MAPIStoreActiveTables.m \ MAPIStoreAuthenticator.m \ MAPIStoreMapping.m \ MAPIStoreTypes.m \ diff --git a/OpenChange/MAPIStoreActiveTables.h b/OpenChange/MAPIStoreActiveTables.h new file mode 100644 index 000000000..106e73b1e --- /dev/null +++ b/OpenChange/MAPIStoreActiveTables.h @@ -0,0 +1,47 @@ +/* MAPIStoreActiveTables.h - this file is part of SOGo + * + * Copyright (C) 2011 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef MAPISTOREACTIVETABLES_H +#define MAPISTOREACTIVETABLES_H + +#import + +@class NSMutableArray; + +@class MAPIStoreTable; + +@interface MAPIStoreActiveTables : NSObject +{ + NSMutableArray *records; +} + ++ (id) activeTables; + +- (void) registerTable: (MAPIStoreTable *) table; +- (void) unregisterTable: (MAPIStoreTable *) table; + +- (NSArray *) activeTablesForFMID: (uint64_t) fmid + andType: (uint8_t) tableType; + +@end + +#endif /* MAPISTOREACTIVETABLES_H */ diff --git a/OpenChange/MAPIStoreActiveTables.m b/OpenChange/MAPIStoreActiveTables.m new file mode 100644 index 000000000..d72a62f02 --- /dev/null +++ b/OpenChange/MAPIStoreActiveTables.m @@ -0,0 +1,198 @@ +/* MAPIStoreActiveTables.m - this file is part of SOGo + * + * Copyright (C) 2011 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* MAPIStoreActiveTables provides an interface to keep accounting of all + instances of a given table, independently from its store and context. + Primary useful for notifications across different connections. */ + +#import +#import + +#import "MAPIStoreFolder.h" +#import "MAPIStoreTable.h" + +#import "MAPIStoreActiveTables.h" + +@interface MAPIStoreActiveTableRecord : NSObject +{ + uint64_t folderId; + uint8_t tableType; + MAPIStoreTable *table; +} + ++ (id) recordForTable: (MAPIStoreTable *) newTable; +- (id) initWithTable: (MAPIStoreTable *) newTable; + +- (MAPIStoreTable *) table; + +- (BOOL) exactlyMatchesTable: (MAPIStoreTable *) otherTable; +- (BOOL) matchesFMID: (uint64_t) otherFMid + andTableType: (uint8_t) otherTableType; +- (BOOL) matchesTable: (MAPIStoreTable *) otherTable; + +@end + +@implementation MAPIStoreActiveTableRecord : NSObject + ++ (id) recordForTable: (MAPIStoreTable *) newTable +{ + MAPIStoreActiveTableRecord *record; + + record = [[self alloc] initWithTable: newTable]; + [record autorelease]; + + return record; +} + +- (id) init +{ + if ((self = [super init])) + { + folderId = 0; + tableType = 0; + table = nil; + } + + return self; +} + +- (id) initWithTable: (MAPIStoreTable *) newTable +{ + if ((self = [self init])) + { + table = newTable; + folderId = [[table container] objectId]; + tableType = [table tableType]; + } + + return self; +} + +- (MAPIStoreTable *) table +{ + return table; +} + +- (BOOL) exactlyMatchesTable: (MAPIStoreTable *) otherTable +{ + return (table == otherTable); +} + +- (BOOL) matchesFMID: (uint64_t) otherFMid + andTableType: (uint8_t) otherTableType +{ + return (tableType == otherTableType + && folderId == otherFMid); +} + +- (BOOL) matchesTable: (MAPIStoreTable *) otherTable +{ + uint64_t otherFMid; + BOOL rc; + + rc = [self exactlyMatchesTable: otherTable]; + if (!rc) + { + otherFMid = [[otherTable container] objectId]; + rc = [self matchesFMID: otherFMid andTableType: [otherTable tableType]]; + } + + return rc; +} + +@end + +@implementation MAPIStoreActiveTables + ++ (id) activeTables +{ + static MAPIStoreActiveTables *activeTables = nil; + + if (!activeTables) + activeTables = [self new]; + + return activeTables; +} + +- (id) init +{ + if ((self = [super init])) + { + records = [NSMutableArray new]; + } + + return self; +} + +- (void) dealloc +{ + [records release]; + [super dealloc]; +} + +- (void) registerTable: (MAPIStoreTable *) table +{ + MAPIStoreActiveTableRecord *newRecord; + + newRecord = [MAPIStoreActiveTableRecord recordForTable: table]; + [records addObject: newRecord]; +} + +- (void) unregisterTable: (MAPIStoreTable *) table +{ + MAPIStoreActiveTableRecord *currentRecord; + NSUInteger count, max; + BOOL done = NO; + + max = [records count]; + for (count = 0; !done && count < max; count++) + { + currentRecord = [records objectAtIndex: count]; + if ([currentRecord exactlyMatchesTable: table]) + { + [records removeObject: currentRecord]; + done = YES; + } + } +} + +- (NSArray *) activeTablesForFMID: (uint64_t) fmid + andType: (uint8_t) tableType +{ + NSUInteger count, max; + NSMutableArray *tables; + MAPIStoreActiveTableRecord *currentRecord; + + tables = [NSMutableArray arrayWithCapacity: 5]; + + max = [records count]; + for (count = 0; count < max; count++) + { + currentRecord = [records objectAtIndex: count]; + if ([currentRecord matchesFMID: fmid andTableType: tableType]) + [tables addObject: [currentRecord table]]; + } + + return tables; +} + +@end diff --git a/OpenChange/MAPIStoreFolder.m b/OpenChange/MAPIStoreFolder.m index 903b7082d..8e8739009 100644 --- a/OpenChange/MAPIStoreFolder.m +++ b/OpenChange/MAPIStoreFolder.m @@ -29,6 +29,7 @@ #import #import +#import "MAPIStoreActiveTables.h" #import "MAPIStoreContext.h" #import "MAPIStoreFAIMessage.h" #import "MAPIStoreFAIMessageTable.h" @@ -80,9 +81,6 @@ Class NSExceptionK, MAPIStoreMessageTableK, MAPIStoreFAIMessageTableK, MAPIStore folderURL = nil; context = nil; - activeMessageTables = [NSMutableArray new]; - activeFAIMessageTables = [NSMutableArray new]; - activeFolderTables = [NSMutableArray new]; } return self; @@ -110,9 +108,6 @@ Class NSExceptionK, MAPIStoreMessageTableK, MAPIStoreFAIMessageTableK, MAPIStore [faiMessageKeys release]; [folderKeys release]; [faiFolder release]; - [activeMessageTables release]; - [activeFAIMessageTables release]; - [activeFolderTables release]; [super dealloc]; } @@ -165,59 +160,36 @@ Class NSExceptionK, MAPIStoreMessageTableK, MAPIStoreFAIMessageTableK, MAPIStore - (NSArray *) activeMessageTables { - return activeMessageTables; + return [[MAPIStoreActiveTables activeTables] + activeTablesForFMID: [self objectId] + andType: MAPISTORE_MESSAGE_TABLE]; } - (NSArray *) activeFAIMessageTables { - return activeFAIMessageTables; + return [[MAPIStoreActiveTables activeTables] + activeTablesForFMID: [self objectId] + andType: MAPISTORE_FAI_TABLE]; } -- (NSArray *) activeFolderTables -{ - return activeFolderTables; -} - -- (NSMutableArray *) _arrayForActiveTable: (MAPIStoreTable *) activeTable -{ - NSMutableArray *tablesArray; - - if ([activeTable isKindOfClass: MAPIStoreFAIMessageTableK]) - tablesArray = activeMessageTables; - else if ([activeTable isKindOfClass: MAPIStoreMessageTableK]) - tablesArray = activeMessageTables; - else if ([activeTable isKindOfClass: MAPIStoreFolderTableK]) - tablesArray = activeMessageTables; - else - tablesArray = nil; - - return tablesArray; -} - -- (void) addActiveTable: (MAPIStoreTable *) activeTable -{ - [[self _arrayForActiveTable: activeTable] addObject: activeTable]; -} - -- (void) removeActiveTable: (MAPIStoreTable *) activeTable -{ - [[self _arrayForActiveTable: activeTable] removeObject: activeTable]; -} - -- (void) _cleanupTableCaches: (NSArray *) activeTables +- (void) _cleanupTableCaches: (uint8_t) tableType { + NSArray *tables; NSUInteger count, max; - max = [activeTables count]; + tables = [[MAPIStoreActiveTables activeTables] + activeTablesForFMID: [self objectId] + andType: tableType]; + max = [tables count]; for (count = 0; count < max; count++) - [[activeTables objectAtIndex: count] cleanupCaches]; + [[tables objectAtIndex: count] cleanupCaches]; } - (void) cleanupCaches { - [self _cleanupTableCaches: activeMessageTables]; - [self _cleanupTableCaches: activeFAIMessageTables]; - [self _cleanupTableCaches: activeFolderTables]; + [self _cleanupTableCaches: MAPISTORE_MESSAGE_TABLE]; + [self _cleanupTableCaches: MAPISTORE_FAI_TABLE]; + [self _cleanupTableCaches: MAPISTORE_FOLDER_TABLE]; [faiMessageKeys release]; faiMessageKeys = nil; [messageKeys release]; diff --git a/OpenChange/MAPIStoreObject.h b/OpenChange/MAPIStoreObject.h index 1c1e07f6a..19307dd11 100644 --- a/OpenChange/MAPIStoreObject.h +++ b/OpenChange/MAPIStoreObject.h @@ -69,8 +69,6 @@ - (uint64_t) objectId; - (NSString *) url; -- (void) addActiveTable: (MAPIStoreTable *) activeTable; -- (void) removeActiveTable: (MAPIStoreTable *) activeTable; /* properties */ diff --git a/OpenChange/MAPIStoreObject.m b/OpenChange/MAPIStoreObject.m index f97014007..2cd260d20 100644 --- a/OpenChange/MAPIStoreObject.m +++ b/OpenChange/MAPIStoreObject.m @@ -188,15 +188,7 @@ static Class NSExceptionK, MAPIStoreFolderK; containerURL, [self nameInContainer]]; } -- (void) addActiveTable: (MAPIStoreTable *) activeTable -{ - [self subclassResponsibility: _cmd]; -} -- (void) removeActiveTable: (MAPIStoreTable *) activeTable -{ - [self subclassResponsibility: _cmd]; -} - (void) addNewProperties: (NSDictionary *) newNewProperties { diff --git a/OpenChange/MAPIStoreSOGo.m b/OpenChange/MAPIStoreSOGo.m index f9973c3a8..e9c74d65c 100644 --- a/OpenChange/MAPIStoreSOGo.m +++ b/OpenChange/MAPIStoreSOGo.m @@ -45,12 +45,6 @@ #include #include -@interface MAPIStoreObject (MAPIStoreObjectProtocol) - -- (void) deactivate; - -@end - /** \details Initialize sogo mapistore backend @@ -1164,8 +1158,6 @@ sogo_pocop_release (void *object) if (propObject) { pool = [NSAutoreleasePool new]; - if ([propObject respondsToSelector: @selector (deactivate)]) - [propObject deactivate]; [propObject release]; [pool release]; rc = MAPI_E_SUCCESS; diff --git a/OpenChange/MAPIStoreTable.h b/OpenChange/MAPIStoreTable.h index cf199c1ef..75eb321a7 100644 --- a/OpenChange/MAPIStoreTable.h +++ b/OpenChange/MAPIStoreTable.h @@ -60,7 +60,7 @@ typedef enum { uint32_t currentRow; MAPIStoreObject *currentChild; - uint16_t tableType; /* mapistore */ + uint8_t tableType; /* mapistore */ /* proof of concept */ uint16_t columnsCount; @@ -72,6 +72,9 @@ typedef enum { - (id) initForContainer: (MAPIStoreObject *) newContainer; +- (id) container; +- (uint8_t) tableType; + - (void) setHandleId: (uint32_t) newHandleId; - (NSArray *) childKeys; diff --git a/OpenChange/MAPIStoreTable.m b/OpenChange/MAPIStoreTable.m index 210e4b3e0..bf985a442 100644 --- a/OpenChange/MAPIStoreTable.m +++ b/OpenChange/MAPIStoreTable.m @@ -26,6 +26,7 @@ #import #import "EOBitmaskQualifier.h" +#import "MAPIStoreActiveTables.h" #import "MAPIStoreObject.h" #import "MAPIStoreTypes.h" #import "NSData+MAPIStore.h" @@ -295,19 +296,16 @@ static Class NSDataK, NSStringK; if ((self = [self init])) { container = newContainer; - [container addActiveTable: self]; + [[MAPIStoreActiveTables activeTables] registerTable: self]; } return self; } -- (void) deactivate -{ - [container removeActiveTable: self]; -} - - (void) dealloc { + if (container) + [[MAPIStoreActiveTables activeTables] unregisterTable: self]; [currentChild release]; [childKeys release]; [restrictedChildKeys release]; @@ -315,6 +313,16 @@ static Class NSDataK, NSStringK; [super dealloc]; } +- (id) container +{ + return container; +} + +- (uint8_t) tableType +{ + return tableType; +} + - (void) setHandleId: (uint32_t) newHandleId { handleId = newHandleId;