BusAccess.h

Go to the documentation of this file.
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 <stdexcept>
00035 
00036 namespace casa {
00037     namespace dbus {    
00038         // this function is a little odd... it gets a connection with a unique name
00039         // (via a suffix) using 'name' and upon success returns 'path', otherwise
00040         // it throws an exception...
00041         std::string adaptor_object( const std::string &name, const std::string &path );
00042         std::string object( const std::string &name );
00043         std::string path( const std::string &name );
00044 
00045         class address {
00046             public:
00047                     address( const std::string &bus_address, bool unique=true );
00048                         address( );
00049                         virtual ~address( );
00050                         std::string busName( ) const { return name_; }
00051             private:
00052                         std::string generate_name( const std::string &base, bool unique=true );
00053                         std::string name_;
00054         };
00055 
00056         char *launch_casa_proxy( bool unique_name, const std::string &dbusname, const std::string &default_name,  const std::list<std::string> &args );
00057 
00058         template<class proxy> proxy *launch( const std::list<std::string> &args=std::list<std::string>( ), bool unique_name=true,
00059                                              const std::string &name="", int trys=60, unsigned long delay=500000 ) {
00060             char *dbname = launch_casa_proxy( unique_name, name, proxy::dbusName( ), proxy::execArgs(args) );
00061             if ( dbname == 0 ) { throw  std::runtime_error( "launch failed" ); }
00062             proxy *result = 0;
00063             int count = trys;
00064             while ( count > 0 ) {
00065                 usleep(delay);
00066                 try {
00067                   result = new proxy(dbname);
00068                   break;
00069                 } catch (...) { }
00070                 --count;
00071             }
00072             delete [] dbname;
00073             return result;
00074         }
00075 
00076     }
00077 }
00078 
00079 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1