summaryrefslogtreecommitdiff
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
parentfcb91a8a32e79f52e31b68180ed50c123cac5cb1 (diff)
downloadvyconf-63ff0861f88229d5948dff88ac5217ceb8f32060.tar.gz
vyconf-63ff0861f88229d5948dff88ac5217ceb8f32060.zip
Add session module stub.
-rw-r--r--_oasis5
-rw-r--r--src/session.ml42
-rw-r--r--src/session.mli16
3 files changed, 63 insertions, 0 deletions
diff --git a/_oasis b/_oasis
index 3fc026f..f645e5a 100644
--- a/_oasis
+++ b/_oasis
@@ -44,6 +44,11 @@ Library "util"
FindlibParent: vyconf
BuildDepends: xml-light
+Library "session"
+ Path: src
+ Modules: Session
+ FindlibParent: vyconf
+
Executable "vyconfd"
Path: src
MainIs: vyconfd.ml
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)
+
diff --git a/src/session.mli b/src/session.mli
new file mode 100644
index 0000000..51e9292
--- /dev/null
+++ b/src/session.mli
@@ -0,0 +1,16 @@
+type cfg_op =
+ | CfgSet of string list * string option * Config_tree.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
+}
+
+val make : string -> Config_tree.t ref -> Reference_tree.t ref -> (string, string) Hashtbl.t -> session_data
+