ObjectStore.h
Go to the documentation of this file.
1 
22 #pragma once
23 
24 #include "Object.h"
25 #include "Error.h"
26 #include <Storage/Partition.h>
27 
28 namespace IFS
29 {
32 struct ObjRef {
33  uint32_t offset{0};
34  Object::ID id{0};
35  uint8_t handle{0};
36  uint8_t storenum{0};
37  uint8_t readCount{0};
38  uint8_t refCount{0};
39 
41  {
42  }
43 
44  ObjRef(const ObjRef& parent, Object::ID objID)
45  {
46  storenum = parent.storenum;
47  id = objID;
48  }
49 
50  ObjRef(uint32_t fileid)
51  {
52  storenum = fileid >> 16;
53  id = fileid & 0xffff;
54  }
55 
57  {
58  assert(refCount == 0);
59  }
60 
61  uint32_t fileID() const
62  {
63  return (storenum << 16) | id;
64  }
65 };
66 
69 struct FWObjDesc {
72 
74  {
75  }
76 
77  FWObjDesc(const ObjRef& objRef) : ref(objRef)
78  {
79  }
80 
81  FWObjDesc(uint32_t fileid) : ref(fileid)
82  {
83  }
84 
85  uint32_t nextOffset() const
86  {
87  return ref.offset + obj.sizeAligned();
88  }
89 
90  // Move to next object location
91  void next()
92  {
93  ref.offset = nextOffset();
94  ++ref.id;
95  }
96 
97  uint32_t contentOffset() const
98  {
99  return ref.offset + obj.contentOffset();
100  }
101 
102  uint32_t childTableOffset() const
103  {
104  return ref.offset + obj.childTableOffset();
105  }
106 };
107 
109 {
110 public:
111  virtual ~IObjectStore()
112  {
113  }
114 
118  virtual int initialise() = 0;
119 
124  virtual int mounted(const FWObjDesc& od) = 0;
125 
129  virtual bool isMounted() = 0;
130 
136  virtual int open(FWObjDesc& od) = 0;
137 
144  virtual int openChild(const FWObjDesc& parent, const FWObjDesc& child, FWObjDesc& od) = 0;
145 
151  virtual int readHeader(FWObjDesc& od) = 0;
152 
162  virtual int readChildHeader(const FWObjDesc& parent, FWObjDesc& child) = 0;
163 
171  virtual int readContent(const FWObjDesc& od, uint32_t offset, uint32_t size, void* buffer) = 0;
172 
178  virtual int close(FWObjDesc& od) = 0;
179 
180  virtual Storage::Partition& getPartition() = 0;
181 };
182 
183 } // namespace IFS
ObjRef(uint32_t fileid)
Definition: ObjectStore.h:50
Definition: ObjectStore.h:108
uint32_t contentOffset() const
Definition: ObjectStore.h:97
uint8_t storenum
Object store number.
Definition: ObjectStore.h:36
uint8_t readCount
For profiling.
Definition: ObjectStore.h:37
Object structure.
Definition: Object.h:137
size_t contentOffset() const
return offset to start of object content
Definition: Object.h:339
FWObjDesc(const ObjRef &objRef)
Definition: ObjectStore.h:77
Object obj
The object structure.
Definition: ObjectStore.h:70
uint8_t handle
SPIFFS object store requires handles.
Definition: ObjectStore.h:35
FWObjDesc(uint32_t fileid)
Definition: ObjectStore.h:81
ObjRef()
Definition: ObjectStore.h:40
ObjRef(const ObjRef &parent, Object::ID objID)
Definition: ObjectStore.h:44
Definition: DirectoryTemplate.h:36
uint32_t nextOffset() const
Definition: ObjectStore.h:85
uint32_t childTableOffset() const
Definition: Object.h:365
FWFS Object Descriptor.
Definition: ObjectStore.h:69
uint32_t childTableOffset() const
Definition: ObjectStore.h:102
gives the identity and location of an FWFS object
Definition: ObjectStore.h:32
Represents a flash partition.
Definition: Partition.h:77
~ObjRef()
Definition: ObjectStore.h:56
Object::ID id
Definition: ObjectStore.h:34
FWObjDesc()
Definition: ObjectStore.h:73
uint32_t offset
Offset from start of image.
Definition: ObjectStore.h:33
ObjRef ref
location
Definition: ObjectStore.h:71
virtual ~IObjectStore()
Definition: ObjectStore.h:111
uint32_t fileID() const
Definition: ObjectStore.h:61
uint8_t refCount
For testing open/close correctness.
Definition: ObjectStore.h:38
void next()
Definition: ObjectStore.h:91
uint32_t sizeAligned() const
Definition: Object.h:386