-//
-// Copyright (c) 2013 Ford Motor Company
-//
-package com.smartdevicelink.transport;
-
-import com.smartdevicelink.exception.SmartDeviceLinkException;
-import com.smartdevicelink.trace.SyncTrace;
-import com.smartdevicelink.trace.enums.InterfaceActivityDirection;
-import com.smartdevicelink.util.DebugTool;
-
-public abstract class SmartDeviceLinkTransport {
- private static final String SMARTDEVICELINK_LIB_TRACE_KEY = "42baba60-eb57-11df-98cf-0800200c9a66";
-
- private final static String FailurePropagating_Msg = "Failure propagating ";
- private Boolean isConnected = false;
-
- private String _sendLockObj = "lock";
-
- // Get status of transport connection
- public Boolean getIsConnected() {
- return isConnected;
- }
-
- //protected SmartDeviceLinkTransport(String endpointName, String param2, ITransportListener transportListener)
- protected SmartDeviceLinkTransport(ITransportListener transportListener) {
- if (transportListener == null) {
- throw new IllegalArgumentException("Provided transport listener interface reference is null");
- } // end-if
- _transportListener = transportListener;
- } // end-method
-
- // This method is called by the subclass to indicate that data has arrived from
- // the transport.
- protected void handleReceivedBytes(byte[] receivedBytes, int receivedBytesLength) {
- try {
- // Trace received data
- if (receivedBytesLength > 0) {
- // Send transport data to the siphon server
- SiphonServer.sendBytesFromSmartDeviceLink(receivedBytes, 0, receivedBytesLength);
- SyncTrace.logTransportEvent("", null, InterfaceActivityDirection.Receive, receivedBytes, receivedBytesLength, SMARTDEVICELINK_LIB_TRACE_KEY);
-
- _transportListener.onTransportBytesReceived(receivedBytes, receivedBytesLength);
- } // end-if
- } catch (Exception excp) {
- DebugTool.logError(FailurePropagating_Msg + "handleBytesFromTransport: " + excp.toString(), excp);
- handleTransportError(FailurePropagating_Msg, excp);
- } // end-catch
- } // end-method
-
- // This method must be implemented by transport subclass, and is called by this
- // base class to actually send an array of bytes out over the transport. This
- // method is meant to only be callable within the class hierarchy.
- protected abstract boolean sendBytesOverTransport(byte[] msgBytes, int offset, int length);
-
- // This method is called by whomever has reference to transport to have bytes
- // sent out over transport.
- public boolean sendBytes(byte[] message) {
- return sendBytes(message, 0, message.length);
- } // end-method
-
- // This method is called by whomever has reference to transport to have bytes
- // sent out over transport.
- public boolean sendBytes(byte[] message, int offset, int length) {
- boolean bytesWereSent = false;
- synchronized (_sendLockObj) {
- bytesWereSent = sendBytesOverTransport(message, offset, length);
- } // end-lock
- // Send transport data to the siphon server
- SiphonServer.sendBytesFromAPP(message, offset, length);
-
- SyncTrace.logTransportEvent("", null, InterfaceActivityDirection.Transmit, message, offset, length, SMARTDEVICELINK_LIB_TRACE_KEY);
- return bytesWereSent;
- } // end-method
-
- private ITransportListener _transportListener = null;
-
- // This method is called by the subclass to indicate that transport connection
- // has been established.
- protected void handleTransportConnected() {
- isConnected = true;
- try {
- SyncTrace.logTransportEvent("Transport.connected", null, InterfaceActivityDirection.Receive, null, 0, SMARTDEVICELINK_LIB_TRACE_KEY);
- _transportListener.onTransportConnected();
- } catch (Exception excp) {
- DebugTool.logError(FailurePropagating_Msg + "onTransportConnected: " + excp.toString(), excp);
- handleTransportError(FailurePropagating_Msg + "onTransportConnected", excp);
- } // end-catch
- } // end-method
-
- // This method is called by the subclass to indicate that transport disconnection
- // has occurred.
- protected void handleTransportDisconnected(final String info) {
- isConnected = false;
-
- try {
- SyncTrace.logTransportEvent("Transport.disconnect: " + info, null, InterfaceActivityDirection.Transmit, null, 0, SMARTDEVICELINK_LIB_TRACE_KEY);
- _transportListener.onTransportDisconnected(info);
- } catch (Exception excp) {
- DebugTool.logError(FailurePropagating_Msg + "onTransportDisconnected: " + excp.toString(), excp);
- } // end-catch
- } // end-method
-
- // This method is called by the subclass to indicate a transport error has occurred.
- protected void handleTransportError(final String message, final Exception ex) {
- isConnected = false;
- _transportListener.onTransportError(message, ex);
- }
-
- public abstract void openConnection() throws SmartDeviceLinkException;
- public abstract void disconnect();
-
- /**
- * Abstract method which should be implemented by subclasses in order to return actual type of the transport.
- *
- * @return One of {@link TransportType} enumeration values.
- *
- * @see TransportType
- */
- public abstract TransportType getTransportType();
-} // end-class
+package com.smartdevicelink.transport;\r
+\r
+import com.smartdevicelink.exception.SmartDeviceLinkException;\r
+import com.smartdevicelink.trace.SmartDeviceLinkTrace;\r
+import com.smartdevicelink.trace.enums.InterfaceActivityDirection;\r
+import com.smartdevicelink.util.DebugTool;\r
+\r
+public abstract class SmartDeviceLinkTransport {\r
+ private static final String SMARTDEVICELINK_LIB_TRACE_KEY = "42baba60-eb57-11df-98cf-0800200c9a66";\r
+ \r
+ private final static String FailurePropagating_Msg = "Failure propagating ";\r
+ private Boolean isConnected = false;\r
+ \r
+ private String _sendLockObj = "lock";\r
+ \r
+ // Get status of transport connection\r
+ public Boolean getIsConnected() {\r
+ return isConnected;\r
+ }\r
+\r
+ //protected SmartDeviceLinkTransport(String endpointName, String param2, ITransportListener transportListener)\r
+ protected SmartDeviceLinkTransport(ITransportListener transportListener) {\r
+ if (transportListener == null) {\r
+ throw new IllegalArgumentException("Provided transport listener interface reference is null");\r
+ } // end-if\r
+ _transportListener = transportListener;\r
+ } // end-method\r
+ \r
+ // This method is called by the subclass to indicate that data has arrived from\r
+ // the transport.\r
+ protected void handleReceivedBytes(byte[] receivedBytes, int receivedBytesLength) {\r
+ try {\r
+ // Trace received data\r
+ if (receivedBytesLength > 0) {\r
+ // Send transport data to the siphon server\r
+ SiphonServer.sendBytesFromSMARTDEVICELINK(receivedBytes, 0, receivedBytesLength);\r
+ SmartDeviceLinkTrace.logTransportEvent("", null, InterfaceActivityDirection.Receive, receivedBytes, receivedBytesLength, SMARTDEVICELINK_LIB_TRACE_KEY);\r
+ \r
+ _transportListener.onTransportBytesReceived(receivedBytes, receivedBytesLength);\r
+ } // end-if\r
+ } catch (Exception excp) {\r
+ DebugTool.logError(FailurePropagating_Msg + "handleBytesFromTransport: " + excp.toString(), excp);\r
+ handleTransportError(FailurePropagating_Msg, excp);\r
+ } // end-catch\r
+ } // end-method\r
+\r
+ // This method must be implemented by transport subclass, and is called by this\r
+ // base class to actually send an array of bytes out over the transport. This\r
+ // method is meant to only be callable within the class hierarchy.\r
+ protected abstract boolean sendBytesOverTransport(byte[] msgBytes, int offset, int length);\r
+\r
+ // This method is called by whomever has reference to transport to have bytes\r
+ // sent out over transport.\r
+ public boolean sendBytes(byte[] message) {\r
+ return sendBytes(message, 0, message.length);\r
+ } // end-method\r
+ \r
+ // This method is called by whomever has reference to transport to have bytes\r
+ // sent out over transport.\r
+ public boolean sendBytes(byte[] message, int offset, int length) {\r
+ boolean bytesWereSent = false;\r
+ synchronized (_sendLockObj) {\r
+ bytesWereSent = sendBytesOverTransport(message, offset, length);\r
+ } // end-lock\r
+ // Send transport data to the siphon server\r
+ SiphonServer.sendBytesFromAPP(message, offset, length);\r
+ \r
+ SmartDeviceLinkTrace.logTransportEvent("", null, InterfaceActivityDirection.Transmit, message, offset, length, SMARTDEVICELINK_LIB_TRACE_KEY);\r
+ return bytesWereSent;\r
+ } // end-method\r
+\r
+ private ITransportListener _transportListener = null;\r
+\r
+ // This method is called by the subclass to indicate that transport connection\r
+ // has been established.\r
+ protected void handleTransportConnected() {\r
+ isConnected = true;\r
+ try {\r
+ SmartDeviceLinkTrace.logTransportEvent("Transport.connected", null, InterfaceActivityDirection.Receive, null, 0, SMARTDEVICELINK_LIB_TRACE_KEY);\r
+ _transportListener.onTransportConnected();\r
+ } catch (Exception excp) {\r
+ DebugTool.logError(FailurePropagating_Msg + "onTransportConnected: " + excp.toString(), excp);\r
+ handleTransportError(FailurePropagating_Msg + "onTransportConnected", excp);\r
+ } // end-catch\r
+ } // end-method\r
+ \r
+ // This method is called by the subclass to indicate that transport disconnection\r
+ // has occurred.\r
+ protected void handleTransportDisconnected(final String info) {\r
+ isConnected = false;\r
+\r
+ try {\r
+ SmartDeviceLinkTrace.logTransportEvent("Transport.disconnect: " + info, null, InterfaceActivityDirection.Transmit, null, 0, SMARTDEVICELINK_LIB_TRACE_KEY);\r
+ _transportListener.onTransportDisconnected(info);\r
+ } catch (Exception excp) {\r
+ DebugTool.logError(FailurePropagating_Msg + "onTransportDisconnected: " + excp.toString(), excp);\r
+ } // end-catch\r
+ } // end-method\r
+ \r
+ // This method is called by the subclass to indicate a transport error has occurred.\r
+ protected void handleTransportError(final String message, final Exception ex) {\r
+ isConnected = false;\r
+ _transportListener.onTransportError(message, ex);\r
+ }\r
+\r
+ public abstract void openConnection() throws SmartDeviceLinkException;\r
+ public abstract void disconnect();\r
+ \r
+ /**\r
+ * Abstract method which should be implemented by subclasses in order to return actual type of the transport. \r
+ * \r
+ * @return One of {@link TransportType} enumeration values.\r
+ * \r
+ * @see TransportType\r
+ */\r
+ public abstract TransportType getTransportType();\r
+} // end-class\r