datamgr.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. (******************************************************************************
  2. *
  3. * Copyright (c) 1994-2000 Palm, Inc. or its subsidiaries.
  4. * All rights reserved.
  5. *
  6. * File: DataMgr.h
  7. *
  8. * Release: Palm OS SDK 4.0 (63220)
  9. *
  10. * Description:
  11. * Header for the Data Manager
  12. *
  13. * History:
  14. * 11/14/94 RM - Created by Ron Marianetti
  15. *
  16. *****************************************************************************)
  17. unit datamgr;
  18. interface
  19. uses palmos, coretraps, errorbase;
  20. type
  21. DmResType = UInt32;
  22. DmResID = UInt16;
  23. (************************************************************
  24. * Category equates
  25. *************************************************************)
  26. const
  27. dmRecAttrCategoryMask = $0F; // mask for category #
  28. dmRecNumCategories = 16; // number of categories
  29. dmCategoryLength = 16; // 15 chars + 1 null terminator
  30. dmAllCategories = $ff;
  31. dmUnfiledCategory = 0;
  32. dmMaxRecordIndex = $ffff;
  33. // Record Attributes
  34. //
  35. // *** IMPORTANT:
  36. // ***
  37. // *** Any changes to record attributes must be reflected in dmAllRecAttrs and dmSysOnlyRecAttrs ***
  38. // ***
  39. // *** Only one nibble is available for record attributes
  40. //
  41. // *** ANY CHANGES MADE TO THESE ATTRIBUTES MUST BE REFLECTED IN DESKTOP LINK
  42. // *** SERVER CODE (DLCommon.h, DLServer.c)
  43. dmRecAttrDelete = $80; // delete this record next sync
  44. dmRecAttrDirty = $40; // archive this record next sync
  45. dmRecAttrBusy = $20; // record currently in use
  46. dmRecAttrSecret = $10; // "secret" record - password protected
  47. // All record atributes (for error-checking)
  48. dmAllRecAttrs = dmRecAttrDelete or dmRecAttrDirty or dmRecAttrBusy or dmRecAttrSecret;
  49. // Record attributes which only the system is allowed to change (for error-checking)
  50. dmSysOnlyRecAttrs = dmRecAttrBusy;
  51. (************************************************************
  52. * Database Header equates
  53. *************************************************************)
  54. dmDBNameLength = 32; // 31 chars + 1 null terminator
  55. // Attributes of a Database
  56. //
  57. // *** IMPORTANT:
  58. // ***
  59. // *** Any changes to database attributes must be reflected in dmAllHdrAttrs and dmSysOnlyHdrAttrs ***
  60. // ***
  61. dmHdrAttrResDB = $0001; // Resource database
  62. dmHdrAttrReadOnly = $0002; // Read Only database
  63. dmHdrAttrAppInfoDirty = $0004; // Set if Application Info block is dirty
  64. // Optionally supported by an App's conduit
  65. dmHdrAttrBackup = $0008; // Set if database should be backed up to PC if
  66. // no app-specific synchronization conduit has
  67. // been supplied.
  68. dmHdrAttrOKToInstallNewer = $0010; // This tells the backup conduit that it's OK
  69. // for it to install a newer version of this database
  70. // with a different name if the current database is
  71. // open. This mechanism is used to update the
  72. // Graffiti Shortcuts database, for example.
  73. dmHdrAttrResetAfterInstall = $0020; // Device requires a reset after this database is
  74. // installed.
  75. dmHdrAttrCopyPrevention = $0040; // This database should not be copied to
  76. dmHdrAttrStream = $0080; // This database is used for file stream implementation.
  77. dmHdrAttrHidden = $0100; // This database should generally be hidden from view
  78. // used to hide some apps from the main view of the
  79. // launcher for example.
  80. // For data (non-resource) databases, this hides the record
  81. // count within the launcher info screen.
  82. dmHdrAttrLaunchableData = $0200; // This data database (not applicable for executables)
  83. // can be "launched" by passing it's name to it's owner
  84. // app ('appl' database with same creator) using
  85. // the sysAppLaunchCmdOpenNamedDB action code.
  86. dmHdrAttrRecyclable = $0400; // This database (resource or record) is recyclable:
  87. // it will be deleted Real Soon Now, generally the next
  88. // time the database is closed.
  89. dmHdrAttrBundle = $0800; // This database (resource or record) is associated with
  90. // the application with the same creator. It will be beamed
  91. // and copied along with the application.
  92. dmHdrAttrOpen = $8000; // Database not closed properly
  93. // All database atributes (for error-checking)
  94. dmAllHdrAttrs = dmHdrAttrResDB or
  95. dmHdrAttrReadOnly or
  96. dmHdrAttrAppInfoDirty or
  97. dmHdrAttrBackup or
  98. dmHdrAttrOKToInstallNewer or
  99. dmHdrAttrResetAfterInstall or
  100. dmHdrAttrCopyPrevention or
  101. dmHdrAttrStream or
  102. dmHdrAttrLaunchableData or
  103. dmHdrAttrRecyclable or
  104. dmHdrAttrBundle or
  105. dmHdrAttrOpen;
  106. // Database attributes which only the system is allowed to change (for error-checking)
  107. dmSysOnlyHdrAttrs = dmHdrAttrResDB or dmHdrAttrOpen;
  108. (************************************************************
  109. * Unique ID equates
  110. *************************************************************)
  111. dmRecordIDReservedRange = 1; // The range of upper bits in the database's
  112. // uniqueIDSeed from 0 to this number are
  113. // reserved and not randomly picked when a
  114. // database is created.
  115. dmDefaultRecordsID = 0; // Records in a default database are copied
  116. // with their uniqueIDSeeds set in this range.
  117. dmUnusedRecordID = 0; // Record ID not allowed on the device
  118. (************************************************************
  119. * Mode flags passed to DmOpenDatabase
  120. *************************************************************)
  121. dmModeReadOnly = $0001; // read access
  122. dmModeWrite = $0002; // write access
  123. dmModeReadWrite = $0003; // read & write access
  124. dmModeLeaveOpen = $0004; // leave open when app quits
  125. dmModeExclusive = $0008; // don't let anyone else open it
  126. dmModeShowSecret = $0010; // force show of secret records
  127. // Generic type used to represent an open Database
  128. type
  129. DmOpenRef = Pointer;
  130. (************************************************************
  131. * Structure passed to DmGetNextDatabaseByTypeCreator and used
  132. * to cache search information between multiple searches.
  133. *************************************************************)
  134. type
  135. DmSearchStateType = record
  136. info: array [0..8-1] of UInt32;
  137. end;
  138. DmSearchStatePtr = ^DmSearchStateType;
  139. (************************************************************
  140. * Structures used by the sorting routines
  141. *************************************************************)
  142. SortRecordInfoType = record
  143. attributes: UInt8; // record attributes;
  144. uniqueID: array [0..3-1] of UInt8; // unique ID of record
  145. end;
  146. SortRecordInfoPtr = ^SortRecordInfoType;
  147. DmComparF = function(p1, p2: Pointer; other: Int16; s1, s2: SortRecordInfoPtr; appInfoH: MemHandle): Int16;
  148. (************************************************************
  149. * Database manager error codes
  150. * the constant dmErrorClass is defined in ErrorBase.h
  151. *************************************************************)
  152. const
  153. dmErrMemError = dmErrorClass or 1;
  154. dmErrIndexOutOfRange = dmErrorClass or 2;
  155. dmErrInvalidParam = dmErrorClass or 3;
  156. dmErrReadOnly = dmErrorClass or 4;
  157. dmErrDatabaseOpen = dmErrorClass or 5;
  158. dmErrCantOpen = dmErrorClass or 6;
  159. dmErrCantFind = dmErrorClass or 7;
  160. dmErrRecordInWrongCard = dmErrorClass or 8;
  161. dmErrCorruptDatabase = dmErrorClass or 9;
  162. dmErrRecordDeleted = dmErrorClass or 10;
  163. dmErrRecordArchived = dmErrorClass or 11;
  164. dmErrNotRecordDB = dmErrorClass or 12;
  165. dmErrNotResourceDB = dmErrorClass or 13;
  166. dmErrROMBased = dmErrorClass or 14;
  167. dmErrRecordBusy = dmErrorClass or 15;
  168. dmErrResourceNotFound = dmErrorClass or 16;
  169. dmErrNoOpenDatabase = dmErrorClass or 17;
  170. dmErrInvalidCategory = dmErrorClass or 18;
  171. dmErrNotValidRecord = dmErrorClass or 19;
  172. dmErrWriteOutOfBounds = dmErrorClass or 20;
  173. dmErrSeekFailed = dmErrorClass or 21;
  174. dmErrAlreadyOpenForWrites = dmErrorClass or 22;
  175. dmErrOpenedByAnotherTask = dmErrorClass or 23;
  176. dmErrUniqueIDNotFound = dmErrorClass or 24;
  177. dmErrAlreadyExists = dmErrorClass or 25;
  178. dmErrInvalidDatabaseName = dmErrorClass or 26;
  179. dmErrDatabaseProtected = dmErrorClass or 27;
  180. dmErrDatabaseNotProtected = dmErrorClass or 28;
  181. (************************************************************
  182. * Values for the direction parameter of DmSeekRecordInCategory
  183. *************************************************************)
  184. dmSeekForward = 1;
  185. dmSeekBackward = -1;
  186. (************************************************************
  187. * Data Manager procedures
  188. *************************************************************)
  189. // Initialization
  190. function DmInit: Err; syscall sysTrapDmInit;
  191. // Directory Lists
  192. function DmCreateDatabase(cardNo: UInt16; const nameP: PChar;
  193. creator, type_: UInt32; resDB: Boolean): Err; syscall sysTrapDmCreateDatabase;
  194. function DmCreateDatabaseFromImage(bufferP: MemPtr): Err; syscall sysTrapDmCreateDatabaseFromImage;
  195. function DmDeleteDatabase(cardNo: UInt16; dbID: LocalID): Err; syscall sysTrapDmDeleteDatabase;
  196. function DmNumDatabases(cardNo: UInt16): UInt16; syscall sysTrapDmNumDatabases;
  197. function DmGetDatabase(cardNo, index: UInt16): LocalID; syscall sysTrapDmGetDatabase;
  198. function DmFindDatabase(cardNo: UInt16; const nameP: PChar): LocalID; syscall sysTrapDmFindDatabase;
  199. function DmGetNextDatabaseByTypeCreator(newSearch: Boolean; stateInfoP: DmSearchStatePtr;
  200. type_, creator: UInt32; onlyLatestVers: Boolean;
  201. var cardNoP: UInt16; var dbIDP: LocalID): Err; syscall sysTrapDmGetNextDatabaseByTypeCreator;
  202. // Database info
  203. function DmDatabaseInfo(cardNo: UInt16; dbID: LocalID; nameP: PChar;
  204. var attributesP, versionP: UInt16; var crDateP, modDateP, bckUpDateP, modNumP: UInt32;
  205. var appInfoIDP, sortInfoIDP: LocalID; var typeP, creatorP: UInt32): Err; syscall sysTrapDmDatabaseInfo;
  206. function DmSetDatabaseInfo(cardNo: UInt16; dbID: LocalID; const nameP: PChar;
  207. var attributesP, versionP: UInt16; var crDateP, modDateP, bckUpDateP, modNumP: UInt32;
  208. var appInfoIDP, sortInfoIDP: LocalID; var typeP, creatorP: UInt32): Err; syscall sysTrapDmSetDatabaseInfo;
  209. function DmDatabaseSize(cardNo: UInt16; dbID: LocalID; var numRecordsP, totalBytesP, dataBytesP: UInt32): Err; syscall sysTrapDmDatabaseSize;
  210. // This routine can be used to prevent a database from being deleted (by passing
  211. // true for 'protect'). It will increment the protect count if 'protect' is true
  212. // and decrement it if 'protect' is false. This is used by code that wants to
  213. // keep a particular record or resource in a database locked down but doesn't
  214. // want to keep the database open. This information is keep in the dynamic heap so
  215. // all databases are "unprotected" at system reset.
  216. function DmDatabaseProtect(cardNo: UInt16; dbID: LocalID; protect: Boolean): Err; syscall sysTrapDmDatabaseProtect;
  217. // Open/close Databases
  218. function DmOpenDatabase(cardNo: UInt16; dbID: LocalID; mode: UInt16): DmOpenRef; syscall sysTrapDmOpenDatabase;
  219. function DmOpenDatabaseByTypeCreator(type_, creator: UInt32; mode: UInt16): DmOpenRef; syscall sysTrapDmOpenDatabaseByTypeCreator;
  220. function DmOpenDBNoOverlay(cardNo: UInt16; dbID: LocalID; mode: UInt16): DmOpenRef; syscall sysTrapDmOpenDBNoOverlay;
  221. function DmCloseDatabase(dbP: DmOpenRef): Err; syscall sysTrapDmCloseDatabase;
  222. // Info on open databases
  223. function DmNextOpenDatabase(currentP: DmOpenRef): DmOpenRef; syscall sysTrapDmNextOpenDatabase;
  224. function DmOpenDatabaseInfo(dbP: DmOpenRef; var dbIDP: LocalID;
  225. var openCountP, modeP, cardNoP: UInt16; var resDBP: Boolean): Err; syscall sysTrapDmOpenDatabaseInfo;
  226. function DmGetAppInfoID(dbP: DmOpenRef): LocalID; syscall sysTrapDmGetAppInfoID;
  227. procedure DmGetDatabaseLockState(dbR: DmOpenRef; var highest: UInt8; count, busy: UInt32); syscall sysTrapDmGetDatabaseLockState;
  228. // Utility to unlock all records and clear busy bits
  229. function DmResetRecordStates(dbP: DmOpenRef): Err; syscall sysTrapDmResetRecordStates;
  230. // Error Query
  231. function DmGetLastErr: Err; syscall sysTrapDmGetLastErr;
  232. //------------------------------------------------------------
  233. // Record based access routines
  234. //------------------------------------------------------------
  235. // Record Info
  236. function DmNumRecords(dbP: DmOpenRef): UInt16; syscall sysTrapDmNumRecords;
  237. function DmNumRecordsInCategory(dbP: DmOpenRef; category: UInt16): UInt16; syscall sysTrapDmNumRecordsInCategory;
  238. function DmRecordInfo(dbP: DmOpenRef; index: UInt16;
  239. var attrP: UInt16; var uniqueIDP: UInt32; var chunkIDP: LocalID): Err; syscall sysTrapDmRecordInfo;
  240. function DmSetRecordInfo(dbP: DmOpenRef; index: UInt16;
  241. var attrP: UInt16; var uniqueIDP: UInt32): Err; syscall sysTrapDmSetRecordInfo;
  242. // Record attaching and detaching
  243. function DmAttachRecord(dbP: DmOpenRef; var atP: UInt16; newH: MemHandle; var oldHP: MemHandle): Err; syscall sysTrapDmAttachRecord;
  244. function DmDetachRecord(dbP: DmOpenRef; index: UInt16; var oldHP: MemHandle): Err; syscall sysTrapDmDetachRecord;
  245. function DmMoveRecord(dbP: DmOpenRef; from, to_: UInt16): Err; syscall sysTrapDmMoveRecord;
  246. // Record creation and deletion
  247. function DmNewRecord(dbP: DmOpenRef; var atP: UInt16; size: UInt32): MemHandle; syscall sysTrapDmNewRecord;
  248. function DmRemoveRecord(dbP: DmOpenRef; index: UInt16): Err; syscall sysTrapDmRemoveRecord;
  249. function DmDeleteRecord(dbP: DmOpenRef; index: UInt16): Err; syscall sysTrapDmDeleteRecord;
  250. function DmArchiveRecord(dbP: DmOpenRef; index: UInt16): Err; syscall sysTrapDmArchiveRecord;
  251. function DmNewHandle(dbP: DmOpenRef; size: UInt32): MemHandle; syscall sysTrapDmNewHandle;
  252. function DmRemoveSecretRecords(dbP: DmOpenRef): Err; syscall sysTrapDmRemoveSecretRecords;
  253. // Record viewing manipulation
  254. function DmFindRecordByID(dbP: DmOpenRef; uniqueID: UInt32; var indexP: UInt16): Err; syscall sysTrapDmFindRecordByID;
  255. function DmQueryRecord(dbP: DmOpenRef; index: UInt16): MemHandle; syscall sysTrapDmQueryRecord;
  256. function DmGetRecord(dbP: DmOpenRef; index: UInt16): MemHandle; syscall sysTrapDmGetRecord;
  257. function DmQueryNextInCategory(dbP: DmOpenRef; var indexP: UInt16; category: UInt16): MemHandle; syscall sysTrapDmQueryNextInCategory;
  258. function DmPositionInCategory(dbP: DmOpenRef; index, category: UInt16): UInt16; syscall sysTrapDmPositionInCategory;
  259. function DmSeekRecordInCategory(dbP: DmOpenRef; var indexP: UInt16; offset: UInt16;
  260. direction: Int16; category: UInt16): Err; syscall sysTrapDmSeekRecordInCategory;
  261. function DmResizeRecord(dbP: DmOpenRef; index: UInt16; newSize: UInt32): MemHandle; syscall sysTrapDmResizeRecord;
  262. function DmReleaseRecord(dbP: DmOpenRef; index: UInt16; dirty: Boolean): Err; syscall sysTrapDmReleaseRecord;
  263. function DmSearchRecord(recH: MemHandle; var dbPP: DmOpenRef): UInt16; syscall sysTrapDmSearchRecord;
  264. // Category manipulation
  265. function DmMoveCategory(dbP: DmOpenRef; toCategory, fromCategory: UInt16; dirty: Boolean): Err; syscall sysTrapDmMoveCategory;
  266. function DmDeleteCategory(dbR: DmOpenRef; categoryNum: UInt16): Err; syscall sysTrapDmDeleteCategory;
  267. // Validation for writing
  268. function DmWriteCheck(recordP: Pointer; offset, bytes: UInt32): Err; syscall sysTrapDmWriteCheck;
  269. // Writing
  270. function DmWrite(recordP: Pointer; offset: UInt32; const srcP: Pointer; bytes: UInt32): Err; syscall sysTrapDmWrite;
  271. function DmStrCopy(recordP: Pointer; offset: UInt32; const srcP: PChar): Err; syscall sysTrapDmStrCopy;
  272. function DmSet(recordP: Pointer; offset, bytes: UInt32; value: UInt8): Err; syscall sysTrapDmSet;
  273. //------------------------------------------------------------
  274. // Resource based access routines
  275. //------------------------------------------------------------
  276. // High level access routines
  277. function DmGetResource(type_: DmResType; resID: DmResID): MemHandle; syscall sysTrapDmGetResource;
  278. function DmGet1Resource(type_: DmResType; resID: DmResID): MemHandle; syscall sysTrapDmGet1Resource;
  279. function DmReleaseResource(resourceH: MemHandle): Err; syscall sysTrapDmReleaseResource;
  280. function DmResizeResource(resourceH: MemHandle; newSize: UInt32): MemHandle; syscall sysTrapDmResizeResource;
  281. // Searching resource databases
  282. function DmNextOpenResDatabase(dbP: DmOpenRef): DmOpenRef; syscall sysTrapDmNextOpenResDatabase;
  283. function DmFindResourceType(dbP: DmOpenRef; resType: DmResType; typeIndex: UInt16): UInt16; syscall sysTrapDmFindResourceType;
  284. function DmFindResource(dbP: DmOpenRef; resType: DmResType; resID: DmResID; resH: MemHandle): UInt16; syscall sysTrapDmFindResource;
  285. function DmSearchResource(resType: DmResType; resID: DmResID; resH: MemHandle; var dbPP: DmOpenRef): UInt16; syscall sysTrapDmSearchResource;
  286. // Resource Info
  287. function DmNumResources(dbP: DmOpenRef): UInt16; syscall sysTrapDmNumResources;
  288. function DmResourceInfo(dbP: DmOpenRef; index: UInt16;
  289. var resTypeP: DmResType; var resIDP: DmResID;
  290. var chunkLocalIDP: LocalID): Err; syscall sysTrapDmResourceInfo;
  291. function DmSetResourceInfo(dbP: DmOpenRef; index: UInt16;
  292. var resTypeP: DmResType; var resIDP: DmResID): Err; syscall sysTrapDmSetResourceInfo;
  293. // Resource attaching and detaching
  294. function DmAttachResource(dbP: DmOpenRef; newH: MemHandle;
  295. resType: DmResType; resID: DmResID): Err; syscall sysTrapDmAttachResource;
  296. function DmDetachResource(dbP: DmOpenRef; index: UInt16; var oldHP: MemHandle): Err; syscall sysTrapDmDetachResource;
  297. // Resource creation and deletion
  298. function DmNewResource(dbP: DmOpenRef; resType: DmResType; resID: DmResID; size: UInt32): MemHandle; syscall sysTrapDmNewResource;
  299. function DmRemoveResource(dbP: DmOpenRef; index: UInt16): Err; syscall sysTrapDmRemoveResource;
  300. // Resource manipulation
  301. function DmGetResourceIndex(dbP: DmOpenRef; index: UInt16): MemHandle; syscall sysTrapDmGetResourceIndex;
  302. // Record sorting
  303. function DmQuickSort(dbP: DmOpenRef; compar: DmComparF; other: Int16): Err; syscall sysTrapDmQuickSort;
  304. function DmInsertionSort(dbR: DmOpenRef; compar: DmComparF; other: Int16): Err; syscall sysTrapDmInsertionSort;
  305. function DmFindSortPosition(dbP: DmOpenRef; newRecord: Pointer;
  306. newRecordInfo: SortRecordInfoPtr; compar: DmComparF; other: Int16): UInt16; syscall sysTrapDmFindSortPosition;
  307. function DmFindSortPositionV10(dbP: DmOpenRef; newRecord: Pointer; compar: DmComparF; other: Int16): UInt16; syscall sysTrapDmFindSortPositionV10;
  308. implementation
  309. end.