package adaptive;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class ReceiverFileMonitor {
	String procFileMonitor;
	File file = null;

	int maxListSize = 10;

	private LinkedList ll = new LinkedList();

	float quality = 0;
	float signal = 0;
	float noise = 0;
	float sum = 0;

	public void update() {
		FileReader fileReader;
		BufferedReader in = null;
		try {
			fileReader = new FileReader(file);
			in = new BufferedReader(fileReader);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		String status = null, inputLine;

		try {
			while ((inputLine = in.readLine()) != null) {
				if (inputLine != null)
					status = inputLine;
			}
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

		int i = 0;

		// parse status
		StringTokenizer stok = new StringTokenizer(status);
		while (stok.hasMoreElements()) {
			String tok = (String) stok.nextElement();
			switch (i) {
				case 2 :
					quality = new Float(tok).floatValue();
					break;
				case 3 :
					signal = new Float(tok).floatValue();
					break;
				case 4 :
					noise = new Float(tok).floatValue();
					break;
			}
			i++;
		}
	}

	public ReceiverFileMonitor(String procFilePath) {
		file = new File(procFilePath);
	}

	public float getSignalNoiseRatio() {
		return signal/noise;
	}

	public float getSignal() {
		return signal;
	}

	public float getNoise() {
		return noise;
	}

	public float getQuality() {
		return quality;
	}
}


//float currentQuality = getQuality();
//
//sum += currentQuality;
//ll.addLast(new Float(currentQuality));
//
//if (ll.size() > maxListSize) {
//	sum -= ((Float) (ll.getFirst())).floatValue();
//	ll.removeFirst();
//}
//
//Media
//		float sum = 0;
//		for (int i = 0; i < ll.size(); i++) {
//			sum += ((Float) ll.get(i)).floatValue();
//		}
//averageQuality = (float) sum / ll.size();
