connection.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *  D-Bus++ - C++ bindings for D-Bus
00004  *
00005  *  Copyright (C) 2005-2007  Paolo Durante <shackan@gmail.com>
00006  *
00007  *
00008  *  This library is free software; you can redistribute it and/or
00009  *  modify it under the terms of the GNU Lesser General Public
00010  *  License as published by the Free Software Foundation; either
00011  *  version 2.1 of the License, or (at your option) any later version.
00012  *
00013  *  This library is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  *  Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public
00019  *  License along with this library; if not, write to the Free Software
00020  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00024 
00025 #ifndef __DBUSXX_CONNECTION_H
00026 #define __DBUSXX_CONNECTION_H
00027 
00028 #include <list>
00029 
00030 #include "api.h"
00031 #include "types.h"
00032 #include "util.h"
00033 #include "message.h"
00034 #include "pendingcall.h"
00035 
00036 namespace DBus
00037 {
00038 
00039 class Connection;
00040 
00041 typedef Slot<bool, const Message &> MessageSlot;
00042 
00043 typedef std::list<Connection> ConnectionList;
00044 
00045 class ObjectAdaptor;
00046 class Dispatcher;
00047 
00048 class DXXAPI Connection
00049 {
00050 public:
00051 
00052   static Connection SystemBus();
00053 
00054   static Connection SessionBus();
00055 
00056   static Connection ActivationBus();
00057 
00058   struct Private;
00059 
00060   typedef std::list<Private *> PrivatePList;
00061 
00062   Connection(Private *);
00063 
00064   Connection(const char *address, bool priv = true);
00065 
00066   Connection(const Connection &c);
00067 
00068   virtual ~Connection();
00069 
00070   Dispatcher *setup(Dispatcher *);
00071 
00072   bool operator == (const Connection &) const;
00073 
00130   void add_match(const char *rule);
00131 
00144   void remove_match(const char *rule, bool    throw_on_error);
00145 
00157   bool add_filter(MessageSlot &s);
00158 
00168   void remove_filter(MessageSlot &s);
00169 
00200   bool unique_name(const char *n);
00201 
00217   const char *unique_name() const;
00218 
00263   bool register_bus();
00264 
00276   bool connected() const;
00277 
00315   void disconnect();
00316 
00329   void exit_on_disconnect(bool exit);
00330 
00334   void flush();
00335 
00356   bool send(const Message &msg, unsigned int *serial = NULL);
00357 
00383   Message send_blocking(Message &msg, int timeout = -1);
00384 
00410   PendingCall send_async(Message &msg, int timeout = -1);
00411 
00412   void request_name(const char *name, int flags = 0);
00413 
00414   unsigned long sender_unix_uid(const char *sender);
00415 
00429   bool has_name(const char *name);
00430 
00447   bool start_service(const char *name, unsigned long flags);
00448 
00449   const std::vector<std::string>& names();
00450 
00451   void set_timeout(int timeout);
00452 
00453   int get_timeout();
00454 
00455 private:
00456 
00457   DXXAPILOCAL void init();
00458 
00459 private:
00460 
00461   RefPtrI<Private> _pvt;
00462   int _timeout;
00463 
00464   friend class ObjectAdaptor; // needed in order to register object paths for a connection
00465 };
00466 
00467 } /* namespace DBus */
00468 
00469 #endif//__DBUSXX_CONNECTION_H