Package ghidra.framework.plugintool.mgr
Class ServiceManager
- java.lang.Object
-
- ghidra.framework.plugintool.mgr.ServiceManager
-
public class ServiceManager extends java.lang.Object
Class for managing plugin services. A plugin may provide a service, or it may depend on a service. The ServiceManager maintains a list of service names and plugins that provide those services. A plugin may dynamically add and remove services from the service registry. As services are added and removed, all the plugins (ServiceListener) in the tool are notified.
-
-
Constructor Summary
Constructors Constructor Description ServiceManager()
Construct a new Service Registry.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> void
addService(java.lang.Class<? extends T> interfaceClass, T service)
Add the service to the tool.void
addServiceListener(ServiceListener listener)
Add listener that is notified when services are added or removed.java.util.List<ServiceInterfaceImplementationPair>
getAllServices()
Returns a array of all service implementors.<T> T
getService(java.lang.Class<T> interfaceClass)
Return the first implementation found for the given service class.<T> T[]
getServices(java.lang.Class<T> interfaceClass)
Get an array of objects that implement the given interfaceClass.boolean
isService(java.lang.Class<?> serviceInterface)
Returns true if the specifiedserviceInterface
is a valid service that exists in this service manager.void
removeService(java.lang.Class<?> interfaceClass, java.lang.Object service)
Remove the service from the tool.void
removeServiceListener(ServiceListener listener)
Remove the given listener from list of listeners notified when services are added or removed.void
setServiceAddedNotificationsOn(boolean b)
Set the indicator for whether service listeners should be notified.
-
-
-
Method Detail
-
addServiceListener
public void addServiceListener(ServiceListener listener)
Add listener that is notified when services are added or removed.- Parameters:
listener
- listener to notify
-
removeServiceListener
public void removeServiceListener(ServiceListener listener)
Remove the given listener from list of listeners notified when services are added or removed.- Parameters:
listener
- listener to remove
-
setServiceAddedNotificationsOn
public void setServiceAddedNotificationsOn(boolean b)
Set the indicator for whether service listeners should be notified. While plugins are being restored from a tool state, this indicator is false, as a plugin may not be in the proper state to handle the notification.- Parameters:
b
- true means to notify listeners of the services added to the tool
-
addService
public <T> void addService(java.lang.Class<? extends T> interfaceClass, T service)
Add the service to the tool. Notify the service listeners if the notification indicator is true; otherwise, add the service to a list that will be used to notify listeners when notifications are turned on again.- Parameters:
interfaceClass
- class of the service interface being addedservice
- implementation of the service; it may be a plugin or may be some object created by the plugin- See Also:
setServiceAddedNotificationsOn(boolean)
-
removeService
public void removeService(java.lang.Class<?> interfaceClass, java.lang.Object service)
Remove the service from the tool.
-
getService
public <T> T getService(java.lang.Class<T> interfaceClass)
Return the first implementation found for the given service class.- Parameters:
interfaceClass
- interface class for the service- Returns:
- null if the interfaceClass was not registered
-
getServices
public <T> T[] getServices(java.lang.Class<T> interfaceClass)
Get an array of objects that implement the given interfaceClass.- Parameters:
interfaceClass
- interface class for the service- Returns:
- zero length array if the interfaceClass was not registered
-
isService
public boolean isService(java.lang.Class<?> serviceInterface)
Returns true if the specifiedserviceInterface
is a valid service that exists in this service manager.- Parameters:
serviceInterface
- the service interface- Returns:
- true if the specified
serviceInterface
-
getAllServices
public java.util.List<ServiceInterfaceImplementationPair> getAllServices()
Returns a array of all service implementors.- Returns:
- a array of all service implementors
-
-