Added SubscriptionHandler capability to Subscriptions.
This commit is contained in:
1 parent
69dcbae428
commit
001cd8c06c
152 files changed
+15005
-64
No files matched your search
+23
-6
@@ -1,16 +1,19 @@
|
||||
#include "Subscription.h"
|
||||
#include "TCPSession.h"
|
||||
#include "Log.h"
|
||||
#include "TCPSession.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace core
|
||||
{
|
||||
|
||||
Subscription::Subscription(std::string id, std::string mode)
|
||||
: id(id), mode(mode), owner(NULL) {}
|
||||
|
||||
: id(id), mode(mode), owner(NULL), handler(NULL) {}
|
||||
|
||||
Subscription::Subscription(std::string id, TCPSession &session, std::string mode)
|
||||
: id(id), mode(mode), owner(&session) {}
|
||||
: id(id), mode(mode), owner(&session), handler(NULL) {}
|
||||
|
||||
Subscription::Subscription(std::string id, TCPSession &session, std::string mode, SubscriptionHandler *handler)
|
||||
: id(id), mode(mode), owner(&session), handler(handler) {}
|
||||
|
||||
Subscription::~Subscription()
|
||||
{
|
||||
@@ -24,7 +27,11 @@ namespace core
|
||||
|
||||
int Subscription::subscribe(TCPSession &session)
|
||||
{
|
||||
onSubscribe(session);
|
||||
if(handler)
|
||||
handler->onSubscribe(session);
|
||||
else
|
||||
onSubscribe(session);
|
||||
|
||||
subscribers.push_back(&session);
|
||||
return 1;
|
||||
}
|
||||
@@ -44,7 +51,11 @@ namespace core
|
||||
|
||||
int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session)
|
||||
{
|
||||
out << "event:" << request[1] << ":" << request[2] << std::endl;
|
||||
std::cout << "(" << handler << ")" << std::endl;
|
||||
if (handler)
|
||||
handler->process(request, out, session);
|
||||
else
|
||||
out << "event:" << request[1] << ":" << request[2] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -65,4 +76,10 @@ namespace core
|
||||
return 0;
|
||||
}
|
||||
|
||||
// void Subscription::setHandler(SubscriptionHandler *handlers)
|
||||
// {
|
||||
// handler = handlers;
|
||||
|
||||
// coreutils::Log(coreutils::LOG_DEBUG_1) << "Test Test";
|
||||
// }
|
||||
}
|
||||
Reference in new issue
Block a user