summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/muniad.cc15
-rw-r--r--src/taskmanager.cc15
-rw-r--r--src/taskmanager.h4
3 files changed, 25 insertions, 9 deletions
diff --git a/src/muniad.cc b/src/muniad.cc
index 741241a..b9651dd 100644
--- a/src/muniad.cc
+++ b/src/muniad.cc
@@ -38,6 +38,8 @@
#include "http.h"
#include "munia_proto.h"
#include "debug.h"
+#include "taskmanager.h"
+extern TaskManager task_manager;
static struct libwebsocket_protocols protocols[] = {
// first protocol must always be HTTP handler
@@ -51,6 +53,7 @@ static struct libwebsocket_protocols protocols[] = {
static struct option options[] = {
{ "help", no_argument, NULL, 'h' },
{ "port", required_argument, NULL, 'p' },
+ { "file", required_argument, NULL, 'f' },
{ "ssl", no_argument, NULL, 's' },
{ "killmask", no_argument, NULL, 'k' },
{ "interface", required_argument, NULL, 'i' },
@@ -60,6 +63,7 @@ static struct option options[] = {
int main(int argc, char **argv)
{
+ const char *db_filename = "/tmp/munia.xml";
int n = 0;
const char *cert_path =
LOCAL_RESOURCE_PATH"/libwebsockets-test-server.pem";
@@ -84,7 +88,7 @@ int main(int argc, char **argv)
"There is NO WARRANTY, to the extent permitted by law.\n");
while(n >= 0) {
- n = getopt_long(argc, argv, "ci:khsp:", options, NULL);
+ n = getopt_long(argc, argv, "ci:khsp:f:", options, NULL);
if(n < 0) continue;
switch(n) {
case 's':
@@ -98,19 +102,24 @@ int main(int argc, char **argv)
case 'p':
port = atoi(optarg);
break;
- case 'i':
+ case 'f':
+ db_filename = strdup(optarg);
+ break;
+ case 'i':
strncpy(interface_name, optarg, sizeof interface_name);
interface_name[(sizeof interface_name) - 1] = '\0';
interface = interface_name;
break;
case 'h':
- fprintf(stderr, "Usage: muniad [--port=<p>] [--ssl]\n");
+ fprintf(stderr, "Usage: muniad [--port=<p>] [--ssl] [--file=<f>]\n");
exit(1);
}
}
debug_parse("+all");
+ task_manager.init(db_filename);
+
if(!use_ssl) cert_path = key_path = NULL;
context = libwebsocket_create_context(port, interface, protocols,
diff --git a/src/taskmanager.cc b/src/taskmanager.cc
index 0d15eb6..c7cdb6d 100644
--- a/src/taskmanager.cc
+++ b/src/taskmanager.cc
@@ -44,10 +44,18 @@ static bool isProtected(taskid_t id)
return id < FIRST_TASK_ID;
}
-TaskManager::TaskManager(std::string file) {
+TaskManager::TaskManager() {
idCount = FIRST_TASK_ID;
- this->file = file;
+}
+
+TaskManager::~TaskManager() {
+}
+
+void TaskManager::init(std::string filename)
+{
+ printf("Reading tasks from file: %s\n", filename.c_str());
+ file = filename;
FILE *fp = fopen(file.c_str(), "r");
if(fp) {
@@ -87,9 +95,6 @@ TaskManager::TaskManager(std::string file) {
tree.toStdOut();
}
-TaskManager::~TaskManager() {
-}
-
task_t TaskManager::task(taskid_t t) {
return tree.data(t);
}
diff --git a/src/taskmanager.h b/src/taskmanager.h
index 52daa05..e11736b 100644
--- a/src/taskmanager.h
+++ b/src/taskmanager.h
@@ -40,9 +40,11 @@ typedef std::pair<TaskIdList, TaskIdList> TaskIdListPair;
class TaskManager {
public:
- TaskManager(std::string file = "/tmp/munia.xml");
+ TaskManager();
~TaskManager();
+ void init(std::string filename);
+
TaskIdList createTask(taskid_t parentid, taskid_t *id) throw (std::exception);
TaskIdList updateTask(taskid_t id, task_t task) throw (std::exception);
TaskIdList removeTask(taskid_t id) throw (std::exception);