package modules.dataflow;

import utils.*;
import simulator.*;
import java.util.*;
import modules.codegas.*;
import modules.gradient.*;
import modules.line.*;
import modules.node.*;
import java.awt.*;

// will only color itself once per tick
public class GraphBuilder implements ProcessorModule {
  PortedProcessor pp; ActiveGradient ag; //PersistentNode pn; 
  CodeGas cg; PersistentLineB pl; // use type B instead

  public Symbol getName() { return Symbol.GetSymbol("GraphBuilder"); }
  public void link(PortedProcessor p) { 
    pp = p; 
    pp.addClockListener(this);
    ag = (ActiveGradient)p.getModule("ActiveGradient");
    cg = (CodeGas)p.getModule("CodeGas");
    //pn = (PersistentNode)p.getModule("PersistentNode");
    pl = (PersistentLineB)p.getModule("PersistentLine");
  }
  public void init() {} // nothing needs to happen

  public boolean signalEvent(Symbol name,Object data) {
    boolean changed = false;
    if(name==PortedProcessor.kClock) {
    } 
    return changed;
  }

  public String toString() { return "GraphBuilder: "; }
}

// at each step, get codegas members.
// If named lambda: fix lambda and send out lambda gradient to eliminate
//   all others. After timeout, create node and begin build cycle.

// Build cycle: 
// at node N, send search out for node X [cannot be answered in < min-hops
// at nodes containing X, fix particle and send reply gradient.
// when N gets a reply, re-versions gradient to say "you win"
//  [note: N must be careful it's not twinned at that point]
// N also initiates its line-search at this point
// if X hears "you win", creates a node.
