-//
-// Copyright (c) 2013 Ford Motor Company
-//
-package com.smartdevicelink.protocol;
-
-import com.smartdevicelink.protocol.SmartDeviceLinkProtocol.MessageFrameAssembler;
-import com.smartdevicelink.protocol.enums.SessionType;
-import com.smartdevicelink.trace.SyncTrace;
-import com.smartdevicelink.trace.enums.InterfaceActivityDirection;
-
-public abstract class AbstractProtocol {
- private static final String SmartDeviceLink_LIB_TRACE_KEY = "42baba60-eb57-11df-98cf-0800200c9a66";
-
- private IProtocolListener _protocolListener = null;
-
- // Lock to ensure all frames are sent uninterupted
- private Object _frameLock = new Object();
-
- // Caller must provide a non-null IProtocolListener interface reference.
- public AbstractProtocol(IProtocolListener protocolListener) {
- if (protocolListener == null) {
- throw new IllegalArgumentException("Provided protocol listener interface reference is null");
- } // end-if
-
- _protocolListener = protocolListener;
- } // end-ctor
-
- // This method receives raw bytes as they arrive from transport. Those bytes
- // are then collected by the protocol and assembled into complete messages and
- // handled internally by the protocol or propagated to the protocol listener.
- public abstract void HandleReceivedBytes(byte[] receivedBytes, int length);
-
- // This method receives a protocol message (e.g. RPC, BULK, etc.) and processes
- // it for transmission over the transport. The results of this processing will
- // be sent to the onProtocolMessageBytesToSend() method on protocol listener
- // interface. Note that the ProtocolMessage itself contains information
- // about the type of message (e.g. RPC, BULK, etc.) and the protocol session
- // over which to send the message, etc.
- public abstract void SendMessage(ProtocolMessage msg);
-
- // This method starts a protocol session. A corresponding call to the protocol
- // listener onProtocolSessionStarted() method will be made when the protocol
- // session has been established.
- public abstract void StartProtocolSession(SessionType sessionType);
-
- // This method ends a protocol session. A corresponding call to the protocol
- // listener onProtocolSessionEnded() method will be made when the protocol
- // session has ended.
- public abstract void EndProtocolSession(SessionType sessionType, byte sessionID);
-
- // This method is called whenever the protocol receives a complete frame
- protected void handleProtocolFrameReceived(ProtocolFrameHeader header, byte[] data, MessageFrameAssembler assembler) {
- SyncTrace.logProtocolEvent(InterfaceActivityDirection.Receive, header, data,
- 0, data.length, SmartDeviceLink_LIB_TRACE_KEY);
-
- assembler.handleFrame(header, data);
- }
-
- // This method is called whenever a protocol has an entire frame to send
- protected void handleProtocolFrameToSend(ProtocolFrameHeader header, byte[] data, int offset, int length) {
- SyncTrace.logProtocolEvent(InterfaceActivityDirection.Transmit, header, data,
- offset, length, SmartDeviceLink_LIB_TRACE_KEY);
-
- synchronized(_frameLock) {
- byte[] frameHeader = header.assembleHeaderBytes();
- handleProtocolMessageBytesToSend(frameHeader, 0, frameHeader.length);
-
- if (data != null) {
- handleProtocolMessageBytesToSend(data, offset, length);
- } // end-if
- }
- }
-
- // This method handles protocol message bytes that are ready to send.
- // A callback is sent to the protocol listener.
- protected void handleProtocolMessageBytesToSend(byte[] bytesToSend,
- int offset, int length) {
- _protocolListener.onProtocolMessageBytesToSend(bytesToSend, offset, length);
- }
-
- // This method handles received protocol messages.
- protected void handleProtocolMessageReceived(ProtocolMessage message) {
- _protocolListener.onProtocolMessageReceived(message);
- }
-
- // This method handles the end of a protocol session. A callback is
- // sent to the protocol listener.
- protected void handleProtocolSessionEnded(SessionType sessionType,
- byte sessionID, String correlationID) {
- _protocolListener.onProtocolSessionEnded(sessionType, sessionID, correlationID);
- }
-
- // This method handles the startup of a protocol session. A callback is sent
- // to the protocol listener.
- protected void handleProtocolSessionStarted(SessionType sessionType,
- byte sessionID, byte version, String correlationID) {
- _protocolListener.onProtocolSessionStarted(sessionType, sessionID, version, correlationID);
- }
-
- // This method handles protocol errors. A callback is sent to the protocol
- // listener.
- protected void handleProtocolError(String string, Exception ex) {
- _protocolListener.onProtocolError(string, ex);
- }
-} // end-class
+package com.smartdevicelink.protocol;\r
+\r
+import com.smartdevicelink.protocol.SmartDeviceLinkProtocol.MessageFrameAssembler;\r
+import com.smartdevicelink.protocol.enums.SessionType;\r
+import com.smartdevicelink.trace.SmartDeviceLinkTrace;\r
+import com.smartdevicelink.trace.enums.InterfaceActivityDirection;\r
+\r
+public abstract class AbstractProtocol {\r
+ private static final String SMARTDEVICELINK_LIB_TRACE_KEY = "42baba60-eb57-11df-98cf-0800200c9a66";\r
+ \r
+ private IProtocolListener _protocolListener = null;\r
+ //protected IProtocolListener ProtocolListener() { return _protocolListener; }\r
+ \r
+ // Lock to ensure all frames are sent uninterupted \r
+ private Object _frameLock = new Object();\r
+\r
+ // Caller must provide a non-null IProtocolListener interface reference.\r
+ public AbstractProtocol(IProtocolListener protocolListener) {\r
+ if (protocolListener == null) {\r
+ throw new IllegalArgumentException("Provided protocol listener interface reference is null");\r
+ } // end-if\r
+ \r
+ _protocolListener = protocolListener;\r
+ } // end-ctor\r
+\r
+ // This method receives raw bytes as they arrive from transport. Those bytes\r
+ // are then collected by the protocol and assembled into complete messages and\r
+ // handled internally by the protocol or propagated to the protocol listener.\r
+ public abstract void HandleReceivedBytes(byte[] receivedBytes, int length);\r
+\r
+ // This method receives a protocol message (e.g. RPC, BULK, etc.) and processes\r
+ // it for transmission over the transport. The results of this processing will\r
+ // be sent to the onProtocolMessageBytesToSend() method on protocol listener\r
+ // interface. Note that the ProtocolMessage itself contains information\r
+ // about the type of message (e.g. RPC, BULK, etc.) and the protocol session\r
+ // over which to send the message, etc.\r
+ public abstract void SendMessage(ProtocolMessage msg);\r
+\r
+ // This method starts a protocol session. A corresponding call to the protocol\r
+ // listener onProtocolSessionStarted() method will be made when the protocol\r
+ // session has been established.\r
+ public abstract void StartProtocolSession(SessionType sessionType);\r
+\r
+ // This method ends a protocol session. A corresponding call to the protocol\r
+ // listener onProtocolSessionEnded() method will be made when the protocol\r
+ // session has ended.\r
+ public abstract void EndProtocolSession(SessionType sessionType, byte sessionID);\r
+ \r
+ // This method is called whenever the protocol receives a complete frame\r
+ protected void handleProtocolFrameReceived(ProtocolFrameHeader header, byte[] data, MessageFrameAssembler assembler) {\r
+ SmartDeviceLinkTrace.logProtocolEvent(InterfaceActivityDirection.Receive, header, data, \r
+ 0, data.length, SMARTDEVICELINK_LIB_TRACE_KEY);\r
+ \r
+ assembler.handleFrame(header, data);\r
+ }\r
+ \r
+ // This method is called whenever a protocol has an entire frame to send\r
+ protected void handleProtocolFrameToSend(ProtocolFrameHeader header, byte[] data, int offset, int length) {\r
+ SmartDeviceLinkTrace.logProtocolEvent(InterfaceActivityDirection.Transmit, header, data, \r
+ offset, length, SMARTDEVICELINK_LIB_TRACE_KEY);\r
+ \r
+ synchronized(_frameLock) {\r
+ byte[] frameHeader = header.assembleHeaderBytes();\r
+ handleProtocolMessageBytesToSend(frameHeader, 0, frameHeader.length);\r
+ \r
+ if (data != null) {\r
+ handleProtocolMessageBytesToSend(data, offset, length);\r
+ } // end-if\r
+ }\r
+ }\r
+ \r
+ // This method handles protocol message bytes that are ready to send.\r
+ // A callback is sent to the protocol listener.\r
+ protected void handleProtocolMessageBytesToSend(byte[] bytesToSend,\r
+ int offset, int length) {\r
+ _protocolListener.onProtocolMessageBytesToSend(bytesToSend, offset, length);\r
+ }\r
+ \r
+ // This method handles received protocol messages. \r
+ protected void handleProtocolMessageReceived(ProtocolMessage message) {\r
+ _protocolListener.onProtocolMessageReceived(message);\r
+ }\r
+ \r
+ // This method handles the end of a protocol session. A callback is \r
+ // sent to the protocol listener.\r
+ protected void handleProtocolSessionEnded(SessionType sessionType,\r
+ byte sessionID, String correlationID) {\r
+ _protocolListener.onProtocolSessionEnded(sessionType, sessionID, correlationID);\r
+ }\r
+ \r
+ // This method handles the startup of a protocol session. A callback is sent\r
+ // to the protocol listener.\r
+ protected void handleProtocolSessionStarted(SessionType sessionType,\r
+ byte sessionID, byte version, String correlationID) {\r
+ _protocolListener.onProtocolSessionStarted(sessionType, sessionID, version, correlationID);\r
+ }\r
+ \r
+ // This method handles protocol errors. A callback is sent to the protocol\r
+ // listener.\r
+ protected void handleProtocolError(String string, Exception ex) {\r
+ _protocolListener.onProtocolError(string, ex);\r
+ }\r
+} // end-class\r