1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
// license:BSD-3-Clause
// copyright-holders:Vas Crabb
/***************************************************************************
ui/systemlist.h
Persistent system list data.
***************************************************************************/
#ifndef MAME_FRONTEND_UI_SYSTEMLIST_H
#define MAME_FRONTEND_UI_SYSTEMLIST_H
#pragma once
#include "ui/utils.h"
#include <atomic>
#include <condition_variable>
#include <functional>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
class ui_options;
namespace ui {
class system_list
{
public:
enum available : unsigned
{
AVAIL_NONE = 0U,
AVAIL_SYSTEM_NAMES = 1U << 0,
AVAIL_SORTED_LIST = 1U << 1,
AVAIL_BIOS_COUNT = 1U << 2,
AVAIL_UCS_SHORTNAME = 1U << 3,
AVAIL_UCS_DESCRIPTION = 1U << 4,
AVAIL_UCS_MANUF_DESC = 1U << 5,
AVAIL_UCS_DFLT_DESC = 1U << 6,
AVAIL_UCS_MANUF_DFLT_DESC = 1U << 7,
AVAIL_FILTER_DATA = 1U << 8
};
using system_vector = std::vector<ui_system_info>;
using system_reference = std::reference_wrapper<ui_system_info>;
using system_reference_vector = std::vector<system_reference>;
void cache_data(ui_options const &options);
void reset_cache();
bool is_available(available desired) const
{
return (m_available.load(std::memory_order_acquire) & desired) == desired;
}
void wait_available(available desired);
system_vector const &systems()
{
wait_available(AVAIL_SYSTEM_NAMES);
return m_systems;
}
system_reference_vector const &sorted_list()
{
wait_available(AVAIL_SORTED_LIST);
return m_sorted_list;
}
int bios_count()
{
wait_available(AVAIL_BIOS_COUNT);
return m_bios_count;
}
bool unavailable_systems()
{
wait_available(AVAIL_SORTED_LIST);
return std::find_if(m_sorted_list.begin(), m_sorted_list.end(), [] (ui_system_info const &info) { return !info.available; }) != m_sorted_list.end();
}
machine_filter_data &filter_data()
{
wait_available(AVAIL_FILTER_DATA);
return m_filter_data;
}
static system_list &instance();
private:
system_list();
~system_list();
void notify_available(available value);
void do_cache_data(std::string const &datpath, std::string const &titles);
void populate_list(bool copydesc);
void load_titles(util::core_file &file);
void populate_parents();
// synchronisation
std::mutex m_mutex;
std::condition_variable m_condition;
std::unique_ptr<std::thread> m_thread;
std::atomic<bool> m_started;
std::atomic<unsigned> m_available;
// data
system_vector m_systems;
system_reference_vector m_sorted_list;
machine_filter_data m_filter_data;
int m_bios_count;
};
} // namespace ui
#endif // MAME_FRONTEND_UI_SYSTEMLIST_H
|