mirror of http://gerrit.asterisk.org/asterisk
make datastore creation and destruction a generic API since it is not really channel related, and add the ability to add/find/remove datastores to manager sessions
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@135680 65c4cc65-6c06-0410-ace0-fbb531ad65f31.6.1
parent
8ba981911a
commit
7df8b8b848
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2007 - 2008, Digium, Inc.
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
* \brief Asterisk datastore objects
|
||||
*/
|
||||
|
||||
#ifndef _ASTERISK_DATASTORE_H
|
||||
#define _ASTERISK_DATASTORE_H
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "asterisk/linkedlists.h"
|
||||
|
||||
#define DATASTORE_INHERIT_FOREVER INT_MAX
|
||||
|
||||
/*! \brief Structure for a data store type */
|
||||
struct ast_datastore_info {
|
||||
const char *type; /*!< Type of data store */
|
||||
void *(*duplicate)(void *data); /*!< Duplicate item data (used for inheritance) */
|
||||
void (*destroy)(void *data); /*!< Destroy function */
|
||||
|
||||
/*!
|
||||
* \brief Fix up channel references
|
||||
*
|
||||
* \arg data The datastore data
|
||||
* \arg old_chan The old channel owning the datastore
|
||||
* \arg new_chan The new channel owning the datastore
|
||||
*
|
||||
* This is exactly like the fixup callback of the channel technology interface.
|
||||
* It allows a datastore to fix any pointers it saved to the owning channel
|
||||
* in case that the owning channel has changed. Generally, this would happen
|
||||
* when the datastore is set to be inherited, and a masquerade occurs.
|
||||
*
|
||||
* \return nothing.
|
||||
*/
|
||||
void (*chan_fixup)(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan);
|
||||
};
|
||||
|
||||
/*! \brief Structure for a data store object */
|
||||
struct ast_datastore {
|
||||
const char *uid; /*!< Unique data store identifier */
|
||||
void *data; /*!< Contained data */
|
||||
const struct ast_datastore_info *info; /*!< Data store type information */
|
||||
unsigned int inheritance; /*!< Number of levels this item will continue to be inherited */
|
||||
AST_LIST_ENTRY(ast_datastore) entry; /*!< Used for easy linking */
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Create a data store object
|
||||
*/
|
||||
struct ast_datastore *ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid);
|
||||
|
||||
/*!
|
||||
* \brief Free a data store object
|
||||
*/
|
||||
int ast_datastore_free(struct ast_datastore *datastore);
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ASTERISK_DATASTORE_H */
|
||||
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2007 - 2008, Digium, Inc.
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
*
|
||||
* \brief Asterisk datastore objects
|
||||
*/
|
||||
|
||||
#include "asterisk.h"
|
||||
|
||||
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
|
||||
#include "asterisk/_private.h"
|
||||
|
||||
#include "asterisk/datastore.h"
|
||||
#include "asterisk/utils.h"
|
||||
|
||||
struct ast_datastore *ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
|
||||
{
|
||||
struct ast_datastore *datastore = NULL;
|
||||
|
||||
/* Make sure we at least have type so we can identify this */
|
||||
if (!info) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Allocate memory for datastore and clear it */
|
||||
datastore = ast_calloc(1, sizeof(*datastore));
|
||||
if (!datastore) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
datastore->info = info;
|
||||
|
||||
datastore->uid = ast_strdup(uid);
|
||||
|
||||
return datastore;
|
||||
}
|
||||
|
||||
int ast_datastore_free(struct ast_datastore *datastore)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
/* Using the destroy function (if present) destroy the data */
|
||||
if (datastore->info->destroy != NULL && datastore->data != NULL) {
|
||||
datastore->info->destroy(datastore->data);
|
||||
datastore->data = NULL;
|
||||
}
|
||||
|
||||
/* Free allocated UID memory */
|
||||
if (datastore->uid != NULL) {
|
||||
ast_free((void *) datastore->uid);
|
||||
datastore->uid = NULL;
|
||||
}
|
||||
|
||||
/* Finally free memory used by ourselves */
|
||||
ast_free(datastore);
|
||||
|
||||
return res;
|
||||
}
|
||||
Loading…
Reference in new issue