TINC
Toolkit for Interactive Computation
tinc::DiskBufferJson Class Reference

A DiskBuffer that reads and decodes json files. More...

#include <DiskBufferJson.hpp>

Inheritance diagram for tinc::DiskBufferJson:
tinc::DiskBuffer< nlohmann::json > tinc::BufferManager< DataType > tinc::DiskBufferAbstract tinc::IdObject

Public Member Functions

 DiskBufferJson (std::string id="", std::string fileName="", std::string relPath="", std::string rootPath="", uint16_t size=2)
 
bool loadData (std::string filename="", bool notify=true) override
 updateData More...
 
std::string setData (nlohmann::json &newData)
 Write data from memory to disk buffer and then load it. More...
 
std::shared_ptr< DataType > get (bool markAsUsed=true)
 Get current buffer for reading. More...
 
std::shared_ptr< DataType > get (bool *isNew)
 Get current buffer for reading checking if data is new. More...
 
std::shared_ptr< DataType > getWritable ()
 Get a pointer to a writable buffer. More...
 
void doneWriting (std::shared_ptr< DataType > buffer)
 Mark a buffer as ready to read. More...
 
bool newDataAvailable ()
 Check if there are buffers that have been written but not read. More...
 
std::string getCurrentFileName ()
 getCurrentFileName More...
 
std::string getBaseFileName ()
 
void setBaseFileName (std::string name)
 
void setRelativePath (std::string path)
 
std::string getRelativePath ()
 
void setRootPath (std::string path)
 
std::string getRootPath ()
 
std::string getFullPath ()
 
void cleanupRoundRobinFiles ()
 
void enableRoundRobin (int cacheSize=0, bool clearLocks=true)
 
void useFileLock (bool use=true, bool clearLocks=true)
 
std::string getFilenameForWriting ()
 
void registerUpdateCallback (std::function< void(bool)> cb)
 register a function to be called when this object generates new buffer data More...
 
void registerNotifyCallback (std::function< void(bool)> cb)
 register a function to be called when this object generates new buffer data More...
 
std::string getId ()
 get this object's id More...
 
void setId (std::string id)
 set this object's id More...
 
std::string getDocumentation () const
 
void setDocumentation (const std::string &documentation)
 

Public Attributes

const int mSize
 
std::function< void(al::Socket *src)> modified = [](al::Socket * ) {}
 

Protected Member Functions

bool parseFile (std::string fileName, std::shared_ptr< nlohmann::json > newData) override
 
bool encodeData (std::string fileName, nlohmann::json &newData) override
 
std::string makeNextFileName ()
 
std::string makeFileName (uint64_t index)
 

Protected Attributes

std::vector< std::shared_ptr< DataType > > mData
 
std::mutex mDataLock
 
bool mNewData {false}
 
uint16_t mReadBuffer {0}
 
uint16_t mWriteBuffer {1}
 
std::string m_fileName
 
DistributedPath m_distPath
 
std::shared_ptr< al::ParameterString > m_trigger
 
std::mutex m_writeLock
 
uint64_t m_roundRobinCounter {0}
 
uint64_t m_roundRobinSize {0}
 
std::vector< std::function< void(bool)> > mUpdateCallbacks
 
std::vector< std::function< void(bool)> > mNotifyCallbacks
 
std::string mId
 
std::string mDocumentation
 

Detailed Description

A DiskBuffer that reads and decodes json files.

Definition at line 44 of file DiskBufferJson.hpp.

Constructor & Destructor Documentation

◆ DiskBufferJson()

tinc::DiskBufferJson::DiskBufferJson ( std::string  id = "",
std::string  fileName = "",
std::string  relPath = "",
std::string  rootPath = "",
uint16_t  size = 2 
)
inline

Definition at line 46 of file DiskBufferJson.hpp.

Member Function Documentation

◆ cleanupRoundRobinFiles()

void tinc::DiskBufferAbstract::cleanupRoundRobinFiles ( )
inlineinherited

Definition at line 87 of file DiskBufferAbstract.hpp.

◆ doneWriting()

template<class DataType >
void tinc::BufferManager< DataType >::doneWriting ( std::shared_ptr< DataType >  buffer)
inlineinherited

Mark a buffer as ready to read.

Parameters
bufferThe buffer previously received from getWritable()

The buffer provided must come from getWritable() otherwise behavior is undefined.

Definition at line 114 of file BufferManager.hpp.

◆ enableRoundRobin()

void tinc::DiskBufferAbstract::enableRoundRobin ( int  cacheSize = 0,
bool  clearLocks = true 
)
inlineinherited

Definition at line 88 of file DiskBufferAbstract.hpp.

◆ encodeData()

bool tinc::DiskBufferJson::encodeData ( std::string  fileName,
nlohmann::json &  newData 
)
inlineoverrideprotectedvirtual

Implements tinc::DiskBuffer< nlohmann::json >.

Definition at line 76 of file DiskBufferJson.hpp.

◆ get() [1/2]

template<class DataType >
std::shared_ptr<DataType> tinc::BufferManager< DataType >::get ( bool *  isNew)
inlineinherited

Get current buffer for reading checking if data is new.

Parameters
isNewthis is set to true if data returned is "new", false otherwise
Returns

Definition at line 76 of file BufferManager.hpp.

◆ get() [2/2]

template<class DataType >
std::shared_ptr<DataType> tinc::BufferManager< DataType >::get ( bool  markAsUsed = true)
inlineinherited

Get current buffer for reading.

Parameters
markAsUsedif false, the returned buffer keeps its "new" status
Returns
a pointer to the data

Definition at line 63 of file BufferManager.hpp.

◆ getBaseFileName()

std::string tinc::DiskBufferAbstract::getBaseFileName ( )
inlineinherited

Definition at line 75 of file DiskBufferAbstract.hpp.

◆ getCurrentFileName()

std::string tinc::DiskBufferAbstract::getCurrentFileName ( )
inlineinherited

getCurrentFileName

Returns

This function is not thread safe. Needs to be called synchronously to any process functions

Definition at line 60 of file DiskBufferAbstract.hpp.

◆ getDocumentation()

std::string tinc::IdObject::getDocumentation ( ) const
inherited

◆ getFilenameForWriting()

std::string tinc::DiskBufferAbstract::getFilenameForWriting ( )
inlineinherited

Definition at line 96 of file DiskBufferAbstract.hpp.

◆ getFullPath()

std::string tinc::DiskBufferAbstract::getFullPath ( )
inlineinherited

Definition at line 84 of file DiskBufferAbstract.hpp.

◆ getId()

std::string tinc::IdObject::getId ( )
inherited

get this object's id

◆ getRelativePath()

std::string tinc::DiskBufferAbstract::getRelativePath ( )
inlineinherited

Definition at line 79 of file DiskBufferAbstract.hpp.

◆ getRootPath()

std::string tinc::DiskBufferAbstract::getRootPath ( )
inlineinherited

Definition at line 82 of file DiskBufferAbstract.hpp.

◆ getWritable()

template<class DataType >
std::shared_ptr<DataType> tinc::BufferManager< DataType >::getWritable ( )
inlineinherited

Get a pointer to a writable buffer.

When done writing this buffer, call doneWriting()

Definition at line 92 of file BufferManager.hpp.

◆ loadData()

bool tinc::DiskBuffer< nlohmann::json >::loadData ( std::string  filename = "",
bool  notify = true 
)
overridevirtualinherited

updateData

Parameters
filename
Returns

Whenever overriding this function, you must make sure you call the update callbacks in mUpdateCallbacks

Implements tinc::DiskBufferAbstract.

Definition at line 67 of file DiskBuffer.hpp.

◆ makeFileName()

std::string tinc::DiskBufferAbstract::makeFileName ( uint64_t  index)
inlineprotectedinherited

Definition at line 156 of file DiskBufferAbstract.hpp.

◆ makeNextFileName()

std::string tinc::DiskBufferAbstract::makeNextFileName ( )
inlineprotectedinherited

Definition at line 144 of file DiskBufferAbstract.hpp.

◆ newDataAvailable()

template<class DataType >
bool tinc::BufferManager< DataType >::newDataAvailable ( )
inlineinherited

Check if there are buffers that have been written but not read.

Definition at line 124 of file BufferManager.hpp.

◆ parseFile()

bool tinc::DiskBufferJson::parseFile ( std::string  fileName,
std::shared_ptr< nlohmann::json >  newData 
)
inlineoverrideprotectedvirtual

Implements tinc::DiskBuffer< nlohmann::json >.

Definition at line 58 of file DiskBufferJson.hpp.

◆ registerNotifyCallback()

void tinc::DiskBufferAbstract::registerNotifyCallback ( std::function< void(bool)>  cb)
inlineinherited

register a function to be called when this object generates new buffer data

Parameters
cbIf this object is registered with a TINC server or client, this function will only be called if the data creation is local to the node.

When defining loadData(), these callbacks should only be called accodring to the notify argument.

Definition at line 125 of file DiskBufferAbstract.hpp.

◆ registerUpdateCallback()

void tinc::DiskBufferAbstract::registerUpdateCallback ( std::function< void(bool)>  cb)
inlineinherited

register a function to be called when this object generates new buffer data

Parameters
cbIf this object is registered with a TINC server or client, this function will only be called if the data creation is local to the node.

Definition at line 110 of file DiskBufferAbstract.hpp.

◆ setBaseFileName()

void tinc::DiskBufferAbstract::setBaseFileName ( std::string  name)
inlineinherited

Definition at line 76 of file DiskBufferAbstract.hpp.

◆ setData()

std::string tinc::DiskBuffer< nlohmann::json >::setData ( nlohmann::json &  newData)
inherited

Write data from memory to disk buffer and then load it.

Parameters
newData
Returns
the name of the file where buffer was written

Definition at line 74 of file DiskBuffer.hpp.

◆ setDocumentation()

void tinc::IdObject::setDocumentation ( const std::string &  documentation)
inherited

◆ setId()

void tinc::IdObject::setId ( std::string  id)
inherited

set this object's id

◆ setRelativePath()

void tinc::DiskBufferAbstract::setRelativePath ( std::string  path)
inlineinherited

Definition at line 78 of file DiskBufferAbstract.hpp.

◆ setRootPath()

void tinc::DiskBufferAbstract::setRootPath ( std::string  path)
inlineinherited

Definition at line 81 of file DiskBufferAbstract.hpp.

◆ useFileLock()

void tinc::DiskBufferAbstract::useFileLock ( bool  use = true,
bool  clearLocks = true 
)
inlineinherited

Definition at line 92 of file DiskBufferAbstract.hpp.

Member Data Documentation

◆ m_distPath

DistributedPath tinc::DiskBufferAbstract::m_distPath
protectedinherited

Definition at line 132 of file DiskBufferAbstract.hpp.

◆ m_fileName

std::string tinc::DiskBufferAbstract::m_fileName
protectedinherited

Definition at line 130 of file DiskBufferAbstract.hpp.

◆ m_roundRobinCounter

uint64_t tinc::DiskBufferAbstract::m_roundRobinCounter {0}
protectedinherited

Definition at line 138 of file DiskBufferAbstract.hpp.

◆ m_roundRobinSize

uint64_t tinc::DiskBufferAbstract::m_roundRobinSize {0}
protectedinherited

Definition at line 139 of file DiskBufferAbstract.hpp.

◆ m_trigger

std::shared_ptr<al::ParameterString> tinc::DiskBufferAbstract::m_trigger
protectedinherited

Definition at line 134 of file DiskBufferAbstract.hpp.

◆ m_writeLock

std::mutex tinc::DiskBufferAbstract::m_writeLock
protectedinherited

Definition at line 136 of file DiskBufferAbstract.hpp.

◆ mData

template<class DataType >
std::vector<std::shared_ptr<DataType> > tinc::BufferManager< DataType >::mData
protectedinherited

Definition at line 130 of file BufferManager.hpp.

◆ mDataLock

template<class DataType >
std::mutex tinc::BufferManager< DataType >::mDataLock
protectedinherited

Definition at line 132 of file BufferManager.hpp.

◆ mDocumentation

std::string tinc::IdObject::mDocumentation
protectedinherited

Definition at line 69 of file IdObject.hpp.

◆ mId

std::string tinc::IdObject::mId
protectedinherited

Definition at line 68 of file IdObject.hpp.

◆ mNewData

template<class DataType >
bool tinc::BufferManager< DataType >::mNewData {false}
protectedinherited

Definition at line 133 of file BufferManager.hpp.

◆ mNotifyCallbacks

std::vector<std::function<void(bool)> > tinc::DiskBufferAbstract::mNotifyCallbacks
protectedinherited

Definition at line 142 of file DiskBufferAbstract.hpp.

◆ modified

std::function<void(al::Socket *src)> tinc::IdObject::modified = [](al::Socket * ) {}
inherited

Definition at line 65 of file IdObject.hpp.

◆ mReadBuffer

template<class DataType >
uint16_t tinc::BufferManager< DataType >::mReadBuffer {0}
protectedinherited

Definition at line 134 of file BufferManager.hpp.

◆ mSize

template<class DataType >
const int tinc::BufferManager< DataType >::mSize
inherited

Definition at line 50 of file BufferManager.hpp.

◆ mUpdateCallbacks

std::vector<std::function<void(bool)> > tinc::DiskBufferAbstract::mUpdateCallbacks
protectedinherited

Definition at line 141 of file DiskBufferAbstract.hpp.

◆ mWriteBuffer

template<class DataType >
uint16_t tinc::BufferManager< DataType >::mWriteBuffer {1}
protectedinherited

Definition at line 135 of file BufferManager.hpp.


The documentation for this class was generated from the following file: