Skip to content

Commit

Permalink
Handling buffered input from socket-logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Saikat Chakrabarti committed Sep 13, 2010
1 parent 2b5e94e commit 6ba1d6a
Showing 1 changed file with 62 additions and 42 deletions.
104 changes: 62 additions & 42 deletions AppController.j
Expand Up @@ -16,7 +16,8 @@
CPTableView openRequestsView;
CPTableColumn clientsColumn;
CPTableColumn projectsColumn;
CPScrollView scrollView;
CPScrollView clientProjectScrollView;
CPScrollView openRequestsScrollView;
JSObject clients;
}

Expand All @@ -36,23 +37,34 @@
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];

clientProjectView = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 200, 300)];
clientProjectView = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 400, 300)];

[clientProjectView setBackgroundColor:[CPColor colorWithHexString:"DDDDDD"]];
clientsColumn = [[CPTableColumn alloc] initWithIdentifier:@"clients"];
projectsColumn = [[CPTableColumn alloc] initWithIdentifier:@"projects"];
[clientProjectView setDataSource:self];
[clientProjectView setAllowsColumnReordering:YES];
[clientProjectView setAllowsColumnResizing:YES];

clientProjectScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(20, 20, 300, 400)];
clientProjectScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(20, 20, 400, 400)];
[clientProjectScrollView setAutoresizingMask:CPViewHeightSizable];
[clientProjectScrollView setAutohidesScrollers:YES];
[clientProjectScrollView setHasHorizontalScroller:YES];
[clientProjectScrollView setDocumentView:clientProjectView];

[clientProjectView addTableColumn:clientsColumn];
[clientProjectView addTableColumn:projectsColumn];

openRequestsView = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 800, 500)];
[openRequestsView setBackgroundColor:[CPColor colorWithHexString:"DDDDDD"]];
openRequestsScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(440, 20, 800, 500)];
[openRequestsScrollView setAutoresizingMask:CPViewHeightSizable];
[openRequestsScrollView setAutohidesScrollers:YES];
[openRequestsScrollView setHasHorizontalScroller:YES];
[openRequestsScrollView setDocumentView:openRequestsView];

[contentView addSubview:clientProjectScrollView];
[contentView addSubview:openRequestsScrollView];
[theWindow orderFront:self];
}

Expand All @@ -63,26 +75,29 @@

- (void)tableView:(CPTableView)aView objectValueForTableColumn:(unsigned)aColumn row:(unsigned)aRow
{
var count = 0;
var obj = nil;
for (key in clients)
if (clients.hasOwnProperty(key))
{
if (count != aRow)
count++;
else
if (aView === clientProjectView)
{
var count = 0;
var obj = nil;
for (key in clients)
if (clients.hasOwnProperty(key))
{
obj = {"client" : key,
"project" : clients[key]};
break;
}
};
if (count != aRow)
count++;
else
{
obj = {"client" : key,
"project" : clients[key]};
break;
}
};

if ([aColumn identifier] === 'clients')
return obj.client;
if ([aColumn identifier] === 'clients')
return obj.client;

if ([aColumn identifier] === 'projects')
return obj.project;
if ([aColumn identifier] === 'projects')
return obj.project;
}
}

- (void)refresh
Expand All @@ -94,36 +109,41 @@
[[clientsColumn headerView] setStringValue:"Clients (" + Object.keys(clients).length + ")"];
[[projectsColumn headerView] setStringValue:"Projects (" + projectCount + ")"];
[clientProjectView reloadData];
setTimeout(function() {[self refresh]}, 500);
}

- (void)socket:(SCSocket)aSocket didReceiveMessage:(CPString)aMessage
- (void)socket:(SCSocket)aSocket didReceiveMessage:(JSObject)aMessage
{
if (aMessage.init)
{
var allClients = aMessage.clients;
var count = allClients.length;
for (var i = 0; i < count; ++i)
clients[allClients[i]] = nil;
[self refresh];
}
else
var count = aMessage.length;
for (var i = 0; i < count; ++i)
{
if (aMessage[1] === "connect")
clients[aMessage[2]] = nil;
else if (aMessage[1] === "disconnect")
var theAction = aMessage[i];
if (theAction.init)
{
for (key in clients)
{
if (clients.hasOwnProperty(key) && key === aMessage[2])
delete clients[key];
}
var allClients = theAction.clients;
var count = allClients.length;
for (var i = 0; i < count; ++i)
clients[allClients[i]] = nil;
[self refresh];
}
else if (aMessage[1] === "message")
else
{
if (aMessage[3][1] == "subscribe" || aMessage[3][1] === "update")
clients[aMessage[2]] = aMessage[3][2];
if (theAction[1] === "connect")
clients[theAction[2]] = nil;
else if (theAction[1] === "disconnect")
{
for (key in clients)
{
if (clients.hasOwnProperty(key) && key === theAction[2])
delete clients[key];
}
}
else if (theAction[1] === "message")
{
if (theAction[3][1] == "subscribe" || theAction[3][1] === "update")
clients[theAction[2]] = theAction[3][2];
}
}
}
[self refresh];
}
@end

0 comments on commit 6ba1d6a

Please sign in to comment.