protid.lisp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. (in-package :hurd-translator)
  2. ;;
  3. ;; This file implements protid's.
  4. ;; They group a user and a open node.
  5. ;;
  6. (defclass protid (port-info)
  7. ((user :initform nil
  8. :initarg :user
  9. :accessor user
  10. :documentation "The user that opened the node.")
  11. (open-node :initform nil
  12. :initarg :open-node
  13. :accessor open-node
  14. :documentation "The open node."))
  15. (:documentation "The protid class."))
  16. (defun make-protid (user open-node)
  17. "Create a new protid."
  18. (make-instance 'protid
  19. :user user
  20. :open-node open-node))
  21. (defmethod get-stat ((protid protid))
  22. "Get stat information about the node opened."
  23. (stat (get-node protid)))
  24. (defmethod get-box ((protid protid))
  25. "Get the transbox from the node."
  26. (box (get-node protid)))
  27. (defmethod get-node ((protid protid))
  28. "Get the opened node."
  29. (refers (open-node protid)))
  30. (defmethod get-user ((protid protid))
  31. "Get the user."
  32. (slot-value protid 'user))
  33. (defmethod get-shadow-root ((protid protid))
  34. "Get the shadow root."
  35. (shadow-root (open-node protid)))
  36. (defmethod get-shadow-root-parent ((protid protid))
  37. "Get the shadow root parent."
  38. (shadow-root-parent (open-node protid)))
  39. (defmethod get-root-parent ((protid protid))
  40. "Get the root parent."
  41. (root-parent (open-node protid)))
  42. (defmethod get-open-flags ((protid protid))
  43. "Get the open flags."
  44. (flags (open-node protid)))
  45. (defmethod initialize-node ((node node))
  46. (tg:finalize node
  47. (lambda ()
  48. (pre-drop-node node)
  49. (when *translator*
  50. (drop-node *translator* node)))))
  51. (defmethod initialize-instance :after ((protid protid) &key)
  52. "Increment number of user nodes. If current count is 0, report it."
  53. (let ((node (get-node protid)))
  54. (when (zerop (num-users node))
  55. (report-new-user *translator* node))
  56. (inc-users node)))
  57. (defmethod port-cleanup :after ((protid protid))
  58. "When cleaning up this port, decrease number of users. Report it if it drops to 0."
  59. (let ((node (get-node protid)))
  60. (dec-users node)
  61. (when (zerop (num-users node))
  62. (report-no-users *translator* node))))