2018-01-28 22:22:21 -05:00
|
|
|
//
|
|
|
|
// MultiMachine.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 28/01/2018.
|
2018-05-13 15:19:52 -04:00
|
|
|
// Copyright 2018 Thomas Harte. All rights reserved.
|
2018-01-28 22:22:21 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef MultiMachine_hpp
|
|
|
|
#define MultiMachine_hpp
|
|
|
|
|
2018-01-29 21:49:49 -05:00
|
|
|
#include "../../../Machines/DynamicMachine.hpp"
|
|
|
|
|
2020-04-01 23:19:34 -04:00
|
|
|
#include "Implementation/MultiProducer.hpp"
|
2018-02-09 16:31:05 -05:00
|
|
|
#include "Implementation/MultiConfigurable.hpp"
|
2020-04-01 23:19:34 -04:00
|
|
|
#include "Implementation/MultiProducer.hpp"
|
2018-02-09 16:31:05 -05:00
|
|
|
#include "Implementation/MultiJoystickMachine.hpp"
|
|
|
|
#include "Implementation/MultiKeyboardMachine.hpp"
|
2018-07-10 21:32:28 -04:00
|
|
|
#include "Implementation/MultiMediaTarget.hpp"
|
2018-01-28 22:22:21 -05:00
|
|
|
|
|
|
|
#include <memory>
|
2018-02-10 19:38:26 -05:00
|
|
|
#include <mutex>
|
2018-01-28 22:22:21 -05:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Analyser {
|
|
|
|
namespace Dynamic {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Provides the same interface as to a single machine, while multiplexing all
|
|
|
|
underlying calls to an array of real dynamic machines.
|
|
|
|
|
2018-02-19 16:03:17 -05:00
|
|
|
Calls to crt_machine->get_crt will return that for the frontmost machine;
|
|
|
|
anything installed as the speaker's delegate will similarly receive
|
|
|
|
feedback only from that machine.
|
2018-01-28 22:22:21 -05:00
|
|
|
|
|
|
|
Following each crt_machine->run_for, reorders the supplied machines by
|
|
|
|
confidence.
|
|
|
|
|
|
|
|
If confidence for any machine becomes disproportionately low compared to
|
2018-02-19 16:03:17 -05:00
|
|
|
the others in the set, that machine stops running.
|
2018-01-28 22:22:21 -05:00
|
|
|
*/
|
2020-04-01 23:19:34 -04:00
|
|
|
class MultiMachine: public ::Machine::DynamicMachine, public MultiTimedMachine::Delegate {
|
2018-01-28 22:22:21 -05:00
|
|
|
public:
|
2018-03-06 19:08:02 -05:00
|
|
|
/*!
|
|
|
|
Allows a potential MultiMachine creator to enquire as to whether there's any benefit in
|
|
|
|
requesting this class as a proxy.
|
|
|
|
|
|
|
|
@returns @c true if the multimachine would discard all but the first machine in this list;
|
|
|
|
@c false otherwise.
|
|
|
|
*/
|
|
|
|
static bool would_collapse(const std::vector<std::unique_ptr<DynamicMachine>> &machines);
|
2018-01-28 22:22:21 -05:00
|
|
|
MultiMachine(std::vector<std::unique_ptr<DynamicMachine>> &&machines);
|
|
|
|
|
2020-01-23 22:57:51 -05:00
|
|
|
Activity::Source *activity_source() final;
|
|
|
|
Configurable::Device *configurable_device() final;
|
2020-04-01 23:19:34 -04:00
|
|
|
MachineTypes::TimedMachine *timed_machine() final;
|
|
|
|
MachineTypes::ScanProducer *scan_producer() final;
|
|
|
|
MachineTypes::AudioProducer *audio_producer() final;
|
|
|
|
MachineTypes::JoystickMachine *joystick_machine() final;
|
|
|
|
MachineTypes::KeyboardMachine *keyboard_machine() final;
|
|
|
|
MachineTypes::MouseMachine *mouse_machine() final;
|
|
|
|
MachineTypes::MediaTarget *media_target() final;
|
2020-01-23 22:57:51 -05:00
|
|
|
void *raw_pointer() final;
|
2018-01-28 22:22:21 -05:00
|
|
|
|
2018-02-19 16:03:17 -05:00
|
|
|
private:
|
2020-04-01 23:19:34 -04:00
|
|
|
void did_run_machines(MultiTimedMachine *) final;
|
2018-02-01 07:53:52 -05:00
|
|
|
|
2018-01-28 22:22:21 -05:00
|
|
|
std::vector<std::unique_ptr<DynamicMachine>> machines_;
|
2019-02-27 22:39:33 -05:00
|
|
|
std::recursive_mutex machines_mutex_;
|
2018-01-29 21:49:49 -05:00
|
|
|
|
2018-02-09 16:31:05 -05:00
|
|
|
MultiConfigurable configurable_;
|
2020-04-01 23:19:34 -04:00
|
|
|
MultiTimedMachine timed_machine_;
|
|
|
|
MultiScanProducer scan_producer_;
|
|
|
|
MultiAudioProducer audio_producer_;
|
2018-02-09 16:31:05 -05:00
|
|
|
MultiJoystickMachine joystick_machine_;
|
|
|
|
MultiKeyboardMachine keyboard_machine_;
|
2018-07-10 21:32:28 -04:00
|
|
|
MultiMediaTarget media_target_;
|
2018-02-11 20:24:08 -05:00
|
|
|
|
|
|
|
void pick_first();
|
|
|
|
bool has_picked_ = false;
|
2018-01-28 22:22:21 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MultiMachine_hpp */
|