Class ServiceManager

java.lang.Object
ghidra.framework.plugintool.mgr.ServiceManager

public class ServiceManager extends 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 Details

    • ServiceManager

      public ServiceManager()
      Construct a new Service Registry.
  • Method Details

    • 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(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 added
      service - implementation of the service; it may be a plugin or may be some object created by the plugin
      See Also:
    • removeService

      public void removeService(Class<?> interfaceClass, Object service)
      Remove the service from the tool.
      Parameters:
      interfaceClass - the service interface
      service - the service implementation
    • getService

      public <T> T getService(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(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(Class<?> serviceInterface)
      Returns true if the specified serviceInterface is a valid service that exists in this service manager.
      Parameters:
      serviceInterface - the service interface
      Returns:
      true if the specified serviceInterface
    • getAllServices

      public List<ServiceInterfaceImplementationPair> getAllServices()
      Returns a array of all service implementors.
      Returns:
      a array of all service implementors