summaryrefslogtreecommitdiff
path: root/src/broker.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/broker.cc')
-rw-r--r--src/broker.cc40
1 files changed, 15 insertions, 25 deletions
diff --git a/src/broker.cc b/src/broker.cc
index 3270702..59c23bb 100644
--- a/src/broker.cc
+++ b/src/broker.cc
@@ -14,18 +14,11 @@ using std::string;
BrokerFactory::BrokerFactory()
{
- auto &session = Session::getInstance();
- Parser p(session);
+ Parser p{Session::getInstance()};
- brokers[Session::State::NONAUTHENTICATED] = new Broker(p);
- brokers[Session::State::AUTHENTICATED] = new Broker(p);
- brokers[Session::State::SELECTED] = new Broker(p);
-}
-
-BrokerFactory::~BrokerFactory()
-{
- for (auto &[_, second] : brokers)
- delete second;
+ brokers.emplace(Session::State::NONAUTHENTICATED, Broker(p));
+ brokers.emplace(Session::State::AUTHENTICATED, Broker(p));
+ brokers.emplace(Session::State::SELECTED, Broker(p));
}
BrokerFactory &BrokerFactory::getInstance()
@@ -34,10 +27,10 @@ BrokerFactory &BrokerFactory::getInstance()
return brokerfactory;
}
-void BrokerFactory::addCapability(const std::string &c)
+void BrokerFactory::addCapability(const string &c)
{
for (const auto &[_, second] : brokers) {
- auto o = dynamic_cast<CapabilityOperator *>(second->get("CAPABILITY"));
+ auto o = dynamic_cast<CapabilityOperator *>(second.get("CAPABILITY"));
if (o != nullptr) {
o->addCapability(c);
break;
@@ -45,13 +38,11 @@ void BrokerFactory::addCapability(const std::string &c)
}
}
-void BrokerFactory::assign(const string &fname, Operator *o)
+void BrokerFactory::assign(const string &fname, std::shared_ptr<Operator> o)
{
- int deletable = true;
- for (const auto &[first, second] : brokers) {
- if (first & o->getState()) {
- second->assign(fname, o, deletable);
- deletable = false;
+ for (auto &[state, broker] : brokers) {
+ if (state & o->getState()) {
+ broker.assign(fname, o);
}
}
}
@@ -61,30 +52,29 @@ Operator *BrokerFactory::getOperator(Session::State state, const string &name) c
if (brokers.find(state) == brokers.end())
return nullptr;
else
- return brokers.find(state)->second->get(name);
+ return brokers.find(state)->second.get(name);
}
Broker *BrokerFactory::getBroker(Session::State state)
{
- auto it = brokers.find(state);
+ const auto it = brokers.find(state);
if (it == brokers.end()) {
setLastError("No appropriate broker for state.");
return nullptr;
}
- return it->second;
+ return &it->second;
}
-void Broker::assign(const string &fname, Operator *o, bool deletable)
+void Broker::assign(const string &fname, std::shared_ptr<Operator> o)
{
- deletables[fname] = deletable;
operators[fname] = o;
}
Operator *Broker::get(const string &name) const
{
if (operators.find(name) == operators.end()) return nullptr;
- return operators.find(name)->second;
+ return operators.find(name)->second.get();
}
Parser::ParseResult Broker::parseStub(Request &command)