diff --git a/src/proc/engine/buffer-provider.cpp b/src/proc/engine/buffer-provider.cpp index 0ca617577..78cded609 100644 --- a/src/proc/engine/buffer-provider.cpp +++ b/src/proc/engine/buffer-provider.cpp @@ -29,6 +29,46 @@ namespace engine { namespace { // impl. details and definitions const uint DEFAULT_DESCRIPTOR = 0; + + typedef uint64_t LocalKey; + typedef size_t HashVal; + + const LocalKey UNSPECIFIC = 0; + + struct TypeHandler + { + typedef void (*Ctor) (void*); + typedef void (*Dtor) (void*); + + Ctor createAttached; + Dtor destroyAttached; + + TypeHandler() + : createAttached (0) + , destroyAttached (0) + { } + + template + TypeHandler() + : createAttached (0) /////////TODO: how to attach the ctor function??? mabye better use a class with virtual functions? + , destroyAttached (0) + { } + }; + + const TypeHandler RAW_BUFFER; + + + class Metadata + { + public: + static HashVal + key ( size_t storageSize + , TypeHandler instanceFunc =RAW_BUFFER + , LocalKey specifics =UNSPECIFIC) + { + UNIMPLEMENTED ("combine the distinguishing properties into a single hash"); + } + }; } @@ -47,9 +87,9 @@ namespace engine { BufferDescriptor - BufferProvider::getDefaultDescriptor() + BufferProvider::getDescriptorFor (size_t storageSize) { - return BufferDescriptor (*this, DEFAULT_DESCRIPTOR); + return BufferDescriptor (*this, Metadata::key (storageSize)); } diff --git a/src/proc/engine/buffer-provider.hpp b/src/proc/engine/buffer-provider.hpp index bbb7766ef..cb66710d3 100644 --- a/src/proc/engine/buffer-provider.hpp +++ b/src/proc/engine/buffer-provider.hpp @@ -61,8 +61,11 @@ namespace engine { /** - * Handle for a buffer for processing data, abstracting away the actual implementation. - * The real buffer pointer can be retrieved by dereferencing this smart-handle class. + * Interface: a facility providing and managing working buffers for media calculations. + * The pointer to actual buffer storage can be retrieved by + * - optionally announcing the required buffer(s) beforehand + * - "locking" a buffer to yield a buffer handle + * - dereferencing this smart-handle class * * @todo as of 6/2011 buffer management within the engine is still a bit vague */ @@ -82,7 +85,11 @@ namespace engine { /** describe the kind of buffer managed by this provider */ - BufferDescriptor getDefaultDescriptor(); //////////////TODO really? there is no sensible "default" + BufferDescriptor getDescriptorFor(size_t storageSize=0); + + template + BufferDescriptor getDescriptor(); + /* === API for BuffHandle internal access === */ @@ -111,5 +118,13 @@ namespace engine { } + template + BufferDescriptor + BufferProvider::getDescriptor() + { + UNIMPLEMENTED ("build descriptor for automatically placing an object instance into the buffer"); + } + + } // namespace engine #endif diff --git a/src/proc/engine/diagnostic-buffer-provider.cpp b/src/proc/engine/diagnostic-buffer-provider.cpp index 69df7c35a..b8f527d41 100644 --- a/src/proc/engine/diagnostic-buffer-provider.cpp +++ b/src/proc/engine/diagnostic-buffer-provider.cpp @@ -63,28 +63,25 @@ namespace engine { { return was_locked_; } + + bool + was_closed() const + { + return was_locked_; + } + + void* + accessMemory() const + { + return storage_.get(); + } }; namespace { // Details of allocation and accounting - - using lumiera::typelist::FunctionSignature; - using std::tr1::placeholders::_1; - using std::tr1::function; - using std::tr1::bind; - /** - * type rebinding template for issuing flexible queries - * and forwarding them to the individual block entries - */ - template - struct _Query - { - typedef typename FunctionSignature::Ret Result; - }; - - function QUERY_was_used = bind (&Block::was_used, _1 ); + const uint MAX_BUFFERS = 50; } // (END) Details of allocation and accounting @@ -119,21 +116,27 @@ namespace engine { virtual ~HeapMemProvider() { - INFO (proc_mem, "discarding %uz diagnostic buffer entries", HeapMemProvider::size()); + INFO (proc_mem, "discarding %zu diagnostic buffer entries", HeapMemProvider::size()); } - template - typename _Query::Result - accessStats (uint bufferID, FUN queryFunction) - { - queryFunction (access_or_create (bufferID)); - } - - private: Block& access_or_create (uint bufferID) { - UNIMPLEMENTED ("either get existing block or create new entries to fit"); + while (!withinStorageSize (bufferID)) + manage (new Block); + + ENSURE (withinStorageSize (bufferID)); + return (*this)[bufferID]; + } + + private: + bool + withinStorageSize (uint bufferID) const + { + if (bufferID >= MAX_BUFFERS) + throw error::Fatal ("hardwired internal limit for test buffers exceeded"); + + return bufferID < size(); } }; @@ -181,21 +184,21 @@ namespace engine { bool DiagnosticBufferProvider::buffer_was_used (uint bufferID) const { - pImpl_->accessStats (bufferID, QUERY_was_used); + return pImpl_->access_or_create(bufferID).was_used(); } bool DiagnosticBufferProvider::buffer_was_closed (uint bufferID) const { - UNIMPLEMENTED ("check closed-flag of a specific buffer"); + return pImpl_->access_or_create(bufferID).was_closed(); } void* - DiagnosticBufferProvider::accessStorage (uint bufferID) const + DiagnosticBufferProvider::accessMemory (uint bufferID) const { - + return pImpl_->access_or_create(bufferID).accessMemory(); } diff --git a/src/proc/engine/diagnostic-buffer-provider.hpp b/src/proc/engine/diagnostic-buffer-provider.hpp index 399f7d782..f79ca49d2 100644 --- a/src/proc/engine/diagnostic-buffer-provider.hpp +++ b/src/proc/engine/diagnostic-buffer-provider.hpp @@ -80,7 +80,7 @@ namespace engine { * for diagnostic access or wasn't registered beforehand. */ static DiagnosticBufferProvider& - access (BufferProvider const&); + access (BufferProvider const& ); @@ -89,7 +89,7 @@ namespace engine { bool buffer_was_used (uint bufferID) const; bool buffer_was_closed (uint bufferID) const; - void* accessStorage (uint bufferID) const; + void* accessMemory (uint bufferID) const; template diff --git a/tests/components/proc/engine/buffer-provider-protocol-test.cpp b/tests/components/proc/engine/buffer-provider-protocol-test.cpp index 7846dec5a..553f93190 100644 --- a/tests/components/proc/engine/buffer-provider-protocol-test.cpp +++ b/tests/components/proc/engine/buffer-provider-protocol-test.cpp @@ -101,7 +101,7 @@ namespace test { CHECK (checker.object_was_attached (0)); CHECK (checker.object_was_destroyed (0)); - CHECK (testData(0) == checker.accessStorage (0)); + CHECK (testData(0) == checker.accessMemory (0)); } @@ -112,10 +112,10 @@ namespace test { // In real usage, a suitable memory/frame/buffer provider // will be preconfigured, depending on the usage context BufferProvider& provider = DiagnosticBufferProvider::build(); -#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #829 BufferDescriptor desc1 = provider.getDescriptor(); BufferDescriptor desc2 = provider.getDescriptorFor(TEST_SIZE); +#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #829 CHECK (desc1.verifyValidity()); CHECK (desc2.verifyValidity());