-module(ex3a). -export([start/0,botonera/0, proxy/3,bucle_proxy/2]). start() -> spawn(ex3a, botonera, []). botonera()-> % Iniciar la botonera de 8 al node8 spawn( node8@TONIF, ex3b, proxy, [8, b8, self()]), % Crear la botonera de 8 a l’altre node %Iniciar la botonera de 2 L = proxy(2,b2,self()), % L -> Pid de la botonera de 2 bucle(L). bucle(L)-> receive {b2,clicked,Pis}-> if (Pis == 0) -> encen(0); (Pis == 1) -> encen(1) end, bucle(L); {b8,clicked,Pis}-> if (Pis rem 2 =:= 0) -> apaga(0); (Pis rem 2 =:= 1) -> apaga(1) end, bucle(L); {b8, abort} -> L!close, receive _ -> "ok" end; {b2, abort} -> {bot8, node8@TONIF}!close, receive _ -> "ok28" end end. proxy(N,Nom,Pid)->%N es la mida total B = spawn(ex3a,bucle_proxy,[Nom,Pid]), bots:nou(N,B). bucle_proxy(Nom,Pid)-> receive {clicked,Pis} -> Pid!{Nom,clicked,Pis}, bucle_proxy(Nom,Pid); abort -> Pid!{Nom,abort}, ok end. encen(Pis) -> if Pis < 6 -> %Mentres no has acabat ves incrementant Pis {bot8, node8@TONIF}!{light_on,Pis}, encen(Pis+2); Pis >= 6 -> % Si es mes gran que 7, per tant ja és l'ultim, 8, has acabat, torna al bucle {bot8, node8@TONIF}!{light_on,Pis} end. apaga(Pis)-> if Pis < 6 -> {bot8, node8@TONIF}!{light_off,Pis}, apaga(Pis+2); Pis >= 6 -> {bot8, node8@TONIF}!{light_off,Pis} end.