• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 
16 #include "scanner_info_helper.h"
17 #include "napi_scan_utils.h"
18 #include "scan_log.h"
19 
20 namespace OHOS::Scan {
21 
22 static constexpr const char *PARAM_SCANNERID = "scannerId";
23 static constexpr const char *PARAM_INFO_DISCOVERMODE = "discoveryMode";
24 static constexpr const char *PARAM_UNIQUE_ID = "uniqueId";
25 static constexpr const char *PARAM_MANUFACTURER = "manufacturer";
26 static constexpr const char *PARAM_MODEL = "model";
27 static constexpr const char *PARAM_INFO_DEVICENAME = "deviceName";
28 
29 static constexpr const char *PARAM_OLD_SCANNERID = "oldScannerId";
30 static constexpr const char *PARAM_INFO_SYNCMODE = "syncMode";
31 
MakeJsObject(napi_env env,const ScanDeviceInfo & info)32 napi_value ScannerInfoHelper::MakeJsObject(napi_env env, const ScanDeviceInfo &info)
33 {
34     napi_value jsObj = nullptr;
35     SCAN_CALL(env, napi_create_object(env, &jsObj));
36     NapiScanUtils::SetStringPropertyUtf8(env, jsObj, PARAM_SCANNERID, info.GetDeviceId());
37     NapiScanUtils::SetStringPropertyUtf8(env, jsObj, PARAM_INFO_DISCOVERMODE, info.GetDiscoverMode());
38     NapiScanUtils::SetStringPropertyUtf8(env, jsObj, PARAM_UNIQUE_ID, info.GetUniqueId());
39     NapiScanUtils::SetStringPropertyUtf8(env, jsObj, PARAM_MANUFACTURER, info.GetManufacturer());
40     NapiScanUtils::SetStringPropertyUtf8(env, jsObj, PARAM_MODEL, info.GetModel());
41     NapiScanUtils::SetStringPropertyUtf8(env, jsObj, PARAM_INFO_DEVICENAME, info.GetDeviceName());
42     return jsObj;
43 }
44 
MakeJsObject(napi_env env,const ScanDeviceInfoSync & info)45 napi_value ScannerInfoSyncHelper::MakeJsObject(napi_env env, const ScanDeviceInfoSync &info)
46 {
47     napi_value jsObj = nullptr;
48     SCAN_CALL(env, napi_create_object(env, &jsObj));
49     NapiScanUtils::SetStringPropertyUtf8(env, jsObj, PARAM_SCANNERID, info.GetDeviceId());
50     NapiScanUtils::SetStringPropertyUtf8(env, jsObj, PARAM_INFO_DISCOVERMODE, info.GetDiscoverMode());
51     NapiScanUtils::SetStringPropertyUtf8(env, jsObj, PARAM_UNIQUE_ID, info.GetUniqueId());
52     NapiScanUtils::SetStringPropertyUtf8(env, jsObj, PARAM_INFO_SYNCMODE, info.GetSyncMode());
53     if (info.GetSyncMode() == "update") {
54         NapiScanUtils::SetStringPropertyUtf8(env, jsObj, PARAM_OLD_SCANNERID, info.GetOldDeviceId());
55     }
56     return jsObj;
57 }
58 }  // namespace OHOS::Print
59