summaryrefslogtreecommitdiff
path: root/map65/stdout_channel.h
blob: 2179598694d40535122a4bb014c7adb97c823ada (plain)
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
// stdout_channel.h
#pragma once
#include "stdout_shared_memory.h"
#include <string>
#include <stdexcept>

// Cross-platform event API implemented in win_event_shim.c or posix_event_shim.c
extern "C" {
    void* win_create_event();
    int   win_set_event(void*);
    int   win_reset_event(void*);
    int   win_wait_for_single_object(void*);
    void  win_close_event(void*);
}

struct StdoutChannel
{
    StdoutSharedMemory shared;
    void*              eventHandle;

    StdoutChannel(const std::wstring &mappingName,
                  const std::wstring & /*eventName*/,
                  std::size_t bufferBytes)
        : shared(mappingName, sizeof(StdoutSharedHeader) + bufferBytes),
          eventHandle(nullptr)
    {
        // Cross-platform event creation
        eventHandle = win_create_event();
        if (!eventHandle)
            throw std::runtime_error("win_create_event failed for stdout channel");
    }

    ~StdoutChannel()
    {
        if (eventHandle) {
            win_close_event(eventHandle);
            eventHandle = nullptr;
        }
    }

    StdoutChannel(const StdoutChannel&) = delete;
    StdoutChannel& operator=(const StdoutChannel&) = delete;
};