public final class DBusConnection extends AbstractConnection
This is a Singleton class, only 1 connection to the SYSTEM or SESSION busses can be made. Repeated calls to getConnection will return the same reference.
Signal Handlers and method calls from remote objects are run in their own threads, you MUST handle the concurrency issues.
| Modifier and Type | Class and Description |
|---|---|
static class |
DBusConnection.DBusBusType |
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_SYSTEM_BUS_ADDRESS |
BUSNAME_REGEX, CONNID_REGEX, DOLLAR_PATTERN, FLOAT_SUPPORT, MAX_ARRAY_LENGTH, MAX_NAME_LENGTH, OBJECT_REGEX, TCP_CONNECT_TIMEOUT| Modifier and Type | Method and Description |
|---|---|
void |
addGenericSigHandler(DBusMatchRule _rule,
DBusSigHandler<DBusSignal> _handler)
Adds a
DBusMatchRule to with a generic signal handler. |
<T extends DBusSignal> |
addSigHandler(Class<T> _type,
String _source,
DBusInterface _object,
DBusSigHandler<T> _handler)
Add a Signal Handler.
|
<T extends DBusSignal> |
addSigHandler(Class<T> _type,
String _source,
DBusSigHandler<T> _handler)
Add a Signal Handler.
|
<T extends DBusSignal> |
addSigHandler(DBusMatchRule _rule,
DBusSigHandler<T> _handler)
Add a signal handler with the given
DBusMatchRule to DBus. |
void |
close()
Same as disconnect.
|
void |
disconnect()
Disconnect from the Bus.
|
protected DBusInterface |
dynamicProxy(String _source,
String _path) |
static DBusConnection |
getConnection(DBusConnection.DBusBusType _bustype)
Connect to DBus.
|
static DBusConnection |
getConnection(DBusConnection.DBusBusType _bustype,
boolean _shared,
int _timeout)
Connect to the BUS.
|
static DBusConnection |
getConnection(String _address)
Connect to the BUS.
|
static DBusConnection |
getConnection(String _address,
boolean _registerSelf,
boolean _shared)
Connect to the BUS.
|
static DBusConnection |
getConnection(String _address,
boolean _registerSelf,
boolean _shared,
int _timeout)
Connect to the BUS.
|
static String |
getDbusMachineId()
Extracts the machine-id usually found in /var/lib/dbus/machine-id.
|
DBusInterface |
getExportedObject(String _source,
String _path) |
String |
getMachineId()
The generated UUID of this machine.
|
String[] |
getNames()
Returns all the names owned by this connection.
|
DBusInterface |
getPeerRemoteObject(String _busname,
String _objectpath)
Return a reference to a remote object.
|
<I extends DBusInterface> |
getPeerRemoteObject(String _busname,
String _objectpath,
Class<I> _type) |
<I extends DBusInterface> |
getPeerRemoteObject(String _busname,
String _objectpath,
Class<I> _type,
boolean _autostart)
Return a reference to a remote object.
|
DBusInterface |
getRemoteObject(String _busname,
String _objectpath)
Return a reference to a remote object.
|
<I extends DBusInterface> |
getRemoteObject(String _busname,
String _objectpath,
Class<I> _type)
Return a reference to a remote object.
|
<I extends DBusInterface> |
getRemoteObject(String _busname,
String _objectpath,
Class<I> _type,
boolean _autostart)
Return a reference to a remote object.
|
String |
getUniqueName()
Returns the unique name of this connection.
|
static DBusConnection |
newConnection(DBusConnection.DBusBusType _bustype)
Connect to DBus using a new connection even if there is already a connection established.
|
void |
releaseBusName(String _busname)
Release a bus name.
|
void |
removeGenericSigHandler(DBusMatchRule _rule,
DBusSigHandler<DBusSignal> _handler)
Remove a generic signal handler with the given
DBusMatchRule. |
<T extends DBusSignal> |
removeSigHandler(Class<T> _type,
String _source,
DBusInterface _object,
DBusSigHandler<T> _handler)
Remove a Signal Handler.
|
<T extends DBusSignal> |
removeSigHandler(Class<T> _type,
String _source,
DBusSigHandler<T> _handler)
Remove a Signal Handler.
|
protected <T extends DBusSignal> |
removeSigHandler(DBusMatchRule _rule,
DBusSigHandler<T> _handler)
Remove a match rule with the given
DBusSigHandler. |
void |
requestBusName(String _busname)
Request a bus name.
|
addFallback, addSigHandler, addSigHandler, addSigHandlerWithoutMatch, callMethodAsync, callWithCallback, changeThreadCount, disconnect, exportObject, getAddress, getCallInfo, getEndianness, getError, getExportedObject, getExportedObjects, getGenericHandledSignals, getHandledSignals, getImportedObjects, getObjectTree, getPendingCalls, getPendingErrorQueue, getSystemEndianness, handleException, isConnected, listen, queueCallback, removeFallback, removeSigHandler, removeSigHandler, sendMessage, setEndianness, setWeakReferences, unExportObjectpublic static final String DEFAULT_SYSTEM_BUS_ADDRESS
public static DBusConnection getConnection(String _address) throws DBusException
_address - The address of the bus to connect toDBusConnectionDBusException - If there is a problem connecting to the Bus.public static DBusConnection getConnection(String _address, boolean _registerSelf, boolean _shared) throws DBusException
_address - The address of the bus to connect to_registerSelf - register own session in dbus_shared - use a shared connectionsDBusConnectionDBusException - If there is a problem connecting to the Bus.public static DBusConnection getConnection(String _address, boolean _registerSelf, boolean _shared, int _timeout) throws DBusException
_address - The address of the bus to connect to_registerSelf - register own session in dbus_shared - use a shared connections_timeout - connect timeout if this is a TCP socket, 0 will block forever, if this is not a TCP socket this value is ignoredDBusConnectionDBusException - If there is a problem connecting to the Bus.public static DBusConnection getConnection(DBusConnection.DBusBusType _bustype) throws DBusException
_bustype - The Bus to connect to.DBusConnectionDBusException - If there is a problem connecting to the Bus.public static DBusConnection newConnection(DBusConnection.DBusBusType _bustype) throws DBusException
_bustype - The Bus to connect to.DBusConnectionDBusException - If there is a problem connecting to the Bus.public static DBusConnection getConnection(DBusConnection.DBusBusType _bustype, boolean _shared, int _timeout) throws DBusException
_bustype - The Bus to connect to._shared - use shared connection_timeout - connect timeout if this is a TCP socket, 0 will block forever, if this is not a TCP socket this value is ignoredDBusConnectionDBusException - If there is a problem connecting to the Bus.public static String getDbusMachineId() throws DBusException
DBusException - if machine-id could not be foundprotected DBusInterface dynamicProxy(String _source, String _path) throws DBusException
DBusExceptionpublic DBusInterface getExportedObject(String _source, String _path) throws DBusException
getExportedObject in class AbstractConnectionDBusExceptionpublic void releaseBusName(String _busname) throws DBusException
_busname - The name to release. MUST be in dot-notation like "org.freedesktop.local"DBusException - If the busname is incorrectly formatted.public void requestBusName(String _busname) throws DBusException
_busname - The name to respond to. MUST be in dot-notation like "org.freedesktop.local"DBusException - If the register name failed, or our name already exists on the bus. or if busname is incorrectly
formatted.public String getUniqueName()
public String[] getNames()
public <I extends DBusInterface> I getPeerRemoteObject(String _busname, String _objectpath, Class<I> _type) throws DBusException
DBusExceptionpublic DBusInterface getPeerRemoteObject(String _busname, String _objectpath) throws DBusException
_busname - The bus name to connect to. Usually a well known bus name in dot-notation (such as
"org.freedesktop.local") or may be a DBus address such as ":1-16"._objectpath - The path on which the process is exporting the object.$ClassCastException - If type is not a sub-type of DBusInterfaceDBusException - If busname or objectpath are incorrectly formatted.public DBusInterface getRemoteObject(String _busname, String _objectpath) throws DBusException
_busname - The bus name to connect to. Usually a well known bus name name in dot-notation (such as
"org.freedesktop.local") or may be a DBus address such as ":1-16"._objectpath - The path on which the process is exporting the object.ClassCastException - If type is not a sub-type of DBusInterfaceDBusException - If busname or objectpath are incorrectly formatted.public <I extends DBusInterface> I getPeerRemoteObject(String _busname, String _objectpath, Class<I> _type, boolean _autostart) throws DBusException
I - class extending DBusInterface_busname - The bus name to connect to. Usually a well known bus name in dot-notation (such as
"org.freedesktop.local") or may be a DBus address such as ":1-16"._objectpath - The path on which the process is exporting the object.$_type - The interface they are exporting it on. This type must have the same full class name and exposed
method signatures as the interface the remote object is exporting._autostart - Disable/Enable auto-starting of services in response to calls on this object. Default is enabled; when
calling a method with auto-start enabled, if the destination is a well-known name and is not owned the
bus will attempt to start a process to take the name. When disabled an error is returned immediately.ClassCastException - If type is not a sub-type of DBusInterfaceDBusException - If busname or objectpath are incorrectly formatted or type is not in a package.public <I extends DBusInterface> I getRemoteObject(String _busname, String _objectpath, Class<I> _type) throws DBusException
I - class extending DBusInterface_busname - The bus name to connect to. Usually a well known bus name name in dot-notation (such as
"org.freedesktop.local") or may be a DBus address such as ":1-16"._objectpath - The path on which the process is exporting the object._type - The interface they are exporting it on. This type must have the same full class name and exposed
method signatures as the interface the remote object is exporting.ClassCastException - If type is not a sub-type of DBusInterfaceDBusException - If busname or objectpath are incorrectly formatted or type is not in a package.public <I extends DBusInterface> I getRemoteObject(String _busname, String _objectpath, Class<I> _type, boolean _autostart) throws DBusException
I - class extending DBusInterface_busname - The bus name to connect to. Usually a well known bus name name in dot-notation (such as
"org.freedesktop.local") or may be a DBus address such as ":1-16"._objectpath - The path on which the process is exporting the object._type - The interface they are exporting it on. This type must have the same full class name and exposed
method signatures as the interface the remote object is exporting._autostart - Disable/Enable auto-starting of services in response to calls on this object. Default is enabled; when
calling a method with auto-start enabled, if the destination is a well-known name and is not owned the
bus will attempt to start a process to take the name. When disabled an error is returned immediately.ClassCastException - If type is not a sub-type of DBusInterfaceDBusException - If busname or objectpath are incorrectly formatted or type is not in a package.public <T extends DBusSignal> void removeSigHandler(Class<T> _type, String _source, DBusSigHandler<T> _handler) throws DBusException
T - class extending DBusSignal_type - The signal to watch for._source - The source of the signal._handler - the handlerDBusException - If listening for the signal on the bus failed.ClassCastException - If type is not a sub-type of DBusSignal.public <T extends DBusSignal> void removeSigHandler(Class<T> _type, String _source, DBusInterface _object, DBusSigHandler<T> _handler) throws DBusException
T - class extending DBusSignal_type - The signal to watch for._source - The source of the signal._object - The object emitting the signal._handler - the handlerDBusException - If listening for the signal on the bus failed.ClassCastException - If type is not a sub-type of DBusSignal.protected <T extends DBusSignal> void removeSigHandler(DBusMatchRule _rule, DBusSigHandler<T> _handler) throws DBusException
DBusSigHandler.
The rule will only be removed from DBus if no other additional handlers are registered to the same rule.removeSigHandler in class AbstractConnection_rule - rule to remove_handler - handler to removeDBusException - on errorpublic <T extends DBusSignal> void addSigHandler(Class<T> _type, String _source, DBusSigHandler<T> _handler) throws DBusException
T - class extending DBusSignal_type - The signal to watch for._source - The process which will send the signal. This MUST be a unique bus name and not a well known
name._handler - The handler to call when a signal is received.DBusException - If listening for the signal on the bus failed.ClassCastException - If type is not a sub-type of DBusSignal.public <T extends DBusSignal> void addSigHandler(Class<T> _type, String _source, DBusInterface _object, DBusSigHandler<T> _handler) throws DBusException
T - class extending DBusSignal_type - The signal to watch for._source - The process which will send the signal. This MUST be a unique bus name and not a well known
name._object - The object from which the signal will be emitted_handler - The handler to call when a signal is received.DBusException - If listening for the signal on the bus failed.ClassCastException - If type is not a sub-type of DBusSignal.public <T extends DBusSignal> void addSigHandler(DBusMatchRule _rule, DBusSigHandler<T> _handler) throws DBusException
DBusMatchRule to DBus.
The rule will be added to DBus if it was not added before.
If the rule was already added, the signal handler is added to the internal map receiving
the same signal as the first (and additional) handlers for this rule.addSigHandler in class AbstractConnection_rule - rule to add_handler - handler to useDBusException - on errorpublic void disconnect()
disconnect in class AbstractConnectionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class AbstractConnectionIOExceptionpublic void removeGenericSigHandler(DBusMatchRule _rule, DBusSigHandler<DBusSignal> _handler) throws DBusException
DBusMatchRule.
The rule will only be removed from DBus if no other additional handlers are registered to the same rule.removeGenericSigHandler in class AbstractConnection_rule - rule to remove_handler - handler to removeDBusException - on errorpublic void addGenericSigHandler(DBusMatchRule _rule, DBusSigHandler<DBusSignal> _handler) throws DBusException
DBusMatchRule to with a generic signal handler.
Generic signal handlers allow receiving different signals with the same handler.
If the rule was already added, the signal handler is added to the internal map receiving
the same signal as the first (and additional) handlers for this rule.addGenericSigHandler in class AbstractConnection_rule - rule to add_handler - handler to useDBusException - on errorpublic String getMachineId()
AbstractConnectiongetMachineId in class AbstractConnectionCopyright © 2020. All rights reserved.