openMSX
RecordedCommand.hh
Go to the documentation of this file.
1 #ifndef RECORDEDCOMMAND_HH
2 #define RECORDEDCOMMAND_HH
3 
4 #include "Command.hh"
5 #include "StateChangeListener.hh"
6 #include "StateChange.hh"
7 #include "TclObject.hh"
8 #include "EmuTime.hh"
9 
10 namespace openmsx {
11 
12 class CommandController;
13 class StateChangeDistributor;
14 class Scheduler;
15 
20 class MSXCommandEvent final : public StateChange
21 {
22 public:
23  MSXCommandEvent() = default; // for serialize
24  MSXCommandEvent(span<std::string> tokens, EmuTime::param time);
25  MSXCommandEvent(span<const TclObject> tokens, EmuTime::param time);
26  const std::vector<TclObject>& getTokens() const { return tokens; }
27 
28  template<typename Archive>
29  void serialize(Archive& ar, unsigned version);
30 private:
31  std::vector<TclObject> tokens;
32 };
33 
34 
46 {
47 public:
51  virtual void execute(
52  span<const TclObject> tokens, TclObject& result,
53  EmuTime::param time) = 0;
54 
60  virtual bool needRecord(span<const TclObject> tokens) const;
61 
62 protected:
63  RecordedCommand(CommandController& commandController,
64  StateChangeDistributor& stateChangeDistributor,
65  Scheduler& scheduler,
66  std::string_view name);
68 
69 private:
70  // Command
71  void execute(span<const TclObject> tokens, TclObject& result) override;
72 
73  // StateChangeListener
74  void signalStateChange(const std::shared_ptr<StateChange>& event) override;
75  void stopReplay(EmuTime::param time) override;
76 
77  StateChangeDistributor& stateChangeDistributor;
78  Scheduler& scheduler;
79  TclObject dummyResultObject;
80  TclObject* currentResultObject;
81 };
82 
83 } // namespace openmsx
84 
85 #endif
openmsx::Scheduler
Definition: Scheduler.hh:33
openmsx::CommandController
Definition: CommandController.hh:17
openmsx::RecordedCommand::~RecordedCommand
~RecordedCommand()
Definition: RecordedCommand.cc:29
StateChangeListener.hh
openmsx::StateChange
Base class for all external MSX state changing events.
Definition: StateChange.hh:13
TclObject.hh
openmsx::RecordedCommand::needRecord
virtual bool needRecord(span< const TclObject > tokens) const
It's possible that in some cases the command doesn't need to be recorded after all (e....
Definition: RecordedCommand.cc:46
openmsx::RecordedCommand::execute
virtual void execute(span< const TclObject > tokens, TclObject &result, EmuTime::param time)=0
This is like the execute() method of the Command class, it only has an extra time parameter.
openmsx::StateChangeDistributor
Definition: StateChangeDistributor.hh:14
span
Definition: span.hh:34
openmsx::MSXCommandEvent::getTokens
const std::vector< TclObject > & getTokens() const
Definition: RecordedCommand.hh:26
StateChange.hh
EmuTime.hh
Command.hh
openmsx::RecordedCommand
Commands that directly influence the MSX state should send and events so that they can be recorded by...
Definition: RecordedCommand.hh:45
openmsx::Command
Definition: Command.hh:40
openmsx::Scheduler
Scheduler
Definition: Scheduler.cc:133
openmsx::TclObject
Definition: TclObject.hh:21
openmsx::MSXCommandEvent::serialize
void serialize(Archive &ar, unsigned version)
Definition: RecordedCommand.cc:103
openmsx::RecordedCommand::RecordedCommand
RecordedCommand(CommandController &commandController, StateChangeDistributor &stateChangeDistributor, Scheduler &scheduler, std::string_view name)
Definition: RecordedCommand.cc:17
openmsx::MSXCommandEvent
This class is used to for Tcl commands that directly influence the MSX state (e.g.
Definition: RecordedCommand.hh:20
openmsx::MSXCommandEvent::MSXCommandEvent
MSXCommandEvent()=default
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::StateChangeListener
Definition: StateChangeListener.hh:11