aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/concepts/Condition.ml2
-rw-r--r--lib/kernel/Initialization.ml1
-rw-r--r--lib/kernel/Session.ml27
-rw-r--r--lib/kernel/Session.mli3
-rw-r--r--lib/protocols/Session.ml23
-rw-r--r--lib/protocols/Session.mli13
6 files changed, 67 insertions, 2 deletions
diff --git a/lib/concepts/Condition.ml b/lib/concepts/Condition.ml
index a9082ad..16f02d0 100644
--- a/lib/concepts/Condition.ml
+++ b/lib/concepts/Condition.ml
@@ -1,5 +1,3 @@
-(* @uses Value -- renders property values in to_string_hum *)
-
type properties = (string, Value.value) BatMap.t
type ps = properties -> properties
diff --git a/lib/kernel/Initialization.ml b/lib/kernel/Initialization.ml
index 25c2b3d..3c8addb 100644
--- a/lib/kernel/Initialization.ml
+++ b/lib/kernel/Initialization.ml
@@ -18,5 +18,6 @@ module Make (S : Abstract.Storage.STORAGE) = struct
(Ok true) evaluators
in
let* _ = Registry.update registry "evaluator" None (Some evaluator_namespace) in
+ let* _ = Registry.update registry "session" None (Some (Namespace.make ())) in
Ok root
end
diff --git a/lib/kernel/Session.ml b/lib/kernel/Session.ml
new file mode 100644
index 0000000..75bf8c9
--- /dev/null
+++ b/lib/kernel/Session.ml
@@ -0,0 +1,27 @@
+module Make (S : Abstract.Storage.STORAGE) = struct
+ module SI = Storage.Make (S)
+ module B = Branch.Make (S)
+
+ class session storage state =
+ object (self)
+ inherit Lifecycle.null
+ inherit Identity.of_id
+ method to_string = "session"
+ val storage : S.connection = storage
+ val state : Protocols.Session.state Atomic.t = Atomic.make state
+ method state = Atomic.get state
+ method pin state' = Atomic.set state state'
+ method protocols = Protocols.[Directory.make self; Session.make self]
+ method list = Ok (BatFingerTree.singleton "branch")
+
+ method find =
+ function
+ | "branch" ->
+ SI.with_read storage (fun tx ->
+ B.load tx storage (Atomic.get state).Protocols.Session.snapshot )
+ |> Result.map Option.some
+ | _ -> Ok None
+ end
+
+ let make storage state = new session storage state |> Protocols.Handle.make
+end
diff --git a/lib/kernel/Session.mli b/lib/kernel/Session.mli
new file mode 100644
index 0000000..be4451b
--- /dev/null
+++ b/lib/kernel/Session.mli
@@ -0,0 +1,3 @@
+module Make (S : Abstract.Storage.STORAGE) : sig
+ val make : S.connection -> Protocols.Session.state -> Protocols.Handle.t
+end
diff --git a/lib/protocols/Session.ml b/lib/protocols/Session.ml
new file mode 100644
index 0000000..f740c1a
--- /dev/null
+++ b/lib/protocols/Session.ml
@@ -0,0 +1,23 @@
+module Error = struct
+ open Concepts.Condition
+
+ let not_a_session () =
+ condition "not-a-session" "A handle was expected to carry the session protocol and did not"
+ empty
+end
+
+type state = {branch: string; snapshot: Concepts.Hash.hash}
+
+class type implementation = object
+ method state : state
+ method pin : state -> unit
+end
+
+type Handle.protocol += Session of implementation
+type t = implementation
+
+let make impl = Session (impl :> implementation)
+let from handle = Handle.into handle (function Session impl -> Some impl | _ -> None)
+let require handle = from handle |> Option.to_result ~none:(Error.not_a_session ())
+let state i = Handle.invoke i (fun o -> o#state)
+let pin i state = Handle.invoke i (fun o -> o#pin state)
diff --git a/lib/protocols/Session.mli b/lib/protocols/Session.mli
new file mode 100644
index 0000000..141c250
--- /dev/null
+++ b/lib/protocols/Session.mli
@@ -0,0 +1,13 @@
+type state = {branch: string; snapshot: Concepts.Hash.hash}
+type t
+
+class type implementation = object
+ method state : state
+ method pin : state -> unit
+end
+
+val make : #implementation -> Handle.protocol
+val from : Handle.t -> t Handle.interface option
+val require : Handle.t -> (t Handle.interface, Concepts.Condition.condition) result
+val state : t Handle.interface -> state
+val pin : t Handle.interface -> state -> unit