Package org.freedesktop.dbus
Class AbstractConnection
- java.lang.Object
-
- org.freedesktop.dbus.AbstractConnection
-
- Direct Known Subclasses:
DBusConnection
,DirectConnection
public abstract class AbstractConnection extends java.lang.Object
Handles a connection to DBus.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractConnection._thread
protected class
AbstractConnection._workerthread
protected class
AbstractConnection.FallbackContainer
-
Field Summary
Fields Modifier and Type Field Description protected boolean
_run
protected java.lang.String
addr
protected boolean
connected
static boolean
EXCEPTION_DEBUG
protected java.util.Map<java.lang.String,org.freedesktop.dbus.ExportedObject>
exportedObjects
protected AbstractConnection.FallbackContainer
fallbackcontainer
protected java.util.Map<org.freedesktop.dbus.SignalTuple,java.util.Vector<DBusSigHandler<? extends DBusSignal>>>
handledSignals
protected java.util.Map<DBusInterface,org.freedesktop.dbus.RemoteObject>
importedObjects
protected java.util.Map<MethodCall,DBusAsyncReply<? extends java.lang.Object>>
pendingCallbackReplys
protected java.util.Map<MethodCall,CallbackHandler<? extends java.lang.Object>>
pendingCallbacks
protected org.freedesktop.dbus.EfficientMap
pendingCalls
protected java.util.LinkedList<java.lang.Runnable>
runnables
protected org.freedesktop.dbus.AbstractConnection._sender
sender
protected AbstractConnection._thread
thread
protected static int
TIMEOUT
Timeout in us on checking the BUS for incoming messages and sending outgoing messagesprotected Transport
transport
protected boolean
weakreferences
protected java.util.LinkedList<AbstractConnection._workerthread>
workers
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConnection(java.lang.String address)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addFallback(java.lang.String objectprefix, DBusInterface object)
Export an object as a fallback object.<T extends DBusSignal>
voidaddSigHandler(java.lang.Class<T> type, DBusInterface object, DBusSigHandler<T> handler)
Add a Signal Handler.<T extends DBusSignal>
voidaddSigHandler(java.lang.Class<T> type, DBusSigHandler<T> handler)
Add a Signal Handler.protected abstract <T extends DBusSignal>
voidaddSigHandler(DBusMatchRule rule, DBusSigHandler<T> handler)
protected <T extends DBusSignal>
voidaddSigHandlerWithoutMatch(java.lang.Class<? extends DBusSignal> signal, DBusSigHandler<T> handler)
DBusAsyncReply
callMethodAsync(DBusInterface object, java.lang.String m, java.lang.Object... parameters)
Call a method asynchronously and get a handle with which to get the reply.<A> void
callWithCallback(DBusInterface object, java.lang.String m, CallbackHandler<A> callback, java.lang.Object... parameters)
Call a method asynchronously and set a callback.void
changeThreadCount(byte newcount)
Change the number of worker threads to receive method calls and handle signals.void
disconnect()
Disconnect from the Bus.void
exportObject(java.lang.String objectpath, DBusInterface object)
Export an object so that its methods can be called on DBus.void
finalize()
BusAddress
getAddress()
Returns the address this connection is connected to.static DBusCallInfo
getCallInfo()
Returns a structure with information on the current method call.DBusExecutionException
getError()
Return any DBus error which has been received.protected void
listen()
void
removeFallback(java.lang.String objectprefix)
Remove a fallback<T extends DBusSignal>
voidremoveSigHandler(java.lang.Class<T> type, DBusInterface object, DBusSigHandler<T> handler)
Remove a Signal Handler.<T extends DBusSignal>
voidremoveSigHandler(java.lang.Class<T> type, DBusSigHandler<T> handler)
Remove a Signal Handler.protected abstract <T extends DBusSignal>
voidremoveSigHandler(DBusMatchRule rule, DBusSigHandler<T> handler)
protected void
sendMessage(Message m)
void
sendSignal(DBusSignal signal)
Send a signal.void
setWeakReferences(boolean weakreferences)
If set to true the bus will not hold a strong reference to exported objects.void
unExportObject(java.lang.String objectpath)
Stop Exporting an object
-
-
-
Field Detail
-
TIMEOUT
protected static final int TIMEOUT
Timeout in us on checking the BUS for incoming messages and sending outgoing messages- See Also:
- Constant Field Values
-
exportedObjects
protected java.util.Map<java.lang.String,org.freedesktop.dbus.ExportedObject> exportedObjects
-
importedObjects
protected java.util.Map<DBusInterface,org.freedesktop.dbus.RemoteObject> importedObjects
-
handledSignals
protected java.util.Map<org.freedesktop.dbus.SignalTuple,java.util.Vector<DBusSigHandler<? extends DBusSignal>>> handledSignals
-
pendingCalls
protected org.freedesktop.dbus.EfficientMap pendingCalls
-
pendingCallbacks
protected java.util.Map<MethodCall,CallbackHandler<? extends java.lang.Object>> pendingCallbacks
-
pendingCallbackReplys
protected java.util.Map<MethodCall,DBusAsyncReply<? extends java.lang.Object>> pendingCallbackReplys
-
runnables
protected java.util.LinkedList<java.lang.Runnable> runnables
-
workers
protected java.util.LinkedList<AbstractConnection._workerthread> workers
-
fallbackcontainer
protected AbstractConnection.FallbackContainer fallbackcontainer
-
_run
protected boolean _run
-
thread
protected AbstractConnection._thread thread
-
sender
protected org.freedesktop.dbus.AbstractConnection._sender sender
-
transport
protected Transport transport
-
addr
protected java.lang.String addr
-
weakreferences
protected boolean weakreferences
-
EXCEPTION_DEBUG
public static final boolean EXCEPTION_DEBUG
-
connected
protected boolean connected
-
-
Constructor Detail
-
AbstractConnection
protected AbstractConnection(java.lang.String address) throws DBusException
- Throws:
DBusException
-
-
Method Detail
-
listen
protected void listen()
-
changeThreadCount
public void changeThreadCount(byte newcount)
Change the number of worker threads to receive method calls and handle signals. Default is 4 threads- Parameters:
newcount
- The new number of worker Threads to use.
-
getCallInfo
public static DBusCallInfo getCallInfo()
Returns a structure with information on the current method call.- Returns:
- the DBusCallInfo for this method call, or null if we are not in a method call.
-
setWeakReferences
public void setWeakReferences(boolean weakreferences)
If set to true the bus will not hold a strong reference to exported objects. If they go out of scope they will automatically be unexported from the bus. The default is to hold a strong reference, which means objects must be explicitly unexported before they will be garbage collected.
-
exportObject
public void exportObject(java.lang.String objectpath, DBusInterface object) throws DBusException
Export an object so that its methods can be called on DBus.- Parameters:
objectpath
- The path to the object we are exposing. MUST be in slash-notation, like "/org/freedesktop/Local", and SHOULD end with a capitalised term. Only one object may be exposed on each path at any one time, but an object may be exposed on several paths at once.object
- The object to export.- Throws:
DBusException
- If the objectpath is already exporting an object. or if objectpath is incorrectly formatted,
-
addFallback
public void addFallback(java.lang.String objectprefix, DBusInterface object) throws DBusException
Export an object as a fallback object. This object will have it's methods invoked for all paths starting with this object path.- Parameters:
objectprefix
- The path below which the fallback handles calls. MUST be in slash-notation, like "/org/freedesktop/Local",object
- The object to export.- Throws:
DBusException
- If the objectpath is incorrectly formatted,
-
removeFallback
public void removeFallback(java.lang.String objectprefix)
Remove a fallback- Parameters:
objectprefix
- The prefix to remove the fallback for.
-
unExportObject
public void unExportObject(java.lang.String objectpath)
Stop Exporting an object- Parameters:
objectpath
- The objectpath to stop exporting.
-
sendSignal
public void sendSignal(DBusSignal signal)
Send a signal.- Parameters:
signal
- The signal to send.
-
removeSigHandler
public <T extends DBusSignal> void removeSigHandler(java.lang.Class<T> type, DBusSigHandler<T> handler) throws DBusException
Remove a Signal Handler. Stops listening for this signal.- Parameters:
type
- The signal to watch for.- Throws:
DBusException
- If listening for the signal on the bus failed.java.lang.ClassCastException
- If type is not a sub-type of DBusSignal.
-
removeSigHandler
public <T extends DBusSignal> void removeSigHandler(java.lang.Class<T> type, DBusInterface object, DBusSigHandler<T> handler) throws DBusException
Remove a Signal Handler. Stops listening for this signal.- Parameters:
type
- The signal to watch for.object
- The object emitting the signal.- Throws:
DBusException
- If listening for the signal on the bus failed.java.lang.ClassCastException
- If type is not a sub-type of DBusSignal.
-
removeSigHandler
protected abstract <T extends DBusSignal> void removeSigHandler(DBusMatchRule rule, DBusSigHandler<T> handler) throws DBusException
- Throws:
DBusException
-
addSigHandler
public <T extends DBusSignal> void addSigHandler(java.lang.Class<T> type, DBusSigHandler<T> handler) throws DBusException
Add a Signal Handler. Adds a signal handler to call when a signal is received which matches the specified type and name.- Parameters:
type
- The signal to watch for.handler
- The handler to call when a signal is received.- Throws:
DBusException
- If listening for the signal on the bus failed.java.lang.ClassCastException
- If type is not a sub-type of DBusSignal.
-
addSigHandler
public <T extends DBusSignal> void addSigHandler(java.lang.Class<T> type, DBusInterface object, DBusSigHandler<T> handler) throws DBusException
Add a Signal Handler. Adds a signal handler to call when a signal is received which matches the specified type, name and object.- Parameters:
type
- The signal to watch for.object
- The object from which the signal will be emittedhandler
- The handler to call when a signal is received.- Throws:
DBusException
- If listening for the signal on the bus failed.java.lang.ClassCastException
- If type is not a sub-type of DBusSignal.
-
addSigHandler
protected abstract <T extends DBusSignal> void addSigHandler(DBusMatchRule rule, DBusSigHandler<T> handler) throws DBusException
- Throws:
DBusException
-
addSigHandlerWithoutMatch
protected <T extends DBusSignal> void addSigHandlerWithoutMatch(java.lang.Class<? extends DBusSignal> signal, DBusSigHandler<T> handler) throws DBusException
- Throws:
DBusException
-
disconnect
public void disconnect()
Disconnect from the Bus.
-
finalize
public void finalize()
- Overrides:
finalize
in classjava.lang.Object
-
getError
public DBusExecutionException getError()
Return any DBus error which has been received.- Returns:
- A DBusExecutionException, or null if no error is pending.
-
callWithCallback
public <A> void callWithCallback(DBusInterface object, java.lang.String m, CallbackHandler<A> callback, java.lang.Object... parameters)
Call a method asynchronously and set a callback. This handler will be called in a separate thread.- Parameters:
object
- The remote object on which to call the method.m
- The name of the method on the interface to call.callback
- The callback handler.parameters
- The parameters to call the method with.
-
callMethodAsync
public DBusAsyncReply callMethodAsync(DBusInterface object, java.lang.String m, java.lang.Object... parameters)
Call a method asynchronously and get a handle with which to get the reply.- Parameters:
object
- The remote object on which to call the method.m
- The name of the method on the interface to call.parameters
- The parameters to call the method with.- Returns:
- A handle to the call.
-
sendMessage
protected void sendMessage(Message m)
-
getAddress
public BusAddress getAddress() throws java.text.ParseException
Returns the address this connection is connected to.- Throws:
java.text.ParseException
-
-