LUMIERA.clone/src/steam/engine/buffer-proxy-provider.hpp
Ichthyostega 9c5eb11b0c BufferProvider: switch to the new implementation structure
More or less forcibly squeeze all the existing implementation
into the new basic structure with two separate »pillars«

**Breakages**
 - existing code expected the `BufferStore` to transition to ''locked'' state
 - existing code expected `provideLockedBuffer(typeID)` to tail-call the
   `buildHandle()` function of the enclosing `BufferProvider` base implementation
 - various diagnostic usages bypassed the official APIs and called directly
   into the implementation. This is no longer possible; rather, `DiagnosticBufferProvider`
   needs to provide additional diagnostic API to suit those purposes
2026-02-11 02:13:43 +01:00

133 lines
4.8 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
BUFFER-PROXY-PROVIDER.hpp - Adapter to access existing allocation via buffer handling protocol
Copyright (C)
2024, Hermann Vosseler <Ichthyostega@web.de>
  **Lumiera** is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
  Free Software Foundation; either version 2 of the License, or (at your
  option) any later version. See the file COPYING for further details.
*/
/** @file buffer-proxy-provider.hpp
** Adapter to expose a given memory block through a BuffHandle.
** This allows to integrate a specific data access (e.g. related to input / output)
** with the buffer lifecycle protocol as defined by BufferProvider.
** @todo BROKEN as of 12/2024 //////////////////////////////////////////////////////////////////////////////TICKET #1387 : can not properly compose BufferProvider
** @see output-slot.hpp
** @see output-proxy-provider-test.cpp
*/
#ifndef STEAM_ENGINE_BUFFER_PROXY_PROVIDER_H
#define STEAM_ENGINE_BUFFER_PROXY_PROVIDER_H
#include "lib/error.hpp"
#include "lib/symbol.hpp"
#include "lib/meta/util.hpp"
//#include "lib/hash-value.h"
#include "steam/engine/buffer-provider.hpp"
#include "steam/engine/buffer-metadata.hpp"
//#include "steam/engine/engine-ctx.hpp"
//#include "steam/engine/type-handler.hpp"
//#include "steam/engine/buffer-local-tag.hpp"
#include "lib/nocopy.hpp"
#include <functional>
#include <utility>
//#include <memory>
namespace steam {
namespace engine {
using lib::Literal;
// using std::unique_ptr;
// using std::forward;
/**
* Adapter to expose access to data blocks via BuffHandle and the BufferProvider protocol.
* @todo WIP-WIP 12/2024 this is a design sketch to explore extension capabilities of BufferProvider
* @todo 2/2026 broken by refactoring of BufferProvider //////////////////////////////////////////////TICKET #1410 : refactoring to separate external and implementation API
*/
class BufferProxyProvider
: util::NonCopyable
{
using Listener = std::function<void(size_t,BufferState)>;
class ForwardingBufferProvider
: public BufferProvider /////////////////////////////////////////////////////////////TICKET #1410 : its clear now (2/26) that this must be some other base type; maybe we'll offer the ability to decorate, directly through BufferProviderSetup?
{
Listener listener_;
#if false //////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1410 : disabled code to while BufferProvider is being refactored...
/* === BufferProvider API === */
uint
prepareBuffers (uint, HashVal) override
{
NOTREACHED ("this part of the API should not be used");
return 1; // can not sensibly do anything for "pre-allocation",
} // other than telling the caller that we only "have one buffer to provide"
BuffHandle
provideLockedBuffer (HashVal typeID) override
{
/////////////////////////////////////////////////////////////////////////////////////TICKET #1387 : BufferProvider default impl. is lacking means to compose and delegate
// return buildHandle (typeID, asBuffer(newBlock.accessMemory()), &newBlock);
}
void
mark_emitted (HashVal, LocalTag const&) override
{
}
void
detachBuffer (HashVal, LocalTag const&, Buff&) override
{
}
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1410 : (end) disabled code
public:
ForwardingBufferProvider (Listener listener)
: BufferProvider{}
, listener_{std::move (listener)}
{ }
};
ForwardingBufferProvider passThroughProvider_;
public:
template<class LIS, typename = lib::meta::disable_if_self<BufferProxyProvider, LIS>>
BufferProxyProvider (LIS&& listener)
: passThroughProvider_{std::forward<LIS> (listener)}
{ }
template<typename TAR>
BuffHandle
lockBuffer (TAR& dataBlock)
{
//////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1387 : impossible due to inner contradictions in BufferProvider and OutputSlot
UNIMPLEMENTED ("setup type handler and then create a locked BuffHandle");
}
};
/* === Implementation === */
/** convenience shortcut: */
}} // namespace steam::engine
#endif /*STEAM_ENGINE_BUFFER_PROXY_PROVIDER_H*/