Merge branch 'master' into develop
This commit is contained in:
commit
bbf904729f
4
.gitignore
vendored
4
.gitignore
vendored
@ -3,8 +3,12 @@ Release
|
|||||||
*.o
|
*.o
|
||||||
*~
|
*~
|
||||||
*.mk
|
*.mk
|
||||||
|
.history
|
||||||
libServerCore.a
|
libServerCore.a
|
||||||
docs/latex/
|
docs/latex/
|
||||||
docs/html
|
docs/html
|
||||||
*/*.ipch
|
*/*.ipch
|
||||||
*/mmap_address.bin
|
*/mmap_address.bin
|
||||||
|
.history/*
|
||||||
|
html
|
||||||
|
latex
|
68
.history/SubscriptionHandler_20221013185305.cpp
Normal file
68
.history/SubscriptionHandler_20221013185305.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
.history/SubscriptionHandler_20221013191001.h
Normal file
24
.history/SubscriptionHandler_20221013191001.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef __SubscriptionHandler_h__
|
||||||
|
#define __SubscriptionHandler_h__
|
||||||
|
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
class SubscriptionHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
SubscriptionHandler();
|
||||||
|
|
||||||
|
virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session);
|
||||||
|
|
||||||
|
virtual int onSubscribe(TCPSession &session);
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
23
.history/SubscriptionHandler_20221013204338.h
Normal file
23
.history/SubscriptionHandler_20221013204338.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef __SubscriptionHandler_h__
|
||||||
|
#define __SubscriptionHandler_h__
|
||||||
|
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
class SubscriptionHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
SubscriptionHandler();
|
||||||
|
|
||||||
|
virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session);
|
||||||
|
|
||||||
|
virtual int onSubscribe(TCPSession &session);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
68
.history/SubscriptionHandler_20221013204409.cpp
Normal file
68
.history/SubscriptionHandler_20221013204409.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
23
.history/SubscriptionHandler_20221013204504.h
Normal file
23
.history/SubscriptionHandler_20221013204504.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef __SubscriptionHandler_h__
|
||||||
|
#define __SubscriptionHandler_h__
|
||||||
|
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
class SubscriptionHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
SubscriptionHandler();
|
||||||
|
|
||||||
|
virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session);
|
||||||
|
|
||||||
|
virtual int onSubscribe(TCPSession &session);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
68
.history/SubscriptionHandler_20221013204612.cpp
Normal file
68
.history/SubscriptionHandler_20221013204612.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#include "Log.h"
|
||||||
|
#include "Subscription.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
22
.history/SubscriptionHandler_20221014152050.h
Normal file
22
.history/SubscriptionHandler_20221014152050.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef __SubscriptionHandler_h__
|
||||||
|
#define __SubscriptionHandler_h__
|
||||||
|
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
class SubscriptionHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session);
|
||||||
|
virtual int onSubscribe(TCPSession &session){};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
22
.history/SubscriptionHandler_20221014152131.h
Normal file
22
.history/SubscriptionHandler_20221014152131.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef __SubscriptionHandler_h__
|
||||||
|
#define __SubscriptionHandler_h__
|
||||||
|
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
class SubscriptionHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session);
|
||||||
|
virtual int onSubscribe(TCPSession &session) {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
22
.history/SubscriptionHandler_20221014152241.h
Normal file
22
.history/SubscriptionHandler_20221014152241.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef __SubscriptionHandler_h__
|
||||||
|
#define __SubscriptionHandler_h__
|
||||||
|
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
class SubscriptionHandler : public Base
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session);
|
||||||
|
virtual int onSubscribe(TCPSession &session) {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
22
.history/SubscriptionHandler_20221014152252.h
Normal file
22
.history/SubscriptionHandler_20221014152252.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef __SubscriptionHandler_h__
|
||||||
|
#define __SubscriptionHandler_h__
|
||||||
|
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
class SubscriptionHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session);
|
||||||
|
virtual int onSubscribe(TCPSession &session) {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
22
.history/SubscriptionHandler_20221014152513.h
Normal file
22
.history/SubscriptionHandler_20221014152513.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef __SubscriptionHandler_h__
|
||||||
|
#define __SubscriptionHandler_h__
|
||||||
|
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
class SubscriptionHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session);
|
||||||
|
virtual int onSubscribe(TCPSession &session) { return 1; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
23
.history/SubscriptionHandler_20221014153238.h
Normal file
23
.history/SubscriptionHandler_20221014153238.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef __SubscriptionHandler_h__
|
||||||
|
#define __SubscriptionHandler_h__
|
||||||
|
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
class TCPSession;
|
||||||
|
|
||||||
|
class SubscriptionHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session);
|
||||||
|
virtual int onSubscribe(TCPSession &session);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
33
.history/SubscriptionManager_20221013225816.h
Normal file
33
.history/SubscriptionManager_20221013225816.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef __SubscriptionManager_h__
|
||||||
|
#define __SubscriptionManager_h__
|
||||||
|
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "Subscription.h"
|
||||||
|
#include "Command.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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<std::string, Subscription *> subscriptions;
|
||||||
|
std::map<std::string, SubscriptionHandler> handlers;
|
||||||
|
std::mutex lock;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
34
.history/SubscriptionManager_20221013231834.h
Normal file
34
.history/SubscriptionManager_20221013231834.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef __SubscriptionManager_h__
|
||||||
|
#define __SubscriptionManager_h__
|
||||||
|
|
||||||
|
#include "Command.h"
|
||||||
|
#include "Subscription.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<std::string, Subscription *> subscriptions;
|
||||||
|
std::map<std::string, SubscriptionHandler> handlers;
|
||||||
|
std::mutex lock;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
34
.history/SubscriptionManager_20221013232252.h
Normal file
34
.history/SubscriptionManager_20221013232252.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef __SubscriptionManager_h__
|
||||||
|
#define __SubscriptionManager_h__
|
||||||
|
|
||||||
|
#include "Command.h"
|
||||||
|
#include "Subscription.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<std::string, Subscription *> subscriptions;
|
||||||
|
std::map<std::string, SubscriptionHandler *> handlers;
|
||||||
|
std::mutex lock;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
34
.history/SubscriptionManager_20221013232501.h
Normal file
34
.history/SubscriptionManager_20221013232501.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef __SubscriptionManager_h__
|
||||||
|
#define __SubscriptionManager_h__
|
||||||
|
|
||||||
|
#include "Command.h"
|
||||||
|
#include "Subscription.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<std::string, Subscription *> subscriptions;
|
||||||
|
std::map<std::string, SubscriptionHandler *> handlers;
|
||||||
|
std::mutex lock;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
34
.history/SubscriptionManager_20221013232513.h
Normal file
34
.history/SubscriptionManager_20221013232513.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef __SubscriptionManager_h__
|
||||||
|
#define __SubscriptionManager_h__
|
||||||
|
|
||||||
|
#include "Command.h"
|
||||||
|
#include "Subscription.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<std::string, Subscription *> subscriptions;
|
||||||
|
std::map<std::string, SubscriptionHandler *> handlers;
|
||||||
|
std::mutex lock;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
34
.history/SubscriptionManager_20221013232519.h
Normal file
34
.history/SubscriptionManager_20221013232519.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef __SubscriptionManager_h__
|
||||||
|
#define __SubscriptionManager_h__
|
||||||
|
|
||||||
|
#include "Command.h"
|
||||||
|
#include "Subscription.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<std::string, Subscription *> subscriptions;
|
||||||
|
std::map<std::string, SubscriptionHandler *> handlers;
|
||||||
|
std::mutex lock;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
37
.history/SubscriptionManager_20221015140418.h
Normal file
37
.history/SubscriptionManager_20221015140418.h
Normal file
@ -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 <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<std::string, Subscription *> subscriptions;
|
||||||
|
std::map<std::string, SubscriptionHandler *> handlers;
|
||||||
|
Subscription *newSubscription;
|
||||||
|
std::mutex lock;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
38
.history/SubscriptionManager_20221015201436.h
Normal file
38
.history/SubscriptionManager_20221015201436.h
Normal file
@ -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 <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<std::string, Subscription *> subscriptions;
|
||||||
|
std::map<std::string, SubscriptionHandler *> handlers;
|
||||||
|
Subscription *newSubscription;
|
||||||
|
std::mutex lock;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
38
.history/SubscriptionManager_20221015201440.h
Normal file
38
.history/SubscriptionManager_20221015201440.h
Normal file
@ -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 <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<std::string, Subscription *> subscriptions;
|
||||||
|
std::map<std::string, SubscriptionHandler *> handlers;
|
||||||
|
Subscription *newSubscription;
|
||||||
|
std::mutex lock;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
38
.history/SubscriptionManager_20221016180248.h
Normal file
38
.history/SubscriptionManager_20221016180248.h
Normal file
@ -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 <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<std::string, Subscription *> subscriptions;
|
||||||
|
std::map<std::string, SubscriptionHandler *> handlers;
|
||||||
|
Subscription *newSubscription;
|
||||||
|
std::mutex lock;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
46
.history/Subscription_20221013190812.h
Normal file
46
.history/Subscription_20221013190812.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#ifndef __Subscription_h__
|
||||||
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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<TCPSession *> subscribers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
75
.history/Subscription_20221013190943.cpp
Normal file
75
.history/Subscription_20221013190943.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
47
.history/Subscription_20221013204658.h
Normal file
47
.history/Subscription_20221013204658.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#ifndef __Subscription_h__
|
||||||
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<TCPSession *> subscribers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
76
.history/Subscription_20221013204725.cpp
Normal file
76
.history/Subscription_20221013204725.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
76
.history/Subscription_20221013204753.cpp
Normal file
76
.history/Subscription_20221013204753.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
76
.history/Subscription_20221013205054.cpp
Normal file
76
.history/Subscription_20221013205054.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
47
.history/Subscription_20221014003150.h
Normal file
47
.history/Subscription_20221014003150.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#ifndef __Subscription_h__
|
||||||
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<TCPSession *> subscribers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
49
.history/Subscription_20221014212452.h
Normal file
49
.history/Subscription_20221014212452.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef __Subscription_h__
|
||||||
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<TCPSession *> subscribers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
47
.history/Subscription_20221014212457.h
Normal file
47
.history/Subscription_20221014212457.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#ifndef __Subscription_h__
|
||||||
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<TCPSession *> subscribers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
48
.history/Subscription_20221014212653.h
Normal file
48
.history/Subscription_20221014212653.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#ifndef __Subscription_h__
|
||||||
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<TCPSession *> subscribers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
76
.history/Subscription_20221014220951.cpp
Normal file
76
.history/Subscription_20221014220951.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
76
.history/Subscription_20221015131611.cpp
Normal file
76
.history/Subscription_20221015131611.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
79
.history/Subscription_20221015142023.cpp
Normal file
79
.history/Subscription_20221015142023.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
79
.history/Subscription_20221015175629.cpp
Normal file
79
.history/Subscription_20221015175629.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
49
.history/Subscription_20221015182553.h
Normal file
49
.history/Subscription_20221015182553.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef __Subscription_h__
|
||||||
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<TCPSession *> subscribers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
49
.history/Subscription_20221015182613.h
Normal file
49
.history/Subscription_20221015182613.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef __Subscription_h__
|
||||||
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<TCPSession *> subscribers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
79
.history/Subscription_20221015182633.cpp
Normal file
79
.history/Subscription_20221015182633.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
79
.history/Subscription_20221015182644.cpp
Normal file
79
.history/Subscription_20221015182644.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
49
.history/Subscription_20221015182655.h
Normal file
49
.history/Subscription_20221015182655.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef __Subscription_h__
|
||||||
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<TCPSession *> subscribers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
79
.history/Subscription_20221015182706.cpp
Normal file
79
.history/Subscription_20221015182706.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
79
.history/Subscription_20221015182712.cpp
Normal file
79
.history/Subscription_20221015182712.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
49
.history/Subscription_20221015203632.h
Normal file
49
.history/Subscription_20221015203632.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef __Subscription_h__
|
||||||
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<TCPSession *> subscribers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
79
.history/Subscription_20221015203643.cpp
Normal file
79
.history/Subscription_20221015203643.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
79
.history/Subscription_20221015203655.cpp
Normal file
79
.history/Subscription_20221015203655.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
79
.history/Subscription_20221015203702.cpp
Normal file
79
.history/Subscription_20221015203702.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
49
.history/Subscription_20221015203734.h
Normal file
49
.history/Subscription_20221015203734.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef __Subscription_h__
|
||||||
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<TCPSession *> subscribers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
79
.history/Subscription_20221015203735.cpp
Normal file
79
.history/Subscription_20221015203735.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
79
.history/Subscription_20221015203805.cpp
Normal file
79
.history/Subscription_20221015203805.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
79
.history/Subscription_20221015204939.cpp
Normal file
79
.history/Subscription_20221015204939.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
79
.history/Subscription_20221016151339.cpp
Normal file
79
.history/Subscription_20221016151339.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
79
.history/Subscription_20221016162014.cpp
Normal file
79
.history/Subscription_20221016162014.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
79
.history/Subscription_20221016172637.cpp
Normal file
79
.history/Subscription_20221016172637.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
79
.history/Subscription_20221016172643.cpp
Normal file
79
.history/Subscription_20221016172643.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
79
.history/Subscription_20221016173312.cpp
Normal file
79
.history/Subscription_20221016173312.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
79
.history/Subscription_20221016173458.cpp
Normal file
79
.history/Subscription_20221016173458.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
79
.history/Subscription_20221016173903.cpp
Normal file
79
.history/Subscription_20221016173903.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
79
.history/Subscription_20221016174406.cpp
Normal file
79
.history/Subscription_20221016174406.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
78
.history/Subscription_20221016174556.cpp
Normal file
78
.history/Subscription_20221016174556.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
78
.history/Subscription_20221016174634.cpp
Normal file
78
.history/Subscription_20221016174634.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
78
.history/Subscription_20221016174652.cpp
Normal file
78
.history/Subscription_20221016174652.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
78
.history/Subscription_20221016174712.cpp
Normal file
78
.history/Subscription_20221016174712.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
49
.history/Subscription_20221016174852.h
Normal file
49
.history/Subscription_20221016174852.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef __Subscription_h__
|
||||||
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<TCPSession *> subscribers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
49
.history/Subscription_20221016174910.h
Normal file
49
.history/Subscription_20221016174910.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef __Subscription_h__
|
||||||
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<TCPSession *> subscribers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
49
.history/Subscription_20221016174913.h
Normal file
49
.history/Subscription_20221016174913.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef __Subscription_h__
|
||||||
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<TCPSession *> subscribers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
78
.history/Subscription_20221016174921.cpp
Normal file
78
.history/Subscription_20221016174921.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
78
.history/Subscription_20221016174923.cpp
Normal file
78
.history/Subscription_20221016174923.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
79
.history/Subscription_20221016175152.cpp
Normal file
79
.history/Subscription_20221016175152.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
80
.history/Subscription_20221016175838.cpp
Normal file
80
.history/Subscription_20221016175838.cpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
80
.history/Subscription_20221016175855.cpp
Normal file
80
.history/Subscription_20221016175855.cpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
80
.history/Subscription_20221016175911.cpp
Normal file
80
.history/Subscription_20221016175911.cpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
80
.history/Subscription_20221016175912.cpp
Normal file
80
.history/Subscription_20221016175912.cpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#include "Subscription.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
Subscription::Subscription(std::string id, std::string mode)
|
||||||
|
: id(id), mode(mode), owner(NULL) {}
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
2
.vscode/c_cpp_properties.json
vendored
2
.vscode/c_cpp_properties.json
vendored
@ -7,7 +7,7 @@
|
|||||||
"${workspaceFolder}/../CoreUtils"
|
"${workspaceFolder}/../CoreUtils"
|
||||||
],
|
],
|
||||||
"defines": [],
|
"defines": [],
|
||||||
"compilerPath": "/usr/bin/g++-9",
|
"compilerPath": "/usr/bin/clang-12",
|
||||||
"cStandard": "c17",
|
"cStandard": "c17",
|
||||||
"cppStandard": "gnu++20",
|
"cppStandard": "gnu++20",
|
||||||
"intelliSenseMode": "windows-gcc-x64",
|
"intelliSenseMode": "windows-gcc-x64",
|
||||||
|
@ -11,20 +11,21 @@ namespace core {
|
|||||||
|
|
||||||
void CommandList::remove(Command &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)
|
if(session.grab != NULL) {
|
||||||
return session.grab->processCommand(request, session);
|
return session.grab->processCommand(request, session);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
if(request.equals(""))
|
if(request.equals(""))
|
||||||
return false;
|
return 0;
|
||||||
request.split(delimiter, 10);
|
request.split(delimiter, depth);
|
||||||
request.reset();
|
request.reset();
|
||||||
try {
|
try {
|
||||||
auto command = commands.at(request[0].str());
|
auto command = commands.at(request[0].str());
|
||||||
return command->processCommand(request, session);
|
return command->processCommand(request, session);
|
||||||
}
|
}
|
||||||
catch(...) {
|
catch(...) {
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -40,12 +41,9 @@ namespace core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int CommandList::processCommand(coreutils::ZString &request, TCPSession &session) {
|
int CommandList::processCommand(coreutils::ZString &request, TCPSession &session) {
|
||||||
// for(Command *command : commands)
|
// for(Command *command : commands)
|
||||||
// session.out << command->getName() << std::endl;
|
// session.out << command->getName() << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ namespace core {
|
|||||||
/// then control is given to the process handler holding the grab on the input.
|
/// 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
|
/// Use grabInput() within a Command object to force the requesting handler to receive
|
||||||
|
@ -10,6 +10,8 @@ namespace core {
|
|||||||
|
|
||||||
void ConsoleSession::protocol(coreutils::ZString &data) {
|
void ConsoleSession::protocol(coreutils::ZString &data) {
|
||||||
|
|
||||||
|
coreutils::Log(coreutils::LOG_DEBUG_1) << data;
|
||||||
|
|
||||||
coreutils::ZString blank("");
|
coreutils::ZString blank("");
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
|
30
EPoll.cpp
30
EPoll.cpp
@ -67,16 +67,6 @@ namespace core {
|
|||||||
return terminateThreads;
|
return terminateThreads;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EPoll::registerSocket(Socket *socket) {
|
|
||||||
enableSocket(socket);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool EPoll::unregisterSocket(Socket *socket) {
|
|
||||||
disableSocket(socket);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int EPoll::getDescriptor() {
|
int EPoll::getDescriptor() {
|
||||||
return epfd;
|
return epfd;
|
||||||
}
|
}
|
||||||
@ -91,24 +81,4 @@ namespace core {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EPoll::enableSocket(Socket *socket) {
|
|
||||||
struct epoll_event event;
|
|
||||||
event.data.ptr = socket;
|
|
||||||
event.events = EPOLLIN | EPOLLONESHOT | EPOLLRDHUP | EPOLLET;
|
|
||||||
epoll_ctl(epfd, EPOLL_CTL_ADD, socket->getDescriptor(), &event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EPoll::disableSocket(Socket *socket) {
|
|
||||||
epoll_ctl(epfd, EPOLL_CTL_DEL, socket->getDescriptor(), NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EPoll::resetSocket(Socket *socket) {
|
|
||||||
struct epoll_event event;
|
|
||||||
event.data.ptr = socket;
|
|
||||||
event.events = EPOLLIN | EPOLLONESHOT | EPOLLRDHUP | EPOLLET;
|
|
||||||
if(socket->needsToWrite())
|
|
||||||
event.events |= EPOLLWRNORM;
|
|
||||||
epoll_ctl(epfd, EPOLL_CTL_MOD, socket->getDescriptor(), &event);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
23
EPoll.h
23
EPoll.h
@ -32,6 +32,8 @@ namespace core {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
volatile long long eventId = 0;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// The constructor for the BMAEPoll object.
|
/// The constructor for the BMAEPoll object.
|
||||||
///
|
///
|
||||||
@ -68,23 +70,6 @@ namespace core {
|
|||||||
|
|
||||||
bool isStopping(); ///< Returns a true if the stop command has been requested.
|
bool isStopping(); ///< Returns a true if the stop command has been requested.
|
||||||
|
|
||||||
///
|
|
||||||
/// Use registerSocket to add a new socket to the ePoll event watch list. This enables
|
|
||||||
/// a new BMASocket object to receive events when data is received as well as to write
|
|
||||||
/// data output to the socket.
|
|
||||||
///
|
|
||||||
/// @param socket a pointer to a BMASocket object.
|
|
||||||
/// @return a booelean that indicates the socket was registered or not.
|
|
||||||
///
|
|
||||||
|
|
||||||
bool registerSocket(Socket *socket); ///< Register a BMASocket for monitoring by BMAEPoll.
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Use this method to remove a socket from receiving events from the epoll system.
|
|
||||||
///
|
|
||||||
|
|
||||||
bool unregisterSocket(Socket *socket); ///< Unregister a BMASocket from monitoring by BMAEPoll.
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Use this method to obtain the current descriptor socket number for the epoll function call.
|
/// Use this method to obtain the current descriptor socket number for the epoll function call.
|
||||||
///
|
///
|
||||||
@ -112,16 +97,12 @@ namespace core {
|
|||||||
|
|
||||||
int processCommand(coreutils::ZString &request, TCPSession &session) override; ///<Output the threads array to the console.
|
int processCommand(coreutils::ZString &request, TCPSession &session) override; ///<Output the threads array to the console.
|
||||||
|
|
||||||
void resetSocket(Socket *socket);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int epfd;
|
int epfd;
|
||||||
int numberOfThreads;
|
int numberOfThreads;
|
||||||
std::vector<Thread> threads;
|
std::vector<Thread> threads;
|
||||||
volatile bool terminateThreads;
|
volatile bool terminateThreads;
|
||||||
void enableSocket(Socket *socket);
|
|
||||||
void disableSocket(Socket *socket);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
13
INotify.cpp
13
INotify.cpp
@ -1,5 +1,6 @@
|
|||||||
#include "INotify.h"
|
#include "INotify.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ namespace core {
|
|||||||
shutdown();
|
shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
int INotify::addWatch(std::string watch) {
|
int INotify::addWatch(coreutils::ZString &watch) {
|
||||||
return inotify_add_watch(getDescriptor(), watch.c_str(), IN_ALL_EVENTS);
|
return inotify_add_watch(getDescriptor(), watch.c_str(), IN_ALL_EVENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,12 +23,14 @@ namespace core {
|
|||||||
void INotify::onDataReceived(coreutils::ZString &buffer) {
|
void INotify::onDataReceived(coreutils::ZString &buffer) {
|
||||||
const struct inotify_event *event;
|
const struct inotify_event *event;
|
||||||
char *ptr;
|
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) {
|
ptr += sizeof(struct inotify_event) + event->len) {
|
||||||
event = (const struct inotify_event *) ptr;
|
event = (const struct inotify_event *) ptr;
|
||||||
|
coreutils::ZString name(event->name);
|
||||||
|
|
||||||
if(event->mask & IN_ACCESS)
|
if(event->mask & IN_ACCESS)
|
||||||
inAccess(std::string(event->name));
|
inAccess(name);
|
||||||
if(event->mask & IN_ATTRIB)
|
if(event->mask & IN_ATTRIB)
|
||||||
inAttrib(std::string(event->name));
|
inAttrib(std::string(event->name));
|
||||||
if(event->mask & IN_CLOSE_WRITE)
|
if(event->mask & IN_CLOSE_WRITE)
|
||||||
@ -35,7 +38,7 @@ namespace core {
|
|||||||
if(event->mask & IN_CLOSE_NOWRITE)
|
if(event->mask & IN_CLOSE_NOWRITE)
|
||||||
inCloseNoWrite(std::string(event->name));
|
inCloseNoWrite(std::string(event->name));
|
||||||
if(event->mask & IN_CREATE)
|
if(event->mask & IN_CREATE)
|
||||||
inCreate(std::string(event->name));
|
inCreate(name);
|
||||||
if(event->mask & IN_DELETE)
|
if(event->mask & IN_DELETE)
|
||||||
inDelete(std::string(event->name));
|
inDelete(std::string(event->name));
|
||||||
if(event->mask & IN_DELETE_SELF)
|
if(event->mask & IN_DELETE_SELF)
|
||||||
@ -50,9 +53,7 @@ namespace core {
|
|||||||
inMovedTo(std::string(event->name));
|
inMovedTo(std::string(event->name));
|
||||||
if(event->mask & IN_OPEN)
|
if(event->mask & IN_OPEN)
|
||||||
inOpen(std::string(event->name));
|
inOpen(std::string(event->name));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,16 +12,16 @@ namespace core {
|
|||||||
INotify(EPoll &ePoll);
|
INotify(EPoll &ePoll);
|
||||||
~INotify();
|
~INotify();
|
||||||
|
|
||||||
int addWatch(std::string watch);
|
int addWatch(coreutils::ZString &watch);
|
||||||
void removeWatch(int wd);
|
void removeWatch(int wd);
|
||||||
|
|
||||||
void onDataReceived(coreutils::ZString &data) override;
|
void onDataReceived(coreutils::ZString &data) override;
|
||||||
|
|
||||||
virtual void inAccess(std::string name) {}
|
virtual void inAccess(coreutils::ZString name) {}
|
||||||
virtual void inAttrib(std::string name) {}
|
virtual void inAttrib(std::string name) {}
|
||||||
virtual void inCloseWrite(std::string name) {}
|
virtual void inCloseWrite(std::string name) {}
|
||||||
virtual void inCloseNoWrite(std::string name) {}
|
virtual void inCloseNoWrite(std::string name) {}
|
||||||
virtual void inCreate(std::string name) {}
|
virtual void inCreate(coreutils::ZString &name) {}
|
||||||
virtual void inDelete(std::string name) {}
|
virtual void inDelete(std::string name) {}
|
||||||
virtual void inDeleteSelf(std::string name) {}
|
virtual void inDeleteSelf(std::string name) {}
|
||||||
virtual void inModify(std::string name) {}
|
virtual void inModify(std::string name) {}
|
||||||
|
@ -2,18 +2,21 @@
|
|||||||
#define __SessionFilter_h__
|
#define __SessionFilter_h__
|
||||||
|
|
||||||
//#include "Session.h"
|
//#include "Session.h"
|
||||||
|
#include "Object.h"
|
||||||
|
|
||||||
namespace core {
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
class TCPSession;
|
class TCPSession;
|
||||||
|
|
||||||
class SessionFilter : public Object {
|
class SessionFilter : public Object
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool test(TCPSession &session) {
|
virtual bool test(TCPSession &session)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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:
|
|
120
Socket.cpp
120
Socket.cpp
@ -1,10 +1,11 @@
|
|||||||
#include "EPoll.h"
|
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
|
#include "EPoll.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "ZString.h"
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
|
||||||
namespace core {
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
void sigpipe_handler(int unused) {}
|
void sigpipe_handler(int unused) {}
|
||||||
|
|
||||||
@ -15,40 +16,46 @@ namespace core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Socket::~Socket() {
|
Socket::~Socket() {
|
||||||
|
shutDown = true;
|
||||||
|
onUnregister();
|
||||||
|
disableSocket();
|
||||||
|
coreutils::Log(coreutils::LOG_DEBUG_4) << "Free on socket " << descriptor;
|
||||||
free(buffer);
|
free(buffer);
|
||||||
if(descriptor == -1)
|
if(descriptor == -1)
|
||||||
return;
|
return;
|
||||||
onUnregister();
|
|
||||||
ePoll.unregisterSocket(this);
|
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_3) << "Socket destroyed for socket " << descriptor << ".";
|
|
||||||
close(descriptor);
|
close(descriptor);
|
||||||
|
coreutils::Log(coreutils::LOG_DEBUG_1) << text << " has ended (" << descriptor << ").";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::setDescriptor(int descriptor) {
|
void Socket::setDescriptor(int descriptor)
|
||||||
if((descriptor == -1) && (errno == 24)) {
|
{
|
||||||
|
if ((descriptor == -1) && (errno == 24))
|
||||||
|
{
|
||||||
shutdown("Too many files open");
|
shutdown("Too many files open");
|
||||||
throw coreutils::Exception("Too many files open. Refusing connection.");
|
throw coreutils::Exception("Too many files open. Refusing connection.");
|
||||||
}
|
}
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_3) << "Descriptor set to " << descriptor << " for Socket.";
|
coreutils::Log(coreutils::LOG_DEBUG_1) << text << " has started (" << descriptor << ").";
|
||||||
if(descriptor < 3)
|
if(descriptor < 3)
|
||||||
throw coreutils::Exception("Descriptor out of range", __FILE__, __LINE__);
|
throw coreutils::Exception("Descriptor out of range", __FILE__, __LINE__);
|
||||||
this->descriptor = descriptor;
|
this->descriptor = descriptor;
|
||||||
onRegister();
|
onRegister();
|
||||||
ePoll.registerSocket(this);
|
enableSocket();
|
||||||
onRegistered();
|
onRegistered();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Socket::getDescriptor() {
|
int Socket::getDescriptor()
|
||||||
|
{
|
||||||
return descriptor;
|
return descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::setBufferSize(int length) {
|
void Socket::setBufferSize(int length)
|
||||||
|
{
|
||||||
this->length = length;
|
this->length = length;
|
||||||
buffer = (char *)realloc(buffer, length);
|
buffer = (char *)realloc(buffer, length);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Socket::getBufferSize() {
|
int Socket::getBufferSize()
|
||||||
|
{
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,54 +67,66 @@ namespace core {
|
|||||||
|
|
||||||
void Socket::onUnregistered() {}
|
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_1) << "Event process beginning for socket " << getDescriptor();
|
||||||
|
if(inHandler)
|
||||||
|
// coreutils::Log(coreutils::LOG_DEBUG_2) << "inHandler was already true.";
|
||||||
inHandler = true;
|
inHandler = true;
|
||||||
if(event.events & EPOLLRDHUP) {
|
if(event.events & EPOLLRDHUP) {
|
||||||
|
// coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLRDHUP";
|
||||||
readHangup = true;
|
readHangup = true;
|
||||||
shutdown("hangup received");
|
shutdown("hangup received");
|
||||||
}
|
}
|
||||||
else if(event.events & EPOLLIN) {
|
if(event.events & EPOLLIN) {
|
||||||
|
// coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLIN";
|
||||||
coreutils::ZString zbuffer(buffer, length);
|
coreutils::ZString zbuffer(buffer, length);
|
||||||
|
lock.lock();
|
||||||
receiveData(zbuffer);
|
receiveData(zbuffer);
|
||||||
|
if(!shutDown) {
|
||||||
|
inHandler = false;
|
||||||
|
lock.unlock();
|
||||||
|
resetSocket();
|
||||||
}
|
}
|
||||||
else if(event.events & EPOLLWRNORM) {
|
}
|
||||||
|
if(event.events & EPOLLWRNORM) {
|
||||||
|
// coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLWRNORM";
|
||||||
writeSocket();
|
writeSocket();
|
||||||
}
|
inHandler = false;
|
||||||
else if(event.events & EPOLLHUP) {
|
resetSocket();
|
||||||
shutdown();
|
|
||||||
}
|
}
|
||||||
inHandler = false;
|
inHandler = false;
|
||||||
|
// coreutils::Log(coreutils::LOG_DEBUG_1) << "Event process ending for socket " << getDescriptor();
|
||||||
return !shutDown;
|
return !shutDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::onDataReceived(std::string data) {
|
void Socket::onDataReceived(std::string data)
|
||||||
|
{
|
||||||
throw coreutils::Exception("Need to override onDataReceived.", __FILE__, __LINE__, -1);
|
throw coreutils::Exception("Need to override onDataReceived.", __FILE__, __LINE__, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::onDataReceived(coreutils::ZString &data) {
|
void Socket::onDataReceived(coreutils::ZString &data)
|
||||||
|
{
|
||||||
onDataReceived(std::string(data.getData(), data.getLength()));
|
onDataReceived(std::string(data.getData(), data.getLength()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::receiveData(coreutils::ZString &buffer) {
|
void Socket::receiveData(coreutils::ZString &buffer) {
|
||||||
|
|
||||||
coreutils::ZString blank("");
|
coreutils::ZString blank("");
|
||||||
|
|
||||||
if(buffer.getLength() <= 0)
|
if(buffer.getLength() <= 0)
|
||||||
throw coreutils::Exception("Request to receive data with a zero buffer length.", __FILE__, __LINE__, -1);
|
throw coreutils::Exception("Request to receive data with a zero buffer length.", __FILE__, __LINE__, -1);
|
||||||
|
|
||||||
int len;
|
int len;
|
||||||
int error = -1;
|
int error = -1;
|
||||||
|
|
||||||
if((len = ::read(getDescriptor(), buffer.getData(), buffer.getLength())) >= 0) {
|
if((len = ::read(getDescriptor(), buffer.getData(), buffer.getLength())) >= 0) {
|
||||||
coreutils::ZString zbuffer(buffer.getData(), len);
|
coreutils::ZString zbuffer(buffer.getData(), len);
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_1) << zbuffer;
|
// coreutils::Log(coreutils::LOG_DEBUG_1) << zbuffer;
|
||||||
onDataReceived(zbuffer);
|
onDataReceived(zbuffer);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
|
|
||||||
error = errno;
|
error = errno;
|
||||||
|
|
||||||
switch (error) {
|
switch (error)
|
||||||
|
{
|
||||||
|
|
||||||
// When a listening socket receives a connection
|
// When a listening socket receives a connection
|
||||||
// request we get one of these.
|
// request we get one of these.
|
||||||
@ -126,36 +145,63 @@ namespace core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Socket::writeSocket() {
|
void Socket::writeSocket() {
|
||||||
if(fifo.size() > 0) {
|
|
||||||
outlock.lock();
|
outlock.lock();
|
||||||
|
// coreutils::Log(coreutils::LOG_DEBUG_3) << "writing data to socket " << getDescriptor();
|
||||||
|
if(fifo.size() > 0) {
|
||||||
if(!shutDown)
|
if(!shutDown)
|
||||||
::write(descriptor, fifo.front().c_str(), fifo.front().length());
|
int rc = ::write(descriptor, fifo.front().c_str(), fifo.front().length());
|
||||||
fifo.pop();
|
fifo.pop();
|
||||||
outlock.unlock();
|
|
||||||
}
|
}
|
||||||
|
outlock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Socket::write(std::string data) {
|
int Socket::write(std::string data) {
|
||||||
outlock.lock();
|
outlock.lock();
|
||||||
fifo.emplace(data);
|
fifo.emplace(data);
|
||||||
outlock.unlock();
|
outlock.unlock();
|
||||||
if(!inHandler)
|
if(lock.try_lock()) {
|
||||||
ePoll.resetSocket(this);
|
resetSocket();
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::output(std::stringstream &out) {
|
void Socket::output(std::stringstream &out)
|
||||||
|
{
|
||||||
out << "|" << descriptor << "|";
|
out << "|" << descriptor << "|";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::needsToWrite() {
|
bool Socket::needsToWrite()
|
||||||
|
{
|
||||||
return fifo.size() > 0;
|
return fifo.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::shutdown(std::string text) {
|
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;
|
shutDown = true;
|
||||||
reset = false;
|
reset = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Socket::enableSocket() {
|
||||||
|
struct epoll_event event;
|
||||||
|
event.data.ptr = this;
|
||||||
|
event.events = EPOLLIN | EPOLLRDHUP | EPOLLONESHOT | EPOLLET;
|
||||||
|
epoll_ctl(ePoll.getDescriptor(), EPOLL_CTL_ADD, getDescriptor(), &event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::disableSocket() {
|
||||||
|
epoll_ctl(ePoll.getDescriptor(), EPOLL_CTL_DEL, getDescriptor(), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::resetSocket() {
|
||||||
|
struct epoll_event event;
|
||||||
|
event.data.ptr = this;
|
||||||
|
event.events = EPOLLIN | EPOLLRDHUP | EPOLLONESHOT | EPOLLET;
|
||||||
|
if(fifo.size() > 0)
|
||||||
|
event.events |= EPOLLWRNORM;
|
||||||
|
if(!shutDown)
|
||||||
|
epoll_ctl(ePoll.getDescriptor(), EPOLL_CTL_MOD, getDescriptor(), &event);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
22
Socket.h
22
Socket.h
@ -80,7 +80,7 @@ namespace core {
|
|||||||
/// The return value of true will enable the socket on ePoll to receive more events.
|
/// The return value of true will enable the socket on ePoll to receive more events.
|
||||||
///
|
///
|
||||||
|
|
||||||
bool eventReceived(struct epoll_event event); ///< Parse epoll event and call specified callbacks.
|
bool eventReceived(struct epoll_event event, long long eventId); ///< Parse epoll event and call specified callbacks.
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Write data to the socket.
|
/// Write data to the socket.
|
||||||
@ -104,7 +104,6 @@ namespace core {
|
|||||||
virtual void onUnregister();
|
virtual void onUnregister();
|
||||||
|
|
||||||
///
|
///
|
||||||
/// The onUnregistered method is called whenever the socket is unregistered with
|
|
||||||
/// ePoll and socket communcation events will be stopped. The default method will
|
/// ePoll and socket communcation events will be stopped. The default method will
|
||||||
/// close the socket and clean up the connection. If this is overridden by an
|
/// close the socket and clean up the connection. If this is overridden by an
|
||||||
/// extended object then the object should call this method to clean the socket up.
|
/// extended object then the object should call this method to clean the socket up.
|
||||||
@ -116,12 +115,15 @@ namespace core {
|
|||||||
|
|
||||||
bool reset = false;
|
bool reset = false;
|
||||||
|
|
||||||
|
volatile bool shutDown = false;
|
||||||
|
|
||||||
|
void enableSocket();
|
||||||
|
void disableSocket();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
EPoll &ePoll; // The EPoll control object.
|
EPoll &ePoll; // The EPoll control object.
|
||||||
|
|
||||||
bool shutDown = false;
|
|
||||||
|
|
||||||
void setBufferSize(int length);
|
void setBufferSize(int length);
|
||||||
|
|
||||||
int getBufferSize();
|
int getBufferSize();
|
||||||
@ -167,11 +169,9 @@ namespace core {
|
|||||||
|
|
||||||
std::string text;
|
std::string text;
|
||||||
int descriptor = -1;
|
int descriptor = -1;
|
||||||
// std::mutex lock;
|
|
||||||
std::mutex outlock;
|
std::mutex outlock;
|
||||||
bool readHangup = false;
|
bool readHangup = false;
|
||||||
bool inHandler = false;
|
volatile bool inHandler = false;
|
||||||
// struct epoll_event event; // Event selection construction structure.
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
// the writeSocket is called when epoll has received a write request for a socket.
|
// the writeSocket is called when epoll has received a write request for a socket.
|
||||||
@ -190,12 +190,12 @@ namespace core {
|
|||||||
char *buffer; // This is a pointer to the managed buffer space.
|
char *buffer; // This is a pointer to the managed buffer space.
|
||||||
int length; // This is the length of the buffer.
|
int length; // This is the length of the buffer.
|
||||||
|
|
||||||
// const char * const begin_;
|
|
||||||
// const char * const end_;
|
|
||||||
// const char * const current_;
|
|
||||||
|
|
||||||
std::queue<std::string> fifo;
|
std::queue<std::string> fifo;
|
||||||
|
|
||||||
|
void resetSocket();
|
||||||
|
|
||||||
|
std::mutex lock;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,42 @@
|
|||||||
#include "Subscription.h"
|
#include "Subscription.h"
|
||||||
#include "TCPSession.h"
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace core
|
namespace core {
|
||||||
{
|
|
||||||
|
|
||||||
Subscription::Subscription(std::string id, std::string mode)
|
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)
|
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()
|
Subscription::Subscription(std::string id, TCPSession &session, std::string mode, SubscriptionHandler *handler)
|
||||||
{
|
: id(id), mode(mode), owner(&session), handler(handler) {
|
||||||
|
// coreutils::Log(coreutils::LOG_DEBUG_3) << "Subscription '" << id << "' with handler '" << handler->name << "'";
|
||||||
|
}
|
||||||
|
|
||||||
|
Subscription::~Subscription() {
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << "cancel:" << id << std::endl;
|
out << "cancel:" << id << std::endl;
|
||||||
for (auto subscriber : subscribers)
|
for (auto subscriber : subscribers) {
|
||||||
{
|
|
||||||
subscriber->write(out.str());
|
subscriber->write(out.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Subscription::subscribe(TCPSession &session)
|
int Subscription::subscribe(TCPSession &session) {
|
||||||
{
|
if (handler)
|
||||||
|
handler->onSubscribe(session, this);
|
||||||
|
else
|
||||||
onSubscribe(session);
|
onSubscribe(session);
|
||||||
|
|
||||||
subscribers.push_back(&session);
|
subscribers.push_back(&session);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Subscription::unsubscribe(TCPSession &session)
|
int Subscription::unsubscribe(TCPSession &session) {
|
||||||
{
|
for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) {
|
||||||
for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber)
|
if (*subscriber == &session) {
|
||||||
{
|
|
||||||
if (*subscriber == &session)
|
|
||||||
{
|
|
||||||
subscribers.erase(subscriber++);
|
subscribers.erase(subscriber++);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -42,27 +44,38 @@ namespace core
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session)
|
int Subscription::process(coreutils::ZString &request, std::stringstream &out, TCPSession &session) {
|
||||||
{
|
if (handler)
|
||||||
|
handler->process(request, out, session, this);
|
||||||
|
else
|
||||||
out << "event:" << request[1] << ":" << request[2] << std::endl;
|
out << "event:" << request[1] << ":" << request[2] << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Subscription::event(std::stringstream &out)
|
int Subscription::event(std::stringstream &out) {
|
||||||
{
|
|
||||||
for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber)
|
for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber)
|
||||||
(*subscriber)->write(out.str());
|
(*subscriber)->write(out.str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Subscription::ifSubscriber(TCPSession &session)
|
bool Subscription::ifSubscriber(TCPSession &session) {
|
||||||
{
|
|
||||||
return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end());
|
return (std::find(subscribers.begin(), subscribers.end(), &session) != subscribers.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
int Subscription::onSubscribe(TCPSession &session)
|
int Subscription::onSubscribe(TCPSession &session) {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Subscription::subInvite(TCPSession &session) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Subscription::sendToAll(std::stringstream &data, TCPSession &sender) {
|
||||||
|
for (auto session : subscribers)
|
||||||
|
if (session != &sender)
|
||||||
|
session->write(data.str());
|
||||||
|
data.str("");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,23 @@
|
|||||||
#ifndef __Subscription_h__
|
#ifndef __Subscription_h__
|
||||||
#define __Subscription_h__
|
#define __Subscription_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "SessionFilter.h"
|
||||||
#include "ZString.h"
|
#include "ZString.h"
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace core
|
namespace core
|
||||||
{
|
{
|
||||||
|
|
||||||
class TCPSession;
|
class TCPSession;
|
||||||
|
|
||||||
class Subscription
|
class Subscription {
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Subscription(std::string id, std::string mode = "*AUTHOR");
|
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();
|
virtual ~Subscription();
|
||||||
|
|
||||||
int subscribe(TCPSession &session);
|
int subscribe(TCPSession &session);
|
||||||
@ -29,12 +31,17 @@ namespace core
|
|||||||
|
|
||||||
bool ifSubscriber(TCPSession &session);
|
bool ifSubscriber(TCPSession &session);
|
||||||
|
|
||||||
// int processCommand(coreutils::ZString &request, TCPSession &session) override;
|
bool subInvite(TCPSession &session);
|
||||||
|
|
||||||
|
void sendToAll(std::stringstream &data, TCPSession &sender);
|
||||||
|
void sendToAll(std::stringstream &data, TCPSession &sender, SessionFilter filter);
|
||||||
|
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string mode;
|
std::string mode;
|
||||||
TCPSession *owner;
|
TCPSession *owner;
|
||||||
|
|
||||||
|
SubscriptionHandler *handler;
|
||||||
|
|
||||||
std::vector<TCPSession *> subscribers;
|
std::vector<TCPSession *> subscribers;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
22
SubscriptionHandler.h
Normal file
22
SubscriptionHandler.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef __SubscriptionHandler_h__
|
||||||
|
#define __SubscriptionHandler_h__
|
||||||
|
|
||||||
|
#include "ZString.h"
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
class Subscription;
|
||||||
|
class TCPSession;
|
||||||
|
|
||||||
|
class SubscriptionHandler {
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session, Subscription *subscription) { return 0; }
|
||||||
|
virtual int onSubscribe(TCPSession &session, Subscription *subscription) { return 0; }
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
21
SubscriptionHandlerFactory.h
Normal file
21
SubscriptionHandlerFactory.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef __SubscriptionHandlerFactory_h__
|
||||||
|
#define __SubscriptionHandlerFactory_h__
|
||||||
|
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class SubscriptionHandlerFactory {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual SubscriptionHandler * getSubscriptionHandler(std::string name) {
|
||||||
|
return new SubscriptionHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,11 +1,12 @@
|
|||||||
#include "SubscriptionManager.h"
|
#include "SubscriptionManager.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "Subscription.h"
|
||||||
|
#include "TCPServer.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include "SubscriptionHandlerFactory.h"
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
SubscriptionManager::SubscriptionManager() {}
|
|
||||||
|
|
||||||
int SubscriptionManager::add(Subscription &subscription) {
|
int SubscriptionManager::add(Subscription &subscription) {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
subscriptions.insert(std::make_pair(subscription.id, &subscription));
|
subscriptions.insert(std::make_pair(subscription.id, &subscription));
|
||||||
@ -19,19 +20,23 @@ namespace core {
|
|||||||
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
std::string temp = "";
|
std::string temp = "";
|
||||||
for(auto [key, subscription] : subscriptions) {
|
for (auto [key, subscription] : subscriptions)
|
||||||
if(temp != "") {
|
{
|
||||||
|
if (temp != "")
|
||||||
|
{
|
||||||
subscriptions.erase(temp);
|
subscriptions.erase(temp);
|
||||||
temp = "";
|
temp = "";
|
||||||
}
|
}
|
||||||
countSubscribed += subscription->unsubscribe(session);
|
countSubscribed += subscription->unsubscribe(session);
|
||||||
if(subscription->owner == &session) {
|
if (subscription->owner == &session)
|
||||||
|
{
|
||||||
temp = key;
|
temp = key;
|
||||||
delete subscription;
|
delete subscription;
|
||||||
++countPublished;
|
++countPublished;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(temp != "") {
|
if (temp != "")
|
||||||
|
{
|
||||||
subscriptions.erase(temp);
|
subscriptions.erase(temp);
|
||||||
temp = "";
|
temp = "";
|
||||||
}
|
}
|
||||||
@ -42,43 +47,57 @@ namespace core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) {
|
int SubscriptionManager::processCommand(coreutils::ZString &request, TCPSession &session) {
|
||||||
if(request[0].equals("publish")) {
|
if (request[0].equals("publish")) {
|
||||||
Subscription *newSubscription = new Subscription(request[1].str(), session, request[2].str());
|
SubscriptionHandler *handler = NULL;
|
||||||
|
if(request.getList().size() > 3) {
|
||||||
|
factory->getSubscriptionHandler(request[3].str());
|
||||||
|
}
|
||||||
|
newSubscription = new Subscription(request[1].str(), session, request[2].str(), handler);
|
||||||
subscriptions.insert(std::make_pair(request[1].str(), newSubscription));
|
subscriptions.insert(std::make_pair(request[1].str(), newSubscription));
|
||||||
|
newSubscription->owner = &session;
|
||||||
return 1;
|
return 1;
|
||||||
} else if(request[0].equals("catalog")) {
|
} else if (request[0].equals("catalog")) {
|
||||||
session.out << ":catalog:";
|
session.out << ":catalog:";
|
||||||
for(auto const& [key, subscription] : subscriptions) {
|
for (auto const &[key, subscription] : subscriptions) {
|
||||||
session.out << subscription->id << ";";
|
session.out << subscription->id << ";";
|
||||||
}
|
}
|
||||||
session.out << std::endl;
|
session.out << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
|
} else if (request[0].equals("invite")) {
|
||||||
|
std::stringstream out;
|
||||||
|
coreutils::Log(coreutils::LOG_DEBUG_1) << request[2];
|
||||||
|
std::string invitee = request[2].str();
|
||||||
|
TCPSession *tempSession = session.server.getSessionByAlias(&invitee);
|
||||||
|
std::stringstream temp;
|
||||||
|
temp << "invite:" << request[1] << ":" << *(std::string *)session.alias;
|
||||||
|
tempSession->write(temp.str());
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto subscription = subscriptions[request[1].str()];
|
auto subscription = subscriptions[request[1].str()];
|
||||||
|
|
||||||
if(request[1].equals(subscription->id)) {
|
if (request[1].equals(subscription->id)) {
|
||||||
if(request[0].equals("unpublish")) {
|
if (request[0].equals("unpublish")) {
|
||||||
subscriptions.erase(request[1].str());
|
subscriptions.erase(request[1].str());
|
||||||
} else if(request[0].equals("subscribe")) {
|
} else if (request[0].equals("subscribe")) {
|
||||||
subscription->subscribe(session);
|
subscription->subscribe(session);
|
||||||
return 1;
|
return 1;
|
||||||
} else if(request[0].equals("unsubscribe")) {
|
} else if (request[0].equals("unsubscribe")) {
|
||||||
subscription->unsubscribe(session);
|
subscription->unsubscribe(session);
|
||||||
return 1;
|
return 1;
|
||||||
} else if(request[0].equals("event")) {
|
} else if (request[0].equals("event")) {
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
subscription->process(request, out, session);
|
subscription->process(request, out, session);
|
||||||
if(subscription->mode == "*ANYONE") {
|
if (subscription->mode == "*ANYONE") {
|
||||||
subscription->event(out);
|
subscription->event(out);
|
||||||
return 1;
|
return 1;
|
||||||
} else if(subscription->mode == "*SUBSCRIBERS") {
|
} else if (subscription->mode == "*SUBSCRIBERS") {
|
||||||
if(subscription->ifSubscriber(session)) {
|
if (subscription->ifSubscriber(session)) {
|
||||||
subscription->event(out);
|
subscription->event(out);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else if(subscription->mode == "*AUTHOR") {
|
} else if (subscription->mode == "*AUTHOR") {
|
||||||
if(subscription->owner == &session) {
|
if (subscription->owner == &session) {
|
||||||
subscription->event(out);
|
subscription->event(out);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -88,5 +107,4 @@ namespace core {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,35 @@
|
|||||||
#ifndef __SubscriptionManager_h__
|
#ifndef __SubscriptionManager_h__
|
||||||
#define __SubscriptionManager_h__
|
#define __SubscriptionManager_h__
|
||||||
|
|
||||||
#include "TCPSession.h"
|
|
||||||
#include "Subscription.h"
|
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
|
#include "Subscription.h"
|
||||||
|
#include "SubscriptionHandler.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
#include "ZString.h"
|
#include "ZString.h"
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
|
class SubscriptionHandlerFactory;
|
||||||
|
|
||||||
class SubscriptionManager : public Command {
|
class SubscriptionManager : public Command {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SubscriptionManager();
|
|
||||||
|
|
||||||
int add(Subscription &subscription);
|
int add(Subscription &subscription);
|
||||||
|
|
||||||
int removeSessionSubscriptions(TCPSession &session);
|
int removeSessionSubscriptions(TCPSession &session);
|
||||||
|
|
||||||
int processCommand(coreutils::ZString &request, TCPSession &session) override;
|
int processCommand(coreutils::ZString &request, TCPSession &session) override;
|
||||||
|
|
||||||
private:
|
SubscriptionHandlerFactory *factory = NULL;
|
||||||
std::map<std::string, Subscription *> subscriptions;
|
|
||||||
std::mutex lock;
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
Subscription *subscription;
|
||||||
|
std::map<std::string, Subscription *> subscriptions;
|
||||||
|
Subscription *newSubscription;
|
||||||
|
std::mutex lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
#include "TCPServer.h"
|
#include "TCPServer.h"
|
||||||
#include "EPoll.h"
|
#include "EPoll.h"
|
||||||
#include "TCPSession.h"
|
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
|
||||||
namespace core {
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter, int depth, std::string text)
|
TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter, int depth, std::string text)
|
||||||
: TCPSocket(ePoll, text), commands(delimiter, depth) {
|
: TCPSocket(ePoll, text), commands(delimiter, depth) {
|
||||||
@ -15,20 +16,21 @@ namespace core {
|
|||||||
commands.add(subscriptions, "unsubscribe");
|
commands.add(subscriptions, "unsubscribe");
|
||||||
commands.add(subscriptions, "catalog");
|
commands.add(subscriptions, "catalog");
|
||||||
commands.add(subscriptions, "event");
|
commands.add(subscriptions, "event");
|
||||||
|
commands.add(subscriptions, "invite");
|
||||||
|
|
||||||
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
|
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
|
||||||
int yes = 1;
|
int yes = 1;
|
||||||
setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
|
setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
|
||||||
|
|
||||||
if(bind(getDescriptor(), address.getPointer(), address.addressLength) < 0)
|
if (bind(getDescriptor(), address.getPointer(), address.addressLength) < 0)
|
||||||
throw coreutils::Exception("Error on bind to socket: " + std::to_string(errno));
|
throw coreutils::Exception("Error on bind to socket: " + std::to_string(errno));
|
||||||
|
|
||||||
if(listen(getDescriptor(), 20) < 0)
|
if (listen(getDescriptor(), 20) < 0)
|
||||||
throw coreutils::Exception("Error on listen to socket");
|
throw coreutils::Exception("Error on listen to socket");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TCPServer::~TCPServer() {
|
TCPServer::~TCPServer()
|
||||||
|
{
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "Closing server socket " << getDescriptor() << ".";
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "Closing server socket " << getDescriptor() << ".";
|
||||||
close(getDescriptor());
|
close(getDescriptor());
|
||||||
}
|
}
|
||||||
@ -36,7 +38,7 @@ namespace core {
|
|||||||
void TCPServer::onDataReceived(std::string data) {
|
void TCPServer::onDataReceived(std::string data) {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
TCPSession *session = accept();
|
TCPSession *session = accept();
|
||||||
if(session)
|
if (session)
|
||||||
sessions.push_back(session);
|
sessions.push_back(session);
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
@ -59,10 +61,12 @@ namespace core {
|
|||||||
// }
|
// }
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
catch(coreutils::Exception e) {
|
catch (coreutils::Exception e)
|
||||||
|
{
|
||||||
coreutils::Log(coreutils::LOG_EXCEPT) << "Major error on session initialization. Error is '" << e.text << "'.";
|
coreutils::Log(coreutils::LOG_EXCEPT) << "Major error on session initialization. Error is '" << e.text << "'.";
|
||||||
}
|
}
|
||||||
catch(...) {
|
catch (...)
|
||||||
|
{
|
||||||
coreutils::Log(coreutils::LOG_EXCEPT) << "Unnspecified error on session initialization.";
|
coreutils::Log(coreutils::LOG_EXCEPT) << "Unnspecified error on session initialization.";
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -93,7 +97,8 @@ namespace core {
|
|||||||
|
|
||||||
int TCPServer::processCommand(coreutils::ZString &request, TCPSession &session) {
|
int TCPServer::processCommand(coreutils::ZString &request, TCPSession &session) {
|
||||||
int sequence = 0;
|
int sequence = 0;
|
||||||
for(auto *sessionx : sessions) {
|
for (auto *sessionx : sessions)
|
||||||
|
{
|
||||||
session.out << "|" << ++sequence;
|
session.out << "|" << ++sequence;
|
||||||
sessionx->output(session.out);
|
sessionx->output(session.out);
|
||||||
session.out << "|" << std::endl;
|
session.out << "|" << std::endl;
|
||||||
@ -101,25 +106,37 @@ namespace core {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPServer::sendToAll(std::stringstream &data) {
|
void TCPServer::sendToAll(std::stringstream &data)
|
||||||
for(auto session : sessions)
|
{
|
||||||
|
for (auto session : sessions)
|
||||||
session->write(data.str());
|
session->write(data.str());
|
||||||
data.str("");
|
data.str("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender) {
|
void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender)
|
||||||
for(auto session : sessions)
|
{
|
||||||
if(session != &sender)
|
for (auto session : sessions)
|
||||||
|
if (session != &sender)
|
||||||
session->write(data.str());
|
session->write(data.str());
|
||||||
data.str("");
|
data.str("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender, SessionFilter filter) {
|
void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender, SessionFilter filter)
|
||||||
for(auto session : sessions)
|
{
|
||||||
if(filter.test(*session))
|
for (auto session : sessions)
|
||||||
if(session != &sender)
|
if (filter.test(*session))
|
||||||
|
if (session != &sender)
|
||||||
session->write(data.str());
|
session->write(data.str());
|
||||||
data.str("");
|
data.str("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TCPSession *TCPServer::getSessionByAlias(void *alias)
|
||||||
|
{
|
||||||
|
coreutils::Log(coreutils::LOG_DEBUG_1) << alias;
|
||||||
|
for (auto session : sessions)
|
||||||
|
if (session->compareAlias(alias))
|
||||||
|
return session;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
30
TCPServer.h
30
TCPServer.h
@ -1,14 +1,16 @@
|
|||||||
#ifndef __TCPServer_h__
|
#ifndef __TCPServer_h__
|
||||||
#define __TCPServer_h__
|
#define __TCPServer_h__
|
||||||
|
|
||||||
#include "Socket.h"
|
|
||||||
#include "TCPSocket.h"
|
|
||||||
#include "IPAddressList.h"
|
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
#include "CommandList.h"
|
#include "CommandList.h"
|
||||||
|
#include "IPAddressList.h"
|
||||||
|
#include "Socket.h"
|
||||||
#include "SubscriptionManager.h"
|
#include "SubscriptionManager.h"
|
||||||
|
#include "TCPSession.h"
|
||||||
|
#include "TCPSocket.h"
|
||||||
|
|
||||||
namespace core {
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
///
|
///
|
||||||
/// TCPServer
|
/// TCPServer
|
||||||
@ -22,10 +24,10 @@ namespace core {
|
|||||||
/// process commands to display status information.
|
/// process commands to display status information.
|
||||||
///
|
///
|
||||||
|
|
||||||
class TCPServer : public TCPSocket, public Command {
|
class TCPServer : public TCPSocket, public Command
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
///
|
///
|
||||||
/// The constructor for the TCPServer object.
|
/// The constructor for the TCPServer object.
|
||||||
///
|
///
|
||||||
@ -53,7 +55,7 @@ namespace core {
|
|||||||
/// service.
|
/// service.
|
||||||
///
|
///
|
||||||
|
|
||||||
virtual TCPSession * getSocketAccept(EPoll &epoll);
|
virtual TCPSession *getSocketAccept(EPoll &epoll);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// The list of sessions that are currently open and being maintained by this object.
|
/// The list of sessions that are currently open and being maintained by this object.
|
||||||
@ -86,7 +88,7 @@ namespace core {
|
|||||||
|
|
||||||
void removeFromSessionList(TCPSession *session);
|
void removeFromSessionList(TCPSession *session);
|
||||||
|
|
||||||
void output(std::stringstream &out); ///<Output the consoles array to the console.
|
void output(std::stringstream &out); ///< Output the consoles array to the console.
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
@ -115,8 +117,14 @@ namespace core {
|
|||||||
|
|
||||||
SubscriptionManager subscriptions;
|
SubscriptionManager subscriptions;
|
||||||
|
|
||||||
protected:
|
///
|
||||||
|
/// Use the getSessionByAlias to retrieve a session pointer by the value
|
||||||
|
/// of the alias pointer.
|
||||||
|
///
|
||||||
|
|
||||||
|
TCPSession *getSessionByAlias(void *alias);
|
||||||
|
|
||||||
|
protected:
|
||||||
///
|
///
|
||||||
/// Override the virtual dataReceived since for the server these
|
/// Override the virtual dataReceived since for the server these
|
||||||
/// are requests to accept the new connection socket.
|
/// are requests to accept the new connection socket.
|
||||||
@ -139,10 +147,8 @@ namespace core {
|
|||||||
int processCommand(coreutils::ZString &request, TCPSession &session) override;
|
int processCommand(coreutils::ZString &request, TCPSession &session) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
TCPSession *accept();
|
||||||
TCPSession * accept();
|
|
||||||
std::mutex lock;
|
std::mutex lock;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,65 +1,87 @@
|
|||||||
#include "TCPSession.h"
|
#include "TCPSession.h"
|
||||||
#include "TCPServer.h"
|
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "TCPServer.h"
|
||||||
|
#include "uuid/uuid.h"
|
||||||
|
|
||||||
namespace core {
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
TCPSession::TCPSession(EPoll &ePoll, TCPServer &server, std::string text) : TCPSocket(ePoll, text), server(server) {}
|
TCPSession::TCPSession(EPoll &ePoll, TCPServer &server, std::string text) : TCPSocket(ePoll, text), server(server)
|
||||||
|
{
|
||||||
|
uuid_t uuidObject;
|
||||||
|
uuid_generate(uuidObject);
|
||||||
|
// std::string aaUuid = {uuidObject, uuidObject + 16};
|
||||||
|
coreutils::Log(coreutils::LOG_DEBUG_1) << uuidObject;
|
||||||
|
alias = (void *)uuidObject;
|
||||||
|
}
|
||||||
|
|
||||||
TCPSession::~TCPSession() {
|
TCPSession::~TCPSession()
|
||||||
|
{
|
||||||
server.removeFromSessionList(this);
|
server.removeFromSessionList(this);
|
||||||
server.subscriptions.removeSessionSubscriptions(*this);
|
server.subscriptions.removeSessionSubscriptions(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPSession::output(std::stringstream &data) {
|
void TCPSession::output(std::stringstream &data)
|
||||||
|
{
|
||||||
data << "|" << ipAddress.getClientAddressAndPort();
|
data << "|" << ipAddress.getClientAddressAndPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPSession::protocol(coreutils::ZString &data) {
|
void TCPSession::protocol(coreutils::ZString &data)
|
||||||
if(data.getLength() != 0) {
|
{
|
||||||
if(!server.commands.processRequest(data, *this)) {
|
if (data.getLength() != 0)
|
||||||
|
{
|
||||||
|
if (!server.commands.processRequest(data, *this))
|
||||||
|
{
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "Received data could not be parsed: " << data.str();
|
coreutils::Log(coreutils::LOG_DEBUG_1) << "Received data could not be parsed: " << data.str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TCPSession::compareAlias(void *alias) {
|
||||||
|
return this->alias = alias;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TCPSession::outputAlias(std::stringstream &out) {
|
||||||
|
out << alias;
|
||||||
|
}
|
||||||
|
|
||||||
void TCPSession::onRegistered() {
|
void TCPSession::onRegistered() {
|
||||||
onConnected();
|
onConnected();
|
||||||
coreutils::ZString blank("");
|
|
||||||
protocol(blank);
|
|
||||||
send();
|
send();
|
||||||
if(term)
|
if (term)
|
||||||
shutdown("termination requested");
|
shutdown("termination requested");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPSession::onConnected() {}
|
void TCPSession::onConnected() {}
|
||||||
|
|
||||||
void TCPSession::onDataReceived(coreutils::ZString &data) {
|
void TCPSession::onDataReceived(coreutils::ZString &data) {
|
||||||
if(data.getLength() > 0) {
|
if (data.getLength() > 0) {
|
||||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength());
|
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength());
|
||||||
memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength());
|
memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength());
|
||||||
lineBufferSize += data.getLength();
|
lineBufferSize += data.getLength();
|
||||||
while(lineBufferSize > 0) {
|
while (lineBufferSize > 0) {
|
||||||
if(blockSize == 0) {
|
if (blockSize == 0) {
|
||||||
lineLength = strcspn(lineBuffer, "\r\n");
|
lineLength = strcspn(lineBuffer, "\r\n");
|
||||||
if(lineLength == lineBufferSize)
|
if (lineLength == lineBufferSize)
|
||||||
break;
|
break;
|
||||||
coreutils::ZString zLine(lineBuffer, lineLength);
|
coreutils::ZString zLine(lineBuffer, lineLength);
|
||||||
onLineReceived(zLine);
|
onLineReceived(zLine);
|
||||||
if(lineBuffer[lineLength] == '\r')
|
if (lineBuffer[lineLength] == '\r')
|
||||||
++lineLength;
|
++lineLength;
|
||||||
if(lineBuffer[lineLength] == '\n')
|
if (lineBuffer[lineLength] == '\n')
|
||||||
++lineLength;
|
++lineLength;
|
||||||
lineBufferSize -= lineLength;
|
lineBufferSize -= lineLength;
|
||||||
if(lineBufferSize > 0)
|
if (lineBufferSize > 0)
|
||||||
memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize);
|
memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize);
|
||||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||||
} else if(lineBufferSize >= blockLength) {
|
}
|
||||||
|
else if (lineBufferSize >= blockLength)
|
||||||
|
{
|
||||||
coreutils::ZString zBlock(lineBuffer, blockLength);
|
coreutils::ZString zBlock(lineBuffer, blockLength);
|
||||||
onBlockReceived(zBlock);
|
onBlockReceived(zBlock);
|
||||||
lineBufferSize -= blockLength;
|
lineBufferSize -= blockLength;
|
||||||
if(lineBufferSize > 0)
|
if (lineBufferSize > 0)
|
||||||
memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize);
|
memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize);
|
||||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||||
}
|
}
|
||||||
@ -67,20 +89,23 @@ namespace core {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPSession::setBlockSize(int blockSize) {
|
void TCPSession::setBlockSize(int blockSize)
|
||||||
|
{
|
||||||
this->blockSize = blockSize;
|
this->blockSize = blockSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPSession::onLineReceived(coreutils::ZString &line) {
|
void TCPSession::onLineReceived(coreutils::ZString &line)
|
||||||
|
{
|
||||||
protocol(line);
|
protocol(line);
|
||||||
send();
|
send();
|
||||||
if(term)
|
if (term)
|
||||||
shutdown("termination requested");
|
shutdown("termination requested");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPSession::onBlockReceived(coreutils::ZString &block) {
|
void TCPSession::onBlockReceived(coreutils::ZString &block)
|
||||||
|
{
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << block.getLength() << "]";
|
coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << block.getLength() << "]";
|
||||||
if(term)
|
if (term)
|
||||||
shutdown("termination requested");
|
shutdown("termination requested");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +115,8 @@ namespace core {
|
|||||||
out.str("");
|
out.str("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPSession::terminate() {
|
void TCPSession::terminate()
|
||||||
|
{
|
||||||
term = true;
|
term = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
37
TCPSession.h
37
TCPSession.h
@ -1,10 +1,11 @@
|
|||||||
#ifndef __Session_h__
|
#ifndef __Session_h__
|
||||||
# define __Session_h__
|
#define __Session_h__
|
||||||
|
|
||||||
#include "TCPSocket.h"
|
|
||||||
#include "SessionFilter.h"
|
#include "SessionFilter.h"
|
||||||
|
#include "TCPSocket.h"
|
||||||
|
|
||||||
namespace core {
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
class Command;
|
class Command;
|
||||||
class TCPServer;
|
class TCPServer;
|
||||||
@ -21,10 +22,10 @@ namespace core {
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
class TCPSession : public TCPSocket {
|
class TCPSession : public TCPSocket
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
@ -66,8 +67,31 @@ namespace core {
|
|||||||
|
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
|
|
||||||
protected:
|
///
|
||||||
|
/// uuid is generated automatically when the session object is instantiated. This
|
||||||
|
/// value can be used to uniquely identify a session and is the default value
|
||||||
|
/// pointed to by the alias pointer.
|
||||||
|
///
|
||||||
|
|
||||||
|
char uuid[37];
|
||||||
|
|
||||||
|
///
|
||||||
|
/// alias is a void pointer that can be set to point to any object that identifies
|
||||||
|
/// this session uniquely. Using this approach, inheriting objects can determine
|
||||||
|
/// how it knows the contacts that this server manages.
|
||||||
|
///
|
||||||
|
|
||||||
|
void *alias;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual bool compareAlias(void *alias);
|
||||||
|
|
||||||
|
virtual void outputAlias(std::stringstream &out);
|
||||||
|
|
||||||
|
protected:
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
@ -135,7 +159,6 @@ namespace core {
|
|||||||
std::mutex mtx;
|
std::mutex mtx;
|
||||||
bool term = false;
|
bool term = false;
|
||||||
int blockSize = 0;
|
int blockSize = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
85
TCPSession2.cpp
Normal file
85
TCPSession2.cpp
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
139
TCPSession2.h
Normal file
139
TCPSession2.h
Normal file
@ -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
|
@ -2,6 +2,7 @@
|
|||||||
#include "EPoll.h"
|
#include "EPoll.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
|
#include "errno.h"
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
@ -14,7 +15,8 @@ namespace core {
|
|||||||
void TCPSocket::connect(IPAddress &address) {
|
void TCPSocket::connect(IPAddress &address) {
|
||||||
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
|
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
|
||||||
if(::connect(getDescriptor(), (struct sockaddr *)&address.addr, address.addressLength) == -1)
|
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) {
|
void TCPSocket::output(std::stringstream &out) {
|
||||||
|
@ -60,9 +60,12 @@ namespace core {
|
|||||||
} else if(rc > 0) {
|
} else if(rc > 0) {
|
||||||
for(int ix = 0; ix < rc; ++ix) {
|
for(int ix = 0; ix < rc; ++ix) {
|
||||||
++count;
|
++count;
|
||||||
if(((Socket *)events[ix].data.ptr)->eventReceived(events[ix])) {
|
if(((Socket *)events[ix].data.ptr)->eventReceived(events[ix], ++ePoll.eventId)) {
|
||||||
ePoll.resetSocket((Socket *)events[ix].data.ptr);
|
// 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;
|
delete (Socket *)events[ix].data.ptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user