casa
$Rev:20696$
|
00001 //# QtDBusXmlApp.qo.h: Abstract parent to use the CASA DBus server. 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 #ifndef QTDBUSAPP_QO_H_ 00028 #define QTDBUSAPP_QO_H_ 00029 00030 #include <set> 00031 #include <string> 00032 #include <QString> 00033 #include <QDBusConnection> 00034 00035 namespace casa { 00036 00037 class QtDBusApp { 00038 public: 00039 static QDBusConnection connection( ); 00040 QString dbusServiceName( const QString &name, const pid_t pid ); 00041 QString dbusObjectName( const QString &name, const pid_t pid ); 00042 static QString serviceOwner( const QString &service ); 00043 static QString serviceOwner( const std::string &service ); 00044 const QString &dbusServiceName( const QString &name="" ); 00045 const QString &dbusObjectName( const QString &name="" ); 00046 static bool serviceIsAvailable(const QString &service); 00047 static bool serviceIsAvailable(const std::string &service); 00048 00049 virtual QString dbusName( ) const = 0; 00050 static QString generateServiceName( const QString &name, const pid_t pid ); 00051 00052 00053 QtDBusApp( ); 00054 virtual ~QtDBusApp( ); 00055 00056 // Connects to the DBus server using the name provided (if non-null). Otherwise, the 00057 // dbusName() method with the current process ID is used. Returns a boolean which 00058 // indicates whether the connection succeeded or not. 00059 virtual bool connectToDBus( const QString &dbus_name="" ) = 0; 00060 00061 protected: 00062 00063 bool connectToDBus( QObject *object, const QString &dbus_name="" ); 00064 00065 private: 00066 static const QString &serviceBase( ); 00067 static const QString &objectBase( ); 00068 QString *service_name; 00069 QString *object_name; 00070 }; 00071 00072 inline std::string to_string(const QString &other) { return std::string((const char*) other.toAscii().data()); } 00073 00074 } 00075 00076 #endif