Ejemplo n.º 1
0
  /**
   * Constructor.
   *
   * @param listener Sdl connection listener.
   * @param transportConfig Transport configuration for this connection.
   */
  public SdlConnection(BaseTransportConfig transportConfig) {
    _connectionListener = new InternalMsgDispatcher();

    // Initialize the transport
    synchronized (TRANSPORT_REFERENCE_LOCK) {
      // Ensure transport is null
      if (_transport != null) {
        if (_transport.getIsConnected()) {
          _transport.disconnect();
        }
        _transport = null;
      }

      if (transportConfig.getTransportType() == TransportType.BLUETOOTH) {
        BTTransportConfig myConfig = (BTTransportConfig) transportConfig;
        _transport = new BTTransport(this, myConfig.getKeepSocketActive());
      } else if (transportConfig.getTransportType() == TransportType.TCP) {
        _transport = new TCPTransport((TCPTransportConfig) transportConfig, this);
      } else if (transportConfig.getTransportType() == TransportType.USB) {
        _transport = new USBTransport((USBTransportConfig) transportConfig, this);
      }
    }

    // Initialize the protocol
    synchronized (PROTOCOL_REFERENCE_LOCK) {
      // Ensure protocol is null
      if (_protocol != null) {
        _protocol = null;
      }

      _protocol = new WiProProtocol(this);
    }
  }
Ejemplo n.º 2
0
  public String getBroadcastComment() {

    if (_transport == null) {
      return "";
    }

    return _transport.getBroadcastComment();
  }
Ejemplo n.º 3
0
 @Override
 public void onProtocolMessageBytesToSend(byte[] msgBytes, int offset, int length) {
   // Protocol has packaged bytes to send, pass to transport for transmission
   synchronized (TRANSPORT_REFERENCE_LOCK) {
     if (_transport != null) {
       _transport.sendBytes(msgBytes, offset, length);
     }
   }
 }
Ejemplo n.º 4
0
  public Boolean getIsConnected() {

    // If _transport is null, then it can't be connected
    if (_transport == null) {
      return false;
    }

    return _transport.getIsConnected();
  }
Ejemplo n.º 5
0
  private void closeConnection(boolean willRecycle, byte rpcSessionID) {
    synchronized (PROTOCOL_REFERENCE_LOCK) {
      if (_protocol != null) {
        // If transport is still connected, sent EndProtocolSessionMessage
        if (_transport != null && _transport.getIsConnected()) {
          _protocol.EndProtocolSession(SessionType.RPC, rpcSessionID);
        }
        if (willRecycle) {
          _protocol = null;
        }
      } // end-if
    }

    synchronized (TRANSPORT_REFERENCE_LOCK) {
      if (willRecycle) {
        if (_transport != null) {
          _transport.disconnect();
        }
        _transport = null;
      }
    }
  }
Ejemplo n.º 6
0
 /**
  * Gets type of transport currently used by this connection.
  *
  * @return One of TransportType enumeration values.
  * @see TransportType
  */
 public TransportType getCurrentTransportType() {
   return _transport.getTransportType();
 }
Ejemplo n.º 7
0
 public void startTransport() throws SdlException {
   _transport.openConnection();
 }