(*---------------------------------------------------------------------------
  :Program.    Notify
  :Author.     Thomas Igracki
  :Address.    Obstallee 45, 1000 Berlin 20, W-Germany
  :E-Mail.     T.IGRACKI@BAMP.ZER
  :Version.    V1.21
  :Date.       27-Apr-92
  :Copyright.  Me
  :Language.   Oberon
  :Translator. Amiga Oberon 2.13d
  :Contents.   Modul zur Unterstützung von _einem_ Notify.
  :Usage.      IMPORT Notify
  :History.    DosEndNotify() wurde auch aufgerufen, wenn kein Notify gestartet wurde! 
  :History.    V1.2: EndNotify() zum vorzeitigen Beenden eines Notifies.
  :History.    V1.2: StartNotify() gibt bei mehrmaligen Aufruf -1 zurück.
  :History.    V1.21:Bug in StartNotify() behoben! (Dank an HARTMUT@ASN.ZER!)
  :Remark.     OS2.0 Only!
  :Remark.     Bei >= V2.14 des OberonCompilers, kann man sich das neudefinieren
  :Remark.     der NotifyRequest Struktur und der StartNotify() und EndNotify()
  :Remark.     Prozeduren sparen (siehe auch Kommentare)!
---------------------------------------------------------------------------*)

MODULE Notify;
IMPORT
  s: SYSTEM, d: Dos, e: Exec;
TYPE
(* NotifyRequest nochmal definiert, da sie in Dos.mod falsch definiert ist! *)
(* Nur bei < V2.14 des OberonCompilers! *)
  NotifyRequest * = STRUCT
    name * : e.STRPTR;
    fullName * : e.STRPTR;           (* set by dos - don't touch *)
    userData * : LONGINT;            (* for applications use *)
    flags * : LONGSET;

    (* port * : e.MsgPortPtr; das war der Fehler! *)

    task * : e.TaskPtr;              (* could also be: port * : e.MsgPortPtr *)
    signalNum * : SHORTINT;
    pad1,pad2,pad3: SHORTINT;

    reserved * : ARRAY 4 OF LONGINT; (* leave 0 for now *)

    (* internal use by handlers *)
    msgCount * : LONGINT;            (* # of outstanding msgs *)
    handler  * : e.MsgPortPtr;       (* handler sent to (for EndNotify) *)
  END;

VAR
   dos : d.DosLibraryPtr; (* Nur bei < V2.14 des OberonCompilers! *)
   not : NotifyRequest;

(* Die nächsten beiden Prozeduren nur bei < V2.14 des OberonCompilers! *)
PROCEDURE DosStartNotify {dos,-888}(VAR notify{1}: NotifyRequest): BOOLEAN;
PROCEDURE DosEndNotify   {dos,-894}(VAR notify{1}: NotifyRequest);

(* Das Signal wird zurückgegeben, oder -1 wenn was falsch lief *)
(* $CopyArrays- *)
PROCEDURE StartNotify* (name: ARRAY OF CHAR): SHORTINT;
BEGIN
     IF not.name # NIL THEN RETURN -1 END;
     not.name := s.ADR(name); not.flags := LONGSET{d.sendSignal};
     not.task := e.exec.thisTask; not.signalNum := e.AllocSignal(-1);
     IF not.signalNum = -1 THEN RETURN -1 END;
     IF DosStartNotify(not) THEN
        RETURN not.signalNum 
     ELSE
        e.FreeSignal(not.signalNum); not.name := NIL; RETURN -1
     END;
END StartNotify;

PROCEDURE EndNotify*;
BEGIN
     IF not.name # NIL THEN
        DosEndNotify(not); e.FreeSignal(not.signalNum); not.name := NIL;
     END;     
END EndNotify;

BEGIN
     dos := d.dos; (* Nur bei < V2.14 des OberonCompilers! *)
CLOSE
     EndNotify
END Notify.
