PageRenderTime 24ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llvfs/lllfsthread.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 148 lines | 88 code | 25 blank | 35 comment | 0 complexity | c1d930feb263ebbaa45dea8ba39bc14a MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lllfsthread.h
  3. * @brief LLLFSThread base class
  4. *
  5. * $LicenseInfo:firstyear=2000&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_LLLFSTHREAD_H
  27. #define LL_LLLFSTHREAD_H
  28. #include <queue>
  29. #include <string>
  30. #include <map>
  31. #include <set>
  32. #include "llapr.h"
  33. #include "llpointer.h"
  34. #include "llqueuedthread.h"
  35. //============================================================================
  36. // Threaded Local File System
  37. //============================================================================
  38. class LLLFSThread : public LLQueuedThread
  39. {
  40. //------------------------------------------------------------------------
  41. public:
  42. enum operation_t {
  43. FILE_READ,
  44. FILE_WRITE,
  45. FILE_RENAME,
  46. FILE_REMOVE
  47. };
  48. //------------------------------------------------------------------------
  49. public:
  50. class Responder : public LLThreadSafeRefCount
  51. {
  52. protected:
  53. ~Responder();
  54. public:
  55. virtual void completed(S32 bytes) = 0;
  56. };
  57. class Request : public QueuedRequest
  58. {
  59. protected:
  60. virtual ~Request(); // use deleteRequest()
  61. public:
  62. Request(LLLFSThread* thread,
  63. handle_t handle, U32 priority,
  64. operation_t op, const std::string& filename,
  65. U8* buffer, S32 offset, S32 numbytes,
  66. Responder* responder);
  67. S32 getBytes()
  68. {
  69. return mBytes;
  70. }
  71. S32 getBytesRead()
  72. {
  73. return mBytesRead;
  74. }
  75. S32 getOperation()
  76. {
  77. return mOperation;
  78. }
  79. U8* getBuffer()
  80. {
  81. return mBuffer;
  82. }
  83. const std::string& getFilename()
  84. {
  85. return mFileName;
  86. }
  87. /*virtual*/ bool processRequest();
  88. /*virtual*/ void finishRequest(bool completed);
  89. /*virtual*/ void deleteRequest();
  90. private:
  91. LLLFSThread* mThread;
  92. operation_t mOperation;
  93. std::string mFileName;
  94. U8* mBuffer; // dest for reads, source for writes, new UUID for rename
  95. S32 mOffset; // offset into file, -1 = append (WRITE only)
  96. S32 mBytes; // bytes to read from file, -1 = all
  97. S32 mBytesRead; // bytes read from file
  98. LLPointer<Responder> mResponder;
  99. };
  100. //------------------------------------------------------------------------
  101. public:
  102. LLLFSThread(bool threaded = TRUE);
  103. ~LLLFSThread();
  104. // Return a Request handle
  105. handle_t read(const std::string& filename, /* Flawfinder: ignore */
  106. U8* buffer, S32 offset, S32 numbytes,
  107. Responder* responder, U32 pri=0);
  108. handle_t write(const std::string& filename,
  109. U8* buffer, S32 offset, S32 numbytes,
  110. Responder* responder, U32 pri=0);
  111. // Misc
  112. U32 priorityCounter() { return mPriorityCounter-- & PRIORITY_LOWBITS; } // Use to order IO operations
  113. // static initializers
  114. static void initClass(bool local_is_threaded = TRUE); // Setup sLocal
  115. static S32 updateClass(U32 ms_elapsed);
  116. static void cleanupClass(); // Delete sLocal
  117. private:
  118. U32 mPriorityCounter;
  119. public:
  120. static LLLFSThread* sLocal; // Default local file thread
  121. };
  122. //============================================================================
  123. #endif // LL_LLLFSTHREAD_H