com.embeddedunveiled.serial.SerialComPortHandleInfo Maven / Gradle / Ivy
/**
* Author : Rishi Gupta
*
* This file is part of 'serial communication manager' library.
*
* The 'serial communication manager' is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* The 'serial communication manager' is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with serial communication manager. If not, see .
*/
package com.embeddedunveiled.serial;
/**
* This class encapsulate port handle, looper object, event listener, data listener and port name associated with a particular port.
*/
public final class SerialComPortHandleInfo {
private String mOpenedPortName = null;
private long mPortHandle = -1;
private SerialComLooper mLooper = null;
private ISerialComEventListener mEventListener = null;
private ISerialComDataListener mDataListener = null;
public SerialComPortHandleInfo(String portName, long handle, SerialComLooper looper, ISerialComDataListener dataListener, ISerialComEventListener eventListener) {
this.mOpenedPortName = portName;
this.mPortHandle = handle;
this.mLooper = looper;
this.mEventListener = eventListener;
this.mDataListener = dataListener;
}
/** Get the name of port associated with given handle Callers first find reference to this class object using given handle and then invoke this method.
*/
public String getOpenedPortName() {
return mOpenedPortName;
}
/** Set the name of port.
*/
public void setOpenedPortName(String portName) {
this.mOpenedPortName = portName;
}
/** Check if the corresponding port name exist.
*/
public boolean containsPort(String portName) throws SerialComException {
if(portName == null) {
throw new SerialComException("containsPort()", SerialComErrorMapper.ERR_PORT_NAME_NULL);
}
if(mOpenedPortName != null) {
if(portName.equals(mOpenedPortName)) {
return true;
}
}
return false;
}
/** Returns handle to the opened port.
*/
public long getPortHandle() {
return mPortHandle;
}
/** Sets the handle of the port opened.
*/
public void setPortHandle(long handle) {
this.mPortHandle = handle;
}
/** Check if the object of this class have this handle.
*/
public boolean containsHandle(long handle) {
if(handle == mPortHandle) {
return true;
}
return false;
}
/** Looper associated with this port, info and manipulation.
*/
public SerialComLooper getLooper() {
return mLooper;
}
/** Set the looper object that is associated with this handle.
*/
public void setLooper(SerialComLooper looper) {
this.mLooper = looper;
}
/** Event listener associated with this port, info and manipulation.
*/
public ISerialComEventListener getEventListener() {
return mEventListener;
}
/** Set the event listener associated with this handle.
*/
public void setEventListener(ISerialComEventListener eventListener) {
this.mEventListener = eventListener;
}
/** Check if there is already a registered event listener for this handle.
*/
public boolean containsEventListener(ISerialComEventListener eventListener) {
if(eventListener == mEventListener) {
return true;
}
return false;
}
/** Data Listener associated with this port, info and manipulation.
*/
public ISerialComDataListener getDataListener() {
return mDataListener;
}
/** Set the data listener for this handle.
*/
public void setDataListener(ISerialComDataListener dataListener) {
this.mDataListener = dataListener;
}
/** Check if there already exist a data listener for this handle.
*/
public boolean containsDataListener(ISerialComDataListener dataListener) {
if(dataListener == mDataListener) {
return true;
}
return false;
}
}