PageRenderTime 38ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcommon/lllivefile.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 95 lines | 20 code | 13 blank | 62 comment | 0 complexity | 9887c1afb9a279e9cebdceae8fe1b3b4 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lllivefile.h
  3. * @brief Automatically reloads a file whenever it changes or is removed.
  4. *
  5. * $LicenseInfo:firstyear=2006&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_LLLIVEFILE_H
  27. #define LL_LLLIVEFILE_H
  28. extern const F32 DEFAULT_CONFIG_FILE_REFRESH;
  29. class LL_COMMON_API LLLiveFile
  30. {
  31. public:
  32. LLLiveFile(const std::string& filename, const F32 refresh_period = 5.f);
  33. virtual ~LLLiveFile();
  34. /**
  35. * @brief Check to see if this live file should reload.
  36. *
  37. * Call this before using anything that was read & cached
  38. * from the file.
  39. *
  40. * This method calls the <code>loadFile()</code> method if
  41. * any of:
  42. * file has a new modify time since the last check
  43. * file used to exist and now does not
  44. * file used to not exist but now does
  45. * @return Returns true if the file was reloaded.
  46. */
  47. bool checkAndReload();
  48. std::string filename() const;
  49. /**
  50. * @brief Add this live file to an automated recheck.
  51. *
  52. * Normally, just calling checkAndReload() is enough. In some
  53. * cases though, you may need to let the live file periodically
  54. * check itself.
  55. */
  56. void addToEventTimer();
  57. void setRefreshPeriod(F32 seconds);
  58. protected:
  59. /**
  60. * @breif Implement this to load your file if it changed.
  61. *
  62. * This method is called automatically by <code>checkAndReload()</code>,
  63. * so though you must implement this in derived classes, you do
  64. * not need to call it manually.
  65. * @return Returns true if the file was successfully loaded.
  66. */
  67. virtual bool loadFile() = 0;
  68. /**
  69. * @brief Implement this method if you want to get a change callback.
  70. *
  71. * This virtual function will be called automatically at the end
  72. * of <code>checkAndReload()</code> if a new configuration was
  73. * loaded. This does not track differences between the current and
  74. * newly loaded file, so any successful load event will trigger a
  75. * <code>changed()</code> callback. Default is to do nothing.
  76. */
  77. virtual void changed() {}
  78. private:
  79. class Impl;
  80. Impl& impl;
  81. };
  82. #endif //LL_LLLIVEFILE_H