Servercore Changes
This commit is contained in:
parent
9a39b6224c
commit
3a75e920d9
@ -1,5 +1,6 @@
|
||||
#include "Subscription.h"
|
||||
#include "Log.h"
|
||||
#include "MString.h"
|
||||
#include "TCPSession.h"
|
||||
#include "TCPSocket.h"
|
||||
#include <algorithm>
|
||||
@ -8,15 +9,18 @@ namespace core
|
||||
{
|
||||
|
||||
Subscription::Subscription(std::string id, std::string mode)
|
||||
: id(id), mode(mode), owner(NULL), handler(NULL) {}
|
||||
: id(id), mode(mode), owner(""), handler(NULL) {}
|
||||
|
||||
Subscription::Subscription(std::string id, coreutils::MString *alias, std::string mode)
|
||||
Subscription::Subscription(std::string id, coreutils::MString alias, std::string mode)
|
||||
: id(id), mode(mode), owner(alias), handler(NULL) {}
|
||||
|
||||
Subscription::Subscription(std::string id, coreutils::MString *alias, std::string ownership, std::string mode, SubscriptionHandler *handler, std::string will, std::string timer)
|
||||
Subscription::Subscription(std::string id, coreutils::MString alias, std::string ownership, std::string mode, SubscriptionHandler *handler, std::string will, std::string timer)
|
||||
: id(id), ownership(ownership), mode(mode), owner(alias), handler(handler), will(will), timer(timer)
|
||||
{
|
||||
// coreutils::Log(coreutils::LOG_DEBUG_3) << "Subscription '" << id << "' with handler '" << handler->name << "'";
|
||||
|
||||
coreutils::Log(coreutils::LOG_DEBUG_3) << owner;
|
||||
coreutils::Log(coreutils::LOG_DEBUG_3) << will;
|
||||
subscriptionOwner(owner, will);
|
||||
}
|
||||
|
||||
Subscription::~Subscription()
|
||||
@ -57,19 +61,12 @@ namespace core
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Subscription::subscriptionOwner(coreutils::MString *alias, std::string ownerSelection)
|
||||
bool Subscription::subscriptionOwner(coreutils::MString alias, std::string ownerSelection)
|
||||
{
|
||||
if (owner != NULL)
|
||||
{
|
||||
owner = alias;
|
||||
will == ownerSelection;
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "Owner of Subscription: " << *(std::string *)owner;
|
||||
}
|
||||
else
|
||||
{
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "There is no owner to this subscription";
|
||||
}
|
||||
subscriptionOwners = alias;
|
||||
selectionOfOwnerForSubscription = ownerSelection;
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "Owner of Subscription: " << subscriptionOwners;
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "Will of Subscription: " << selectionOfOwnerForSubscription;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ namespace core
|
||||
|
||||
public:
|
||||
Subscription(std::string id, std::string mode = "*AUTHOR");
|
||||
Subscription(std::string id, coreutils::MString *alias, std::string mode);
|
||||
Subscription(std::string id, coreutils::MString *alias, std::string ownership, std::string mode, SubscriptionHandler *handler, std::string selection, std::string time);
|
||||
Subscription(std::string id, coreutils::MString alias, std::string mode);
|
||||
Subscription(std::string id, coreutils::MString alias, std::string ownership, std::string mode, SubscriptionHandler *handler, std::string selection, std::string time);
|
||||
virtual ~Subscription();
|
||||
|
||||
int subscribe(TCPSession &session);
|
||||
@ -30,7 +30,7 @@ namespace core
|
||||
virtual int onSubscribe(TCPSession &session);
|
||||
|
||||
int event(std::stringstream &out);
|
||||
bool subscriptionOwner(coreutils::MString *alias, std::string selection);
|
||||
bool subscriptionOwner(coreutils::MString alias, std::string selection);
|
||||
bool ifSubscriber(TCPSession &session);
|
||||
|
||||
bool subInvite(TCPSession &session);
|
||||
@ -40,8 +40,9 @@ namespace core
|
||||
|
||||
std::string id;
|
||||
std::string mode;
|
||||
coreutils::MString *owner;
|
||||
|
||||
coreutils::MString owner;
|
||||
coreutils::MString subscriptionOwners;
|
||||
std::string selectionOfOwnerForSubscription;
|
||||
std::string will;
|
||||
std::string ownership;
|
||||
std::string timer;
|
||||
|
@ -17,11 +17,9 @@ namespace core
|
||||
}
|
||||
bool SubscriptionManager::onClearSubscription(std::string temp, std::string key)
|
||||
{
|
||||
temp = key;
|
||||
// temp = key;
|
||||
temp = "";
|
||||
key = "";
|
||||
// delete subscription;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -41,9 +39,9 @@ namespace core
|
||||
temp = "";
|
||||
}
|
||||
countSubscribed += subscription->unsubscribe(session);
|
||||
if (subscription->owner == session.alias)
|
||||
if (subscription->subscriptionOwners == session.alias)
|
||||
{
|
||||
if (subscription->will == "*DIE") //--> This happens if the owner of the subscription sets it, or if not enough people in Vector -->//
|
||||
if (subscription->selectionOfOwnerForSubscription == "*DIE") //--> This happens if the owner of the subscription sets it, or if not enough people in Vector -->//
|
||||
{
|
||||
onClearSubscription(temp, key);
|
||||
}
|
||||
@ -60,11 +58,11 @@ namespace core
|
||||
|
||||
for (auto subscribed = subscription->subscribers.begin(); subscribed < subscription->subscribers.end(); subscribed++)
|
||||
{
|
||||
if (*subscribed == &session)
|
||||
if ((*subscribed)->alias == session.alias)
|
||||
{
|
||||
subscription->subscribers.erase(subscribed++);
|
||||
}
|
||||
subscription->subscriptionOwner((*subscribed)->alias, "*NEXT");
|
||||
subscription->subscriptionOwner(session.alias, "*NEXT");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -95,14 +93,16 @@ namespace core
|
||||
{
|
||||
handler = factory->getSubscriptionHandler(request[4].str());
|
||||
}
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << request[1].str() << ":" << request[2].str();
|
||||
// coreutils::Log(coreutils::LOG_DEBUG_1) << request[1].str() << ":" << session.alias << ":" << request[2].str() << ":" << request[3].str() << ":" << request[4].str() << ":" << request[5].str() << ":" << request[6].str();
|
||||
if (request[2].str() == "*OWNER")
|
||||
{
|
||||
|
||||
newSubscription = new Subscription(request[1].str(), session.alias, request[2].str(), request[3].str(), handler, request[5].str(), request[6].str());
|
||||
subscriptions.insert(std::make_pair(request[1].str(), newSubscription));
|
||||
subscription->subscriptionOwner(session.alias, request[5].str());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
else if (request[0].equals("catalog"))
|
||||
@ -119,13 +119,12 @@ namespace core
|
||||
{
|
||||
std::stringstream out;
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << request[2];
|
||||
invitee = (coreutils::MString *)&request[2];
|
||||
|
||||
// invitee = (coreutils::MString *)&request[2];
|
||||
|
||||
// TCPSession *tempSession = session.server.getSessionByAlias(invitee);
|
||||
// std::stringstream temp;
|
||||
// temp << "invite:" << request[1] << ":" << invitee;
|
||||
// tempSession->write(temp.str());
|
||||
TCPSession *tempSession = session.server.getSessionByAlias(invitee);
|
||||
std::stringstream temp;
|
||||
temp << "invite:" << request[1] << ":" << invitee;
|
||||
tempSession->write(temp.str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -9,11 +9,9 @@ namespace core
|
||||
|
||||
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 = (coreutils::MString *)uuidObject;
|
||||
uuid_t uuid;
|
||||
uuid_generate(uuid);
|
||||
alias = coreutils::MString((char *)uuid, 26);
|
||||
}
|
||||
|
||||
TCPSession::~TCPSession()
|
||||
@ -40,7 +38,7 @@ namespace core
|
||||
|
||||
bool TCPSession::compareAlias(coreutils::MString &alias)
|
||||
{
|
||||
return this->alias = &alias;
|
||||
return this->alias == alias;
|
||||
}
|
||||
|
||||
void TCPSession::onRegistered()
|
||||
|
@ -76,18 +76,15 @@ namespace core
|
||||
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.
|
||||
/// alias is a MString that can be set to any string of characters that identifies
|
||||
/// this session uniquely. Alias's should be unique between sessions.
|
||||
///
|
||||
|
||||
coreutils::MString *alias;
|
||||
coreutils::MString alias;
|
||||
///
|
||||
///
|
||||
///
|
||||
|
||||
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
|
BIN
output/main
BIN
output/main
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user