|
{
|
|
Adtos 1.0 Software de gestión de Aulas Tecnológicas
|
|
Copyright (C) 2008-2009, Consejería de Educación,Junta de Extremadura
|
|
Programación: Manuel Narváez Martínez <mnarvaez007@gmail.com>
|
|
Diseño gráfico: Ana María Zamora Moreno
|
|
Desarrollado con Lazarus 0.9.26
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
}
|
|
unit clpingequipo;
|
|
|
|
interface
|
|
|
|
uses
|
|
globales,SysUtils,Classes, IdComponent, IdTCPClient;
|
|
|
|
type
|
|
ThrPingEquipo = class(TThread)
|
|
private
|
|
{ Private declarations }
|
|
fEstadoActividad:TEstadoActividadEquipo;
|
|
fNumero:integer;
|
|
fIP:string;
|
|
fUsuario:string;
|
|
fPuerto:integer;
|
|
fcliente: TIdTCPClient;
|
|
fFinEncendiendo,fFinApagando:Boolean;
|
|
procedure refrescarConectados;
|
|
protected
|
|
procedure Execute; override;
|
|
public
|
|
constructor Create(puerto:integer;numero:integer;ip:string;EstadoActividad:TEstadoActividadEquipo;usuario:String;finEncendiendo:Boolean=false;finApagando:Boolean=false);
|
|
end;
|
|
|
|
|
|
implementation
|
|
uses inicio;
|
|
constructor ThrPingEquipo.Create(puerto:integer;numero:integer;ip:string;EstadoActividad:TEstadoActividadEquipo;usuario:String;finEncendiendo:Boolean=false;finApagando:Boolean=false);
|
|
begin
|
|
|
|
|
|
Priority:=tpTimeCritical;
|
|
fFinEncendiendo:=finEncendiendo;
|
|
fFinApagando:=finApagando;
|
|
fPuerto:=puerto;
|
|
fNumero:=numero;
|
|
fEstadoActividad:=EstadoActividad;
|
|
fIP:=ip;
|
|
fUsuario:=usuario;
|
|
inherited Create(true);
|
|
FreeOnTerminate:=True;
|
|
|
|
end;
|
|
|
|
procedure ThrPingEquipo.Execute;
|
|
var
|
|
miUsuario:String;
|
|
miEstadoCambiado:Boolean;
|
|
miEstado:TEstadoActividadEquipo;
|
|
begin
|
|
try
|
|
miEstadoCambiado:=false;
|
|
if fEstadoActividad=eAveriado then exit;
|
|
miUsuario:='';
|
|
try
|
|
fcliente:=TIdTCPClient.Create(nil);
|
|
fcliente.Host:=fIP;
|
|
fcliente.port:=PUERTO_ROOT;
|
|
//fcliente.ConnectTimeout:=2000;
|
|
fcliente.connect;
|
|
fcliente.GetResponse(200);
|
|
sleep(50);
|
|
fcliente.SendCmd('hallarUsurio',306);
|
|
miUsuario:= trim(fcliente.LastCmdResult.text.text);
|
|
// writeln('...................................................');
|
|
// writeln('Soy el equipo ' +inttostr(fNumero), fusuario);
|
|
// writeln('...................................................');
|
|
if length(miUsuario)>0 then
|
|
begin
|
|
if (fEstadoActividad<>eUsuario) or (miUsuario<>fUsuario) then
|
|
miEstadoCambiado:=true;
|
|
fEstadoActividad:=eUsuario;
|
|
fUsuario:=miUsuario;
|
|
end
|
|
else
|
|
begin
|
|
case fEstadoActividad of
|
|
eApagando: if fFinApagando then miEstado:=eEncendido else miEstado:=eApagando;
|
|
eEncendido,eUsuario,eApagado,eEncendiendo: miEstado:=eEncendido;
|
|
end;
|
|
if miEstado<>fEstadoActividad then miEstadoCambiado:=true;
|
|
fEstadoActividad:=miEstado;
|
|
|
|
end;
|
|
except
|
|
begin
|
|
case fEstadoActividad of
|
|
eEncendiendo: if fFinEncendiendo then miEstado:=eApagado else miEstado:=eEncendiendo;
|
|
eEncendido,eUsuario,eApagado,eApagando: miEstado:=eApagado;
|
|
end;
|
|
if miEstado<>fEstadoActividad then miEstadoCambiado:=true;
|
|
fEstadoActividad:=miEstado;
|
|
//writeln(inttostr(fnumero) +' error al conectar '+ fip);
|
|
end;
|
|
end;
|
|
finally
|
|
try
|
|
if fcliente.Connected then fcliente.Disconnect;
|
|
finally
|
|
if miEstadoCambiado then Synchronize(@refrescarConectados);
|
|
fcliente.Free;
|
|
end;
|
|
// writeln('...................................................');
|
|
end
|
|
end;
|
|
|
|
|
|
procedure ThrPingEquipo.refrescarConectados;
|
|
begin
|
|
frmMain.RefrescarEquipoAulaNuevo(fNumero,fEstadoActividad,fUsuario);
|
|
|
|
end;
|
|
|
|
end.
|