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