All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
scriptModuleLoader.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_TF_SCRIPT_MODULE_LOADER_H
8#define PXR_BASE_TF_SCRIPT_MODULE_LOADER_H
9
10#include "pxr/pxr.h"
11
12#include "pxr/base/tf/api.h"
13#include "pxr/base/tf/hash.h"
15#include "pxr/base/tf/spinRWMutex.h"
16#include "pxr/base/tf/token.h"
18
19// XXX: This include is a hack to avoid build errors due to
20// incompatible macro definitions in pyport.h on macOS.
21#include <locale>
22#include "pxr/external/boost/python/dict.hpp"
23
24#include <deque>
25#include <string>
26#include <unordered_map>
27#include <vector>
28
29PXR_NAMESPACE_OPEN_SCOPE
30
42
43 public:
44
46
48 TF_API static This &GetInstance() {
50 }
51
56 TF_API
57 void RegisterLibrary(TfToken const &name, TfToken const &moduleName,
58 std::vector<TfToken> const &predecessors);
59
63 TF_API
65
68 TF_API
69 void LoadModulesForLibrary(TfToken const &name);
70
73 TF_API
74 pxr_boost::python::dict GetModulesDict() const;
75
78 TF_API
79 void WriteDotFile(std::string const &file) const;
80
81 private:
82 friend class TfSingleton<This>;
83
84 struct _LibInfo {
85 _LibInfo() = default;
86 _LibInfo(TfToken const &moduleName,
87 std::vector<TfToken> &&predecessors)
88 : moduleName(moduleName)
89 , predecessors(predecessors) { }
90
91 TfToken moduleName;
92 std::vector<TfToken> predecessors;
93 mutable std::atomic<bool> isLoaded = false;
94 };
95
96 using _LibInfoMap =
97 std::unordered_map<TfToken, _LibInfo, TfToken::HashFunctor>;
98
99 using _LibAndInfo = _LibInfoMap::value_type;
100
102 virtual ~TfScriptModuleLoader();
103
104 _LibInfo const *_FindInfo(TfToken const &lib) const;
105
106 void _LoadLibModules(std::vector<_LibAndInfo const *> const &toLoad) const;
107
108 _LibInfoMap _libInfo;
109 mutable TfSpinRWMutex _mutex;
110};
111
112TF_API_TEMPLATE_CLASS(TfSingleton<TfScriptModuleLoader>);
113
114PXR_NAMESPACE_CLOSE_SCOPE
115
116#endif // PXR_BASE_TF_SCRIPT_MODULE_LOADER_H
Provides low-level facilities for shared libraries with script bindings to register themselves with t...
TF_API void LoadModules()
Load all the script modules for any libraries registered using RegisterLibrary if necessary.
TF_API void LoadModulesForLibrary(TfToken const &name)
Load all the script modules for any libraries registered using RegisterLibrary that depend on library...
static TF_API This & GetInstance()
Return the singleton instance.
TF_API void RegisterLibrary(TfToken const &name, TfToken const &moduleName, std::vector< TfToken > const &predecessors)
Register a library named name and with script module moduleName and libraries which must be loaded fi...
TF_API pxr_boost::python::dict GetModulesDict() const
Return a python dict containing all currently known modules under their canonical names.
TF_API void WriteDotFile(std::string const &file) const
Write a graphviz dot-file for the dependency graph of all currently registered libraries/modules to f...
Manage a single instance of an object (see.
Definition: singleton.h:105
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
Definition: singleton.h:120
This class implements a readers-writer spin lock that emphasizes throughput when there is light conte...
Definition: spinRWMutex.h:51
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:124
Manage a single instance of an object.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...