shrub/pkg/arvo/sys/vane/loch.hoon

198 lines
4.7 KiB
Plaintext
Raw Normal View History

2023-02-09 22:05:23 +03:00
:: %loch
!:
!? 164
::
=, loch
|= our=ship
=> |%
+$ move [p=duct q=(wite note gift)]
2023-02-24 01:16:58 +03:00
+$ note ~ :: out request $->
::$% $: %g :: to %gall
::$>(%deal task:gall) :: full transmission
::== ::
::== ::
2023-02-09 22:05:23 +03:00
::
2023-02-24 01:16:58 +03:00
+$ sign ~
::$% [%loch $>(%red gift)] :: read
:: [%loch $>(%read gift)]
::==
2023-02-09 22:05:23 +03:00
::
+$ loch-state
$: %0
unix-duct=duct
2023-02-16 00:35:09 +03:00
devices=(map @tas device)
commands=(list cmd)
2023-02-22 00:44:00 +03:00
pathing=(map dev duct)
2023-02-09 22:05:23 +03:00
==
::
2023-02-22 00:44:00 +03:00
+$ cmd [cmd=@tas =wut =dev =duct]
2023-02-16 00:35:09 +03:00
::
2023-03-24 18:20:02 +03:00
+$ device [name=@tas dat=(unit @) tus=@]
2023-02-09 22:05:23 +03:00
--
::
=>
~% %loch ..part ~
|%
++ per-event
=| moves=(list move)
|= [[now=@da =duct] state=loch-state]
::
|%
++ this .
:: %entry-points
::
:: +crud: handle failure of previous arvo event
::
2023-02-15 22:26:38 +03:00
++ crud [moves state]
2023-02-09 22:05:23 +03:00
:: +read: give back
::
++ read [moves state]
:: +trim: in response to memory pressue
::
++ trim [moves state]
:: +vega: learn of a kernel upgrade
::
++ vega [moves state]
:: %utilities
::
::+|
::
++ event-core .
--
--
::
=| loch-state
=* state -
|= [now=@da eny=@uvJ rof=roof]
=* loch-gate .
^?
|%
:: +call: handle a +task:loch request
::
2023-02-15 22:26:38 +03:00
++ call
2023-02-09 22:05:23 +03:00
|= $: hen=duct
dud=(unit goof)
wrapped-task=(hobo task)
==
^- [(list move) _loch-gate]
::
=/ =task ((harden task) wrapped-task)
2023-03-24 18:20:02 +03:00
::~& > ["loch call task:" task]
::~& >> ["loch hen:" hen]
2023-02-22 00:44:00 +03:00
::~& >> :* "loch"
::["unix duct" unix-duct:loch-gate]
::["devices" devices:loch-gate]
::["commands" commands:loch-gate]
::["pathing" pathing:loch-gate]
::==
2023-02-15 22:26:38 +03:00
::?^ dud
::~|(%loch-call-dud (mean tang.u.dud))
2023-02-22 00:44:00 +03:00
?+ -.task [~ loch-gate]
2023-02-16 00:35:09 +03:00
%born :: When born you need to wipe your current state
:- ~
2023-02-22 00:44:00 +03:00
loch-gate(unix-duct hen, commands [~], devices ~, pathing ~)
::
2023-02-16 00:35:09 +03:00
%read :: When you read you need to save the command and the wire to return the results
2023-02-24 23:28:29 +03:00
:- ~[[unix-duct.state %give [%read dev.task wut.task cmd.task cnt.task]]]
2023-02-22 00:44:00 +03:00
%_ loch-gate
2023-02-24 23:28:29 +03:00
pathing (~(put by pathing) dev.task hen)
==
::
%rite :: When you read you need to save the command and the wire to return the results
:- ~[[unix-duct.state %give [%rite dev.task wut.task cmd.task dat.task cnt.task]]]
%_ loch-gate
pathing (~(put by pathing) dev.task hen)
2023-02-22 00:44:00 +03:00
==
::
%devs
=/ dev +.task
2023-02-16 00:35:09 +03:00
:- ~
%_ loch-gate
devices (~(put by devices) name.dev [name.dev ~ stat.dev])
==
2023-02-22 00:44:00 +03:00
::
2023-02-24 01:16:58 +03:00
%seen
2023-02-22 00:44:00 +03:00
=/ duct (~(get by pathing) dev.task)
2023-03-24 18:20:02 +03:00
=/ device-save [dev.task `dat.task tus.task]
::~& >> ["devicesave" device-save]
2023-02-24 23:28:29 +03:00
:- ~[[+.duct %give %seen dev.task dat.task tus.task]]
%_ loch-gate
devices (~(put by devices) dev.task device-save)
==
2023-02-24 23:28:29 +03:00
::
%rote
=/ duct (~(get by pathing) dev.task)
2023-03-24 18:20:02 +03:00
=/ device-save [dev.task ~ tus.task]
2023-02-24 23:28:29 +03:00
:- ~[[+.duct %give %rote dev.task tus.task]]
%_ loch-gate
devices (~(put by devices) dev.task device-save)
==
2023-02-15 22:26:38 +03:00
==
2023-02-09 22:05:23 +03:00
:: +load: migrate an old state to a new loch version
::
++ load
|= old=loch-state
^+ loch-gate
2023-02-15 22:26:38 +03:00
~& >> "loch load:"
2023-02-09 22:05:23 +03:00
loch-gate(state old)
:: +scry: view state
::
:: %a scry out a list of devices
:: %d get a device's dat and tus
2023-02-09 22:05:23 +03:00
++ scry
^- roon
|= [lyc=gang car=term bem=beam]
^- (unit (unit cage))
=* ren car
=* why=shop &/p.bem
=* syd q.bem
=* lot=coin $/r.bem
=* tyl s.bem
2023-02-15 22:26:38 +03:00
~& >> "loch scry:"
~& >> ["lyc" lyc]
~& >> ["car" car]
~& >> ["bem" bem]
|^
:: only respond for the local identity, current timestamp
::
?. ?& =(&+our why)
=([%$ %da now] lot)
==
~
?+ car ~
%a (read-a lyc bem)
%d (read-d lyc bem)
==
:: +read-a: scry our list of devices
::
2023-03-14 22:58:23 +03:00
++ read-a
|= [lyc=gang bem=beam]
^- (unit (unit cage))
=/ devs ~(tap in ~(key by devices))
``[%noun !>(devs)]
:: +read d: get devices dat and tus
::
2023-03-14 22:58:23 +03:00
++ read-d
|= [lyc=gang bem=beam]
^- (unit (unit cage))
~& >>> ["lyc" lyc]
~& >>> ["bem" bem]
=* tyl -.s.bem
=/ devs (~(got by devices) tyl)
2023-03-24 18:20:02 +03:00
~& > devs
``[%noun !>(devs)]
--
2023-02-09 22:05:23 +03:00
::
2023-02-15 22:26:38 +03:00
++ stay
~& >> "loch stay:"
state
2023-02-09 22:05:23 +03:00
++ take
|= [tea=wire hen=duct dud=(unit goof) hin=sign]
^- [(list move) _loch-gate]
?^ dud
~|(%loch-take-dud (mean tang.u.dud))
::
2023-02-15 22:26:38 +03:00
~& >> "loch take:"
2023-02-09 22:05:23 +03:00
[~ loch-gate]
--