package testprocs;

import simulator.*;
import modules.color.*;
import modules.codegas.*;
import modules.hashtable.*;
import modules.neighborset.*;
import modules.node.*;
import modules.gradient.*;
import modules.region.*;
import utils.*;
import java.awt.*;
import java.util.*;

// Persistent Node testing

public class FDTestProc implements ProcessorModule {
  public Symbol getName() { return Symbol.GetSymbol("MyProc"); }
  public void link(PortedProcessor p) {
    pp = p;
    pp.addClockListener(this);
    pp.openNetworkPort(this,uiPort);
    fd = (FailureDetector)p.getModule("FailureDetector");
    //ag = (ActiveGradient)p.getModule("ActiveGradient");
    cm = (ColorModule)p.getModule("Color");
    //pn = (PersistentNodeB)p.getModule("PersistentNode");
    //rm = (RegionManager)p.getModule("RegionManager");
  }

  PortedProcessor pp; ActiveGradient ag; ColorModule cm; PersistentNodeB pn;
  RegionManager rm; FailureDetector fd;

  static final Symbol uiPort = Symbol.GetSymbol("UI");

  public void init() {
  }


  int time=0;

  public boolean signalEvent(Symbol name,Object data) {
    boolean dirty = false;
    if(name==uiPort) {
      System.out.println(time+": recv msg: "+data);
    } else if(name==PortedProcessor.kClock) {
      int t = ((Integer)data).intValue();
      time=t;

      if(fd.isEdge()) cm.setColor(Color.red);
      else cm.setColor(Color.blue);
    }
    return dirty;
  }

  public String toString() {
    return "FDTestProc";
  }
}


