2018-01-31 03:23:06 +00:00
|
|
|
//
|
2020-04-02 03:49:07 +00:00
|
|
|
// MultiProducer.hpp
|
2018-01-31 03:23:06 +00:00
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 29/01/2018.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2018 Thomas Harte. All rights reserved.
|
2018-01-31 03:23:06 +00:00
|
|
|
//
|
|
|
|
|
2020-04-02 03:49:07 +00:00
|
|
|
#ifndef MultiProducer_hpp
|
|
|
|
#define MultiProducer_hpp
|
2018-01-31 03:23:06 +00:00
|
|
|
|
2018-02-09 01:33:57 +00:00
|
|
|
#include "../../../../Concurrency/AsyncTaskQueue.hpp"
|
2020-04-02 03:19:34 +00:00
|
|
|
#include "../../../../Machines/MachineTypes.hpp"
|
2018-01-31 03:23:06 +00:00
|
|
|
#include "../../../../Machines/DynamicMachine.hpp"
|
|
|
|
|
2018-02-18 20:23:15 +00:00
|
|
|
#include "MultiSpeaker.hpp"
|
|
|
|
|
2018-01-31 03:23:06 +00:00
|
|
|
#include <memory>
|
2018-02-11 00:38:26 +00:00
|
|
|
#include <mutex>
|
2018-01-31 03:23:06 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Analyser {
|
|
|
|
namespace Dynamic {
|
|
|
|
|
2020-04-02 03:19:34 +00:00
|
|
|
template <typename MachineType> class MultiInterface {
|
2018-01-31 03:23:06 +00:00
|
|
|
public:
|
2020-04-02 03:19:34 +00:00
|
|
|
MultiInterface(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines, std::recursive_mutex &machines_mutex) :
|
|
|
|
machines_(machines), machines_mutex_(machines_mutex), queues_(machines.size()) {}
|
2018-01-31 03:23:06 +00:00
|
|
|
|
2020-04-02 03:19:34 +00:00
|
|
|
protected:
|
2018-02-19 21:03:17 +00:00
|
|
|
/*!
|
2020-04-02 03:19:34 +00:00
|
|
|
Performs a parallel for operation across all machines, performing the supplied
|
|
|
|
function on each and returning only once all applications have completed.
|
|
|
|
|
|
|
|
No guarantees are extended as to which thread operations will occur on.
|
2018-02-19 21:03:17 +00:00
|
|
|
*/
|
2020-04-02 03:19:34 +00:00
|
|
|
void perform_parallel(const std::function<void(MachineType *)> &);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Performs a serial for operation across all machines, performing the supplied
|
|
|
|
function on each on the calling thread.
|
|
|
|
*/
|
|
|
|
void perform_serial(const std::function<void(MachineType *)> &);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines_;
|
|
|
|
std::recursive_mutex &machines_mutex_;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<Concurrency::AsyncTaskQueue> queues_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MultiTimedMachine: public MultiInterface<MachineTypes::TimedMachine>, public MachineTypes::TimedMachine {
|
|
|
|
public:
|
|
|
|
using MultiInterface::MultiInterface;
|
2018-02-19 21:03:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Provides a mechanism by which a delegate can be informed each time a call to run_for has
|
|
|
|
been received.
|
|
|
|
*/
|
|
|
|
struct Delegate {
|
2020-04-02 03:19:34 +00:00
|
|
|
virtual void did_run_machines(MultiTimedMachine *) = 0;
|
2018-02-19 21:03:17 +00:00
|
|
|
};
|
|
|
|
/// Sets @c delegate as the receiver of delegate messages.
|
|
|
|
void set_delegate(Delegate *delegate) {
|
|
|
|
delegate_ = delegate;
|
|
|
|
}
|
|
|
|
|
2020-01-24 03:57:51 +00:00
|
|
|
void run_for(Time::Seconds duration) final;
|
2018-01-31 03:23:06 +00:00
|
|
|
|
2018-02-19 21:03:17 +00:00
|
|
|
private:
|
2020-05-30 04:37:06 +00:00
|
|
|
void run_for(const Cycles) final {}
|
2018-02-01 12:53:52 +00:00
|
|
|
Delegate *delegate_ = nullptr;
|
2020-04-02 03:19:34 +00:00
|
|
|
};
|
2018-02-09 01:33:57 +00:00
|
|
|
|
2020-04-02 03:19:34 +00:00
|
|
|
class MultiScanProducer: public MultiInterface<MachineTypes::ScanProducer>, public MachineTypes::ScanProducer {
|
|
|
|
public:
|
|
|
|
using MultiInterface::MultiInterface;
|
2018-02-09 01:33:57 +00:00
|
|
|
|
2020-04-02 03:19:34 +00:00
|
|
|
/*!
|
|
|
|
Informs the MultiScanProducer that the order of machines has changed; it
|
|
|
|
uses this as an opportunity to synthesis any CRTMachine::Machine::Delegate messages that
|
|
|
|
are necessary to bridge the gap between one machine and the next.
|
2018-02-09 01:33:57 +00:00
|
|
|
*/
|
2020-04-02 03:19:34 +00:00
|
|
|
void did_change_machine_order();
|
|
|
|
|
|
|
|
void set_scan_target(Outputs::Display::ScanTarget *scan_target) final;
|
|
|
|
Outputs::Display::ScanStatus get_scan_status() const final;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Outputs::Display::ScanTarget *scan_target_ = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MultiAudioProducer: public MultiInterface<MachineTypes::AudioProducer>, public MachineTypes::AudioProducer {
|
|
|
|
public:
|
|
|
|
MultiAudioProducer(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines, std::recursive_mutex &machines_mutex);
|
2018-02-09 01:33:57 +00:00
|
|
|
|
|
|
|
/*!
|
2020-04-02 03:19:34 +00:00
|
|
|
Informs the MultiAudio that the order of machines has changed; it
|
|
|
|
uses this as an opportunity to switch speaker delegates as appropriate.
|
2018-02-09 01:33:57 +00:00
|
|
|
*/
|
2020-04-02 03:19:34 +00:00
|
|
|
void did_change_machine_order();
|
|
|
|
|
|
|
|
Outputs::Speaker::Speaker *get_speaker() final;
|
|
|
|
|
|
|
|
private:
|
|
|
|
MultiSpeaker *speaker_ = nullptr;
|
2018-01-31 03:23:06 +00:00
|
|
|
};
|
|
|
|
|
2020-04-02 03:19:34 +00:00
|
|
|
/*!
|
|
|
|
Provides a class that multiplexes the CRT machine interface to multiple machines.
|
|
|
|
|
|
|
|
Keeps a reference to the original vector of machines; will access it only after
|
|
|
|
acquiring a supplied mutex. The owner should also call did_change_machine_order()
|
|
|
|
if the order of machines changes.
|
|
|
|
*/
|
|
|
|
|
2018-01-31 03:23:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-02 03:49:07 +00:00
|
|
|
#endif /* MultiProducer_hpp */
|