[OGo-Developer] stuffing an NSArray into a NSMutableDictionary
Sebastian Reitenbach
developer@opengroupware.org
Tue, 17 Apr 2007 10:23:15 +0200
Hi,
I did not got it working as I wanted to work. I faked the array creation so
that at least an array containing one object as I want it to be, is created.
it is here in the last patch to this enhancement request:
http://bugzilla.opengroupware.org/bugzilla/show_bug.cgi?id=1864
in OGoAsteriskCommands.m in -getQueues:
- (NSArray *)getQueues {
NSException *exc;
if ((exc = [self sendCommand:@"QueueStatus"
withParameters:nil
expectResult:[[[self asteriskCommands]
objectForKey:@"QueueStatus"] objectForKey:@"ExpectedResult"]])) {
ASSIGN(self->lastException, exc);
return nil;
}
else {
/* need to sort the output in multiple */
NSEnumerator *e;
NSMutableDictionary *queuesdict;
NSMutableArray *membersarray;
id event;
queuesdict = [[NSMutableDictionary alloc] init];
membersarray = [[NSMutableArray alloc] init];
e = [self->multipleReturn objectEnumerator];
while ((event = [e nextObject])) {
if ([[event objectForKey:@"Event"] hasSuffix:@" QueueParams"]) {
/* the queue description, their parameters */
NSEnumerator *f;
NSEnumerator *g;
id line;
id value;
f = [event keyEnumerator];
g = [event objectEnumerator];
while ((line = [f nextObject]) && (value = [g nextObject])) {
[queuesdict takeValue:value forKey:line];
}
} else {
/* queue members */
[membersarray addObject:event];
}
}
[queuesdict takeValue:[membersarray copy] forKey:@"Agents"];
NSMutableArray *tmparray;
tmparray = [[NSMutableArray alloc] init];
[tmparray addObject:queuesdict];
[self->multipleReturn removeAllObjects];
ASSIGN(self->multipleReturn, [tmparray copy]);;
}
return self->multipleReturn;
}
in the beginning of getQueues, the array self->multipleReturn is set via the
[self sendCommand:@"QueueStatus" ...
As the slf->multipleReturn contains an unordered list of objects, mixed up
information about queues and their agents, I want to make it more ordered so
that it looks like this:
queues = (
{
queue = "queuename";
servicelevel = "servicelevel";
value = "key";
Agents = (
location = "101";
blah = "plonk";
);
},
{
another queue...
}
)
my initial plan was to enumerate over the self->multipleReturn array, stuff
everything into a dictionary, and then put the dictionary into an array.
NSMutableDictionary queuesdict;
queuesdict = [[NSMutableDictionary alloc] init];
e = [self->multipleReturn objectEnumerator];
while ((event = [e nextObject])) {
if ([[event objectForKey:@"Event"] hasSuffix:@" QueueParams"]) {
/* the queue description, their parameters */
[queuesdict addObject:event forKey:[event objectForKey:@"Queue"]];
} else {
/* queue members */
[[queuesdict objectForKey:[event objectForKey:@"Queue"]
objectForKey:@"Agents"] addObject:event];
[membersarray addObject:event];
}
}
but I am unable to get the Agents stuffed into the dictionary. I do not get
error messages, nothing, it just does not add the Agents to the Dictionary.
It seems I do not yet understand completely how Mutable dictionaries or
arrays are supposed to work.
Any more insights are highly appreciated.
kind regards
Sebastian