/indra/llvfs/llvfsthread.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 142 lines · 84 code · 23 blank · 35 comment · 0 complexity · d89ef4ed1445234ed2b1f37311e208d7 MD5 · raw file

  1. /**
  2. * @file llvfsthread.h
  3. * @brief LLVFSThread definition
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLVFSTHREAD_H
  27. #define LL_LLVFSTHREAD_H
  28. #include <queue>
  29. #include <string>
  30. #include <map>
  31. #include <set>
  32. #include "llapr.h"
  33. #include "llqueuedthread.h"
  34. #include "llvfs.h"
  35. //============================================================================
  36. class LLVFSThread : public LLQueuedThread
  37. {
  38. //------------------------------------------------------------------------
  39. public:
  40. enum operation_t {
  41. FILE_READ,
  42. FILE_WRITE,
  43. FILE_RENAME
  44. };
  45. //------------------------------------------------------------------------
  46. public:
  47. class Request : public QueuedRequest
  48. {
  49. protected:
  50. ~Request() {}; // use deleteRequest()
  51. public:
  52. Request(handle_t handle, U32 priority, U32 flags,
  53. operation_t op, LLVFS* vfs,
  54. const LLUUID &file_id, const LLAssetType::EType file_type,
  55. U8* buffer, S32 offset, S32 numbytes);
  56. S32 getBytesRead()
  57. {
  58. return mBytesRead;
  59. }
  60. S32 getOperation()
  61. {
  62. return mOperation;
  63. }
  64. U8* getBuffer()
  65. {
  66. return mBuffer;
  67. }
  68. LLVFS* getVFS()
  69. {
  70. return mVFS;
  71. }
  72. std::string getFilename()
  73. {
  74. std::string tstring;
  75. mFileID.toString(tstring);
  76. return tstring;
  77. }
  78. /*virtual*/ bool processRequest();
  79. /*virtual*/ void finishRequest(bool completed);
  80. /*virtual*/ void deleteRequest();
  81. private:
  82. operation_t mOperation;
  83. LLVFS* mVFS;
  84. LLUUID mFileID;
  85. LLAssetType::EType mFileType;
  86. U8* mBuffer; // dest for reads, source for writes, new UUID for rename
  87. S32 mOffset; // offset into file, -1 = append (WRITE only)
  88. S32 mBytes; // bytes to read from file, -1 = all (new mFileType for rename)
  89. S32 mBytesRead; // bytes read from file
  90. };
  91. //------------------------------------------------------------------------
  92. public:
  93. static std::string sDataPath;
  94. static LLVFSThread* sLocal; // Default worker thread
  95. public:
  96. LLVFSThread(bool threaded = TRUE);
  97. ~LLVFSThread();
  98. // Return a Request handle
  99. handle_t read(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type, /* Flawfinder: ignore */
  100. U8* buffer, S32 offset, S32 numbytes, U32 pri=PRIORITY_NORMAL, U32 flags = 0);
  101. handle_t write(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
  102. U8* buffer, S32 offset, S32 numbytes, U32 flags);
  103. // SJB: rename seems to have issues, especially when threaded
  104. // handle_t rename(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
  105. // const LLUUID &new_id, const LLAssetType::EType new_type, U32 flags);
  106. // Return number of bytes read
  107. S32 readImmediate(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
  108. U8* buffer, S32 offset, S32 numbytes);
  109. S32 writeImmediate(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
  110. U8* buffer, S32 offset, S32 numbytes);
  111. /*virtual*/ bool processRequest(QueuedRequest* req);
  112. public:
  113. static void initClass(bool local_is_threaded = TRUE); // Setup sLocal
  114. static S32 updateClass(U32 ms_elapsed);
  115. static void cleanupClass(); // Delete sLocal
  116. static void setDataPath(const std::string& path) { sDataPath = path; }
  117. };
  118. //============================================================================
  119. #endif // LL_LLVFSTHREAD_H