run.lisp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. (in-package :hurd-translator)
  2. (defmethod configure ((translator translator) flags)
  3. "Gets the bootstrap port to call fsys-startup and installs a new control port into the bucket."
  4. (with-port-deallocate (bootstrap (task-get-bootstrap-port))
  5. (let ((port (bucket-add-control-port (port-bucket translator))))
  6. (with-port-deallocate (right (get-send-right port))
  7. (setf (slot-value translator 'underlying-node)
  8. (fsys-startup bootstrap flags right :copy-send))))))
  9. (defmethod inner-run ((translator translator) demuxer)
  10. "Run the translator server."
  11. (let ((*translator* translator))
  12. (run-server (lambda (port in out)
  13. (declare (ignore port))
  14. (funcall demuxer in out))
  15. (port-bucket *translator*))))
  16. (defmethod setup-translator ((translator translator) &key flags)
  17. "Setup the translator to be ready to run."
  18. (configure translator flags)
  19. (when (running-p translator)
  20. (let* ((under (underlying-node translator))
  21. (stat (io-stat under)))
  22. (set-trans stat nil)
  23. (set-root stat t)
  24. (setf (root translator)
  25. (make-root-node translator
  26. (underlying-node translator)
  27. (make-stat stat)))
  28. t)))
  29. (defmethod run-translator ((translator translator)
  30. &key flags (demuxer #'translator-demuxer))
  31. "Setup the translator and then run it."
  32. (setup-translator translator :flags flags)
  33. (inner-run translator demuxer))
  34. (defun calculate-miliseconds (seconds miliseconds)
  35. "Return total of miliseconds."
  36. (+ (* 1000 seconds) miliseconds))
  37. (defun wait (&key (seconds 0) (miliseconds 0) (demuxer #'translator-demuxer))
  38. "Runs the translator server during 'seconds' seconds and 'miliseconds' miliseconds."
  39. (unless (and (zerop seconds)
  40. (zerop miliseconds))
  41. (when (running-p *translator*)
  42. (run-server (lambda (port in out)
  43. (declare (ignore port))
  44. (funcall demuxer in out))
  45. (port-bucket *translator*)
  46. (calculate-miliseconds seconds miliseconds)))))