//..............................................................................
//
// USB Data Endpoint session dispatch interface for IAS
//

import "io_usb.jncx"
import "ias.jnc"

//..............................................................................

class UsbDataEndpointDispatch: ias.Session {
	property m_deviceVid {
		uint_t get() {
			return dispatchGet(UsbDataEndpointDispatchCode.GetDeviceVid);
		}
	}

	property m_devicePid {
		uint_t get() {
			return dispatchGet(UsbDataEndpointDispatchCode.GetDevicePid);
		}
	}

	bool errorcode setDeviceVidPid(
		uint_t vid,
		uint_t pid
	) {
		return dispatch(UsbDataEndpointDispatchCode.SetDeviceVidPid, (vid << 16) | (pid & 0xffff));
	}

	property m_interfaceId {
		uint_t get() {
			return dispatchGet(UsbDataEndpointDispatchCode.GetInterfaceId);
		}

		void set(uint_t value) {
			dispatch(UsbDataEndpointDispatchCode.SetInterfaceId, value);
		}
	}

	property m_outEndpointId {
		uint_t get() {
			return dispatchGet(UsbDataEndpointDispatchCode.GetOutEndpointId);
		}

		void set(uint_t value) {
			dispatch(UsbDataEndpointDispatchCode.SetOutEndpointId, value);
		}
	}

	property m_inEndpointId {
		uint_t get() {
			return dispatchGet(UsbDataEndpointDispatchCode.GetInEndpointId);
		}

		void set(uint_t value) {
			dispatch(UsbDataEndpointDispatchCode.SetInEndpointId, value);
		}
	}

	bool errorcode openDevice() {
		return dispatch(UsbDataEndpointDispatchCode.OpenDevice);
	}

	bool errorcode openDevice(
		uint_t vid,
		uint_t pid
	) {
		return dispatch(UsbDataEndpointDispatchCode.OpenDeviceVidPid, (vid << 16) | (pid & 0xffff));
	}

	void closeDevice() {
		dispatch(UsbDataEndpointDispatchCode.CloseDevice);
	}

	void claimInterface() {
		dispatch(UsbDataEndpointDispatchCode.ClaimInterface);
	}

	void claimInterface(uint_t interfaceId) {
		dispatch(UsbDataEndpointDispatchCode.ClaimInterfaceId, interfaceId);
	}

	void releaseInterface() {
		dispatch(UsbDataEndpointDispatchCode.ReleaseInterface);
	}

	void startReading() {
		dispatch(UsbDataEndpointDispatchCode.StartReading);
	}

	void startReading(uint_t endpointId) {
		dispatch(UsbDataEndpointDispatchCode.StartReadingEndpoint, endpointId);
	}

	void stopReading() {
		dispatch(UsbDataEndpointDispatchCode.StopReading);
	}
}

//..............................................................................
