Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DM_HttpServer DM_USBHost
Dependents: lpc4088_displaymodule_emwin lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI ... more
Fork of DMSupport by
Registry.h
- Committer:
- embeddedartists
- Date:
- 2015-01-12
- Revision:
- 20:9df19da50290
- Child:
- 34:fc366bab393f
File content as of revision 20:9df19da50290:
/*
* Copyright 2014 Embedded Artists AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef REGISTRY_H
#define REGISTRY_H
#include "mbed.h"
#include "rtos.h"
#include "InternalEEPROM.h"
/**
* Example of using the Registry class:
*
* @code
* #include "mbed.h"
* #include "DMBoard.h"
*
* int main(void) {
* DMBoard* board = &DMBoard::instance();
* board->init();
* ...
* board->registry()
* }
* @endcode
*/
class Registry {
public:
enum RegistryError {
Ok = 0,
ReadOnlyError,
MemoryError,
EEPROMReadError,
EEPROMWriteError,
NoSuchKeyError,
KeyLenError,
ValueLenError,
InvalidPositionError,
RegistryFullError,
};
/** Get the only instance of the Registry
*
* @returns The Registry
*/
static Registry& instance()
{
static Registry singleton;
return singleton;
}
/** Loads all (if any) values from the internal EEPROM
*
* @returns
* Ok on success
* An error code on failure
*/
RegistryError load();
RegistryError setValue(const char* key, const char* val);
RegistryError getValue(const char* key, char** pVal);
RegistryError entryAt(int pos, char** pKey, char** pVal);
int numEntries() { return _numEntries; }
RegistryError registerListener();
/** Stores the registry in the internal EEPROM
*
* @returns
* Ok on success
* An error code on failure
*/
RegistryError store();
private:
enum Constants {
NumEntries = InternalEEPROM::EEPROM_NUM_PAGES,
EntryLen = 32,
EntrySize = 2*EntryLen,
};
typedef struct {
char key[EntryLen];
char val[EntryLen];
} reg_entry_t;
uint8_t* _data;
int _numEntries;
reg_entry_t* _entries;
bool _modified[NumEntries];
Mutex _mutex;
explicit Registry();
// hide copy constructor
Registry(const Registry&);
// hide assign operator
Registry& operator=(const Registry&);
~Registry();
RegistryError fromEEPROM();
RegistryError toEEPROM();
int find(const char* key);
};
#endif
