1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.support.renderingcontrol.callback;
17
18 import org.fourthline.cling.controlpoint.ActionCallback;
19 import org.fourthline.cling.model.action.ActionException;
20 import org.fourthline.cling.model.action.ActionInvocation;
21 import org.fourthline.cling.model.meta.Service;
22 import org.fourthline.cling.model.types.ErrorCode;
23 import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
24 import org.fourthline.cling.support.model.Channel;
25
26 import java.util.logging.Logger;
27
28
29
30
31
32 public abstract class GetVolume extends ActionCallback {
33
34 private static Logger log = Logger.getLogger(GetVolume.class.getName());
35
36 public GetVolume(Service service) {
37 this(new UnsignedIntegerFourBytes(0), service);
38 }
39
40 public GetVolume(UnsignedIntegerFourBytes instanceId, Service service) {
41 super(new ActionInvocation(service.getAction("GetVolume")));
42 getActionInvocation().setInput("InstanceID", instanceId);
43 getActionInvocation().setInput("Channel", Channel.Master.toString());
44 }
45
46 public void success(ActionInvocation invocation) {
47 boolean ok = true;
48 int currentVolume = 0;
49 try {
50 currentVolume = Integer.valueOf(invocation.getOutput("CurrentVolume").getValue().toString());
51 } catch (Exception ex) {
52 invocation.setFailure(
53 new ActionException(ErrorCode.ACTION_FAILED, "Can't parse ProtocolInfo response: " + ex, ex)
54 );
55 failure(invocation, null);
56 ok = false;
57 }
58 if (ok) received(invocation, currentVolume);
59 }
60
61 public abstract void received(ActionInvocation actionInvocation, int currentVolume);
62
63 }