15#include <dbus-cxx/dbus-cxx-config.h>
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"
51class ObjectPathHandler;
58class ThreadDispatcher;
73class 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 );
257 std::shared_ptr<Object>
create_object(
const std::string& path,
297 std::shared_ptr<ObjectProxy>
create_object_proxy(
const std::string& destination,
const std::string& path,
334 template<
typename... T_arg>
364 std::vector<std::shared_ptr<SignalProxyBase>>
get_free_signal_proxies(
const std::string& interface_name,
const std::string& member );
370 template <
class T_arg>
371 std::shared_ptr<Signal<T_arg> >
create_free_signal(
const std::string& path,
const std::string& interface_name,
const std::string& member ) {
372 std::shared_ptr<Signal<T_arg> > sig;
374 sig->set_connection( shared_from_this() );
378 std::string
introspect(
const std::string& destination,
const std::string& path );
428 std::shared_ptr<ReturnMessage>
send_with_reply_blocking_impl( std::shared_ptr<const CallMessage> msg,
int timeout_milliseconds,
bool disable_timeout );
449std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<DBus::Message> msg ) {
450 if( !ptr ) {
return ptr; }
457std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<const DBus::Message> msg ) {
458 if( !ptr ) {
return ptr; }
465std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<DBus::ReturnMessage> msg ) {
466 if( !ptr ) {
return ptr; }
473std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<const DBus::ReturnMessage> msg ) {
474 if( !ptr ) {
return ptr; }
481std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<DBus::SignalMessage> msg ) {
482 if( !ptr ) {
return ptr; }
489std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<const DBus::SignalMessage> msg ) {
490 if( !ptr ) {
return ptr; }
497std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<DBus::ErrorMessage> msg ) {
498 if( !ptr ) {
return ptr; }
505std::shared_ptr<DBus::Connection>
operator<<( std::shared_ptr<DBus::Connection> ptr, std::shared_ptr<const DBus::ErrorMessage> msg ) {
506 if( !ptr ) {
return ptr; }
Connection point to the DBus.
Definition: connection.h:73
int unix_fd() const
Definition: connection.cpp:884
uint32_t send(const std::shared_ptr< const Message > message)
Queues up the message to be sent on the bus.
Definition: connection.cpp:383
bool unregister_object(const std::string &path)
Unregister an object that has been added with register_object.
Definition: connection.cpp:1013
RequestNameResponse request_name(const std::string &name, unsigned int flags=0)
Request the given name on the bus.
Definition: connection.cpp:236
static std::shared_ptr< Connection > create(BusType type)
Connects to a bus daemon.
Definition: connection.cpp:180
bool is_authenticated() const
Definition: connection.cpp:365
~Connection()
Definition: connection.cpp:199
bool is_connected() const
Definition: connection.cpp:359
bool remove_match(const std::string &rule)
Definition: connection.cpp:335
bool is_anonymous() const
Definition: connection.cpp:371
void process_call_message(std::shared_ptr< const CallMessage > msg)
Definition: connection.cpp:697
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:906
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:845
bool add_match(const std::string &rule)
Definition: connection.cpp:305
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:1198
bool name_has_owner(const std::string &name) const
Check to see if the given name currently has an owner.
Definition: connection.cpp:284
sigc::signal< void()> & signal_needs_dispatch()
This signal is emitted whenever we need to be dispatched.
Definition: connection.cpp:902
void add_thread_dispatcher(std::weak_ptr< ThreadDispatcher > disp)
Add a thread dispatcher that will handle messages for a given thread.
Definition: connection.cpp:1215
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:579
void flush()
Flushes all data out to the bus.
Definition: connection.cpp:587
std::shared_ptr< ObjectProxy > create_object_proxy(const std::string &path, ThreadForCalling calling=ThreadForCalling::DispatcherThread)
Definition: connection.cpp:1001
Connection & operator<<(std::shared_ptr< const Message > msg)
Blindly sends the message on the connection.
Definition: connection.cpp:403
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:335
bool has_messages_to_send()
Definition: connection.cpp:896
std::string unique_name() const
Gets the unique name of the connection as assigned by the message bus.
Definition: connection.cpp:230
void process_single_message()
Definition: connection.cpp:653
std::thread::id thread_id_from_calling(ThreadForCalling calling)
Definition: connection.cpp:1314
Connection(BusType type)
Definition: connection.cpp:121
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:1205
void remove_invalid_threaddispatchers_and_associated_objects()
Definition: connection.cpp:1234
int socket() const
Definition: connection.cpp:890
RegistrationStatus register_object(std::shared_ptr< Object > object, ThreadForCalling calling=ThreadForCalling::DispatcherThread)
Register an object with this connection.
Definition: connection.cpp:918
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:1259
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:1042
std::shared_ptr< ReturnMessage > send_with_reply_blocking_impl(std::shared_ptr< const CallMessage > msg, int timeout_milliseconds, bool disable_timeout)
Definition: connection.cpp:409
void process_signal_message(std::shared_ptr< const SignalMessage > msg)
Definition: connection.cpp:764
std::shared_ptr< ReturnMessage > send_with_reply_blocking_notimeout(std::shared_ptr< const CallMessage > msg)
A timeout-less version of send_with_reply_blocking().
Definition: connection.cpp:583
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:371
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:1086
DispatchStatus dispatch_status() const
Definition: connection.cpp:608
const char * server_id() const
Definition: connection.cpp:377
bool is_valid() const
True if this is a valid connection; false otherwise.
Definition: connection.cpp:206
std::string introspect(const std::string &destination, const std::string &path)
Definition: connection.cpp:1164
bool is_registered() const
True if this connection is already registered.
Definition: connection.cpp:226
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:983
void add_match_nonblocking(const std::string &rule)
Definition: connection.cpp:330
StartReply start_service(const std::string &name, uint32_t flags=0) const
start_service
Definition: connection.cpp:288
ReleaseNameResponse release_name(const std::string &name)
Release the specified name, after requesting it via request_name.
Definition: connection.cpp:264
uint32_t write_single_message(std::shared_ptr< const Message > msg)
Write a single message, return the serial of this message.
Definition: connection.cpp:602
bool unregister_object_proxy(ObjectProxy *obj)
Definition: connection.cpp:1291
DispatchStatus dispatch()
Dispatch the connection.
Definition: connection.cpp:614
const std::vector< std::shared_ptr< SignalProxyBase > > get_free_signal_proxies()
Gets all the free signal handlers.
Definition: connection.cpp:1128
bool register_object_proxy(std::shared_ptr< ObjectProxy > obj, ThreadForCalling calling=ThreadForCalling::DispatcherThread)
Add an ObjectProxy to this Connection.
Definition: connection.cpp:1279
bool bus_register()
Registers this connection with the bus.
Definition: connection.cpp:210
Object proxies are local proxies that provide local methods and signals for remote objects with dbus ...
Definition: objectproxy.h:45
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:449
StartReply
Definition: enums.h:108
BusType
Definition: enums.h:16
ReleaseNameResponse
Definition: enums.h:167
DataType type(const uint8_t &)
Definition: types.h:139
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.