casa
$Rev:20696$
|
00001 //# BusAccess.h: tools for getting access to a dbus object 00002 //# Copyright (C) 2009 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id$ 00027 00028 #ifndef DBUS_BUSACCESS_H_ 00029 #define DBUS_BUSACCESS_H_ 00030 #include <list> 00031 #include <string> 00032 #include <cstdio> 00033 #include <unistd.h> 00034 #include <casa/Exceptions/Error.h> 00035 00036 namespace casa { 00037 namespace dbus { 00038 std::string adaptor_object( const std::string &name ); 00039 std::string object( const std::string &name ); 00040 std::string path( const std::string &name ); 00041 00042 char *launch_casa_proxy( bool unique_name, const std::string &dbusname, const std::string &default_name, const std::list<std::string> &args ); 00043 00044 template<class proxy> proxy *launch( const std::list<std::string> &args=std::list<std::string>( ), bool unique_name=true, 00045 const std::string &name="", int trys=60, unsigned long delay=500000 ) { 00046 char *dbname = launch_casa_proxy( unique_name, name, proxy::dbusName( ), proxy::execArgs(args) ); 00047 if ( dbname == 0 ) { throw AipsError("launch failed"); } 00048 proxy *result = 0; 00049 int count = trys; 00050 while ( count > 0 ) { 00051 usleep(delay); 00052 try { 00053 result = new proxy(dbname); 00054 break; 00055 } catch (...) { } 00056 --count; 00057 } 00058 delete [] dbname; 00059 return result; 00060 } 00061 00062 } 00063 } 00064 00065 #endif