Rework datastores

DatastoreAccess now has "targets". The target determines what datastores
are used for writing and reading data. There are three targets:
  Operational:
  - reads from operational, writes to running
  Startup:
  - reads from startup, writes to startup
  Running:
  - reads from running, writes to running

(the datastores types above correspond to the NMDA datastore types)

The need to define targets instead of just calling them "datastores" is
that the operational target doesn't actually use the operational
datastore for both writing and reading.

Change-Id: Iffb7034c27aba42d10d715e23a2c970031b9bd1b
diff --git a/src/netconf_access.cpp b/src/netconf_access.cpp
index ecd337e..3405fe3 100644
--- a/src/netconf_access.cpp
+++ b/src/netconf_access.cpp
@@ -15,11 +15,38 @@
 
 
 NetconfAccess::~NetconfAccess() = default;
+namespace {
+auto targetToDs_get(const DatastoreTarget target)
+{
+    switch (target) {
+    case DatastoreTarget::Operational:
+        return libnetconf::NmdaDatastore::Operational;
+    case DatastoreTarget::Running:
+        return libnetconf::NmdaDatastore::Running;
+    case DatastoreTarget::Startup:
+        return libnetconf::NmdaDatastore::Startup;
+    }
 
+    __builtin_unreachable();
+}
+
+auto targetToDs_set(const DatastoreTarget target)
+{
+    switch (target) {
+    case DatastoreTarget::Operational:
+    case DatastoreTarget::Running:
+        return libnetconf::NmdaDatastore::Candidate;
+    case DatastoreTarget::Startup:
+        return libnetconf::NmdaDatastore::Startup;
+    }
+
+    __builtin_unreachable();
+}
+}
 DatastoreAccess::Tree NetconfAccess::getItems(const std::string& path) const
 {
     Tree res;
-    auto config = m_session->getData(libnetconf::NmdaDatastore::Operational, (path != "/") ? std::optional{path} : std::nullopt);
+    auto config = m_session->getData(targetToDs_get(m_target), (path != "/") ? std::optional{path} : std::nullopt);
 
     if (config) {
         lyNodesToTree(res, config->tree_for());
@@ -119,7 +146,7 @@
 void NetconfAccess::doEditFromDataNode(std::shared_ptr<libyang::Data_Node> dataNode)
 {
     auto data = dataNode->print_mem(LYD_XML, 0);
-    m_session->editData(libnetconf::NmdaDatastore::Candidate, data);
+    m_session->editData(targetToDs_set(m_target), data);
 }
 
 void NetconfAccess::commitChanges()