diff options
4 files changed, 34 insertions, 3 deletions
diff --git a/same-android/src/main/java/com/orbekk/same/SameService.java b/same-android/src/main/java/com/orbekk/same/SameService.java index 386b9b8..9662d6f 100644 --- a/same-android/src/main/java/com/orbekk/same/SameService.java +++ b/same-android/src/main/java/com/orbekk/same/SameService.java @@ -29,6 +29,7 @@ public class SameService extends Service { public final static int UPDATED_STATE_MESSAGE = 5; public final static int ADD_STATE_RECEIVER = 6; public final static int REMOVE_STATE_RECEIVER = 7; + public final static int SET_STATE = 8; public final static String AVAILABLE_NETWORKS_UPDATE = "com.orbekk.same.SameService.action.AVAILABLE_NETWORKS_UPDATE"; @@ -110,6 +111,16 @@ public class SameService extends Service { Messenger droppedMessenger = (Messenger)message.obj; stateReceivers.remove(droppedMessenger); break; + case SET_STATE: + // TODO: Respond to the callee somehow. + State.Component updatedComponent = + (State.Component)message.obj; + try { + sameController.getClient().getInterface().set( + updatedComponent); + } catch (UpdateConflict e) { + logger.info("Update failed: {}", updatedComponent); + } default: super.handleMessage(message); } diff --git a/same-android/src/main/java/com/orbekk/same/android/ClientInterfaceBridge.java b/same-android/src/main/java/com/orbekk/same/android/ClientInterfaceBridge.java index 662816b..cbfeff3 100644 --- a/same-android/src/main/java/com/orbekk/same/android/ClientInterfaceBridge.java +++ b/same-android/src/main/java/com/orbekk/same/android/ClientInterfaceBridge.java @@ -18,6 +18,7 @@ import android.os.RemoteException; import com.orbekk.same.ClientInterface; import com.orbekk.same.SameService; import com.orbekk.same.State; +import com.orbekk.same.State.Component; import com.orbekk.same.StateChangedListener; import com.orbekk.same.UpdateConflict; import com.orbekk.same.VariableFactory; @@ -113,9 +114,19 @@ public class ClientInterfaceBridge implements ClientInterface { @Override public void set(String name, String data, long revision) throws UpdateConflict { - logger.info("set({}, {}, {}", - new Object[]{name, data, revision}); - throw new RuntimeException("Not implemented."); + set(new Component(name, revision, data)); + } + + @Override + public void set(Component component) throws UpdateConflict { + Message message = Message.obtain(null, SameService.SET_STATE); + message.obj = component; + try { + serviceMessenger.send(message); + } catch (RemoteException e) { + e.printStackTrace(); + throw new UpdateConflict(e.getMessage()); + } } @Override @@ -131,4 +142,5 @@ public class ClientInterfaceBridge implements ClientInterface { public VariableFactory createVariableFactory() { return VariableFactory.create(this); } + } diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java index 244a64d..b496aac 100644 --- a/same/src/main/java/com/orbekk/same/Client.java +++ b/same/src/main/java/com/orbekk/same/Client.java @@ -9,6 +9,7 @@ import org.codehaus.jackson.type.TypeReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.orbekk.same.State.Component; import com.orbekk.util.WorkQueue; public class Client implements DiscoveryListener { @@ -50,6 +51,12 @@ public class Client implements DiscoveryListener { } @Override + public void set(Component component) throws UpdateConflict { + set(component.getName(), component.getData(), + component.getRevision()); + } + + @Override public void addStateListener(StateChangedListener listener) { stateListeners.add(listener); } diff --git a/same/src/main/java/com/orbekk/same/ClientInterface.java b/same/src/main/java/com/orbekk/same/ClientInterface.java index 99adf21..4b4c731 100644 --- a/same/src/main/java/com/orbekk/same/ClientInterface.java +++ b/same/src/main/java/com/orbekk/same/ClientInterface.java @@ -3,6 +3,7 @@ package com.orbekk.same; public interface ClientInterface { State getState(); void set(String name, String data, long revision) throws UpdateConflict; + void set(State.Component component) throws UpdateConflict; void addStateListener(StateChangedListener listener); void removeStateListener(StateChangedListener listener); }
\ No newline at end of file |