Cache: Minor cleanup

This commit is contained in:
Johan Wikman
2016-12-09 00:01:00 +02:00
parent e574af7e6e
commit c421026ce9
6 changed files with 58 additions and 51 deletions

View File

@ -18,10 +18,12 @@
#include <string> #include <string>
#include <maxscale/buffer.h> #include <maxscale/buffer.h>
#include <maxscale/session.h> #include <maxscale/session.h>
#include <maxscale/cpp.hh>
#include "cachefilter.h" #include "cachefilter.h"
#include "cache_storage_api.h" #include "cache_storage_api.h"
class CacheFilterSession; class CacheFilterSession;
class StorageFactory;
class Cache class Cache
{ {

View File

@ -11,6 +11,7 @@
* Public License. * Public License.
*/ */
#define MXS_MODULE_NAME "cache"
#include "cache_storage_api.hh" #include "cache_storage_api.hh"
#include <ctype.h> #include <ctype.h>

View File

@ -28,6 +28,9 @@ using std::string;
static char VERSION_STRING[] = "V1.0.0"; static char VERSION_STRING[] = "V1.0.0";
namespace
{
static const CACHE_CONFIG DEFAULT_CONFIG = static const CACHE_CONFIG DEFAULT_CONFIG =
{ {
CACHE_DEFAULT_MAX_RESULTSET_ROWS, CACHE_DEFAULT_MAX_RESULTSET_ROWS,
@ -44,6 +47,56 @@ static const CACHE_CONFIG DEFAULT_CONFIG =
CACHE_DEFAULT_THREAD_MODEL, CACHE_DEFAULT_THREAD_MODEL,
}; };
/**
* Frees all data of a config object, but not the object itself
*
* @param pConfig Pointer to a config object.
*/
void cache_config_finish(CACHE_CONFIG& config)
{
MXS_FREE(config.rules);
MXS_FREE(config.storage);
MXS_FREE(config.storage_options);
MXS_FREE(config.storage_argv); // The items need not be freed, they point into storage_options.
config.max_resultset_rows = 0;
config.max_resultset_size = 0;
config.rules = NULL;
config.storage = NULL;
config.storage_options = NULL;
config.storage_argc = 0;
config.storage_argv = NULL;
config.ttl = 0;
config.debug = 0;
}
/**
* Frees all data of a config object, and the object itself
*
* @param pConfig Pointer to a config object.
*/
void cache_config_free(CACHE_CONFIG* pConfig)
{
if (pConfig)
{
cache_config_finish(*pConfig);
MXS_FREE(pConfig);
}
}
/**
* Resets the data without freeing anything.
*
* @param config Reference to a config object.
*/
void cache_config_reset(CACHE_CONFIG& config)
{
memset(&config, 0, sizeof(config));
}
}
typedef struct cache_filter typedef struct cache_filter
{ {
cache_filter() cache_filter()
@ -632,50 +685,3 @@ static bool process_params(char **pzOptions, FILTER_PARAMETER **ppParams, CACHE_
return !error; return !error;
} }
/**
* Frees all data of a config object, but not the object itself
*
* @param pConfig Pointer to a config object.
*/
void cache_config_finish(CACHE_CONFIG& config)
{
MXS_FREE(config.rules);
MXS_FREE(config.storage);
MXS_FREE(config.storage_options);
MXS_FREE(config.storage_argv); // The items need not be freed, they point into storage_options.
config.max_resultset_rows = 0;
config.max_resultset_size = 0;
config.rules = NULL;
config.storage = NULL;
config.storage_options = NULL;
config.storage_argc = 0;
config.storage_argv = NULL;
config.ttl = 0;
config.debug = 0;
}
/**
* Frees all data of a config object, and the object itself
*
* @param pConfig Pointer to a config object.
*/
void cache_config_free(CACHE_CONFIG* pConfig)
{
if (pConfig)
{
cache_config_finish(*pConfig);
MXS_FREE(pConfig);
}
}
/**
* Resets the data without freeing anything.
*
* @param config Reference to a config object.
*/
void cache_config_reset(CACHE_CONFIG& config)
{
memset(&config, 0, sizeof(config));
}

View File

@ -77,8 +77,4 @@ typedef struct cache_config
cache_thread_model_t thread_model; /**< Thread model. */ cache_thread_model_t thread_model; /**< Thread model. */
} CACHE_CONFIG; } CACHE_CONFIG;
void cache_config_finish(CACHE_CONFIG& config);
void cache_config_free(CACHE_CONFIG* pConfig);
void cache_config_reset(CACHE_CONFIG& config);
#endif #endif

View File

@ -15,6 +15,7 @@
#include "rules.h" #include "rules.h"
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <new>
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
#include <maxscale/modutil.h> #include <maxscale/modutil.h>
#include <maxscale/protocol/mysql.h> #include <maxscale/protocol/mysql.h>

View File

@ -13,6 +13,7 @@
*/ */
#include <maxscale/cdefs.h> #include <maxscale/cdefs.h>
#include <maxscale/cpp.hh>
#include "cache_storage_api.h" #include "cache_storage_api.h"
class Storage class Storage