HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_OTLManager.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: OP_OTLManager.h ( OTL Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __OP_OTLManager__
13 #define __OP_OTLManager__
14 
15 #include "OP_API.h"
16 #include <UT/UT_Compression.h>
17 #include <UT/UT_IntArray.h>
18 #include <UT/UT_String.h>
19 #include <UT/UT_StringArray.h>
20 #include <UT/UT_StringHolder.h>
21 #include <UT/UT_SymbolTable.h>
22 #include <UT/UT_UniquePtr.h>
23 #include <UT/UT_ValArray.h>
24 #include <iosfwd>
25 #include <time.h>
26 
27 class OP_Node;
28 class OP_Operator;
29 class OP_OperatorTable;
30 class OP_OTLManagerSink;
31 class OP_OTLLibrary;
32 class OP_OTLDefinition;
34 class FS_IndexFile;
35 class UT_IStream;
36 class UT_StringSet;
37 class UT_WorkBuffer;
38 
39 #define OP_TYPEBARMODE_FULLMENU "fullmenu"
40 #define OP_TYPEBARMODE_AUTOMENU "automenu"
41 #define OP_TYPEBARMODE_DISPLAYONLY "displayonly"
42 #define OP_TYPEBARMODE_NONE "none"
43 
44 // Note that the string is deliberately misleading,
45 // since the "compiled" flag might be just a little
46 // too obvious.
47 #define OP_IS_OTL_COMPILED "nodeconntype"
48 
49 // Black boxed assets are assets whose implementation details are hidden
50 // to the user. However, these need no licensing information and can be freely
51 // distributed. This flag is used to indicate if an asset is blackboxed and
52 // is purposefully obfuscated, simmilar to the flag above.
53 #define OP_IS_OTL_BLACKBOXED "nodeparmtype"
54 
55 // Functions get executed whenever we call OP_OTLManager::saveOpTypeFromNode.
57 
59 {
60 public:
61 
63  virtual ~OP_OTLLoadCallback() {}
64 
65  virtual bool onOTLLoadBegin(const char* otl_name,
66  const OP_OTLLibrary* opt_lib,
67  OP_Operator* opt_operator,
68  UT_String& error_message_out) = 0;
69 };
70 
72 {
73 public:
74  OP_OTLManager();
75  virtual ~OP_OTLManager();
76 
77  // Getting and setting of configuration information.
78  bool getSaveToHipFile() const;
79  void setSaveToHipFile(bool savetohip);
80  bool getSaveUnlockedToHipFile() const;
81  void setSaveUnlockedToHipFile(bool saveunlockedtohip);
82  bool getWarnOutOfDateOps() const;
83  void setWarnOutOfDateOps(bool warn);
84  bool getWarnDummyOpsOnLoad() const;
85  void setWarnDummyOpsOnLoad(bool warn);
86  bool getPreferLatestDate() const;
87  void setPreferLatestDate(bool preferlatest);
88  bool getPreferInternal() const;
89  void setPreferInternal(bool preferinternal);
90  bool getPreferIndexFile() const;
91  void setPreferIndexFile(bool preferindexfile);
92  bool getCreateBackups() const;
93  void setCreateBackups(bool createbackups);
94  bool getSafeguardOpDefs() const;
95  void setSafeguardOpDefs(bool safeguardopdefs);
96  bool getLeaveDefaultsUnchanged() const;
97  void setLeaveDefaultsUnchanged(bool leavedefaultsunchanged);
98  bool getUseOplibrariesFiles() const;
99  void setUseOplibrariesFiles(bool useoplibrariesfiles);
100  const UT_StringHolder&getOperatorTypeBarMode() const;
101  void setOperatorTypeBarMode(const UT_StringHolder &mode);
102  const UT_StringArray&getAllowedOperatorTypeBarModes() const;
103 
104  /// Register a new class to be used as a callback when an OTL library
105  /// is loaded.
106  static void registerOTLLoadCallback(OP_OTLLoadCallback * cb);
107 
108  /// Executes onOTLLoadBegin() for each registered callback and returns the result
109  bool runOTLCallbacks(const char* otl_name,
110  const OP_OTLLibrary* opt_lib,
111  OP_Operator* opt_operator,
112  UT_String& error_out);
113 
114  /// Gets the list of otls that have tried to load and failed.
115  UT_StringArray &getFailedOTLs();
116 
117  /// Reset the list of failed otls.
118  void clearFailedOTLList();
119 
120  /// Load in the contents of an OPlibraries file. This is public so that
121  /// when loading a hip file, the OP_Director can use this to parse the
122  /// .OPlibraries packet.
123  bool loadOpLibrariesFile(UT_IStream &is,
124  const char *metasrc, int &libpos);
125  /// Saves the .OPlibraries section that will be included in a .hip file.
126  /// This file must be different from the one above because it has to
127  /// skip the internal hip file library.
128  bool saveInternalMetaFile(std::ostream &os,
129  const char *prefix = 0) const;
130 
131  /// Picks a particular OTL to be the preferred library for a particular
132  /// operator type. Returns true if the operator type exists in an OTL.
133  /// Even if we return false, we keep the information in case this
134  /// operator type gets loaded later.
135  /// WARNING: This method may reload libraries, so holding OP_OTLLibrary
136  /// pointers across this call is unsafe.
137  void setLibraryPreference(const char *tablename,
138  const char *opname,
139  const char *libfile);
140  /// Sets the preference on all assets in the supplied library if
141  /// they are not already the current definition.
142  /// WARNING: This method may reload libraries, so holding OP_OTLLibrary
143  /// pointers across this call is unsafe.
144  void setLibraryPreferencesIfRequired(int index);
145  /// Gets the preferred library for a particular operator type. Returns
146  /// null if no preference is set, or the operator type is not known.
147  const char *getLibraryPreference(const char *tablename,
148  const char *opname) const;
149  /// Clear all explicit preferences.
150  void clearLibraryPreferences(bool refreshlibs);
151  /// Functions to save and load the preferred OTL information.
152  bool loadLibraryPreferences(UT_IStream &is);
153  void saveLibraryPreferences(std::ostream &os,
154  bool includeinternal = true,
155  bool protectstrings = false) const;
156 
157  /// Returns the descriptive name for a particular meta source.
158  const UT_StringHolder &getMetaSourceName(OP_OTLLibrary *lib,
159  bool withpath = true) const;
160  void getMetaSourceName(const char *metasrc,
161  UT_String &metasrcname,
162  bool withpath = true) const;
163  bool setMetaSourceName(const char *metasrc,
164  const char *metasrcname);
165 
166  /// Returns true if we are adding a new instance of an existing library,
167  /// followed immediately be removing the old copy. If so, we can do some
168  /// optimizations in OP_Director::definitionsAdded.
169  bool getIsPerformingAtomicAddRemove() const;
170 
171  /// Returns true if we are in the middle of a call to refreshAll. If we
172  /// are, we can optimize out a whole bunch of calls that can be done
173  /// once at the end of the refresh.
174  bool getIsPerformingRefreshAll() const;
175 
176  /// Returns true if we are in the middle of adding, removing or
177  /// refreshing a library.
178  bool getIsChangingLibraries() const;
179 
180  /// Returns true if the manager is in teh process of creating a new HDA.
181  bool getIsCreatingNewHDA() const;
182 
183  /// Basic operations of adding and removing libraries.
184  void loadAutoOTLs();
185  void installLibrary(char const* lib_filepath, char const* oplib_filepath=nullptr);
186 
187  /// Install a list of libraries as a batch operation.
189  addLibraries(const UT_StringArray& lib_filepaths,
190  const char *metasrcbase,
191  bool changeoplibraries,
192  bool installinternaliffail,
193  UT_WorkBuffer &errors);
194 
195  /// Install a list of .OPLibraries files as a batch operation.
196  void installOpLibraries(const UT_StringArray& oplib_filepaths);
197 
198  int findLibrary(const char *libfile,
199  const char *metasrc = 0) const;
200  int findNextLibrary(const char *libfile,
201  int after) const;
202  bool refreshLibrary(int index, bool force = true);
203  bool removeLibrary(const char *libfile,
204  const char *metasrc,
205  bool changeoplibraries);
206 
207  /// Refresh a list of libraries as a batch operation
208  bool refreshLibraries(const UT_IntArray &indices, bool force = true);
209 
210  /// Remove a list of multiple libraries as a batch operation
211  bool removeLibraries(const UT_StringArray& libfiles,
212  const char *metasrc,
213  bool changeoplibraries);
214 
215  bool removeMetaSource(const char *metasrc);
216 
217  /// Refresh all libraries as a batch operation.
218  void refreshAll(bool reload_op_libraries);
219 
220  /// This function adds the libfile to the specified metasrc if it
221  /// isn't there already (or moves it to the specified position if
222  /// it is there). This is the function external callers should
223  /// always use.
224  OP_OTLLibrary *addLibrary(const char *libfile,
225  const char *metasrc,
226  bool changeoplibraries,
227  bool installinternaliffail,
228  UT_WorkBuffer &errors);
229 
230  // Get basic library information.
231  int getNumLibraries() const;
232  int getPreferredLibrary(const char *tablename,
233  const char *opname);
234  OP_OTLLibrary *getLibrary(int index) const;
235 
236  /// Returns the library that contains the latest (by date) definition
237  /// for the specified operator.
238  int getLatestLibrary(const char *tablename,
239  const char *opname,
240  OP_OTLLibrary *tiegoesto = 0);
241  bool getOutOfDateInternalOps(UT_StringArray &ops);
242 
243  /// Returns the next library with a definition for the specified operator.
244  /// This function loops around to the start of the library list.
245  int getNextLibrary(const char *tablename,
246  const char *opname,
247  OP_OTLLibrary *startat);
248 
249  /// Adds an operator definition to an existing library, or creates
250  /// a new library file if necessary.
251  static bool addToLibrary(OP_OTLLibrary *lib,
252  OP_OTLDefinition &definition,
253  FS_IndexFile *deffile,
254  bool dummydefinition = false);
255  bool addToLibrary(const char *libfile,
256  OP_OTLDefinition &definition,
257  FS_IndexFile *deffile,
258  bool dummydefinition = false,
259  bool create_op_type=false,
260  bool create_backup=true);
261 
262  /// Take the secondary library and merge it into the primary library,
263  /// and save the combined file out to the primary library.
264  bool mergeLibraries(const char *primary,
265  const char *secondary,
266  bool overwrite);
267 
268  /// These functions are for maintaining our one "internal" library.
269  /// This library is where we keep op definitions that have been loaded
270  /// form the hip file, or definitions that we want to uninstall but
271  /// couldn't because of existing operators of that type.
272  bool addToInternalLibrary(OP_OTLLibrary *newlib);
273  bool addToInternalLibrary(UT_IStream &is, time_t modtime);
274 
275  /// Removes some operator definitions from an existing library. We
276  /// check the file name to determine if we are removing from the
277  /// internal library, or an external library file.
278  bool removeFromLibrary(const char *libfile,
279  const UT_StringArray &ops);
280 
281  /// Update the date stamp for the specified definition to be the current
282  /// date. Do a refresh of the library if it is loaded.
283  bool touchDefinition(const char *libfile,
284  const char *tablename,
285  const char *opname,
286  int newtime = -1);
287 
288  /// This functions modifies the data in the OTLDefinition so that it
289  /// will refer to the given index file so that both these elements can
290  /// be embedded into an OTLLibrary.
291  static void modifyDefinitionToInternalPaths(
292  OP_OTLDefinition &def,
293  FS_IndexFile *deffile);
294 
295  /// A utility function for saving the operator definition for a given node.
296  void saveOpTypeFromNode( OP_Node *node, UT_String &errors );
297 
298  /// A utility function for updating the Contents section of an asset
299  /// definition based on a particular OP_Node. The compile flags can be
300  /// used to control whether the contents are compiled
301  void updateContentsFromNode(
302  FS_IndexFile *deffile,
303  OP_Node *node,
304  UT_CompressionType compression_type,
305  bool compilebasic,
306  bool compilevopnets,
307  bool compilechannels,
308  bool compilenodenames,
309  const char *library,
310  bool blackbox = false);
311 
312  /// A utility function for updating an operator definition based on
313  /// a particular OP_Node.
314  void updateDefinitionFromNode(
315  FS_IndexFile *deffile,
316  OP_Node *node,
317  bool lockcontents,
318  bool usedsparms,
319  UT_CompressionType compression_type,
320  bool savespareparms,
321  bool compile_asset,
322  const char *library,
323  bool blackbox = false);
324 
325  /// A utility functino to make sure that the Contents section of the
326  /// given file is either compressed or not, as set by gzipcontents.
327  void setContentsCompression(
328  FS_IndexFile *deffile,
329  UT_CompressionType compression_type);
330  /// Utility functions for getting/setting the comment and version data in an
331  /// operator type definition index file.
332  bool getComment(FS_IndexFile *deffile, UT_String &result);
333  void setComment(FS_IndexFile *deffile, const char *comment);
334  bool getVersion(FS_IndexFile *deffile, UT_String &result);
335  void setVersion(FS_IndexFile *deffile, const char *version);
336 
337  /// Functions for listing information about libraries and ops.
338  void listLibraries(std::ostream &os) const;
339  void listLibrariesWithDefinition(const char *tablename,
340  const char *opname,
341  std::ostream &os) const;
342  void listOperators(const char *libfile,
343  std::ostream &os) const;
344  void listOperator(const char *libfile,
345  const char *tablename,
346  const char *opname,
347  const char *format,
348  std::ostream &os) const;
349 
350  /// Function to get a list of the libraries containing a definition for
351  /// the specified type.
352  void getLibrariesWithDefinition(
353  const char *tablename,
354  const char *opname,
356 
357  /// Get a list of all operators (in tablename/optypenae form) that match
358  /// the passed in mask, which may contain wildcards. Before adding a result
359  /// to the array, it checks the symbol table to see if the result has
360  /// already been found. The tablename/optype string is added to the results
361  /// array. If a library pointer is passed in, only that library is searched.
362  /// Optypes found in that library do not need to be installed or current in
363  /// the Houdini session. If no library is passed in all current definitions
364  /// are searched, and all non-current definitions are ignored (so there
365  /// can be no confusion about which instance of an optype definition
366  /// was found. Returns true if some matching optype was found (even if
367  /// that optype wasn't added because of it already being in the symbol
368  /// table).
369  bool getAllMatchingOperators(const char *opmask,
370  const OP_OTLLibrary *library,
371  bool onlyotlops,
372  UT_StringArray &results,
373  UT_StringSet &resultstable) const;
374 
375  /// Functions for handling our interests.
376  void addManagerSink(OP_OTLManagerSink *sink);
377  void removeManagerSink(OP_OTLManagerSink *sink);
378 
379  /// Checks if the given table and operator type name are valid.
380  bool checkValidNodeName(const char *name,
382  UT_WorkBuffer &errors);
383  /// Creates a new operator type in an OTL, and installs that OTL.
384  bool createOptype(OP_OTLDefinition &def,
385  const char *installpath,
386  const char *extradsinfo,
387  const char *installmetasrc,
388  const UT_StringMap<UT_StringHolder> &extrasections,
389  UT_WorkBuffer &errors,
390  bool create_backup=true);
391 
392 
393  /// Creates a new operator type in an OTL, and installs that OTL.
394  bool createOptype(const char *tablename,
395  const char *opname,
396  const char *oplabel,
397  const char *installpath,
398  int min_input, int max_input,
399  int max_outputs,
400  const char *extradsinfo,
401  const char *installmetasrc,
402  const char *extrainfo,
403  bool subnet,
404  UT_WorkBuffer &errors,
405  bool create_backup=true);
406 
407  static bool getHelpTemplateFile(UT_String &helptemplatefile);
408  static void createDefaultOptypeName(OP_Node *fromnode,
409  UT_String &name,
410  UT_String &label);
411  static void createOptypeLabelFromName(UT_String name,
412  UT_String &label);
413  static void createOptypeNameFromLabel(UT_String label,
414  UT_String &name);
415  static void fullyQualifyLibFileName(const char *libfilebase,
416  UT_String &libfile,
417  const char *basedir = 0);
418  void fullyQualifyMetaSrcName(const char *libfilebase,
419  UT_String &libfile) const;
420  void getSimplifiedPath(UT_String &destpath,
421  const char *srcpath,
422  const char *srcmeta) const;
423 
424  bool canSavePreferences() const;
425 
426  /// Functions for managing fallback libraries. These are libraries that
427  /// are automatically loaded (as a last resort) if a particular type
428  /// definition is missing.
429  ///
430  /// The manager maintains a stack of fallback contexts. In general, each
431  /// fallback context contains the fallback paths specified in a particular
432  /// file fragment (hip file, digital asset contents section) and remains
433  /// active until that file fragment is processed by the loading mechanism.
434  void pushFallbackLibraryContext();
435  void popFallbackLibraryContext();
436  void saveFallbackLibraryPaths(std::ostream &os,
437  const OP_OperatorList &ops) const;
438  bool loadFallbackLibraryPaths(UT_IStream &is);
439  bool loadFallbackLibrary(const char *tablename,
440  const char *opname);
441 
442  /// Functions for managing the dummy definitions for each operator.
443  /// The dummy definition is just a dialog script copied from the last time
444  /// the operator was loaded. It is retrieved if no other definition for
445  /// the operator is available. It should be enough information to load
446  /// and re-save a hip file containing an unknown operator type without
447  /// losing any information.
448  void setDummyDefinition(const OP_OTLDefinition &definition,
449  const FS_IndexFile *deffile);
450  bool getDummyDefinition(const OP_Operator *op,
451  FS_IndexFile *deffile) const;
452  bool loadDummyDefinitions(UT_IStream &is, time_t modtime);
453  void saveDummyDefinitions(std::ostream &os,
454  const OP_OperatorList &ops) const;
455 
456  /// Saves an empty (but valid) dialog script to a stream.
457  static void saveDefaultDialogScript(std::ostream &os,
458  const char *opname,
459  const char *oplabel,
460  const char *extradsinfo);
461  /// Saves a default, do-nothing creation script to a stream.
462  static void saveDefaultCreationScript(std::ostream &os,
463  const char *op,
464  const char *table);
465 
466  /// Writes the index file 'contents' to the output stream 'os'. Ensures
467  /// that the filtering options (ie encryption) are set correctly on the
468  /// index file before it is written out.
469  static void writeOutDefinitionContents(
470  const OP_OTLDefinition &definition,
471  FS_IndexFile & contents,
472  std::ostream & os);
473 
474  /// Sets the encryption and decryption filters on the contents.
475  static void setFilters(const OP_OTLDefinition &definition,
476  FS_IndexFile &contents);
477 
478  /// Reload OTL license files, and notify interested parties of the
479  /// potential for change.
480  void refreshLicenses();
481 
482  /// Get the real file name that is presently being used for the Embedded
483  /// library. This should be used very carefully, and the value should not
484  /// be stored, because it will change anytime a definition is added to or
485  /// removed from the Embedded library.
486  const UT_String &getInternalTempFile() const;
487 
488  /// Checks if the library has a non-commercial (tainted) asset.
489  /// Note, the library does not have to be loaded yet.
490  bool hasNCAsset(const OP_OTLLibrary *lib);
491 
492  /// Returns an array of asset indices that are non-commercial
493  /// Note, the library does not have to be loaded yet.
494  void getNCAssets(const OP_OTLLibrary *lib,
495  UT_IntArray & nc_assets);
496 
497  /// Only called by FUSE_AssetsMenu to clean dirty flags of assets.
499  {mySaveOpTypeCallback = cb;}
500 
501  /// Convert libraries between different formats
502  bool convertLibraryToFile(const char *libfilebase,
503  const char *metasrcbase);
504  bool convertLibraryToDir(const char *libfilebase,
505  const char *metasrcbase);
506 
507 private:
508  struct OTLFallbackData
509  {
510  public:
511  UT_StringArray myPaths;
512  bool myFailFlag;
513  };
514  typedef UT_SymbolMap<OTLFallbackData *> FallbackContext;
515 
516  // Helper struct for doing bulk refresh operations
517  class RefreshScope;
518  friend class RefreshScope;
519 
520  // Helper struct that tracks library changes that are in progress.
521  class ChangeScope;
522  friend class ChangeScope;
523 
524  // Functions for sending notifications to our interests.
525  void notifySinksOfAssetCreated(
526  const OP_OTLLibrary &library,
527  const OP_OTLDefinition &def);
528  void notifySinksOfAssetDeleted(
529  const OP_OTLLibrary &library,
530  const OP_OTLDefinition &def);
531  void notifySinksOfAssetSaved(
532  const OP_OTLLibrary &library,
533  const OP_OTLDefinition &def);
534  void notifySinksOfBeforeAssetCreated(
535  const OP_OTLLibrary &library,
536  const OP_OTLDefinition &def);
537  void notifySinksOfBeforeAssetDeleted(
538  const OP_OTLLibrary &library,
539  const OP_OTLDefinition &def);
540  void notifySinksOfBeforeAssetSaved(
541  const OP_OTLLibrary &library,
542  const OP_OTLDefinition &def);
543  void notifySinksOfLibraryInstalled(OP_OTLLibrary *library);
544  void notifySinksOfLibraryUninstalled(
545  OP_OTLLibrary *library);
546  void notifySinksOfDefinitionsAdded(int libindex,
547  UT_IntArray &defarray);
548  void notifySinksOfDefinitionsRemoved(int libindex,
549  UT_IntArray &defarray,
550  OP_OTLLibrary *&preserve);
551  void notifySinksOfSourceNamesChanged();
552  void notifySinksOfLibraryAdded(OP_OTLLibrary *library);
553  void notifySinksOfLibraryRemoved(OP_OTLLibrary *library);
554  void notifySinksOfConfigurationChanged();
555  void notifySinksOfLicensesChanged();
556  void writeSimplifiedPath(std::ostream &os,
557  const char *srcpath,
558  const char *srcmeta,
559  const char *prefix = 0) const;
560 
561  /// Sets meta source name data for a given meta source.
562  void setMetaSourceNameData(int pos, const char *metasrc,
563  const char *metasrcname);
564  /// Saves an OPlibraries file by looking through our libraries and
565  /// writing out any loaded library that uses that meta source. Optionally
566  /// we can also specify a single library that should not be written, or
567  /// an extra library that should be written.
568  bool saveMetaFile(const char *metafile,
569  const char *skiplib,
570  const char *addlib) const;
571  /// Adds a library to an OPlibraries file, and returns the index of
572  /// where in the overall list of libraries the new library should
573  /// be inserted. Used by addLibrary.
574  int addToMetaSource(const char *libfile,
575  const char *metasrc,
576  bool changeoplibraries);
577  /// Put a library into our list at a particular position. Used
578  /// internally to actually add libraries.
579  ///
580  /// Returns true on success and false on failure. On failure, the
581  /// library is deleted.
582  bool insertLibrary(OP_OTLLibrary *newlib, int before);
583  /// Internal removeLibrary used to actually remove a library.
584  bool removeLibrary(int index, bool external=false);
585  /// Functions for loading and saving our preferences file.
586  void loadPreferences();
587  void savePreferences();
588  /// Use this function to create a new temp file for our internal library.
589  void moveInternalToNewTempFile();
590  /// Removes from lib any definitions for which there is already a
591  /// non-dummy definition in existance.
592  void clearIfGoodDefinitionExists(OP_OTLLibrary *lib);
593  /// Removes some operator definitions from an existing library file.
594  bool removeFromExternalLibrary(const char *libfile,
595  const UT_StringArray &ops);
596  /// Removes some operator defintions from the internal library, but
597  /// only if it is safe to do so (either there is another library
598  /// ready to take over the definition, or the opertor is unused).
599  bool removeFromInternalLibrary(const UT_StringArray &ops);
600  /// backup a libfile before replacing it with the new one. NOTE this
601  /// deletes 'newlib' before returning in order to close any file pointers
602  bool backupAndWriteNewLibrary(const char *libfilebase,
603  const char *libfile,
604  OP_OTLLibrary *newlib);
605 
606  /// Helper functions for touchDefinition which set the modification
607  /// time for an operator definition in either the internal library or
608  /// an external library file.
609  bool touchExternalDefinition(const char *libfile,
610  const char *tablename,
611  const char *opname,
612  int newtime);
613  bool touchInternalDefinition(const char *tablename,
614  const char *opname,
615  int newtime);
616  /// Adds a library from an OPlibraries file.
617  void addFromOpLibrariesFile(const char *file,
618  const char *metasrc,
619  int &libpos);
620 
621  /// Private utility method for implementing the public method.
622  void setLibraryPreference(const char *tablename,
623  const char *opname,
624  const char *libfile,
625  UT_IntArray *libstorefresh);
626 
627  /// Some private utility methods for managing the fallback library tables.
628  void addFallbackLibraryPath(const char *tablename,
629  const char *opname,
630  const char *libfile);
631  bool loadFallbackLibrary(FallbackContext *context,
632  const char *opsymbol,
633  const char *tablename,
634  const char *opname);
635  void clearLibraryFallbacks(FallbackContext *table);
636 
637  /// Tests if the definition is for a non-commercial asset.
638  bool isNCAsset(const FS_IndexFile *lib_file,
639  const OP_OTLDefinition & def);
640 
641  /// This static exit callback is here in case we allocate an
642  /// OP_OTLManager then never free it (which we do, since we never
643  /// delete our OP_Director).
644  static void deleteLibraries(void *data);
645 
646 private: // data
647 
648  UT_ValArray<OP_OTLLibrary *> myLibraries;
649  UT_ValArray<OP_OTLManagerSink *> myManagerSinks;
650  UT_ValArray<OP_OTLLibrary *> myLibrariesBeingRemoved;
651  UT_String myInternalTempFile;
652  UT_String myNewInternalTempFile;
653  UT_StringArray myMetaSourcesWithNames;
654  UT_StringArray myMetaSourceNames;
655  UT_StringArray myMetaSourceNameWithPaths;
656  UT_SymbolMap<UT_StringHolder> myLibraryPreferences;
657  UT_ValArray<FallbackContext *> myLibraryFallbacks;
658  UT_UniquePtr<OP_OTLLibrary> myDummyDefinitions;
659  UT_StringHolder myOperatorTypeBarMode;
660  UT_StringArray myFailedOTLs;
661  OP_SaveOpTypeCallback mySaveOpTypeCallback;
662  int myPerformingRefreshAll;
663  bool myIsPerformingAtomicAddRemove;
664  bool mySaveToHipFile;
665  bool mySaveUnlockedToHipFile;
666  bool myWarnOutOfDateOps;
667  bool myWarnDummyOpsOnLoad;
668  bool myPreferLatestDateDefinition;
669  bool myPreferInternalDefinition;
670  bool myPreferIndexFileDefinition;
671  bool myCreateBackups;
672  bool mySafeguardOpDefs;
673  bool myLeaveDefaultsUnchanged;
674  bool myUseOplibrariesFiles;
675  bool myIsCreatingNewHDA;
676 
678  theOTLLoadCallbacks;
679 };
680 
682 {
683 public:
686  { removeAllManagerSinks(); }
687 
688  /// Called when an asset definition is created.
689  /// This differs from definitionsAdded() which is called even
690  /// when a library is refreshed.
691  virtual void assetCreated(
692  const OP_OTLLibrary &library,
693  const OP_OTLDefinition &def) {}
694 
695  /// Called when an asset definition is deleted from the library.
696  /// This differs from definitionsRemoved() which is called even
697  /// when a library is refreshed.
698  virtual void assetDeleted(
699  const OP_OTLLibrary &library,
700  const OP_OTLDefinition &def) {}
701 
702  /// Called when an asset definition is saved.
703  virtual void assetSaved(
704  const OP_OTLLibrary &library,
705  const OP_OTLDefinition &def) {}
706 
707  /// Called right before an asset definition is created.
708  virtual void beforeAssetCreated(
709  const OP_OTLLibrary &library,
710  const OP_OTLDefinition &def) {}
711 
712  /// Called right before an asset definition is removed from a library.
713  virtual void beforeAssetDeleted(
714  const OP_OTLLibrary &library,
715  const OP_OTLDefinition &def) {}
716 
717  /// Called right before an asset definition is saved.
718  virtual void beforeAssetSaved(
719  const OP_OTLLibrary &library,
720  const OP_OTLDefinition &def) {}
721 
722  /// libraryInstalled() is called after an HDA library is installed.
723  /// This differs from libraryAdded() which is called after a library
724  /// is added to the manager's library list. The latter can be called
725  /// several times in a session due to a library being installed or updated.
726  virtual void libraryInstalled(const OP_OTLLibrary *library) {}
727 
728  /// libraryUinstalled() is called after an HDA library was uninstalled.
729  /// This differs from libraryRemoved() which is called after a library
730  /// is removed from the manager's library list. The latter can be
731  /// called several times in a session due to a library being uninstalled
732  /// or updated.
733  virtual void libraryUninstalled(const OP_OTLLibrary *library) {}
734 
735  virtual void definitionsAdded(int /*libindex*/,
736  UT_IntArray & /*defindex*/) { }
737  virtual void definitionsRemoved(int /*libindex*/,
738  UT_IntArray & /*defindex*/,
739  OP_OTLLibrary *& /*preserve*/){ }
740  virtual void sourceNamesChanged() { }
741  virtual void libraryAdded(OP_OTLLibrary * /*library*/) { }
742  virtual void libraryRemoved(OP_OTLLibrary * /*library*/) { }
743  virtual void configurationChanged() { }
744  virtual void licensesChanged() { }
745 
747  { removeManagerSink(manager); }
748 
749 protected:
751  {
752  if( !manager ) return;
753 
754  // Don't add if we have already added ourselves
755  // to the manager.
756  if (myManagers.find(manager) != -1)
757  return;
758 
759  manager->addManagerSink(this);
760  myManagers.append(manager, 1);
761  }
763  {
764  if( !manager ) return;
765  manager->removeManagerSink(this);
766  myManagers.findAndRemove(manager);
767  }
769  {
770  for( int i = myManagers.entries(); i --> 0; )
771  removeManagerSink(myManagers(i));
772  }
773 
774 private:
775  UT_ValArray<OP_OTLManager *> myManagers;
776 };
777 
778 #endif
779 
void removeManagerSink(OP_OTLManagerSink *sink)
int getVersion(int version)
Definition: ImfVersion.h:99
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
void addManagerSink(OP_OTLManager *manager)
void
Definition: png.h:1083
virtual void libraryInstalled(const OP_OTLLibrary *library)
virtual void libraryRemoved(OP_OTLLibrary *)
virtual ~OP_OTLLoadCallback()
Definition: OP_OTLManager.h:63
virtual void definitionsRemoved(int, UT_IntArray &, OP_OTLLibrary *&)
**But if you need a result
Definition: thread.h:622
virtual void licensesChanged()
void removeManagerSink(OP_OTLManager *manager)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
void removeAllManagerSinks()
virtual void libraryAdded(OP_OTLLibrary *)
void managerDeleted(OP_OTLManager *manager)
virtual ~OP_OTLManagerSink()
void setSaveOpTypeCallback(OP_SaveOpTypeCallback cb)
Only called by FUSE_AssetsMenu to clean dirty flags of assets.
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
OPENVDB_API void setVersion(std::ios_base &, const VersionId &libraryVersion, uint32_t fileVersion)
Associate specific file format and library version numbers with the given stream. ...
virtual void assetSaved(const OP_OTLLibrary &library, const OP_OTLDefinition &def)
Called when an asset definition is saved.
GLuint const GLchar * name
Definition: glcorearb.h:786
GLenum GLenum GLsizei void * table
Definition: glad.h:5129
void addManagerSink(OP_OTLManagerSink *sink)
Functions for handling our interests.
virtual void configurationChanged()
GLenum mode
Definition: glcorearb.h:99
GT_API const UT_StringHolder version
virtual void beforeAssetDeleted(const OP_OTLLibrary &library, const OP_OTLDefinition &def)
Called right before an asset definition is removed from a library.
SIM_API const UT_StringHolder force
UT_CompressionType
#define OP_API
Definition: OP_API.h:10
GLuint index
Definition: glcorearb.h:786
virtual void assetDeleted(const OP_OTLLibrary &library, const OP_OTLDefinition &def)
void(* OP_SaveOpTypeCallback)(OP_Node *)
Definition: OP_OTLManager.h:56
virtual void libraryUninstalled(const OP_OTLLibrary *library)
virtual void sourceNamesChanged()
virtual void assetCreated(const OP_OTLLibrary &library, const OP_OTLDefinition &def)
virtual void definitionsAdded(int, UT_IntArray &)
virtual void beforeAssetCreated(const OP_OTLLibrary &library, const OP_OTLDefinition &def)
Called right before an asset definition is created.
virtual void beforeAssetSaved(const OP_OTLLibrary &library, const OP_OTLDefinition &def)
Called right before an asset definition is saved.
Definition: format.h:1821