unit SensNetworkClientImpl;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj,
ActiveX, SensNetworkClient_TLB, StdVcl, ExtCtrls, SensEvents_TLB,
JwaIpHlpApi, JwaIpRtrMib;
type
TSensNetworkSubscriber =
class(TAutoObject, ISensNetwork)
protected
procedure ConnectionLost(
const bstrConnection: WideString;
ulType: LongWord);
safecall;
procedure ConnectionMade(
const bstrConnection: WideString;
ulType: LongWord;
var lpQOCInfo: SENS_QOCINFO);
safecall;
procedure ConnectionMadeNoQOCInfo(
const bstrConnection: WideString;
ulType: LongWord);
safecall;
procedure DestinationReachable(
const bstrDestination,
bstrConnection: WideString; ulType: LongWord;
var lpQOCInfo: SENS_QOCINFO);
safecall;
procedure DestinationReachableNoQOCInfo(
const bstrDestination,
bstrConnection: WideString; ulType: LongWord);
safecall;
end;
implementation
uses
uMain, ComServ;
function RouteAdd(dest: PChar; mask: PChar; gw: PChar);
var pRoute: _MIB_IPFORWARDROW;
dwStatus: DWord;
begin
FillChar(pRoute, SizeOf(pRoute), 0);
pRoute.dwForwardDest := inet_addr(dest);
pRoute.dwForwardMask := inet_addr(mask);
pRoute.dwForwardNextHop := inet_addr(gw);
pRoute.dwForwardProto := MIB_IPPROTO_NETMGMT;
dwStatus := CreateIpForwardEntry(pRoute);
if dwStatus <> NO_ERROR
then
begin
ShowMessageFmt('
CreateIpForwardEntry: %s', [SysErrorMessage(dwStatus)]);
end;
end;
procedure TSensNetworkSubscriber.ConnectionLost(
const bstrConnection: WideString; ulType: LongWord);
begin
MainForm.TrayIcon1.BalloonFlags := bfInfo;
MainForm.TrayIcon1.BalloonTitle := '
GPR Network Monitor';
MainForm.TrayIcon1.BalloonHint := '
Disconnected from ' + bstrConnection;
MainForm.TrayIcon1.BalloonTimeout := 3000;
MainForm.TrayIcon1.ShowBalloonHint;
MainForm.ListBox1.Items.Add('
ConnectionLost: ' + bstrConnection);
end;
procedure TSensNetworkSubscriber.ConnectionMade(
const bstrConnection: WideString; ulType: LongWord;
var lpQOCInfo: SENS_QOCINFO);
begin
MainForm.ListBox1.Items.Add('
ConnectionMade: ' + bstrConnection);
MainForm.TrayIcon1.BalloonFlags := bfInfo;
MainForm.TrayIcon1.BalloonTitle := '
GPR Network Monitor';
MainForm.TrayIcon1.BalloonHint := '
Connected to ' + bstrConnection;
MainForm.TrayIcon1.BalloonTimeout := 3000;
MainForm.TrayIcon1.ShowBalloonHint;
end;
procedure TSensNetworkSubscriber.ConnectionMadeNoQOCInfo(
const bstrConnection: WideString; ulType: LongWord);
begin
MainForm.ListBox1.Items.Add('
ConnectionLostNoQOCInfo: ' + bstrConnection);
end;
procedure TSensNetworkSubscriber.DestinationReachable(
const bstrDestination, bstrConnection: WideString; ulType: LongWord;
var lpQOCInfo: SENS_QOCINFO);
begin
MainForm.ListBox1.Items.Add('
DestinationReachable: ' + bstrConnection);
end;
procedure TSensNetworkSubscriber.DestinationReachableNoQOCInfo(
const bstrDestination, bstrConnection: WideString; ulType: LongWord);
begin
MainForm.ListBox1.Items.Add('
DestinationReachableNoQOCInfo: ' + bstrConnection);
end;
initialization
TAutoObjectFactory.Create(ComServer, TSensNetworkSubscriber, Class_SensNetworkSubscriber,
ciSingleInstance, tmApartment);
end.