• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <map>
16 #include "oh_convertor.h"
17 #include "oh_preferences_err_code.h"
18 #include "preferences_errno.h"
19 
20 namespace OHOS::PreferencesNdk {
21 const std::map<int, int> ERROR_CODE_MAP = {
22     { OHOS::NativePreferences::E_OK, OH_Preferences_ErrCode::PREFERENCES_OK },
23     { OHOS::NativePreferences::E_INVALID_ARGS, OH_Preferences_ErrCode::PREFERENCES_ERROR_INVALID_PARAM },
24     { OHOS::NativePreferences::E_KEY_EMPTY, OH_Preferences_ErrCode::PREFERENCES_ERROR_INVALID_PARAM },
25     { OHOS::NativePreferences::E_KEY_EXCEED_MAX_LENGTH, OH_Preferences_ErrCode::PREFERENCES_ERROR_INVALID_PARAM },
26     { OHOS::NativePreferences::E_VALUE_EXCEED_MAX_LENGTH, OH_Preferences_ErrCode::PREFERENCES_ERROR_INVALID_PARAM },
27     { OHOS::NativePreferences::E_NOT_SUPPORTED, OH_Preferences_ErrCode::PREFERENCES_ERROR_NOT_SUPPORTED },
28     { OHOS::NativePreferences::E_DELETE_FILE_FAIL, OH_Preferences_ErrCode::PREFERENCES_ERROR_DELETE_FILE },
29     { OHOS::NativePreferences::E_GET_DATAOBSMGRCLIENT_FAIL,
30         OH_Preferences_ErrCode::PREFERENCES_ERROR_GET_DATAOBSMGRCLIENT },
31     { OHOS::NativePreferences::E_NO_DATA, OH_PREFERENCES_ERR_CODE_H::PREFERENCES_ERROR_KEY_NOT_FOUND },
32     { OHOS::NativePreferences::E_OBSERVER_RESERVE, OH_Preferences_ErrCode::PREFERENCES_OK }
33 };
34 
NativeErrToNdk(int nativeCode)35 int OHConvertor::NativeErrToNdk(int nativeCode)
36 {
37     auto iter = ERROR_CODE_MAP.find(nativeCode);
38     if (iter != ERROR_CODE_MAP.end()) {
39         return iter->second;
40     }
41     return PREFERENCES_ERROR_STORAGE;
42 }
43 
NdkStorageTypeToNative(const Preferences_StorageType & type)44 OHOS::NativePreferences::StorageType OHConvertor::NdkStorageTypeToNative(const Preferences_StorageType &type)
45 {
46     if (type == Preferences_StorageType::PREFERENCES_STORAGE_GSKV) {
47         return OHOS::NativePreferences::StorageType::GSKV;
48     }
49     return OHOS::NativePreferences::StorageType::XML;
50 }
51 }