package simulator;

import utils.*;
import java.util.*;
import java.awt.*;

abstract public class Processor extends Observable {
  private Simulator sim;
  private Color outcolor = Color.darkGray; // default color
  private double uid;
  private Double UID;

  public Processor(Simulator sim) 
  { this.sim = sim; uid = Math.random(); UID = new Double(uid); }

  // passthroughs to simulator
  protected void broadcast(Object msg) { sim.processor_broadcast(this,msg); }
  protected void pointtopoint(Object msg,double target) 
  { sim.processor_pointtopoint(this,target,msg); }
  protected void timer(double delay, Object signal) 
  { sim.processor_timer(this,delay,signal); }
  protected boolean carrierSense() { return sim.processor_carrierSense(this); }

  abstract public void init();
  abstract public void signalEvent(Symbol name,Object data);

  public double getUID() { return uid; }
  public Double getUIDd() { return UID; }

  public Color getColor() { return outcolor; }
  protected void colorme(Color c) {
    if(!outcolor.equals(c)) { setChanged(); }
    outcolor = c;
  }

  private boolean suspended = false;
  public boolean suspended() { return suspended; }
  public void suspend() { suspended=true; setChanged(); notifyObservers(); }
  public void revive() { suspended=false; setChanged(); notifyObservers(); }
}

