Servercore Changes
This commit is contained in:
parent
9a39b6224c
commit
3a75e920d9
@ -1,5 +1,6 @@
|
|||||||
#include "Subscription.h"
|
#include "Subscription.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "MString.h"
|
||||||
#include "TCPSession.h"
|
#include "TCPSession.h"
|
||||||
#include "TCPSocket.h"
|
#include "TCPSocket.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -8,15 +9,18 @@ namespace core
|
|||||||
{
|
{
|
||||||
|
|
||||||
Subscription::Subscription(std::string id, std::string mode)
|
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) {}
|
: 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)
|
: 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()
|
Subscription::~Subscription()
|
||||||
@ -57,19 +61,12 @@ namespace core
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
bool Subscription::subscriptionOwner(coreutils::MString alias, std::string ownerSelection)
|
||||||
bool Subscription::subscriptionOwner(coreutils::MString *alias, std::string ownerSelection)
|
|
||||||
{
|
{
|
||||||
if (owner != NULL)
|
subscriptionOwners = alias;
|
||||||
{
|
selectionOfOwnerForSubscription = ownerSelection;
|
||||||
owner = alias;
|
coreutils::Log(coreutils::LOG_DEBUG_1) << "Owner of Subscription: " << subscriptionOwners;
|
||||||
will == ownerSelection;
|
coreutils::Log(coreutils::LOG_DEBUG_1) << "Will of Subscription: " << selectionOfOwnerForSubscription;
|
||||||
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";
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,8 @@ namespace core
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Subscription(std::string id, std::string mode = "*AUTHOR");
|
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 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 ownership, std::string mode, SubscriptionHandler *handler, std::string selection, std::string time);
|
||||||
virtual ~Subscription();
|
virtual ~Subscription();
|
||||||
|
|
||||||
int subscribe(TCPSession &session);
|
int subscribe(TCPSession &session);
|
||||||
@ -30,7 +30,7 @@ namespace core
|
|||||||
virtual int onSubscribe(TCPSession &session);
|
virtual int onSubscribe(TCPSession &session);
|
||||||
|
|
||||||
int event(std::stringstream &out);
|
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 ifSubscriber(TCPSession &session);
|
||||||
|
|
||||||
bool subInvite(TCPSession &session);
|
bool subInvite(TCPSession &session);
|
||||||
@ -40,8 +40,9 @@ namespace core
|
|||||||
|
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string mode;
|
std::string mode;
|
||||||
coreutils::MString *owner;
|
coreutils::MString owner;
|
||||||
|
coreutils::MString subscriptionOwners;
|
||||||
|
std::string selectionOfOwnerForSubscription;
|
||||||
std::string will;
|
std::string will;
|
||||||
std::string ownership;
|
std::string ownership;
|
||||||
std::string timer;
|
std::string timer;
|
||||||
|
@ -17,11 +17,9 @@ namespace core
|
|||||||
}
|
}
|
||||||
bool SubscriptionManager::onClearSubscription(std::string temp, std::string key)
|
bool SubscriptionManager::onClearSubscription(std::string temp, std::string key)
|
||||||
{
|
{
|
||||||
temp = key;
|
// temp = key;
|
||||||
temp = "";
|
temp = "";
|
||||||
key = "";
|
key = "";
|
||||||
// delete subscription;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,9 +39,9 @@ namespace core
|
|||||||
temp = "";
|
temp = "";
|
||||||
}
|
}
|
||||||
countSubscribed += subscription->unsubscribe(session);
|
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);
|
onClearSubscription(temp, key);
|
||||||
}
|
}
|
||||||
@ -60,11 +58,11 @@ namespace core
|
|||||||
|
|
||||||
for (auto subscribed = subscription->subscribers.begin(); subscribed < subscription->subscribers.end(); subscribed++)
|
for (auto subscribed = subscription->subscribers.begin(); subscribed < subscription->subscribers.end(); subscribed++)
|
||||||
{
|
{
|
||||||
if (*subscribed == &session)
|
if ((*subscribed)->alias == session.alias)
|
||||||
{
|
{
|
||||||
subscription->subscribers.erase(subscribed++);
|
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());
|
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")
|
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());
|
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));
|
subscriptions.insert(std::make_pair(request[1].str(), newSubscription));
|
||||||
subscription->subscriptionOwner(session.alias, request[5].str());
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (request[0].equals("catalog"))
|
else if (request[0].equals("catalog"))
|
||||||
@ -119,13 +119,12 @@ namespace core
|
|||||||
{
|
{
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_1) << request[2];
|
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;
|
||||||
// TCPSession *tempSession = session.server.getSessionByAlias(invitee);
|
temp << "invite:" << request[1] << ":" << invitee;
|
||||||
// std::stringstream temp;
|
tempSession->write(temp.str());
|
||||||
// temp << "invite:" << request[1] << ":" << invitee;
|
|
||||||
// tempSession->write(temp.str());
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,11 +9,9 @@ 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_t uuid;
|
||||||
uuid_generate(uuidObject);
|
uuid_generate(uuid);
|
||||||
// std::string aaUuid = {uuidObject, uuidObject + 16};
|
alias = coreutils::MString((char *)uuid, 26);
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_1) << uuidObject;
|
|
||||||
alias = (coreutils::MString *)uuidObject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TCPSession::~TCPSession()
|
TCPSession::~TCPSession()
|
||||||
@ -40,7 +38,7 @@ namespace core
|
|||||||
|
|
||||||
bool TCPSession::compareAlias(coreutils::MString &alias)
|
bool TCPSession::compareAlias(coreutils::MString &alias)
|
||||||
{
|
{
|
||||||
return this->alias = &alias;
|
return this->alias == alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPSession::onRegistered()
|
void TCPSession::onRegistered()
|
||||||
|
@ -76,18 +76,15 @@ namespace core
|
|||||||
char uuid[37];
|
char uuid[37];
|
||||||
|
|
||||||
///
|
///
|
||||||
/// alias is a void pointer that can be set to point to any object that identifies
|
/// alias is a MString that can be set to any string of characters that identifies
|
||||||
/// this session uniquely. Using this approach, inheriting objects can determine
|
/// this session uniquely. Alias's should be unique between sessions.
|
||||||
/// how it knows the contacts that this server manages.
|
|
||||||
///
|
///
|
||||||
|
|
||||||
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