Listing processes might be one way to check for instances, maybe try to communicate with that instance to make sure it's not blocked. There was also a simple way to check using instance handle in C wich could be adapted to FPC but i don't know how it works in Unix world.
Razvan On 12/17/06, Luiz Americo Pereira Camara <[EMAIL PROTECTED]> wrote:
Al Boldi wrote: > Luiz Americo Pereira Camara wrote: > >> Kris Leech wrote: >> >>> Good stuff, did you come across any issues with simpleIPC, Ive been >>> meaning to have a go with it for a while... >>> >> I had two issues with simpleipc: >> - in unix the TSimpleIPCServer.OnMessage event is not fired. To >> override this, a solution is to call ReadMessage in the OnIdle event of >> the application. >> > > Try this implementation: > ======================== > type > > { TPeekThread } > TPeekThread = Class(TThread) > private > FDoPeek: TNotifyEvent; > protected > procedure Execute; override; > procedure Synchronize(Method: TThreadMethod); > Property DoPeek: TNotifyEvent read FDoPeek write FDoPeek; > end; > > { TSimpleIPCpServer } > TSimpleIPCpServer = Class(TSimpleIPCServer) > private > FPeek: Boolean; > FPeekThread: TPeekThread; > procedure PeekMethod(Sender: TObject); > procedure SetPeek(const AValue: Boolean); > protected > Procedure Activate; override; > Procedure Deactivate; override; > published > Property Peek : Boolean read FPeek write SetPeek; > end; > > implementation > > { TPeekThread } > procedure TPeekThread.Execute; > begin > repeat > FDoPeek(self); > until Terminated; > end; > > procedure TPeekThread.Synchronize(Method: TThreadMethod); > begin > inherited; > end; > > { TSimpleIPCpServer } > procedure TSimpleIPCpServer.PeekMethod(Sender: TObject); > begin > if PeekMessage(1000,false) then > TPeekThread(sender).Synchronize(@ReadMessage); > end; > > procedure TSimpleIPCpServer.SetPeek(const AValue: Boolean); > begin > if FPeek=AValue then exit; > if FActive then DoError(SErrActive,[]); > FPeek:=AValue; > end; > > procedure TSimpleIPCpServer.Activate; > begin > inherited Activate; > if FActive and FPeek then begin > FPeekThread:=TPeekThread.Create(true); > FPeekThread.DoPeek:[EMAIL PROTECTED]; > FPeekThread.FreeOnTerminate:=true; > FPeekThread.Resume; > end; > end; > > procedure TSimpleIPCpServer.Deactivate; > begin > if FActive and FPeek then begin > FPeekThread.Terminate; > end; > inherited Deactivate; > end; > ======================== > > Thanks. Another solution is to use the dnotify api of the kernel. Someone already tried dnotify with fpc? > BTW: Somebody know how to override a Classname, like it's possible with > Methods. i.e: TComponent = Class(TComponent); override; > > >> - The other is that there's currently no easy way to diferentiate >> between different message types. Let's say i need to send messages >> telling i started the job, send the results of the job and than finished >> the job. Currently there are two options: send a header in the stream >> with a numeric variable and check it when arrive (you lose the comodity >> of SendStringMessage) or you send a string with a string marker. I will >> propose a change in it (and provide the patch) where we could use the >> MessageType (user defined) to identify the message and we could still >> use SendStringMessage . >> > > Or you could use another SimpleIPC connection. > > >> - another potential problem (not tested) is that in unix a file is used >> to pass the messages. So if the program crashes the file may not be >> deleted and would give that the server is running. >> > > In unix it uses pipes. No problem when program crashes. > Good to know. I don't have experience with pipes. Luiz _________________________________________________________________ To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives
_________________________________________________________________ To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives