LCOV - code coverage report
Current view: top level - casatools/Proc - Registrar.h (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 0 10 0.0 %
Date: 2023-11-06 10:06:49 Functions: 0 8 0.0 %

          Line data    Source code
       1             : //# Registrar.h: maintain registry of services
       2             : //# Copyright (C) 2017
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: aips2-request@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : #ifndef CASATOOLS_PROC_REGISTRAR_H
      27             : #define CASATOOLS_PROC_REGISTRAR_H
      28             : #include <set>
      29             : #include <list>
      30             : #include <mutex>
      31             : #include <string>
      32             : #include <algorithm>
      33             : 
      34             : namespace casatools {   /** namespace for CASAtools classes within "CASA code" **/
      35             : 
      36             :     class ServiceId {
      37             :       public:
      38           0 :         ServiceId( std::string id_p, std::string uri_p, std::list<std::string> types_p, unsigned int priority_p=0 ) : id_(id_p), uri_(uri_p), types_(types_p), priority_(priority_p) { }
      39           0 :         ServiceId( const ServiceId &other ) : id_(other.id_), uri_(other.uri_), types_(other.types_), priority_(other.priority_) { }
      40           0 :         ~ServiceId( ) { }
      41             : 
      42           0 :         std::string id( ) const { return id_; }
      43           0 :         std::string uri( ) const { return uri_; }
      44             :         std::list<std::string> &types( ) { return types_; }
      45           0 :         const std::list<std::string> &types( ) const { return types_; }
      46             :         int priority( ) const { return priority_; }
      47             : 
      48             :         operator std::string( ) const { return id_; }
      49             : 
      50             :         bool operator<( const ServiceId &other ) const { return id_ < other.id_; }
      51             :         bool operator>( const ServiceId &other ) const { return id_ > other.id_; }
      52             :         bool operator==( const ServiceId &other ) const { return id_ == other.id_; }
      53             :         bool operator!=( const ServiceId &other ) const { return id_ != other.id_; }
      54             :         bool operator<=( const ServiceId &other ) const { return id_ <= other.id_; }
      55             :         bool operator>=( const ServiceId &other ) const { return id_ >= other.id_; }
      56             : 
      57             :         bool operator<( const std::string &id_o ) const { return id_ < id_o; }
      58             :         bool operator>( const std::string &id_o ) const { return id_ > id_o; }
      59           0 :         bool operator==( const std::string &id_o ) const { return id_ == id_o; }
      60             :         bool operator!=( const std::string &id_o ) const { return id_ != id_o; }
      61             :         bool operator<=( const std::string &id_o ) const { return id_ <= id_o; }
      62             :         bool operator>=( const std::string &id_o ) const { return id_ >= id_o; }
      63             : 
      64             :       private:
      65             :         std::string id_;
      66             :         std::string uri_;
      67             :         std::list<std::string> types_;
      68             :         int priority_;
      69             :     };
      70             :     
      71             :     class Registrar {
      72             :       public:
      73             : 
      74             :         Registrar( );
      75             : 
      76             :         virtual ~Registrar( );
      77             :         
      78             :         // get map of registrations
      79           0 :         std::list<ServiceId> services( ) {
      80           0 :             std::lock_guard<std::mutex> guard(service_list_mutex);
      81           0 :             return service_list;
      82             :         }
      83             : 
      84             :         // get list of service types
      85             :         std::list<std::string> types( ) {
      86             :             std::lock_guard<std::mutex> guard(service_list_mutex);
      87             :             std::set<std::string> result_set;
      88             :             std::for_each( service_list.begin(), service_list.end( ),
      89             :                            [&] (const ServiceId &sid) {
      90             :                                result_set.insert(sid.types( ).begin( ), sid.types( ).end( ) ); } );
      91             :             
      92             :             return std::list<std::string>(result_set.begin( ),result_set.end( ));
      93             :         }
      94             : 
      95             :         // returns true if a registration for 'id' was found
      96             :         bool remove( std::string id );
      97             : 
      98             :         // returns assigned identifier (likely based upon the proposed_id)
      99             :         ServiceId add( const ServiceId &proposed );
     100             : 
     101             :         std::string uri( ) {
     102             :             std::lock_guard<std::mutex> guard(uri_mutex);
     103             :             return uri_;
     104             :         }
     105             :         
     106             :       private:
     107             :         std::mutex service_list_mutex;
     108             :         std::list<ServiceId> service_list;
     109             :         std::mutex uri_mutex;
     110             :         std::string uri_;
     111             : #ifdef USE_GRPC
     112             :         void *grpc_state;
     113             : #endif
     114             :     };
     115             : 
     116             : }
     117             : 
     118             : #endif

Generated by: LCOV version 1.16