Source
//# 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->types( ).size( ) == 0 || req->uri( ).size( ) == 0 )
return Status::CANCELLED;
// ServiceId actual = registry->add(ServiceId(req->id( ),req->uri( ),std::list<std::string>(req->types( ).begin( ),req->types( ).end( ))));
std::list<std::string> service_types(req->types( ).begin( ),req->types( ).end( ));
ServiceId actual = registry->add(ServiceId(req->id( ),req->uri( ),service_types));
reply->set_id(actual.id( ));
reply->set_uri(actual.uri( ));
std::for_each( service_types.begin( ), service_types.end( ),
[&] (const std::string &s) { reply->add_types(s); } );
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
// -bash-4.2$ GRPC_DEBUG=1 /opt/rh/rh-python36/root/usr/bin/python3
// Python 3.6.3 (default, Jan 9 2018, 10:19:07)
// [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
// Type "help", "copyright", "credits" or "license" for more information.
// >>> from casatools import ctsys
// registry available at 0.0.0.0:39189
// >>> <1> image-view
// <1> interactive-clean
// <2> image-view
// <2> interactive-clean
// <2> ??
// <2> image-view
// <2> interactive-clean
// <2> ??
// <2> image-view
// <2> interactive-clean
// <2> ??
// <2> image-view
// <2> interactive-clean
// <2> ??
// <2> image-view
// <2> interactive-clean
// <2> ??
// <2> image-view
// <2> interactive-clean
// <2> ??
// <2> image-view
// <2> interactive-clean
// <2> ??