summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2020-06-06 16:04:40 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2020-06-06 16:04:40 +0200
commit9e81fcd4bdb089b8f8a05c6fbb586ec2a2a14924 (patch)
tree176d25ee9d55ca82c6d04bfe04891c3dcf8b0384 /src
parent1ae51ff94d0f1f27a4e4cc657371578db13c3ca1 (diff)
Change 'observe' to 'subscribe' (and incidentally 'publish') which is more common lingo.
Diffstat (limited to 'src')
-rw-r--r--src/connectionhandler.cc38
-rw-r--r--src/connectionhandler.h8
-rw-r--r--src/message.h32
-rw-r--r--src/messagehandler.cc28
-rw-r--r--src/messageparser.cc20
-rw-r--r--src/munia_proto.cc32
-rw-r--r--src/muniacli.cc8
-rw-r--r--src/taskmanager.cc4
-rw-r--r--src/testclient.cc18
9 files changed, 96 insertions, 92 deletions
diff --git a/src/connectionhandler.cc b/src/connectionhandler.cc
index d264abe..4cf8fc0 100644
--- a/src/connectionhandler.cc
+++ b/src/connectionhandler.cc
@@ -74,27 +74,27 @@ bool ConnectionHandler::authenticated(clientid_t clientid)
return authlist.find(clientid) != authlist.end() && authlist[clientid];
}
-void ConnectionHandler::observe(clientid_t clientid, taskid_t taskid)
+void ConnectionHandler::subscribe(clientid_t clientid, taskid_t taskid)
{
connlist[clientid].insert(taskid);
- DEBUG(conn, "Added observer of %d\n", taskid);
+ DEBUG(conn, "Added subscriber of %d\n", taskid);
}
-void ConnectionHandler::unobserve(clientid_t clientid, taskid_t taskid)
+void ConnectionHandler::unsubscribe(clientid_t clientid, taskid_t taskid)
{
connlist[clientid].erase(taskid);
}
-ObserverList ConnectionHandler::observerlist(TaskIdList tasks)
+SubscriberList ConnectionHandler::subscriberlist(TaskIdList tasks)
{
- DEBUG(conn, "Observerlist request (#tasks: %d)\n", (int)tasks.size());
- ObserverList clients;
+ DEBUG(conn, "Subscriberlist request (#tasks: %d)\n", (int)tasks.size());
+ SubscriberList clients;
for(TaskIdList::iterator i = tasks.begin(); i != tasks.end(); i++)
{
taskid_t tid = *i;
- DEBUG(conn, "Locating observers of node %d\n", tid);
+ DEBUG(conn, "Locating subscribers of node %d\n", tid);
for(ConnectionList::iterator ci = connlist.begin();
ci != connlist.end(); ci++)
{
@@ -125,20 +125,20 @@ TEST_BEGIN;
ConnectionHandler &h = connection_handler;
h.init((clientid_t)1);
-h.observe((clientid_t)1, (taskid_t)1);
-h.observe((clientid_t)1, (taskid_t)2);
+h.subscribe((clientid_t)1, (taskid_t)1);
+h.subscribe((clientid_t)1, (taskid_t)2);
h.init((clientid_t)2);
-h.observe((clientid_t)2, (taskid_t)1);
-h.observe((clientid_t)2, (taskid_t)2);
+h.subscribe((clientid_t)2, (taskid_t)1);
+h.subscribe((clientid_t)2, (taskid_t)2);
h.init((clientid_t)3);
-h.observe((clientid_t)3, (taskid_t)3);
+h.subscribe((clientid_t)3, (taskid_t)3);
{
TaskIdList tasks;
tasks.push_back((taskid_t)1);
- ObserverList clst = h.observerlist(tasks);
+ SubscriberList clst = h.subscriberlist(tasks);
TEST_TRUE(clst.find((clientid_t)1) != clst.end(), "Got client 1?");
TEST_TRUE(clst.find((clientid_t)2) != clst.end(), "Got client 2?");
@@ -148,7 +148,7 @@ h.observe((clientid_t)3, (taskid_t)3);
{
TaskIdList tasks;
tasks.push_back((taskid_t)3);
- ObserverList clst = h.observerlist(tasks);
+ SubscriberList clst = h.subscriberlist(tasks);
TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?");
TEST_FALSE(clst.find((clientid_t)2) != clst.end(), "Got client 2?");
@@ -158,7 +158,7 @@ h.observe((clientid_t)3, (taskid_t)3);
{
TaskIdList tasks;
tasks.push_back((taskid_t)4);
- ObserverList clst = h.observerlist(tasks);
+ SubscriberList clst = h.subscriberlist(tasks);
TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?");
TEST_FALSE(clst.find((clientid_t)2) != clst.end(), "Got client 2?");
@@ -170,7 +170,7 @@ h.observe((clientid_t)3, (taskid_t)3);
tasks.push_back((taskid_t)1);
tasks.push_back((taskid_t)2);
tasks.push_back((taskid_t)3);
- ObserverList clst = h.observerlist(tasks);
+ SubscriberList clst = h.subscriberlist(tasks);
TEST_TRUE(clst.find((clientid_t)1) != clst.end(), "Got client 1?");
TEST_TRUE(clst.find((clientid_t)2) != clst.end(), "Got client 2?");
@@ -183,7 +183,7 @@ h.close((clientid_t)1);
tasks.push_back((taskid_t)1);
tasks.push_back((taskid_t)2);
tasks.push_back((taskid_t)3);
- ObserverList clst = h.observerlist(tasks);
+ SubscriberList clst = h.subscriberlist(tasks);
TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?");
TEST_TRUE(clst.find((clientid_t)2) != clst.end(), "Got client 2?");
@@ -196,7 +196,7 @@ h.close((clientid_t)2);
tasks.push_back((taskid_t)1);
tasks.push_back((taskid_t)2);
tasks.push_back((taskid_t)3);
- ObserverList clst = h.observerlist(tasks);
+ SubscriberList clst = h.subscriberlist(tasks);
TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?");
TEST_FALSE(clst.find((clientid_t)2) != clst.end(), "Got client 2?");
@@ -209,7 +209,7 @@ h.close((clientid_t)3);
tasks.push_back((taskid_t)1);
tasks.push_back((taskid_t)2);
tasks.push_back((taskid_t)3);
- ObserverList clst = h.observerlist(tasks);
+ SubscriberList clst = h.subscriberlist(tasks);
TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?");
TEST_FALSE(clst.find((clientid_t)2) != clst.end(), "Got client 2?");
diff --git a/src/connectionhandler.h b/src/connectionhandler.h
index 0e28cd3..482c293 100644
--- a/src/connectionhandler.h
+++ b/src/connectionhandler.h
@@ -39,7 +39,7 @@ typedef struct lws* clientid_t;
typedef std::map<clientid_t, bool> AuthList;
typedef std::map<clientid_t, std::set<taskid_t> > ConnectionList;
-typedef std::list<std::pair<clientid_t, taskid_t> > ObserverList;
+typedef std::list<std::pair<clientid_t, taskid_t> > SubscriberList;
class ConnectionHandler
{
@@ -53,10 +53,10 @@ public:
void logout(clientid_t clientid);
bool authenticated(clientid_t clientid);
- void observe(clientid_t clientid, taskid_t taskid);
- void unobserve(clientid_t clientid, taskid_t taskid);
+ void subscribe(clientid_t clientid, taskid_t taskid);
+ void unsubscribe(clientid_t clientid, taskid_t taskid);
- ObserverList observerlist(TaskIdList tasklist);
+ SubscriberList subscriberlist(TaskIdList tasklist);
private:
ConnectionList connlist;
diff --git a/src/message.h b/src/message.h
index ea1c444..bb56932 100644
--- a/src/message.h
+++ b/src/message.h
@@ -35,14 +35,14 @@
namespace cmd
{
typedef enum {
- observe,
- unobserve,
- update,
- move,
- create,
- remove,
login,
logout,
+ subscribe,
+ unsubscribe,
+ create,
+ remove,
+ move,
+ update,
error,
} cmd_t;
};
@@ -55,13 +55,17 @@ typedef struct
typedef struct
{
+} logout_t;
+
+typedef struct
+{
taskid_t id;
-} observe_t;
+} subscribe_t;
typedef struct
{
taskid_t id;
-} unobserve_t;
+} unsubscribe_t;
typedef struct
{
@@ -83,26 +87,26 @@ typedef struct
typedef struct
{
taskid_t id;
- std::string name;
+ std::string attribute;
std::string value;
} update_t;
-
typedef struct
{
cmd::cmd_t cmd;
- observe_t observe;
- unobserve_t unobserve;
+ login_t login;
+ logout_t logout;
+ subscribe_t subscribe;
+ unsubscribe_t unsubscribe;
create_t create;
remove_t remove;
move_t move;
update_t update;
- login_t login;
TaskIdList nodes;
- // tagret node id (observed task id) used for transmissions only.
+ // target node id (subscription node id) used for transmissions only.
taskid_t tid;
} message_t;
diff --git a/src/messagehandler.cc b/src/messagehandler.cc
index ad9b8bb..5ccf3bf 100644
--- a/src/messagehandler.cc
+++ b/src/messagehandler.cc
@@ -57,6 +57,14 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi)
switch(m.cmd)
{
+ case cmd::login:
+ // Already handled, before this switch ... case
+ break;
+
+ case cmd::logout:
+ connection_handler.logout(wsi);
+ break;
+
case cmd::create:
{
INFO(messagehandler, "Handling create command\n");
@@ -162,17 +170,17 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi)
}
break;
- case cmd::observe:
+ case cmd::subscribe:
{
- //connection_handler.observe(wsi, m.observe.id);
+ //connection_handler.subscribe(wsi, m.subscribe.id);
outmsgs.push_back(m);
}
break;
- case cmd::unobserve:
- //connection_handler.unobserve(wsi, m.observe.id);
+ case cmd::unsubscribe:
+ //connection_handler.unsubscribe(wsi, m.subscribe.id);
outmsgs.push_back(m);
- DEBUG(handler, "unobserve: %d\n", m.unobserve.id);
+ DEBUG(handler, "unsubscribe: %d\n", m.unsubscribe.id);
break;
case cmd::update:
@@ -181,7 +189,7 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi)
try
{
m.nodes = task_manager.updateTask(m.update.id,
- m.update.name, m.update.value);
+ m.update.attribute, m.update.value);
outmsgs.push_back(m);
}
catch (std::exception& e)
@@ -191,14 +199,6 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi)
}
break;
- case cmd::login:
- // Already handled, before this switch ... case
- break;
-
- case cmd::logout:
- connection_handler.logout(wsi);
- break;
-
case cmd::error:
ERR(messagehandler, "An error occurred.\n");
break;
diff --git a/src/messageparser.cc b/src/messageparser.cc
index d59cccc..75593f9 100644
--- a/src/messageparser.cc
+++ b/src/messageparser.cc
@@ -185,8 +185,8 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
// DEBUG(msgparser, "%d\n", t.size());
- if(t[origin] == "observe") m.cmd = cmd::observe;
- else if(t[origin] == "unobserve") m.cmd = cmd::unobserve;
+ if(t[origin] == "subscribe") m.cmd = cmd::subscribe;
+ else if(t[origin] == "unsubscribe") m.cmd = cmd::unsubscribe;
else if(t[origin] == "login") m.cmd = cmd::login;
else if(t[origin] == "logout") m.cmd = cmd::logout;
else if(t[origin] == "create") m.cmd = cmd::create;
@@ -197,26 +197,26 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
switch(m.cmd)
{
- case cmd::observe:
+ case cmd::subscribe:
{
if(t.size() != origin+1+1)
{
DEBUG(msgparser, "Wrong number of parameters\n");
continue;
}
- m.observe.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str());
+ m.subscribe.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str());
}
break;
- case cmd::unobserve:
+ case cmd::unsubscribe:
{
if(t.size() != origin+1+1)
{
DEBUG(msgparser, "Wrong number of parameters\n");
continue;
}
- m.unobserve.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str());
- DEBUG(msgparser, "unobserve @ %d\n", m.unobserve.id);
+ m.unsubscribe.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str());
+ DEBUG(msgparser, "unsubscribe @ %d\n", m.unsubscribe.id);
}
break;
@@ -294,7 +294,7 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
continue;
}
m.update.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str());
- m.update.name = t[origin+2];
+ m.update.attribute = t[origin+2];
m.update.value = t[origin+3];
}
break;
@@ -348,7 +348,7 @@ std::string msg_tostring(message_t m)
break;
case cmd::update:
asprintf(&buf, "update %d \"%s\" \"%s\";",
- m.update.id, m.update.name.c_str(), m.update.value.c_str());
+ m.update.id, m.update.attribute.c_str(), m.update.value.c_str());
break;
default:
break;
@@ -378,7 +378,7 @@ message_t create_msg_update(task_t t, const std::string &attr)
message_t m;
m.cmd = cmd::update;
m.update.id = t.id;
- m.update.name = attr;
+ m.update.attribute = attr;
m.update.value = t.attributes[attr];
return m;
}
diff --git a/src/munia_proto.cc b/src/munia_proto.cc
index 6e944cf..333e3c9 100644
--- a/src/munia_proto.cc
+++ b/src/munia_proto.cc
@@ -211,17 +211,17 @@ int callback_lws_task(struct lws *wsi,
while(omi != omsgs.end())
{
DEBUG(proto, "Message\n");
- if(omi->cmd == cmd::observe)
+ if(omi->cmd == cmd::subscribe)
{
- connection_handler.observe(wsi, omi->observe.id);
+ connection_handler.subscribe(wsi, omi->subscribe.id);
TaskIdList ids;
try
{
- ids = task_manager.subTasks(omi->observe.id);
+ ids = task_manager.subTasks(omi->subscribe.id);
}
catch(...)
{
- DEBUG(proto, "No such node %d\n", omi->observe.id);
+ DEBUG(proto, "No such node %d\n", omi->subscribe.id);
omi++;
continue;
}
@@ -231,7 +231,7 @@ int callback_lws_task(struct lws *wsi,
task_t task = task_manager.task(*id);
message_t createmsg = create_msg_create(task);
- createmsg.tid = omi->observe.id;
+ createmsg.tid = omi->subscribe.id;
msgqueue[wsi].push_back(createmsg);
std::map<std::string, std::string>::iterator ai =
@@ -239,8 +239,8 @@ int callback_lws_task(struct lws *wsi,
while(ai != task.attributes.end())
{
message_t updatemsg = create_msg_update(task, ai->first);
- DEBUG(observe, "%s\n", ai->first.c_str());
- updatemsg.tid = omi->observe.id;
+ DEBUG(subscribe, "%s\n", ai->first.c_str());
+ updatemsg.tid = omi->subscribe.id;
msgqueue[wsi].push_back(updatemsg);
ai++;
}
@@ -248,17 +248,17 @@ int callback_lws_task(struct lws *wsi,
id++;
}
}
- else if(omi->cmd == cmd::unobserve)
+ else if(omi->cmd == cmd::unsubscribe)
{
- connection_handler.unobserve(wsi, omi->unobserve.id);
+ connection_handler.unsubscribe(wsi, omi->unsubscribe.id);
TaskIdList ids;
try
{
- ids = task_manager.subTasks(omi->unobserve.id);
+ ids = task_manager.subTasks(omi->unsubscribe.id);
}
catch(...)
{
- DEBUG(proto, "No such node %d\n", omi->unobserve.id);
+ DEBUG(proto, "No such node %d\n", omi->unsubscribe.id);
omi++;
continue;
}
@@ -268,9 +268,9 @@ int callback_lws_task(struct lws *wsi,
task_t task = task_manager.task(*id);
message_t removemsg = create_msg_remove(task);
- removemsg.tid = omi->unobserve.id;
+ removemsg.tid = omi->unsubscribe.id;
msgqueue[wsi].push_back(removemsg);
- DEBUG(unobserve, "remove id: %d\n", *id);
+ DEBUG(unsubscribe, "remove id: %d\n", *id);
id++;
}
@@ -281,16 +281,16 @@ int callback_lws_task(struct lws *wsi,
DEBUG(proto, "%d nodes affected by command\n",
(int)omi->nodes.size());
- ObserverList clients = connection_handler.observerlist(omi->nodes);
+ SubscriberList clients = connection_handler.subscriberlist(omi->nodes);
DEBUG(proto, "Writing message to %d clients\n", (int)clients.size());
- ObserverList::iterator ci = clients.begin();
+ SubscriberList::iterator ci = clients.begin();
while(ci != clients.end())
{
clientid_t clientid = (*ci).first;
taskid_t tid = (*ci).second;
- DEBUG(proto, "Observer id of task: %d\n", tid);
+ DEBUG(proto, "Subscriber id of task: %d\n", tid);
message_t msg = *omi;
msg.tid = tid;
diff --git a/src/muniacli.cc b/src/muniacli.cc
index f28c810..843c028 100644
--- a/src/muniacli.cc
+++ b/src/muniacli.cc
@@ -556,18 +556,18 @@ int main(int argc, char** argv)
switch(cmd)
{
case CREATE:
- msgs = "observe " + taskbyid + ";";
+ msgs = "subscribe " + taskbyid + ";";
msgs += "create " + taskbyid + ";";
break;
case LIST:
- msgs = "observe " + taskbyid + ";"; //+
- // "; unobserve " + task + ";";
+ msgs = "subscribe " + taskbyid + ";"; //+
+ // "; unsubscribe " + task + ";";
break;
case REMOVE:
msgs = "remove " + taskbyid + ";";
break;
case UPDATE:
- msgs = "observe " + taskbyid + ";";
+ msgs = "subscribe " + taskbyid + ";";
msgs += "update " + taskbyid + " \"" + cmd_opts + "\"; ";
break;
case DEFAULT:
diff --git a/src/taskmanager.cc b/src/taskmanager.cc
index 3fafb4e..1b34dde 100644
--- a/src/taskmanager.cc
+++ b/src/taskmanager.cc
@@ -129,7 +129,7 @@ TaskIdListPair TaskManager::moveTask(taskid_t id, taskid_t to)
//task_t t = tree.data(id);
// Make sure the new parent exists. This will throw an exception if it doesn't
- //task_t t_ = tree.data(to);
+ //task_t t_ = tree.data(to);
//t.parentid = to;
@@ -304,7 +304,7 @@ TaskList load_tasklist_from_file(std::string file)
{
TaskList list;
- // create MuniaDb class which handles tasks, db-flush and db-init.
+ // create MuniaDb class which handles tasks, db-flush and db-init.
return list;
}
diff --git a/src/testclient.cc b/src/testclient.cc
index 58e55a1..6733978 100644
--- a/src/testclient.cc
+++ b/src/testclient.cc
@@ -183,21 +183,21 @@ TEST_BEGIN;
static struct test tests[] =
{
- { "observe 0", BASE, false },
- { "unobserve 0", RMBASE, false },
+ { "subscribe 0", BASE, false },
+ { "unsubscribe 0", RMBASE, false },
{ "create 0", nullptr, false },
- { "observe 0", BASE" 0 create 10 0; 0 update 10 \"\";", false },
+ { "subscribe 0", BASE" 0 create 10 0; 0 update 10 \"\";", false },
{ "update 10 \"My title\"", "0 update 10 \"My title\";", false },
- { "unobserve 0", "0 remove 10; "RMBASE, false },
- { "observe 0", BASE" 0 create 10 0; 0 update 10 \"My title\";", false },
+ { "unsubscribe 0", "0 remove 10; "RMBASE, false },
+ { "subscribe 0", BASE" 0 create 10 0; 0 update 10 \"My title\";", false },
{ "move 10 1", "0 move 10 1;", false },
{ "create 10", "0 create 11 10;", false },
{ "remove 10", "0 remove 11; 0 remove 10;", false },
- //{ "observe 0", BASE"0 add title description 5", false },
+ //{ "subscribe 0", BASE"0 add title description 5", false },
//{ "add title2 description 0", BASE"0 add title2 description 6", false },
- //{ "unobserve 0", nullptr, false },
- //{ "observe 0", BASE"0 add title description 5; add title description 6", false },
- //{ "unobserve 0", nullptr, false },
+ //{ "unsubscribe 0", nullptr, false },
+ //{ "subscribe 0", BASE"0 add title description 5; add title description 6", false },
+ //{ "unsubscribe 0", nullptr, false },
{ nullptr, nullptr, false }
};