package org.kne.cloud.network;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.SocketOption;
import java.net.SocketOptions;
import java.util.Objects;

public abstract class RawSocketImpl  implements SocketOptions{
	 int dataAvailable() {
	        // default impl returns zero, which disables the calling
	        // functionality
	        return 0;
	    }
	protected abstract void create()throws IOException;
	
	protected abstract void setIPHeaderInclude(boolean on)throws IOException;

	protected abstract boolean getIPHeaderInclude()throws IOException;

	protected abstract void setUseSelectTimeout(boolean useSelect)throws IOException;

	protected abstract boolean getUseSelectTimeout()throws IOException;

	protected abstract void setSendTimeout(int timeout)throws IOException;

	protected abstract int getSendTimeout()throws IOException;

	protected abstract void setReceiveTimeout(int timeout)throws IOException;

	protected abstract int getReceiveTimeout()throws IOException;

	protected abstract void close();

	protected abstract void bind(InetAddress address,int protocolNumber)throws SocketException;

	 protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
	        Objects.requireNonNull(name);
	        throw new UnsupportedOperationException("'" + name + "' not supported");
	    }

	    protected <T> T getOption(SocketOption<T> name) throws IOException {
	        Objects.requireNonNull(name);
	        throw new UnsupportedOperationException("'" + name + "' not supported");
	    }
	    
	    protected abstract void join(InetAddress inetaddr) throws IOException;

	    
	    protected abstract void leave(InetAddress inetaddr) throws IOException;

	   
	    protected abstract void joinGroup(InetAddress mcastaddr,
	                                      NetworkInterface netIf)
	        throws IOException;

	  
	    protected abstract void leaveGroup(InetAddress mcastaddr,
	                                       NetworkInterface netIf)
	        throws IOException;
	    protected abstract void send(DatagramPacket p) throws IOException;
	    protected abstract InetAddress peek() throws IOException;

	   
	    protected abstract void peekData(DatagramPacket p) throws IOException;
	    
	    protected abstract void receive(DatagramPacket p) throws IOException;
	    
	    protected void connect(InetAddress address) throws SocketException {
	        throw new SocketException("connect not implemented");
	    }
	    
	    protected void disconnect() {
	        throw new UncheckedIOException(new SocketException("disconnect not implemented"));
	    }
}
