InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
IDataBase.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Roey Horns
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //
23 // Reviewed: 10/5/98
24 //
25 // Purpose: Provides access to the database that holds a K2 publication.
26 //
27 // THIS IS NOT A STANDARD BOSS INTERFACE
28 //
29 //========================================================================================
30 
31 #ifndef __IDATABASE__
32 #define __IDATABASE__
33 
34 #include "IPMUnknown.h" // for the definition of
35 #include "GlobalTime.h" // should be removed, but is indirectly included by many files
36 #include "IDFile.h" // for IDFile
37 #include "IDatabaseSnapshot.h"
38 
39 class IDTime;
40 class IPMUnknown;
41 class IPubFile;
42 class IPMPersist;
43 class IDatabaseObserver;
44 class IUIDIterator;
45 class IInstanceProcessor;
46 class InstanceProfiler;
47 class IDBChangesMonitor;
48 class IDatabaseSnapshot;
58 class IDataBase
59 {
60 public:
64  virtual ~IDataBase() {};
65 
67  typedef enum
68  {
70  kNoError = 0,
78  kFileDamagedError, // file may be recoverable
80  kFileCorruptError, // file is not recoverable
110  kMiniSaveFileVerificationFailedError, //temp file damaged due to MiniSave
111  kUserFileVerificationFailedError, //user file damaged due to merge of tempfile
112  kAccessDenied //destionation file access denied because of permission issues.
113  } DBResultCode;
114 
115  //------------------------------------------------------------------------------------
116  // Objects & UIDS
117  //
118  // Create, Instantiate and delete objects in the database.
119  //------------------------------------------------------------------------------------
120 
126  virtual UID NewUID(ClassID clsID) = 0;
134  virtual DBResultCode DeleteUID(UID id) = 0;
142  virtual DBResultCode UndeleteUID(UID id, ClassID clsID) = 0;
149  virtual DBResultCode DestroyDeletedUID(UID id) = 0;
150 
161  virtual IPMUnknown *Instantiate(UID id, PMIID interfaceID) = 0;
162 
170  virtual IPMUnknown *QueryInstance(UID id, PMIID interfaceID) = 0;
171 
179  virtual bool8 IsValidUID(UID id) const = 0;
180 
185  virtual UID GetRootUID() const = 0;
191  virtual ClassID GetClass(UID id) const = 0;
192 
199  virtual IUIDIterator *NewUIDIterator(bool8 includeDeletedUIDs = kFalse) const = 0;
204  virtual void DeleteUIDIterator(IUIDIterator **iterator) const = 0;
205 
207  virtual void AssertOnModification () = 0; // Asserts if the database has been modified used to assert if the database is being dirtied on saveing.
208 
209  //------------------------------------------------------------------------------------
210  // DataBaseObservers
211  //
212  // DataBaseObservers are notified for modification actions to UIDs.
213  // See IDataBaseObserver.h
214  //------------------------------------------------------------------------------------
215 
220  virtual void AttachDataObserver(IDatabaseObserver* observer) = 0;
225  virtual void DetachDataObserver(IDatabaseObserver* observer) = 0;
226 
227 
228 
229  //--------------------------------------------------------------------------------------
230  // DataBase File Info
231  //-------------------------------------------------------------------------------------
232 
234  typedef enum
235  {
242  } ByteSwapOrder;
243 
247  virtual uint32 GetSaveCount() const = 0;
251  virtual bool16 IsReadOnly() const = 0;
255  virtual bool16 IsModified() const = 0;
256  // Sets the version number of the application that was used
257  // to create the database. INTERNAL USE ONLY
258  virtual IDataBase::DBResultCode SetVersionNumber(const int32& majorVersion, const int32& minorVersion) = 0;
264  virtual void GetVersionNumber(int32 *majorVersion, int32 *minorVersion) const = 0;
268  virtual ByteSwapOrder GetByteSwap() const = 0;
273  virtual const IDFile* GetSysFile() const = 0;
274 
275 
276  //------------------------------------------------------------------------------------
277  // DataBase File Handling
278  //------------------------------------------------------------------------------------
279 
281  typedef enum
282  {
292  } OpenFlags;
293 
295  typedef enum
296  {
301  } SaveFlags;
302 
307  typedef enum
308  {
331  } ProtectionLevel;
332 
338  typedef DBResultCode (*DBProgressFunction)(int32 stepsDone, int32 stepCount);
339 
344  virtual DBResultCode New(ProtectionLevel protLevel) = 0;
351  virtual DBResultCode Open(const IDFile& whatFile, ProtectionLevel protLevel,
352  OpenFlags openFlag = kWrite) = 0;
357  virtual DBResultCode Revert() = 0;
365  virtual DBResultCode Recover(const IDFile* damagedFile, ProtectionLevel protLevel,
366  ProtectionLevel oldProtLevel, const IDFile* miniSaveFile = nil) = 0;
367 
372  virtual DBResultCode Save() = 0;
378  virtual DBResultCode SaveAs(const IDFile& destFile,
379  SaveFlags saveFlag = kSaveAs) = 0;
380 
385  virtual void SetModified(bool16 modified) = 0;
386 
387 
395  {
396  public:
398  : fDB(db)
399  {
400  if (db && db->IsModified())
401  fDB = nil; // If the database is already modified we don't need to restore
402  }
403 
405  {
406  if (fDB)
407  fDB->SetModified(kFalse);
408  }
409  private:
410  IDataBase * fDB;
411  };
412 
418  virtual void SetPlatformFileInfo(void *fileInfo) = 0;
419 
424 
425 
426  //--------------------------------------------------------------------------------------
427  // Transactions & Mini-Save
428  //
429  // All changes to the database must be encapsulated in a transaction.
430  // Nested transactions are possible.
431  //
432  // You usually do not have to call Begin/EndTransaction yourself.
433  //
434  // An assert regarding a database change outside of a transaction is usually
435  // caused by either a modification outside of a command, a command with
436  // an incorrect target, or a command that modifies more than one database.
437  //--------------------------------------------------------------------------------------
438 
450  virtual DBResultCode BeginTransaction() = 0;
455  virtual DBResultCode EndTransaction() = 0;
456 
460  virtual int32 GetTransactionLevel() const = 0;
461 
466  virtual ProtectionLevel GetProtectionLevel() const = 0;
472  virtual uint32 SetMiniSaveInterval(uint32 msecs) = 0;
476  virtual uint32 GetMiniSaveInterval() const = 0;
477 
481  virtual const IDFile* GetMiniSaveFile() const = 0;
482 
486  virtual DBResultCode GetErrorCode() = 0;
489  virtual void ClearError() = 0;
490 
491 
492  //------------------------------------------------------------------------------------
493  // Contiguous UID Support
494  //------------------------------------------------------------------------------------
495 
497  virtual UID NewContiguousUID (uint16 type, bool16 externallyWritable) = 0;
499  virtual bool16 GetContiguousUIDChangeMarker (UID id) const = 0;
501  virtual void SetContiguousUIDChangeMarker (UID id, bool16 changed) = 0;
502 
503  //------------------------------------------------------------------------------------
504  // For internal use only
505  //------------------------------------------------------------------------------------
506 
508  virtual void DestructInstance(UID id) = 0;
510  virtual void ClearDirty(IPMPersist *flushThis) = 0;
512  virtual void DirtyObject(IPMPersist *flushThis, ClassID clsID, ImplementationID tag, bool16 allowModification = kTrue, bool16 firstDirtyInterface = kTrue) = 0;
514  virtual void SetError(DBResultCode dbErrCode, const IDFile* userProvidedFile = nullptr) = 0;
516  virtual void PurgeMemory(int32 level) = 0;
518  virtual void AdviseMemoryState(int32 level) = 0;
520  virtual void RegisterRootObject(IPMUnknown *root) = 0;
522  virtual IPubFile* GetPubFile() = 0;
524  virtual void IterateInstantiatedObjects(IInstanceProcessor *i) = 0;
526  virtual InstanceProfiler *NewInstanceProfiler() = 0;
527 
528 #ifdef DEBUG
529 
530  virtual void SetInstanceCacheState(bool16 on) = 0;
532  virtual bool16 GetInstanceCacheState() = 0;
533 
535  virtual bool16 SetDirtyLimit(bool16 allowModification) = 0;
537  virtual bool16 GetDirtyLimit() = 0;
538 
540  virtual bool16 BeingDestructed() = 0;
541 #endif
542 
543  //------------------------------------------------------------------------------------
544  // Date/Time for Underlying Store
545  //------------------------------------------------------------------------------------
546 
551  virtual DBResultCode GetCreationTime (IDTime &gt) = 0;
552 
557  virtual DBResultCode GetModificationTime (IDTime &gt) = 0;
558 
559  //------------------------------------------------------------------------------------
560  // Save Sequence Numbers
561  //------------------------------------------------------------------------------------
562 
564  virtual uint64 GetSequenceNumberAtOpen () const = 0;
566  virtual uint64 GetCurrentSequenceNumber () const = 0;
567 
569  typedef enum
570  {
571  kUserFileExclusive = 0,
572  kUserFileShared
573  } UserFileMode;
574 
575  //------------------------------------------------------------------------------------
576  // Cache performance. This API is for internal use only.
577  //------------------------------------------------------------------------------------
579  virtual uint32 GetCacheFaultRate() const = 0;
581  virtual uint32 GetCacheTotalFaults() const = 0;
582 
585  {
586  kAnnaCachePolicy,
587  kFaultRateBasedPolicy,
588  kCacheAllPolicy
589  };
590 
592  virtual CachePolicy GetCachePolicy() const = 0;
594  virtual void SetCachePolicy(CachePolicy policy) = 0;
595 
596  //------------------------------------------------------------------------------------
597  // Support for better error handling
598  //------------------------------------------------------------------------------------
599 
600 
606  virtual const IDFile* GetSysFileFromOpen() const = 0;
607 
608  //------------------------------------------------------------------------------------
609  // Snapshot Database Handler
610  // Used for tracking changes to UIDs for automatic undo redo of commands.
611  //------------------------------------------------------------------------------------
612 
625  typedef enum {kNoUndoSupport, kFullUndoSupport, kPartialUndoSupport} UndoSupport;
626 
629  virtual UndoSupport GetUndoSupport() const = 0;
630 
632  virtual IDBChangesMonitor* GetDBChangesMonitor() const = 0;
633 
636 
639  virtual void SetDBChangesMonitor(IDBChangesMonitor* dbChangesMonitor, UndoSupport undoSupport) = 0;
640 
641  //------------------------------------------------------------------------------------
642  // Support for documents which are not datbases
643  //------------------------------------------------------------------------------------
644  // InCopy stores documents as XML and merely uses the database as a scratch work file.
645  // As a result, assumptions about the user pubfile are invalid. The "faux" user file
646  // is our way of informing the database of this situation so as to prevent problems
647  // with scripting, the UI and recovery.
649  virtual void SetFauxUserFile(const IDFile &newFile) = 0;
651  virtual bool16 IsFauxUserFile() const = 0;
652 
653  //------------------------------------------------------------------------------------
654  // More UID functions. Move up with rest between builds; but don't change vtable now [][]
655  //------------------------------------------------------------------------------------
656  // Creates a new persistent object in the database. The caller specifies the desired
657  // UID of the new object. This will succeed under the following conditions:
658  // 1. The requested UID is in the valid range - (currently: 1 <= UID <= 2^31-1)
659  // 2. The UID has either never been used, or can be re-used
660  // A UID that was used before can only be re-used provided that it does not exist
661  // in either the temporary file or the user file. This requires at least calling
662  // DeleteUID and DestoryUID, and performing a save operation afterwards if the
663  // database protection level is greater than kNoProtection.
664  //
665  // There may be three outcomes when calling this function. Callers should be prepared:
666  //
667  // If the function succeeds, the object is created and the function returns kTrue
668  //
669  // If the function fails because the UID isn't available to be used (outside of the
670  // valid range, not available for re-use yet), the function returns kFalse but the
671  // database error state is not set
672  //
673  // If the function fails for some more insidious reason, it returns kFalse and the
674  // database error state is set appropriately
676  virtual bool16 PlacementNewUID(ClassID clsID, UID id) = 0;
677 
678  // Returns kTrue if the passed UID is valid for use/re-use with PlacementNewUID()
680  virtual bool16 PlacementUIDIsAvailable (UID id) = 0;
681 
682  // Flush dirty objects for RIDX query
684  virtual void FlushDirtyObjectsForRIDXQuery () = 0;
685 
686  // Clone the database
687  virtual IDataBase* Clone() = 0;
688 
689  // Clone a database snapshot (for internal use only)
690  virtual DatabaseSnapshotPtr CloneADatabaseSnapshot() = 0;
691 
692  // Call this function after an execution context switch took place (call from child task).
693  // Necessary regardless whether the datase has been created as a clone.
694  virtual bool SwitchExecutionContext() = 0;
695  // Call this function before an execution context switch(call from the the parent task).
696  // Not necessary if the datase has just been created as a clone
697  virtual bool PrepareForExecutionContextSwitch() = 0;
698 
699  // clone must be a clone if this
700  virtual DBResultCode Merge(IDataBase *clone) = 0;
701 
704 
706  virtual void AllowPurge() = 0;
707  virtual void DisallowPurge() = 0;
708  virtual void DoScheduledPurge() = 0;
709  virtual bool IsPurgeAllowed() const = 0;
710 
711  virtual DBResultCode AttemptMiniSave() = 0;
712  virtual bool PubFileIsShared() const = 0;
713 
722  virtual PMString GetDocumentID() = 0;
723 
724  /* You can override what Instantiate() does by setting an override function. Use nil to remove a function.
725  SetInstantiateFunction returns the function that was previously being used, in case client code needs to
726  restore it later.
727  */
729  {
730  virtual IPMUnknown* operator () (IDataBase *db, UID id, PMIID faceID) = 0;
731  };
732 
734 
735  virtual InstantiateFunction SetInstantiateFunction(InstantiateFunction overrideInstantiate = nil) = 0;
736  virtual InstantiateFunction GetInstantiateFunction() const = 0 ;
737 
738  /* FileRecoveryMode - for internal use only */
739  typedef enum {
740  kNoRecovery,
741  /* File opened using Pre trans master page */
742  kUsingPreTransMasterPage,
743  /*File opened using LPM CoWP page*/
744  kUsingLPMCoWorkerPage,
745  /*File opened by stripping the XMP data from file*/
746  kUsingXMPDataStripping,
747  /*File opened by fixing/stripping the invalid text story or parcel from file*/
748  kUsingFixingInvalidTextStoryOrParcelMethod
749  } FileRecoveryMode;
750 };
751 
752 
757 template <class T>
759 {
760 public:
761  DBPurgeLock(T *handler) :
762  fHandler(handler)
763  {
764  fHandler->AllowPurge();
765  }
766  ~DBPurgeLock()
767  {
768  fHandler->DisallowPurge();
769  fHandler->DoScheduledPurge();
770  }
771 private:
772  T *fHandler;
773 };
774 
775 // define adobe::type_info<IDatabase> specialization so any_regular_t can move IDataBase across DLL boundaries
776 ADOBE_NAME_TYPE_0("idatabase:indesign:adobe", IDataBase)
777 
778 #endif // __IDATABASE__