Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / platform / Darwin / ConfigurationManagerImpl.cpp
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2018 Nest Labs, Inc.
5  *    All rights reserved.
6  *
7  *    Licensed under the Apache License, Version 2.0 (the "License");
8  *    you may not use this file except in compliance with the License.
9  *    You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *    Unless required by applicable law or agreed to in writing, software
14  *    distributed under the License is distributed on an "AS IS" BASIS,
15  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *    See the License for the specific language governing permissions and
17  *    limitations under the License.
18  */
19
20 /**
21  *    @file
22  *          Provides the implementation of the Device Layer ConfigurationManager object
23  *          for Darwin platforms.
24  */
25
26 #include <platform/internal/CHIPDeviceLayerInternal.h>
27
28 #include <core/CHIPVendorIdentifiers.hpp>
29 #include <platform/ConfigurationManager.h>
30 #include <platform/Darwin/PosixConfig.h>
31 #include <platform/internal/GenericConfigurationManagerImpl.cpp>
32
33 #include <support/CodeUtils.h>
34 #include <support/logging/CHIPLogging.h>
35
36 namespace chip {
37 namespace DeviceLayer {
38
39 using namespace ::chip::DeviceLayer::Internal;
40
41 /** Singleton instance of the ConfigurationManager implementation object.
42  */
43 ConfigurationManagerImpl ConfigurationManagerImpl::sInstance;
44
45 CHIP_ERROR ConfigurationManagerImpl::_Init()
46 {
47     CHIP_ERROR err;
48
49     // Initialize the generic implementation base class.
50     err = Internal::GenericConfigurationManagerImpl<ConfigurationManagerImpl>::_Init();
51     SuccessOrExit(err);
52
53 exit:
54     return err;
55 }
56
57 CHIP_ERROR ConfigurationManagerImpl::_GetPrimaryWiFiMACAddress(uint8_t * buf)
58 {
59     // TODO(#739): add WiFi support
60     return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
61 }
62
63 bool ConfigurationManagerImpl::_CanFactoryReset()
64 {
65     // TODO(#742): query the application to determine if factory reset is allowed.
66     return true;
67 }
68
69 void ConfigurationManagerImpl::_InitiateFactoryReset()
70 {
71     ChipLogError(DeviceLayer, "InitiateFactoryReset not implemented");
72 }
73
74 CHIP_ERROR ConfigurationManagerImpl::_ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value)
75 {
76     PosixConfig::Key configKey{ kConfigNamespace_ChipCounters, key };
77
78     CHIP_ERROR err = ReadConfigValue(configKey, value);
79     if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
80     {
81         err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;
82     }
83     return err;
84 }
85
86 CHIP_ERROR ConfigurationManagerImpl::_WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value)
87 {
88     PosixConfig::Key configKey{ kConfigNamespace_ChipCounters, key };
89     return WriteConfigValue(configKey, value);
90 }
91
92 } // namespace DeviceLayer
93 } // namespace chip