From 9af17daed688c6ccfe86d51ac7140d4ed51aa0bf Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Tue, 26 Jul 2022 16:07:37 -0700 Subject: [PATCH 01/27] Fixing command list delimiter depth. --- CommandList.cpp | 35 +++++++++----------- CommandList.h | 2 +- Sihen.txt | 1 - TCPServer.cpp | 86 ++++++++++++++++++++++++------------------------- TCPSession.cpp | 82 +++++++++++++++++++++++----------------------- 5 files changed, 101 insertions(+), 105 deletions(-) delete mode 100644 Sihen.txt diff --git a/CommandList.cpp b/CommandList.cpp index df97968..a999c72 100644 --- a/CommandList.cpp +++ b/CommandList.cpp @@ -2,50 +2,47 @@ #include "Log.h" namespace core { - + CommandList::CommandList(std::string delimiter, int depth) : delimiter(delimiter), depth(depth) {} - + void CommandList::add(Command &command, std::string name) { commands.insert(std::make_pair(name, &command)); } - + void CommandList::remove(Command &command) {} - - bool CommandList::processRequest(coreutils::ZString &request, TCPSession &session) { + + int CommandList::processRequest(coreutils::ZString &request, TCPSession &session) { if(session.grab != NULL) - return session.grab->processCommand(request, session); + return session.grab->processCommand(request, session); else { if(request.equals("")) - return false; - request.split(delimiter, 10); + return 0; + request.split(delimiter, depth); request.reset(); try { auto command = commands.at(request[0].str()); - return command->processCommand(request, session); + return command->processCommand(request, session); } catch(...) { - return false; + return 0; } } return true; } - + bool CommandList::grabInput(TCPSession &session, Command &command) { session.grab = &command; return true; } - + void CommandList::clearGrab(TCPSession &session) { session.grab = NULL; } - + int CommandList::processCommand(coreutils::ZString &request, TCPSession &session) { -// for(Command *command : commands) -// session.out << command->getName() << std::endl; + // for(Command *command : commands) + // session.out << command->getName() << std::endl; return true; } - + } - - - diff --git a/CommandList.h b/CommandList.h index 5d62707..acbc99d 100644 --- a/CommandList.h +++ b/CommandList.h @@ -40,7 +40,7 @@ namespace core { /// then control is given to the process handler holding the grab on the input. /// - bool processRequest(coreutils::ZString &request, TCPSession &session); + int processRequest(coreutils::ZString &request, TCPSession &session); /// /// Use grabInput() within a Command object to force the requesting handler to receive diff --git a/Sihen.txt b/Sihen.txt deleted file mode 100644 index 3eaf00b..0000000 --- a/Sihen.txt +++ /dev/null @@ -1 +0,0 @@ -0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: \ No newline at end of file diff --git a/TCPServer.cpp b/TCPServer.cpp index 24adf2d..f2347e5 100644 --- a/TCPServer.cpp +++ b/TCPServer.cpp @@ -8,31 +8,31 @@ namespace core { TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter, int depth, std::string text) : TCPSocket(ePoll, text), commands(delimiter, depth) { - - commands.add(subscriptions, "publish"); - commands.add(subscriptions, "unpublish"); - commands.add(subscriptions, "subscribe"); - commands.add(subscriptions, "unsubscribe"); - commands.add(subscriptions, "catalog"); - commands.add(subscriptions, "event"); - - setDescriptor(socket(AF_INET, SOCK_STREAM, 0)); - int yes = 1; - setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); - - if(bind(getDescriptor(), address.getPointer(), address.addressLength) < 0) - throw coreutils::Exception("Error on bind to socket: " + std::to_string(errno)); - - if(listen(getDescriptor(), 20) < 0) - throw coreutils::Exception("Error on listen to socket"); - - } + + commands.add(subscriptions, "publish"); + commands.add(subscriptions, "unpublish"); + commands.add(subscriptions, "subscribe"); + commands.add(subscriptions, "unsubscribe"); + commands.add(subscriptions, "catalog"); + commands.add(subscriptions, "event"); + + setDescriptor(socket(AF_INET, SOCK_STREAM, 0)); + int yes = 1; + setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); + + if(bind(getDescriptor(), address.getPointer(), address.addressLength) < 0) + throw coreutils::Exception("Error on bind to socket: " + std::to_string(errno)); + + if(listen(getDescriptor(), 20) < 0) + throw coreutils::Exception("Error on listen to socket"); + + } TCPServer::~TCPServer() { coreutils::Log(coreutils::LOG_DEBUG_2) << "Closing server socket " << getDescriptor() << "."; close(getDescriptor()); } - + void TCPServer::onDataReceived(std::string data) { lock.lock(); TCPSession *session = accept(); @@ -40,11 +40,11 @@ namespace core { sessions.push_back(session); lock.unlock(); } - + TCPSession * TCPServer::accept() { - + try { - + TCPSession *session = getSocketAccept(ePoll); session->setDescriptor(::accept(getDescriptor(), (struct sockaddr *)&session->ipAddress.addr, &session->ipAddress.addressLength)); // if(blackList && blackList->contains(session->ipAddress.getClientAddress())) { @@ -67,30 +67,30 @@ namespace core { } return NULL; } - + void TCPServer::removeFromSessionList(TCPSession *session) { std::vector::iterator cursor; - lock.lock(); + lock.lock(); for(cursor = sessions.begin(); cursor < sessions.end(); ++cursor) if(*cursor == session) { - sessions.erase(cursor); - break; - } - lock.unlock(); + sessions.erase(cursor); + break; + } + lock.unlock(); } - + void TCPServer::sessionErrorHandler(std::string errorString, std::stringstream &out) { throw coreutils::Exception(errorString); } - + TCPSession * TCPServer::getSocketAccept(EPoll &ePoll) { return new TCPSession(ePoll, *this); } - + void TCPServer::output(std::stringstream &out) { out << "Use the 'help' command to list the commands for this server." << std::endl; } - + int TCPServer::processCommand(coreutils::ZString &request, TCPSession &session) { int sequence = 0; for(auto *sessionx : sessions) { @@ -100,26 +100,26 @@ namespace core { } return 1; } - + void TCPServer::sendToAll(std::stringstream &data) { for(auto session : sessions) - session->write(data.str()); + session->write(data.str()); data.str(""); } - + void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender) { for(auto session : sessions) - if(session != &sender) - session->write(data.str()); + if(session != &sender) + session->write(data.str()); data.str(""); } - + void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender, SessionFilter filter) { for(auto session : sessions) - if(filter.test(*session)) - if(session != &sender) - session->write(data.str()); + if(filter.test(*session)) + if(session != &sender) + session->write(data.str()); data.str(""); } - + } diff --git a/TCPSession.cpp b/TCPSession.cpp index 59283c2..67c25ae 100644 --- a/TCPSession.cpp +++ b/TCPSession.cpp @@ -6,92 +6,92 @@ namespace core { TCPSession::TCPSession(EPoll &ePoll, TCPServer &server, std::string text) : TCPSocket(ePoll, text), server(server) {} - + TCPSession::~TCPSession() { server.removeFromSessionList(this); server.subscriptions.removeSessionSubscriptions(*this); } - + void TCPSession::output(std::stringstream &data) { data << "|" << ipAddress.getClientAddressAndPort(); } - + void TCPSession::protocol(coreutils::ZString &data) { if(data.getLength() != 0) { - if(!server.commands.processRequest(data, *this)) { - coreutils::Log(coreutils::LOG_DEBUG_1) << "Received data could not be parsed: " << data.str(); + if(server.commands.processRequest(data, *this) == 0) { + coreutils::Log(coreutils::LOG_DEBUG_1) << "Received data could not be parsed: " << data.str(); } } } - + void TCPSession::onRegistered() { onConnected(); coreutils::ZString blank(""); protocol(blank); send(); if(term) - shutdown("termination requested"); + shutdown("termination requested"); } - + void TCPSession::onConnected() {} - + void TCPSession::onDataReceived(coreutils::ZString &data) { if(data.getLength() > 0) { - lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength()); - memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength()); - lineBufferSize += data.getLength(); - while(lineBufferSize > 0) { - if(blockSize == 0) { - lineLength = strcspn(lineBuffer, "\r\n"); - if(lineLength == lineBufferSize) - break; + lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength()); + memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength()); + lineBufferSize += data.getLength(); + while(lineBufferSize > 0) { + if(blockSize == 0) { + lineLength = strcspn(lineBuffer, "\r\n"); + if(lineLength == lineBufferSize) + break; coreutils::ZString zLine(lineBuffer, lineLength); - onLineReceived(zLine); - if(lineBuffer[lineLength] == '\r') - ++lineLength; - if(lineBuffer[lineLength] == '\n') - ++lineLength; - lineBufferSize -= lineLength; - if(lineBufferSize > 0) - memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize); - lineBuffer = (char *)realloc(lineBuffer, lineBufferSize); + onLineReceived(zLine); + if(lineBuffer[lineLength] == '\r') + ++lineLength; + if(lineBuffer[lineLength] == '\n') + ++lineLength; + lineBufferSize -= lineLength; + if(lineBufferSize > 0) + memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize); + lineBuffer = (char *)realloc(lineBuffer, lineBufferSize); } else if(lineBufferSize >= blockLength) { - coreutils::ZString zBlock(lineBuffer, blockLength); - onBlockReceived(zBlock); - lineBufferSize -= blockLength; - if(lineBufferSize > 0) - memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize); - lineBuffer = (char *)realloc(lineBuffer, lineBufferSize); - } - } + coreutils::ZString zBlock(lineBuffer, blockLength); + onBlockReceived(zBlock); + lineBufferSize -= blockLength; + if(lineBufferSize > 0) + memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize); + lineBuffer = (char *)realloc(lineBuffer, lineBufferSize); + } + } } } - + void TCPSession::setBlockSize(int blockSize) { this->blockSize = blockSize; } - + void TCPSession::onLineReceived(coreutils::ZString &line) { protocol(line); send(); if(term) shutdown("termination requested"); } - + void TCPSession::onBlockReceived(coreutils::ZString &block) { coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << block.getLength() << "]"; if(term) shutdown("termination requested"); } - + void TCPSession::send() { if(out.tellp() > 0) - write(out.str()); + write(out.str()); out.str(""); } - + void TCPSession::terminate() { term = true; } - + } From 5c87225c6fbfc892cb56f1cd5cc8d92a6d5d3ef0 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Thu, 28 Jul 2022 09:54:31 -0700 Subject: [PATCH 02/27] Documentation updates. --- html/CommandList_8h_source.html | 4 ++-- html/classcore_1_1CommandList-members.html | 2 +- html/classcore_1_1CommandList.html | 10 +++++----- html/functions.html | 2 +- html/functions_func.html | 2 +- html/search/all_8.js | 2 +- html/search/functions_6.js | 2 +- latex/classcore_1_1CommandList.tex | 6 +++--- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/html/CommandList_8h_source.html b/html/CommandList_8h_source.html index 4ed110d..b013265 100644 --- a/html/CommandList_8h_source.html +++ b/html/CommandList_8h_source.html @@ -88,7 +88,7 @@ $(function() {
34  void remove(Command &command);
35 
42 
-
43  bool processRequest(coreutils::ZString &request, TCPSession &session);
+
43  int processRequest(coreutils::ZString &request, TCPSession &session);
44 
50 
51  bool grabInput(TCPSession &session, Command &command);
@@ -115,8 +115,8 @@ $(function() {
int processCommand(coreutils::ZString &request, TCPSession &session)
Definition: CommandList.cpp:42
bool grabInput(TCPSession &session, Command &command)
Definition: CommandList.cpp:33
void add(Command &command, std::string name="")
Definition: CommandList.cpp:8
-
bool processRequest(coreutils::ZString &request, TCPSession &session)
Definition: CommandList.cpp:14
void remove(Command &command)
Definition: CommandList.cpp:12
+
int processRequest(coreutils::ZString &request, TCPSession &session)
Definition: CommandList.cpp:14
std::map< std::string, Command * > commands
Definition: CommandList.h:71
Definition: Command.h:22
Definition: TCPSession.h:24
diff --git a/html/classcore_1_1CommandList-members.html b/html/classcore_1_1CommandList-members.html index 3d4fd38..ae803e0 100644 --- a/html/classcore_1_1CommandList-members.html +++ b/html/classcore_1_1CommandList-members.html @@ -81,7 +81,7 @@ $(function() { grabInput(TCPSession &session, Command &command)core::CommandList output(std::stringstream &out)core::Commandvirtual processCommand(coreutils::ZString &request, TCPSession &session)core::CommandListvirtual - processRequest(coreutils::ZString &request, TCPSession &session)core::CommandList + processRequest(coreutils::ZString &request, TCPSession &session)core::CommandList remove(Command &command)core::CommandList diff --git a/html/classcore_1_1CommandList.html b/html/classcore_1_1CommandList.html index 5044d61..1599308 100644 --- a/html/classcore_1_1CommandList.html +++ b/html/classcore_1_1CommandList.html @@ -103,8 +103,8 @@ Public Member Functions   void remove (Command &command)   -bool processRequest (coreutils::ZString &request, TCPSession &session) -  +int processRequest (coreutils::ZString &request, TCPSession &session) +  bool grabInput (TCPSession &session, Command &command)   @@ -236,14 +236,14 @@ int depth - -

◆ processRequest()

+ +

◆ processRequest()

- + diff --git a/html/functions.html b/html/functions.html index 3817e37..70577a1 100644 --- a/html/functions.html +++ b/html/functions.html @@ -199,7 +199,7 @@ $(function() { , core::TCPServer
  • processRequest() -: core::CommandList +: core::CommandList
  • protocol() : core::ConsoleSession diff --git a/html/functions_func.html b/html/functions_func.html index ff8d96c..ac7756c 100644 --- a/html/functions_func.html +++ b/html/functions_func.html @@ -178,7 +178,7 @@ $(function() { , core::TCPServer
  • processRequest() -: core::CommandList +: core::CommandList
  • protocol() : core::ConsoleSession diff --git a/html/search/all_8.js b/html/search/all_8.js index 5f37b67..26055c1 100644 --- a/html/search/all_8.js +++ b/html/search/all_8.js @@ -1,6 +1,6 @@ var searchData= [ ['processcommand_35',['processCommand',['../classcore_1_1Command.html#a95176f2532c38ee14e3fee40ee28b1bd',1,'core::Command::processCommand()'],['../classcore_1_1CommandList.html#a1819e1cb377b5d8e5e00b4777e2b4aba',1,'core::CommandList::processCommand()'],['../classcore_1_1EPoll.html#a22b5f1545aff3162040844be043abcce',1,'core::EPoll::processCommand()'],['../classcore_1_1SubscriptionManager.html#aaa30bf772ad72b3f319a790662e4f8ae',1,'core::SubscriptionManager::processCommand()'],['../classcore_1_1TCPServer.html#a6b7a7e1ac4132942fcaf418ed41c1437',1,'core::TCPServer::processCommand()']]], - ['processrequest_36',['processRequest',['../classcore_1_1CommandList.html#aa9b789df8eed15dc037bd98d596fe6e0',1,'core::CommandList']]], + ['processrequest_36',['processRequest',['../classcore_1_1CommandList.html#abcfb26e37e1ee6ff5655ebc3d33b1818',1,'core::CommandList']]], ['protocol_37',['protocol',['../classcore_1_1ConsoleSession.html#aa1818efcd33a4152d2089aa545f08833',1,'core::ConsoleSession::protocol()'],['../classcore_1_1TCPSession.html#a98a65da2346b79bee659fca6902e94c7',1,'core::TCPSession::protocol()'],['../classcore_1_1TLSSession.html#a208145cc1fcdc14054602aacc2c51d91',1,'core::TLSSession::protocol()']]] ]; diff --git a/html/search/functions_6.js b/html/search/functions_6.js index 479aeac..5a56dac 100644 --- a/html/search/functions_6.js +++ b/html/search/functions_6.js @@ -1,6 +1,6 @@ var searchData= [ ['processcommand_122',['processCommand',['../classcore_1_1Command.html#a95176f2532c38ee14e3fee40ee28b1bd',1,'core::Command::processCommand()'],['../classcore_1_1CommandList.html#a1819e1cb377b5d8e5e00b4777e2b4aba',1,'core::CommandList::processCommand()'],['../classcore_1_1EPoll.html#a22b5f1545aff3162040844be043abcce',1,'core::EPoll::processCommand()'],['../classcore_1_1SubscriptionManager.html#aaa30bf772ad72b3f319a790662e4f8ae',1,'core::SubscriptionManager::processCommand()'],['../classcore_1_1TCPServer.html#a6b7a7e1ac4132942fcaf418ed41c1437',1,'core::TCPServer::processCommand()']]], - ['processrequest_123',['processRequest',['../classcore_1_1CommandList.html#aa9b789df8eed15dc037bd98d596fe6e0',1,'core::CommandList']]], + ['processrequest_123',['processRequest',['../classcore_1_1CommandList.html#abcfb26e37e1ee6ff5655ebc3d33b1818',1,'core::CommandList']]], ['protocol_124',['protocol',['../classcore_1_1ConsoleSession.html#aa1818efcd33a4152d2089aa545f08833',1,'core::ConsoleSession::protocol()'],['../classcore_1_1TCPSession.html#a98a65da2346b79bee659fca6902e94c7',1,'core::TCPSession::protocol()'],['../classcore_1_1TLSSession.html#a208145cc1fcdc14054602aacc2c51d91',1,'core::TLSSession::protocol()']]] ]; diff --git a/latex/classcore_1_1CommandList.tex b/latex/classcore_1_1CommandList.tex index 02aeab7..06d74cd 100644 --- a/latex/classcore_1_1CommandList.tex +++ b/latex/classcore_1_1CommandList.tex @@ -32,7 +32,7 @@ void \mbox{\hyperlink{classcore_1_1CommandList_a7a45e75e3d21a25fd3f7e887acf395e9 \item void \mbox{\hyperlink{classcore_1_1CommandList_aaac684effb9ecf5238d23ca60d3fffaa}{remove}} (\mbox{\hyperlink{classcore_1_1Command}{Command}} \&command) \item -bool \mbox{\hyperlink{classcore_1_1CommandList_aa9b789df8eed15dc037bd98d596fe6e0}{process\+Request}} (coreutils\+::\+ZString \&request, \mbox{\hyperlink{classcore_1_1TCPSession}{TCPSession}} \&session) +int \mbox{\hyperlink{classcore_1_1CommandList_abcfb26e37e1ee6ff5655ebc3d33b1818}{process\+Request}} (coreutils\+::\+ZString \&request, \mbox{\hyperlink{classcore_1_1TCPSession}{TCPSession}} \&session) \item bool \mbox{\hyperlink{classcore_1_1CommandList_a72aea93a650f148c639ba25a724da243}{grab\+Input}} (\mbox{\hyperlink{classcore_1_1TCPSession}{TCPSession}} \&session, \mbox{\hyperlink{classcore_1_1Command}{Command}} \&command) \item @@ -94,11 +94,11 @@ Returns 0 if execution of the command was successful. Otherwise returns a non-\/ Reimplemented from \mbox{\hyperlink{classcore_1_1Command_a95176f2532c38ee14e3fee40ee28b1bd}{core\+::\+Command}}. -\mbox{\Hypertarget{classcore_1_1CommandList_aa9b789df8eed15dc037bd98d596fe6e0}\label{classcore_1_1CommandList_aa9b789df8eed15dc037bd98d596fe6e0}} +\mbox{\Hypertarget{classcore_1_1CommandList_abcfb26e37e1ee6ff5655ebc3d33b1818}\label{classcore_1_1CommandList_abcfb26e37e1ee6ff5655ebc3d33b1818}} \index{core::CommandList@{core::CommandList}!processRequest@{processRequest}} \index{processRequest@{processRequest}!core::CommandList@{core::CommandList}} \doxysubsubsection{\texorpdfstring{processRequest()}{processRequest()}} -{\footnotesize\ttfamily bool core\+::\+Command\+List\+::process\+Request (\begin{DoxyParamCaption}\item[{coreutils\+::\+ZString \&}]{request, }\item[{\mbox{\hyperlink{classcore_1_1TCPSession}{TCPSession}} \&}]{session }\end{DoxyParamCaption})} +{\footnotesize\ttfamily int core\+::\+Command\+List\+::process\+Request (\begin{DoxyParamCaption}\item[{coreutils\+::\+ZString \&}]{request, }\item[{\mbox{\hyperlink{classcore_1_1TCPSession}{TCPSession}} \&}]{session }\end{DoxyParamCaption})} Use this method to apply a parsed ZString to the command set and execute the matching parameter. The selected command will return a true on a call to check(). If there is a handler that has a grab on the process handler then control is given to the process handler holding the grab on the input. \mbox{\Hypertarget{classcore_1_1CommandList_aaac684effb9ecf5238d23ca60d3fffaa}\label{classcore_1_1CommandList_aaac684effb9ecf5238d23ca60d3fffaa}} \index{core::CommandList@{core::CommandList}!remove@{remove}} From 69dcbae4284bff85bedc525586eacb5de4009b3d Mon Sep 17 00:00:00 2001 From: Brad Date: Thu, 13 Oct 2022 17:50:13 +0000 Subject: [PATCH 03/27] output/main and cpp sproperties. --- .vscode/c_cpp_properties.json | 2 +- output/main | Bin 106576 -> 33272 bytes 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 7adc94f..6720a7b 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -7,7 +7,7 @@ "${workspaceFolder}/../CoreUtils" ], "defines": [], - "compilerPath": "/usr/bin/g++-9", + "compilerPath": "/usr/bin/clang-12", "cStandard": "c17", "cppStandard": "gnu++20", "intelliSenseMode": "windows-gcc-x64", diff --git a/output/main b/output/main index 71318ccd0a992ac70416356d3e4622123bf3d84d..89da3b05b6af1e05a2997300b9368c772d0ff315 100755 GIT binary patch literal 33272 zcmeHwd3apKm2cg?YIVz{rEM*?88!ku8CZSBwFZcB{K3HI}+XcgwOf z>}0_YoIpr2I3W{<3<(J&LkP)0!X%Io60)#l9t<;?mkAk2U_!zYk})vg_xqi?)oQin zftT-n?|Xmf>g#)|&Q_;R?RBr}UeUf~lh1LKynVA?#wy@$L2K$}{oDsZ2r zW~x%eO9W@=Z3cj9uBUw?VbH_7fRvlWz$kEvK`RTbg@lwl-PP+QV4?EzK{-E#ym&F} z_w2OL((~zsDU2&D_dMK423!^v%F#E6<_lRJT0Iip?4|cBFaK7KXv*E-$=%?|S*ScY z3#~ut6aJQY`ikK~(0Ex`EZ6JF6~m22Oj*b@c0ADV{lVupk%x9u zhCIBe&lWl33~T(zWBhTWgo)$zc;eCi+MCNanAoZJO+ZaJ6|JhFa5Vg^)8M~+8a>BO zga7qu@XT)*zv7Ge3l}31fA4AVR{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N4XK!{0ZsYz$qSV~~ z-a9yecgp`Y8PA6PcR-ME(#! z{%ZdFK=Z5l?J4{pkAK~b_n$wP-S6eNzr3G~_x6nc-10ZN&wTu^;QII9d1vnD@9iG{ z`M4YB&60fnJ$(Nm{PW|zedIr{I)KR<zjec?YJ@f(wk_mBOX zY`nK?{pUygjqWpt-`~3N;WbZP_+R$VkN0-6|GX35jNkM3|8q9p z+tdE@3l9JMV?6%&zyB4#h>hsjPO!W0pSO2-IQ#qkc>no5eDSepytmK4>c;!~wDJFg zF9dh}`@J3imK*N@_)%KuMfNTyW7LJe*Eol#s1*@Ap@)DC7U}ZFffou>AcmXyd`VV% Yf3NU|>=yIY_y5S=`D@vL?9b}|0E7n@n*aa+ From 001cd8c06cd8bc9c2777a3de59a1446374a2f57c Mon Sep 17 00:00:00 2001 From: Brad Date: Tue, 18 Oct 2022 02:37:46 +0000 Subject: [PATCH 04/27] Added SubscriptionHandler capability to Subscriptions. --- .../SubscriptionHandler_20221013185305.cpp | 68 ++++++++ .history/SubscriptionHandler_20221013191001.h | 24 +++ .history/SubscriptionHandler_20221013204338.h | 23 +++ .../SubscriptionHandler_20221013204409.cpp | 68 ++++++++ .history/SubscriptionHandler_20221013204504.h | 23 +++ .../SubscriptionHandler_20221013204612.cpp | 68 ++++++++ .history/SubscriptionHandler_20221014152050.h | 22 +++ .history/SubscriptionHandler_20221014152131.h | 22 +++ .history/SubscriptionHandler_20221014152241.h | 22 +++ .history/SubscriptionHandler_20221014152252.h | 22 +++ .history/SubscriptionHandler_20221014152513.h | 22 +++ .history/SubscriptionHandler_20221014153238.h | 23 +++ .history/SubscriptionManager_20221013225816.h | 33 ++++ .../SubscriptionManager_20221013230931.cpp | 100 ++++++++++++ .../SubscriptionManager_20221013231054.cpp | 127 +++++++++++++++ .history/SubscriptionManager_20221013231834.h | 34 ++++ .history/SubscriptionManager_20221013232252.h | 34 ++++ .history/SubscriptionManager_20221013232501.h | 34 ++++ .history/SubscriptionManager_20221013232513.h | 34 ++++ .history/SubscriptionManager_20221013232519.h | 34 ++++ .../SubscriptionManager_20221013232529.cpp | 127 +++++++++++++++ .../SubscriptionManager_20221013232559.cpp | 128 +++++++++++++++ .../SubscriptionManager_20221013232603.cpp | 128 +++++++++++++++ .../SubscriptionManager_20221013232637.cpp | 128 +++++++++++++++ .../SubscriptionManager_20221013232709.cpp | 128 +++++++++++++++ .../SubscriptionManager_20221013232718.cpp | 127 +++++++++++++++ .../SubscriptionManager_20221014001552.cpp | 141 +++++++++++++++++ .../SubscriptionManager_20221014001640.cpp | 141 +++++++++++++++++ .../SubscriptionManager_20221014001750.cpp | 141 +++++++++++++++++ .../SubscriptionManager_20221014001801.cpp | 141 +++++++++++++++++ .../SubscriptionManager_20221014001829.cpp | 141 +++++++++++++++++ .../SubscriptionManager_20221014001848.cpp | 141 +++++++++++++++++ .../SubscriptionManager_20221014002019.cpp | 141 +++++++++++++++++ .../SubscriptionManager_20221014002052.cpp | 141 +++++++++++++++++ .../SubscriptionManager_20221014002112.cpp | 141 +++++++++++++++++ .../SubscriptionManager_20221014002118.cpp | 141 +++++++++++++++++ .../SubscriptionManager_20221014002130.cpp | 141 +++++++++++++++++ .../SubscriptionManager_20221014002136.cpp | 141 +++++++++++++++++ .../SubscriptionManager_20221014002203.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221014002300.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221014002351.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221014002355.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221014002404.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221014002416.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221014002543.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221014002547.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221014002751.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221014002909.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221014002931.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221014002952.cpp | 141 +++++++++++++++++ .../SubscriptionManager_20221014003012.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221014003016.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221014003032.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221014003110.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221014003112.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221014003118.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221014003740.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221014003842.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221014224510.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221015132404.cpp | 142 +++++++++++++++++ .../SubscriptionManager_20221015135839.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015140050.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015140147.cpp | 146 +++++++++++++++++ .history/SubscriptionManager_20221015140418.h | 37 +++++ .../SubscriptionManager_20221015140432.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015140547.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015140637.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015140703.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015140849.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015140915.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015141339.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015141418.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015141638.cpp | 147 +++++++++++++++++ .../SubscriptionManager_20221015180125.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015181249.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015181639.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015181912.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015182122.cpp | 143 +++++++++++++++++ .../SubscriptionManager_20221015183109.cpp | 143 +++++++++++++++++ .../SubscriptionManager_20221015183204.cpp | 144 +++++++++++++++++ .../SubscriptionManager_20221015183209.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015183518.cpp | 146 +++++++++++++++++ .../SubscriptionManager_20221015191146.cpp | 147 +++++++++++++++++ .../SubscriptionManager_20221015193901.cpp | 147 +++++++++++++++++ .../SubscriptionManager_20221015200446.cpp | 147 +++++++++++++++++ .../SubscriptionManager_20221015200502.cpp | 147 +++++++++++++++++ .history/SubscriptionManager_20221015201436.h | 38 +++++ .history/SubscriptionManager_20221015201440.h | 38 +++++ .../SubscriptionManager_20221015201500.cpp | 147 +++++++++++++++++ .../SubscriptionManager_20221015201542.cpp | 147 +++++++++++++++++ .../SubscriptionManager_20221015201557.cpp | 147 +++++++++++++++++ .../SubscriptionManager_20221016174159.cpp | 148 ++++++++++++++++++ .../SubscriptionManager_20221016174206.cpp | 148 ++++++++++++++++++ .../SubscriptionManager_20221016175448.cpp | 148 ++++++++++++++++++ .../SubscriptionManager_20221016180238.cpp | 148 ++++++++++++++++++ .history/SubscriptionManager_20221016180248.h | 38 +++++ .history/Subscription_20221013190812.h | 46 ++++++ .history/Subscription_20221013190943.cpp | 75 +++++++++ .history/Subscription_20221013204658.h | 47 ++++++ .history/Subscription_20221013204725.cpp | 76 +++++++++ .history/Subscription_20221013204753.cpp | 76 +++++++++ .history/Subscription_20221013205054.cpp | 76 +++++++++ .history/Subscription_20221014003150.h | 47 ++++++ .history/Subscription_20221014212452.h | 49 ++++++ .history/Subscription_20221014212457.h | 47 ++++++ .history/Subscription_20221014212653.h | 48 ++++++ .history/Subscription_20221014220951.cpp | 76 +++++++++ .history/Subscription_20221015131611.cpp | 76 +++++++++ .history/Subscription_20221015142023.cpp | 79 ++++++++++ .history/Subscription_20221015175629.cpp | 79 ++++++++++ .history/Subscription_20221015182553.h | 49 ++++++ .history/Subscription_20221015182613.h | 49 ++++++ .history/Subscription_20221015182633.cpp | 79 ++++++++++ .history/Subscription_20221015182644.cpp | 79 ++++++++++ .history/Subscription_20221015182655.h | 49 ++++++ .history/Subscription_20221015182706.cpp | 79 ++++++++++ .history/Subscription_20221015182712.cpp | 79 ++++++++++ .history/Subscription_20221015203632.h | 49 ++++++ .history/Subscription_20221015203643.cpp | 79 ++++++++++ .history/Subscription_20221015203655.cpp | 79 ++++++++++ .history/Subscription_20221015203702.cpp | 79 ++++++++++ .history/Subscription_20221015203734.h | 49 ++++++ .history/Subscription_20221015203735.cpp | 79 ++++++++++ .history/Subscription_20221015203805.cpp | 79 ++++++++++ .history/Subscription_20221015204939.cpp | 79 ++++++++++ .history/Subscription_20221016151339.cpp | 79 ++++++++++ .history/Subscription_20221016162014.cpp | 79 ++++++++++ .history/Subscription_20221016172637.cpp | 79 ++++++++++ .history/Subscription_20221016172643.cpp | 79 ++++++++++ .history/Subscription_20221016173312.cpp | 79 ++++++++++ .history/Subscription_20221016173458.cpp | 79 ++++++++++ .history/Subscription_20221016173903.cpp | 79 ++++++++++ .history/Subscription_20221016174406.cpp | 79 ++++++++++ .history/Subscription_20221016174556.cpp | 78 +++++++++ .history/Subscription_20221016174634.cpp | 78 +++++++++ .history/Subscription_20221016174652.cpp | 78 +++++++++ .history/Subscription_20221016174712.cpp | 78 +++++++++ .history/Subscription_20221016174852.h | 49 ++++++ .history/Subscription_20221016174910.h | 49 ++++++ .history/Subscription_20221016174913.h | 49 ++++++ .history/Subscription_20221016174921.cpp | 78 +++++++++ .history/Subscription_20221016174923.cpp | 78 +++++++++ .history/Subscription_20221016175152.cpp | 79 ++++++++++ .history/Subscription_20221016175838.cpp | 80 ++++++++++ .history/Subscription_20221016175855.cpp | 80 ++++++++++ .history/Subscription_20221016175911.cpp | 80 ++++++++++ .history/Subscription_20221016175912.cpp | 80 ++++++++++ Subscription.cpp | 29 +++- Subscription.h | 10 +- SubscriptionHandler.h | 25 +++ SubscriptionManager.cpp | 125 +++++++++------ SubscriptionManager.h | 29 ++-- 152 files changed, 15005 insertions(+), 64 deletions(-) create mode 100644 .history/SubscriptionHandler_20221013185305.cpp create mode 100644 .history/SubscriptionHandler_20221013191001.h create mode 100644 .history/SubscriptionHandler_20221013204338.h create mode 100644 .history/SubscriptionHandler_20221013204409.cpp create mode 100644 .history/SubscriptionHandler_20221013204504.h create mode 100644 .history/SubscriptionHandler_20221013204612.cpp create mode 100644 .history/SubscriptionHandler_20221014152050.h create mode 100644 .history/SubscriptionHandler_20221014152131.h create mode 100644 .history/SubscriptionHandler_20221014152241.h create mode 100644 .history/SubscriptionHandler_20221014152252.h create mode 100644 .history/SubscriptionHandler_20221014152513.h create mode 100644 .history/SubscriptionHandler_20221014153238.h create mode 100644 .history/SubscriptionManager_20221013225816.h create mode 100644 .history/SubscriptionManager_20221013230931.cpp create mode 100644 .history/SubscriptionManager_20221013231054.cpp create mode 100644 .history/SubscriptionManager_20221013231834.h create mode 100644 .history/SubscriptionManager_20221013232252.h create mode 100644 .history/SubscriptionManager_20221013232501.h create mode 100644 .history/SubscriptionManager_20221013232513.h create mode 100644 .history/SubscriptionManager_20221013232519.h create mode 100644 .history/SubscriptionManager_20221013232529.cpp create mode 100644 .history/SubscriptionManager_20221013232559.cpp create mode 100644 .history/SubscriptionManager_20221013232603.cpp create mode 100644 .history/SubscriptionManager_20221013232637.cpp create mode 100644 .history/SubscriptionManager_20221013232709.cpp create mode 100644 .history/SubscriptionManager_20221013232718.cpp create mode 100644 .history/SubscriptionManager_20221014001552.cpp create mode 100644 .history/SubscriptionManager_20221014001640.cpp create mode 100644 .history/SubscriptionManager_20221014001750.cpp create mode 100644 .history/SubscriptionManager_20221014001801.cpp create mode 100644 .history/SubscriptionManager_20221014001829.cpp create mode 100644 .history/SubscriptionManager_20221014001848.cpp create mode 100644 .history/SubscriptionManager_20221014002019.cpp create mode 100644 .history/SubscriptionManager_20221014002052.cpp create mode 100644 .history/SubscriptionManager_20221014002112.cpp create mode 100644 .history/SubscriptionManager_20221014002118.cpp create mode 100644 .history/SubscriptionManager_20221014002130.cpp create mode 100644 .history/SubscriptionManager_20221014002136.cpp create mode 100644 .history/SubscriptionManager_20221014002203.cpp create mode 100644 .history/SubscriptionManager_20221014002300.cpp create mode 100644 .history/SubscriptionManager_20221014002351.cpp create mode 100644 .history/SubscriptionManager_20221014002355.cpp create mode 100644 .history/SubscriptionManager_20221014002404.cpp create mode 100644 .history/SubscriptionManager_20221014002416.cpp create mode 100644 .history/SubscriptionManager_20221014002543.cpp create mode 100644 .history/SubscriptionManager_20221014002547.cpp create mode 100644 .history/SubscriptionManager_20221014002751.cpp create mode 100644 .history/SubscriptionManager_20221014002909.cpp create mode 100644 .history/SubscriptionManager_20221014002931.cpp create mode 100644 .history/SubscriptionManager_20221014002952.cpp create mode 100644 .history/SubscriptionManager_20221014003012.cpp create mode 100644 .history/SubscriptionManager_20221014003016.cpp create mode 100644 .history/SubscriptionManager_20221014003032.cpp create mode 100644 .history/SubscriptionManager_20221014003110.cpp create mode 100644 .history/SubscriptionManager_20221014003112.cpp create mode 100644 .history/SubscriptionManager_20221014003118.cpp create mode 100644 .history/SubscriptionManager_20221014003740.cpp create mode 100644 .history/SubscriptionManager_20221014003842.cpp create mode 100644 .history/SubscriptionManager_20221014224510.cpp create mode 100644 .history/SubscriptionManager_20221015132404.cpp create mode 100644 .history/SubscriptionManager_20221015135839.cpp create mode 100644 .history/SubscriptionManager_20221015140050.cpp create mode 100644 .history/SubscriptionManager_20221015140147.cpp create mode 100644 .history/SubscriptionManager_20221015140418.h create mode 100644 .history/SubscriptionManager_20221015140432.cpp create mode 100644 .history/SubscriptionManager_20221015140547.cpp create mode 100644 .history/SubscriptionManager_20221015140637.cpp create mode 100644 .history/SubscriptionManager_20221015140703.cpp create mode 100644 .history/SubscriptionManager_20221015140849.cpp create mode 100644 .history/SubscriptionManager_20221015140915.cpp create mode 100644 .history/SubscriptionManager_20221015141339.cpp create mode 100644 .history/SubscriptionManager_20221015141418.cpp create mode 100644 .history/SubscriptionManager_20221015141638.cpp create mode 100644 .history/SubscriptionManager_20221015180125.cpp create mode 100644 .history/SubscriptionManager_20221015181249.cpp create mode 100644 .history/SubscriptionManager_20221015181639.cpp create mode 100644 .history/SubscriptionManager_20221015181912.cpp create mode 100644 .history/SubscriptionManager_20221015182122.cpp create mode 100644 .history/SubscriptionManager_20221015183109.cpp create mode 100644 .history/SubscriptionManager_20221015183204.cpp create mode 100644 .history/SubscriptionManager_20221015183209.cpp create mode 100644 .history/SubscriptionManager_20221015183518.cpp create mode 100644 .history/SubscriptionManager_20221015191146.cpp create mode 100644 .history/SubscriptionManager_20221015193901.cpp create mode 100644 .history/SubscriptionManager_20221015200446.cpp create mode 100644 .history/SubscriptionManager_20221015200502.cpp create mode 100644 .history/SubscriptionManager_20221015201436.h create mode 100644 .history/SubscriptionManager_20221015201440.h create mode 100644 .history/SubscriptionManager_20221015201500.cpp create mode 100644 .history/SubscriptionManager_20221015201542.cpp create mode 100644 .history/SubscriptionManager_20221015201557.cpp create mode 100644 .history/SubscriptionManager_20221016174159.cpp create mode 100644 .history/SubscriptionManager_20221016174206.cpp create mode 100644 .history/SubscriptionManager_20221016175448.cpp create mode 100644 .history/SubscriptionManager_20221016180238.cpp create mode 100644 .history/SubscriptionManager_20221016180248.h create mode 100644 .history/Subscription_20221013190812.h create mode 100644 .history/Subscription_20221013190943.cpp create mode 100644 .history/Subscription_20221013204658.h create mode 100644 .history/Subscription_20221013204725.cpp create mode 100644 .history/Subscription_20221013204753.cpp create mode 100644 .history/Subscription_20221013205054.cpp create mode 100644 .history/Subscription_20221014003150.h create mode 100644 .history/Subscription_20221014212452.h create mode 100644 .history/Subscription_20221014212457.h create mode 100644 .history/Subscription_20221014212653.h create mode 100644 .history/Subscription_20221014220951.cpp create mode 100644 .history/Subscription_20221015131611.cpp create mode 100644 .history/Subscription_20221015142023.cpp create mode 100644 .history/Subscription_20221015175629.cpp create mode 100644 .history/Subscription_20221015182553.h create mode 100644 .history/Subscription_20221015182613.h create mode 100644 .history/Subscription_20221015182633.cpp create mode 100644 .history/Subscription_20221015182644.cpp create mode 100644 .history/Subscription_20221015182655.h create mode 100644 .history/Subscription_20221015182706.cpp create mode 100644 .history/Subscription_20221015182712.cpp create mode 100644 .history/Subscription_20221015203632.h create mode 100644 .history/Subscription_20221015203643.cpp create mode 100644 .history/Subscription_20221015203655.cpp create mode 100644 .history/Subscription_20221015203702.cpp create mode 100644 .history/Subscription_20221015203734.h create mode 100644 .history/Subscription_20221015203735.cpp create mode 100644 .history/Subscription_20221015203805.cpp create mode 100644 .history/Subscription_20221015204939.cpp create mode 100644 .history/Subscription_20221016151339.cpp create mode 100644 .history/Subscription_20221016162014.cpp create mode 100644 .history/Subscription_20221016172637.cpp create mode 100644 .history/Subscription_20221016172643.cpp create mode 100644 .history/Subscription_20221016173312.cpp create mode 100644 .history/Subscription_20221016173458.cpp create mode 100644 .history/Subscription_20221016173903.cpp create mode 100644 .history/Subscription_20221016174406.cpp create mode 100644 .history/Subscription_20221016174556.cpp create mode 100644 .history/Subscription_20221016174634.cpp create mode 100644 .history/Subscription_20221016174652.cpp create mode 100644 .history/Subscription_20221016174712.cpp create mode 100644 .history/Subscription_20221016174852.h create mode 100644 .history/Subscription_20221016174910.h create mode 100644 .history/Subscription_20221016174913.h create mode 100644 .history/Subscription_20221016174921.cpp create mode 100644 .history/Subscription_20221016174923.cpp create mode 100644 .history/Subscription_20221016175152.cpp create mode 100644 .history/Subscription_20221016175838.cpp create mode 100644 .history/Subscription_20221016175855.cpp create mode 100644 .history/Subscription_20221016175911.cpp create mode 100644 .history/Subscription_20221016175912.cpp create mode 100644 SubscriptionHandler.h diff --git a/.history/SubscriptionHandler_20221013185305.cpp b/.history/SubscriptionHandler_20221013185305.cpp new file mode 100644 index 0000000..ce40556 --- /dev/null +++ b/.history/SubscriptionHandler_20221013185305.cpp @@ -0,0 +1,68 @@ +#include "Subscription.h" +#include "TCPSession.h" +#include "Log.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + +} diff --git a/.history/SubscriptionHandler_20221013191001.h b/.history/SubscriptionHandler_20221013191001.h new file mode 100644 index 0000000..43d7bd0 --- /dev/null +++ b/.history/SubscriptionHandler_20221013191001.h @@ -0,0 +1,24 @@ +#ifndef __SubscriptionHandler_h__ +#define __SubscriptionHandler_h__ + +#include "ZString.h" +#include +#include + +namespace core +{ + + class SubscriptionHandler + { + + public: + SubscriptionHandler(); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + }; +} + +#endif diff --git a/.history/SubscriptionHandler_20221013204338.h b/.history/SubscriptionHandler_20221013204338.h new file mode 100644 index 0000000..6fc8994 --- /dev/null +++ b/.history/SubscriptionHandler_20221013204338.h @@ -0,0 +1,23 @@ +#ifndef __SubscriptionHandler_h__ +#define __SubscriptionHandler_h__ + +#include "ZString.h" +#include +#include + +namespace core +{ + + class SubscriptionHandler + { + + public: + SubscriptionHandler(); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + }; +} + +#endif diff --git a/.history/SubscriptionHandler_20221013204409.cpp b/.history/SubscriptionHandler_20221013204409.cpp new file mode 100644 index 0000000..23c2e94 --- /dev/null +++ b/.history/SubscriptionHandler_20221013204409.cpp @@ -0,0 +1,68 @@ +#include "SubscriptionHandler.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + +} diff --git a/.history/SubscriptionHandler_20221013204504.h b/.history/SubscriptionHandler_20221013204504.h new file mode 100644 index 0000000..6fc8994 --- /dev/null +++ b/.history/SubscriptionHandler_20221013204504.h @@ -0,0 +1,23 @@ +#ifndef __SubscriptionHandler_h__ +#define __SubscriptionHandler_h__ + +#include "ZString.h" +#include +#include + +namespace core +{ + + class SubscriptionHandler + { + + public: + SubscriptionHandler(); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + }; +} + +#endif diff --git a/.history/SubscriptionHandler_20221013204612.cpp b/.history/SubscriptionHandler_20221013204612.cpp new file mode 100644 index 0000000..45cb3fb --- /dev/null +++ b/.history/SubscriptionHandler_20221013204612.cpp @@ -0,0 +1,68 @@ +#include "Log.h" +#include "Subscription.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + +} diff --git a/.history/SubscriptionHandler_20221014152050.h b/.history/SubscriptionHandler_20221014152050.h new file mode 100644 index 0000000..a625a99 --- /dev/null +++ b/.history/SubscriptionHandler_20221014152050.h @@ -0,0 +1,22 @@ +#ifndef __SubscriptionHandler_h__ +#define __SubscriptionHandler_h__ + +#include "TCPSession.h" +#include "ZString.h" +#include +#include +#include + +namespace core +{ + + class SubscriptionHandler + { + + public: + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + virtual int onSubscribe(TCPSession &session){}; + }; +} + +#endif diff --git a/.history/SubscriptionHandler_20221014152131.h b/.history/SubscriptionHandler_20221014152131.h new file mode 100644 index 0000000..fef3b55 --- /dev/null +++ b/.history/SubscriptionHandler_20221014152131.h @@ -0,0 +1,22 @@ +#ifndef __SubscriptionHandler_h__ +#define __SubscriptionHandler_h__ + +#include "TCPSession.h" +#include "ZString.h" +#include +#include +#include + +namespace core +{ + + class SubscriptionHandler + { + + public: + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + virtual int onSubscribe(TCPSession &session) {} + }; +} + +#endif diff --git a/.history/SubscriptionHandler_20221014152241.h b/.history/SubscriptionHandler_20221014152241.h new file mode 100644 index 0000000..1c8484b --- /dev/null +++ b/.history/SubscriptionHandler_20221014152241.h @@ -0,0 +1,22 @@ +#ifndef __SubscriptionHandler_h__ +#define __SubscriptionHandler_h__ + +#include "TCPSession.h" +#include "ZString.h" +#include +#include +#include + +namespace core +{ + + class SubscriptionHandler : public Base + { + + public: + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + virtual int onSubscribe(TCPSession &session) {} + }; +} + +#endif diff --git a/.history/SubscriptionHandler_20221014152252.h b/.history/SubscriptionHandler_20221014152252.h new file mode 100644 index 0000000..fef3b55 --- /dev/null +++ b/.history/SubscriptionHandler_20221014152252.h @@ -0,0 +1,22 @@ +#ifndef __SubscriptionHandler_h__ +#define __SubscriptionHandler_h__ + +#include "TCPSession.h" +#include "ZString.h" +#include +#include +#include + +namespace core +{ + + class SubscriptionHandler + { + + public: + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + virtual int onSubscribe(TCPSession &session) {} + }; +} + +#endif diff --git a/.history/SubscriptionHandler_20221014152513.h b/.history/SubscriptionHandler_20221014152513.h new file mode 100644 index 0000000..7ad43f5 --- /dev/null +++ b/.history/SubscriptionHandler_20221014152513.h @@ -0,0 +1,22 @@ +#ifndef __SubscriptionHandler_h__ +#define __SubscriptionHandler_h__ + +#include "TCPSession.h" +#include "ZString.h" +#include +#include +#include + +namespace core +{ + + class SubscriptionHandler + { + + public: + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + virtual int onSubscribe(TCPSession &session) { return 1; } + }; +} + +#endif diff --git a/.history/SubscriptionHandler_20221014153238.h b/.history/SubscriptionHandler_20221014153238.h new file mode 100644 index 0000000..71929a1 --- /dev/null +++ b/.history/SubscriptionHandler_20221014153238.h @@ -0,0 +1,23 @@ +#ifndef __SubscriptionHandler_h__ +#define __SubscriptionHandler_h__ + +#include "ZString.h" +#include +#include +#include + +namespace core +{ + + class TCPSession; + + class SubscriptionHandler + { + + public: + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + virtual int onSubscribe(TCPSession &session); + }; +} + +#endif diff --git a/.history/SubscriptionManager_20221013225816.h b/.history/SubscriptionManager_20221013225816.h new file mode 100644 index 0000000..d748e1c --- /dev/null +++ b/.history/SubscriptionManager_20221013225816.h @@ -0,0 +1,33 @@ +#ifndef __SubscriptionManager_h__ +#define __SubscriptionManager_h__ + +#include "TCPSession.h" +#include "Subscription.h" +#include "Command.h" +#include "ZString.h" +#include +#include + +namespace core { + + class SubscriptionManager : public Command { + + public: + SubscriptionManager(); + + int add(Subscription &subscription); + int addHandler(std::string name, SubscriptionHandler &handler) + + int removeSessionSubscriptions(TCPSession &session); + + int processCommand(coreutils::ZString &request, TCPSession &session) override; + + private: + std::map subscriptions; + std::map handlers; + std::mutex lock; + + }; +} + +#endif diff --git a/.history/SubscriptionManager_20221013230931.cpp b/.history/SubscriptionManager_20221013230931.cpp new file mode 100644 index 0000000..bff4406 --- /dev/null +++ b/.history/SubscriptionManager_20221013230931.cpp @@ -0,0 +1,100 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core { + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription, SubscriptionHandler *handler) { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + handlers. + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for(auto [key, subscription] : subscriptions) { + if(temp != "") { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if(subscription->owner == &session) { + temp = key; + delete subscription; + ++countPublished; + } + } + if(temp != "") { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) { + if(request[0].equals("publish")) { + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } else if(request[0].equals("catalog")) { + session.out << ":catalog:"; + for(auto const& [key, subscription] : subscriptions) { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if(request[1].equals(subscription->id)) { + if(request[0].equals("unpublish")) { + subscriptions.erase(request[1].str()); + } else if(request[0].equals("subscribe")) { + subscription->subscribe(session); + return 1; + } else if(request[0].equals("unsubscribe")) { + subscription->unsubscribe(session); + return 1; + } else if(request[0].equals("event")) { + std::stringstream out; + subscription->process(request, out, session); + if(subscription->mode == "*ANYONE") { + subscription->event(out); + return 1; + } else if(subscription->mode == "*SUBSCRIBERS") { + if(subscription->ifSubscriber(session)) { + subscription->event(out); + return 1; + } + } else if(subscription->mode == "*AUTHOR") { + if(subscription->owner == &session) { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } + +} diff --git a/.history/SubscriptionManager_20221013231054.cpp b/.history/SubscriptionManager_20221013231054.cpp new file mode 100644 index 0000000..2c897ba --- /dev/null +++ b/.history/SubscriptionManager_20221013231054.cpp @@ -0,0 +1,127 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription, SubscriptionHandler *handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + handlers.lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } + +} diff --git a/.history/SubscriptionManager_20221013231834.h b/.history/SubscriptionManager_20221013231834.h new file mode 100644 index 0000000..6113b52 --- /dev/null +++ b/.history/SubscriptionManager_20221013231834.h @@ -0,0 +1,34 @@ +#ifndef __SubscriptionManager_h__ +#define __SubscriptionManager_h__ + +#include "Command.h" +#include "Subscription.h" +#include "TCPSession.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class SubscriptionManager : public Command + { + + public: + SubscriptionManager(); + + int add(Subscription &subscription); + int addHandler(std::string name, SubscriptionHandler &handler); + + int removeSessionSubscriptions(TCPSession &session); + + int processCommand(coreutils::ZString &request, TCPSession &session) override; + + private: + std::map subscriptions; + std::map handlers; + std::mutex lock; + }; +} + +#endif diff --git a/.history/SubscriptionManager_20221013232252.h b/.history/SubscriptionManager_20221013232252.h new file mode 100644 index 0000000..69e27ad --- /dev/null +++ b/.history/SubscriptionManager_20221013232252.h @@ -0,0 +1,34 @@ +#ifndef __SubscriptionManager_h__ +#define __SubscriptionManager_h__ + +#include "Command.h" +#include "Subscription.h" +#include "TCPSession.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class SubscriptionManager : public Command + { + + public: + SubscriptionManager(); + + int add(Subscription &subscription); + int addHandler(std::string name, SubscriptionHandler &handler); + + int removeSessionSubscriptions(TCPSession &session); + + int processCommand(coreutils::ZString &request, TCPSession &session) override; + + private: + std::map subscriptions; + std::map handlers; + std::mutex lock; + }; +} + +#endif diff --git a/.history/SubscriptionManager_20221013232501.h b/.history/SubscriptionManager_20221013232501.h new file mode 100644 index 0000000..33bfae4 --- /dev/null +++ b/.history/SubscriptionManager_20221013232501.h @@ -0,0 +1,34 @@ +#ifndef __SubscriptionManager_h__ +#define __SubscriptionManager_h__ + +#include "Command.h" +#include "Subscription.h" +#include "TCPSession.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class SubscriptionManager : public Command + { + + public: + SubscriptionManager(); + + int add(Subscription &subscription, SubscriptionHandler &handlers); + int addHandler(std::string name, SubscriptionHandler &handler); + + int removeSessionSubscriptions(TCPSession &session); + + int processCommand(coreutils::ZString &request, TCPSession &session) override; + + private: + std::map subscriptions; + std::map handlers; + std::mutex lock; + }; +} + +#endif diff --git a/.history/SubscriptionManager_20221013232513.h b/.history/SubscriptionManager_20221013232513.h new file mode 100644 index 0000000..22b4d1d --- /dev/null +++ b/.history/SubscriptionManager_20221013232513.h @@ -0,0 +1,34 @@ +#ifndef __SubscriptionManager_h__ +#define __SubscriptionManager_h__ + +#include "Command.h" +#include "Subscription.h" +#include "TCPSession.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class SubscriptionManager : public Command + { + + public: + SubscriptionManager(); + + int add(Subscription &subscription, SubscriptionHandler *handlers); + int addHandler(std::string name, SubscriptionHandler &handler); + + int removeSessionSubscriptions(TCPSession &session); + + int processCommand(coreutils::ZString &request, TCPSession &session) override; + + private: + std::map subscriptions; + std::map handlers; + std::mutex lock; + }; +} + +#endif diff --git a/.history/SubscriptionManager_20221013232519.h b/.history/SubscriptionManager_20221013232519.h new file mode 100644 index 0000000..4e31671 --- /dev/null +++ b/.history/SubscriptionManager_20221013232519.h @@ -0,0 +1,34 @@ +#ifndef __SubscriptionManager_h__ +#define __SubscriptionManager_h__ + +#include "Command.h" +#include "Subscription.h" +#include "TCPSession.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class SubscriptionManager : public Command + { + + public: + SubscriptionManager(); + + int add(Subscription &subscription, SubscriptionHandler *handler); + int addHandler(std::string name, SubscriptionHandler &handler); + + int removeSessionSubscriptions(TCPSession &session); + + int processCommand(coreutils::ZString &request, TCPSession &session) override; + + private: + std::map subscriptions; + std::map handlers; + std::mutex lock; + }; +} + +#endif diff --git a/.history/SubscriptionManager_20221013232529.cpp b/.history/SubscriptionManager_20221013232529.cpp new file mode 100644 index 0000000..d618840 --- /dev/null +++ b/.history/SubscriptionManager_20221013232529.cpp @@ -0,0 +1,127 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription, SubscriptionHandler *handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + handler.lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } + +} diff --git a/.history/SubscriptionManager_20221013232559.cpp b/.history/SubscriptionManager_20221013232559.cpp new file mode 100644 index 0000000..e4e91fb --- /dev/null +++ b/.history/SubscriptionManager_20221013232559.cpp @@ -0,0 +1,128 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription, SubscriptionHandler *handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + + handler.lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } + +} diff --git a/.history/SubscriptionManager_20221013232603.cpp b/.history/SubscriptionManager_20221013232603.cpp new file mode 100644 index 0000000..9cb8023 --- /dev/null +++ b/.history/SubscriptionManager_20221013232603.cpp @@ -0,0 +1,128 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription, SubscriptionHandler *handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + + handlers.lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } + +} diff --git a/.history/SubscriptionManager_20221013232637.cpp b/.history/SubscriptionManager_20221013232637.cpp new file mode 100644 index 0000000..b77390f --- /dev/null +++ b/.history/SubscriptionManager_20221013232637.cpp @@ -0,0 +1,128 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription, SubscriptionHandler *handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } + +} diff --git a/.history/SubscriptionManager_20221013232709.cpp b/.history/SubscriptionManager_20221013232709.cpp new file mode 100644 index 0000000..75f920d --- /dev/null +++ b/.history/SubscriptionManager_20221013232709.cpp @@ -0,0 +1,128 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription, SubscriptionHandler *handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } + +} diff --git a/.history/SubscriptionManager_20221013232718.cpp b/.history/SubscriptionManager_20221013232718.cpp new file mode 100644 index 0000000..616f635 --- /dev/null +++ b/.history/SubscriptionManager_20221013232718.cpp @@ -0,0 +1,127 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription, SubscriptionHandler *handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } + +} diff --git a/.history/SubscriptionManager_20221014001552.cpp b/.history/SubscriptionManager_20221014001552.cpp new file mode 100644 index 0000000..8324d3c --- /dev/null +++ b/.history/SubscriptionManager_20221014001552.cpp @@ -0,0 +1,141 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler) + subscription.setHandler = handler[handler]; + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014001640.cpp b/.history/SubscriptionManager_20221014001640.cpp new file mode 100644 index 0000000..784a103 --- /dev/null +++ b/.history/SubscriptionManager_20221014001640.cpp @@ -0,0 +1,141 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler) + subscription->setHandler = handler[handler]; + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014001750.cpp b/.history/SubscriptionManager_20221014001750.cpp new file mode 100644 index 0000000..bae78e2 --- /dev/null +++ b/.history/SubscriptionManager_20221014001750.cpp @@ -0,0 +1,141 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers) + subscription->setHandler = handler[handler]; + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014001801.cpp b/.history/SubscriptionManager_20221014001801.cpp new file mode 100644 index 0000000..784a103 --- /dev/null +++ b/.history/SubscriptionManager_20221014001801.cpp @@ -0,0 +1,141 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler) + subscription->setHandler = handler[handler]; + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014001829.cpp b/.history/SubscriptionManager_20221014001829.cpp new file mode 100644 index 0000000..1278eb1 --- /dev/null +++ b/.history/SubscriptionManager_20221014001829.cpp @@ -0,0 +1,141 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler) + subscription->setHandler = handlers[handler]; + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014001848.cpp b/.history/SubscriptionManager_20221014001848.cpp new file mode 100644 index 0000000..7405bf1 --- /dev/null +++ b/.history/SubscriptionManager_20221014001848.cpp @@ -0,0 +1,141 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler) + subscription->setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002019.cpp b/.history/SubscriptionManager_20221014002019.cpp new file mode 100644 index 0000000..efc059b --- /dev/null +++ b/.history/SubscriptionManager_20221014002019.cpp @@ -0,0 +1,141 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler) + subscription->setHandler(*handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002052.cpp b/.history/SubscriptionManager_20221014002052.cpp new file mode 100644 index 0000000..7405bf1 --- /dev/null +++ b/.history/SubscriptionManager_20221014002052.cpp @@ -0,0 +1,141 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler) + subscription->setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002112.cpp b/.history/SubscriptionManager_20221014002112.cpp new file mode 100644 index 0000000..9324632 --- /dev/null +++ b/.history/SubscriptionManager_20221014002112.cpp @@ -0,0 +1,141 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler != NULL) + subscription->setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002118.cpp b/.history/SubscriptionManager_20221014002118.cpp new file mode 100644 index 0000000..23e3e53 --- /dev/null +++ b/.history/SubscriptionManager_20221014002118.cpp @@ -0,0 +1,141 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler == NULL) + subscription->setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002130.cpp b/.history/SubscriptionManager_20221014002130.cpp new file mode 100644 index 0000000..4580af7 --- /dev/null +++ b/.history/SubscriptionManager_20221014002130.cpp @@ -0,0 +1,141 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler = !NULL) + subscription->setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002136.cpp b/.history/SubscriptionManager_20221014002136.cpp new file mode 100644 index 0000000..7405bf1 --- /dev/null +++ b/.history/SubscriptionManager_20221014002136.cpp @@ -0,0 +1,141 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler) + subscription->setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002203.cpp b/.history/SubscriptionManager_20221014002203.cpp new file mode 100644 index 0000000..a26a962 --- /dev/null +++ b/.history/SubscriptionManager_20221014002203.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler) + subscription.setHandler(handlers[handler]); + subscription->setHandler(); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(SubscriptionHandler &handler, std::string name) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002300.cpp b/.history/SubscriptionManager_20221014002300.cpp new file mode 100644 index 0000000..ccfb690 --- /dev/null +++ b/.history/SubscriptionManager_20221014002300.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler) + subscription.setHandler(handlers[handler]); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002351.cpp b/.history/SubscriptionManager_20221014002351.cpp new file mode 100644 index 0000000..00c9082 --- /dev/null +++ b/.history/SubscriptionManager_20221014002351.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers != NULL) + subscription.setHandler(handlers[handler]); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002355.cpp b/.history/SubscriptionManager_20221014002355.cpp new file mode 100644 index 0000000..17f04bb --- /dev/null +++ b/.history/SubscriptionManager_20221014002355.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers = NULL) + subscription.setHandler(handlers[handler]); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002404.cpp b/.history/SubscriptionManager_20221014002404.cpp new file mode 100644 index 0000000..a07e58e --- /dev/null +++ b/.history/SubscriptionManager_20221014002404.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers == NULL) + subscription.setHandler(handlers[handler]); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002416.cpp b/.history/SubscriptionManager_20221014002416.cpp new file mode 100644 index 0000000..33ca4eb --- /dev/null +++ b/.history/SubscriptionManager_20221014002416.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers) + subscription.setHandler(handlers[handler]); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002543.cpp b/.history/SubscriptionManager_20221014002543.cpp new file mode 100644 index 0000000..5e29a2f --- /dev/null +++ b/.history/SubscriptionManager_20221014002543.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (*handlers) + subscription.setHandler(handlers[handler]); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002547.cpp b/.history/SubscriptionManager_20221014002547.cpp new file mode 100644 index 0000000..33ca4eb --- /dev/null +++ b/.history/SubscriptionManager_20221014002547.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers) + subscription.setHandler(handlers[handler]); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002751.cpp b/.history/SubscriptionManager_20221014002751.cpp new file mode 100644 index 0000000..66ccaf0 --- /dev/null +++ b/.history/SubscriptionManager_20221014002751.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers.empty()) + subscription.setHandler(handlers[handler]); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002909.cpp b/.history/SubscriptionManager_20221014002909.cpp new file mode 100644 index 0000000..1422f5b --- /dev/null +++ b/.history/SubscriptionManager_20221014002909.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers.find(handler)) + subscription.setHandler(handlers[handler]); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002931.cpp b/.history/SubscriptionManager_20221014002931.cpp new file mode 100644 index 0000000..c7ac40c --- /dev/null +++ b/.history/SubscriptionManager_20221014002931.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers.find(handler) == handlers.end()) + subscription.setHandler(handlers[handler]); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014002952.cpp b/.history/SubscriptionManager_20221014002952.cpp new file mode 100644 index 0000000..69b185b --- /dev/null +++ b/.history/SubscriptionManager_20221014002952.cpp @@ -0,0 +1,141 @@ +#include "Log.h" +#include "SubscriptionManager.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014003012.cpp b/.history/SubscriptionManager_20221014003012.cpp new file mode 100644 index 0000000..558ff62 --- /dev/null +++ b/.history/SubscriptionManager_20221014003012.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers.find(handler) == handlers.end()) + { + } + else + { + subscription.setHandler(handlers[handler]); + lock.unlock(); + } + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014003016.cpp b/.history/SubscriptionManager_20221014003016.cpp new file mode 100644 index 0000000..558ff62 --- /dev/null +++ b/.history/SubscriptionManager_20221014003016.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers.find(handler) == handlers.end()) + { + } + else + { + subscription.setHandler(handlers[handler]); + lock.unlock(); + } + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014003032.cpp b/.history/SubscriptionManager_20221014003032.cpp new file mode 100644 index 0000000..558ff62 --- /dev/null +++ b/.history/SubscriptionManager_20221014003032.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers.find(handler) == handlers.end()) + { + } + else + { + subscription.setHandler(handlers[handler]); + lock.unlock(); + } + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014003110.cpp b/.history/SubscriptionManager_20221014003110.cpp new file mode 100644 index 0000000..6f3cc96 --- /dev/null +++ b/.history/SubscriptionManager_20221014003110.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers.find(handler) == handlers.end()) + { + } + else + { + subscription.setHandler(handlers[handler]); + lock.unlock(); + } + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscriptions = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014003112.cpp b/.history/SubscriptionManager_20221014003112.cpp new file mode 100644 index 0000000..c6463cd --- /dev/null +++ b/.history/SubscriptionManager_20221014003112.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers.find(handler) == handlers.end()) + { + } + else + { + subscription.setHandler(handlers[handler]); + lock.unlock(); + } + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscriptions = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscriptions)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014003118.cpp b/.history/SubscriptionManager_20221014003118.cpp new file mode 100644 index 0000000..558ff62 --- /dev/null +++ b/.history/SubscriptionManager_20221014003118.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handlers.find(handler) == handlers.end()) + { + } + else + { + subscription.setHandler(handlers[handler]); + lock.unlock(); + } + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014003740.cpp b/.history/SubscriptionManager_20221014003740.cpp new file mode 100644 index 0000000..ccfb690 --- /dev/null +++ b/.history/SubscriptionManager_20221014003740.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler) + subscription.setHandler(handlers[handler]); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014003842.cpp b/.history/SubscriptionManager_20221014003842.cpp new file mode 100644 index 0000000..c04fdce --- /dev/null +++ b/.history/SubscriptionManager_20221014003842.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + if (handler) + subscription.setHandler = handlers[handler]; + + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + if (request.getList().size() > 2) + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; +} +} diff --git a/.history/SubscriptionManager_20221014224510.cpp b/.history/SubscriptionManager_20221014224510.cpp new file mode 100644 index 0000000..fd31da3 --- /dev/null +++ b/.history/SubscriptionManager_20221014224510.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + Subscription *newSubscription; + if (request.getList().size() > 2) + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015132404.cpp b/.history/SubscriptionManager_20221015132404.cpp new file mode 100644 index 0000000..6d5fa0b --- /dev/null +++ b/.history/SubscriptionManager_20221015132404.cpp @@ -0,0 +1,142 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + Subscription *newSubscription; + // if (request.getList().size() > 2) + // newSubscription = new Subscription(request[1].str(), session, request[2].str()); + // else + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015135839.cpp b/.history/SubscriptionManager_20221015135839.cpp new file mode 100644 index 0000000..3beda7c --- /dev/null +++ b/.history/SubscriptionManager_20221015135839.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + Subscription *newSubscription; + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015140050.cpp b/.history/SubscriptionManager_20221015140050.cpp new file mode 100644 index 0000000..71a21da --- /dev/null +++ b/.history/SubscriptionManager_20221015140050.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + Subscription *newSubscription; + if (request.getList().size() > 3) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015140147.cpp b/.history/SubscriptionManager_20221015140147.cpp new file mode 100644 index 0000000..4baacdb --- /dev/null +++ b/.history/SubscriptionManager_20221015140147.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + Subscription *newSubscription; + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015140418.h b/.history/SubscriptionManager_20221015140418.h new file mode 100644 index 0000000..e370a76 --- /dev/null +++ b/.history/SubscriptionManager_20221015140418.h @@ -0,0 +1,37 @@ +#ifndef __SubscriptionManager_h__ +#define __SubscriptionManager_h__ + +#include "Command.h" +#include "Subscription.h" +#include "SubscriptionHandler.h" +#include "TCPSession.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class SubscriptionManager : public Command + { + + public: + SubscriptionManager(); + + int add(Subscription &subscription); + int add(Subscription &subscription, std::string handler); + int addHandler(std::string name, SubscriptionHandler &handler); + + int removeSessionSubscriptions(TCPSession &session); + + int processCommand(coreutils::ZString &request, TCPSession &session) override; + + private: + std::map subscriptions; + std::map handlers; + Subscription *newSubscription; + std::mutex lock; + }; +} + +#endif diff --git a/.history/SubscriptionManager_20221015140432.cpp b/.history/SubscriptionManager_20221015140432.cpp new file mode 100644 index 0000000..a7b9c82 --- /dev/null +++ b/.history/SubscriptionManager_20221015140432.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015140547.cpp b/.history/SubscriptionManager_20221015140547.cpp new file mode 100644 index 0000000..f976bcf --- /dev/null +++ b/.history/SubscriptionManager_20221015140547.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.str().getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015140637.cpp b/.history/SubscriptionManager_20221015140637.cpp new file mode 100644 index 0000000..92e4dc5 --- /dev/null +++ b/.history/SubscriptionManager_20221015140637.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getLength.size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015140703.cpp b/.history/SubscriptionManager_20221015140703.cpp new file mode 100644 index 0000000..a7b9c82 --- /dev/null +++ b/.history/SubscriptionManager_20221015140703.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015140849.cpp b/.history/SubscriptionManager_20221015140849.cpp new file mode 100644 index 0000000..a7b9c82 --- /dev/null +++ b/.history/SubscriptionManager_20221015140849.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015140915.cpp b/.history/SubscriptionManager_20221015140915.cpp new file mode 100644 index 0000000..fdfdec3 --- /dev/null +++ b/.history/SubscriptionManager_20221015140915.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + // newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015141339.cpp b/.history/SubscriptionManager_20221015141339.cpp new file mode 100644 index 0000000..b120314 --- /dev/null +++ b/.history/SubscriptionManager_20221015141339.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + // newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015141418.cpp b/.history/SubscriptionManager_20221015141418.cpp new file mode 100644 index 0000000..7b8d183 --- /dev/null +++ b/.history/SubscriptionManager_20221015141418.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + else + { + // newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015141638.cpp b/.history/SubscriptionManager_20221015141638.cpp new file mode 100644 index 0000000..6424f60 --- /dev/null +++ b/.history/SubscriptionManager_20221015141638.cpp @@ -0,0 +1,147 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + } + + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015180125.cpp b/.history/SubscriptionManager_20221015180125.cpp new file mode 100644 index 0000000..df0809a --- /dev/null +++ b/.history/SubscriptionManager_20221015180125.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015181249.cpp b/.history/SubscriptionManager_20221015181249.cpp new file mode 100644 index 0000000..464076a --- /dev/null +++ b/.history/SubscriptionManager_20221015181249.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 3) + { + + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015181639.cpp b/.history/SubscriptionManager_20221015181639.cpp new file mode 100644 index 0000000..be48bd0 --- /dev/null +++ b/.history/SubscriptionManager_20221015181639.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() >= 2) + { + + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015181912.cpp b/.history/SubscriptionManager_20221015181912.cpp new file mode 100644 index 0000000..df0809a --- /dev/null +++ b/.history/SubscriptionManager_20221015181912.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015182122.cpp b/.history/SubscriptionManager_20221015182122.cpp new file mode 100644 index 0000000..3ed7565 --- /dev/null +++ b/.history/SubscriptionManager_20221015182122.cpp @@ -0,0 +1,143 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015183109.cpp b/.history/SubscriptionManager_20221015183109.cpp new file mode 100644 index 0000000..4a7a545 --- /dev/null +++ b/.history/SubscriptionManager_20221015183109.cpp @@ -0,0 +1,143 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() >= 2) + + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + else + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015183204.cpp b/.history/SubscriptionManager_20221015183204.cpp new file mode 100644 index 0000000..0981e51 --- /dev/null +++ b/.history/SubscriptionManager_20221015183204.cpp @@ -0,0 +1,144 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() >= 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + else + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015183209.cpp b/.history/SubscriptionManager_20221015183209.cpp new file mode 100644 index 0000000..8d76f43 --- /dev/null +++ b/.history/SubscriptionManager_20221015183209.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() >= 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015183518.cpp b/.history/SubscriptionManager_20221015183518.cpp new file mode 100644 index 0000000..a7b9c82 --- /dev/null +++ b/.history/SubscriptionManager_20221015183518.cpp @@ -0,0 +1,146 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015191146.cpp b/.history/SubscriptionManager_20221015191146.cpp new file mode 100644 index 0000000..1ab0538 --- /dev/null +++ b/.history/SubscriptionManager_20221015191146.cpp @@ -0,0 +1,147 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015193901.cpp b/.history/SubscriptionManager_20221015193901.cpp new file mode 100644 index 0000000..1db78ab --- /dev/null +++ b/.history/SubscriptionManager_20221015193901.cpp @@ -0,0 +1,147 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015200446.cpp b/.history/SubscriptionManager_20221015200446.cpp new file mode 100644 index 0000000..0804ac6 --- /dev/null +++ b/.history/SubscriptionManager_20221015200446.cpp @@ -0,0 +1,147 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + subscription.setHandler(handlers["handler"]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015200502.cpp b/.history/SubscriptionManager_20221015200502.cpp new file mode 100644 index 0000000..1db78ab --- /dev/null +++ b/.history/SubscriptionManager_20221015200502.cpp @@ -0,0 +1,147 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015201436.h b/.history/SubscriptionManager_20221015201436.h new file mode 100644 index 0000000..7e928e4 --- /dev/null +++ b/.history/SubscriptionManager_20221015201436.h @@ -0,0 +1,38 @@ +#ifndef __SubscriptionManager_h__ +#define __SubscriptionManager_h__ + +#include "Command.h" +#include "Subscription.h" +#include "SubscriptionHandler.h" +#include "TCPSession.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class SubscriptionManager : public Command + { + + public: + SubscriptionManager(); + + int add(Subscription &subscription); + int add(Subscription &subscription, std::string handler); + int addHandler(std::string name, SubscriptionHandler &handler); + + int removeSessionSubscriptions(TCPSession &session); + + int processCommand(coreutils::ZString &request, TCPSession &session) override; + + private: + Subscription subscription; + std::map subscriptions; + std::map handlers; + Subscription *newSubscription; + std::mutex lock; + }; +} + +#endif diff --git a/.history/SubscriptionManager_20221015201440.h b/.history/SubscriptionManager_20221015201440.h new file mode 100644 index 0000000..566cac8 --- /dev/null +++ b/.history/SubscriptionManager_20221015201440.h @@ -0,0 +1,38 @@ +#ifndef __SubscriptionManager_h__ +#define __SubscriptionManager_h__ + +#include "Command.h" +#include "Subscription.h" +#include "SubscriptionHandler.h" +#include "TCPSession.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class SubscriptionManager : public Command + { + + public: + SubscriptionManager(); + + int add(Subscription &subscription); + int add(Subscription &subscription, std::string handler); + int addHandler(std::string name, SubscriptionHandler &handler); + + int removeSessionSubscriptions(TCPSession &session); + + int processCommand(coreutils::ZString &request, TCPSession &session) override; + + private: + Subscription *subscription; + std::map subscriptions; + std::map handlers; + Subscription *newSubscription; + std::mutex lock; + }; +} + +#endif diff --git a/.history/SubscriptionManager_20221015201500.cpp b/.history/SubscriptionManager_20221015201500.cpp new file mode 100644 index 0000000..1db78ab --- /dev/null +++ b/.history/SubscriptionManager_20221015201500.cpp @@ -0,0 +1,147 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015201542.cpp b/.history/SubscriptionManager_20221015201542.cpp new file mode 100644 index 0000000..cc7c533 --- /dev/null +++ b/.history/SubscriptionManager_20221015201542.cpp @@ -0,0 +1,147 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + subscription->setHandler(handlers[name]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221015201557.cpp b/.history/SubscriptionManager_20221015201557.cpp new file mode 100644 index 0000000..cc7c533 --- /dev/null +++ b/.history/SubscriptionManager_20221015201557.cpp @@ -0,0 +1,147 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + subscription->setHandler(handlers[name]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221016174159.cpp b/.history/SubscriptionManager_20221016174159.cpp new file mode 100644 index 0000000..f32b63a --- /dev/null +++ b/.history/SubscriptionManager_20221016174159.cpp @@ -0,0 +1,148 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + coreutils::Log(coreutils::LOG_DEBUG_1) << "Adding handler to SubscriptionManager for " << name; + subscription->setHandler(handler); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221016174206.cpp b/.history/SubscriptionManager_20221016174206.cpp new file mode 100644 index 0000000..d34f2f4 --- /dev/null +++ b/.history/SubscriptionManager_20221016174206.cpp @@ -0,0 +1,148 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + coreutils::Log(coreutils::LOG_DEBUG_1) << "Adding handler to SubscriptionManager for " << name; + subscription->setHandler(&handler); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221016175448.cpp b/.history/SubscriptionManager_20221016175448.cpp new file mode 100644 index 0000000..42235f3 --- /dev/null +++ b/.history/SubscriptionManager_20221016175448.cpp @@ -0,0 +1,148 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler &handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, &handler)); + coreutils::Log(coreutils::LOG_DEBUG_1) << "Adding handler to SubscriptionManager for " << name; + subscription->setHandler(handlers[name]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221016180238.cpp b/.history/SubscriptionManager_20221016180238.cpp new file mode 100644 index 0000000..614e1f4 --- /dev/null +++ b/.history/SubscriptionManager_20221016180238.cpp @@ -0,0 +1,148 @@ +#include "SubscriptionManager.h" +#include "Log.h" +#include "Subscription.h" +#include + +namespace core +{ + + SubscriptionManager::SubscriptionManager() {} + + int SubscriptionManager::add(Subscription &subscription) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::add(Subscription &subscription, std::string handler) + { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + subscription.setHandler(handlers[handler]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler *handler) + { + lock.lock(); + handlers.insert(std::make_pair(name, handler)); + coreutils::Log(coreutils::LOG_DEBUG_1) << "Adding handler to SubscriptionManager for " << name; + subscription->setHandler(handlers[name]); + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { + int countSubscribed = 0; + int countPublished = 0; + + lock.lock(); + std::string temp = ""; + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + countSubscribed += subscription->unsubscribe(session); + if (subscription->owner == &session) + { + temp = key; + delete subscription; + ++countPublished; + } + } + if (temp != "") + { + subscriptions.erase(temp); + temp = ""; + } + coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; + lock.unlock(); + return countSubscribed; + } + + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + + if (request.getList().size() > 2) + { + newSubscription = new Subscription(request[1].str(), session, request[2].str(), request[3].str()); + } + else + { + newSubscription = new Subscription(request[1].str(), session, request[2].str()); + } + + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; + } + session.out << std::endl; + return 1; + } + + auto subscription = subscriptions[request[1].str()]; + + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); + return 1; + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); + return 1; + } + else if (request[0].equals("event")) + { + std::stringstream out; + subscription->process(request, out, session); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); + return 1; + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); + return 1; + } + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); + return 1; + } + } + } + return 0; + } + return 0; + } +} diff --git a/.history/SubscriptionManager_20221016180248.h b/.history/SubscriptionManager_20221016180248.h new file mode 100644 index 0000000..d7613fd --- /dev/null +++ b/.history/SubscriptionManager_20221016180248.h @@ -0,0 +1,38 @@ +#ifndef __SubscriptionManager_h__ +#define __SubscriptionManager_h__ + +#include "Command.h" +#include "Subscription.h" +#include "SubscriptionHandler.h" +#include "TCPSession.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class SubscriptionManager : public Command + { + + public: + SubscriptionManager(); + + int add(Subscription &subscription); + int add(Subscription &subscription, std::string handler); + int addHandler(std::string name, SubscriptionHandler *handler); + + int removeSessionSubscriptions(TCPSession &session); + + int processCommand(coreutils::ZString &request, TCPSession &session) override; + + private: + Subscription *subscription; + std::map subscriptions; + std::map handlers; + Subscription *newSubscription; + std::mutex lock; + }; +} + +#endif diff --git a/.history/Subscription_20221013190812.h b/.history/Subscription_20221013190812.h new file mode 100644 index 0000000..e995db7 --- /dev/null +++ b/.history/Subscription_20221013190812.h @@ -0,0 +1,46 @@ +#ifndef __Subscription_h__ +#define __Subscription_h__ + +#include "ZString.h" +#include +#include + +namespace core +{ + + class TCPSession; + + class Subscription + { + + public: + Subscription(std::string id, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode = "*AUTHOR"); + virtual ~Subscription(); + + int subscribe(TCPSession &session); + int unsubscribe(TCPSession &session); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + int event(std::stringstream &out); + + bool ifSubscriber(TCPSession &session); + + void setHandler(SubscriptionHandler *handler); + + // int processCommand(coreutils::ZString &request, TCPSession &session) override; + + std::string id; + std::string mode; + TCPSession *owner; + + SubscriptionHandler *handler; + + std::vector subscribers; + }; +} + +#endif diff --git a/.history/Subscription_20221013190943.cpp b/.history/Subscription_20221013190943.cpp new file mode 100644 index 0000000..6fa4cd0 --- /dev/null +++ b/.history/Subscription_20221013190943.cpp @@ -0,0 +1,75 @@ +#include "Subscription.h" +#include "TCPSession.h" +#include "Log.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if(handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void setHandler(SubscriptionHandler *handler) { + this->handler = handler; + } + +} diff --git a/.history/Subscription_20221013204658.h b/.history/Subscription_20221013204658.h new file mode 100644 index 0000000..e2c4d84 --- /dev/null +++ b/.history/Subscription_20221013204658.h @@ -0,0 +1,47 @@ +#ifndef __Subscription_h__ +#define __Subscription_h__ + +#include "SubscriptionHandler.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class TCPSession; + + class Subscription + { + + public: + Subscription(std::string id, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode = "*AUTHOR"); + virtual ~Subscription(); + + int subscribe(TCPSession &session); + int unsubscribe(TCPSession &session); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + int event(std::stringstream &out); + + bool ifSubscriber(TCPSession &session); + + void setHandler(SubscriptionHandler *handler); + + // int processCommand(coreutils::ZString &request, TCPSession &session) override; + + std::string id; + std::string mode; + TCPSession *owner; + + SubscriptionHandler *handler; + + std::vector subscribers; + }; +} + +#endif diff --git a/.history/Subscription_20221013204725.cpp b/.history/Subscription_20221013204725.cpp new file mode 100644 index 0000000..3f683db --- /dev/null +++ b/.history/Subscription_20221013204725.cpp @@ -0,0 +1,76 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void setHandler(SubscriptionHandler *handler) + { + this->handler = handler; + } + +} diff --git a/.history/Subscription_20221013204753.cpp b/.history/Subscription_20221013204753.cpp new file mode 100644 index 0000000..3f683db --- /dev/null +++ b/.history/Subscription_20221013204753.cpp @@ -0,0 +1,76 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void setHandler(SubscriptionHandler *handler) + { + this->handler = handler; + } + +} diff --git a/.history/Subscription_20221013205054.cpp b/.history/Subscription_20221013205054.cpp new file mode 100644 index 0000000..2fe2d13 --- /dev/null +++ b/.history/Subscription_20221013205054.cpp @@ -0,0 +1,76 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221014003150.h b/.history/Subscription_20221014003150.h new file mode 100644 index 0000000..e2c4d84 --- /dev/null +++ b/.history/Subscription_20221014003150.h @@ -0,0 +1,47 @@ +#ifndef __Subscription_h__ +#define __Subscription_h__ + +#include "SubscriptionHandler.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class TCPSession; + + class Subscription + { + + public: + Subscription(std::string id, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode = "*AUTHOR"); + virtual ~Subscription(); + + int subscribe(TCPSession &session); + int unsubscribe(TCPSession &session); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + int event(std::stringstream &out); + + bool ifSubscriber(TCPSession &session); + + void setHandler(SubscriptionHandler *handler); + + // int processCommand(coreutils::ZString &request, TCPSession &session) override; + + std::string id; + std::string mode; + TCPSession *owner; + + SubscriptionHandler *handler; + + std::vector subscribers; + }; +} + +#endif diff --git a/.history/Subscription_20221014212452.h b/.history/Subscription_20221014212452.h new file mode 100644 index 0000000..6f8ef82 --- /dev/null +++ b/.history/Subscription_20221014212452.h @@ -0,0 +1,49 @@ +#ifndef __Subscription_h__ +#define __Subscription_h__ + +#include "SubscriptionHandler.h" +#include "TCPSession.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class TCPSession; + + class Subscription + { + + public: + Subscription(std::string id, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode); + Subscription(std::string id, TCPSession &session, std::string mode, std::string handler); + virtual ~Subscription(); + + int subscribe(TCPSession &session); + int unsubscribe(TCPSession &session); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + int event(std::stringstream &out); + + bool ifSubscriber(TCPSession &session); + + void setHandler(SubscriptionHandler *handler); + + // int processCommand(coreutils::ZString &request, TCPSession &session) override; + + std::string id; + std::string mode; + TCPSession *owner; + + SubscriptionHandler *handler; + + std::vector subscribers; + }; +} + +#endif diff --git a/.history/Subscription_20221014212457.h b/.history/Subscription_20221014212457.h new file mode 100644 index 0000000..d55b0e7 --- /dev/null +++ b/.history/Subscription_20221014212457.h @@ -0,0 +1,47 @@ +#ifndef __Subscription_h__ +#define __Subscription_h__ + +#include "SubscriptionHandler.h" +#include "TCPSession.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class Subscription + { + + public: + Subscription(std::string id, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode); + Subscription(std::string id, TCPSession &session, std::string mode, std::string handler); + virtual ~Subscription(); + + int subscribe(TCPSession &session); + int unsubscribe(TCPSession &session); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + int event(std::stringstream &out); + + bool ifSubscriber(TCPSession &session); + + void setHandler(SubscriptionHandler *handler); + + // int processCommand(coreutils::ZString &request, TCPSession &session) override; + + std::string id; + std::string mode; + TCPSession *owner; + + SubscriptionHandler *handler; + + std::vector subscribers; + }; +} + +#endif diff --git a/.history/Subscription_20221014212653.h b/.history/Subscription_20221014212653.h new file mode 100644 index 0000000..c5ef04a --- /dev/null +++ b/.history/Subscription_20221014212653.h @@ -0,0 +1,48 @@ +#ifndef __Subscription_h__ +#define __Subscription_h__ + +#include "SubscriptionHandler.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class TCPSession; + + class Subscription + { + + public: + Subscription(std::string id, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode); + Subscription(std::string id, TCPSession &session, std::string mode, std::string handler); + virtual ~Subscription(); + + int subscribe(TCPSession &session); + int unsubscribe(TCPSession &session); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + int event(std::stringstream &out); + + bool ifSubscriber(TCPSession &session); + + void setHandler(SubscriptionHandler *handler); + + // int processCommand(coreutils::ZString &request, TCPSession &session) override; + + std::string id; + std::string mode; + TCPSession *owner; + + SubscriptionHandler *handler; + + std::vector subscribers; + }; +} + +#endif diff --git a/.history/Subscription_20221014220951.cpp b/.history/Subscription_20221014220951.cpp new file mode 100644 index 0000000..6a1cb7b --- /dev/null +++ b/.history/Subscription_20221014220951.cpp @@ -0,0 +1,76 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handler) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221015131611.cpp b/.history/Subscription_20221015131611.cpp new file mode 100644 index 0000000..6a1cb7b --- /dev/null +++ b/.history/Subscription_20221015131611.cpp @@ -0,0 +1,76 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handler) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221015142023.cpp b/.history/Subscription_20221015142023.cpp new file mode 100644 index 0000000..640cd6b --- /dev/null +++ b/.history/Subscription_20221015142023.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handler) + : id(id), mode(mode), owner(&session) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221015175629.cpp b/.history/Subscription_20221015175629.cpp new file mode 100644 index 0000000..640cd6b --- /dev/null +++ b/.history/Subscription_20221015175629.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handler) + : id(id), mode(mode), owner(&session) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221015182553.h b/.history/Subscription_20221015182553.h new file mode 100644 index 0000000..7f0398f --- /dev/null +++ b/.history/Subscription_20221015182553.h @@ -0,0 +1,49 @@ +#ifndef __Subscription_h__ +#define __Subscription_h__ + +#include "SubscriptionHandler.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class TCPSession; + + class Subscription + { + + public: + Subscription(std::string id, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode); + Subscription(std::string id, TCPSession &session, std::string mode, std::string handler); + virtual ~Subscription(); + + int subscribe(TCPSession &session); + int unsubscribe(TCPSession &session); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + int event(std::stringstream &out); + + bool ifSubscriber(TCPSession &session); + + void setHandler(SubscriptionHandler *handler); + + // int processCommand(coreutils::ZString &request, TCPSession &session) override; + + std::string id; + std::string mode; + TCPSession *owner; + + + SubscriptionHandler *handler; + + std::vector subscribers; + }; +} + +#endif diff --git a/.history/Subscription_20221015182613.h b/.history/Subscription_20221015182613.h new file mode 100644 index 0000000..0d98e5e --- /dev/null +++ b/.history/Subscription_20221015182613.h @@ -0,0 +1,49 @@ +#ifndef __Subscription_h__ +#define __Subscription_h__ + +#include "SubscriptionHandler.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class TCPSession; + + class Subscription + { + + public: + Subscription(std::string id, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode); + Subscription(std::string id, TCPSession &session, std::string mode, std::string handler); + virtual ~Subscription(); + + int subscribe(TCPSession &session); + int unsubscribe(TCPSession &session); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + int event(std::stringstream &out); + + bool ifSubscriber(TCPSession &session); + + void setHandler(SubscriptionHandler *handler); + + // int processCommand(coreutils::ZString &request, TCPSession &session) override; + + std::string id; + std::string mode; + TCPSession *owner; + std::string handler; + + SubscriptionHandler *handler; + + std::vector subscribers; + }; +} + +#endif diff --git a/.history/Subscription_20221015182633.cpp b/.history/Subscription_20221015182633.cpp new file mode 100644 index 0000000..3c1199a --- /dev/null +++ b/.history/Subscription_20221015182633.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handler) + : id(id), mode(mode), owner(&session), handler(handler) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221015182644.cpp b/.history/Subscription_20221015182644.cpp new file mode 100644 index 0000000..fc07da5 --- /dev/null +++ b/.history/Subscription_20221015182644.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handler(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221015182655.h b/.history/Subscription_20221015182655.h new file mode 100644 index 0000000..53fd588 --- /dev/null +++ b/.history/Subscription_20221015182655.h @@ -0,0 +1,49 @@ +#ifndef __Subscription_h__ +#define __Subscription_h__ + +#include "SubscriptionHandler.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class TCPSession; + + class Subscription + { + + public: + Subscription(std::string id, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode); + Subscription(std::string id, TCPSession &session, std::string mode, std::string handler); + virtual ~Subscription(); + + int subscribe(TCPSession &session); + int unsubscribe(TCPSession &session); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + int event(std::stringstream &out); + + bool ifSubscriber(TCPSession &session); + + void setHandler(SubscriptionHandler *handler); + + // int processCommand(coreutils::ZString &request, TCPSession &session) override; + + std::string id; + std::string mode; + TCPSession *owner; + std::string handlers; + + SubscriptionHandler *handler; + + std::vector subscribers; + }; +} + +#endif diff --git a/.history/Subscription_20221015182706.cpp b/.history/Subscription_20221015182706.cpp new file mode 100644 index 0000000..c583ea8 --- /dev/null +++ b/.history/Subscription_20221015182706.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221015182712.cpp b/.history/Subscription_20221015182712.cpp new file mode 100644 index 0000000..c583ea8 --- /dev/null +++ b/.history/Subscription_20221015182712.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221015203632.h b/.history/Subscription_20221015203632.h new file mode 100644 index 0000000..b9340b2 --- /dev/null +++ b/.history/Subscription_20221015203632.h @@ -0,0 +1,49 @@ +#ifndef __Subscription_h__ +#define __Subscription_h__ + +#include "SubscriptionHandler.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class TCPSession; + + class Subscription + { + + public: + Subscription(std::string id, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode); + Subscription(std::string id, TCPSession &session, std::string mode, std::string handler); + virtual ~Subscription(); + + int subscribe(TCPSession &session); + int unsubscribe(TCPSession &session); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + int event(std::stringstream &out); + + bool ifSubscriber(TCPSession &session); + + void setHandler(SubscriptionHandler *handler); + + // int processCommand(coreutils::ZString &request, TCPSession &session) override; + + std::string id; + std::string mode; + TCPSession *owner; + std::string handlers; + + SubscriptionHandler &handler; + + std::vector subscribers; + }; +} + +#endif diff --git a/.history/Subscription_20221015203643.cpp b/.history/Subscription_20221015203643.cpp new file mode 100644 index 0000000..ac861a6 --- /dev/null +++ b/.history/Subscription_20221015203643.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler.process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221015203655.cpp b/.history/Subscription_20221015203655.cpp new file mode 100644 index 0000000..73d9ad2 --- /dev/null +++ b/.history/Subscription_20221015203655.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (&handler) + handler.process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221015203702.cpp b/.history/Subscription_20221015203702.cpp new file mode 100644 index 0000000..73d9ad2 --- /dev/null +++ b/.history/Subscription_20221015203702.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (&handler) + handler.process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221015203734.h b/.history/Subscription_20221015203734.h new file mode 100644 index 0000000..53fd588 --- /dev/null +++ b/.history/Subscription_20221015203734.h @@ -0,0 +1,49 @@ +#ifndef __Subscription_h__ +#define __Subscription_h__ + +#include "SubscriptionHandler.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class TCPSession; + + class Subscription + { + + public: + Subscription(std::string id, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode); + Subscription(std::string id, TCPSession &session, std::string mode, std::string handler); + virtual ~Subscription(); + + int subscribe(TCPSession &session); + int unsubscribe(TCPSession &session); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + int event(std::stringstream &out); + + bool ifSubscriber(TCPSession &session); + + void setHandler(SubscriptionHandler *handler); + + // int processCommand(coreutils::ZString &request, TCPSession &session) override; + + std::string id; + std::string mode; + TCPSession *owner; + std::string handlers; + + SubscriptionHandler *handler; + + std::vector subscribers; + }; +} + +#endif diff --git a/.history/Subscription_20221015203735.cpp b/.history/Subscription_20221015203735.cpp new file mode 100644 index 0000000..c583ea8 --- /dev/null +++ b/.history/Subscription_20221015203735.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221015203805.cpp b/.history/Subscription_20221015203805.cpp new file mode 100644 index 0000000..c583ea8 --- /dev/null +++ b/.history/Subscription_20221015203805.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221015204939.cpp b/.history/Subscription_20221015204939.cpp new file mode 100644 index 0000000..dde1003 --- /dev/null +++ b/.history/Subscription_20221015204939.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (!handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221016151339.cpp b/.history/Subscription_20221016151339.cpp new file mode 100644 index 0000000..c583ea8 --- /dev/null +++ b/.history/Subscription_20221016151339.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221016162014.cpp b/.history/Subscription_20221016162014.cpp new file mode 100644 index 0000000..c583ea8 --- /dev/null +++ b/.history/Subscription_20221016162014.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } + +} diff --git a/.history/Subscription_20221016172637.cpp b/.history/Subscription_20221016172637.cpp new file mode 100644 index 0000000..0040988 --- /dev/null +++ b/.history/Subscription_20221016172637.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + coreutils::Log(coreutils::LOG_DEBUG_1) << "Setting handler" << handler; + } +} diff --git a/.history/Subscription_20221016172643.cpp b/.history/Subscription_20221016172643.cpp new file mode 100644 index 0000000..0040988 --- /dev/null +++ b/.history/Subscription_20221016172643.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + coreutils::Log(coreutils::LOG_DEBUG_1) << "Setting handler" << handler; + } +} diff --git a/.history/Subscription_20221016173312.cpp b/.history/Subscription_20221016173312.cpp new file mode 100644 index 0000000..ee6d5ea --- /dev/null +++ b/.history/Subscription_20221016173312.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + coreutils::Log(coreutils::LOG_DEBUG_1) << "Setting handler"; + } +} diff --git a/.history/Subscription_20221016173458.cpp b/.history/Subscription_20221016173458.cpp new file mode 100644 index 0000000..b843257 --- /dev/null +++ b/.history/Subscription_20221016173458.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + // handler = handler; + coreutils::Log(coreutils::LOG_DEBUG_1) << "Setting handler"; + } +} diff --git a/.history/Subscription_20221016173903.cpp b/.history/Subscription_20221016173903.cpp new file mode 100644 index 0000000..ee6d5ea --- /dev/null +++ b/.history/Subscription_20221016173903.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + coreutils::Log(coreutils::LOG_DEBUG_1) << "Setting handler"; + } +} diff --git a/.history/Subscription_20221016174406.cpp b/.history/Subscription_20221016174406.cpp new file mode 100644 index 0000000..0040988 --- /dev/null +++ b/.history/Subscription_20221016174406.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + coreutils::Log(coreutils::LOG_DEBUG_1) << "Setting handler" << handler; + } +} diff --git a/.history/Subscription_20221016174556.cpp b/.history/Subscription_20221016174556.cpp new file mode 100644 index 0000000..d62d2b5 --- /dev/null +++ b/.history/Subscription_20221016174556.cpp @@ -0,0 +1,78 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } +} diff --git a/.history/Subscription_20221016174634.cpp b/.history/Subscription_20221016174634.cpp new file mode 100644 index 0000000..6b2e0b2 --- /dev/null +++ b/.history/Subscription_20221016174634.cpp @@ -0,0 +1,78 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } +} diff --git a/.history/Subscription_20221016174652.cpp b/.history/Subscription_20221016174652.cpp new file mode 100644 index 0000000..ce23872 --- /dev/null +++ b/.history/Subscription_20221016174652.cpp @@ -0,0 +1,78 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = &handler; + } +} diff --git a/.history/Subscription_20221016174712.cpp b/.history/Subscription_20221016174712.cpp new file mode 100644 index 0000000..6b2e0b2 --- /dev/null +++ b/.history/Subscription_20221016174712.cpp @@ -0,0 +1,78 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handler) + { + handler = handler; + } +} diff --git a/.history/Subscription_20221016174852.h b/.history/Subscription_20221016174852.h new file mode 100644 index 0000000..6010ad0 --- /dev/null +++ b/.history/Subscription_20221016174852.h @@ -0,0 +1,49 @@ +#ifndef __Subscription_h__ +#define __Subscription_h__ + +#include "SubscriptionHandler.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class TCPSession; + + class Subscription + { + + public: + Subscription(std::string id, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode); + Subscription(std::string id, TCPSession &session, std::string mode, std::string handler); + virtual ~Subscription(); + + int subscribe(TCPSession &session); + int unsubscribe(TCPSession &session); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + int event(std::stringstream &out); + + bool ifSubscriber(TCPSession &session); + + void setHandler(SubscriptionHandler *handler); + + // int processCommand(coreutils::ZString &request, TCPSession &session) override; + + std::string id; + std::string mode; + TCPSession *owner; + std::string handlers; + + SubscriptionHandler *handlers; + + std::vector subscribers; + }; +} + +#endif diff --git a/.history/Subscription_20221016174910.h b/.history/Subscription_20221016174910.h new file mode 100644 index 0000000..53fd588 --- /dev/null +++ b/.history/Subscription_20221016174910.h @@ -0,0 +1,49 @@ +#ifndef __Subscription_h__ +#define __Subscription_h__ + +#include "SubscriptionHandler.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class TCPSession; + + class Subscription + { + + public: + Subscription(std::string id, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode); + Subscription(std::string id, TCPSession &session, std::string mode, std::string handler); + virtual ~Subscription(); + + int subscribe(TCPSession &session); + int unsubscribe(TCPSession &session); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + int event(std::stringstream &out); + + bool ifSubscriber(TCPSession &session); + + void setHandler(SubscriptionHandler *handler); + + // int processCommand(coreutils::ZString &request, TCPSession &session) override; + + std::string id; + std::string mode; + TCPSession *owner; + std::string handlers; + + SubscriptionHandler *handler; + + std::vector subscribers; + }; +} + +#endif diff --git a/.history/Subscription_20221016174913.h b/.history/Subscription_20221016174913.h new file mode 100644 index 0000000..b9e448b --- /dev/null +++ b/.history/Subscription_20221016174913.h @@ -0,0 +1,49 @@ +#ifndef __Subscription_h__ +#define __Subscription_h__ + +#include "SubscriptionHandler.h" +#include "ZString.h" +#include +#include + +namespace core +{ + + class TCPSession; + + class Subscription + { + + public: + Subscription(std::string id, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode); + Subscription(std::string id, TCPSession &session, std::string mode, std::string handler); + virtual ~Subscription(); + + int subscribe(TCPSession &session); + int unsubscribe(TCPSession &session); + + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session); + + virtual int onSubscribe(TCPSession &session); + + int event(std::stringstream &out); + + bool ifSubscriber(TCPSession &session); + + void setHandler(SubscriptionHandler *handlers); + + // int processCommand(coreutils::ZString &request, TCPSession &session) override; + + std::string id; + std::string mode; + TCPSession *owner; + std::string handlers; + + SubscriptionHandler *handler; + + std::vector subscribers; + }; +} + +#endif diff --git a/.history/Subscription_20221016174921.cpp b/.history/Subscription_20221016174921.cpp new file mode 100644 index 0000000..e18853c --- /dev/null +++ b/.history/Subscription_20221016174921.cpp @@ -0,0 +1,78 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handlers) + { + handler = handler; + } +} diff --git a/.history/Subscription_20221016174923.cpp b/.history/Subscription_20221016174923.cpp new file mode 100644 index 0000000..21c5b39 --- /dev/null +++ b/.history/Subscription_20221016174923.cpp @@ -0,0 +1,78 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handlers) + { + handler = handlers; + } +} diff --git a/.history/Subscription_20221016175152.cpp b/.history/Subscription_20221016175152.cpp new file mode 100644 index 0000000..9f30eaf --- /dev/null +++ b/.history/Subscription_20221016175152.cpp @@ -0,0 +1,79 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handlers) + { + handler = handlers; + coreutils::Log(coreutils::LOG_DEBUG_1) << "Test Test"; + } +} diff --git a/.history/Subscription_20221016175838.cpp b/.history/Subscription_20221016175838.cpp new file mode 100644 index 0000000..33256cc --- /dev/null +++ b/.history/Subscription_20221016175838.cpp @@ -0,0 +1,80 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handlers) + { + handler = handlers; + + coreutils::Log(coreutils::LOG_DEBUG_1) << "Test Test"; + } +} diff --git a/.history/Subscription_20221016175855.cpp b/.history/Subscription_20221016175855.cpp new file mode 100644 index 0000000..6271e2e --- /dev/null +++ b/.history/Subscription_20221016175855.cpp @@ -0,0 +1,80 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handlers) + { + handler = handlers; + + return handler; + } +} diff --git a/.history/Subscription_20221016175911.cpp b/.history/Subscription_20221016175911.cpp new file mode 100644 index 0000000..33256cc --- /dev/null +++ b/.history/Subscription_20221016175911.cpp @@ -0,0 +1,80 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handlers) + { + handler = handlers; + + coreutils::Log(coreutils::LOG_DEBUG_1) << "Test Test"; + } +} diff --git a/.history/Subscription_20221016175912.cpp b/.history/Subscription_20221016175912.cpp new file mode 100644 index 0000000..33256cc --- /dev/null +++ b/.history/Subscription_20221016175912.cpp @@ -0,0 +1,80 @@ +#include "Subscription.h" +#include "Log.h" +#include "TCPSession.h" +#include + +namespace core +{ + + Subscription::Subscription(std::string id, std::string mode) + : id(id), mode(mode), owner(NULL) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode, std::string handlers) + : id(id), mode(mode), owner(&session), handlers(handlers) {} + + Subscription::Subscription(std::string id, TCPSession &session, std::string mode) + : id(id), mode(mode), owner(&session) {} + + Subscription::~Subscription() + { + std::stringstream out; + out << "cancel:" << id << std::endl; + for (auto subscriber : subscribers) + { + subscriber->write(out.str()); + } + } + + int Subscription::subscribe(TCPSession &session) + { + onSubscribe(session); + subscribers.push_back(&session); + return 1; + } + + int Subscription::unsubscribe(TCPSession &session) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + { + if (*subscriber == &session) + { + subscribers.erase(subscriber++); + return 1; + } + } + return 0; + } + + int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) + { + if (handler) + handler->process(request, out, session); + else + out << "event:" << request[1] << ":" << request[2] << std::endl; + return 1; + } + + int Subscription::event(std::stringstream &out) + { + for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) + (*subscriber)->write(out.str()); + return 1; + } + + bool Subscription::ifSubscriber(TCPSession &session) + { + return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end()); + } + + int Subscription::onSubscribe(TCPSession &session) + { + return 0; + } + + void Subscription::setHandler(SubscriptionHandler *handlers) + { + handler = handlers; + + coreutils::Log(coreutils::LOG_DEBUG_1) << "Test Test"; + } +} diff --git a/Subscription.cpp b/Subscription.cpp index ce40556..f37a6d5 100644 --- a/Subscription.cpp +++ b/Subscription.cpp @@ -1,16 +1,19 @@ #include "Subscription.h" -#include "TCPSession.h" #include "Log.h" +#include "TCPSession.h" #include 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"; +// } } diff --git a/Subscription.h b/Subscription.h index 371b6c4..b62e342 100644 --- a/Subscription.h +++ b/Subscription.h @@ -1,9 +1,10 @@ #ifndef __Subscription_h__ #define __Subscription_h__ +#include "SubscriptionHandler.h" #include "ZString.h" -#include #include +#include namespace core { @@ -15,7 +16,8 @@ namespace core public: Subscription(std::string id, std::string mode = "*AUTHOR"); - Subscription(std::string id, TCPSession &session, std::string mode = "*AUTHOR"); + Subscription(std::string id, TCPSession &session, std::string mode); + Subscription(std::string id, TCPSession &session, std::string mode, SubscriptionHandler *handler); virtual ~Subscription(); int subscribe(TCPSession &session); @@ -29,12 +31,16 @@ namespace core bool ifSubscriber(TCPSession &session); +// void setHandler(SubscriptionHandler *handlers); + // int processCommand(coreutils::ZString &request, TCPSession &session) override; std::string id; std::string mode; TCPSession *owner; + SubscriptionHandler *handler; + std::vector subscribers; }; } diff --git a/SubscriptionHandler.h b/SubscriptionHandler.h new file mode 100644 index 0000000..786faf6 --- /dev/null +++ b/SubscriptionHandler.h @@ -0,0 +1,25 @@ +#ifndef __SubscriptionHandler_h__ +#define __SubscriptionHandler_h__ + +#include "ZString.h" +#include +#include +#include + +namespace core +{ + + class TCPSession; + + class SubscriptionHandler + { + + public: + virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) { return 0; } + + virtual int onSubscribe(TCPSession &session) { return 0; } + + }; +} + +#endif diff --git a/SubscriptionManager.cpp b/SubscriptionManager.cpp index 44c2468..29e1af0 100644 --- a/SubscriptionManager.cpp +++ b/SubscriptionManager.cpp @@ -1,85 +1,123 @@ #include "SubscriptionManager.h" #include "Log.h" +#include "Subscription.h" #include -namespace core { +namespace core +{ SubscriptionManager::SubscriptionManager() {} - - int SubscriptionManager::add(Subscription &subscription) { - lock.lock(); - subscriptions.insert(std::make_pair(subscription.id, &subscription)); - lock.unlock(); - return 1; - } - - int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) { + + int SubscriptionManager::add(Subscription &subscription) { + lock.lock(); + subscriptions.insert(std::make_pair(subscription.id, &subscription)); + lock.unlock(); + return 1; + } + + int SubscriptionManager::addHandler(std::string name, SubscriptionHandler *handler) { + lock.lock(); + handlers.insert(std::make_pair(name, handler)); + coreutils::Log(coreutils::LOG_DEBUG_1) << "Adding handler to SubscriptionManager for '" << name << "' (" << handler; + lock.unlock(); + return 1; + } + + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) + { int countSubscribed = 0; int countPublished = 0; - lock.lock(); + lock.lock(); std::string temp = ""; - for(auto [key, subscription] : subscriptions) { - if(temp != "") { + for (auto [key, subscription] : subscriptions) + { + if (temp != "") + { subscriptions.erase(temp); temp = ""; } countSubscribed += subscription->unsubscribe(session); - if(subscription->owner == &session) { + if (subscription->owner == &session) + { temp = key; delete subscription; ++countPublished; - } + } } - if(temp != "") { + if (temp != "") + { subscriptions.erase(temp); temp = ""; } coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; - lock.unlock(); + lock.unlock(); return countSubscribed; } - int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) { - if(request[0].equals("publish")) { - Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str()); + int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) + { + if (request[0].equals("publish")) + { + SubscriptionHandler *handler = handlers[request[3].str()]; + newSubscription = new Subscription(request[1].str(), session, request[2].str(), handler); + subscriptions.insert(std::make_pair(request[1].str(), newSubscription)); - return 1; - } else if(request[0].equals("catalog")) { - session.out << ":catalog:"; - for(auto const& [key, subscription] : subscriptions) { - session.out << subscription->id << ";"; + return 1; + } + + else if (request[0].equals("catalog")) + { + session.out << ":catalog:"; + for (auto const &[key, subscription] : subscriptions) + { + session.out << subscription->id << ";"; } - session.out << std::endl; - return 1; + session.out << std::endl; + return 1; } auto subscription = subscriptions[request[1].str()]; - if(request[1].equals(subscription->id)) { - if(request[0].equals("unpublish")) { - subscriptions.erase(request[1].str()); - } else if(request[0].equals("subscribe")) { - subscription->subscribe(session); + if (request[1].equals(subscription->id)) + { + if (request[0].equals("unpublish")) + { + subscriptions.erase(request[1].str()); + } + else if (request[0].equals("subscribe")) + { + subscription->subscribe(session); return 1; - } else if(request[0].equals("unsubscribe")) { - subscription->unsubscribe(session); + } + else if (request[0].equals("unsubscribe")) + { + subscription->unsubscribe(session); return 1; - } else if(request[0].equals("event")) { + } + else if (request[0].equals("event")) + { std::stringstream out; subscription->process(request, out, session); - if(subscription->mode == "*ANYONE") { - subscription->event(out); + if (subscription->mode == "*ANYONE") + { + subscription->event(out); return 1; - } else if(subscription->mode == "*SUBSCRIBERS") { - if(subscription->ifSubscriber(session)) { - subscription->event(out); + } + else if (subscription->mode == "*SUBSCRIBERS") + { + if (subscription->ifSubscriber(session)) + { + subscription->event(out); return 1; } - } else if(subscription->mode == "*AUTHOR") { - if(subscription->owner == &session) { - subscription->event(out); + } + else if (subscription->mode == "*AUTHOR") + { + if (subscription->owner == &session) + { + subscription->event(out); return 1; } } @@ -88,5 +126,4 @@ namespace core { } return 0; } - } diff --git a/SubscriptionManager.h b/SubscriptionManager.h index 6fa042a..38226e7 100644 --- a/SubscriptionManager.h +++ b/SubscriptionManager.h @@ -1,31 +1,36 @@ #ifndef __SubscriptionManager_h__ #define __SubscriptionManager_h__ -#include "TCPSession.h" -#include "Subscription.h" #include "Command.h" +#include "Subscription.h" +#include "SubscriptionHandler.h" +#include "TCPSession.h" #include "ZString.h" -#include #include +#include namespace core { - + class SubscriptionManager : public Command { - + public: SubscriptionManager(); - - int add(Subscription &subscription); - + + int add(Subscription &subscription); + int addHandler(std::string name, SubscriptionHandler *handler); + int removeSessionSubscriptions(TCPSession &session); - + int processCommand(coreutils::ZString &request, TCPSession &session) override; - + private: + Subscription *subscription; std::map subscriptions; - std::mutex lock; - + std::map handlers; + Subscription *newSubscription; + std::mutex lock; }; + } #endif From fd70c79282a3da1cb02143642ee3127101546917 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 17 Oct 2022 20:03:23 -0700 Subject: [PATCH 05/27] Create TCPSession2 for outpubound connections. --- CommandList.cpp | 21 +- EPoll.cpp | 11 +- EPoll.h | 20 +- INotify.cpp | 53 +- INotify.h | 34 +- IPAddress.cpp | 12 +- IPAddress.h | 8 +- Socket.cpp | 36 +- Socket.h | 69 ++- SubscriptionManager.cpp | 12 +- TCPSession.cpp | 35 +- TCPSession2.cpp | 85 ++++ TCPSession2.h | 139 +++++ TCPSocket.cpp | 4 +- Thread.cpp | 7 +- Thread.h | 26 +- Timer.cpp | 41 +- html/CommandList_8h_source.html | 4 +- html/EPoll_8h_source.html | 78 +-- html/INotify_8h_source.html | 34 +- html/IPAddress_8h_source.html | 4 +- html/Socket_8h_source.html | 170 +++---- html/TCPSession2_8h_source.html | 161 ++++++ html/TCPSession_8h_source.html | 16 +- html/TCPSocket_8h_source.html | 2 +- html/Thread_8h_source.html | 26 +- html/Timer_8h_source.html | 2 +- html/annotated.html | 19 +- html/classcore_1_1ConsoleServer-members.html | 6 +- html/classcore_1_1ConsoleServer.html | 15 +- html/classcore_1_1ConsoleSession-members.html | 4 +- html/classcore_1_1ConsoleSession.html | 15 +- html/classcore_1_1EPoll-members.html | 25 +- html/classcore_1_1EPoll.html | 3 + html/classcore_1_1INotify-members.html | 6 +- html/classcore_1_1INotify.html | 18 +- html/classcore_1_1Socket-members.html | 6 +- html/classcore_1_1Socket.html | 46 +- html/classcore_1_1Socket__inherit__graph.map | 13 +- html/classcore_1_1Socket__inherit__graph.md5 | 2 +- html/classcore_1_1Socket__inherit__graph.png | Bin 23043 -> 28528 bytes html/classcore_1_1TCPServer-members.html | 4 +- html/classcore_1_1TCPServer.html | 15 +- html/classcore_1_1TCPSession-members.html | 4 +- html/classcore_1_1TCPSession.html | 15 +- html/classcore_1_1TCPSession2-members.html | 119 +++++ html/classcore_1_1TCPSession2.html | 480 ++++++++++++++++++ .../classcore_1_1TCPSession2__coll__graph.map | 9 + .../classcore_1_1TCPSession2__coll__graph.md5 | 1 + .../classcore_1_1TCPSession2__coll__graph.png | Bin 0 -> 18134 bytes ...asscore_1_1TCPSession2__inherit__graph.map | 5 + ...asscore_1_1TCPSession2__inherit__graph.md5 | 1 + ...asscore_1_1TCPSession2__inherit__graph.png | Bin 0 -> 6244 bytes html/classcore_1_1TCPSocket-members.html | 4 +- html/classcore_1_1TCPSocket.html | 22 +- ...classcore_1_1TCPSocket__inherit__graph.map | 5 +- ...classcore_1_1TCPSocket__inherit__graph.md5 | 2 +- ...classcore_1_1TCPSocket__inherit__graph.png | Bin 16595 -> 17771 bytes html/classcore_1_1TLSServer-members.html | 6 +- html/classcore_1_1TLSServer.html | 15 +- html/classcore_1_1TLSSession-members.html | 4 +- html/classcore_1_1TLSSession.html | 15 +- .../classcore_1_1TerminalSession-members.html | 4 +- html/classcore_1_1TerminalSession.html | 15 +- .../classcore_1_1UDPServerSocket-members.html | 4 +- html/classcore_1_1UDPServerSocket.html | 15 +- html/classcore_1_1UDPSocket-members.html | 4 +- html/classcore_1_1UDPSocket.html | 15 +- html/classes.html | 2 +- html/files.html | 19 +- html/functions.html | 27 +- html/functions_func.html | 24 +- html/functions_vars.html | 3 +- html/hierarchy.html | 11 +- html/inherit_graph_0.map | 21 +- html/inherit_graph_0.md5 | 2 +- html/inherit_graph_0.png | Bin 41510 -> 43394 bytes html/inherits.html | 21 +- html/search/all_3.js | 2 +- html/search/all_7.js | 14 +- html/search/all_8.js | 2 +- html/search/all_a.js | 4 +- html/search/all_b.js | 17 +- html/search/all_c.js | 6 +- html/search/all_d.js | 4 +- html/search/all_e.js | 8 +- html/search/classes_0.js | 8 +- html/search/classes_1.js | 2 +- html/search/classes_2.js | 6 +- html/search/classes_3.js | 2 +- html/search/classes_4.js | 8 +- html/search/classes_5.js | 19 +- html/search/classes_6.js | 4 +- html/search/functions_0.js | 2 +- html/search/functions_1.js | 6 +- html/search/functions_2.js | 4 +- html/search/functions_3.js | 14 +- html/search/functions_4.js | 2 +- html/search/functions_5.js | 18 +- html/search/functions_6.js | 6 +- html/search/functions_7.js | 6 +- html/search/functions_8.js | 20 +- html/search/functions_9.js | 6 +- html/search/functions_a.js | 2 +- html/search/functions_b.js | 2 +- html/search/functions_c.js | 8 +- html/search/variables_0.js | 2 +- html/search/variables_1.js | 2 +- html/search/variables_2.js | 2 +- html/search/variables_3.js | 2 +- html/search/variables_4.js | 4 +- html/search/variables_5.js | 2 +- latex/annotated.tex | 1 + latex/classcore_1_1EPoll.tex | 3 + latex/classcore_1_1INotify.tex | 12 +- latex/classcore_1_1Socket.tex | 17 +- latex/classcore_1_1Socket__inherit__graph.md5 | 2 +- latex/classcore_1_1Socket__inherit__graph.pdf | Bin 12995 -> 13668 bytes latex/classcore_1_1TCPSession2.tex | 152 ++++++ .../classcore_1_1TCPSession2__coll__graph.md5 | 1 + .../classcore_1_1TCPSession2__coll__graph.pdf | Bin 0 -> 10730 bytes ...asscore_1_1TCPSession2__inherit__graph.md5 | 1 + ...asscore_1_1TCPSession2__inherit__graph.pdf | Bin 0 -> 7309 bytes latex/classcore_1_1TCPSocket.tex | 2 +- ...classcore_1_1TCPSocket__inherit__graph.md5 | 2 +- ...classcore_1_1TCPSocket__inherit__graph.pdf | Bin 10337 -> 10932 bytes latex/classcore_1_1Timer__inherit__graph.pdf | Bin 6234 -> 6236 bytes latex/hierarchy.tex | 1 + latex/refman.tex | 1 + 129 files changed, 1902 insertions(+), 710 deletions(-) create mode 100644 TCPSession2.cpp create mode 100644 TCPSession2.h create mode 100644 html/TCPSession2_8h_source.html create mode 100644 html/classcore_1_1TCPSession2-members.html create mode 100644 html/classcore_1_1TCPSession2.html create mode 100644 html/classcore_1_1TCPSession2__coll__graph.map create mode 100644 html/classcore_1_1TCPSession2__coll__graph.md5 create mode 100644 html/classcore_1_1TCPSession2__coll__graph.png create mode 100644 html/classcore_1_1TCPSession2__inherit__graph.map create mode 100644 html/classcore_1_1TCPSession2__inherit__graph.md5 create mode 100644 html/classcore_1_1TCPSession2__inherit__graph.png create mode 100644 latex/classcore_1_1TCPSession2.tex create mode 100644 latex/classcore_1_1TCPSession2__coll__graph.md5 create mode 100644 latex/classcore_1_1TCPSession2__coll__graph.pdf create mode 100644 latex/classcore_1_1TCPSession2__inherit__graph.md5 create mode 100644 latex/classcore_1_1TCPSession2__inherit__graph.pdf diff --git a/CommandList.cpp b/CommandList.cpp index a999c72..919836e 100644 --- a/CommandList.cpp +++ b/CommandList.cpp @@ -2,18 +2,19 @@ #include "Log.h" namespace core { - + CommandList::CommandList(std::string delimiter, int depth) : delimiter(delimiter), depth(depth) {} - + void CommandList::add(Command &command, std::string name) { commands.insert(std::make_pair(name, &command)); } - + void CommandList::remove(Command &command) {} - + int CommandList::processRequest(coreutils::ZString &request, TCPSession &session) { - if(session.grab != NULL) - return session.grab->processCommand(request, session); + if(session.grab != NULL) { + return session.grab->processCommand(request, session); + } else { if(request.equals("")) return 0; @@ -29,20 +30,20 @@ namespace core { } return true; } - + bool CommandList::grabInput(TCPSession &session, Command &command) { session.grab = &command; return true; } - + void CommandList::clearGrab(TCPSession &session) { session.grab = NULL; } - + int CommandList::processCommand(coreutils::ZString &request, TCPSession &session) { // for(Command *command : commands) // session.out << command->getName() << std::endl; return true; } - + } diff --git a/EPoll.cpp b/EPoll.cpp index 9f669e9..9a6420a 100644 --- a/EPoll.cpp +++ b/EPoll.cpp @@ -96,19 +96,22 @@ namespace core { event.data.ptr = socket; event.events = EPOLLIN | EPOLLONESHOT | EPOLLRDHUP | EPOLLET; epoll_ctl(epfd, EPOLL_CTL_ADD, socket->getDescriptor(), &event); +// coreutils::Log(coreutils::LOG_DEBUG_4) << "BMAXenable: " << socket->getDescriptor(); } - + void EPoll::disableSocket(Socket *socket) { epoll_ctl(epfd, EPOLL_CTL_DEL, socket->getDescriptor(), NULL); +// coreutils::Log(coreutils::LOG_DEBUG_4) << "BMAXdisable: " << socket->getDescriptor(); } - + void EPoll::resetSocket(Socket *socket) { struct epoll_event event; event.data.ptr = socket; event.events = EPOLLIN | EPOLLONESHOT | EPOLLRDHUP | EPOLLET; - if(socket->needsToWrite()) + if(socket->needsToWrite() && !socket->shutDown) event.events |= EPOLLWRNORM; epoll_ctl(epfd, EPOLL_CTL_MOD, socket->getDescriptor(), &event); +// coreutils::Log(coreutils::LOG_DEBUG_4) << "BMAXreset: " << socket->getDescriptor(); } - + } diff --git a/EPoll.h b/EPoll.h index dcd389b..3db2031 100644 --- a/EPoll.h +++ b/EPoll.h @@ -32,6 +32,8 @@ namespace core { public: + volatile long long eventId = 0; + /// /// The constructor for the BMAEPoll object. /// @@ -41,9 +43,9 @@ namespace core { /// /// The destructor for the BMAEPoll object. /// - + ~EPoll(); - + /// /// Use the start() method to initiate the threads and begin epoll queue processing. /// @@ -109,22 +111,22 @@ namespace core { /// /// @param session the session to write the requested data to. /// - + int processCommand(coreutils::ZString &request, TCPSession &session) override; /// threads; - volatile bool terminateThreads; + int numberOfThreads; + std::vector threads; + volatile bool terminateThreads; void enableSocket(Socket *socket); void disableSocket(Socket *socket); - + }; - + } #endif diff --git a/INotify.cpp b/INotify.cpp index da82e79..010435c 100644 --- a/INotify.cpp +++ b/INotify.cpp @@ -1,17 +1,18 @@ #include "INotify.h" #include "Log.h" +#include "ZString.h" namespace core { - + INotify::INotify(EPoll &ePoll) : Socket(ePoll, "INotify") { - setDescriptor(inotify_init()); - } - + setDescriptor(inotify_init()); + } + INotify::~INotify() { shutdown(); } - - int INotify::addWatch(std::string watch) { + + int INotify::addWatch(coreutils::ZString &watch) { return inotify_add_watch(getDescriptor(), watch.c_str(), IN_ALL_EVENTS); } @@ -22,37 +23,37 @@ namespace core { void INotify::onDataReceived(coreutils::ZString &buffer) { const struct inotify_event *event; char *ptr; - for (ptr = buffer.getData(); ptr < buffer.getData() + buffer.getLength(); + for (ptr = buffer.getData(); + ptr < buffer.getData() + buffer.getLength(); ptr += sizeof(struct inotify_event) + event->len) { event = (const struct inotify_event *) ptr; - - if(event->mask & IN_ACCESS) - inAccess(std::string(event->name)); - if(event->mask & IN_ATTRIB) + coreutils::ZString name(event->name); + + if(event->mask & IN_ACCESS) + inAccess(name); + if(event->mask & IN_ATTRIB) inAttrib(std::string(event->name)); - if(event->mask & IN_CLOSE_WRITE) + if(event->mask & IN_CLOSE_WRITE) inCloseWrite(std::string(event->name)); - if(event->mask & IN_CLOSE_NOWRITE) + if(event->mask & IN_CLOSE_NOWRITE) inCloseNoWrite(std::string(event->name)); - if(event->mask & IN_CREATE) - inCreate(std::string(event->name)); - if(event->mask & IN_DELETE) + if(event->mask & IN_CREATE) + inCreate(name); + if(event->mask & IN_DELETE) inDelete(std::string(event->name)); - if(event->mask & IN_DELETE_SELF) + if(event->mask & IN_DELETE_SELF) inDeleteSelf(std::string(event->name)); - if(event->mask & IN_MODIFY) + if(event->mask & IN_MODIFY) inModify(std::string(event->name)); - if(event->mask & IN_MOVE_SELF) + if(event->mask & IN_MOVE_SELF) inMoveSelf(std::string(event->name)); - if(event->mask & IN_MOVED_FROM) + if(event->mask & IN_MOVED_FROM) inMovedFrom(std::string(event->name)); - if(event->mask & IN_MOVED_TO) + if(event->mask & IN_MOVED_TO) inMovedTo(std::string(event->name)); - if(event->mask & IN_OPEN) + if(event->mask & IN_OPEN) inOpen(std::string(event->name)); - - } + } } - - + } diff --git a/INotify.h b/INotify.h index b63abf9..4961710 100644 --- a/INotify.h +++ b/INotify.h @@ -5,33 +5,33 @@ #include "Socket.h" namespace core { - + class INotify : Socket { - + public: INotify(EPoll &ePoll); ~INotify(); - - int addWatch(std::string watch); + + int addWatch(coreutils::ZString &watch); void removeWatch(int wd); - void onDataReceived(coreutils::ZString &data) override; + void onDataReceived(coreutils::ZString &data) override; - virtual void inAccess(std::string name) {} - virtual void inAttrib(std::string name) {} + virtual void inAccess(coreutils::ZString name) {} + virtual void inAttrib(std::string name) {} virtual void inCloseWrite(std::string name) {} virtual void inCloseNoWrite(std::string name) {} - virtual void inCreate(std::string name) {} - virtual void inDelete(std::string name) {} - virtual void inDeleteSelf(std::string name) {} - virtual void inModify(std::string name) {} - virtual void inMoveSelf(std::string name) {} - virtual void inMovedFrom(std::string name) {} - virtual void inMovedTo(std::string name) {} - virtual void inOpen(std::string name) {} - + virtual void inCreate(coreutils::ZString &name) {} + virtual void inDelete(std::string name) {} + virtual void inDeleteSelf(std::string name) {} + virtual void inModify(std::string name) {} + virtual void inMoveSelf(std::string name) {} + virtual void inMovedFrom(std::string name) {} + virtual void inMovedTo(std::string name) {} + virtual void inOpen(std::string name) {} + }; - + } #endif diff --git a/IPAddress.cpp b/IPAddress.cpp index c4f5e69..c1cb39b 100644 --- a/IPAddress.cpp +++ b/IPAddress.cpp @@ -1,7 +1,7 @@ #include "IPAddress.h" namespace core { - + IPAddress::IPAddress() { addressLength = sizeof(addr); } @@ -14,7 +14,7 @@ namespace core { convert >> port; IPAddress(url, port); } - + IPAddress::IPAddress(std::string address, int port) { memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; @@ -25,7 +25,7 @@ namespace core { } IPAddress::~IPAddress() { - + } struct sockaddr * IPAddress::getPointer() { @@ -36,16 +36,16 @@ namespace core { std::string result; return result; } - + std::string IPAddress::getClientAddressAndPort() { std::stringstream out; out << inet_ntoa(addr.sin_addr); out << ":" << addr.sin_port; return out.str(); } - + int IPAddress::getClientPort() { - int result = -1; + int result = -1; return result; } diff --git a/IPAddress.h b/IPAddress.h index 4beca82..d1029f7 100644 --- a/IPAddress.h +++ b/IPAddress.h @@ -7,20 +7,20 @@ namespace core { class IPAddress : public Object { - + public: IPAddress(); IPAddress(std::string address); IPAddress(std::string address, int port); ~IPAddress(); - - struct sockaddr_in addr; + + struct sockaddr_in addr; socklen_t addressLength; struct sockaddr * getPointer(); std::string getClientAddress(); ///descriptor = descriptor; @@ -45,7 +48,6 @@ namespace core { void Socket::setBufferSize(int length) { this->length = length; buffer = (char *)realloc(buffer, length); - } int Socket::getBufferSize() { @@ -60,20 +62,21 @@ namespace core { void Socket::onUnregistered() {} - bool Socket::eventReceived(struct epoll_event event) { + bool Socket::eventReceived(struct epoll_event event, long long eventId) { +// coreutils::Log(coreutils::LOG_DEBUG_3) << "eventReceived " << eventId << ": " << descriptor << ":" << event.events; inHandler = true; if(event.events & EPOLLRDHUP) { readHangup = true; shutdown("hangup received"); } - else if(event.events & EPOLLIN) { + if(event.events & EPOLLIN) { coreutils::ZString zbuffer(buffer, length); receiveData(zbuffer); } - else if(event.events & EPOLLWRNORM) { + if(event.events & EPOLLWRNORM) { writeSocket(); } - else if(event.events & EPOLLHUP) { + if(event.events & EPOLLHUP) { shutdown(); } inHandler = false; @@ -89,15 +92,11 @@ namespace core { } void Socket::receiveData(coreutils::ZString &buffer) { - coreutils::ZString blank(""); - if(buffer.getLength() <= 0) throw coreutils::Exception("Request to receive data with a zero buffer length.", __FILE__, __LINE__, -1); - int len; int error = -1; - if((len = ::read(getDescriptor(), buffer.getData(), buffer.getLength())) >= 0) { coreutils::ZString zbuffer(buffer.getData(), len); coreutils::Log(coreutils::LOG_DEBUG_1) << zbuffer; @@ -129,7 +128,7 @@ namespace core { if(fifo.size() > 0) { outlock.lock(); if(!shutDown) - ::write(descriptor, fifo.front().c_str(), fifo.front().length()); + int rc = ::write(descriptor, fifo.front().c_str(), fifo.front().length()); fifo.pop(); outlock.unlock(); } @@ -139,8 +138,9 @@ namespace core { outlock.lock(); fifo.emplace(data); outlock.unlock(); - if(!inHandler) - ePoll.resetSocket(this); +// coreutils::Log(coreutils::LOG_DEBUG_4) << "inHandler " << descriptor << " " << inHandler << ":" << shutDown << ":[" << data << "]"; + if(!inHandler) + ePoll.resetSocket(this); return 1; } @@ -153,7 +153,7 @@ namespace core { } void Socket::shutdown(std::string text) { - coreutils::Log(coreutils::LOG_DEBUG_2) << "Shutdown requested on socket " << descriptor << " with reason " << text << "."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Shutdown requested from " << this->text << " (" << descriptor << ") with reason: " << text << "."; shutDown = true; reset = false; } diff --git a/Socket.h b/Socket.h index d0049c0..bf70108 100644 --- a/Socket.h +++ b/Socket.h @@ -60,39 +60,39 @@ namespace core { /// /// setDescriptor establishes the file descriptor for the socket and registers the socket - /// on the EPoll controller. setDescriptor will invoke the onRegister() event. + /// on the EPoll controller. setDescriptor will invoke the onRegister() event. /// - + void setDescriptor(int descriptor); /// fifo; - + }; } diff --git a/SubscriptionManager.cpp b/SubscriptionManager.cpp index 44c2468..48fb233 100644 --- a/SubscriptionManager.cpp +++ b/SubscriptionManager.cpp @@ -5,19 +5,19 @@ namespace core { SubscriptionManager::SubscriptionManager() {} - + int SubscriptionManager::add(Subscription &subscription) { lock.lock(); subscriptions.insert(std::make_pair(subscription.id, &subscription)); lock.unlock(); return 1; } - + int SubscriptionManager::removeSessionSubscriptions(TCPSession &session) { int countSubscribed = 0; int countPublished = 0; - lock.lock(); + lock.lock(); std::string temp = ""; for(auto [key, subscription] : subscriptions) { if(temp != "") { @@ -29,14 +29,14 @@ namespace core { temp = key; delete subscription; ++countPublished; - } + } } if(temp != "") { subscriptions.erase(temp); temp = ""; } - coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; - coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; +// coreutils::Log(coreutils::LOG_DEBUG_2) << "Removed session from " << countSubscribed << " subscription(s)."; +// coreutils::Log(coreutils::LOG_DEBUG_2) << "Cancelled " << countPublished << " channel(s) for session."; lock.unlock(); return countSubscribed; } diff --git a/TCPSession.cpp b/TCPSession.cpp index 67c25ae..d9fe0db 100644 --- a/TCPSession.cpp +++ b/TCPSession.cpp @@ -6,35 +6,32 @@ namespace core { TCPSession::TCPSession(EPoll &ePoll, TCPServer &server, std::string text) : TCPSocket(ePoll, text), server(server) {} - + TCPSession::~TCPSession() { server.removeFromSessionList(this); server.subscriptions.removeSessionSubscriptions(*this); } - + void TCPSession::output(std::stringstream &data) { data << "|" << ipAddress.getClientAddressAndPort(); } - + void TCPSession::protocol(coreutils::ZString &data) { - if(data.getLength() != 0) { - if(server.commands.processRequest(data, *this) == 0) { - coreutils::Log(coreutils::LOG_DEBUG_1) << "Received data could not be parsed: " << data.str(); - } - } + if(server.commands.processRequest(data, *this) == 0) + coreutils::Log(coreutils::LOG_DEBUG_1) << "Received data could not be parsed: " << getDescriptor() << " [" << data.str() << "]"; } - + void TCPSession::onRegistered() { onConnected(); - coreutils::ZString blank(""); - protocol(blank); +// coreutils::ZString blank(""); +// protocol(blank); send(); if(term) shutdown("termination requested"); } - + void TCPSession::onConnected() {} - + void TCPSession::onDataReceived(coreutils::ZString &data) { if(data.getLength() > 0) { lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength()); @@ -66,32 +63,32 @@ namespace core { } } } - + void TCPSession::setBlockSize(int blockSize) { this->blockSize = blockSize; } - + void TCPSession::onLineReceived(coreutils::ZString &line) { protocol(line); send(); if(term) shutdown("termination requested"); } - + void TCPSession::onBlockReceived(coreutils::ZString &block) { coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << block.getLength() << "]"; if(term) shutdown("termination requested"); } - + void TCPSession::send() { if(out.tellp() > 0) write(out.str()); out.str(""); } - + void TCPSession::terminate() { term = true; } - + } diff --git a/TCPSession2.cpp b/TCPSession2.cpp new file mode 100644 index 0000000..af272aa --- /dev/null +++ b/TCPSession2.cpp @@ -0,0 +1,85 @@ +#include "TCPSession2.h" +#include "Exception.h" +#include "Log.h" + +namespace core { + + TCPSession2::TCPSession2(EPoll &ePoll, std::string text) : TCPSocket(ePoll, text) {} + + TCPSession2::~TCPSession2() {} + + void TCPSession2::output(std::stringstream &data) { + data << "|" << ipAddress.getClientAddressAndPort(); + } + + void TCPSession2::protocol(coreutils::ZString &data) {} + + void TCPSession2::onRegistered() { + onConnected(); + send(); + if(term) + TCPSocket::shutdown("termination requested"); + } + + void TCPSession2::onConnected() {} + + void TCPSession2::onDataReceived(coreutils::ZString &data) { + if(data.getLength() > 0) { + lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength()); + memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength()); + lineBufferSize += data.getLength(); + while(lineBufferSize > 0) { + if(blockSize == 0) { + lineLength = strcspn(lineBuffer, "\r\n"); + if(lineLength == lineBufferSize) + break; + coreutils::ZString zLine(lineBuffer, lineLength); + onLineReceived(zLine); + if(lineBuffer[lineLength] == '\r') + ++lineLength; + if(lineBuffer[lineLength] == '\n') + ++lineLength; + lineBufferSize -= lineLength; + if(lineBufferSize > 0) + memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize); + lineBuffer = (char *)realloc(lineBuffer, lineBufferSize); + } else if(lineBufferSize >= blockLength) { + coreutils::ZString zBlock(lineBuffer, blockLength); + onBlockReceived(zBlock); + lineBufferSize -= blockLength; + if(lineBufferSize > 0) + memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize); + lineBuffer = (char *)realloc(lineBuffer, lineBufferSize); + } + } + } + } + + void TCPSession2::setBlockSize(int blockSize) { + this->blockSize = blockSize; + } + + void TCPSession2::onLineReceived(coreutils::ZString &line) { + protocol(line); + send(); + if(term) + TCPSocket::shutdown("termination requested"); + } + + void TCPSession2::onBlockReceived(coreutils::ZString &block) { + coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << block.getLength() << "]"; + if(term) + TCPSocket::shutdown("termination requested"); + } + + void TCPSession2::send() { + if(out.tellp() > 0) + TCPSocket::write(out.str()); + out.str(""); + } + + void TCPSession2::terminate() { + term = true; + } + +} diff --git a/TCPSession2.h b/TCPSession2.h new file mode 100644 index 0000000..8ad4a20 --- /dev/null +++ b/TCPSession2.h @@ -0,0 +1,139 @@ +#ifndef __TCPSession2_h__ +# define __TCPSession2_h__ + +#include "TCPSocket.h" +#include "Timer.h" +#include "SessionFilter.h" + +namespace core { + + class Command; + class TCPServer; + + /// + /// TCPSession2 + /// + /// TCPSession defines the nature of the interaction with the client + /// and stores persistent data for a defined session. TCPSession objects + /// are not sockets but instead provide a communications control + /// mechanism. Protocol conversations are provided through extensions + /// from this object. + /// + /// TCPSession2 is designed to be 'connected' instead of being served + /// by a server. + /// + + class TCPSession2 : public TCPSocket { + + public: + + /// + /// + /// + + TCPSession2(EPoll &ePoll, std::string text = ""); + + /// + /// + /// + + virtual ~TCPSession2(); + + Command *grab = NULL; + + virtual void output(std::stringstream &data); + + /// + /// The send method is used to output the contents of the out stream + /// to the session containing the stream. + /// + + void send(); + + /// + /// Use this method to terminate this TCPSession. + /// + + void terminate(); + + /// + /// Use out to send data to the session socket or other session sockets. + /// + + std::stringstream out; + + protected: + + /// + /// + /// + + virtual void onRegistered() override; + + /// + /// Override this method to receive data directly from the socket as data is + /// received. If you need data split by line termination characters then + /// override the onLineReceived method instead. + /// + virtual void onDataReceived(coreutils::ZString &data) override; + + /// + /// Override the onLineReceived method to receive a string of characters that + /// represents a single line of data terminated by a LF or CRLF. If onDataReceived + /// was overriden this method will not be called unless the onDataReceived calls + /// this method explicitly using the class and member name. + /// + + virtual void onLineReceived(coreutils::ZString &line); + + /// + /// Override the onBlockReceived method to receive a string of characters that + /// represents a single block of data of length determined by the block length value. If + /// onDataReceived was overriden this method will not be called unless the onDataReceived + /// calls this method explicitly using the class and member name. + /// + + virtual void onBlockReceived(coreutils::ZString &block); + + /// + /// This method is called from within the protocol method when protocol is called + /// on the initial connection where the data is an empty string. Use this method + /// to deliver a message to the connection upon connection. + /// + + virtual void onConnected(); + + /// + /// Override the protocol method to manage and control the session communications + /// in your inherited session. If you do not override this method then the Session + /// default will process the 'commands' added to the server object using the + /// processRequest method on the session input. + /// + /// When data is received within the session two modes are available to pass the + /// data through the protocol method: LINE or BLOCK. + /// + + virtual void protocol(coreutils::ZString &data); + + /// + /// Use setBlockSize to set the amount of data that should be read at once from the + /// session data buffer. + /// If this value is set to 0 then the data will be retrieved + /// + + void setBlockSize(int size = 0); + + private: + char *lineBuffer = NULL; + int lineBufferSize = 0; + int lineLength = 0; + int blockLength = 0; + std::mutex mtx; + bool term = false; + int blockSize = 0; + + }; + +} + +#endif diff --git a/TCPSocket.cpp b/TCPSocket.cpp index 3345032..20afa4a 100644 --- a/TCPSocket.cpp +++ b/TCPSocket.cpp @@ -2,6 +2,7 @@ #include "EPoll.h" #include "Log.h" #include "Exception.h" +#include "errno.h" namespace core { @@ -14,7 +15,8 @@ namespace core { void TCPSocket::connect(IPAddress &address) { setDescriptor(socket(AF_INET, SOCK_STREAM, 0)); if(::connect(getDescriptor(), (struct sockaddr *)&address.addr, address.addressLength) == -1) - throw coreutils::Exception("Error on connect to TCP socket."); + throw coreutils::Exception("Error on connect to TCP socket." + errno); + coreutils::Log(coreutils::LOG_DEBUG_3) << "Connected to IP..." << address.getClientAddressAndPort(); } void TCPSocket::output(std::stringstream &out) { diff --git a/Thread.cpp b/Thread.cpp index d942b51..cea1074 100644 --- a/Thread.cpp +++ b/Thread.cpp @@ -60,9 +60,12 @@ namespace core { } else if(rc > 0) { for(int ix = 0; ix < rc; ++ix) { ++count; - if(((Socket *)events[ix].data.ptr)->eventReceived(events[ix])) { + if(((Socket *)events[ix].data.ptr)->eventReceived(events[ix], ++ePoll.eventId)) { +// coreutils::Log(coreutils::LOG_DEBUG_4) << "return true"; ePoll.resetSocket((Socket *)events[ix].data.ptr); - } else { + } else { + ((Socket *)events[ix].data.ptr)->shutDown = true; +// coreutils::Log(coreutils::LOG_DEBUG_4) << "return false"; delete (Socket *)events[ix].data.ptr; } } diff --git a/Thread.h b/Thread.h index 023123a..41baa8e 100644 --- a/Thread.h +++ b/Thread.h @@ -10,7 +10,7 @@ namespace core { class EPoll; - + /// /// Thread /// @@ -18,37 +18,37 @@ namespace core { /// object to allow maintaining a status value for monitoring the thread activity. EPoll will instantiate /// a Thread object for each thread specified in the EPoll's start method. /// - + class Thread : public Object { - - public: + + public: Thread(EPoll &ePoll); Thread(EPoll &ePoll, ThreadScope *thread); ~Thread(); - + /// /// Start the thread object. This will cause the epoll scheduler to commence reading the epoll queue. /// - + void start(); void join(); - std::string getStatus(); + std::string getStatus(); pid_t getThreadId(); int getCount(); - void output(std::stringstream &data); - + void output(std::stringstream &data); + private: EPoll &ePoll; // The EPoll control object. std::string status; - int count; + int count; std::thread *_thread; void print_thread_start_log(); pid_t threadId; - void run(); + void run(); ThreadScope *thread; - + }; - + } #endif diff --git a/Timer.cpp b/Timer.cpp index 8f74c8d..9b3d536 100644 --- a/Timer.cpp +++ b/Timer.cpp @@ -1,61 +1,60 @@ #include "Timer.h" namespace core { - + Timer::Timer(EPoll &ePoll, double delay = 0.0f) : Socket(ePoll, "Timer") { setDescriptor(timerfd_create(CLOCK_REALTIME, 0)); setTimer(delay); } - + Timer::~Timer() { } - + void Timer::setTimer(double delay) { - + double integer; double fraction; struct itimerspec timer; - + delayValue = delay; - + timer.it_interval.tv_sec = 0; timer.it_interval.tv_nsec = 0; - + fraction = modf(delay, &integer); - + timer.it_value.tv_sec = (int)integer; timer.it_value.tv_nsec = (int)(fraction * 1000000000); - + timerfd_settime(getDescriptor(), 0, &timer, NULL); - + } - + void Timer::clearTimer() { - + struct itimerspec timer; - + timer.it_interval.tv_sec = 0; timer.it_interval.tv_nsec = 0; timer.it_value.tv_sec = 0; timer.it_value.tv_nsec = 0; - + timerfd_settime(getDescriptor(), 0, &timer, NULL); - } - + double Timer::getElapsed() { struct itimerspec timer; timerfd_gettime(getDescriptor(), &timer); double toTimeout = (double)((timer.it_value.tv_sec * 1000000000L) + timer.it_value.tv_nsec) / 1000000000L; return delayValue - toTimeout; } - - void Timer::onDataReceived(std::string data) { + + void Timer::onDataReceived(std::string data) { onTimeout(); - } - + } + double Timer::getEpoch() { return (double)std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() /1000000000L; } - + } diff --git a/html/CommandList_8h_source.html b/html/CommandList_8h_source.html index b013265..04f32e6 100644 --- a/html/CommandList_8h_source.html +++ b/html/CommandList_8h_source.html @@ -112,8 +112,8 @@ $(function() {
    78 
    79 #endif
    Definition: CommandList.h:18
    -
    int processCommand(coreutils::ZString &request, TCPSession &session)
    Definition: CommandList.cpp:42
    -
    bool grabInput(TCPSession &session, Command &command)
    Definition: CommandList.cpp:33
    +
    int processCommand(coreutils::ZString &request, TCPSession &session)
    Definition: CommandList.cpp:43
    +
    bool grabInput(TCPSession &session, Command &command)
    Definition: CommandList.cpp:34
    void add(Command &command, std::string name="")
    Definition: CommandList.cpp:8
    void remove(Command &command)
    Definition: CommandList.cpp:12
    int processRequest(coreutils::ZString &request, TCPSession &session)
    Definition: CommandList.cpp:14
    diff --git a/html/EPoll_8h_source.html b/html/EPoll_8h_source.html index 757633f..ebf61e2 100644 --- a/html/EPoll_8h_source.html +++ b/html/EPoll_8h_source.html @@ -81,56 +81,58 @@ $(function() {
    32 
    33  public:
    34 
    -
    38 
    -
    39  EPoll();
    +
    35  volatile long long eventId = 0;
    +
    36 
    40 
    -
    44 
    -
    45  ~EPoll();
    -
    46 
    -
    53 
    -
    54  bool start(int numberOfThreads, int maxSockets);
    +
    41  EPoll();
    +
    42 
    +
    46 
    +
    47  ~EPoll();
    +
    48 
    55 
    -
    61 
    -
    62  bool stop();
    +
    56  bool start(int numberOfThreads, int maxSockets);
    +
    57 
    63 
    -
    68 
    -
    69  bool isStopping();
    +
    64  bool stop();
    +
    65 
    70 
    -
    79 
    -
    80  bool registerSocket(Socket *socket);
    +
    71  bool isStopping();
    +
    72 
    81 
    -
    85 
    -
    86  bool unregisterSocket(Socket *socket);
    +
    82  bool registerSocket(Socket *socket);
    +
    83 
    87 
    -
    91 
    -
    92  int getDescriptor();
    +
    88  bool unregisterSocket(Socket *socket);
    +
    89 
    93 
    -
    97 
    -
    98  int maxSockets;
    +
    94  int getDescriptor();
    +
    95 
    99 
    -
    103 
    -
    104  void eventReceived(struct epoll_event event);
    + +
    101 
    105 
    -
    112 
    -
    113  int processCommand(coreutils::ZString &request, TCPSession &session) override;
    +
    106  void eventReceived(struct epoll_event event);
    +
    107 
    114 
    -
    115  void resetSocket(Socket *socket);
    +
    115  int processCommand(coreutils::ZString &request, TCPSession &session) override;
    116 
    -
    117  private:
    -
    118 
    -
    119  int epfd;
    -
    120  int numberOfThreads;
    -
    121  std::vector<Thread> threads;
    -
    122  volatile bool terminateThreads;
    -
    123  void enableSocket(Socket *socket);
    -
    124  void disableSocket(Socket *socket);
    -
    125 
    -
    126  };
    -
    127 
    -
    128 }
    +
    117  void resetSocket(Socket *socket);
    +
    118 
    +
    119  private:
    +
    120 
    +
    121  int epfd;
    +
    122  int numberOfThreads;
    +
    123  std::vector<Thread> threads;
    +
    124  volatile bool terminateThreads;
    +
    125  void enableSocket(Socket *socket);
    +
    126  void disableSocket(Socket *socket);
    +
    127 
    +
    128  };
    129 
    -
    130 #endif
    +
    130 }
    131 
    +
    132 #endif
    +
    133 
    Definition: Command.h:22
    Definition: EPoll.h:31
    bool stop()
    Stop and shut down the BMAEPoll processing.
    Definition: EPoll.cpp:46
    @@ -143,7 +145,7 @@ $(function() {
    bool unregisterSocket(Socket *socket)
    Unregister a BMASocket from monitoring by BMAEPoll.
    Definition: EPoll.cpp:75
    ~EPoll()
    Definition: EPoll.cpp:18
    bool start(int numberOfThreads, int maxSockets)
    Start the BMAEPoll processing.
    Definition: EPoll.cpp:20
    -
    int maxSockets
    The maximum number of socket allowed.
    Definition: EPoll.h:98
    +
    int maxSockets
    The maximum number of socket allowed.
    Definition: EPoll.h:100
    Definition: Socket.h:34
    Definition: TCPSession.h:24
    diff --git a/html/INotify_8h_source.html b/html/INotify_8h_source.html index 1f79a59..d9b1771 100644 --- a/html/INotify_8h_source.html +++ b/html/INotify_8h_source.html @@ -72,33 +72,33 @@ $(function() {
    5 #include "Socket.h"
    6 
    7 namespace core {
    -
    8 
    +
    8 
    9  class INotify : Socket {
    -
    10 
    +
    10 
    11  public:
    12  INotify(EPoll &ePoll);
    13  ~INotify();
    -
    14 
    -
    15  int addWatch(std::string watch);
    +
    14 
    +
    15  int addWatch(coreutils::ZString &watch);
    16  void removeWatch(int wd);
    17 
    -
    18  void onDataReceived(coreutils::ZString &data) override;
    +
    18  void onDataReceived(coreutils::ZString &data) override;
    19 
    -
    20  virtual void inAccess(std::string name) {}
    -
    21  virtual void inAttrib(std::string name) {}
    +
    20  virtual void inAccess(coreutils::ZString name) {}
    +
    21  virtual void inAttrib(std::string name) {}
    22  virtual void inCloseWrite(std::string name) {}
    23  virtual void inCloseNoWrite(std::string name) {}
    -
    24  virtual void inCreate(std::string name) {}
    -
    25  virtual void inDelete(std::string name) {}
    -
    26  virtual void inDeleteSelf(std::string name) {}
    -
    27  virtual void inModify(std::string name) {}
    -
    28  virtual void inMoveSelf(std::string name) {}
    -
    29  virtual void inMovedFrom(std::string name) {}
    -
    30  virtual void inMovedTo(std::string name) {}
    -
    31  virtual void inOpen(std::string name) {}
    -
    32 
    +
    24  virtual void inCreate(coreutils::ZString &name) {}
    +
    25  virtual void inDelete(std::string name) {}
    +
    26  virtual void inDeleteSelf(std::string name) {}
    +
    27  virtual void inModify(std::string name) {}
    +
    28  virtual void inMoveSelf(std::string name) {}
    +
    29  virtual void inMovedFrom(std::string name) {}
    +
    30  virtual void inMovedTo(std::string name) {}
    +
    31  virtual void inOpen(std::string name) {}
    +
    32 
    33  };
    -
    34 
    +
    34 
    35 }
    36 
    37 #endif
    diff --git a/html/IPAddress_8h_source.html b/html/IPAddress_8h_source.html index 376e6e9..33793d8 100644 --- a/html/IPAddress_8h_source.html +++ b/html/IPAddress_8h_source.html @@ -74,14 +74,14 @@ $(function() {
    7 namespace core {
    8 
    9  class IPAddress : public Object {
    -
    10 
    +
    10 
    11  public:
    12  IPAddress();
    13  IPAddress(std::string address);
    14  IPAddress(std::string address, int port);
    15  ~IPAddress();
    16 
    -
    17  struct sockaddr_in addr;
    +
    17  struct sockaddr_in addr;
    18  socklen_t addressLength;
    19 
    20  struct sockaddr * getPointer();
    diff --git a/html/Socket_8h_source.html b/html/Socket_8h_source.html index 1be47c5..925b28f 100644 --- a/html/Socket_8h_source.html +++ b/html/Socket_8h_source.html @@ -90,15 +90,15 @@ $(function() {
    58 
    59  void shutdown(std::string text = "unknown");
    60 
    -
    65 
    +
    65 
    66  void setDescriptor(int descriptor);
    -
    67 
    +
    67 
    68  int getDescriptor();
    -
    69 
    -
    82 
    -
    83  bool eventReceived(struct epoll_event event);
    +
    69 
    +
    82 
    +
    83  bool eventReceived(struct epoll_event event, long long eventId);
    84 
    -
    88 
    +
    88 
    89  int write(std::string data);
    90  void write(char *buffer, int length);
    91 
    @@ -107,93 +107,87 @@ $(function() {
    100 
    101  virtual void onRegister();
    102  virtual void onRegistered();
    -
    103 
    +
    103 
    104  virtual void onUnregister();
    -
    105 
    -
    112 
    -
    113  virtual void onUnregistered();
    -
    114 
    -
    115  bool needsToWrite();
    -
    116 
    -
    117  bool reset = false;
    -
    118 
    -
    119  protected:
    -
    120 
    -
    121  EPoll &ePoll; // The EPoll control object.
    -
    122 
    -
    123  bool shutDown = false;
    -
    124 
    -
    125  void setBufferSize(int length);
    -
    126 
    -
    127  int getBufferSize();
    -
    128 
    -
    134 
    -
    135 // virtual void onConnected(); ///< Called when socket is open and ready to communicate.
    -
    136 
    -
    140 
    -
    141 // virtual void onDisconnected(); ///< Called when socket is closing and no longer ready to communicate.
    -
    142 
    -
    150 
    -
    151  virtual void onDataReceived(std::string data);
    -
    152 
    -
    156 
    -
    157  virtual void onDataReceived(coreutils::ZString &data);
    -
    158 
    -
    163 
    -
    164  virtual void receiveData(coreutils::ZString &buffer);
    -
    165 
    -
    166  private:
    -
    167 
    -
    168  std::string text;
    -
    169  int descriptor = -1;
    -
    170 // std::mutex lock;
    -
    171  std::mutex outlock;
    -
    172  bool readHangup = false;
    -
    173  bool inHandler = false;
    -
    174 // struct epoll_event event; // Event selection construction structure.
    -
    175 
    -
    176  //-------------------------------------------------------------------------------------
    -
    177  // the writeSocket is called when epoll has received a write request for a socket.
    -
    178  // Writing data to this socket is queued in the streambuf and permission is requested
    -
    179  // to write to the socket. This routine handles the writing of the streambuf data
    -
    180  // buffer to the socket.
    -
    181  //-------------------------------------------------------------------------------------
    -
    182 
    -
    183  void writeSocket();
    -
    184 
    -
    185  // int_type underflow();
    -
    186 // int_type uflow();
    -
    187 // int_type pbackfail(int_type ch);
    -
    188 // streamsize showmanyc();
    +
    105 
    +
    111 
    +
    112  virtual void onUnregistered();
    +
    113 
    +
    114  bool needsToWrite();
    +
    115 
    +
    116  bool reset = false;
    +
    117 
    +
    118  volatile bool shutDown = false;
    +
    119 
    +
    120  protected:
    +
    121 
    +
    122  EPoll &ePoll; // The EPoll control object.
    +
    123 
    +
    124  void setBufferSize(int length);
    +
    125 
    +
    126  int getBufferSize();
    +
    127 
    +
    133 
    +
    134 // virtual void onConnected(); ///< Called when socket is open and ready to communicate.
    +
    135 
    +
    139 
    +
    140 // virtual void onDisconnected(); ///< Called when socket is closing and no longer ready to communicate.
    +
    141 
    +
    149 
    +
    150  virtual void onDataReceived(std::string data);
    +
    151 
    +
    155 
    +
    156  virtual void onDataReceived(coreutils::ZString &data);
    +
    157 
    +
    162 
    +
    163  virtual void receiveData(coreutils::ZString &buffer);
    +
    164 
    +
    165  private:
    +
    166 
    +
    167  std::string text;
    +
    168  int descriptor = -1;
    +
    169  std::mutex outlock;
    +
    170  bool readHangup = false;
    +
    171  volatile bool inHandler = false;
    +
    172 
    +
    173  //-------------------------------------------------------------------------------------
    +
    174  // the writeSocket is called when epoll has received a write request for a socket.
    +
    175  // Writing data to this socket is queued in the streambuf and permission is requested
    +
    176  // to write to the socket. This routine handles the writing of the streambuf data
    +
    177  // buffer to the socket.
    +
    178  //-------------------------------------------------------------------------------------
    +
    179 
    +
    180  void writeSocket();
    +
    181 
    +
    182  // int_type underflow();
    +
    183 // int_type uflow();
    +
    184 // int_type pbackfail(int_type ch);
    +
    185 // streamsize showmanyc();
    +
    186 
    +
    187  char *buffer; // This is a pointer to the managed buffer space.
    +
    188  int length; // This is the length of the buffer.
    189 
    -
    190  char *buffer; // This is a pointer to the managed buffer space.
    -
    191  int length; // This is the length of the buffer.
    -
    192 
    -
    193 // const char * const begin_;
    -
    194 // const char * const end_;
    -
    195 // const char * const current_;
    -
    196 
    -
    197  std::queue<std::string> fifo;
    -
    198 
    -
    199  };
    -
    200 
    -
    201 }
    -
    202 
    -
    203 #endif
    -
    204 
    +
    190  std::queue<std::string> fifo;
    +
    191 
    +
    192  };
    +
    193 
    +
    194 }
    +
    195 
    +
    196 #endif
    +
    197 
    Definition: EPoll.h:31
    Definition: Socket.h:34
    -
    int getDescriptor()
    Get the descriptor for the socket.
    Definition: Socket.cpp:41
    -
    int write(std::string data)
    Definition: Socket.cpp:138
    -
    virtual void onRegistered()
    Called after the socket has been registered with epoll processing.
    Definition: Socket.cpp:57
    -
    virtual void receiveData(coreutils::ZString &buffer)
    Definition: Socket.cpp:91
    +
    int getDescriptor()
    Get the descriptor for the socket.
    Definition: Socket.cpp:44
    +
    int write(std::string data)
    Definition: Socket.cpp:137
    +
    bool eventReceived(struct epoll_event event, long long eventId)
    Parse epoll event and call specified callbacks.
    Definition: Socket.cpp:65
    +
    virtual void onRegistered()
    Called after the socket has been registered with epoll processing.
    Definition: Socket.cpp:59
    +
    virtual void receiveData(coreutils::ZString &buffer)
    Definition: Socket.cpp:94
    Socket(EPoll &ePoll, std::string text="")
    Definition: Socket.cpp:11
    -
    bool eventReceived(struct epoll_event event)
    Parse epoll event and call specified callbacks.
    Definition: Socket.cpp:63
    -
    virtual void onRegister()
    Called before the socket has registered with the epoll processing.
    Definition: Socket.cpp:55
    -
    virtual ~Socket()
    Definition: Socket.cpp:17
    -
    void setDescriptor(int descriptor)
    Set the descriptor for the socket.
    Definition: Socket.cpp:27
    -
    virtual void onDataReceived(std::string data)
    Called when data is received from the socket.
    Definition: Socket.cpp:83
    -
    virtual void onUnregistered()
    Called when the socket has finished unregistering for the epoll processing.
    Definition: Socket.cpp:61
    +
    virtual void onRegister()
    Called before the socket has registered with the epoll processing.
    Definition: Socket.cpp:57
    +
    virtual ~Socket()
    Definition: Socket.cpp:16
    +
    void setDescriptor(int descriptor)
    Set the descriptor for the socket.
    Definition: Socket.cpp:29
    +
    virtual void onDataReceived(std::string data)
    Called when data is received from the socket.
    Definition: Socket.cpp:86
    +
    virtual void onUnregistered()
    Called when the socket has finished unregistering for the epoll processing.
    Definition: Socket.cpp:63
    void shutdown(std::string text="unknown")
    Definition: Socket.cpp:155
    diff --git a/html/TCPSession2_8h_source.html b/html/TCPSession2_8h_source.html new file mode 100644 index 0000000..6eafeb1 --- /dev/null +++ b/html/TCPSession2_8h_source.html @@ -0,0 +1,161 @@ + + + + + + + +My Project: TCPSession2.h Source File + + + + + + + + + +
    +
    +
  • bool core::CommandList::processRequest int core::CommandList::processRequest ( coreutils::ZString &  request,
    + + + + + +
    +
    My Project +
    +
    +
    + + + + + + + +
    + +
    +
    + + +
    + +
    + +
    +
    +
    TCPSession2.h
    +
    +
    +
    1 #ifndef __TCPSession2_h__
    +
    2 # define __TCPSession2_h__
    +
    3 
    +
    4 #include "TCPSocket.h"
    +
    5 #include "Timer.h"
    +
    6 #include "SessionFilter.h"
    +
    7 
    +
    8 namespace core {
    +
    9 
    +
    10  class Command;
    +
    11  class TCPServer;
    +
    12 
    +
    25 
    +
    26  class TCPSession2 : public TCPSocket {
    +
    27 
    +
    28  public:
    +
    29 
    +
    33 
    +
    34  TCPSession2(EPoll &ePoll, std::string text = "");
    +
    35 
    +
    39 
    +
    40  virtual ~TCPSession2();
    +
    41 
    +
    42  Command *grab = NULL;
    +
    43 
    +
    44  virtual void output(std::stringstream &data);
    +
    45 
    +
    50 
    +
    51  void send();
    +
    52 
    +
    56 
    +
    57  void terminate();
    +
    58 
    +
    62 
    +
    63  std::stringstream out;
    +
    64 
    +
    65  protected:
    +
    66 
    +
    70 
    +
    71  virtual void onRegistered() override;
    +
    72 
    +
    78  virtual void onDataReceived(coreutils::ZString &data) override;
    +
    79 
    +
    86 
    +
    87  virtual void onLineReceived(coreutils::ZString &line);
    +
    88 
    +
    95 
    +
    96  virtual void onBlockReceived(coreutils::ZString &block);
    +
    97 
    +
    103 
    +
    104  virtual void onConnected();
    +
    105 
    +
    115 
    +
    116  virtual void protocol(coreutils::ZString &data);
    +
    117 
    +
    123 
    +
    124  void setBlockSize(int size = 0);
    +
    125 
    +
    126  private:
    +
    127  char *lineBuffer = NULL;
    +
    128  int lineBufferSize = 0;
    +
    129  int lineLength = 0;
    +
    130  int blockLength = 0;
    +
    131  std::mutex mtx;
    +
    132  bool term = false;
    +
    133  int blockSize = 0;
    +
    134 
    +
    135  };
    +
    136 
    +
    137 }
    +
    138 
    +
    139 #endif
    +
    Definition: Command.h:22
    +
    Definition: EPoll.h:31
    +
    Definition: TCPSession2.h:26
    +
    virtual void protocol(coreutils::ZString &data)
    Definition: TCPSession2.cpp:15
    +
    virtual void onDataReceived(coreutils::ZString &data) override
    Definition: TCPSession2.cpp:26
    +
    std::stringstream out
    Definition: TCPSession2.h:63
    +
    void terminate()
    Definition: TCPSession2.cpp:81
    +
    virtual void onBlockReceived(coreutils::ZString &block)
    Definition: TCPSession2.cpp:69
    +
    virtual void onLineReceived(coreutils::ZString &line)
    Definition: TCPSession2.cpp:62
    +
    void setBlockSize(int size=0)
    Definition: TCPSession2.cpp:58
    +
    virtual void onRegistered() override
    Called after the socket has been registered with epoll processing.
    Definition: TCPSession2.cpp:17
    +
    void send()
    Definition: TCPSession2.cpp:75
    +
    virtual void output(std::stringstream &data)
    Definition: TCPSession2.cpp:11
    +
    virtual void onConnected()
    Definition: TCPSession2.cpp:24
    +
    Definition: TCPSocket.h:20
    +
    + + + + diff --git a/html/TCPSession_8h_source.html b/html/TCPSession_8h_source.html index cac4bce..4249d08 100644 --- a/html/TCPSession_8h_source.html +++ b/html/TCPSession_8h_source.html @@ -143,17 +143,17 @@ $(function() {
    Definition: EPoll.h:31
    Definition: TCPServer.h:25
    Definition: TCPSession.h:24
    -
    void send()
    Definition: TCPSession.cpp:87
    -
    void terminate()
    Definition: TCPSession.cpp:93
    -
    virtual void onLineReceived(coreutils::ZString &line)
    Definition: TCPSession.cpp:74
    +
    void send()
    Definition: TCPSession.cpp:84
    +
    void terminate()
    Definition: TCPSession.cpp:90
    +
    virtual void onLineReceived(coreutils::ZString &line)
    Definition: TCPSession.cpp:71
    virtual void output(std::stringstream &data)
    Definition: TCPSession.cpp:15
    -
    void setBlockSize(int size=0)
    Definition: TCPSession.cpp:70
    -
    virtual void onConnected()
    Definition: TCPSession.cpp:36
    +
    void setBlockSize(int size=0)
    Definition: TCPSession.cpp:67
    +
    virtual void onConnected()
    Definition: TCPSession.cpp:33
    virtual void protocol(coreutils::ZString &data)
    Definition: TCPSession.cpp:19
    -
    virtual void onBlockReceived(coreutils::ZString &block)
    Definition: TCPSession.cpp:81
    +
    virtual void onBlockReceived(coreutils::ZString &block)
    Definition: TCPSession.cpp:78
    std::stringstream out
    Definition: TCPSession.h:67
    -
    virtual void onRegistered() override
    Called after the socket has been registered with epoll processing.
    Definition: TCPSession.cpp:27
    -
    virtual void onDataReceived(coreutils::ZString &data) override
    Definition: TCPSession.cpp:38
    +
    virtual void onRegistered() override
    Called after the socket has been registered with epoll processing.
    Definition: TCPSession.cpp:24
    +
    virtual void onDataReceived(coreutils::ZString &data) override
    Definition: TCPSession.cpp:35
    Definition: TCPSocket.h:20
    diff --git a/html/TCPSocket_8h_source.html b/html/TCPSocket_8h_source.html index d57da81..d09b5f5 100644 --- a/html/TCPSocket_8h_source.html +++ b/html/TCPSocket_8h_source.html @@ -99,7 +99,7 @@ $(function() {
    Definition: IPAddress.h:9
    Definition: Socket.h:34
    Definition: TCPSocket.h:20
    -
    virtual void output(std::stringstream &out)
    Definition: TCPSocket.cpp:20
    +
    virtual void output(std::stringstream &out)
    Definition: TCPSocket.cpp:22