package com.coiweb.oe.foglight.api;

import com.ociweb.gl.api.TimeListener;
import com.ociweb.iot.maker.FogCommandChannel;
import com.ociweb.iot.maker.FogRuntime;
import com.ociweb.iot.maker.SerialWritable;
import com.ociweb.iot.maker.SerialWriter;
import com.ociweb.pronghorn.pipe.BlobWriter;

import static com.ociweb.iot.maker.FogRuntime.SERIAL_WRITER;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SerialWriterBehavior implements TimeListener {

	private static Logger logger = LoggerFactory.getLogger(SerialWriterBehavior.class);
	private final FogCommandChannel cmd;
	private int value = 0;

	SerialWritable writable = new SerialWritable() {
		@Override
		public void write(BlobWriter writer) {
			writer.writeByte(value++);
		}		
	};
	
	public SerialWriterBehavior(FogRuntime runtime) {	
		cmd = runtime.newCommandChannel(SERIAL_WRITER );
	}

	@Override
	public void timeEvent(long time, int iteration) {			
		if (!cmd.publishSerial(writable)) {
			logger.warn("unable to write to serial, the system is too busy");
		}
	}

}

@@ -65,24 +65,59 @@
 meListener;%0A
+import com.ociweb.gl.api.Writable;%0A
 import com.o
@@ -195,94 +195,8 @@
 me;%0A
-import com.ociweb.iot.maker.SerialWritable;%0Aimport com.ociweb.iot.maker.SerialWriter;%0A
 impo
@@ -567,22 +567,16 @@
  = 0;%0A%0A%09
-Serial
 Writable
@@ -591,22 +591,16 @@
 e = new 
-Serial
 Writable

update to remove old interface