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 the manager is in teh process of creating a new HDA.
177  bool getIsCreatingNewHDA() const;
178 
179  /// Basic operations of adding and removing libraries.
180  void loadAutoOTLs();
181  void installLibrary(char const* lib_filepath, char const* oplib_filepath=nullptr);
182 
183  /// Install a list of libraries as a batch operation.
185  addLibraries(const UT_StringArray& lib_filepaths,
186  const char *metasrcbase,
187  bool changeoplibraries,
188  bool installinternaliffail,
189  UT_WorkBuffer &errors);
190 
191  /// Install a list of .OPLibraries files as a batch operation.
192  void installOpLibraries(const UT_StringArray& oplib_filepaths);
193 
194  int findLibrary(const char *libfile,
195  const char *metasrc = 0) const;
196  int findNextLibrary(const char *libfile,
197  int after) const;
198  bool refreshLibrary(int index, bool force = true);
199  bool removeLibrary(const char *libfile,
200  const char *metasrc,
201  bool changeoplibraries);
202 
203  /// Refresh a list of libraries as a batch operation
204  bool refreshLibraries(const UT_IntArray &indices, bool force = true);
205 
206  /// Remove a list of multiple libraries as a batch operation
207  bool removeLibraries(const UT_StringArray& libfiles,
208  const char *metasrc,
209  bool changeoplibraries);
210 
211  bool removeMetaSource(const char *metasrc);
212 
213  /// Refresh all libraries as a batch operation.
214  void refreshAll(bool reloadOpLibraries);
215 
216  /// This function adds the libfile to the specified metasrc if it
217  /// isn't there already (or moves it to the specified position if
218  /// it is there). This is the function external callers should
219  /// always use.
220  OP_OTLLibrary *addLibrary(const char *libfile,
221  const char *metasrc,
222  bool changeoplibraries,
223  bool installinternaliffail,
224  UT_WorkBuffer &errors);
225 
226  // Get basic library information.
227  int getNumLibraries() const;
228  int getPreferredLibrary(const char *tablename,
229  const char *opname);
230  OP_OTLLibrary *getLibrary(int index) const;
231 
232  /// Returns the library that contains the latest (by date) definition
233  /// for the specified operator.
234  int getLatestLibrary(const char *tablename,
235  const char *opname,
236  OP_OTLLibrary *tiegoesto = 0);
237  bool getOutOfDateInternalOps(UT_StringArray &ops);
238 
239  /// Returns the next library with a definition for the specified operator.
240  /// This function loops around to the start of the library list.
241  int getNextLibrary(const char *tablename,
242  const char *opname,
243  OP_OTLLibrary *startat);
244 
245  /// Adds an operator definition to an existing library, or creates
246  /// a new library file if necessary.
247  static bool addToLibrary(OP_OTLLibrary *lib,
248  OP_OTLDefinition &definition,
249  FS_IndexFile *deffile,
250  bool dummydefinition = false);
251  bool addToLibrary(const char *libfile,
252  OP_OTLDefinition &definition,
253  FS_IndexFile *deffile,
254  bool dummydefinition = false,
255  bool create_op_type=false,
256  bool create_backup=true);
257 
258  /// Take the secondary library and merge it into the primary library,
259  /// and save the combined file out to the primary library.
260  bool mergeLibraries(const char *primary,
261  const char *secondary,
262  bool overwrite);
263 
264  /// These functions are for maintaining our one "internal" library.
265  /// This library is where we keep op definitions that have been loaded
266  /// form the hip file, or definitions that we want to uninstall but
267  /// couldn't because of existing operators of that type.
268  bool addToInternalLibrary(OP_OTLLibrary *newlib);
269  bool addToInternalLibrary(UT_IStream &is, time_t modtime);
270 
271  /// Removes some operator definitions from an existing library. We
272  /// check the file name to determine if we are removing from the
273  /// internal library, or an external library file.
274  bool removeFromLibrary(const char *libfile,
275  const UT_StringArray &ops);
276 
277  /// Update the date stamp for the specified definition to be the current
278  /// date. Do a refresh of the library if it is loaded.
279  bool touchDefinition(const char *libfile,
280  const char *tablename,
281  const char *opname,
282  int newtime = -1);
283 
284  /// This functions modifies the data in the OTLDefinition so that it
285  /// will refer to the given index file so that both these elements can
286  /// be embedded into an OTLLibrary.
287  static void modifyDefinitionToInternalPaths(
288  OP_OTLDefinition &def,
289  FS_IndexFile *deffile);
290 
291  /// A utility function for saving the operator definition for a given node.
292  void saveOpTypeFromNode( OP_Node *node, UT_String &errors );
293 
294  /// A utility function for updating the Contents section of an asset
295  /// definition based on a particular OP_Node. The compile flags can be
296  /// used to control whether the contents are compiled
297  void updateContentsFromNode(FS_IndexFile *deffile,
298  OP_Node *node,
299  UT_CompressionType compressionType,
300  bool compilebasic,
301  bool compilevopnets,
302  bool compilechannels,
303  bool compilenodenames,
304  const char *library,
305  bool blackbox = false);
306 
307  /// A utility function for updating an operator definition based on
308  /// a particular OP_Node.
309  void updateDefinitionFromNode(FS_IndexFile *deffile,
310  OP_Node *node,
311  bool lockcontents,
312  bool usedsparms,
313  UT_CompressionType compressionType,
314  bool savespareparms,
315  bool compile_asset,
316  const char *library,
317  bool blackbox = false);
318 
319  /// A utility functino to make sure that the Contents section of the
320  /// given file is either compressed or not, as set by gzipcontents.
321  void setContentsCompression(FS_IndexFile *deffile,
322  UT_CompressionType compressionType);
323  /// Utility functions for getting/setting the comment and version data in an
324  /// operator type definition index file.
325  bool getComment(FS_IndexFile *deffile, UT_String &result);
326  void setComment(FS_IndexFile *deffile, const char *comment);
327  bool getVersion(FS_IndexFile *deffile, UT_String &result);
328  void setVersion(FS_IndexFile *deffile, const char *version);
329 
330  /// Functions for listing information about libraries and ops.
331  void listLibraries(std::ostream &os) const;
332  void listLibrariesWithDefinition(const char *tablename,
333  const char *opname,
334  std::ostream &os) const;
335  void listOperators(const char *libfile,
336  std::ostream &os) const;
337  void listOperator(const char *libfile,
338  const char *tablename,
339  const char *opname,
340  const char *format,
341  std::ostream &os) const;
342 
343  /// Function to get a list of the libraries containing a definition for
344  /// the specified type.
345  void getLibrariesWithDefinition(
346  const char *tablename,
347  const char *opname,
349 
350  /// Get a list of all operators (in tablename/optypenae form) that match
351  /// the passed in mask, which may contain wildcards. Before adding a result
352  /// to the array, it checks the symbol table to see if the result has
353  /// already been found. The tablename/optype string is added to the results
354  /// array. If a library pointer is passed in, only that library is searched.
355  /// Optypes found in that library do not need to be installed or current in
356  /// the Houdini session. If no library is passed in all current definitions
357  /// are searched, and all non-current definitions are ignored (so there
358  /// can be no confusion about which instance of an optype definition
359  /// was found. Returns true if some matching optype was found (even if
360  /// that optype wasn't added because of it already being in the symbol
361  /// table).
362  bool getAllMatchingOperators(const char *opmask,
363  const OP_OTLLibrary *library,
364  bool onlyotlops,
365  UT_StringArray &results,
366  UT_StringSet &resultstable) const;
367 
368  /// Functions for handling our interests.
369  void addManagerSink(OP_OTLManagerSink *sink);
370  void removeManagerSink(OP_OTLManagerSink *sink);
371 
372  /// Checks if the given table and operator type name are valid.
373  bool checkValidNodeName(const char *name,
375  UT_WorkBuffer &errors);
376  /// Creates a new operator type in an OTL, and installs that OTL.
377  bool createOptype(OP_OTLDefinition &def,
378  const char *installpath,
379  const char *extradsinfo,
380  const char *installmetasrc,
381  const UT_StringMap<UT_StringHolder> &extrasections,
382  UT_WorkBuffer &errors,
383  bool create_backup=true);
384 
385 
386  /// Creates a new operator type in an OTL, and installs that OTL.
387  bool createOptype(const char *tablename,
388  const char *opname,
389  const char *oplabel,
390  const char *installpath,
391  int min_input, int max_input,
392  int max_outputs,
393  const char *extradsinfo,
394  const char *installmetasrc,
395  const char *extrainfo,
396  bool subnet,
397  UT_WorkBuffer &errors,
398  bool create_backup=true);
399 
400  static bool getHelpTemplateFile(UT_String &helptemplatefile);
401  static void createDefaultOptypeName(OP_Node *fromnode,
402  UT_String &name,
403  UT_String &label);
404  static void createOptypeLabelFromName(UT_String name,
405  UT_String &label);
406  static void createOptypeNameFromLabel(UT_String label,
407  UT_String &name);
408  static void fullyQualifyLibFileName(const char *libfilebase,
409  UT_String &libfile,
410  const char *basedir = 0);
411  void fullyQualifyMetaSrcName(const char *libfilebase,
412  UT_String &libfile) const;
413  void getSimplifiedPath(UT_String &destpath,
414  const char *srcpath,
415  const char *srcmeta) const;
416 
417  bool canSavePreferences() const;
418 
419  /// Functions for managing fallback libraries. These are libraries that
420  /// are automatically loaded (as a last resort) if a particular type
421  /// definition is missing.
422  ///
423  /// The manager maintains a stack of fallback contexts. In general, each
424  /// fallback context contains the fallback paths specified in a particular
425  /// file fragment (hip file, digital asset contents section) and remains
426  /// active until that file fragment is processed by the loading mechanism.
427  void pushFallbackLibraryContext();
428  void popFallbackLibraryContext();
429  void saveFallbackLibraryPaths(std::ostream &os,
430  const OP_OperatorList &ops) const;
431  bool loadFallbackLibraryPaths(UT_IStream &is);
432  bool loadFallbackLibrary(const char *tablename,
433  const char *opname);
434 
435  /// Functions for managing the dummy definitions for each operator.
436  /// The dummy definition is just a dialog script copied from the last time
437  /// the operator was loaded. It is retrieved if no other definition for
438  /// the operator is available. It should be enough information to load
439  /// and re-save a hip file containing an unknown operator type without
440  /// losing any information.
441  void setDummyDefinition(const OP_OTLDefinition &definition,
442  const FS_IndexFile *deffile);
443  bool getDummyDefinition(const OP_Operator *op,
444  FS_IndexFile *deffile) const;
445  bool loadDummyDefinitions(UT_IStream &is, time_t modtime);
446  void saveDummyDefinitions(std::ostream &os,
447  const OP_OperatorList &ops) const;
448 
449  /// Saves an empty (but valid) dialog script to a stream.
450  static void saveDefaultDialogScript(std::ostream &os,
451  const char *opname,
452  const char *oplabel,
453  const char *extradsinfo);
454  /// Saves a default, do-nothing creation script to a stream.
455  static void saveDefaultCreationScript(std::ostream &os,
456  const char *op,
457  const char *table);
458 
459  /// Writes the index file 'contents' to the output stream 'os'. Ensures
460  /// that the filtering options (ie encryption) are set correctly on the
461  /// index file before it is written out.
462  static void writeOutDefinitionContents(
463  const OP_OTLDefinition &definition,
464  FS_IndexFile & contents,
465  std::ostream & os);
466 
467  /// Sets the encryption and decryption filters on the contents.
468  static void setFilters(const OP_OTLDefinition &definition,
469  FS_IndexFile &contents);
470 
471  /// Reload OTL license files, and notify interested parties of the
472  /// potential for change.
473  void refreshLicenses();
474 
475  /// Get the real file name that is presently being used for the Embedded
476  /// library. This should be used very carefully, and the value should not
477  /// be stored, because it will change anytime a definition is added to or
478  /// removed from the Embedded library.
479  const UT_String &getInternalTempFile() const;
480 
481  /// Checks if the library has a non-commercial (tainted) asset.
482  /// Note, the library does not have to be loaded yet.
483  bool hasNCAsset(const OP_OTLLibrary *lib);
484 
485  /// Returns an array of asset indices that are non-commercial
486  /// Note, the library does not have to be loaded yet.
487  void getNCAssets(const OP_OTLLibrary *lib,
488  UT_IntArray & nc_assets);
489 
490  /// Only called by FUSE_AssetsMenu to clean dirty flags of assets.
492  {mySaveOpTypeCallback = cb;}
493 
494  /// Convert libraries between different formats
495  bool convertLibraryToFile(const char *libfilebase,
496  const char *metasrcbase);
497  bool convertLibraryToDir(const char *libfilebase,
498  const char *metasrcbase);
499 
500 private:
501  struct OTLFallbackData
502  {
503  public:
504  UT_StringArray myPaths;
505  bool myFailFlag;
506  };
507  typedef UT_SymbolMap<OTLFallbackData *> FallbackContext;
508 
509  // Helper struct for doing bulk refresh operations
510  class RefreshScope;
511  friend class RefreshScope;
512 
513  // Functions for sending notifications to our interests.
514  void notifySinksOfAssetCreated(
515  const OP_OTLLibrary &library,
516  const OP_OTLDefinition &def);
517  void notifySinksOfAssetDeleted(
518  const OP_OTLLibrary &library,
519  const OP_OTLDefinition &def);
520  void notifySinksOfAssetSaved(
521  const OP_OTLLibrary &library,
522  const OP_OTLDefinition &def);
523  void notifySinksOfBeforeAssetCreated(
524  const OP_OTLLibrary &library,
525  const OP_OTLDefinition &def);
526  void notifySinksOfBeforeAssetDeleted(
527  const OP_OTLLibrary &library,
528  const OP_OTLDefinition &def);
529  void notifySinksOfBeforeAssetSaved(
530  const OP_OTLLibrary &library,
531  const OP_OTLDefinition &def);
532  void notifySinksOfLibraryInstalled(OP_OTLLibrary *library);
533  void notifySinksOfLibraryUninstalled(
534  OP_OTLLibrary *library);
535  void notifySinksOfDefinitionsAdded(int libindex,
536  UT_IntArray &defarray);
537  void notifySinksOfDefinitionsRemoved(int libindex,
538  UT_IntArray &defarray,
539  OP_OTLLibrary *&preserve);
540  void notifySinksOfSourceNamesChanged();
541  void notifySinksOfLibraryAdded(OP_OTLLibrary *library);
542  void notifySinksOfLibraryRemoved(OP_OTLLibrary *library);
543  void notifySinksOfConfigurationChanged();
544  void notifySinksOfLicensesChanged();
545  void writeSimplifiedPath(std::ostream &os,
546  const char *srcpath,
547  const char *srcmeta,
548  const char *prefix = 0) const;
549 
550  /// Sets meta source name data for a given meta source.
551  void setMetaSourceNameData(int pos, const char *metasrc,
552  const char *metasrcname);
553  /// Saves an OPlibraries file by looking through our libraries and
554  /// writing out any loaded library that uses that meta source. Optionally
555  /// we can also specify a single library that should not be written, or
556  /// an extra library that should be written.
557  bool saveMetaFile(const char *metafile,
558  const char *skiplib,
559  const char *addlib) const;
560  /// Adds a library to an OPlibraries file, and returns the index of
561  /// where in the overall list of libraries the new library should
562  /// be inserted. Used by addLibrary.
563  int addToMetaSource(const char *libfile,
564  const char *metasrc,
565  bool changeoplibraries);
566  /// Put a library into our list at a particular position. Used
567  /// internally to actually add libraries.
568  ///
569  /// Returns true on success and false on failure. On failure, the
570  /// library is deleted.
571  bool insertLibrary(OP_OTLLibrary *newlib, int before);
572  /// Internal removeLibrary used to actually remove a library.
573  bool removeLibrary(int index, bool external=false);
574  /// Functions for loading and saving our preferences file.
575  void loadPreferences();
576  void savePreferences();
577  /// Use this function to create a new temp file for our internal library.
578  void moveInternalToNewTempFile();
579  /// Removes from lib any definitions for which there is already a
580  /// non-dummy definition in existance.
581  void clearIfGoodDefinitionExists(OP_OTLLibrary *lib);
582  /// Removes some operator definitions from an existing library file.
583  bool removeFromExternalLibrary(const char *libfile,
584  const UT_StringArray &ops);
585  /// Removes some operator defintions from the internal library, but
586  /// only if it is safe to do so (either there is another library
587  /// ready to take over the definition, or the opertor is unused).
588  bool removeFromInternalLibrary(const UT_StringArray &ops);
589  /// backup a libfile before replacing it with the new one. NOTE this
590  /// deletes 'newlib' before returning in order to close any file pointers
591  bool backupAndWriteNewLibrary(const char *libfilebase,
592  const char *libfile,
593  OP_OTLLibrary *newlib);
594 
595  /// Helper functions for touchDefinition which set the modification
596  /// time for an operator definition in either the internal library or
597  /// an external library file.
598  bool touchExternalDefinition(const char *libfile,
599  const char *tablename,
600  const char *opname,
601  int newtime);
602  bool touchInternalDefinition(const char *tablename,
603  const char *opname,
604  int newtime);
605  /// Adds a library from an OPlibraries file.
606  void addFromOpLibrariesFile(const char *file,
607  const char *metasrc,
608  int &libpos);
609 
610  /// Private utility method for implementing the public method.
611  void setLibraryPreference(const char *tablename,
612  const char *opname,
613  const char *libfile,
614  UT_IntArray *libstorefresh);
615 
616  /// Some private utility methods for managing the fallback library tables.
617  void addFallbackLibraryPath(const char *tablename,
618  const char *opname,
619  const char *libfile);
620  bool loadFallbackLibrary(FallbackContext *context,
621  const char *opsymbol,
622  const char *tablename,
623  const char *opname);
624  void clearLibraryFallbacks(FallbackContext *table);
625 
626  /// Tests if the definition is for a non-commercial asset.
627  bool isNCAsset(const FS_IndexFile *lib_file,
628  const OP_OTLDefinition & def);
629 
630  /// This static exit callback is here in case we allocate an
631  /// OP_OTLManager then never free it (which we do, since we never
632  /// delete our OP_Director).
633  static void deleteLibraries(void *data);
634 
635 private: // data
636 
637  UT_ValArray<OP_OTLLibrary *> myLibraries;
638  UT_ValArray<OP_OTLManagerSink *> myManagerSinks;
639  UT_ValArray<OP_OTLLibrary *> myLibrariesBeingRemoved;
640  UT_String myInternalTempFile;
641  UT_String myNewInternalTempFile;
642  UT_StringArray myMetaSourcesWithNames;
643  UT_StringArray myMetaSourceNames;
644  UT_StringArray myMetaSourceNameWithPaths;
645  UT_SymbolMap<UT_StringHolder> myLibraryPreferences;
646  UT_ValArray<FallbackContext *> myLibraryFallbacks;
647  UT_UniquePtr<OP_OTLLibrary> myDummyDefinitions;
648  UT_StringHolder myOperatorTypeBarMode;
649  UT_StringArray myFailedOTLs;
650  OP_SaveOpTypeCallback mySaveOpTypeCallback;
651  int myPerformingRefreshAll;
652  bool myIsPerformingAtomicAddRemove;
653  bool mySaveToHipFile;
654  bool mySaveUnlockedToHipFile;
655  bool myWarnOutOfDateOps;
656  bool myWarnDummyOpsOnLoad;
657  bool myPreferLatestDateDefinition;
658  bool myPreferInternalDefinition;
659  bool myPreferIndexFileDefinition;
660  bool myCreateBackups;
661  bool mySafeguardOpDefs;
662  bool myLeaveDefaultsUnchanged;
663  bool myUseOplibrariesFiles;
664  bool myIsCreatingNewHDA;
665 
667  theOTLLoadCallbacks;
668 };
669 
671 {
672 public:
675  { removeAllManagerSinks(); }
676 
677  /// Called when an asset definition is created.
678  /// This differs from definitionsAdded() which is called even
679  /// when a library is refreshed.
680  virtual void assetCreated(
681  const OP_OTLLibrary &library,
682  const OP_OTLDefinition &def) {}
683 
684  /// Called when an asset definition is deleted from the library.
685  /// This differs from definitionsRemoved() which is called even
686  /// when a library is refreshed.
687  virtual void assetDeleted(
688  const OP_OTLLibrary &library,
689  const OP_OTLDefinition &def) {}
690 
691  /// Called when an asset definition is saved.
692  virtual void assetSaved(
693  const OP_OTLLibrary &library,
694  const OP_OTLDefinition &def) {}
695 
696  /// Called right before an asset definition is created.
697  virtual void beforeAssetCreated(
698  const OP_OTLLibrary &library,
699  const OP_OTLDefinition &def) {}
700 
701  /// Called right before an asset definition is removed from a library.
702  virtual void beforeAssetDeleted(
703  const OP_OTLLibrary &library,
704  const OP_OTLDefinition &def) {}
705 
706  /// Called right before an asset definition is saved.
707  virtual void beforeAssetSaved(
708  const OP_OTLLibrary &library,
709  const OP_OTLDefinition &def) {}
710 
711  /// libraryInstalled() is called after an HDA library is installed.
712  /// This differs from libraryAdded() which is called after a library
713  /// is added to the manager's library list. The latter can be called
714  /// several times in a session due to a library being installed or updated.
715  virtual void libraryInstalled(const OP_OTLLibrary *library) {}
716 
717  /// libraryUinstalled() is called after an HDA library was uninstalled.
718  /// This differs from libraryRemoved() which is called after a library
719  /// is removed from the manager's library list. The latter can be
720  /// called several times in a session due to a library being uninstalled
721  /// or updated.
722  virtual void libraryUninstalled(const OP_OTLLibrary *library) {}
723 
724  virtual void definitionsAdded(int /*libindex*/,
725  UT_IntArray & /*defindex*/) { }
726  virtual void definitionsRemoved(int /*libindex*/,
727  UT_IntArray & /*defindex*/,
728  OP_OTLLibrary *& /*preserve*/){ }
729  virtual void sourceNamesChanged() { }
730  virtual void libraryAdded(OP_OTLLibrary * /*library*/) { }
731  virtual void libraryRemoved(OP_OTLLibrary * /*library*/) { }
732  virtual void configurationChanged() { }
733  virtual void licensesChanged() { }
734 
736  { removeManagerSink(manager); }
737 
738 protected:
740  {
741  if( !manager ) return;
742 
743  // Don't add if we have already added ourselves
744  // to the manager.
745  if (myManagers.find(manager) != -1)
746  return;
747 
748  manager->addManagerSink(this);
749  myManagers.append(manager, 1);
750  }
752  {
753  if( !manager ) return;
754  manager->removeManagerSink(this);
755  myManagers.findAndRemove(manager);
756  }
758  {
759  for( int i = myManagers.entries(); i --> 0; )
760  removeManagerSink(myManagers(i));
761  }
762 
763 private:
764  UT_ValArray<OP_OTLManager *> myManagers;
765 };
766 
767 #endif
768 
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