package jGPIO;

import java.util.Arrays;
import java.util.List;

import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;

import anywheresoftware.b4a.BA;

public interface Linux_C_lib extends com.sun.jna.Library {
	public long memcpy(int[] dst, short[] src, long n);

    public int memcpy(int[] dst, short[] src, int n);

    public int pipe(int[] fds);

    public int tcdrain(int fd);

    public int fcntl(int bus_handle, int command, int args);

    public int ioctl(int bus_handle, int command, int args);
    
    public int ioctl(int bus_handle, int command, int... args);
    
    public int ioctl(int bus_handle, int command, Pointer args);
    
    public int open(String path, int flags);

    public int close(int fd);

    public int write(int bus_handle, byte[] buffer, int count);

    public int read(int bus_handle, byte[] buffer, int count);

    public long write(int bus_handle, byte[] buffer, long count);

    public long read(int bus_handle, byte[] buffer, long count);

    public int select(int n, int[] read, int[] write, int[] error, timeval timeout);

    public int poll(int[] fds, int nfds, int timeout);

    public int tcflush(int fd, int qs);

    public void perror(String msg);

    public int tcsendbreak(int fd, int duration);
    
    static public class timeval extends Structure {
        public NativeLong tv_sec;
        public NativeLong tv_usec;

        
		protected List<String> getFieldOrder() {
            return Arrays.asList(//
                    "tv_sec",//
                    "tv_usec"//
                    );
        }
		
		@BA.Hide public void autoWrite(){}
		@BA.Hide public void autoRead(){}

        public timeval(long second, long usecond) {
        	tv_sec =  new NativeLong(second);
        	tv_usec = new NativeLong(usecond);
        }
    }
}
