View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  
16  package org.fourthline.cling.support.connectionmanager.callback;
17  
18  import org.fourthline.cling.controlpoint.ActionCallback;
19  import org.fourthline.cling.controlpoint.ControlPoint;
20  import org.fourthline.cling.model.ServiceReference;
21  import org.fourthline.cling.model.action.ActionException;
22  import org.fourthline.cling.model.action.ActionInvocation;
23  import org.fourthline.cling.model.meta.Service;
24  import org.fourthline.cling.model.types.ErrorCode;
25  import org.fourthline.cling.support.model.ConnectionInfo;
26  import org.fourthline.cling.support.model.ProtocolInfo;
27  
28  /**
29   * @author Alessio Gaeta
30   * @author Christian Bauer
31   */
32  public abstract class GetCurrentConnectionInfo extends ActionCallback {
33  
34      public GetCurrentConnectionInfo(Service service, int connectionID) {
35          this(service, null, connectionID);
36      }
37  
38      protected GetCurrentConnectionInfo(Service service, ControlPoint controlPoint, int connectionID) {
39          super(new ActionInvocation(service.getAction("GetCurrentConnectionInfo")), controlPoint);
40  		getActionInvocation().setInput("ConnectionID", connectionID);
41  	}
42  
43      @Override
44      public void success(ActionInvocation invocation) {
45  
46          try {
47              ConnectionInfo info = new ConnectionInfo(
48                      (Integer)invocation.getInput("ConnectionID").getValue(),
49                      (Integer)invocation.getOutput("RcsID").getValue(),
50                      (Integer)invocation.getOutput("AVTransportID").getValue(),
51                      new ProtocolInfo(invocation.getOutput("ProtocolInfo").toString()),
52                      new ServiceReference(invocation.getOutput("PeerConnectionManager").toString()),
53                      (Integer)invocation.getOutput("PeerConnectionID").getValue(),
54                      ConnectionInfo.Direction.valueOf(invocation.getOutput("Direction").toString()),
55                      ConnectionInfo.Status.valueOf(invocation.getOutput("Status").toString())
56              );
57  
58              received(invocation, info);
59  
60          } catch (Exception ex) {
61              invocation.setFailure(
62                      new ActionException(ErrorCode.ACTION_FAILED, "Can't parse ConnectionInfo response: " + ex, ex)
63              );
64              failure(invocation, null);
65          }
66      }
67  
68      public abstract void received(ActionInvocation invocation, ConnectionInfo connectionInfo);
69  
70  }