1 { Copyright (C) 2005-2017 Robin Green, Bas Steendijk, Peter Green
\r
2 For conditions of distribution and use, see copyright notice in zlib_license.
\r
4 which is included in the package
\r
5 -----------------------------------------------------------------------------
\r
14 Classes, SysUtils,Forms,fd_utils,LCLIntf,InterfaceBase,ExtCtrls;
\r
17 procedure lcoreinit;
\r
21 absolutemaxs_select = (sizeof(fdset)*8)-1;
\r
24 fdreverse:array[0..absolutemaxs_select] of tlasio;
\r
25 fdEventHandlers:array[0..absolutemaxs_select] of PEventHandler;
\r
26 fdflags:array[0..absolutemaxs_select] of byte;
\r
27 tasksoutstanding : boolean;
\r
29 tlazaruseventcore=class(teventcore)
\r
31 procedure processmessages; override;
\r
32 procedure messageloop; override;
\r
33 procedure exitmessageloop;override;
\r
34 procedure setfdreverse(fd : integer;reverseto : tlasio); override;
\r
35 procedure rmasterset(fd : integer;islistensocket : boolean); override;
\r
36 procedure rmasterclr(fd: integer); override;
\r
37 procedure wmasterset(fd : integer); override;
\r
38 procedure wmasterclr(fd: integer); override;
\r
39 procedure WaitHandleEvent(AData: PtrInt; AFlags: dword);
\r
40 procedure taskcb(Data: PtrInt);
\r
43 tlaztimerwrapperinterface=class(ttimerwrapperinterface)
\r
45 function createwrappedtimer : tobject;override;
\r
46 // procedure setinitialevent(wrappedtimer : tobject;newvalue : boolean);override;
\r
47 procedure setontimer(wrappedtimer : tobject;newvalue:tnotifyevent);override;
\r
48 procedure setenabled(wrappedtimer : tobject;newvalue : boolean);override;
\r
49 procedure setinterval(wrappedtimer : tobject;newvalue : integer);override;
\r
55 procedure tlazaruseventcore.taskcb(Data: PtrInt);
\r
58 tasksoutstanding := false;
\r
62 procedure tlazaruseventcore.WaitHandleEvent(AData: PtrInt; AFlags: dword);
\r
65 lasio:=fdreverse[AData];
\r
66 if lasio<>nil then lasio.handlefdtrigger((AFlags and G_IO_IN)<>0,(AFlags and G_IO_OUT)<>0);
\r
69 procedure tlazaruseventcore.processmessages;
\r
71 Application.ProcessMessages;
\r
73 procedure tlazaruseventcore.messageloop;
\r
77 procedure tlazaruseventcore.exitmessageloop;
\r
79 Application.Terminate;
\r
81 procedure tlazaruseventcore.setfdreverse(fd : integer;reverseto : tlasio);
\r
83 fdreverse[fd] := reverseto;
\r
86 procedure addfdflags(fd : integer;flags:byte);
\r
88 fdflags[fd]:=fdflags[fd] or flags;
\r
89 if fdEventHandlers[fd]=nil then begin
\r
90 fdEventHandlers[fd]:=AddEventHandler(fd,flags,tlazaruseventcore(eventcore).WaitHandleEvent,fd);
\r
93 SetEventHandlerFlags(fdEventHandlers[fd], fdflags[fd]);
\r
97 procedure removefdflags(fd : integer;flags:byte);
\r
99 if fdEventHandlers[fd]<>nil then begin
\r
100 fdflags[fd]:=fdflags[fd] and (not flags);
\r
101 if fdflags[fd]=0 then begin
\r
102 RemoveEventHandler(fdEventHandlers[fd]);
\r
103 fdEventHandlers[fd]:=nil;
\r
106 SetEventHandlerFlags(fdEventHandlers[fd], fdflags[fd]);
\r
111 procedure tlazaruseventcore.rmasterset(fd : integer;islistensocket : boolean);
\r
113 addfdflags(fd,G_IO_IN);
\r
115 procedure tlazaruseventcore.rmasterclr(fd: integer);
\r
117 removefdflags(fd,G_IO_IN);
\r
119 procedure tlazaruseventcore.wmasterset(fd : integer);
\r
121 addfdflags(fd,G_IO_OUT);
\r
124 procedure tlazaruseventcore.wmasterclr(fd: integer);
\r
126 removefdflags(fd,G_IO_OUT);
\r
129 procedure lazaddtask(ahandler:ttaskevent;aobj:tobject;awparam,alparam:longint);
\r
131 if not tasksoutstanding then Application.QueueAsyncCall(tlazaruseventcore(eventcore).taskcb,0);
\r
132 tasksoutstanding := true;
\r
135 function tlaztimerwrapperinterface.createwrappedtimer : tobject;
\r
137 result := ttimer.create(nil);
\r
139 procedure tlaztimerwrapperinterface.setontimer(wrappedtimer : tobject;newvalue:tnotifyevent);
\r
141 ttimer(wrappedtimer).ontimer := newvalue;
\r
143 procedure tlaztimerwrapperinterface.setenabled(wrappedtimer : tobject;newvalue : boolean);
\r
145 ttimer(wrappedtimer).enabled := newvalue;
\r
149 procedure tlaztimerwrapperinterface.setinterval(wrappedtimer : tobject;newvalue : integer);
\r
151 ttimer(wrappedtimer).interval := newvalue;
\r
155 procedure lcoreinit;
\r
157 if (inited) then exit;
\r
158 eventcore := tlazaruseventcore.create;
\r
159 onaddtask := lazaddtask;
\r
161 absolutemaxs := absolutemaxs_select;
\r