VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
MsgQueue.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "MsgQueueTypes.h"
16#include "CoreObject.h"
17#include "Synchronizable.h"
18#include "RingBuffer.h"
19
20namespace vc64 {
21
22class MsgQueue final : CoreObject, Synchronizable {
23
24 // Ring buffer storing all pending messages
25 util::RingBuffer <Message, 128> queue;
26
27 // The registered listener
28 const void *listener = nullptr;
29
30 // The registered callback function
31 Callback *callback = nullptr;
32
33 // If disabled, no messages will be stored
34 bool enabled = true;
35
36
37 //
38 // Methods
39 //
40
41private:
42
43 const char *objectName() const override { return "MsgQueue"; }
44
45
46 //
47 // Managing the queue
48 //
49
50public:
51
52 // Registers a listener together with it's callback function
53 void setListener(const void *listener, Callback *func);
54
55 // Disables the message queue
56 void disable() { enabled = false; }
57
58 // Sends a message
59 void put(const Message &msg);
60 void put(MsgType type, i64 payload = 0);
61 void put(MsgType type, CpuMsg payload);
62 void put(MsgType type, DriveMsg payload);
63 void put(MsgType type, ScriptMsg payload);
64 // void put(MsgType type, Snapshot *payload);
65
66 // Reads a message
67 bool get(Message &msg);
68};
69
70}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16