22 #include <sigc++/sigc++.h>
26 #ifndef DBUSCXX_CONNECTION_H
27 #define DBUSCXX_CONNECTION_H
30 #define DBUSCXX_NAME_FLAG_ALLOW_REPLACEMENT 0x01
32 #define DBUSCXX_NAME_FLAG_REPLACE_EXISTING 0x02
34 #define DBUSCXX_NAME_FLAG_DO_NOT_QUEUE 0x04
36 #define DBUSCXX_INTERFACE_INTROSPECTABLE "org.freedesktop.DBus.Introspectable"
38 #define DBUSCXX_INTROSPECT_1_0_XML_NAMESPACE "http://www.freedesktop.org/standards/dbus"
40 #define DBUSCXX_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
42 #define DBUSCXX_INTROSPECT_1_0_XML_SYSTEM_IDENTIFIER "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"
44 #define DBUSCXX_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE "<!DOCTYPE node PUBLIC \""\
45 DBUSCXX_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER "\"\n\"" DBUSCXX_INTROSPECT_1_0_XML_SYSTEM_IDENTIFIER "\">\n"
51 class ObjectPathHandler;
58 class ThreadDispatcher;
60 class DBusDaemonProxy;
73 class Connection :
public std::enable_shared_from_this<Connection> {
100 static std::shared_ptr<Connection>
create( std::string address );
105 operator bool()
const;
164 bool add_match(
const std::string& rule );
184 uint32_t
send(
const std::shared_ptr<const Message> message );
201 std::shared_ptr<ReturnMessage>
send_with_reply_blocking( std::shared_ptr<const CallMessage> msg,
int timeout_milliseconds = -1 );
252 std::shared_ptr<Object>
create_object(
const std::string& path,
292 std::shared_ptr<ObjectProxy>
create_object_proxy(
const std::string& destination,
const std::string& path,
318 template<
typename... T_arg>
348 std::vector<std::shared_ptr<SignalProxyBase>>
get_free_signal_proxies(
const std::string& interface_name,
const std::string& member );
354 template <
class T_arg>
355 std::shared_ptr<Signal<T_arg> >
create_free_signal(
const std::string& path,
const std::string& interface_name,
const std::string& member ) {
356 std::shared_ptr<Signal<T_arg> > sig;
358 sig->set_connection( shared_from_this() );
362 std::string
introspect(
const std::string& destination,
const std::string& path );
431 std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<DBus::Message> msg ) {
432 if( !ptr ) {
return ptr; }
439 std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<const DBus::Message> msg ) {
440 if( !ptr ) {
return ptr; }
447 std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<DBus::ReturnMessage> msg ) {
448 if( !ptr ) {
return ptr; }
455 std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<const DBus::ReturnMessage> msg ) {
456 if( !ptr ) {
return ptr; }
463 std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<DBus::SignalMessage> msg ) {
464 if( !ptr ) {
return ptr; }
471 std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<const DBus::SignalMessage> msg ) {
472 if( !ptr ) {
return ptr; }
479 std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<DBus::ErrorMessage> msg ) {
480 if( !ptr ) {
return ptr; }
487 std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<const DBus::ErrorMessage> msg ) {
488 if( !ptr ) {
return ptr; }
Connection point to the DBus.
Definition: connection.h:73
int unix_fd() const
Definition: connection.cpp:797
uint32_t send(const std::shared_ptr< const Message > message)
Queues up the message to be sent on the bus.
Definition: connection.cpp:371
bool unregister_object(const std::string &path)
Definition: connection.cpp:890
RequestNameResponse request_name(const std::string &name, unsigned int flags=0)
Request the given name on the bus.
Definition: connection.cpp:233
static std::shared_ptr< Connection > create(BusType type)
Connects to a bus daemon.
Definition: connection.cpp:183
bool is_authenticated() const
Definition: connection.cpp:353
~Connection()
Definition: connection.cpp:196
bool is_connected() const
Definition: connection.cpp:347
bool remove_match(const std::string &rule)
Definition: connection.cpp:329
bool is_anonymous() const
Definition: connection.cpp:359
void process_call_message(std::shared_ptr< const CallMessage > msg)
Definition: connection.cpp:659
std::shared_ptr< Object > create_object(const std::string &path, ThreadForCalling calling=ThreadForCalling::DispatcherThread)
Create and return a new object, registering the object automatically.
Definition: connection.cpp:819
void send_error_on_handler_result(std::shared_ptr< const CallMessage > msg, HandlerResult result)
Send an error back to the calling application based on HandlerResult.
Definition: connection.cpp:758
bool add_match(const std::string &rule)
Definition: connection.cpp:302
DBUS_CXX_PROPAGATE_CONST(std::unique_ptr< priv_data >) m_priv
void set_dispatching_thread(std::thread::id tid)
Set the ID of the thread that all of the dispatching hapens from.
Definition: connection.cpp:1047
bool name_has_owner(const std::string &name) const
Check to see if the given name currently has an owner.
Definition: connection.cpp:281
sigc::signal< void()> & signal_needs_dispatch()
This signal is emitted whenever we need to be dispatched.
Definition: connection.cpp:815
void add_thread_dispatcher(std::weak_ptr< ThreadDispatcher > disp)
Add a thread dispatcher that will handle messages for a given thread.
Definition: connection.cpp:1061
std::shared_ptr< ReturnMessage > send_with_reply_blocking(std::shared_ptr< const CallMessage > msg, int timeout_milliseconds=-1)
Send a CallMessage, and wait for the reply.
Definition: connection.cpp:397
void flush()
Flushes all data out to the bus.
Definition: connection.cpp:552
std::shared_ptr< ObjectProxy > create_object_proxy(const std::string &path, ThreadForCalling calling=ThreadForCalling::DispatcherThread)
Definition: connection.cpp:878
Connection & operator<<(std::shared_ptr< const Message > msg)
Blindly sends the message on the connection.
Definition: connection.cpp:391
std::shared_ptr< Signal< T_arg > > create_free_signal(const std::string &path, const std::string &interface_name, const std::string &member)
Create a free signal, that when it is emitted will send that signal over the DBus.
Definition: connection.h:355
bool has_messages_to_send()
Definition: connection.cpp:809
std::string unique_name() const
Gets the unique name of the connection as assigned by the message bus.
Definition: connection.cpp:227
void process_single_message()
Definition: connection.cpp:615
std::thread::id thread_id_from_calling(ThreadForCalling calling)
Definition: connection.cpp:1129
Connection(BusType type)
Definition: connection.cpp:124
void notify_dispatcher_or_dispatch()
Depending on what thread this is called from, will either notify the dispatcher that we need to be di...
Definition: connection.cpp:1051
void remove_invalid_threaddispatchers_and_associated_objects()
Definition: connection.cpp:1066
int socket() const
Definition: connection.cpp:803
RegistrationStatus register_object(std::shared_ptr< Object > object, ThreadForCalling calling=ThreadForCalling::DispatcherThread)
Register an object with this connection.
Definition: connection.cpp:831
bool change_object_proxy_calling_thread(std::shared_ptr< ObjectProxy > object, ThreadForCalling calling)
Change the thread that the signals on this ObjectProxy will be called from.
Definition: connection.cpp:1098
std::shared_ptr< SignalProxyBase > add_free_signal_proxy(std::shared_ptr< SignalProxyBase > Signal, ThreadForCalling calling=ThreadForCalling::DispatcherThread)
Adds the given signal proxy to the connection.
Definition: connection.cpp:903
void process_signal_message(std::shared_ptr< const SignalMessage > msg)
Definition: connection.cpp:707
bool remove_free_signal_proxy(std::shared_ptr< SignalProxyBase > proxy)
Remove a free signal proxy, so that it will not be called anymore.
Definition: connection.cpp:947
DispatchStatus dispatch_status() const
Definition: connection.cpp:573
const char * server_id() const
Definition: connection.cpp:365
std::shared_ptr< SignalProxy< T_arg... > > create_free_signal_proxy(const SignalMatchRule &rule, ThreadForCalling calling=ThreadForCalling::DispatcherThread)
Create and return a signal proxy that lets you listen to signals sent on the DBus as a free proxy.
Definition: connection.h:319
bool is_valid() const
True if this is a valid connection; false otherwise.
Definition: connection.cpp:203
std::string introspect(const std::string &destination, const std::string &path)
Definition: connection.cpp:1025
bool is_registered() const
True if this connection is already registered.
Definition: connection.cpp:223
bool change_object_calling_thread(std::shared_ptr< Object > object, ThreadForCalling calling)
Change the thread that the methods on this object will be called from.
Definition: connection.cpp:858
void add_match_nonblocking(const std::string &rule)
Definition: connection.cpp:324
StartReply start_service(const std::string &name, uint32_t flags=0) const
start_service
Definition: connection.cpp:285
ReleaseNameResponse release_name(const std::string &name)
Release the specified name, after requesting it via request_name.
Definition: connection.cpp:261
uint32_t write_single_message(std::shared_ptr< const Message > msg)
Write a single message, return the serial of this message.
Definition: connection.cpp:567
DispatchStatus dispatch()
Dispatch the connection.
Definition: connection.cpp:579
const std::vector< std::shared_ptr< SignalProxyBase > > get_free_signal_proxies()
Gets all the free signal handlers.
Definition: connection.cpp:989
bool register_object_proxy(std::shared_ptr< ObjectProxy > obj, ThreadForCalling calling=ThreadForCalling::DispatcherThread)
Add an ObjectProxy to this Connection.
Definition: connection.cpp:1117
bool bus_register()
Registers this connection with the bus.
Definition: connection.cpp:207
A special MatchRule for signals.
Definition: matchrule.h:45
Definition: signalproxy.h:26
Definition: transport.h:22
Global DBus namespace, where everything happens.
Definition: callmessage.cpp:18
DispatchStatus
Definition: enums.h:89
std::shared_ptr< DBus::Connection > operator<<(std::shared_ptr< DBus::Connection > ptr, std::shared_ptr< DBus::Message > msg)
Definition: connection.h:431
StartReply
Definition: enums.h:108
BusType
Definition: enums.h:16
ReleaseNameResponse
Definition: enums.h:167
DataType type(const uint8_t &)
Definition: types.h:137
HandlerResult
Definition: enums.h:95
RequestNameResponse
Response status to attempting to register a name on the bus.
Definition: enums.h:156
RegistrationStatus
Definition: enums.h:119
ThreadForCalling
Gives hints to the connection as to which thread should be the one to call the methods on the given o...
Definition: enums.h:133
@ DispatcherThread
Always call methods for this object from the dispatcher thread.