Program Listing for File base_executive.hpp
↰ Return to documentation for file (cosm/ta/base_executive.hpp
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include <functional>
#include <list>
#include <memory>
#include <random>
#include <string>
#include "rcppsw/er/client.hpp"
#include "rcppsw/math/rng.hpp"
#include "cosm/ta/config/task_alloc_config.hpp"
#include "cosm/ta/ds/ds_variant.hpp"
#include "cosm/ta/polled_task.hpp"
/*******************************************************************************
* Namespaces/Decls
******************************************************************************/
namespace cosm::ta {
namespace config { struct task_executive_config;}
/*******************************************************************************
* Class Definitions
******************************************************************************/
class base_executive : public rer::client<base_executive> {
public:
using abort_notify_cb = std::function<void(polled_task*)>;
using finish_notify_cb = std::function<void(polled_task*)>;
using start_notify_cb = std::function<void(polled_task*)>;
base_executive(const config::task_executive_config* exec_config,
const config::task_alloc_config* alloc_config,
ds::ds_variant&& ds,
rmath::rng* rng);
~base_executive(void) override;
base_executive& operator=(const base_executive&) = delete;
base_executive(const base_executive&) = delete;
void run(void);
const config::task_alloc_config* alloc_config(void) const {
return &mc_alloc_config;
}
const polled_task* current_task(void) const { return m_current_task; }
polled_task* current_task(void) { return m_current_task; }
void task_abort_notify(const abort_notify_cb& cb) {
m_task_abort_notify.push_back(cb);
}
const std::list<abort_notify_cb>& task_abort_notify(void) const {
return m_task_abort_notify;
}
void task_finish_notify(const finish_notify_cb& cb) {
m_task_finish_notify.push_back(cb);
}
const std::list<finish_notify_cb>& task_finish_notify(void) const {
return m_task_finish_notify;
}
void task_start_notify(const start_notify_cb& cb) {
m_task_start_notify.push_back(cb);
}
const std::list<start_notify_cb>& task_start_notify(void) const {
return m_task_start_notify;
}
const ds::ds_variant* ds(void) const { return &m_ds; }
bool update_exec_ests(void) const { return mc_update_exec_ests; }
bool update_interface_ests(void) const { return mc_update_interface_ests; }
protected:
virtual void task_abort_handle(polled_task* task);
virtual void task_start_handle(polled_task* new_task);
virtual void task_finish_handle(polled_task* task);
virtual polled_task* task_allocate(const polled_task* task) = 0;
void do_task_start(polled_task* task);
void task_ests_update(polled_task* task);
void task_times_update(polled_task* task);
void current_task(polled_task* current_task) { m_current_task = current_task; }
ds::ds_variant* ds(void) { return &m_ds; }
const rmath::rng* rng(void) const { return m_rng; }
rmath::rng* rng(void) { return m_rng; }
size_t task_alloc_count(void) const { return m_alloc_count; }
private:
/* clang-format off */
const bool mc_update_exec_ests;
const bool mc_update_interface_ests;
const config::task_alloc_config mc_alloc_config;
size_t m_alloc_count{0};
polled_task* m_current_task{nullptr};
std::list<abort_notify_cb> m_task_abort_notify{};
std::list<finish_notify_cb> m_task_finish_notify{};
std::list<start_notify_cb> m_task_start_notify{};
ds::ds_variant m_ds;
rmath::rng* m_rng;
/* clang-format on */
};
} /* namespace cosm::ta */