dbus-cxx logo

interfaceproxy.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007,2008,2009 by Rick L. Vinyard, Jr.                  *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This file is part of the dbus-cxx library.                            *
00006  *                                                                         *
00007  *   The dbus-cxx library is free software; you can redistribute it and/or *
00008  *   modify it under the terms of the GNU General Public License           *
00009  *   version 3 as published by the Free Software Foundation.               *
00010  *                                                                         *
00011  *   The dbus-cxx library is distributed in the hope that it will be       *
00012  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty   *
00013  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00014  *   General Public License for more details.                              *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this software. If not see <http://www.gnu.org/licenses/>.  *
00018  ***************************************************************************/
00019 #ifndef DBUSCXXINTERFACEPROXY_H
00020 #define DBUSCXXINTERFACEPROXY_H
00021 
00022 #include <sigc++/sigc++.h>
00023 
00024 #include <string>
00025 #include <map>
00026 #include <set>
00027 
00028 #include <dbus-cxx/methodproxy.h>
00029 #include <dbus-cxx/signal_proxy.h>
00030 
00031 namespace DBus {
00032 
00033   class ObjectProxy;
00034 
00041   class InterfaceProxy
00042   {
00043     protected:
00044       InterfaceProxy(const std::string& name);
00045 
00046     public:
00047       typedef DBusCxxPointer<InterfaceProxy> pointer;
00048 
00049       typedef DBusCxxWeakPointer<InterfaceProxy> weak_pointer;
00050       
00051       typedef std::multimap<std::string, MethodProxyBase::pointer> Methods;
00052 
00053       typedef std::set<signal_proxy_base::pointer> Signals;
00054 
00055       static pointer create( const std::string& name = std::string() );
00056 
00057       virtual ~InterfaceProxy();
00058 
00059       ObjectProxy* object() const;
00060 
00061       std::string path() const;
00062 
00063       DBusCxxPointer<Connection> connection() const;
00064 
00065       const std::string& name() const;
00066 
00067       void set_name( const std::string& new_name );
00068 
00069       const Methods& methods() const;
00070 
00072       MethodProxyBase::pointer method( const std::string& name ) const;
00073 
00074       template <class T_return, class T_arg1=nil, class T_arg2=nil, class T_arg3=nil, class T_arg4=nil, class T_arg5=nil, class T_arg6=nil, class T_arg7=nil>
00075       DBusCxxPointer<MethodProxy<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7> > create_method( const std::string& name )
00076       {
00077         DBusCxxPointer< MethodProxy<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7> > method;
00078         method = MethodProxy<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7>::create(name);
00079         this->add_method( method );
00080         return method;
00081       }
00082 
00084       bool add_method( MethodProxyBase::pointer method );
00085 
00087       void remove_method( const std::string& name );
00088 
00090       void remove_method( MethodProxyBase::pointer method );
00091 
00093       bool has_method( const std::string& name ) const;
00094 
00096       bool has_method( MethodProxyBase::pointer method ) const;
00097       
00098       CallMessage::pointer create_call_message( const std::string& method_name ) const;
00099 
00100       ReturnMessage::const_pointer call( CallMessage::const_pointer, int timeout_milliseconds=-1 ) const;
00101 
00102       PendingCall::pointer call_async( CallMessage::const_pointer, int timeout_milliseconds=-1 ) const;
00103 
00104       template <class T_return, class T_arg1=nil, class T_arg2=nil, class T_arg3=nil, class T_arg4=nil, class T_arg5=nil, class T_arg6=nil, class T_arg7=nil>
00105       DBusCxxPointer<signal_proxy<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7> > create_signal( const std::string& sig_name )
00106       {
00107         DBusCxxPointer< signal_proxy<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7> > sig;
00108         sig = signal_proxy<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7>::create(this->path(), m_name, sig_name);
00109         this->add_signal( sig );
00110         return sig;
00111       }
00112 
00113       const Signals& signals() const;
00114 
00115       signal_proxy_base::pointer signal( const std::string& signame );
00116 
00117       bool add_signal( signal_proxy_base::pointer sig );
00118 
00119       bool remove_signal( const std::string& signame );
00120 
00121       bool remove_signal( signal_proxy_base::pointer sig );
00122 
00123       bool has_signal( const std::string& signame ) const;
00124 
00125       bool has_signal( signal_proxy_base::pointer sig ) const;
00126 
00128       sigc::signal<void,const std::string&/*old name*/,const std::string&/*new name*/> signal_name_changed();
00129 
00131       sigc::signal<void,MethodProxyBase::pointer> signal_method_added();
00132 
00134       sigc::signal<void,MethodProxyBase::pointer> signal_method_removed();
00135 
00136     protected:
00137 
00138       friend class ObjectProxy;
00139       
00140       ObjectProxy* m_object;
00141       
00142       std::string m_name;
00143       
00144       Methods m_methods;
00145 
00146       Signals m_signals;
00147 
00148       mutable pthread_rwlock_t m_methods_rwlock;
00149 
00151       pthread_mutex_t m_name_mutex;
00152 
00153       sigc::signal<void,const std::string&,const std::string&> m_signal_name_changed;
00154       
00155       sigc::signal<void,MethodProxyBase::pointer> m_signal_method_added;
00156       
00157       sigc::signal<void,MethodProxyBase::pointer> m_signal_method_removed;
00158 
00159       typedef std::map<MethodProxyBase::pointer,sigc::connection> MethodSignalNameConnections;
00160 
00161       MethodSignalNameConnections m_method_signal_name_connections;
00162 
00163       void on_method_name_changed(const std::string& oldname, const std::string& newname, MethodProxyBase::pointer method);
00164 
00165       void on_object_set_connection( DBusCxxPointer<Connection> conn );
00166 
00167       void on_object_set_path( const std::string& path );
00168   };
00169 
00170 }
00171 
00172 #endif
00173 

Generated on Thu May 28 16:50:50 2009 for dbus-cxx by doxygen 1.5.7.1