Free memory with dbus_free instead of free. Account for NULL signatures.
[dbus-cxx-async.git] / include / dbus-c++ / connection.h
blob4d7a9324b71a7d406eb87987f7a453dac1246654
1 /*
3 * D-Bus++ - C++ bindings for D-Bus
5 * Copyright (C) 2005-2009 Paolo Durante <shackan@gmail.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifndef __DBUSXX_CONNECTION_H
26 #define __DBUSXX_CONNECTION_H
28 #include <list>
30 #include "api.h"
31 #include "types.h"
32 #include "util.h"
33 #include "message.h"
34 #include "pendingcall.h"
36 namespace DBus {
38 class Connection;
40 typedef Slot<bool, const Message &> MessageSlot;
42 typedef std::list<Connection> ConnectionList;
44 class ObjectAdaptor;
45 class ObjectProxy;
46 class Dispatcher;
48 class DBUSXXAPI Connection
50 public:
52 static Connection system_bus(Dispatcher *dispatcher = NULL);
53 static Connection system_bus_private(Dispatcher *dispatcher = NULL);
55 static Connection session_bus(Dispatcher *dispatcher = NULL);
56 static Connection session_bus_private(Dispatcher *dispatcher = NULL);
58 static Connection activation_bus(Dispatcher *dispatcher = NULL);
59 static Connection activation_bus_private(Dispatcher *dispatcher = NULL);
61 struct Private;
63 typedef std::list<Private *> PrivatePList;
65 Connection();
67 Connection(RefPtrI<Private>);
69 Connection(const char *address, bool priv, Dispatcher *dispatcher = NULL);
71 Connection(const Connection &c);
73 virtual ~Connection();
75 bool operator == (const Connection &) const;
77 Connection &operator = (const Connection &);
79 void add_match(const char *rule);
81 void remove_match(const char *rule);
83 bool add_filter(MessageSlot &);
85 void remove_filter(MessageSlot &);
87 bool unique_name(const char *n);
89 const char *unique_name() const;
91 bool register_bus();
93 bool connected() const;
95 void disconnect();
97 void exit_on_disconnect(bool exit);
99 void flush();
101 bool send(const Message &, unsigned int *serial = NULL);
103 Message send_blocking(Message &msg, int timeout = -1);
105 PendingCall send_async(Message &msg, ObjectProxy *proxy, const PendingCallSlot &slot, void* data, int timeout);
107 void request_name(const char *name, int flags = 0);
109 bool has_name(const char *name);
111 bool start_service(const char *name, unsigned long flags);
113 const std::vector<std::string>& names();
115 private:
117 DBUSXXAPILOCAL void init();
119 private:
121 RefPtrI<Private> _pvt;
123 friend class ObjectAdaptor; // needed in order to register object paths for a connection
126 class DBUSXXAPI CallInfo
128 public:
130 CallInfo();
131 CallInfo(const Connection &c, const Message &m);
132 CallInfo(const Connection &c, const PendingCall &pc);
134 const Connection &conn() const { return _conn; }
135 const Message &msg() const { return _msg; }
136 const Error &error() const { return _error; }
138 uint32_t sender_pid();
139 uint32_t sender_uid();
141 CallInfo &operator = (const CallInfo& info);
143 protected:
145 Connection _conn;
146 Message _msg;
147 Error _error;
150 } /* namespace DBus */
152 #endif//__DBUSXX_CONNECTION_H