You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. namespace IPA.Config
  9. {
  10. /// <summary>
  11. /// A storage for a config structure.
  12. /// </summary>
  13. public interface IConfigStore
  14. {
  15. /// <summary>
  16. /// A synchronization object for the save thread to wait on for changes.
  17. /// It should be signaled whenever the internal state of the object is changed.
  18. /// The writer will never signal this handle.
  19. /// </summary>
  20. WaitHandle SyncObject { get; }
  21. /// <summary>
  22. /// A synchronization object for the load thread and accessors to maintain safe synchronization.
  23. /// Any readers should take a read lock with <see cref="ReaderWriterLockSlim.EnterReadLock()"/> or
  24. /// <see cref="ReaderWriterLockSlim.EnterUpgradeableReadLock()"/>, and any writers should take a
  25. /// write lock with <see cref="ReaderWriterLockSlim.EnterWriteLock()"/>.
  26. /// </summary>
  27. /// <remarks>
  28. /// Read and write are read and write to *this object*, not to the file on disk.
  29. /// </remarks>
  30. ReaderWriterLockSlim WriteSyncObject { get; }
  31. /// <summary>
  32. /// Writes the config structure stored by the current <see cref="IConfigStore"/> to the given
  33. /// <see cref="IConfigProvider"/>.
  34. /// </summary>
  35. /// <remarks>
  36. /// The calling code will have entered a read lock on <see cref="WriteSyncObject"/> when
  37. /// this is called.
  38. /// </remarks>
  39. /// <param name="provider">the provider to write to</param>
  40. void WriteTo(ConfigProvider provider);
  41. /// <summary>
  42. /// Reads the config structure from the given <see cref="IConfigProvider"/> into the current
  43. /// <see cref="IConfigStore"/>.
  44. /// </summary>
  45. /// <remarks>
  46. /// The calling code will have entered a write lock on <see cref="WriteSyncObject"/> when
  47. /// this is called.
  48. /// </remarks>
  49. /// <param name="provider">the provider to read from</param>
  50. void ReadFrom(ConfigProvider provider);
  51. }
  52. }