private void serverMessageLoop()
{
while (mRunning)
{
Message message = mServerInBox.waitForMessage();
if ("ClientConnectionCreated".equals(message.getMessage()))
{
// Get connection object.
ClientConnection connection = (ClientConnection) message.getObject();
// Inform user that a new connection is opened.
mMainWindow.showMessage("Client connected: " + connection.getHostName());
// Add connection.
mClientConnections.add(connection);
// Start connection thread.
connection.start();
}
else if ("ClientConnectionClosed".equals(message.getMessage()))
{
ClientConnection connection = (ClientConnection) message.getObject();
mClientConnections.remove(connection);
// Inform user that a client connection is closed.
mMainWindow.showMessage("Client has disconnected: " + connection.getHostName());
}
else if ("CommandEvalLua".equals(message.getMessage()))
{
for (ClientConnection connection : mClientConnections)
{
connection.postMessage(
new Message("CommandEvalLua", message.getObject()));
}
}
else if ("CommandSendFile".equals(message.getMessage()))
{
File file = (File) message.getObject();
String filePath = FileData.unixPath(file);
//String rootPath = FileData.basePath(filePath);
Log.i("CommandSendFile");
Log.i("filePath: " + filePath);
//Log.i("rootPath: " + rootPath);
// Collect files (we may have a directory).
ArrayList<String> files = new FileWalker().collectFiles(filePath);
mMainWindow.showMessage("Sending " + files.size() + " file(s)");
Log.i("Number of files to send: " + files.size());
// Send update message.
for (ClientConnection connection : mClientConnections)
{
//Log.i("Sending CommandSendFile to client connection: " + connection);
connection.postMessage(
new Message(
"CommandSendFile",
new FileData(filePath, files)));
}
}
// CommandResetClient not used for now.
else if ("CommandResetClient".equals(message.getMessage()))
{
for (ClientConnection connection : mClientConnections)
{
connection.postMessage(
new Message("CommandResetClient", message.getObject()));
}
}
else if ("MessageFromClient".equals(message.getMessage()))
{
mMainWindow.showMessage(message.getObject().toString());
}
else if ("CommandServerStop".equals(message.getMessage()))
{
stopServer();
}
// TODO: How is this used?
else if("ServerAddressReceived".equals(message.getMessage()))
{
Log.i("ServerAddressReceived: " + message.getObject());
mMainWindow.showMessage(message.getObject().toString());
}
/*
else if ("CommandRun".equals(message.getMessage()))
{
File runFile = (File) message.getObject();