flat_file_dictionary_handler.h File Reference
#include "flat_file_types.h"
#include "flat_file.h"

Description

Function declarations at the dictionary interface level for the flat file store.

Author
Eric Huang

These functions are not intended to be used directly. The entry point here is the initialization function, which is used to bind these functions to a dictionary.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1.Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2.Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3.Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file flat_file_dictionary_handler.h.

Include dependency graph for flat_file_dictionary_handler.h:
This graph shows which files directly or indirectly include this file:

Functions

void ffdict_init (ion_dictionary_handler_t *handler)
 Given the handler instance, bind the appropriate flat file functions. More...
 
ion_status_t ffdict_insert (ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
 Given a record ( key, value ), insert it into the dictionary. More...
 
ion_status_t ffdict_get (ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
 Performs a "get" operation on the dictionary to retrieve a single record. More...
 
ion_err_t ffdict_create_dictionary (ion_dictionary_id_t id, ion_key_type_t key_type, ion_key_size_t key_size, ion_value_size_t value_size, ion_dictionary_size_t dictionary_size, ion_dictionary_compare_t compare, ion_dictionary_handler_t *handler, ion_dictionary_t *dictionary)
 Creates an instance of a flat file backed dictionary. More...
 
ion_status_t ffdict_delete (ion_dictionary_t *dictionary, ion_key_t key)
 Removes all instances of any record with key equal to key. More...
 
ion_err_t ffdict_delete_dictionary (ion_dictionary_t *dictionary)
 Cleans up all files created by the dictionary, and frees any allocated memory. More...
 
ion_err_t ffdict_destroy_dictionary (ion_dictionary_id_t id)
 Cleans up all files created by the dictionary, and frees any allocated memory, for an already closed dictionary. More...
 
ion_status_t ffdict_update (ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
 Updates all records stored at key to have value equal to value. More...
 

Function Documentation

ion_err_t ffdict_create_dictionary ( ion_dictionary_id_t  id,
ion_key_type_t  key_type,
ion_key_size_t  key_size,
ion_value_size_t  value_size,
ion_dictionary_size_t  dictionary_size,
ion_dictionary_compare_t  compare,
ion_dictionary_handler_t handler,
ion_dictionary_t dictionary 
)

Creates an instance of a flat file backed dictionary.

Parameters
[in]idThe ID to assign to the dictionary. This is either user defined or is given by the master table.
[in]key_typeThe category of key used by the dictionary. See ION_KEY_TYPE for more information.
[in]key_sizeThe size of the keys used for this dictionary, specified in bytes. It is strongly recommended to use a sizeof() directive to specify this size to avoid painful problems.
[in]value_sizeSame as above, for values.
[in]dictionary_sizeDesignates how many records we buffer in memory. Higher means better overall performance at the cost of increased memory usage.
[in]compareThe function pointer that designates how to compare two keys. This is given by the upper dictionary layers.
[in]handlerThe allocated, initialized handler that will be bound to the dictionary instance.
[in]dictionaryThe allocated dictionary instance that we are going to initialize.
Returns
The resulting status of the operation.

Definition at line 398 of file flat_file_dictionary_handler.c.

407  {
408  dictionary->instance = malloc(sizeof(ion_flat_file_t));
409 
410  if (NULL == dictionary->instance) {
411  return err_out_of_memory;
412  }
413 
414  dictionary->instance->compare = compare;
416 
417  ion_err_t result = flat_file_initialize((ion_flat_file_t *) dictionary->instance, id, key_type, key_size, value_size, dictionary_size);
418 
419  if ((err_ok == result) && (NULL != handler)) {
420  dictionary->handler = handler;
421  }
422 
423  return result;
424 }
Metadata container that holds flat file specific information.
ion_err_t flat_file_initialize(ion_flat_file_t *flat_file, ion_dictionary_id_t id, ion_key_type_t key_type, ion_key_size_t key_size, ion_value_size_t value_size, ion_dictionary_size_t dictionary_size)
Initializes the flat file implementation and creates all necessary files.
Definition: flat_file.c:40
ion_dictionary_handler_t * handler
ion_dictionary_parent_t * instance
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226
ion_dictionary_type_t type
ion_dictionary_compare_t compare

Here is the call graph for this function:

Here is the caller graph for this function:

ion_status_t ffdict_delete ( ion_dictionary_t dictionary,
ion_key_t  key 
)

Removes all instances of any record with key equal to key.

Parameters
[in]dictionaryWhich dictionary to delete from.
[in]keyDesignated key to look for and remove.
Returns
The resulting status of the operation.

Definition at line 427 of file flat_file_dictionary_handler.c.

430  {
431  return flat_file_delete((ion_flat_file_t *) dictionary->instance, key);
432 }
Metadata container that holds flat file specific information.
ion_dictionary_parent_t * instance
#define key(k)
Definition: bpp_tree.c:75
ion_status_t flat_file_delete(ion_flat_file_t *flat_file, ion_key_t key)
Deletes all records stored with the given key.
Definition: flat_file.c:495

Here is the call graph for this function:

Here is the caller graph for this function:

ion_err_t ffdict_delete_dictionary ( ion_dictionary_t dictionary)

Cleans up all files created by the dictionary, and frees any allocated memory.

Parameters
[in]dictionaryWhich dictionary instance to delete.
Returns
The resulting status of the operation.

Definition at line 435 of file flat_file_dictionary_handler.c.

437  {
438  ion_err_t result = flat_file_destroy((ion_flat_file_t *) dictionary->instance);
439 
440  free(dictionary->instance);
441  dictionary->instance = NULL;
442  return result;
443 }
Metadata container that holds flat file specific information.
ion_err_t flat_file_destroy(ion_flat_file_t *flat_file)
Destroys and cleans up any implementation specific memory or files.
Definition: flat_file.c:134
ion_dictionary_parent_t * instance
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226

Here is the call graph for this function:

Here is the caller graph for this function:

ion_err_t ffdict_destroy_dictionary ( ion_dictionary_id_t  id)

Cleans up all files created by the dictionary, and frees any allocated memory, for an already closed dictionary.

Parameters
[in]idThe identifier identifying the dictionary to delete.
Returns
The resulting status of the operation.

Definition at line 446 of file flat_file_dictionary_handler.c.

448  {
449  char filename[ION_MAX_FILENAME_LENGTH];
450 
451  dictionary_get_filename(id, "ffs", filename);
452 
453  if (0 != fremove(filename)) {
454  return err_file_delete_error;
455  }
456 
457  return err_ok;
458 }
#define fremove(x)
Definition: kv_system.h:56
int dictionary_get_filename(ion_dictionary_id_t id, char *ext, char *filename)
Given the ID, implementation specific extension, and a buffer to write to, writes back the formatted ...
Definition: dictionary.c:41
#define ION_MAX_FILENAME_LENGTH
Since the arduino conforms to 8.3 syntax, that's 8 + 3 = 11 + 1 (null terminator) characters...
Definition: kv_system.h:73

Here is the call graph for this function:

Here is the caller graph for this function:

ion_status_t ffdict_get ( ion_dictionary_t dictionary,
ion_key_t  key,
ion_value_t  value 
)

Performs a "get" operation on the dictionary to retrieve a single record.

Given a key, returns the associated value stored under that key. If there are duplicate records all with the same key, the exact one that is returned is undefined. If you need to get all records stored under a specific key, use a cursor query.

Parameters
[in]dictionaryWhich dictionary to perform the operation on.
[in]keyThe desired search key.
[out]valueThe output location in which to write the returned value. This space must be allocated by the user to at least value_size bytes, as originally defined on dictionary creation.
Returns
The resulting status of the operation.

Definition at line 389 of file flat_file_dictionary_handler.c.

393  {
394  return flat_file_get((ion_flat_file_t *) dictionary->instance, key, value);
395 }
ion_status_t flat_file_get(ion_flat_file_t *flat_file, ion_key_t key, ion_value_t value)
Fetches the record stored with the given key.
Definition: flat_file.c:439
Metadata container that holds flat file specific information.
ion_dictionary_parent_t * instance
#define key(k)
Definition: bpp_tree.c:75

Here is the call graph for this function:

Here is the caller graph for this function:

void ffdict_init ( ion_dictionary_handler_t handler)

Given the handler instance, bind the appropriate flat file functions.

Parameters
[in]handlerThe handler is assumed to be memory that is allocated and initialized by the user.

Definition at line 364 of file flat_file_dictionary_handler.c.

366  {
367  handler->insert = ffdict_insert;
369  handler->get = ffdict_get;
370  handler->update = ffdict_update;
371  handler->find = ffdict_find;
372  handler->remove = ffdict_delete;
377 }
ion_status_t ffdict_delete(ion_dictionary_t *dictionary, ion_key_t key)
Removes all instances of any record with key equal to key.
ion_status_t(* insert)(ion_dictionary_t *, ion_key_t, ion_value_t)
ion_status_t ffdict_update(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
Updates all records stored at key to have value equal to value.
ion_err_t ffdict_destroy_dictionary(ion_dictionary_id_t id)
Cleans up all files created by the dictionary, and frees any allocated memory, for an already closed ...
ion_err_t ffdict_find(ion_dictionary_t *dictionary, ion_predicate_t *predicate, ion_dict_cursor_t **cursor)
Initializes a cursor query and returns an allocated cursor object.
ion_status_t(* remove)(ion_dictionary_t *, ion_key_t)
ion_err_t(* destroy_dictionary)(ion_dictionary_id_t id)
ion_err_t ffdict_open_dictionary(ion_dictionary_handler_t *handler, ion_dictionary_t *dictionary, ion_dictionary_config_info_t *config, ion_dictionary_compare_t compare)
Re-instances a previously created flat file store instance and prepares it to be used again...
ion_err_t ffdict_close_dictionary(ion_dictionary_t *dictionary)
Closes this flat file store and persists everything to disk to be brought back later using dictionary...
ion_status_t ffdict_get(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
Performs a "get" operation on the dictionary to retrieve a single record.
ion_status_t(* update)(ion_dictionary_t *, ion_key_t, ion_value_t)
ion_err_t(* close_dictionary)(ion_dictionary_t *)
ion_err_t(* open_dictionary)(ion_dictionary_handler_t *, ion_dictionary_t *, ion_dictionary_config_info_t *, ion_dictionary_compare_t)
ion_err_t(* create_dictionary)(ion_dictionary_id_t, ion_key_type_t, ion_key_size_t, ion_value_size_t, ion_dictionary_size_t, ion_dictionary_compare_t, ion_dictionary_handler_t *, ion_dictionary_t *)
ion_err_t(* delete_dictionary)(ion_dictionary_t *)
ion_err_t ffdict_delete_dictionary(ion_dictionary_t *dictionary)
Cleans up all files created by the dictionary, and frees any allocated memory.
ion_err_t(* find)(ion_dictionary_t *, ion_predicate_t *, ion_dict_cursor_t **)
ion_status_t ffdict_insert(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
Given a record ( key, value ), insert it into the dictionary.
ion_err_t ffdict_create_dictionary(ion_dictionary_id_t id, ion_key_type_t key_type, ion_key_size_t key_size, ion_value_size_t value_size, ion_dictionary_size_t dictionary_size, ion_dictionary_compare_t compare, ion_dictionary_handler_t *handler, ion_dictionary_t *dictionary)
Creates an instance of a flat file backed dictionary.
ion_status_t(* get)(ion_dictionary_t *, ion_key_t, ion_value_t)

Here is the call graph for this function:

Here is the caller graph for this function:

ion_status_t ffdict_insert ( ion_dictionary_t dictionary,
ion_key_t  key,
ion_value_t  value 
)

Given a record ( key, value ), insert it into the dictionary.

Parameters
[in]dictionaryThe initialized dictionary instance we want to insert into.
[in]keyThe key portion of the record to be inserted.
[in]valueThe value portion of the record to be inserted.
Returns
The resulting status of the operation.

Definition at line 380 of file flat_file_dictionary_handler.c.

384  {
385  return flat_file_insert((ion_flat_file_t *) dictionary->instance, key, value);
386 }
Metadata container that holds flat file specific information.
ion_dictionary_parent_t * instance
#define key(k)
Definition: bpp_tree.c:75
ion_status_t flat_file_insert(ion_flat_file_t *flat_file, ion_key_t key, ion_value_t value)
Inserts the given record into the flat file store.
Definition: flat_file.c:388

Here is the call graph for this function:

Here is the caller graph for this function:

ion_status_t ffdict_update ( ion_dictionary_t dictionary,
ion_key_t  key,
ion_value_t  value 
)

Updates all records stored at key to have value equal to value.

If no records are stored at key, then an "upsert" (insert instead of update) is performed.

Parameters
[in]dictionaryWhich dictionary to update.
[in]keyTarget key to update.
[in]valueNew value to update to.
Returns
The resulting status of the operation.

Definition at line 461 of file flat_file_dictionary_handler.c.

465  {
466  return flat_file_update((ion_flat_file_t *) dictionary->instance, key, value);
467 }
Metadata container that holds flat file specific information.
ion_status_t flat_file_update(ion_flat_file_t *flat_file, ion_key_t key, ion_value_t value)
Updates all records stored with the given key to have value.
Definition: flat_file.c:560
ion_dictionary_parent_t * instance
#define key(k)
Definition: bpp_tree.c:75

Here is the call graph for this function:

Here is the caller graph for this function: