(*---------------------------------------------------------------------------
  :Program.    Notify
  :Author.     Thomas Igracki
  :Address.    Obstallee 45, 1000 Berlin 20, W-Germany
  :E-Mail.     T.IGRACKI@BAMP.ZER
  :Version.    V1.0
  :Date.       08-Apr-92
  :Copyright.  Me
  :Language.   Oberon
  :Translator. Amiga Oberon 2.13d
  :Contents.   Modul zur Unterstützung von _einem_ Notify.
  :Usage.      IMPORT Notify
  :Remark.     OS2.0 Only!
---------------------------------------------------------------------------*)

MODULE Notify;
IMPORT
  s: SYSTEM, d: Dos, e: Exec;
TYPE
(* NotifyRequest nochmal definiert, da sie in Dos.mod falsch definiert ist! *)
  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;
   not : NotifyRequest;

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 *)
PROCEDURE StartNotify* (name: ARRAY OF CHAR): SHORTINT;
BEGIN
     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 RETURN -1 END;
END StartNotify;

BEGIN
     dos := d.dos;
CLOSE
     e.FreeSignal(not.signalNum); DosEndNotify(not);
END Notify.
