// $Id: Reactor.hh 5979 2007-01-06 18:54:52Z m9710797 $ #ifndef REACTOR_HH #define REACTOR_HH #include "Observer.hh" #include "EventListener.hh" #include "Semaphore.hh" #include "noncopyable.hh" #include #include #include namespace openmsx { class EventDistributor; class CommandController; class GlobalCommandController; class GlobalCliComm; class Display; class Mixer; class CommandConsole; class IconStatus; class InputEventGenerator; class DiskManipulator; class FilePool; class BooleanSetting; class MSXMotherBoard; class Setting; class CommandLineParser; class QuitCommand; class MachineCommand; class TestMachineCommand; class AviRecorder; class ConfigInfo; class GlobalSettings; template class EnumSetting; /** * Contains the main loop of openMSX. * openMSX is almost single threaded: the main thread does most of the work, * we create additional threads only if we need blocking calls for * communicating with peripherals. * This class serializes all incoming requests so they can be handled by the * main thread. */ class Reactor : private Observer, private EventListener, private noncopyable { public: Reactor(); ~Reactor(); /** * Main loop. */ void run(CommandLineParser& parser); void enterMainLoop(); EventDistributor& getEventDistributor(); GlobalCommandController& getGlobalCommandController(); GlobalCliComm& getGlobalCliComm(); InputEventGenerator& getInputEventGenerator(); Display& getDisplay(); Mixer& getMixer(); CommandConsole& getCommandConsole(); IconStatus& getIconStatus(); DiskManipulator& getDiskManipulator(); FilePool& getFilePool(); EnumSetting& getMachineSetting(); void createMotherBoard(const std::string& machine); MSXMotherBoard* getMotherBoard() const; static void getHwConfigs(const std::string& type, std::set& result); // convenience methods GlobalSettings& getGlobalSettings(); CommandController& getCommandController(); private: void createMachineSetting(); MSXMotherBoard& prepareMotherBoard(const std::string& machine); void switchMotherBoard(std::auto_ptr mb); void deleteMotherBoard(); // Observer virtual void update(const Setting& setting); // EventListener virtual bool signalEvent(shared_ptr event); void block(); void unblock(); void unpause(); void pause(); bool paused; int blockedCounter; /** * True iff the Reactor should keep running. * When this is set to false, the Reactor will end the main loop after * finishing the pending request(s). */ bool running; Semaphore mbSem; // note: order of auto_ptr's is important std::auto_ptr eventDistributor; std::auto_ptr globalCommandController; std::auto_ptr globalCliComm; std::auto_ptr inputEventGenerator; std::auto_ptr display; std::auto_ptr mixer; std::auto_ptr commandConsole; std::auto_ptr iconStatus; std::auto_ptr diskManipulator; std::auto_ptr filePool; BooleanSetting& pauseSetting; std::auto_ptr > machineSetting; const std::auto_ptr quitCommand; const std::auto_ptr machineCommand; const std::auto_ptr testMachineCommand; const std::auto_ptr aviRecordCommand; const std::auto_ptr extensionInfo; const std::auto_ptr machineInfo; std::auto_ptr motherBoard; std::auto_ptr newMotherBoard; friend class QuitCommand; friend class MachineCommand; }; } // namespace openmsx #endif // REACTOR_HH