Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / platform / Tizen / CHIPLinuxStorage.h
1 /*
2  *
3  *    Copyright (c) 2020 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  *         This file defines a class for managing client application
22  *         user-editable settings. CHIP settings are partitioned into two
23  *         distinct areas:
24  *
25  *         1. immutable / durable: factory parameters (CHIP_DEFAULT_FACTORY_PATH)
26  *         2. mutable / ephemeral: user parameters (CHIP_DEFAULT_CONFIG_PATH/CHIP_DEFAULT_DATA_PATH)
27  *
28  *         The ephemeral partition should be erased during factory reset.
29  *
30  *         ChipLinuxStorage wraps the storage class ChipLinuxStorageIni with mutex.
31  *
32  */
33
34 #pragma once
35
36 #include <mutex>
37 #include <platform/Linux/CHIPLinuxStorageIni.h>
38
39 #ifndef FATCONFDIR
40 #define FATCONFDIR "/tmp"
41 #endif
42
43 #ifndef SYSCONFDIR
44 #define SYSCONFDIR "/tmp"
45 #endif
46
47 #ifndef LOCALSTATEDIR
48 #define LOCALSTATEDIR "/tmp"
49 #endif
50
51 #define CHIP_DEFAULT_FACTORY_PATH                                                                                                  \
52     FATCONFDIR "/"                                                                                                                 \
53                "chip_factory.ini"
54 #define CHIP_DEFAULT_CONFIG_PATH                                                                                                   \
55     SYSCONFDIR "/"                                                                                                                 \
56                "chip_config.ini"
57 #define CHIP_DEFAULT_DATA_PATH                                                                                                     \
58     LOCALSTATEDIR "/"                                                                                                              \
59                   "chip_counters.ini"
60
61 namespace chip {
62 namespace DeviceLayer {
63 namespace Internal {
64
65 class ChipLinuxStorage : private ChipLinuxStorageIni
66 {
67 public:
68     ChipLinuxStorage();
69     ~ChipLinuxStorage();
70
71     CHIP_ERROR Init(const char * configFile);
72     CHIP_ERROR ReadValue(const char * key, bool & val);
73     CHIP_ERROR ReadValue(const char * key, uint32_t & val);
74     CHIP_ERROR ReadValue(const char * key, uint64_t & val);
75     CHIP_ERROR ReadValueStr(const char * key, char * buf, size_t bufSize, size_t & outLen);
76     CHIP_ERROR ReadValueBin(const char * key, uint8_t * buf, size_t bufSize, size_t & outLen);
77     CHIP_ERROR WriteValue(const char * key, bool val);
78     CHIP_ERROR WriteValue(const char * key, uint32_t val);
79     CHIP_ERROR WriteValue(const char * key, uint64_t val);
80     CHIP_ERROR WriteValueStr(const char * key, const char * val);
81     CHIP_ERROR WriteValueBin(const char * key, const uint8_t * data, size_t dataLen);
82     CHIP_ERROR ClearValue(const char * key);
83     CHIP_ERROR ClearAll();
84     CHIP_ERROR Commit();
85     bool HasValue(const char * key);
86
87 private:
88     std::mutex mLock;
89     bool mDirty;
90     std::string mConfigPath;
91 };
92
93 } // namespace Internal
94 } // namespace DeviceLayer
95 } // namespace chip