"""Support required by the Carbonite extension loader"""
import omni.ext

from ..bindings._omni_graph_test import acquire_interface as _acquire_interface  # noqa: PLE0402
from ..bindings._omni_graph_test import release_interface as _release_interface  # noqa: PLE0402


class _PublicExtension(omni.ext.IExt):
    """Object that tracks the lifetime of the Python part of the extension loading"""

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.__interface = None

    def on_startup(self):
        """Set up initial conditions for the Python part of the extension"""
        self.__interface = _acquire_interface()

    def on_shutdown(self):
        """Shutting down this part of the extension prepares it for hot reload"""
        if self.__interface is not None:
            _release_interface(self.__interface)
            self.__interface = None
