1 // 2 // Copyright 2016 Pixar 3 // 4 // Licensed under the Apache License, Version 2.0 (the "Apache License") 5 // with the following modification; you may not use this file except in 6 // compliance with the Apache License and the following modification to it: 7 // Section 6. Trademarks. is deleted and replaced with: 8 // 9 // 6. Trademarks. This License does not grant permission to use the trade 10 // names, trademarks, service marks, or product names of the Licensor 11 // and its affiliates, except as required to comply with Section 4(c) of 12 // the License and to reproduce the content of the NOTICE file. 13 // 14 // You may obtain a copy of the Apache License at 15 // 16 // http://www.apache.org/licenses/LICENSE-2.0 17 // 18 // Unless required by applicable law or agreed to in writing, software 19 // distributed under the Apache License with the above modification is 20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21 // KIND, either express or implied. See the Apache License for the specific 22 // language governing permissions and limitations under the Apache License. 23 // 24 #ifndef PXR_BASE_PLUG_INFO_H 25 #define PXR_BASE_PLUG_INFO_H 26 27 #include "pxr/pxr.h" 28 #include "pxr/base/arch/attributes.h" 29 #include "pxr/base/js/value.h" 30 31 #include <functional> 32 #include <memory> 33 #include <string> 34 #include <vector> 35 36 PXR_NAMESPACE_OPEN_SCOPE 37 38 class JsValue; 39 40 /// Data describing the plugin itself. 41 class Plug_RegistrationMetadata { 42 public: 43 enum Type { 44 UnknownType, 45 LibraryType, 46 #ifdef PXR_PYTHON_SUPPORT_ENABLED 47 PythonType, 48 #endif // PXR_PYTHON_SUPPORT_ENABLED 49 ResourceType 50 }; 51 Plug_RegistrationMetadata()52 Plug_RegistrationMetadata() : type(UnknownType) { } 53 Plug_RegistrationMetadata(const JsValue&, 54 const std::string& valuePathname, 55 const std::string& locationForErrorReporting); 56 57 Type type; 58 std::string pluginName; 59 std::string pluginPath; 60 JsObject plugInfo; 61 std::string libraryPath; 62 std::string resourcePath; 63 }; 64 65 /// A task arena for reading plug info. 66 class Plug_TaskArena { 67 public: 68 class Synchronous { }; // For single-threaded debugging. 69 Plug_TaskArena(); 70 Plug_TaskArena(Synchronous); 71 ~Plug_TaskArena(); 72 73 /// Schedule \p fn to run. 74 template <class Fn> 75 void Run(Fn const &fn); 76 77 /// Wait for all scheduled tasks to complete. 78 void Wait(); 79 80 private: 81 class _Impl; 82 std::unique_ptr<_Impl> _impl; 83 }; 84 85 /// Reads several plugInfo files, recursively loading any included files. 86 /// \p addPlugin is invoked each time a plugin is found. The order in 87 /// which plugins is discovered is undefined. \p addPlugin is invoked 88 /// by calling \c Run() on \p taskArena. 89 /// 90 /// \p addVisitedPath is called each time a plug info file is found; if it 91 /// returns \c true then the file is processed, otherwise it is ignored. 92 /// Clients should return \c true or \c false the first time a given path 93 /// is passed and \c false all subsequent times. 94 void 95 Plug_ReadPlugInfo( 96 const std::vector<std::string>& pathnames, 97 bool pathsAreOrdered, 98 const std::function<bool (const std::string&)>& addVisitedPath, 99 const std::function<void (const Plug_RegistrationMetadata&)>& addPlugin, 100 Plug_TaskArena* taskArena); 101 102 /// Sets the paths to the bootstrap plugInfo JSON files, also any diagnostic 103 /// messages that should be reported when plugins are registered (if any). 104 /// The priority order of elements of the path is honored if pathsAreOrdered. 105 /// Defined in registry.cpp. 106 void Plug_SetPaths(const std::vector<std::string>&, 107 const std::vector<std::string>&, 108 bool pathsAreOrdered); 109 110 PXR_NAMESPACE_CLOSE_SCOPE 111 112 #endif // PXR_BASE_PLUG_INFO_H 113