Monotone-Parent: 173c16ed57e319da55ef0f43152bfbba829d1119

Monotone-Revision: ea1c783b905b07e028051a8a9d8f7bf4c894b0f2

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2011-05-31T03:39:36
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2011-05-31 03:39:36 +00:00
parent 0c99e04252
commit a5440bd52d
10 changed files with 299 additions and 70 deletions

View File

@@ -1,3 +1,21 @@
2011-05-31 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* 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 <wsourdeau@inverse.ca>
* OpenChange/code-MAPIStorePropertySelectors.m

View File

@@ -27,6 +27,7 @@ $(SOGOBACKEND)_PRINCIPAL_CLASS = MAPIApplication
$(SOGOBACKEND)_OBJC_FILES += \
MAPIApplication.m \
MAPIStoreActiveTables.m \
MAPIStoreAuthenticator.m \
MAPIStoreMapping.m \
MAPIStoreTypes.m \

View File

@@ -0,0 +1,47 @@
/* MAPIStoreActiveTables.h - this file is part of SOGo
*
* Copyright (C) 2011 Inverse inc
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
* 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 <Foundation/NSObject.h>
@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 */

View File

@@ -0,0 +1,198 @@
/* MAPIStoreActiveTables.m - this file is part of SOGo
*
* Copyright (C) 2011 Inverse inc
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
* 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 <Foundation/NSArray.h>
#import <Foundation/NSString.h>
#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

View File

@@ -29,6 +29,7 @@
#import <NGExtensions/NSObject+Logs.h>
#import <SOGo/SOGoFolder.h>
#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];

View File

@@ -69,8 +69,6 @@
- (uint64_t) objectId;
- (NSString *) url;
- (void) addActiveTable: (MAPIStoreTable *) activeTable;
- (void) removeActiveTable: (MAPIStoreTable *) activeTable;
/* properties */

View File

@@ -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
{

View File

@@ -45,12 +45,6 @@
#include <mapistore/mapistore.h>
#include <mapistore/mapistore_errors.h>
@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;

View File

@@ -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;

View File

@@ -26,6 +26,7 @@
#import <EOControl/EOQualifier.h>
#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;