bincimap

Log | Files | Refs | LICENSE

broker.h (2969B)


      1 /* -*- Mode: c++; -*- */
      2 /*  --------------------------------------------------------------------
      3  *  Filename:
      4  *    src/broker.h
      5  *  
      6  *  Description:
      7  *    <--->
      8  *
      9  *  Authors:
     10  *    Andreas Aardal Hanssen <andreas-binc curly bincimap spot org>
     11  *
     12  *  Bugs:
     13  *
     14  *  ChangeLog:
     15  *
     16  *  --------------------------------------------------------------------
     17  *  Copyright 2002-2005 Andreas Aardal Hanssen
     18  *
     19  *  This program is free software; you can redistribute it and/or modify
     20  *  it under the terms of the GNU General Public License as published by
     21  *  the Free Software Foundation; either version 2 of the License, or
     22  *  (at your option) any later version.
     23  *
     24  *  This program is distributed in the hope that it will be useful,
     25  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     26  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     27  *  GNU General Public License for more details.
     28  *
     29  *  You should have received a copy of the GNU General Public License
     30  *  along with this program; if not, write to the Free Software
     31  *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
     32  *  --------------------------------------------------------------------
     33  */
     34 #ifndef broker_h_included
     35 #define broker_h_included
     36 #include "depot.h"
     37 #include "operators.h"
     38 
     39 #include <string>
     40 #include <map>
     41 
     42 namespace Binc {
     43 
     44   class Request;
     45   class Broker;
     46 
     47   //------------------------------------------------------------------
     48   class BrokerFactory {
     49   private:
     50     std::map<int, Broker *> brokers;
     51 
     52     //--
     53     BrokerFactory(void);
     54 
     55     mutable std::string lastError;
     56 
     57   public:
     58     Broker *getBroker(int state);
     59     void assign(const std::string &fname, Operator *o);
     60     void addCapability(const std::string &c);
     61     Operator *getOperator(int state, const std::string &name) const;
     62 
     63     inline const std::string &getLastError(void) const;
     64     inline void setLastError(const std::string &error) const;
     65 
     66     //--
     67     static BrokerFactory &getInstance(void);
     68     ~BrokerFactory(void);
     69   };
     70 
     71   //------------------------------------------------------------------
     72   inline const std::string &BrokerFactory::getLastError(void) const
     73   {
     74     return lastError;
     75   }
     76 
     77   //------------------------------------------------------------------
     78   inline void BrokerFactory::setLastError(const std::string &error) const
     79   {
     80     lastError = error;
     81   }
     82 
     83   //------------------------------------------------------------------
     84   class Broker {
     85   private:
     86     std::map<std::string, Operator *> operators;
     87     std::map<std::string, bool> deletables;
     88 
     89   public:
     90     Operator * get(const std::string &name) const;
     91     void assign(const std::string &fname, Operator *o, bool deletable = false);
     92     Operator::ParseResult parseStub(Request &cmd);
     93 
     94     //--
     95     inline Broker(Broker &);
     96     inline Broker(const Broker &);
     97     Broker(void);
     98     ~Broker(void);
     99   };
    100 
    101   inline Broker::Broker(Broker &)
    102   {
    103   }
    104 
    105   inline Broker::Broker(const Broker &)
    106   {
    107   }
    108 }
    109 
    110 #endif