casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BusAccess.h
Go to the documentation of this file.
1 //# BusAccess.h: tools for getting access to a dbus object
2 //# Copyright (C) 2009
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 //# $Id$
27 
28 #ifndef DBUS_BUSACCESS_H_
29 #define DBUS_BUSACCESS_H_
30 #include <list>
31 #include <string>
32 #include <cstdio>
33 #include <unistd.h>
34 #include <stdexcept>
35 
36 namespace casa {
37  namespace dbus {
38  // this function is a little odd... it gets a connection with a unique name
39  // (via a suffix) using 'name' and upon success returns 'path', otherwise
40  // it throws an exception...
41  std::string adaptor_object( const std::string &name, const std::string &path );
42  std::string object( const std::string &name );
43  std::string path( const std::string &name );
44 
45  class address {
46  public:
47  address( const std::string &bus_address, bool unique=true );
48  address( );
49  virtual ~address( );
50  std::string busName( ) const { return name_; }
51  private:
52  std::string generate_name( const std::string &base, bool unique=true );
53  std::string name_;
54  };
55 
56  char *launch_casa_proxy( bool unique_name, const std::string &dbusname, const std::string &default_name, const std::list<std::string> &args );
57 
58  template<class proxy> proxy *launch( const std::list<std::string> &args=std::list<std::string>( ), bool unique_name=true,
59  const std::string &name="", int trys=60, unsigned long delay=500000 ) {
60  char *dbname = launch_casa_proxy( unique_name, name, proxy::dbusName( ), proxy::execArgs(args) );
61  if ( dbname == 0 ) { throw std::runtime_error( "launch failed" ); }
62  proxy *result = 0;
63  int count = trys;
64  while ( count > 0 ) {
65  usleep(delay);
66  try {
67  result = new proxy(dbname);
68  break;
69  } catch (...) { }
70  --count;
71  }
72  delete [] dbname;
73  return result;
74  }
75 
76  }
77 }
78 
79 #endif
std::string busName() const
Definition: BusAccess.h:50
char * launch_casa_proxy(bool unique_name, const std::string &dbusname, const std::string &default_name, const std::list< std::string > &args)
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
proxy * launch(const std::list< std::string > &args=std::list< std::string >(), bool unique_name=true, const std::string &name="", int trys=60, unsigned long delay=500000)
Definition: BusAccess.h:58
std::string object(const std::string &name)
std::string path(const std::string &name)
std::string name_
Definition: BusAccess.h:53
std::string generate_name(const std::string &base, bool unique=true)
std::string adaptor_object(const std::string &name, const std::string &path)
this function is a little odd...