summaryrefslogtreecommitdiff
path: root/src/session.ml
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2015-09-23 06:37:02 +0600
committerDaniil Baturin <daniil@baturin.org>2015-09-23 06:37:02 +0600
commit63ff0861f88229d5948dff88ac5217ceb8f32060 (patch)
treeee3f038982ff147e9539cb0529b8b3259f00c8da /src/session.ml
parentfcb91a8a32e79f52e31b68180ed50c123cac5cb1 (diff)
downloadvyconf-63ff0861f88229d5948dff88ac5217ceb8f32060.tar.gz
vyconf-63ff0861f88229d5948dff88ac5217ceb8f32060.zip
Add session module stub.
Diffstat (limited to 'src/session.ml')
-rw-r--r--src/session.ml42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/session.ml b/src/session.ml
new file mode 100644
index 0000000..5b99a4b
--- /dev/null
+++ b/src/session.ml
@@ -0,0 +1,42 @@
+module CT = Config_tree
+
+type cfg_op =
+ | CfgSet of string list * string option * CT.value_behaviour
+ | CfgDelete of string list * string option
+
+type session_data = {
+ id: string;
+ running_config: Config_tree.t ref;
+ proposed_config : Config_tree.t ref;
+ reference_tree: Reference_tree.t ref;
+ validators: (string, string) Hashtbl.t;
+ modified: bool;
+ changeset: cfg_op list
+}
+
+let make i c r v = {
+ id = i;
+ running_config = c;
+ proposed_config = c;
+ reference_tree = r;
+ validators = v;
+ modified = false;
+ changeset = []
+}
+
+let set_modified s =
+ if s.modified = true then s
+ else {s with modified = true}
+
+let apply_cfg_op op config =
+ match op with
+ | CfgSet (path, value, value_behaviour) ->
+ CT.set config path value value_behaviour
+ | CfgDelete (path, value) ->
+ CT.delete config path value
+
+let rec apply_changes changeset config =
+ match changeset with
+ | [] -> config
+ | c :: cs -> apply_changes cs (apply_cfg_op c config)
+