Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
FIX the interface of GLI
Browse files Browse the repository at this point in the history
  • Loading branch information
chaos-ad committed Aug 1, 2012
1 parent 1a5c1bd commit 0460675
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -3,4 +3,5 @@ all: build
build:
javac 2>&1 src/*.java -d bin -classpath lib/protobuf-java-2.4.1.jar


generate:
protoc -I=./ --java_out=./src *.proto
8 changes: 4 additions & 4 deletions src/GLI.java
Expand Up @@ -2,11 +2,11 @@

import com.google.protobuf.ByteString;

public interface GLI {
public interface GLI {
public JOutPiqi.response init(List<String> players);
public JOutPiqi.response handle_action(String user_id, String command_name, List<ByteString> args, ByteString state);
public JOutPiqi.response handle_user_join(String user_id, ByteString state);
public JOutPiqi.response handle_user_leave(String user_id, ByteString state);
public JOutPiqi.response handle_timer(ByteString identifier, int delta, ByteString state);
public JOutPiqi.response handle_timer_complete(ByteString identifier, int delta, ByteString state);
public JOutPiqi.response handle_user_leave(String user_id, ByteString state);
public JOutPiqi.response handle_timer(String id, int delta, ByteString state);
public JOutPiqi.response handle_timer_complete(String id, int delta, ByteString state);
}
10 changes: 5 additions & 5 deletions src/GLIExample.java
Expand Up @@ -27,22 +27,22 @@ public JOutPiqi.response init(List<String> players) {
@Override
public JOutPiqi.response handle_action(String userId, String commandName,
List<ByteString> args, ByteString state) {
System.out.println("handle_action [" + commandName + "] with [" + args + "], state: ["+state.toStringUtf8() + "]");
System.out.println("handle_action [" + commandName + "] with [" + args + "], state: ["+state.toStringUtf8() + "]");
// service.buy_item_request(userId, 1, 1);
return demo().build();
}

@Override
public JOutPiqi.response handle_timer(ByteString identifier, int delta,
public JOutPiqi.response handle_timer(String id, int delta,
ByteString state) {
System.out.println("handle_timer [" + identifier.toStringUtf8() + "], delta [" + delta + "], state: [" + state.toStringUtf8() + "]");
System.out.println("handle_timer [" + id + "], delta [" + delta + "], state: [" + state.toStringUtf8() + "]");
return demo().build();
}

@Override
public JOutPiqi.response handle_timer_complete(ByteString identifier, int delta,
public JOutPiqi.response handle_timer_complete(String id, int delta,
ByteString state) {
System.out.println("handle_timer_complete [" + identifier.toStringUtf8() + "], delta [" + delta + "], state: [" + state.toStringUtf8() + "]");
System.out.println("handle_timer_complete [" + id + "], delta [" + delta + "], state: [" + state.toStringUtf8() + "]");
return demo().build();
}

Expand Down
30 changes: 15 additions & 15 deletions src/GLSProtoServer.java
Expand Up @@ -5,8 +5,8 @@
import java.net.Socket;

/**
* Waits for incoming GLSResponseProto obects. When one arrives, recreates it from
* the inputStream and prints out its state
* Waits for incoming GLSResponseProto obects. When one arrives, recreates it from
* the inputStream and prints out its state
* @author kevinparkings
*
*/
Expand All @@ -27,7 +27,7 @@ public static void main (String [] argv) throws Exception {

public void loop(){
socket = new ServerSocket(PORT);
service = new GLIService(this);
service = new GLIService(this);

while (true) {

Expand Down Expand Up @@ -58,10 +58,10 @@ public void loop(){
}

write_message(response);

os.flush();
os.close();

sock.close();
}
}
Expand All @@ -71,12 +71,12 @@ public void send_system_request(JSystemPiqi.system_request request) {
write_message(JOutPiqi.response.getBuilder().setSystem(request).build());
JInPiqi.request response = read_message();

if(response.hasSystem()){
JInPiqi.system_response system_response = packet.getSystem();
if (!system_response.hasOk()) {
throw new Exception("Received error response: message: "
+ system_response.getError().getMessage() + ", code: "
+ system_response.getError().getCode()
if(packet.hasSystem()){
JInPiqi.system_response response = packet.getSystem();
if (!response.hasOk()) {
throw new Exception("Received error response: message: "
+ response.getError().getMessage() + ", code: "
+ response.getError().getCode()
);
}
}else{
Expand All @@ -86,7 +86,7 @@ public void send_system_request(JSystemPiqi.system_request request) {
}
}

public void write_message(Object r){
public void write_message(Object r){
OutputStream os = sock.getOutputStream();

if (r != null) {
Expand All @@ -98,17 +98,17 @@ public void write_message(Object r){
}
}

public void read_message(){
public JInPiqi.request read_message(){
System.out.println ("Waiting for connections on port " + PORT);

//This waits for an incomming message
sock = ss.accept();
InputStream is = sock.getInputStream();
InputStream is = sock.getInputStream();

byte[] lb = new byte[4];
int length = 0;
//Gets the incoming data and recreates the proto object

is.read(lb, 0, 4);
length = lb[0] << 24 | lb[1] << 16 | lb[2] << 8 | lb[3] << 0;

Expand Down

0 comments on commit 0460675

Please sign in to comment.