/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package CREATOR_CONDICTIONS_RULES;
import LOGIC.Instance;
import LOGIC.Protocols;
import java.util.LinkedList;
/**
*
* @author sarah
*/
public class CreatorOutputFunction {
private LinkedList<Instance> instance;
private String creatorFunction = "";
private LinkedList<String> prot_imp_outputs;
private LinkedList<Protocols> prot;
private LinkedList<String> pegarProtRIO;
private CreatorNamesOfProcessCSP creatNamePcsp;
private LinkedList<String> nomecanal;
private String eventoprotocol1 = "";
private String eventoprotocol2 = "";
public CreatorOutputFunction(LinkedList<Instance> i,LinkedList<Protocols> p){
this.instance = i;
this.prot = p;
pegarProtRIO = new LinkedList<>();
creatNamePcsp = new CreatorNamesOfProcessCSP(i, p);
nomecanal = new LinkedList<>();
nomecanal.add(p.get(0).getCanal().getName().replace(".","_"));
nomecanal.add(p.get(1).getCanal().getName().replace(".","_"));
prot_imp_outputs = new LinkedList<>();
//esse comportamento pode ser manual, pois a ferramenta recebe
//sempre dois componentes
prot_imp_outputs.add("PROT_IMP_"+ instance.get(0).getName() +
"_"+nomecanal.get(0));
prot_imp_outputs.add("PROT_IMP_"+ instance.get(1).getName() +
"_"+nomecanal.get(1));
//
prot_imp_outputs.add("PROT_IMP_"+instance.get(0).getName()+
"_"+nomecanal.get(0)+"_R_IO_"
+nomecanal.get(1));
prot_imp_outputs.add("PROT_IMP_"+instance.get(1).getName()+
"_"+nomecanal.get(1)+"_R_IO_"+
nomecanal.get(0));
//
prot_imp_outputs.add("DUAL_PROT_IMP_"+instance.get(0).getName()+
"_"+nomecanal.get(0)+"_R_IO_"+
nomecanal.get(1));
//
prot_imp_outputs.add("DUAL_PROT_IMP_"+instance.get(1).getName()+
"_"+nomecanal.get(1)+"_R_IO_"+
nomecanal.get(0));
//pegando o nome do evento que passei por paramentro no protocolo
int pr1, pr2, pr3, pr4;
pr1 = p.get(0).getProtocol().indexOf("(");
pr2 = p.get(0).getProtocol().lastIndexOf(")");
eventoprotocol1 = p.get(0).getProtocol().substring(pr1 + 1, pr2);
pr3 = p.get(1).getProtocol().indexOf("(");
pr4 = p.get(1).getProtocol().lastIndexOf(")");
eventoprotocol2 = p.get(1).getProtocol().substring(pr3 + 1, pr4);
}
public String creatorOutputFunction() {
pegarProtRIO = creatNamePcsp.CreatorProt_RIO();
int cont = 0;
//função outputs
creatorFunction = creatorFunction + "\n outputs( P ) = ";
creatorFunction = creatorFunction + "\n \t let f =\n\t < ";
for (Instance instance1 : instance) {// para cada objeto pertencente a lista inst, execute o que est[a logo a baixo
creatorFunction = creatorFunction + "\n\t ( " + instance1.getName() + ", {| ";
// coloca todos os canais de out associado com seus tipos. ex: {|c.1, c.2|}
for (int i = 0; i < instance1.getOut().size(); i++) {
if (i == instance1.getOut().size() - 1) {
creatorFunction = creatorFunction + instance1.getOut().get(i).getEvento();
} else {
creatorFunction = creatorFunction + instance1.getOut().get(i).getEvento() + ",";
}
}
//if (cont == instance.size() - 1) {
// creatorFunction = creatorFunction + " |})";
//} else {
creatorFunction = creatorFunction + " |}),";
//}
cont++;
}
creatorFunction = creatorFunction + "\n\t";
creatorFunction = creatorFunction + "("+ prot_imp_outputs.get(0)+","+
"outputs_PROT_IMP("
+instance.get(0).getName()+","+eventoprotocol1+
")),";
creatorFunction = creatorFunction + "\n\n\t";
creatorFunction = creatorFunction + "("+ prot_imp_outputs.get(1)+","
+"outputs_PROT_IMP("
+instance.get(1).getName()+","+eventoprotocol2+
")),";
creatorFunction = creatorFunction + "\n\n\t";
creatorFunction = creatorFunction + "("+ prot_imp_outputs.get(2)+","+
"outputs_R_IO("+instance.get(0).getName()
+","+eventoprotocol1+","+
eventoprotocol2+")),";
creatorFunction = creatorFunction + "\n\n\t";
creatorFunction = creatorFunction + "("+ prot_imp_outputs.get(3)+","
+"outputs_R_IO("+instance.get(1).getName()
+","+eventoprotocol2+","+
eventoprotocol1+")),";
creatorFunction = creatorFunction + "\n\n\t";
creatorFunction = creatorFunction + "("+ prot_imp_outputs.get(4)+
","+"inputs("+pegarProtRIO.get(0)+")),";
creatorFunction = creatorFunction + "\n\n\t";
creatorFunction = creatorFunction + "("+ prot_imp_outputs.get(5)+
","+"inputs("+pegarProtRIO.get(1)+"))";
creatorFunction = creatorFunction + "\n \t > \n";
creatorFunction = creatorFunction + "\n \t within apply(f, P )";
creatorFunction = creatorFunction + "\n\n";
return creatorFunction;
}
}