HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
discoveryPlugin.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_USD_NDR_DISCOVERY_PLUGIN_H
9 #define PXR_USD_NDR_DISCOVERY_PLUGIN_H
10 
11 /// \file ndr/discoveryPlugin.h
12 ///
13 /// \deprecated
14 /// All Ndr objects are deprecated in favor of the corresponding Sdr objects
15 /// in sdr/discoveryPlugin.h
16 
17 #include "pxr/pxr.h"
18 #include "pxr/usd/ndr/api.h"
20 #include "pxr/base/tf/type.h"
21 #include "pxr/base/tf/weakBase.h"
22 #include "pxr/usd/ndr/declare.h"
24 
26 
27 /// Register a discovery plugin (`DiscoveryPluginClass`) with the plugin system.
28 /// If registered, the discovery plugin will execute its discovery process when
29 /// the registry is instantiated.
30 ///
31 /// \deprecated
32 /// Deprecated in favor of SDR_REGISTER_DISCOVERY_PLUGIN
33 #define NDR_REGISTER_DISCOVERY_PLUGIN(DiscoveryPluginClass) \
34 TF_REGISTRY_FUNCTION(TfType) \
35 { \
36  TfType::Define<DiscoveryPluginClass, TfType::Bases<NdrDiscoveryPlugin>>() \
37  .SetFactory<NdrDiscoveryPluginFactory<DiscoveryPluginClass>>(); \
38 }
39 
41 
42 /// A context for discovery. Discovery plugins can use this to get
43 /// a limited set of non-local information without direct coupling
44 /// between plugins.
45 ///
46 /// \deprecated
47 /// Deprecated in favor of SdrDiscoveryPluginContext
49 {
50 public:
51  NDR_API
52  virtual ~NdrDiscoveryPluginContext() = default;
53 
54  /// Returns the source type associated with the discovery type.
55  /// This may return an empty token if there is no such association.
56  NDR_API
57  virtual TfToken GetSourceType(const TfToken& discoveryType) const = 0;
58 };
59 
61 
62 /// \class NdrDiscoveryPlugin
63 ///
64 /// Interface for discovery plugins.
65 ///
66 /// Discovery plugins, like the name implies, find nodes. Where the plugin
67 /// searches is up to the plugin that implements this interface. Examples
68 /// of discovery plugins could include plugins that look for nodes on the
69 /// filesystem, another that finds nodes in a cloud service, and another that
70 /// searches a local database. Multiple discovery plugins that search the
71 /// filesystem in specific locations/ways could also be created. All discovery
72 /// plugins are executed as soon as the registry is instantiated.
73 ///
74 /// These plugins simply report back to the registry what nodes they found in
75 /// a generic way. The registry doesn't know much about the innards of the
76 /// nodes yet, just that the nodes exist. Understanding the nodes is the
77 /// responsibility of another set of plugins defined by the `NdrParserPlugin`
78 /// interface.
79 ///
80 /// Discovery plugins report back to the registry via `NdrNodeDiscoveryResult`s.
81 /// These are small, lightweight classes that contain the information for a
82 /// single node that was found during discovery. The discovery result only
83 /// includes node information that can be gleaned pre-parse, so the data is
84 /// fairly limited; to see exactly what's included, and what is expected to
85 /// be populated, see the documentation for `NdrNodeDiscoveryResult`.
86 ///
87 /// \section create How to Create a Discovery Plugin
88 /// There are three steps to creating a discovery plugin:
89 /// <ul>
90 /// <li>
91 /// Implement the discovery plugin interface, `NdrDiscoveryPlugin`
92 /// </li>
93 /// <li>
94 /// Register your new plugin with the registry. The registration macro
95 /// must be called in your plugin's implementation file:
96 /// \code{.cpp}
97 /// NDR_REGISTER_DISCOVERY_PLUGIN(YOUR_DISCOVERY_PLUGIN_CLASS_NAME)
98 /// \endcode
99 /// This macro is available in discoveryPlugin.h.
100 /// </li>
101 /// <li>
102 /// In the same folder as your plugin, create a `plugInfo.json` file.
103 /// This file must be formatted like so, substituting
104 /// `YOUR_LIBRARY_NAME`, `YOUR_CLASS_NAME`, and `YOUR_DISPLAY_NAME`:
105 /// \code{.json}
106 /// {
107 /// "Plugins": [{
108 /// "Type": "library",
109 /// "Name": "YOUR_LIBRARY_NAME",
110 /// "Root": "@PLUG_INFO_ROOT@",
111 /// "LibraryPath": "@PLUG_INFO_LIBRARY_PATH@",
112 /// "ResourcePath": "@PLUG_INFO_RESOURCE_PATH@",
113 /// "Info": {
114 /// "Types": {
115 /// "YOUR_CLASS_NAME" : {
116 /// "bases": ["NdrDiscoveryPlugin"],
117 /// "displayName": "YOUR_DISPLAY_NAME"
118 /// }
119 /// }
120 /// }
121 /// }]
122 /// }
123 /// \endcode
124 ///
125 /// The NDR ships with one discovery plugin, the
126 /// `_NdrFilesystemDiscoveryPlugin`. Take a look at NDR's plugInfo.json
127 /// file for example values for `YOUR_LIBRARY_NAME`, `YOUR_CLASS_NAME`,
128 /// and `YOUR_DISPLAY_NAME`. If multiple discovery plugins exist in the
129 /// same folder, you can continue adding additional plugins under the
130 /// `Types` key in the JSON. More detailed information about the
131 /// plugInfo.json format can be found in the documentation for the
132 /// `plug` library (in pxr/base).
133 /// </li>
134 /// </ul>
135 ///
136 /// \deprecated
137 /// Deprecated in favor of SdrDiscoveryPlugin
139 {
140 public:
142 
143  NDR_API
145  NDR_API
146  virtual ~NdrDiscoveryPlugin();
147 
148  /// Finds and returns all nodes that the implementing plugin should be
149  /// aware of.
150  /// \deprecated
151  /// Deprecated in favor of SdrDiscoveryPlugin::DiscoverShaderNodes.
152  NDR_API
153  virtual NdrNodeDiscoveryResultVec DiscoverNodes(const Context&) = 0;
154 
155  /// Gets the URIs that this plugin is searching for nodes in.
156  NDR_API
157  virtual const NdrStringVec& GetSearchURIs() const = 0;
158 };
159 
160 
161 /// \cond
162 /// Factory classes should be hidden from the documentation.
163 /// \deprecated
164 /// Deprecated in favor of SdrDiscoveryPluginFactoryBase and
165 /// SdrDiscoveryPluginFactory
166 class NdrDiscoveryPluginFactoryBase : public TfType::FactoryBase
167 {
168 public:
169  NDR_API
170  virtual NdrDiscoveryPluginRefPtr New() const = 0;
171 };
172 
173 template <class T>
174 class NdrDiscoveryPluginFactory : public NdrDiscoveryPluginFactoryBase
175 {
176 public:
177  NdrDiscoveryPluginRefPtr New() const override
178  {
179  return TfCreateRefPtr(new T);
180  }
181 };
182 
183 /// \endcond
184 
186 
187 #endif // PXR_USD_NDR_DISCOVERY_PLUGIN_H
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1190
virtual NDR_API ~NdrDiscoveryPluginContext()=default
std::vector< NdrNodeDiscoveryResult > NdrNodeDiscoveryResultVec
NDR_API NdrDiscoveryPlugin()
Base class of all factory types.
Definition: type.h:56
Definition: token.h:70
virtual NDR_API NdrNodeDiscoveryResultVec DiscoverNodes(const Context &)=0
std::vector< std::string > NdrStringVec
Definition: declare.h:70
TF_DECLARE_WEAK_AND_REF_PTRS(NdrDiscoveryPluginContext)
virtual NDR_API const NdrStringVec & GetSearchURIs() const =0
Gets the URIs that this plugin is searching for nodes in.
#define NDR_API
Definition: api.h:23
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
virtual NDR_API ~NdrDiscoveryPlugin()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
virtual NDR_API TfToken GetSourceType(const TfToken &discoveryType) const =0