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
25 #include "pxr/pxr.h"
26 #include "pxr/usd/pcp/errors.h"
27 #include "pxr/base/tf/pyContainerConversions.h"
28 #include "pxr/base/tf/pyPtrHelpers.h"
29 #include "pxr/base/tf/pyResultConversions.h"
30
31 #include "pxr/base/tf/pyEnum.h"
32 #include <boost/python.hpp>
33
34 using namespace boost::python;
35
36 PXR_NAMESPACE_USING_DIRECTIVE
37
38 // Wrap this with a function so that add_property does not
39 // try to return an lvalue (and fail)
_GetErrorType(PcpErrorBasePtr const & err)40 static TfEnum _GetErrorType(PcpErrorBasePtr const& err)
41 {
42 return err->errorType;
43 }
44
45 void
wrapErrors()46 wrapErrors()
47 {
48 TfPyWrapEnum<PcpErrorType>("ErrorType");
49
50 // NOTE: Do not allow construction of these objects from Python.
51 // Boost Python's shared_ptr_from_python will attach a custom
52 // deleter that releases the PyObject, which requires the GIL.
53 // Therefore it's unsafe for C++ code to release a shared_ptr
54 // without holding the GIL. That's impractical so we just
55 // ensure that we don't create error objects in Python.
56
57 class_<PcpErrorBase, boost::noncopyable, PcpErrorBasePtr>
58 ("ErrorBase", "", no_init)
59 .add_property("errorType", _GetErrorType)
60 .def("__str__", &PcpErrorBase::ToString)
61 ;
62
63 class_<PcpErrorTargetPathBase, boost::noncopyable,
64 bases<PcpErrorBase>, PcpErrorTargetPathBasePtr >
65 ("ErrorTargetPathBase", "", no_init)
66 ;
67
68 class_<PcpErrorArcCycle, bases<PcpErrorBase>, PcpErrorArcCyclePtr >
69 ("ErrorArcCycle", "", no_init)
70 ;
71
72 class_<PcpErrorArcPermissionDenied, bases<PcpErrorBase>,
73 PcpErrorArcPermissionDeniedPtr>
74 ("ErrorArcPermissionDenied", "", no_init)
75 ;
76
77 class_<PcpErrorCapacityExceeded, bases<PcpErrorBase>,
78 PcpErrorCapacityExceededPtr >
79 ("ErrorCapacityExceeded", "", no_init)
80 ;
81
82 class_<PcpErrorInconsistentPropertyType, bases<PcpErrorBase>,
83 PcpErrorInconsistentPropertyTypePtr>
84 ("ErrorInconsistentPropertyType", "", no_init)
85 ;
86
87 class_<PcpErrorInconsistentAttributeType, bases<PcpErrorBase>,
88 PcpErrorInconsistentAttributeTypePtr>
89 ("ErrorInconsistentAttributeType", "", no_init)
90 ;
91
92 class_<PcpErrorInconsistentAttributeVariability, bases<PcpErrorBase>,
93 PcpErrorInconsistentAttributeVariabilityPtr>
94 ("ErrorInconsistentAttributeVariability", "", no_init)
95 ;
96
97 class_<PcpErrorInternalAssetPath, bases<PcpErrorBase>,
98 PcpErrorInternalAssetPathPtr>
99 ("ErrorInternalAssetPath", "", no_init)
100 ;
101
102 class_<PcpErrorInvalidPrimPath, bases<PcpErrorBase>,
103 PcpErrorInvalidPrimPathPtr>
104 ("ErrorInvalidPrimPath", "", no_init)
105 ;
106
107 class_<PcpErrorInvalidAssetPathBase, boost::noncopyable,
108 bases<PcpErrorBase>, PcpErrorInvalidAssetPathBasePtr>
109 ("ErrorInvalidAssetPathBase", "", no_init)
110 ;
111
112 class_<PcpErrorInvalidAssetPath, bases<PcpErrorInvalidAssetPathBase>,
113 PcpErrorInvalidAssetPathPtr>
114 ("ErrorInvalidAssetPath", "", no_init)
115 ;
116
117 class_<PcpErrorMutedAssetPath, bases<PcpErrorInvalidAssetPathBase>,
118 PcpErrorMutedAssetPathPtr>
119 ("ErrorMutedAssetPath", "", no_init)
120 ;
121
122 class_<PcpErrorInvalidInstanceTargetPath, bases<PcpErrorTargetPathBase>,
123 PcpErrorInvalidInstanceTargetPathPtr>
124 ("ErrorInvalidInstanceTargetPath", "", no_init)
125 ;
126
127 class_<PcpErrorInvalidExternalTargetPath, bases<PcpErrorTargetPathBase>,
128 PcpErrorInvalidExternalTargetPathPtr>
129 ("ErrorInvalidExternalTargetPath", "", no_init)
130 ;
131
132 class_<PcpErrorInvalidTargetPath, bases<PcpErrorTargetPathBase>,
133 PcpErrorInvalidTargetPathPtr>
134 ("ErrorInvalidTargetPath", "", no_init)
135 ;
136
137 class_<PcpErrorInvalidSublayerOffset, bases<PcpErrorBase>,
138 PcpErrorInvalidSublayerOffsetPtr>
139 ("ErrorInvalidSublayerOffset", "", no_init)
140 ;
141
142 class_<PcpErrorInvalidReferenceOffset, bases<PcpErrorBase>,
143 PcpErrorInvalidReferenceOffsetPtr>
144 ("ErrorInvalidReferenceOffset", "", no_init)
145 ;
146
147 class_<PcpErrorInvalidSublayerOwnership, bases<PcpErrorBase>,
148 PcpErrorInvalidSublayerOwnershipPtr>
149 ("ErrorInvalidSublayerOwnership", "", no_init)
150 ;
151
152 class_<PcpErrorInvalidSublayerPath, bases<PcpErrorBase>,
153 PcpErrorInvalidSublayerPathPtr>
154 ("ErrorInvalidSublayerPath", "", no_init)
155 ;
156
157 class_<PcpErrorInvalidVariantSelection, bases<PcpErrorBase>,
158 PcpErrorInvalidVariantSelectionPtr>
159 ("ErrorInvalidVariantSelection", "", no_init)
160 ;
161
162 class_<PcpErrorOpinionAtRelocationSource, bases<PcpErrorBase>,
163 PcpErrorOpinionAtRelocationSourcePtr>
164 ("ErrorOpinionAtRelocationSource", "", no_init)
165 ;
166
167 class_<PcpErrorPrimPermissionDenied, bases<PcpErrorBase>,
168 PcpErrorPrimPermissionDeniedPtr>
169 ("ErrorPrimPermissionDenied", "", no_init)
170 ;
171
172 class_<PcpErrorPropertyPermissionDenied, bases<PcpErrorBase>,
173 PcpErrorPropertyPermissionDeniedPtr>
174 ("ErrorPropertyPermissionDenied", "", no_init)
175 ;
176
177 class_<PcpErrorSublayerCycle, bases<PcpErrorBase>,
178 PcpErrorSublayerCyclePtr>
179 ("ErrorSublayerCycle", "", no_init)
180 ;
181
182 class_<PcpErrorTargetPermissionDenied, bases<PcpErrorTargetPathBase>,
183 PcpErrorTargetPermissionDeniedPtr>
184 ("ErrorTargetPermissionDenied", "", no_init)
185 ;
186
187 class_<PcpErrorUnresolvedPrimPath, bases<PcpErrorBase>,
188 PcpErrorUnresolvedPrimPathPtr>
189 ("ErrorUnresolvedPrimPath", "", no_init)
190 ;
191
192 // Register conversion for python list <-> vector<PcpErrorBasePtr>
193 to_python_converter< PcpErrorVector,
194 TfPySequenceToPython<PcpErrorVector> >();
195 TfPyContainerConversions::from_python_sequence<
196 PcpErrorVector,
197 TfPyContainerConversions::variable_capacity_policy >();
198 }
199
200 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInvalidVariantSelection)
201 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorPropertyPermissionDenied)
202 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorBase)
203 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorTargetPathBase)
204 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorArcCycle)
205 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorArcPermissionDenied)
206 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorCapacityExceeded)
207 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInconsistentPropertyType)
208 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInconsistentAttributeType)
209 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInconsistentAttributeVariability)
210 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInternalAssetPath)
211 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInvalidPrimPath)
212 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInvalidAssetPathBase)
213 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInvalidAssetPath)
214 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorMutedAssetPath)
215 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInvalidInstanceTargetPath)
216 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInvalidExternalTargetPath)
217 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInvalidTargetPath)
218 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInvalidSublayerOffset)
219 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInvalidReferenceOffset)
220 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInvalidSublayerOwnership)
221 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorInvalidSublayerPath)
222 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorOpinionAtRelocationSource)
223 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorPrimPermissionDenied)
224 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorSublayerCycle)
225 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorTargetPermissionDenied)
226 TF_REFPTR_CONST_VOLATILE_GET(PcpErrorUnresolvedPrimPath)
227