aboutsummaryrefslogtreecommitdiffstats
path: root/lib/session.ml
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-09-26 23:01:03 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-09-26 23:01:03 -0300
commit818b77f04452c7cb8d7cb4e77c23312901e5a4bd (patch)
treedea3d25643f9c0f4256fca125b83d277a1068719 /lib/session.ml
parent320954996e921d7b34eb61f462799b5c6ab8ee09 (diff)
downloadSakura-818b77f04452c7cb8d7cb4e77c23312901e5a4bd.tar.gz
Sakura-818b77f04452c7cb8d7cb4e77c23312901e5a4bd.zip
listener working under RNT with a minimal drl
Diffstat (limited to 'lib/session.ml')
-rw-r--r--lib/session.ml36
1 files changed, 10 insertions, 26 deletions
diff --git a/lib/session.ml b/lib/session.ml
index ba4d96d..ca129d1 100644
--- a/lib/session.ml
+++ b/lib/session.ml
@@ -1,30 +1,15 @@
-type t = {identifier: string; branch: string; snapshot: string; commit: unit}
+let path_of identifier = "\\session\\" ^ identifier
-let namespace identifier = "\\session\\" ^ identifier
-let branch_path name = "\\branch\\" ^ name
-
-let snapshot_of kernel branch =
- let open Utilities.Result in
- let* handle = RNT.lookup kernel (branch_path branch) in
- let snapshot = RNT.identity handle in
- RNT.release handle; Ok snapshot
-
-class session ~kernel ~identifier ~branch ~snapshot ~commit =
+class session ~kernel ~identifier =
object
- val mutable session : t = {identifier; branch; snapshot; commit}
- method identifier = session.identifier
- method branch = session.branch
- method snapshot = session.snapshot
- method namespace = namespace session.identifier
+ method identifier = identifier
+ method path = path_of identifier
+ method state = RNT.session kernel (path_of identifier)
(** Switch to a different branch within the same session. *)
- method set_branch_to branch =
- let open Utilities.Result in
- let* snapshot = snapshot_of kernel branch in
- session <- {session with branch; snapshot};
- Ok ()
+ method set_branch_to branch = RNT.pin kernel (path_of identifier) branch
- method close = RNT.remove kernel (namespace session.identifier)
+ method close = RNT.remove kernel (path_of identifier)
end
(* Open a session on a live (mutable) branch.
@@ -34,12 +19,11 @@ let open_session kernel ~branch_name =
let* branches = RNT.list kernel "\\branch" in
let* () =
if List.mem branch_name branches then Ok ()
- else RNT.create kernel (branch_path branch_name) RNT.Branch
+ else RNT.create kernel ("\\branch\\" ^ branch_name) RNT.Branch
in
- let* snapshot = snapshot_of kernel branch_name in
let identifier = Printf.sprintf "%016Lx" (Random.State.bits64 (Random.State.make_self_init ())) in
- let* () = RNT.create kernel (namespace identifier) RNT.Namespace in
- Ok (new session ~kernel ~identifier ~branch:branch_name ~snapshot ~commit:())
+ let* () = RNT.create kernel (path_of identifier) (RNT.Session branch_name) in
+ Ok (new session ~kernel ~identifier)
(* Open a session pinned to a specific snapshot hash (detached / read-only).
Mutations through the returned branch are refused. *)