HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_OTLLibrary.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_OTLLibrary.h ( OTL Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __OP_OTLLibrary__
13 #define __OP_OTLLibrary__
14 
15 #include "OP_API.h"
16 #include "OP_OTLDefinition.h"
17 #include "OP_OTLSectionNames.h"
18 #include <VEX/VEX_VexTypes.h>
19 #include <FS/FS_IndexFile.h>
20 #include <UT/UT_Defines.h>
21 #include <UT/UT_String.h>
22 #include <UT/UT_StringHolder.h>
23 #include <UT/UT_SymbolTable.h>
24 #include <UT/UT_TimeGate.h>
25 #include <time.h>
26 
27 
28 // Prefix "oplib:" for referencing OTL library files. Eg, "oplib:/Object/hda".
29 #define OTL_LIBRARY_PREFIX UT_OTL_LIBRARY_PREFIX
30 
31 // Prefix "opdef:" for referencing HDA definition index file ("opdef:/Sop/hda").
32 #define OTL_DEFINITION_PREFIX UT_HDA_DEFINITION_PREFIX
33 
34 #define OTL_INTERNAL "Embedded"
35 #define OTL_INTERNAL_SH "Embedded"_UTsh
36 #define OTL_INTERNAL_META "Current HIP File"
37 #define OTL_INTERNAL_META_SH "Current HIP File"_UTsh
38 #define OTL_FALLBACK_META "Fallback Libraries"
39 #define OTL_OTLSCAN_META "Scanned Asset Library Directories"
40 #define OTL_ROOTHDANAME "hdaroot"
41 
42 
43 
45 {
46 public:
47  OP_OTLLibrary();
48  OP_OTLLibrary(FS_Reader *reader);
49  OP_OTLLibrary(const char *source, const char *metasrc);
50  ~OP_OTLLibrary() override;
51 
52  const UT_StringHolder &getMetaSource() const;
53  const UT_StringHolder &getSource() const;
54 
56  {
57  MOD_TIME_OK, //modifiction time was obtained without errors
58  MOD_TIME_INTERNAL, //error; definition is internal (embedded)
59  MOD_TIME_SAVE_QUIT, //error; user chose save and quit
60  MOD_TIME_DISCARD_QUIT, //error; user chose discard and quit
61  MOD_TIME_EMBED, //error; user chose to embed dummy definition
62  MOD_TIME_REFRESH_ALL, // error: user chose to refresh otls and retry
63  MOD_TIME_LOAD_FILE // error: user chose to load alternative file
64  };
65 
66  /// Checks if filename has a .otl, if not, appends it.
67  /// Respects OTL_INTERNAL and other magic constants.
68  /// Returns true if filename was modified
69  static bool forceOTLExtension(UT_String &filename);
70 
71  /// Constructs a good vfl and vex code section names given the original
72  /// suggestion.
73  SYS_DEPRECATED(13.0)
74  static void getVexAndVflSectionNames( const char * suggestion,
75  UT_String & vexsect, UT_String & vflsect);
76 
77  /// Constructs a valid VEX code section, with an optional prefix.
78  static void getVexCodeSectionName(const char * prefix,
79  UT_String & vex_code_sect);
80 
81  // obtains the source's modification time. If source is not accessible,
82  // a pop-up dialog is displayed to prompt for an action:
83  // save & quit, discard & quit, retry, or embed)
84  // OUTPUTS:
85  // mod_time - a modification time of the source
86  // RETURNS:
87  // status of the attempt of getting modification time
88  OP_ModTimeStatus getSourceModTime(time_t &mod_time,
89  const char *type_name = NULL) const;
90 
91  bool addDefinition(const OP_OTLDefinition &definition,
92  time_t modtime = time_t(-1));
93  bool removeDefinition(int index);
94 
95  int getNumDefinitions() const
96  { return myDefinitions.entries(); }
97  const OP_OTLDefinition &
98  getDefinition(int index) const
99  { return *myDefinitions(index); }
100 
101  int getDefinitionIndex(const char *tablename,
102  const char *opname) const;
103  time_t getDefinitionModTime(int index) const;
104  const UT_StringHolder &getDefinitionName(int index) const;
105  const UT_StringHolder &getDefinitionOpTableName(int index) const;
106  bool getDefinitionIsDummy(int index) const;
107  bool getDefinition(int index,
108  OP_OTLDefinition &definition) const;
109 
110  // Get the FS_IndexFile for an asset definition in this library. Returns
111  // null if no such asset exists. Otherwise, it is up to the caller to
112  // delete the FS_IndexFile returned.
113  // NOTE: that this will NOT properly get the definition index file if the
114  // actual library has not been installed into the scene yet, even if
115  // all you want is an FS_IndexFile.
116  // WARNING: Caller gains ownership of the returned index file. You *MUST*
117  // delete the returned pointer when done to avoid memory leaks.
118  FS_IndexFileHandle getDefinitionIndexFile(
119  const char *tablename, const char *opname) const;
120 
121  // Remove a section from the given definition, if it is empty. This
122  // loads the index file that corresponds to the given section, modifies
123  // it, and then saves the modified section back to the otl. Returns
124  // true when modification occurred.
125  bool removeDefinitionSectionIfEmpty(
126  int index, const char *definition_section);
127 
128  void mergeLibrary(const OP_OTLLibrary &lib);
129 
130  bool expandToDirectory(const char *destdir) override;
131  bool collapseFromDirectory(const char *srcdir) override;
132  void writeFile(std::ostream &os) const override;
133 
134  void setIsBeingRefreshed(bool beingrefreshed);
135  bool getIsBeingRefreshed() const;
136 
137  // Use these methods to start and end source modfication time caching,
138  // preventing redundant stat() calls on the source file when we expect
139  // multiple successive calls to getSourceModTime().
140  void beginCachingSourceModTime();
141  void endCachingSourceModTime();
142 
143  bool getIsModTimeAccessOK() const;
144 
145  const UT_StringArray &getErrorMessages() const;
146 
147  static bool createBackupFile(const char *filename,
148  bool domove = false);
149  static bool isReservedSectionName(const UT_StringRef &sectname);
150  static const char *getEventName(int index);
151  static const UT_StringHolder &getEventSectionName(int index);
152 
153  static const UT_StringHolder &getVexCodeSectionName(VEX_ContextType type);
154  static const UT_StringHolder &getVflCodeSectionName(VEX_ContextType type);
155  static const UT_StringHolder &getEncapsulatedVexSectionName(VEX_ContextType type);
156  static UT_StringHolder getShaderPathWithSection(
157  const UT_StringRef &shader,
159  UT_String *opname = nullptr);
160 
161  // Returns a list of the files that are used in the OTL_Library 'libfile'.
162  // This will ignore extraneous files in the file system.
163  // NOTE: This is only currently implemented for expanded HDAs (OTLs).
164  static bool getFilenames(const UT_StringHolder &libfile,
165  UT_StringArray &filenames);
166 
167  // Get the default meta source to which a library should install. This
168  // will either be OTL_OTLSCAN_META or OTL_INTERNAL_META, depending on
169  // whether or not the library would be found in the scan path.
170  static const char *getDefaultInstallMetaSource(const char *lib_path);
171 
172 private:
173  void readDefinitions();
174  void saveDefinitionsToSection(bool binary);
175 
176  UT_StringHolder mySource;
177  UT_StringHolder myMetaSource;
178  OP_OTLDefinitionArray myDefinitions;
179  UT_SymbolMap<int> myDefinitionIndexMap;
180  UT_StringArray myErrorMessages;
181  int myUseCachedModTime;
182  mutable UT_TimeGate<1000> myModTimeGate;
183  mutable bool myIsModTimeAccessOK;
184  bool myIsBeingRefreshed;
185 };
186 
187 #endif
188 
Class for reading files.
Definition: FS_Reader.h:33
GT_API const UT_StringHolder filename
#define SYS_DEPRECATED(__V__)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
const OP_OTLDefinition & getDefinition(int index) const
Definition: OP_OTLLibrary.h:98
int getSource() override
virtual bool collapseFromDirectory(const char *srcdir)
virtual bool expandToDirectory(const char *destdir)
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
GLuint shader
Definition: glcorearb.h:785
#define OP_API
Definition: OP_API.h:10
GLuint index
Definition: glcorearb.h:786
#define const
Definition: zconf.h:214
VEX_ContextType
Definition: VEX_VexTypes.h:60
type
Definition: core.h:1059
virtual void writeFile(std::ostream &os) const