aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/Session.ml
blob: 322d0e0b2745d37c975367f8d00b1b3ebcfd56c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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.exclusive
      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