;;;
;;; process.lisp
;;;
;;; Process abstraction, events, etc.
;;;

(cl:in-package :lh-debug-core)


;;; The process class.

(defclass process ()
  (status
   (event-function :initform nil)))


;;; Event-function stuff.

;; An event function is a function with an arglist of (process event
;; &rest args), and is called when the state of a process changes.
;;
;; Valid events and extra arguments are as follows:
;;
;;    :attaching -- The process is being attached to, but has not yet
;;    stopped.
;;
;;    :running -- The process is running.
;;
;;    :exited exit-code -- The process has exited with code exit-code.
;;
;;    :killed terminating-signal core-dumped -- The process has been
;;    killed with signal terminating-signal.  If core-dumped is true,
;;    a core file was created.
;;
;;    :detached -- The process has been detached from.
;;
;;    :stopped stop-signal -- The process has stopped upon receiving
;;    signal stop-signal.
;;
;;    :event event-code -- A "ptrace event" has occurred.  Event-code
;;    is one of the ptrace-event constants.  If event-code is one of
;;    ptrace-event-fork, ptrace-event-vfork or ptrace-event-clone, the
;;    pid of a new (stopped with SIGSTOP) process/thread is available
;;    via ptrace-geteventmsg.
;;
;;    :syscall -- The process has stopped just prior to executing a
;;    system call.

(defgeneric call-event-function (process event &rest args))

(defmethod call-event-function ((process process) event &rest args)
  (with-slots (event-function) process
    (when event-function
      (apply event-function process event args))))

(defun (setf event-function) (function process)
  (setf (slot-value process 'event-function) function))


;;; Basic interface methods.

(defgeneric update-process-status (process &key wait))

(defgeneric detach-from-process (process &optional signal-number))

(defgeneric resume-process (process &key send-signal resume-mode))


;;; EOF
