summaryrefslogtreecommitdiff
path: root/Simulator/include/database/Database.h
diff options
context:
space:
mode:
authorMDBijman <matthijs@bijman.org>2017-01-24 12:15:26 +0100
committerMDBijman <matthijs@bijman.org>2017-01-24 12:15:26 +0100
commit070ce923574dcc57435cb3fb2dfe86b6a38cd249 (patch)
treeffd69a842ac4ad22aaf7161f923b9f0b47c7147a /Simulator/include/database/Database.h
Initial code commit with organized dependencies
Diffstat (limited to 'Simulator/include/database/Database.h')
-rw-r--r--Simulator/include/database/Database.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/Simulator/include/database/Database.h b/Simulator/include/database/Database.h
new file mode 100644
index 00000000..6e8bfeef
--- /dev/null
+++ b/Simulator/include/database/Database.h
@@ -0,0 +1,74 @@
+#pragma once
+#include "simulation/Section.h"
+#include "modeling/ModelingTypes.h"
+
+#include <sqlite3.h>
+#include "simulation/Experiment.h"
+
+namespace Database
+{
+ /*
+ The Database class provides a wrapper for the sqlite interface.
+ */
+ class Database
+ {
+ public:
+ /*
+ Initializes a database with the given name. If it does not yet exist is creates a $name.db file.
+ */
+ explicit Database(char* name);
+
+ /*
+ Closes the database connection.
+ */
+ ~Database();
+
+ /*
+ Starts a sqlite transaction.
+ */
+ void startTransaction() const;
+
+ /*
+ Ends a sqlite transaction.
+ */
+ void endTransaction() const;
+
+ /*
+ Writes the history of the experiment to the database.
+ */
+ void writeExperimentHistory(Simulation::Experiment& simulation) const;
+
+ /*
+ Polls the database for new simulation sections to simulate.
+ If there are no rows in the table, this returns -1.
+ */
+ int pollQueuedExperiments() const;
+
+ /*
+ Removes a row of the queued simulation sections.
+ */
+ void dequeueExperiment(int id) const;
+
+
+ /*
+ Creates a simulation object from a simulation in the database.
+ */
+ Simulation::Experiment createExperiment(uint32_t id);
+
+ private:
+ /*
+ Sets the scheduler of the datacenter
+ */
+ Simulation::Scheduler* loadScheduler(uint32_t simulationSectionId) const;
+
+ DefaultDatacenter loadDatacenter(uint32_t datacenterId) const;
+
+ /*
+ Fills the datacenter with workloads from the database.
+ */
+ Simulation::WorkloadPool loadWorkloads(uint32_t traceId) const;
+
+ // The sqlite db connection.
+ sqlite3 *db;
+ };
+}