openMSX
ThrottleManager.hh
Go to the documentation of this file.
1 #ifndef THROTTLEMANAGER_HH
2 #define THROTTLEMANAGER_HH
3 
4 #include "Subject.hh"
5 #include "BooleanSetting.hh"
6 
7 namespace openmsx {
8 
10 
11 /**
12  * Manages the throttle state of openMSX. It depends on the throttle setting,
13  * but also on the fullspeedwhenfastloading setting and if the MSX has
14  * notified us that it is loading... If you want to know about the throttle
15  * status of openMSX, attach to me! (And not just to throttleSetting!)
16  */
17 class ThrottleManager final : public Subject<ThrottleManager>
18  , private Observer<Setting>
19 {
20 public:
21  explicit ThrottleManager(CommandController& commandController);
22  ~ThrottleManager();
23 
24  /**
25  * Ask if throttling is enabled. Depends on the throttle setting, but
26  * also on the fullspeedwhenfastloading setting and if the MSX has
27  * notified us that it is loading... To be used for the timing.
28  */
29  bool isThrottled() const { return throttle; }
30 
31 private:
32  friend class LoadingIndicator;
33 
34  /**
35  * Use to indicate that the MSX is in a loading state, so that full
36  * speed can be enabled. Note that the caller can only call it once,
37  * when the state changes. It may not call it twice in a row with the
38  * same value for the argument.
39  * @param state true for loading, false for not loading
40  */
41  void indicateLoadingState(bool state);
42 
43  void updateStatus();
44 
45  // Observer<Setting>
46  void update(const Setting& setting) override;
47 
48  BooleanSetting throttleSetting;
49  BooleanSetting fullSpeedLoadingSetting;
50  int loading;
51  bool throttle;
52 };
53 
54 /**
55  * Used by a device to indicate when it is loading.
56  */
58 {
59 public:
60  explicit LoadingIndicator(ThrottleManager& throttleManager);
62 
63  /**
64  * Called by the device to indicate its loading state may have changed.
65  */
66  void update(bool newState);
67 
68 private:
69  ThrottleManager& throttleManager;
70  bool isLoading;
71 };
72 
73 } // namespace openmsx
74 
75 #endif
bool getEnum() const noexcept
Definition: EnumSetting.hh:96
bool isThrottled() const
Ask if throttling is enabled.
void update(bool newState)
Called by the device to indicate its loading state may have changed.
ThrottleManager(CommandController &commandController)
LoadingIndicator(ThrottleManager &throttleManager)
Used by a device to indicate when it is loading.