Decouple component class from plugin subsystem, remove component factory
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 18 Jan 2017 18:30:07 +0000 (13:30 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:37 +0000 (12:57 -0400)
commit33b34c437c354e1c065e33151135bc2e57e2e29c
treeda7b941ff75ac18500f65861189e0d773ca16ac9
parent09ac5ce7990677798a58638ab45ab1a62e615a9a
Decouple component class from plugin subsystem, remove component factory

This is a refactoring of the component class and plugin subsystems of
Babeltrace 2. There's not much new code, it's mostly moved from one
file to another and some functions are renamed.

The goal of this patch is to decouple the component class objects from
plugin objects, that is, remove the dependency from the component class
to the plugin. This reference is not necessary, as component classes
can be provided by many sources, a plugin being one of them. A similar
plugin subsystem could be implemented outside of the Babeltrace library
with plugin-agnostic component class objects.

Also the component factory concept is completely removed. At the end
of this refactoring, it's nothing more than a hash table, so the name
is bad, and the object itself is just a very basic util.

Summary of changes:

* You can create a bt_component_class object manually with
  bt_component_class_create(). The function accepts the same parameters
  as before, except for a plugin reference.

* Internal code can use bt_component_class_add_destroy_listener() to add
  a custom destroy listener to a component class. Destroy listeners are
  called in reverse order just before the component class is destroyed
  when its last reference is dropped.

  This is needed to implement the plugin subsystem. It could be made
  public eventually to allow a custom component class provider system
  similar to the Babeltrace plugin subsystem. It could be generalized to
  bt_object_add_destroy_listener() or bt_add_destroy_listener().

* bt_component_class_get_plugin() is removed.

* There are three functions to create a bt_plugin object (in
  `babeltrace/plugin/plugin.h`):

  * bt_plugin_create_from_file(): Accepts a path and creates a plugin
    object from this single file. This must be a `.so` or `.la` file for
    the moment, but eventually we can support other plugins like Python
    plugins `.py`, Windows DLLs `.dll`, etc.

  * bt_plugin_create_all_from_dir(): Traverses a directory, optionally
    recursively, and creates one plugin object for each shared library
    found. Errors are ignored in this function because it's possible
    that a shared library in this directoy is not a Babeltrace plugin
    and we still want to continue the search.

    The return value is a NULL-terminated array of bt_plugin objects
    which the caller must free. Each plugin object in this array has its
    reference count set to 1.

  * bt_plugin_create_all_from_static(): Loads all the plugins found in
    the static sections of the Babeltrace binary. The return value has
    the same format as with bt_plugin_create_all_from_dir().

  There is no way to create an "empty", fresh bt_plugin object. It's
  always created from an existing file in the end.

* A bt_plugin object is a simple provider of component classes. Once
  it's created with one of the three functions above, you can access its
  global properties (name, license, description, etc.), as well as its
  component classes with bt_plugin_get_component_class_count(),
  bt_plugin_get_component_class(), and
  bt_plugin_get_component_class_by_name_and_type().

  The initialization function of a plugin can add new component classes
  to a bt_plugin object (passed as a parameter) thanks to the new
  bt_plugin_add_component_class() function. This function is exclusive
  to a plugin's initialization stage: once the initialization is done,
  the plugin is marked as frozen, and you cannot call
  bt_plugin_add_component_class() again on this plugin. This ensures
  that all the contained component classes were created by the plugin's
  code itself.

  There's a mechanism which involves a global hash table of
  component class adresses to shared library handles and a custom
  component class destroy listener to ensure that, even if a bt_plugin
  object is destroyed (reference count falls to zero), its associated
  shared library is not closed until all its component classes are
  also destroyed. See plugin.c:89 for more details.

* All the headers related to components, component classes, and
  notifications are moved to `babeltrace/component`. Plugin-specific
  headers are in `babeltrace/plugin`.

* Plugin development macros are in `babeltrace/plugin/plugin-dev.h`
  (instead of `plugin-macros.h`). This is the header that any plugin's
  main source file must include.

  * Two new function typedefs in `plugin-dev.h`:

    * bt_plugin_init_func: plugin's initialization function which
      accepts a plugin object to which to add component classes.

      You can set such a function with BT_PLUGIN_INIT().

    * bt_plugin_exit_func: plugin's exit function, if anything global to
      the plugin must be freed/released.

      This is not called when the bt_plugin object is destroyed: because
      component classes could still be alive when this happens, it's
      called just before the shared library is closed (when it is
      guaranteed that no user code found in this plugin will be called
      in the future of this process).

      You can set such a function with BT_PLUGIN_EXIT().

  * The BT_PLUGIN_COMPONENT_CLASS_*_ENTRY() macros create a component
    class of the associated type with bt_component_class_create(), and
    add it to the plugin object with bt_plugin_add_component_class().

    You can also do this manually in a custom initialization function.
    When you use BT_PLUGIN_COMPONENT_CLASSES_BEGIN and
    BT_PLUGIN_COMPONENT_CLASSES_END, BT_PLUGIN_INIT() and
    BT_PLUGIN_EXIT() (no-op exit function) are automatically used.

* Everything found in `babeltrace/plugin/plugin-system.h` is moved to
  the appropriate headers, depending on the types of the objects.

* Plugins, tests, and internal code are updated to use the new macros
  and header files.

* The converter is updated to use the updated subsystems instead of
  relying on a component factory.

  A global GLib pointer array is used to keep the currently loaded
  plugins. This is used instead of the component factory. When a new
  plugin is found, we check in this array if it was already added (same
  name) from another file or statically before adding it.

  The static find_plugin() and find_component_class() are the equivalent
  of the component factory interface.

  print_component_classes_found() also prints the number of loaded
  plugins.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
125 files changed:
configure.ac
converter/babeltrace.c
formats/ctf/ir/trace.c
include/Makefile.am
include/babeltrace/component/component-class-internal.h [new file with mode: 0644]
include/babeltrace/component/component-class.h [new file with mode: 0644]
include/babeltrace/component/component-connection-internal.h [new file with mode: 0644]
include/babeltrace/component/component-connection.h [new file with mode: 0644]
include/babeltrace/component/component-graph-internal.h [new file with mode: 0644]
include/babeltrace/component/component-graph.h [new file with mode: 0644]
include/babeltrace/component/component-internal.h [new file with mode: 0644]
include/babeltrace/component/component.h [new file with mode: 0644]
include/babeltrace/component/filter-internal.h [new file with mode: 0644]
include/babeltrace/component/filter.h [new file with mode: 0644]
include/babeltrace/component/input.h [new file with mode: 0644]
include/babeltrace/component/notification/eot-internal.h [new file with mode: 0644]
include/babeltrace/component/notification/eot.h [new file with mode: 0644]
include/babeltrace/component/notification/event-internal.h [new file with mode: 0644]
include/babeltrace/component/notification/event.h [new file with mode: 0644]
include/babeltrace/component/notification/heap-internal.h [new file with mode: 0644]
include/babeltrace/component/notification/heap.h [new file with mode: 0644]
include/babeltrace/component/notification/iterator-internal.h [new file with mode: 0644]
include/babeltrace/component/notification/iterator.h [new file with mode: 0644]
include/babeltrace/component/notification/notification-internal.h [new file with mode: 0644]
include/babeltrace/component/notification/notification.h [new file with mode: 0644]
include/babeltrace/component/notification/packet-internal.h [new file with mode: 0644]
include/babeltrace/component/notification/packet.h [new file with mode: 0644]
include/babeltrace/component/notification/schema.h [new file with mode: 0644]
include/babeltrace/component/notification/stream-internal.h [new file with mode: 0644]
include/babeltrace/component/notification/stream.h [new file with mode: 0644]
include/babeltrace/component/sink-internal.h [new file with mode: 0644]
include/babeltrace/component/sink.h [new file with mode: 0644]
include/babeltrace/component/source-internal.h [new file with mode: 0644]
include/babeltrace/component/source.h [new file with mode: 0644]
include/babeltrace/ctf-ir/trace.h
include/babeltrace/plugin/component-class-internal.h [deleted file]
include/babeltrace/plugin/component-class.h [deleted file]
include/babeltrace/plugin/component-connection-internal.h [deleted file]
include/babeltrace/plugin/component-connection.h [deleted file]
include/babeltrace/plugin/component-factory-internal.h [deleted file]
include/babeltrace/plugin/component-factory.h [deleted file]
include/babeltrace/plugin/component-graph-internal.h [deleted file]
include/babeltrace/plugin/component-graph.h [deleted file]
include/babeltrace/plugin/component-internal.h [deleted file]
include/babeltrace/plugin/component.h [deleted file]
include/babeltrace/plugin/filter-internal.h [deleted file]
include/babeltrace/plugin/filter.h [deleted file]
include/babeltrace/plugin/input.h [deleted file]
include/babeltrace/plugin/notification/eot-internal.h [deleted file]
include/babeltrace/plugin/notification/eot.h [deleted file]
include/babeltrace/plugin/notification/event-internal.h [deleted file]
include/babeltrace/plugin/notification/event.h [deleted file]
include/babeltrace/plugin/notification/heap-internal.h [deleted file]
include/babeltrace/plugin/notification/heap.h [deleted file]
include/babeltrace/plugin/notification/iterator-internal.h [deleted file]
include/babeltrace/plugin/notification/iterator.h [deleted file]
include/babeltrace/plugin/notification/notification-internal.h [deleted file]
include/babeltrace/plugin/notification/notification.h [deleted file]
include/babeltrace/plugin/notification/packet-internal.h [deleted file]
include/babeltrace/plugin/notification/packet.h [deleted file]
include/babeltrace/plugin/notification/schema.h [deleted file]
include/babeltrace/plugin/notification/stream-internal.h [deleted file]
include/babeltrace/plugin/notification/stream.h [deleted file]
include/babeltrace/plugin/plugin-dev.h [new file with mode: 0644]
include/babeltrace/plugin/plugin-internal.h
include/babeltrace/plugin/plugin-macros.h [deleted file]
include/babeltrace/plugin/plugin-system.h [deleted file]
include/babeltrace/plugin/plugin.h
include/babeltrace/plugin/sink-internal.h [deleted file]
include/babeltrace/plugin/sink.h [deleted file]
include/babeltrace/plugin/source-internal.h [deleted file]
include/babeltrace/plugin/source.h [deleted file]
lib/Makefile.am
lib/component/Makefile.am [new file with mode: 0644]
lib/component/component-class.c [new file with mode: 0644]
lib/component/component-graph.c [new file with mode: 0644]
lib/component/component.c [new file with mode: 0644]
lib/component/filter.c [new file with mode: 0644]
lib/component/input.c [new file with mode: 0644]
lib/component/iterator.c [new file with mode: 0644]
lib/component/notification/Makefile.am [new file with mode: 0644]
lib/component/notification/event.c [new file with mode: 0644]
lib/component/notification/heap.c [new file with mode: 0644]
lib/component/notification/notification.c [new file with mode: 0644]
lib/component/notification/packet.c [new file with mode: 0644]
lib/component/notification/stream.c [new file with mode: 0644]
lib/component/sink.c [new file with mode: 0644]
lib/component/source.c [new file with mode: 0644]
lib/plugin-system/Makefile.am [deleted file]
lib/plugin-system/component-class.c [deleted file]
lib/plugin-system/component-factory.c [deleted file]
lib/plugin-system/component-graph.c [deleted file]
lib/plugin-system/component.c [deleted file]
lib/plugin-system/filter.c [deleted file]
lib/plugin-system/input.c [deleted file]
lib/plugin-system/iterator.c [deleted file]
lib/plugin-system/notification/Makefile.am [deleted file]
lib/plugin-system/notification/event.c [deleted file]
lib/plugin-system/notification/heap.c [deleted file]
lib/plugin-system/notification/notification.c [deleted file]
lib/plugin-system/notification/packet.c [deleted file]
lib/plugin-system/notification/stream.c [deleted file]
lib/plugin-system/plugin.c [deleted file]
lib/plugin-system/sink.c [deleted file]
lib/plugin-system/source.c [deleted file]
lib/plugin/Makefile.am [new file with mode: 0644]
lib/plugin/plugin.c [new file with mode: 0644]
plugins/ctf/common/notif-iter/notif-iter.c
plugins/ctf/fs/data-stream.c
plugins/ctf/fs/fs.c
plugins/ctf/fs/fs.h
plugins/ctf/lttng-live/lttng-live-internal.h
plugins/ctf/lttng-live/lttng-live.c
plugins/ctf/plugin.c
plugins/muxer/muxer.c
plugins/muxer/muxer.h
plugins/text/text.c
plugins/text/text.h
plugins/trimmer/iterator.c
plugins/trimmer/iterator.h
plugins/trimmer/trimmer.c
plugins/trimmer/trimmer.h
plugins/writer/writer.c
plugins/writer/writer.h
tests/lib/test_bt_notification_heap.c
This page took 0.034555 seconds and 4 git commands to generate.