summaryrefslogtreecommitdiff
path: root/src/include/broker.h
blob: 7cca0aa31d9e15e1137923bb2a07f2b4622fc29c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
 *  @file broker.h
 *  @brief Declaration of the Broker class.
 *  @author Andreas Aardal Hanssen
 *  @date 2002-2005
 */

#ifndef broker_h_included
#define broker_h_included

#include "depot.h"
#include "operators.h"

#include <map>
#include <string>

namespace Binc {

  class Request;
  class Broker;

  class BrokerFactory {
  private:
    std::map<int, Broker *> brokers;

    BrokerFactory();

    mutable std::string lastError;

  public:
    Broker *getBroker(int state);
    void assign(const std::string &fname, Operator *o);
    void addCapability(const std::string &c);
    Operator *getOperator(int state, const std::string &name) const;

    inline const std::string &getLastError() const;
    inline void setLastError(const std::string &error) const;

    static BrokerFactory &getInstance();
    ~BrokerFactory();
  };

  inline const std::string &BrokerFactory::getLastError() const
  {
    return lastError;
  }

  inline void BrokerFactory::setLastError(const std::string &error) const
  {
    lastError = error;
  }

  class Broker {
  private:
    std::map<std::string, Operator *> operators;
    std::map<std::string, bool> deletables;

  public:
    Operator *get(const std::string &name) const;
    void assign(const std::string &fname, Operator *o, bool deletable = false);
    Operator::ParseResult parseStub(Request &cmd);

    inline Broker(Broker &);
    inline Broker(const Broker &);
    Broker();
    ~Broker();
  };

  inline Broker::Broker(Broker &) {}

  inline Broker::Broker(const Broker &) {}

}

#endif