Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-06 03:49:13

0001 #ifndef ServiceRegistry_ServiceToken_h
0002 #define ServiceRegistry_ServiceToken_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     ServiceRegistry
0006 // Class  :     ServiceToken
0007 //
0008 /**\class ServiceToken ServiceToken.h FWCore/ServiceRegistry/interface/ServiceToken.h
0009 
0010  Description: Token used to denote a 'service set' 
0011 
0012  Usage:
0013     When you request a new 'service set' to be created from the ServiceRegistry, 
0014   the ServiceRegistry will return a ServiceToken.  When you want this 'service set' to be used,
0015   create a ServiceRegistry::Operate by passing the ServiceToken via the constructor.
0016 
0017 */
0018 //
0019 // Original Author:  Chris Jones
0020 //         Created:  Tue Sep  6 18:31:44 EDT 2005
0021 //
0022 
0023 // system include files
0024 #include <memory>
0025 
0026 // user include files
0027 
0028 // forward declarations
0029 class testServicesManager;
0030 class TestServicesManagerOrder;
0031 
0032 namespace edm {
0033   class ServiceRegistry;
0034   class ActivityRegistry;
0035 
0036   namespace serviceregistry {
0037     class ServicesManager;
0038   }
0039 
0040   class ServiceWeakToken;
0041 
0042   class ServiceToken {
0043     friend class edm::ServiceRegistry;
0044     friend class edm::serviceregistry::ServicesManager;
0045     //for testing
0046     friend class ::testServicesManager;
0047     friend class ::TestServicesManagerOrder;
0048 
0049   public:
0050     ServiceToken() {}
0051     //virtual ~ServiceToken();
0052     ServiceToken(ServiceToken&&) = default;
0053     ServiceToken(ServiceToken const&) = default;
0054     ServiceToken& operator=(ServiceToken&&) = default;
0055     ServiceToken& operator=(ServiceToken const&) = default;
0056 
0057     // ---------- const member functions ---------------------
0058 
0059     // ---------- static member functions --------------------
0060 
0061     // ---------- member functions ---------------------------
0062 
0063     ///the argument's signals are propagated to the Service's held by the token
0064     void connectTo(ActivityRegistry&);
0065     ///the argument's signals will forward the token's signals
0066     void connect(ActivityRegistry&);
0067 
0068     ///copy our Service's slots to the argument's signals
0069     void copySlotsTo(ActivityRegistry&);
0070     ///the copy the argument's slots to the token's signals
0071     void copySlotsFrom(ActivityRegistry&);
0072 
0073     friend class ServiceWeakToken;
0074 
0075   private:
0076     ServiceToken(std::shared_ptr<edm::serviceregistry::ServicesManager> iManager) : manager_(iManager) {}
0077 
0078     //ServiceToken(const ServiceToken&); // stop default
0079 
0080     //const ServiceToken& operator=(const ServiceToken&); // stop default
0081 
0082     // ---------- member data --------------------------------
0083     std::shared_ptr<edm::serviceregistry::ServicesManager> manager_;
0084   };
0085 
0086   class ServiceWeakToken {
0087   public:
0088     ServiceWeakToken(ServiceToken const& iToken) : manager_(iToken.manager_) {}
0089     ServiceWeakToken() = default;
0090 
0091     ServiceWeakToken(ServiceWeakToken&&) = default;
0092     ServiceWeakToken(ServiceWeakToken const&) = default;
0093     ServiceWeakToken& operator=(ServiceWeakToken&&) = default;
0094     ServiceWeakToken& operator=(ServiceWeakToken const&) = default;
0095 
0096     ServiceWeakToken& operator=(ServiceToken const& iToken) {
0097       manager_ = iToken.manager_;
0098       return *this;
0099     }
0100 
0101     ServiceToken lock() const { return ServiceToken(manager_.lock()); }
0102 
0103   private:
0104     std::weak_ptr<edm::serviceregistry::ServicesManager> manager_;
0105   };
0106 }  // namespace edm
0107 
0108 #endif