Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / platform / Linux / KeyValueStoreManagerImpl.h
1 /*
2  *
3  *    Copyright (c) 2021 Project CHIP Authors
4  *    All rights reserved.
5  *
6  *    Licensed under the Apache License, Version 2.0 (the "License");
7  *    you may not use this file except in compliance with the License.
8  *    You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *    Unless required by applicable law or agreed to in writing, software
13  *    distributed under the License is distributed on an "AS IS" BASIS,
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *    See the License for the specific language governing permissions and
16  *    limitations under the License.
17  */
18
19 /**
20  *    @file
21  *          Platform-specific implementation of KVS for linux.
22  */
23
24 #pragma once
25
26 #include <platform/Linux/CHIPLinuxStorage.h>
27
28 namespace chip {
29 namespace DeviceLayer {
30 namespace PersistedStorage {
31
32 class KeyValueStoreManagerImpl : public KeyValueStoreManager
33 {
34 public:
35     /**
36      * @brief
37      * Initalize the KVS, must be called before using.
38      */
39     void Init(const char * file) { mStorage.Init(file); }
40
41     CHIP_ERROR _Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size = nullptr, size_t offset = 0);
42     CHIP_ERROR _Delete(const char * key);
43     CHIP_ERROR _Put(const char * key, const void * value, size_t value_size);
44
45 private:
46     DeviceLayer::Internal::ChipLinuxStorage mStorage;
47
48     // ===== Members for internal use by the following friends.
49     friend KeyValueStoreManager & KeyValueStoreMgr();
50     friend KeyValueStoreManagerImpl & KeyValueStoreMgrImpl();
51
52     static KeyValueStoreManagerImpl sInstance;
53 };
54
55 /**
56  * Returns the public interface of the KeyValueStoreManager singleton object.
57  *
58  * Chip applications should use this to access features of the KeyValueStoreManager object
59  * that are common to all platforms.
60  */
61 inline KeyValueStoreManager & KeyValueStoreMgr(void)
62 {
63     return KeyValueStoreManagerImpl::sInstance;
64 }
65
66 /**
67  * Returns the platform-specific implementation of the KeyValueStoreManager singleton object.
68  *
69  * Chip applications can use this to gain access to features of the KeyValueStoreManager
70  * that are specific to the ESP32 platform.
71  */
72 inline KeyValueStoreManagerImpl & KeyValueStoreMgrImpl(void)
73 {
74     return KeyValueStoreManagerImpl::sInstance;
75 }
76
77 } // namespace PersistedStorage
78 } // namespace DeviceLayer
79 } // namespace chip