Contiki 2.5
storage.h
Go to the documentation of this file.
1 /**
2  * \addtogroup agent
3  * @{
4  */
5 
6 /**
7  * \defgroup bundle_storage Bundle Storage modules
8  *
9  * @{
10  */
11 
12 /**
13  * \file
14  * \brief this file defines the interface for storage modules
15  * \author Georg von Zengen <vonzeng@ibr.cs.tu-bs.de>
16  */
17 
18 #ifndef __STORAGE_H__
19 #define __STORAGE_H__
20 
21 #include <stdlib.h>
22 #include <stdio.h>
23 
24 #include "contiki.h"
25 #include "memb.h"
26 
27 #include "bundle.h"
28 
29 /**
30  * Which storage driver are we going to use?
31  * Default is RAM
32  */
33 #ifdef BUNDLE_CONF_STORAGE
34 #define BUNDLE_STORAGE BUNDLE_CONF_STORAGE
35 #else
36 #define BUNDLE_STORAGE storage_mmem
37 #endif
38 
39 /**
40  * How many bundles can possibly be stored in the data structures?
41  */
42 #ifdef BUNDLE_CONF_STORAGE_SIZE
43 #define BUNDLE_STORAGE_SIZE BUNDLE_CONF_STORAGE_SIZE
44 #else
45 #define BUNDLE_STORAGE_SIZE 10
46 #endif
47 
48 /**
49  * Should storage go into an initial safe state when starting up?
50  * Otherwise, some storages may try to reconstruct the last start before powering down
51  */
52 #ifdef BUNDLE_CONF_STORAGE_INIT
53 #define BUNDLE_STORAGE_INIT BUNDLE_CONF_STORAGE_INIT
54 #else
55 #define BUNDLE_STORAGE_INIT 0
56 #endif
57 
58 /**
59  * Should the storage run out if space, what shall we do?
60  */
61 // Options
62 #define BUNDLE_STORAGE_BEHAVIOUR_DELETE_OLDER 1
63 #define BUNDLE_STORAGE_BEHAVIOUR_DELETE_YOUNGER 2
64 #define BUNDLE_STORAGE_BEHAVIOUR_DO_NOT_DELETE 3
65 #define BUNDLE_STORAGE_BEHAVIOUR_DELETE_OLDEST 4
66 #define BUNDLE_STORAGE_BEHAVIOUR_DELETE_YOUNGEST 5
67 // Selection
68 #ifdef BUNDLE_CONF_STORAGE_BEHAVIOUR
69 #define BUNDLE_STORAGE_BEHAVIOUR BUNDLE_CONF_STORAGE_BEHAVIOUR
70 #else
71 #define BUNDLE_STORAGE_BEHAVIOUR BUNDLE_STORAGE_BEHAVIOUR_DELETE_OLDER
72 #endif
73 
74 /**
75  * Representation of a bundle as returned by the "get_bundles" call to the storage module
76  */
78  /** pointer to the next list element */
80 
81  /** Internal number of the bundle */
82  uint32_t bundle_num;
83 };
84 
85 /** storage module interface */
87  char *name;
88  /** called by agent a startup */
89  void (* init)(void);
90  void (* reinit)(void);
91  /** saves a bundle */
92  uint8_t (* save_bundle)(struct mmem *bundlemem, uint32_t ** bundle_number);
93  /** deletes a bundle */
94  uint16_t (* del_bundle)(uint32_t bundle_num, uint8_t reason);
95  /** reads a bundle */
96  struct mmem *(* read_bundle)(uint32_t bundle_num);
97  /** Marks a bundle as locked so it will not be deleted until it is unlocked */
98  uint8_t (* lock_bundle)(uint32_t bundle_num);
99  /** Unlocks a bundle so it can be deleted again */
100  void (* unlock_bundle)(uint32_t bundle_num);
101  /** checks if there is space for a bundle */
102  uint16_t (* free_space)(struct mmem *bundlemem);
103  /** returns the number of saved bundles */
104  uint16_t (* get_bundle_num)(void);
105  /** returns pointer to list of bundles */
106  struct storage_entry_t * (* get_bundles)(void);
107 };
108 extern const struct storage_driver BUNDLE_STORAGE;
109 #endif
110 /** @} */
111 /** @} */