Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4b91047
added very basic persistant cache API
pfederl Aug 11, 2016
e6afff8
basic cache performance testing using leveldb
pfederl Aug 23, 2016
7f926ff
Added persistent cache plugin using Qt's sqlite.
pfederl Nov 7, 2016
aaa2994
merge develop
confluence Nov 18, 2016
0ab0ea2
basic usage of Pavol's sqlite cache; needs testing
confluence Nov 20, 2016
f776eea
added forgotten insertion into disk cache; put back memory cache in _…
confluence Nov 20, 2016
8199ad6
somehow this manual merge got screwed up
confluence Nov 20, 2016
ca49962
missing linebreak escapes
confluence Nov 20, 2016
909821e
missing declaration and header
confluence Nov 20, 2016
b01220e
m_diskCache is a pointer
confluence Nov 20, 2016
c80570e
revert cat typing
confluence Nov 20, 2016
6f5c13f
fixed c&p error
confluence Nov 20, 2016
a60696e
missing header?
confluence Nov 20, 2016
8be4b3d
re-create key variables
confluence Nov 20, 2016
ea44948
misunderstanding how .back() works
confluence Nov 20, 2016
1e6909a
can't print QString
confluence Nov 20, 2016
9742c4d
qDebug, not QDebug
confluence Nov 20, 2016
e715241
converted Pavol's LevelDB persistent cache implementation to a plugin
confluence Nov 28, 2016
dfd6775
added new plugin
confluence Nov 29, 2016
7ebfad1
missign header?
confluence Nov 29, 2016
f544684
This spelling mistake was driving me crazy.
confluence Nov 29, 2016
ae244de
wrong header
confluence Nov 29, 2016
17ef885
creating database file incorrectly
confluence Nov 29, 2016
3645189
We don't actually want to warn on failed reads; that happens whenever…
confluence Nov 29, 2016
5d098a8
Cleaning up cache test. Commented out duplicate implementation; tryin…
confluence Dec 5, 2016
274c71d
trying to use forEach correctly
confluence Dec 5, 2016
6e73e65
semicolon after lambda
confluence Dec 5, 2016
c673a16
removed commented-out cruft
confluence Dec 5, 2016
3bb1e42
removed duplicate implementation of packing / unpacking functions
confluence Dec 5, 2016
a099477
Change plugin config to specify the full path to the pcache file / di…
confluence Dec 7, 2016
3ba9bbe
fixed c&p error in error message
confluence Dec 7, 2016
7878924
attempting to add function to config object class to allow config to …
confluence Dec 7, 2016
6ff4ab8
correct return type
confluence Dec 7, 2016
a906ca6
missing header
confluence Dec 7, 2016
b970680
use test database files in test; delete afterwards
confluence Dec 7, 2016
78316ba
leveldb cache file is a directory
confluence Dec 7, 2016
eadc3df
revert last commit; this function is in Boost and C++17
confluence Dec 7, 2016
0efb609
try to delete the contents of the leveldb dir using leveldb's function
confluence Dec 7, 2016
9b44336
missing parameter
confluence Dec 7, 2016
dd27811
now we have to link to leveldb from the test
confluence Dec 7, 2016
2038d03
Delete all entries instead of deleting db files, which was being done…
confluence Dec 7, 2016
ff4759f
in the test, delete all data before the test, not after, in case it w…
confluence Dec 7, 2016
79c2699
check if disk cache exists before using it, otherwise ignore it
confluence Jan 19, 2017
aa2a23f
fixed variable scope
confluence Jan 19, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions carta/cpp/CartaLib/CartaLib.pro
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ SOURCES += \
Algorithms/LineCombiner.cpp \
IImageRenderService.cpp \
IRemoteVGView.cpp \
IPCache.cpp \
Hooks/GetPersistentCache.cpp \
Hooks/GetProfileExtractor.cpp \
Regions/IRegion.cpp \
InputEvents.cpp \
Expand All @@ -55,8 +57,7 @@ SOURCES += \
Regions/CoordinateSystemFormatter.cpp \
Regions/Ellipse.cpp \
Regions/Point.cpp \
Regions/Rectangle.cpp \
IPCache.cpp
Regions/Rectangle.cpp

HEADERS += \
CartaLib.h\
Expand Down Expand Up @@ -108,12 +109,14 @@ HEADERS += \
IImageRenderService.h \
Hooks/GetImageRenderService.h \
IRemoteVGView.h \
RegionInfo.h \
Hooks/GetProfileExtractor.h \
Regions/IRegion.h \
InputEvents.h \
Regions/ICoordSystem.h \
Hooks/CoordSystemHook.h \
Regions/CoordinateSystemFormatter.h \
Hooks/GetPersistentCache.h \
Regions/Ellipse.h \
Regions/Point.h \
Regions/Rectangle.h \
Expand Down
14 changes: 14 additions & 0 deletions carta/cpp/CartaLib/Hooks/GetPersistentCache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
*
**/

#include "GetPersistentCache.h"

namespace Carta
{
namespace Lib
{
namespace Hooks
{ }
}
}
57 changes: 57 additions & 0 deletions carta/cpp/CartaLib/Hooks/GetPersistentCache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Defines a hook for obtaining a persistent cache object.
*
**/

#pragma once

#include "CartaLib/CartaLib.h"
#include "CartaLib/IPlugin.h"
#include "CartaLib/IPCache.h"

namespace Carta
{
namespace Lib
{
namespace Hooks
{
/// \brief Hook for loading a plugin of an unknown type
///
class GetPersistentCache : public BaseHook
{
CARTA_HOOK_BOILER1( GetPersistentCache );

public:

/// Result of the hook is an instance of IPCache object.
/// This hook should only be ever called once, since the persistent cache
/// should be treated as a singleton. The reason I am not implementing this
/// as a singleton is because in the future, we may addd a mechanism (see below)
/// to be able to create multiple independent caches.
typedef IPCache::SharedPtr ResultType;

/// input parameters are:
/// nothing
/// All necessary parameters are retrieved from carta.config.
///
/// In the future we could make this contain overrides of some sort, in case
/// some code would like to create additional independent caches...
struct Params {
Params( )
{
}
};

/// standard constructor (could be probably a macro)
GetPersistentCache( Params * pptr ) : BaseHook( staticId ), paramsPtr( pptr )
{
// force instantiation of templates
CARTA_ASSERT( is < Me > () );
}

ResultType result;
Params * paramsPtr = nullptr;
};
}
}
}
2 changes: 1 addition & 1 deletion carta/cpp/CartaLib/Hooks/HookIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ enum class UniqueHookIDs {
ProfileHook_ID,
Fit1DHook_ID,
ImageStatisticsHook_ID,

GetPersistentCache_ID,
GetProfileExtractor_ID,

/// region related stuff, still to be considered experimental
Expand Down
11 changes: 6 additions & 5 deletions carta/cpp/CartaLib/IPCache.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
*
**/
/// IPCache is a set of APIs to access persistent cache.

#pragma once

#include "CartaLib/CartaLib.h"
#include <QJsonObject>
#include <QByteArray>
#include <QString>
Expand All @@ -15,6 +14,8 @@ namespace Lib
{
class IPCache
{
CLASS_BOILERPLATE( IPCache );

public:

/// return maximum storage in bytes
Expand All @@ -34,8 +35,8 @@ class IPCache
deleteAll() = 0;

/// read a value of an entry
/// if entry does not exist, val will be null
virtual void
/// if entry does not exist, false is returned
virtual bool
readEntry( const QByteArray & key,
QByteArray & val ) = 0;

Expand Down
3 changes: 3 additions & 0 deletions carta/cpp/CartaLib/IPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class IPlugin

/// called immediately after the plugin was loaded
/// TODO: should be pure virtual, don't be lazy!
///
/// This is different from the Initialize hook, which is delivered after
/// all plugins have been loaded and after core is started.
virtual void
initialize( const InitInfo & initInfo )
{
Expand Down
119 changes: 119 additions & 0 deletions carta/cpp/core/Algorithms/cacheUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* Functions for serializing and deserializing keys and values to be used with the disk cache
**/

#pragma once

/**
* Int --> byte array
**/
QByteArray i2qb( const int & d) {
QByteArray ba;
ba.append( (const char *)( & d), sizeof( int));
return ba;
}

/**
* Byte array --> int
**/
int qb2i( const QByteArray & ba) {
if( ba.size() != sizeof(int)) {
throw std::runtime_error("Could not unpack QByteArray into int: size is incorrect.");
}
return * ((const int *) (ba.constData()));
}

/**
* Double --> byte array
**/
QByteArray d2qb( const double & d) {
QByteArray ba;
ba.append( (const char *)( & d), sizeof( double));
return ba;
}

/**
* Byte array --> double
**/
double qb2d( const QByteArray & ba) {
if( ba.size() != sizeof(double)) {
throw std::runtime_error("Could not unpack QByteArray into double: size is incorrect.");
}
return * ((const double *) (ba.constData()));
}

/**
* Vector of doubles --> byte array
**/
QByteArray vd2qb( const std::vector<double> & vd) {
QByteArray ba;
for( const double & d : vd) {
ba.append( (const char *)( & d), sizeof( double));
}
return ba;
}

/**
* Byte array --> vector of doubles
**/
std::vector<double> qb2vd( const QByteArray & ba) {
std::vector<double> vd;
if( ba.size() % sizeof(double) != 0) {
throw std::runtime_error("Could not unpack QByteArray into std::vector<double>: size is incorrect.");
}
const char * cptr = ba.constData();
for( int i = 0 ; i < ba.size() ; i += sizeof(double)) {
vd.push_back( * ((const double *) (cptr + i)));
}
return vd;
}

/**
* Vector of integers --> byte array
**/
QByteArray vi2qb( const std::vector<int> & vi) {
QByteArray ba;
for( const int & i : vi) {
ba.append( (const char *)( & i), sizeof( int));
}
return ba;
}

/**
* Byte array --> vector of integers
**/
std::vector<int> qb2vi( const QByteArray & ba) {
std::vector<int> vi;
if( ba.size() % sizeof(int) != 0) {
throw std::runtime_error("Could not unpack QByteArray into std::vector<int>: size is incorrect.");
}
const char * cptr = ba.constData();
for( int i = 0 ; i < ba.size() ; i += sizeof(int)) {
vi.push_back( * ((const int *) (cptr + i)));
}
return vi;
}

/**
* Pair of int, double --> byte array
**/
QByteArray id2qb( const std::pair<int, double> & id) {
QByteArray ba;
ba.append( (const char *)( & id.first), sizeof( int));
ba.append( (const char *)( & id.second), sizeof( double));
return ba;
}


/**
* Byte array --> pair of int, double
**/
std::pair<int, double> qb2id( const QByteArray & ba) {
if( ba.size() != (sizeof(double) + sizeof(int))) {
throw std::runtime_error("Could not unpack QByteArray into std::pair<int, double>: size is incorrect.");
}
const char * cptr = ba.constData();
int int_val( * ((const int *) (cptr)));
double double_val( * ((const double *) (cptr + sizeof(int))));
return std::make_pair(int_val, double_val);
}
Loading