-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- code to parse and dispatch commands added - ResponseWriter utility class added - Password command implementation added Several bugfixes - wakelock added - preferences properly loaded (first start) - rebinding removed
- Loading branch information
Lukas Vacek
committed
Feb 25, 2015
1 parent
f1fff1d
commit 9e49237
Showing
11 changed files
with
272 additions
and
54 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/src/main/java/github/luv/mockgeofix/CommandDispatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package github.luv.mockgeofix; | ||
|
||
import android.content.Context; | ||
import android.util.Log; | ||
|
||
import java.nio.channels.SocketChannel; | ||
|
||
import github.luv.mockgeofix.command.PasswordCommand; | ||
import github.luv.mockgeofix.util.ResponseWriter; | ||
|
||
public class CommandDispatcher { | ||
String TAG = "CommandDispatcher"; | ||
|
||
static private CommandDispatcher instance = new CommandDispatcher(); | ||
static public CommandDispatcher getInstance() { return instance; } | ||
private CommandDispatcher() {} | ||
|
||
protected Context mContext; | ||
protected PasswordCommand passwordCommand; | ||
|
||
static public void init(Context context) { | ||
getInstance()._init(context); | ||
} | ||
|
||
static public void dispatch(SocketChannel client, String command) { | ||
getInstance()._verifyInitiated(); | ||
getInstance()._dispatch(client, command); | ||
} | ||
|
||
protected void _init(Context context) { | ||
if (mContext != null) { | ||
throw new AssertionError("CommandDispatcher.init called twice!"); | ||
} | ||
mContext = context; | ||
passwordCommand = new PasswordCommand(context); | ||
} | ||
|
||
protected void _dispatch(SocketChannel client, String command) { | ||
String cmd = command.split(" ", 2)[0].toLowerCase(); | ||
if (cmd.equals("password")) { | ||
passwordCommand.execute(client, command); | ||
} else if (cmd.equals("geo")) { | ||
if ( passwordCommand.passwordRequired() && (! passwordCommand.loggedIn(client)) ) { | ||
ResponseWriter.notLoggedIn(client); | ||
} else { | ||
Log.i(TAG, "GEO FIX::" + command); | ||
} | ||
} else if (cmd.equals("help")) { | ||
Log.i(TAG, "GEO HELP::" + command); | ||
} else { | ||
ResponseWriter.unknownCommand(client); | ||
} | ||
} | ||
|
||
private void _verifyInitiated() { | ||
if (mContext == null) { | ||
throw new AssertionError("CommandDispatcher.init has not been called!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package github.luv.mockgeofix.command; | ||
|
||
import java.nio.channels.SocketChannel; | ||
|
||
public interface Command { | ||
public void execute(SocketChannel client, String command); | ||
} |
Oops, something went wrong.