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| Modifier and Type | Method and Description |
|---|---|
void |
addGenericSigHandler(DBusMatchRule _rule,
DBusSigHandler<DBusSignal> _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) |
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)
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 String |
getDbusMachineId()
Extracts the machine-id usually found in /var/lib/dbus/machine-id.
|
DBusInterface |
getExportedObject(String _source,
String _path) |
String |
getMachineId() |
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) |
<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) |
void |
requestBusName(String _busname)
Request a bus name.
|
addFallback, addSigHandler, addSigHandler, addSigHandlerWithoutMatch, callMethodAsync, callWithCallback, changeThreadCount, exportObject, getAddress, getCallInfo, getError, getExportedObject, getExportedObjects, getGenericHandledSignals, getHandledSignals, getImportedObjects, getObjectTree, getPendingCalls, getPendingErrorQueue, handleException, isConnected, listen, queueCallback, removeFallback, removeSigHandler, removeSigHandler, sendMessage, 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(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) throws DBusException
_bustype - The Bus to connect to._shared - use shared connectionDBusConnectionDBusException - 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
removeSigHandler in class AbstractConnectionDBusExceptionpublic <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
addSigHandler in class AbstractConnectionDBusExceptionpublic 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
removeGenericSigHandler in class AbstractConnectionDBusExceptionpublic void addGenericSigHandler(DBusMatchRule _rule, DBusSigHandler<DBusSignal> _handler) throws DBusException
addGenericSigHandler in class AbstractConnectionDBusExceptionpublic String getMachineId()
getMachineId in class AbstractConnectionCopyright © 2020. All rights reserved.