Source
xxxxxxxxxx
auto search = find_if(service_list.begin(), service_list.end(), [=](const ServiceId &id) { return id == (proposed.id() + buf); });
//# Registrar.cc: maintain registry of services
//# Copyright (C) 2017
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: aips2-request@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
//#
using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using std::find_if;
namespace casatools { /** namespace for CASAtools classes within "CASA code" **/
// generated stubs/base-classes are in casatools::rpc namespace...
class grpcRegistrar final : public rpc::Registrar::Service {
Status add( ServerContext* context, const rpc::ServiceId* req, rpc::ServiceId* reply) override {
std::lock_guard<std::mutex> guard(registry_mutex);
if ( registry == 0 || req->id( ).size( ) == 0 ||
req->type( ).size( ) == 0 || req->uri( ).size( ) == 0 )
return Status::CANCELLED;
ServiceId actual = registry->add(ServiceId(req->id( ),req->type( ),req->uri( )));
reply->set_id(actual.id( ));
reply->set_type(actual.type( ));
reply->set_uri(actual.uri( ));
return Status::OK;
}
Status remove( ServerContext* context, const rpc::ServiceId* req, ::google::protobuf::BoolValue* reply) override {
std::lock_guard<std::mutex> guard(registry_mutex);
if ( registry == 0 || req->id( ).size( ) == 0 )
return Status::CANCELLED;
reply->set_value(registry->remove(req->id( )));
return Status::OK;
}
Status services( ServerContext* context, const ::google::protobuf::Empty* req, rpc::ServiceIds* reply) override {
std::list<ServiceId> services;
{
std::lock_guard<std::mutex> guard(registry_mutex);
if ( registry == 0 )
return Status::CANCELLED;
services = registry->services( );
}
for ( std::list<ServiceId>::const_iterator ci = services.begin( ); ci != services.end( ); ++ci ) {
rpc::ServiceId *serv = reply->add_service( );
serv->set_id(ci->id( ));
serv->set_type(ci->type( ));
serv->set_uri(ci->uri( ));
}
return Status::OK;
}
std::mutex registry_mutex;
Registrar *registry;