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.

52 lines
2.1 KiB

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