// // Copyright 2018 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in // compliance with the Apache License and the following modification to it: // Section 6. Trademarks. is deleted and replaced with: // // 6. Trademarks. This License does not grant permission to use the trade // names, trademarks, service marks, or product names of the Licensor // and its affiliates, except as required to comply with Section 4(c) of // the License and to reproduce the content of the NOTICE file. // // You may obtain a copy of the Apache License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the Apache License with the above modification is // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the Apache License for the specific // language governing permissions and limitations under the Apache License. // #ifndef PXR_USD_NDR_DISCOVERY_PLUGIN_H #define PXR_USD_NDR_DISCOVERY_PLUGIN_H /// \file ndr/registry.h #include "pxr/pxr.h" #include "pxr/usd/ndr/api.h" #include "pxr/base/tf/declarePtrs.h" #include "pxr/base/tf/type.h" #include "pxr/base/tf/weakBase.h" #include "pxr/usd/ndr/declare.h" #include "pxr/usd/ndr/nodeDiscoveryResult.h" PXR_NAMESPACE_OPEN_SCOPE /// Register a discovery plugin (`DiscoveryPluginClass`) with the plugin system. /// If registered, the discovery plugin will execute its discovery process when /// the registry is instantiated. #define NDR_REGISTER_DISCOVERY_PLUGIN(DiscoveryPluginClass) \ TF_REGISTRY_FUNCTION(TfType) \ { \ TfType::Define>() \ .SetFactory>(); \ } TF_DECLARE_WEAK_AND_REF_PTRS(NdrDiscoveryPluginContext); /// A context for discovery. Discovery plugins can use this to get /// a limited set of non-local information without direct coupling /// between plugins. class NdrDiscoveryPluginContext : public TfRefBase, public TfWeakBase { public: NDR_API virtual ~NdrDiscoveryPluginContext() = default; /// Returns the source type associated with the discovery type. /// This may return an empty token if there is no such association. NDR_API virtual TfToken GetSourceType(const TfToken& discoveryType) const = 0; }; TF_DECLARE_WEAK_AND_REF_PTRS(NdrDiscoveryPlugin); /// \class NdrDiscoveryPlugin /// /// Interface for discovery plugins. /// /// Discovery plugins, like the name implies, find nodes. Where the plugin /// searches is up to the plugin that implements this interface. Examples /// of discovery plugins could include plugins that look for nodes on the /// filesystem, another that finds nodes in a cloud service, and another that /// searches a local database. Multiple discovery plugins that search the /// filesystem in specific locations/ways could also be created. All discovery /// plugins are executed as soon as the registry is instantiated. /// /// These plugins simply report back to the registry what nodes they found in /// a generic way. The registry doesn't know much about the innards of the /// nodes yet, just that the nodes exist. Understanding the nodes is the /// responsibility of another set of plugins defined by the `NdrParserPlugin` /// interface. /// /// Discovery plugins report back to the registry via `NdrNodeDiscoveryResult`s. /// These are small, lightweight classes that contain the information for a /// single node that was found during discovery. The discovery result only /// includes node information that can be gleaned pre-parse, so the data is /// fairly limited; to see exactly what's included, and what is expected to /// be populated, see the documentation for `NdrNodeDiscoveryResult`. /// /// \section create How to Create a Discovery Plugin /// There are three steps to creating a discovery plugin: /// /// class NdrDiscoveryPlugin : public TfRefBase, public TfWeakBase { public: using Context = NdrDiscoveryPluginContext; NDR_API NdrDiscoveryPlugin(); NDR_API virtual ~NdrDiscoveryPlugin(); /// Finds and returns all nodes that the implementing plugin should be /// aware of. NDR_API virtual NdrNodeDiscoveryResultVec DiscoverNodes(const Context&) = 0; /// Gets the URIs that this plugin is searching for nodes in. NDR_API virtual const NdrStringVec& GetSearchURIs() const = 0; }; /// \cond /// Factory classes should be hidden from the documentation. class NdrDiscoveryPluginFactoryBase : public TfType::FactoryBase { public: NDR_API virtual NdrDiscoveryPluginRefPtr New() const = 0; }; template class NdrDiscoveryPluginFactory : public NdrDiscoveryPluginFactoryBase { public: NdrDiscoveryPluginRefPtr New() const override { return TfCreateRefPtr(new T); } }; /// \endcond PXR_NAMESPACE_CLOSE_SCOPE #endif // PXR_USD_NDR_DISCOVERY_PLUGIN_H