diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets index fe45b632df0a8f6d861a31bbd4fccef7ec29539f..cbf94592d4ad2c4be521bacbe46021c96aa2cc0a 100755 --- a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets @@ -13,10 +13,14 @@ * limitations under the License. */ +// [Start import_os_account] import { osAccount, BusinessError } from '@kit.BasicServicesKit'; +// [End import_os_account] import { router } from '@kit.ArkUI'; +// [Start get_account_manager] let osAccountMgr = osAccount.getAccountManager(); +// [End get_account_manager] @Entry @Component @@ -24,21 +28,26 @@ struct ManageDomainAccounts { @State message: string = 'Hello World'; private async domainAccountExists(): Promise { + // [Start domain_account_exists] let domainAccountInfo: osAccount.DomainAccountInfo = { accountName: 'testAccountName', domain: 'testDomain' } let isAccountExisted: boolean = await osAccount.DomainAccountManager.hasAccount(domainAccountInfo); + // [StartExclude domain_account_exists] console.log('domainAccount isAccountExisted:' + isAccountExisted); if(isAccountExisted) { this.message = 'Domain account already exists'; } else { this.message = 'Domain account does not exist'; } + // [EndExclude domain_account_exists] + // [End domain_account_exists] } private async createDomainAccount(): Promise { + // [Start create_domain_account] let domainInfo: osAccount.DomainAccountInfo = { domain: 'testDomain', accountName: 'testAccountName' @@ -49,15 +58,21 @@ struct ManageDomainAccounts { (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ console.log('createOsAccountForDomain err:' + JSON.stringify(err)); console.log('createOsAccountForDomain osAccountInfo:' + JSON.stringify(osAccountInfo)); + // [StartExclude create_domain_account] this.message = 'Account creation information: ' + JSON.stringify(osAccountInfo.localName); + // [EndExclude create_domain_account] }); } catch (e) { console.error('createOsAccountForDomain exception: ' + JSON.stringify(e)); + // [StartExclude create_domain_account] this.message = 'Account creation failed: ' + JSON.stringify(e); + // [EndExclude create_domain_account] } + // [End create_domain_account] } private async deleteDomainAccount(): Promise { + // [Start delete_domain_account] let domainInfo: osAccount.DomainAccountInfo = { domain: 'testDomain', accountName: 'testAccountName' @@ -67,25 +82,32 @@ struct ManageDomainAccounts { localId = await osAccountMgr.getOsAccountLocalIdForDomain(domainInfo); } catch (err) { console.error('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err)); + // [StartExclude delete_domain_account] this.message = 'Failed to get account deletion information: ' + JSON.stringify(err); + // [EndExclude delete_domain_account] } try { osAccountMgr.removeOsAccount(localId, (err: BusinessError)=>{ if (err) { console.log('removeOsAccount failed, error: ' + JSON.stringify(err)); + // [StartExclude delete_domain_account] this.message = 'Failed to delete account: ' + JSON.stringify(err); + // [EndExclude delete_domain_account] } else { console.log('removeOsAccount successfully'); + // [StartExclude delete_domain_account] this.message = 'Successfully deleted account'; + // [EndExclude delete_domain_account] } }); } catch (err) { console.error('removeOsAccount exception: ' + JSON.stringify(err)); } - + // [End delete_domain_account] } private async queryDomainAccount(): Promise { + // [Start get_domain_account_info] let options: osAccount.GetDomainAccountInfoOptions = { domain: 'testDomain', accountName: 'testAccountName' @@ -95,16 +117,23 @@ struct ManageDomainAccounts { (err: BusinessError, result: osAccount.DomainAccountInfo) => { if (err) { console.log('call getAccountInfo failed, error: ' + JSON.stringify(err)); + // [StartExclude get_domain_account_info] this.message = 'Query failed: ' + JSON.stringify(err); + // [EndExclude get_domain_account_info] } else { console.log('getAccountInfo result: ' + result); + // [StartExclude get_domain_account_info] this.message = 'Queried account information: ' + JSON.stringify(result.accountName); + // [EndExclude get_domain_account_info] } }); } catch (err) { console.error('getAccountInfo exception = ' + JSON.stringify(err)); + // [StartExclude get_domain_account_info] this.message = 'Failed to query account information: ' + JSON.stringify(err); + // [EndExclude get_domain_account_info] } + // [End get_domain_account_info] } build() { diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets index 8a74171a47d1cb37bc6ee0fc6600111ee4f0c0c6..49a59901e6c790752e95653b80b4b81ed9d52341 100755 --- a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets +++ b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets @@ -13,9 +13,13 @@ * limitations under the License. */ +// [Start import_os_account_01] import { osAccount, BusinessError } from '@kit.BasicServicesKit'; +// [End import_os_account_01] +// [Start get_account_manager_01] let accountManager = osAccount.getAccountManager(); +// [End get_account_manager_01] @Entry @Component @@ -24,47 +28,60 @@ struct ManageSystemAccounts { @State createLocalId: number = -1; private async createOsAccount(): Promise { + // [Start create_os_account] let name: string = 'Bob'; let type: osAccount.OsAccountType = osAccount.OsAccountType.NORMAL; accountManager.createOsAccount(name, type, (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ console.log('createOsAccount err:' + JSON.stringify(err)); console.log('createOsAccount osAccountInfo:' + JSON.stringify(osAccountInfo)); + // [StartExclude create_os_account] if (!err) { this.message = 'Account creation successful. Account name: ' + JSON.stringify(osAccountInfo.localName); this.createLocalId = osAccountInfo.localId; } else { this.message = 'Failed to create account: ' + JSON.stringify(err); } + // [EndExclude create_os_account] }); + // [End create_os_account] } private async findAllOsAccount(): Promise { + // [Start query_all_os_account] accountManager.queryAllCreatedOsAccounts((err: BusinessError, accountArr: osAccount.OsAccountInfo[])=>{ console.log('queryAllCreatedOsAccounts err:' + JSON.stringify(err)); console.log('queryAllCreatedOsAccounts accountArr:' + JSON.stringify(accountArr)); + // [StartExclude query_all_os_account] if (!err) { this.message = 'Query account successful. Account name:' + JSON.stringify(accountArr[0].localName); } else { this.message = 'Query account failed: ' + JSON.stringify(err); } + // [EndExclude query_all_os_account] }); + // [End query_all_os_account] } private async findOsAccount(): Promise { + // [Start query_id_os_account] let localId: number = 100; accountManager.queryOsAccountById(localId, (err: BusinessError, accountInfo: osAccount.OsAccountInfo)=>{ console.log('queryOsAccountById err:' + JSON.stringify(err)); console.log('queryOsAccountById accountInfo:' + JSON.stringify(accountInfo)); + // [StartExclude query_id_os_account] if (!err) { this.message = 'Query account successful. Account name for account 100: ' + JSON.stringify(accountInfo.localName); } else { this.message = 'Query account failed: ' + JSON.stringify(err); } + // [EndExclude query_id_os_account] }); + // [End query_id_os_account] } private async changeOsAccountHead(): Promise { + // [Start set_os_account_photo] let localId: number = 100; localId = this.createLocalId; let newPhoto: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+ @@ -74,19 +91,24 @@ struct ManageSystemAccounts { accountManager.setOsAccountProfilePhoto(localId, newPhoto, (err: BusinessError)=>{ console.log('setOsAccountProfilePhoto err:' + JSON.stringify(err)); + // [StartExclude set_os_account_photo] if(!err) { this.message = 'Successfully updated system account avatar' } else { this.message = 'Failed to update system account avatar: ' + JSON.stringify(err); } + // [EndExclude set_os_account_photo] }); + // [End set_os_account_photo] } private async changeOsAccountName(): Promise { + // [Start set_os_account_name] let localId: number = 100; localId = this.createLocalId; let newName: string = 'Tom'; accountManager.setOsAccountName(localId, newName, (err: BusinessError) => { + // [StartExclude set_os_account_name] if (err) { console.error('setOsAccountName failed, error: ' + JSON.stringify(err)); this.message = 'Failed to modify system account name: ' + JSON.stringify(err); @@ -94,13 +116,17 @@ struct ManageSystemAccounts { console.log('setOsAccountName successfully'); this.message = 'Successfully modified system account name'; } + // [EndExclude set_os_account_name] }); + // [End set_os_account_name] } private async activateOsAccount(): Promise { + // [Start activate_os_account] let localId: number = 101; localId = this.createLocalId; accountManager.activateOsAccount(localId, (err: BusinessError)=>{ + // [StartExclude activate_os_account] if (err) { console.error(`activateOsAccount failed, code is ${err.code}, message is ${err.message}`); this.message = 'Failed to activate system account: ' + err.code; @@ -108,13 +134,17 @@ struct ManageSystemAccounts { console.log('activateOsAccount successfully'); this.message = 'Successfully activated system account' } + // [EndExclude activate_os_account] }); + // [End activate_os_account] } private async deleteOsAccount(): Promise { + // [Start delete_os_account] let localId: number = 101; localId = this.createLocalId; accountManager.removeOsAccount(localId, (err: BusinessError)=>{ + // [StartExclude activate_os_account] if (err) { console.error('removeOsAccount failed, error: ' + JSON.stringify(err)); this.message = 'Failed to delete system account: ' + JSON.stringify(err); @@ -122,7 +152,9 @@ struct ManageSystemAccounts { console.log('removeOsAccount successfully'); this.message = 'Successfully deleted system account' } + // [EndExclude activate_os_account] }); + // [End activate_os_account] } build() { diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets index 3a5acacc09fcd027a548498c66ac124bf390312f..b28d403d69428724904bf35dda21fbb590bdcc1c 100755 --- a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets +++ b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets @@ -13,10 +13,14 @@ * limitations under the License. */ +// [Start import_os_account_02] import { osAccount } from '@kit.BasicServicesKit'; +// [End import_os_account_02] import { router } from '@kit.ArkUI'; +// [Start get_account_manager_02] let accountManager = osAccount.getAccountManager(); +// [End get_account_manager_02] @Entry @Component @@ -24,28 +28,38 @@ struct UseConstraintManagementSystemAccount { @State message: string = 'No work done'; private async setOsAccountConstraints(): Promise { + // [Start set_os_account_constraints] let localId: number = 100; let constraint: string[] = [ 'constraint.wifi.set' ]; try { accountManager.setOsAccountConstraints(localId, constraint, true); console.log('setOsAccountConstraints successfully'); + // [StartExclude set_os_account_constraints] this.message = 'Successfully set the constraint list for the specified system account'; + // [EndExclude set_os_account_constraints] } catch (err) { console.error('setOsAccountConstraints failed, error: ' + JSON.stringify(err)); + // [StartExclude set_os_account_constraints] this.message = 'Failed to set the constraint list for the specified system account'; + // [EndExclude set_os_account_constraints] } + // [End set_os_account_constraints] } private async isOsAccountConstraintEnabled(): Promise { + // [Start is_os_account_constraints_enabled] let localId: number = 100; let constraint: string = 'constraint.wifi.set'; let isEnabled: boolean = await accountManager.isOsAccountConstraintEnabled(localId, constraint); if (isEnabled) { // your business logic + // [StartExclude is_os_account_constraints_enabled] this.message = 'Set the constraint list for the specified system account'; } else { this.message = 'Can not set the constraint list for the specified system account'; } + // [EndExclude is_os_account_constraints_enabled] + // [End is_os_account_constraints_enabled] } build() { diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/build-profile.json5 index aea44a0d28aa56a4d432a4a3ce22fa622312e5ea..110bc2d681f63ac6ab8cc5c11e96073d41894d6a 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/build-profile.json5 +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/build-profile.json5 @@ -47,7 +47,7 @@ "x86_64", "armeabi-v7a" ] - } + }, }, "buildOptionSet": [ { diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/index.d.ts index ee23dfc10e8c3c5c7533a3eb1f136c195859ada9..27eb9617d25b96bff253c65e175409784697cd34 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/index.d.ts @@ -13,4 +13,6 @@ * limitations under the License. */ -export const add: (a: number, b: number) => number; \ No newline at end of file +// [Start hap_const_dynamic_import_native] +export const add: (a: number, b: number) => number; +// [End hap_const_dynamic_import_native] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/Calc.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/Calc.ets index 591ad6994e8a1151843d46a2dc078a1fdde9b44a..606453a50db5c26c26696742b3d97d43ade54552 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/Calc.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/Calc.ets @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start hap_const_dynamic_import_add] export function add(a: number, b: number): number { let c = a + b; console.info('DynamicImport I am a HAP, %d + %d = %d', a, b, c); return c; -} \ No newline at end of file +} +// [End hap_const_dynamic_import_add] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Index.ets index 6eacb0025008ddd888ac7b6e2462400070ef8b0d..1ba61845df6f9afc8e1d52adde501435eea6139c 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Index.ets @@ -70,6 +70,7 @@ struct Index { .fontSize(16) .onClick(() => { if (item === resourceToString($r('app.string.business_expansion_scenario'))) { + // [Start dynamic_load_har_module_reflect_call] import('harlibrary').then((ns: ESObject) => { ns.Calc.staticAdd(8, 9); // 调用静态成员函数staticAdd() let calc: ESObject = new ns.Calc(); // 实例化类Calc @@ -86,47 +87,65 @@ struct Index { calc1[methodName](14, 15); // 调用成员函数instanceAdd() ns[functionName](16, 17); // 调用全局方法addHarlibrary() }) + // [End dynamic_load_har_module_reflect_call] } else if (item === resourceToString($r('app.string.dynamic_import_HAR_name'))) { + // [Start const_dynamic_import_har_name] //HAP常量动态import HAR模块名 import('myhar').then((ns: ESObject) => { console.info(ns.add(3, 5)); }) + // [End const_dynamic_import_har_name] } else if (item === resourceToString($r('app.string.dynamic_import_HAR_path'))) { + // [Start const_dynamic_import_har_path] // HAP常量动态import HAR模块文件路径 import('myhar/Index').then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [End const_dynamic_import_har_path] } else if (item === resourceToString($r('app.string.dynamic_import_HSP_name'))) { + // [Start const_dynamic_import_hsp_name] // HAP常量动态import HSP模块名 import('myhsp').then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [End const_dynamic_import_hsp_name] } else if (item === resourceToString($r('app.string.dynamic_import_HSP_path'))) { + // [Start const_dynamic_import_hsp_path] // HAP常量动态import HSP模块名文件路径 import('myhsp/Index').then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [End const_dynamic_import_hsp_path] } else if (item === resourceToString($r('app.string.dynamic_import_remote_HAR_name'))) { + // [Start const_dynamic_import_crypto] // HAP常量动态import远程HAR模块名 import('@ohos/crypto-js').then((ns: ESObject) => { console.info('DynamicImport @ohos/crypto-js: ' + ns.CryptoJS.src); }); + // [End const_dynamic_import_crypto] } else if (item === resourceToString($r('app.string.dynamic_import_ohpm'))) { + // [Start const_dynamic_import_ohpm] // HAP常量动态import ohpm包 import('@ohos/hypium').then((ns: ESObject) => { console.info('DynamicImport @ohos/hypium: ', ns.TestType.FUNCTION.toString()); }); + // [End const_dynamic_import_ohpm] } else if (item === resourceToString($r('app.string.dynamic_import_file'))) { + // [Start hap_const_dynamic_import] // HAP常量动态import自己的单文件 import('../Calc').then((ns: ESObject) => { console.info(ns.add(3, 5)); }) + // [End hap_const_dynamic_import] } else if (item === resourceToString($r('app.string.dynamic_import_native'))) { + // [Start hap_const_dynamic_import_native_index] // HAP常量动态import自己的Native库 import('libentry.so').then((ns: ESObject) => { console.info('DynamicImport libnativeapi.so: ' + ns.default.add(2, 3)); }); + // [End hap_const_dynamic_import_native_index] } else if (item === resourceToString($r('app.string.dynamic_import_system_app'))) { + // [Start hap_const_dynamic_import_api] // HAP常量动态import加载API import('@system.app').then((ns: ESObject) => { ns.default.getInfo(); @@ -147,55 +166,73 @@ struct Index { ns.default.info(0x0000, 'testTag', '%{public}s', 'DynamicImport @ohos.hilog.'); hilog.info(0x000, 'testTag', '%{public}s', ns.default.LogLevel.DEBUG); }); + // [End hap_const_dynamic_import_api] } else if (item === resourceToString($r('app.string.dynamic_import_module_myhar'))) { + // [Start variable_dynamic_import] // 变量动态import其他模块myHar let harName = 'myhar'; import(harName).then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [StartExclude variable_dynamic_import] } else if (item === resourceToString($r('app.string.dynamic_import_module_file'))) { + // [EndExclude variable_dynamic_import] // 变量动态import本模块自己的单文件 let filePath = '../utils/Calc'; import(filePath).then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [End variable_dynamic_import] } else if (item === resourceToString($r('app.string.dynamic_import_HAR_name_variable'))) { + // [Start hap_variable_dynamic_import_har] // HAP变量动态import HAR模块名 let harPackageName = 'myhar'; import(harPackageName).then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [End hap_variable_dynamic_import_har] } else if (item === resourceToString($r('app.string.dynamic_import_HSP_name_variable'))) { + // [Start hap_variable_dynamic_import_hsp] // HAP变量动态import HSP模块名 let hspPackageName = 'myhsp'; import(hspPackageName).then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [End hap_variable_dynamic_import_hsp] } else if (item === resourceToString($r('app.string.dynamic_import_remote_HAR_name_variable'))) { + // [Start hap_variable_dynamic_import_har_crypto] // HAP变量动态import远程HAR模块名 let remoteHarPackageName = '@ohos/crypto-js'; import(remoteHarPackageName).then((ns: ESObject) => { console.info('DynamicImport @ohos/crypto-js: ' + ns.CryptoJS.src); }); + // [End hap_variable_dynamic_import_har_crypto] } else if (item === resourceToString($r('app.string.dynamic_import_ohpm_variable'))) { + // [Start hap_variable_dynamic_import_ohpm] // HAP变量动态import ohpm包 let ohpmPackageName = '@ohos/hypium'; import(ohpmPackageName).then((ns: ESObject) => { console.info('DynamicImport @ohos/hypium: ', ns.TestType.FUNCTION.toString()); }); + // [End hap_variable_dynamic_import_ohpm] } else if (item === resourceToString($r('app.string.dynamic_import_file_variable'))) { + // [Start hap_variable_dynamic_import_calc] // HAP变量动态import自己的单文件 let calcFilePath = '../Calc'; import(calcFilePath).then((ns: ESObject) => { console.info(ns.add(3, 5)); }); + // [End hap_variable_dynamic_import_calc] } else if (item === resourceToString($r('app.string.dynamic_import_native_variable'))) { + // [Start hap_variable_dynamic_import_native] // HAP变量动态import自己的Native库 let soName = 'libentry.so'; import(soName).then((ns: ESObject) => { console.info('DynamicImport libnativeapi.so: ' + ns.default.add(2, 3)); }); + // [End hap_variable_dynamic_import_native] } else if (item === resourceToString($r('app.string.dynamic_import_system_app_variable'))) { + // [Start hap_variable_dynamic_import_api] // HAP变量动态import加载API let packageName = '@system.app'; import(packageName).then((ns: ESObject) => { @@ -219,11 +256,14 @@ struct Index { import(packageName).then((ns: ESObject) => { ns.default.info(0x0000, 'testTag', '%{public}s', 'DynamicImport @ohos.hilog.'); }) + // [End hap_variable_dynamic_import_api] } else if (item === resourceToString($r('app.string.dynamic_import_HAR'))) { + // [Start hap_variable_dynamic_import_har1] let harName = 'har1'; import(harName).then((ns: ESObject) => { console.info('DynamicImport addHar1 4 + 5 = ' + ns.addHar1(4, 5)); }); + // [End hap_variable_dynamic_import_har1] } }) } diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/Index.ets index a5b03f1cd6c3ae32d58a2ba56c657b44ce0a78ac..e0345cb61d753496fc4de59a5e8d08c67e695009 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/Index.ets @@ -15,4 +15,6 @@ export { MainPage } from './src/main/ets/components/MainPage'; +// [Start export_add_har1] export { addHar1 } from './src/main/ets/utils/Calc'; +// [End export_add_har1] diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/utils/Calc.ets index 91ff3de13565e5b0a6c883ec691a8befcbb24712..7cc5071259ad983e4117ffe8cfbc4be961d60b17 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/utils/Calc.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/utils/Calc.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start function_add_har1] export function addHar1(a: number, b: number): number { let c = a + b; console.info('DynamicImport I am har1, %d + %d = %d', a, b, c); @@ -22,4 +23,5 @@ export function addHar1(a: number, b: number): number { console.info('DynamicImport addHar2 4 + 5 = ' + ns.addHar2(4, 5)); }); return c; -} \ No newline at end of file +} +// [End function_add_har1] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/Index.ets index 2a6f2ea192c7f21c0440bb861a02d807a5b7e4f4..248cad021d26d33980fb855f19ae7cba8ea59f2b 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/Index.ets @@ -15,4 +15,6 @@ export { MainPage } from './src/main/ets/components/MainPage'; +// [Start export_add_har2] export { addHar2 } from './src/main/ets/utils/Calc' +// [End export_add_har2] diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/utils/Calc.ets index d32c0d2b4b44acb46735adf36c9baef6200dab20..13cc0fe20a97836f97a2dca506a6d7705a088812 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/utils/Calc.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/utils/Calc.ets @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start function_add_har2] export function addHar2(a: number, b: number): number { let c = a + b; console.info('DynamicImport I am har2, %d + %d = %d', a, b, c); return c; -} \ No newline at end of file +} +// [End function_add_har2] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/Index.ets index e73569c227acc4ed4e1011c1421adfa0371b337b..ce8819144b46a1b13a52e65fac1975f790871cd7 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/Index.ets @@ -15,4 +15,6 @@ export { MainPage } from './src/main/ets/components/MainPage' -export { Calc, addHarlibrary } from './src/main/ets/utils/Calc' \ No newline at end of file +// [Start module_members_export] +export { Calc, addHarlibrary } from './src/main/ets/utils/Calc' +// [End module_members_export] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/utils/Calc.ets index 6e327fcdbe8c38c8b557e6cf7c3fdec3607377e4..022d3ccd82446561cd408adad7c1764bf76dd418 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/utils/Calc.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/utils/Calc.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start dynamic_call_add] export class Calc { public static staticAdd(a: number, b: number): number { let c = a + b; @@ -31,4 +32,5 @@ export function addHarlibrary(a: number, b: number): number { let c = a + b; console.info('DynamicImport I am harlibrary in addHarlibrary, %d + %d = %d', a, b, c); return c; -} \ No newline at end of file +} +// [End dynamic_call_add] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/Index.ets index 4cb302f7806f6f036712fd300917cf92cc4134ed..04b0c498128340aa4d66aca8ab42b5fc575c14f0 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/Index.ets @@ -15,8 +15,10 @@ export { MainPage } from './src/main/ets/components/MainPage' +// [Start const_dynamic_import_har] export function add(a: number, b: number): number { let c = a + b; console.info('DynamicImport I am a HAR, %d + %d = %d', a, b, c); return c; -} \ No newline at end of file +} +// [End const_dynamic_import_har] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/Index.ets index 4e5d57e9a1e475627b975e874ab1740d657d8d17..5166a860b1b3511064990194a968074e21ef5244 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/Index.ets @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start const_dynamic_import_hsp] export function add(a: number, b: number): number { let c = a + b; console.info('DynamicImport I am a HSP, %d + %d = %d', a, b, c); return c; -} \ No newline at end of file +} +// [End const_dynamic_import_hsp] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/build-profile.json5 index cd2a037ba51404d6eec4ac5fbe92037cde2eb048..472a9260420cea77f8d432f967a475169d6cea87 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/build-profile.json5 +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/build-profile.json5 @@ -15,6 +15,7 @@ { "apiType": "stageMode", + // [Start hap_load_native_dependence_01] "buildOption": { "arkOptions": { "runtimeOnly": { @@ -23,6 +24,7 @@ ] } }, + // [StartExclude hap_load_native_dependence_01] "externalNativeOptions": { "path": "./src/main/cpp/CMakeLists.txt", "arguments": "", @@ -32,8 +34,10 @@ "x86_64", "armeabi-v7a" ] - } + }, + // [EndExclude hap_load_native_dependence_01] }, + // [End hap_load_native_dependence_01] "buildOptionSet": [ { "name": "release", diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/oh-package.json5 index 16d8311f8d087adc540a27323b460dded7358b13..d11c699914c5da1f6f69880a2bbcc07a1f26de71 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/oh-package.json5 +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/oh-package.json5 @@ -20,7 +20,9 @@ "main": "", "author": "", "license": "", + // [Start hap_load_native_dependence] "dependencies": { "libentry.so": "file:./src/main/cpp/types/libentry" - } + }, + // [End hap_load_native_dependence] } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/index.d.ts index ee23dfc10e8c3c5c7533a3eb1f136c195859ada9..0069b64ba2422995f2a96e701ec78bd063c26d64 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/index.d.ts @@ -13,4 +13,6 @@ * limitations under the License. */ -export const add: (a: number, b: number) => number; \ No newline at end of file +// [Start hap_load_native] +export const add: (a: number, b: number) => number; +// [End hap_load_native] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/pages/Index.ets index 82e54f7fe6437b37ce3118ba5ff7bf7f112dd086..169d519a7c4425b187148d5b091ce29c37c7f9d2 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/pages/Index.ets @@ -24,9 +24,11 @@ struct Index { .width('50%') .margin({ bottom: 3 }) .onClick(() => { + // [Start hap_load_system_module] //HAP加载系统库模块 let hilog: ESObject = loadNativeModule('@ohos.hilog'); hilog.info(0, 'testTag', 'loadNativeModule ohos.hilog success'); + // [End hap_load_system_module] this.message = 'loadNativeModule ohos.hilog success' }) @@ -34,9 +36,11 @@ struct Index { .width('50%') .margin({ bottom: 3 }) .onClick(() => { + // [Start load_native_module_libentry] //HAP加载Native库 let module: ESObject = loadNativeModule('libentry.so'); let sum: number = module.add(1, 2); + // [End load_native_module_libentry] this.message = 'loadNativeModule libentry.so success result: ' + sum.toString(); }) Text(this.message) diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A.ets index f0961f349aecf97460e15ac863382e58d8a2a1bc..b26b2ae4786ceae9c5fad9e8e9a52fa97748b557 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A.ets @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start export_variable_a] import { c } from './B'; console.info(c); +// [End export_variable_a] -export { c }; \ No newline at end of file +export { c }; diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A_ns.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A_ns.ets index 109e5bb9e12cb7bb4e57716b5f8b6cbb87366cc0..4928cba69da43798c536046b6110d12cd07419b1 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A_ns.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A_ns.ets @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start export_variable_a_ns] import * as ns from './B'; console.info(ns.c); +// [End export_variable_a_ns] export { ns }; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/B.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/B.ets index 7db34e2051a952dca1407bd7360194e0d922f40c..4a67139893e0bb4992088dce946d7c82d846e3e8 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/B.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/B.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start export_variable_b] import lazy { c } from './C'; // 从'C'内获取c对象,标记为延迟加载 -export { c }; \ No newline at end of file +export { c }; +// [End export_variable_b] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/C.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/C.ets index 8fd891992df1365fb1e7b0491137be2d6af4c4b5..0e13c989d5b8f13b8082abfcbc0c24f06dd73491 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/C.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/C.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start export_variable_c] let c = 'c'; -export { c }; \ No newline at end of file +export { c }; +// [End export_variable_c] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/main.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/main.ets index 24e9cd4a0a6613cbdebfb9b0a6b7df9537c57f93..31fe7cfc716a1a936e3a93b758596c4a53d79c8e 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/main.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/main.ets @@ -13,17 +13,28 @@ * limitations under the License. */ +// [Start import_module] +// [Start import_lazy_module] import lazy { a } from './mod1'; // 'mod1' 未执行 +// [StartExclude import_lazy_module] import { c } from './mod2'; // 'mod2' 执行 +// [EndExclude import_lazy_module] import { b } from './mod1'; // 'mod1' 执行 import { hilog } from '@kit.PerformanceAnalysisKit'; +// [End import_lazy_module] +// [End import_module] + +// [Start main_running_info] console.info('main executed'); while (false) { let xx = a; + // [StartExclude main_running_info] let xy = b; let xz = c; + // [EndExclude main_running_info] } +// [End main_running_info] @Entry @Component diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod1.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod1.ets index 155a9f710cc3a3b119b3dcd880afebcc8de039ab..520baeafa3141c7677697bc0e0d82f5949e1f612 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod1.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod1.ets @@ -13,10 +13,12 @@ * limitations under the License. */ +// [Start export_module_variable_01] export let a = 'mod1 a executed'; console.info(a); export let b = 'mod1 b executed'; -console.info(b); \ No newline at end of file +console.info(b); +// [End export_module_variable_01] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod2.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod2.ets index 0fa63554af43423f62a03a28bbc65ac810cf8487..bab31537ac4767071e97d06e2cf5cd487db70adf 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod2.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod2.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start export_module_variable_02] export let c = 'mod2 c executed'; -console.info(c); \ No newline at end of file +console.info(c); +// [End export_module_variable_02] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/module.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/module.ets index 8c53919574f65a6bcbb1ed81fb35ba98d2e6c287..77afe81b29fc135ba68bdf81d4e3e23a62f8b176 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/module.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/module.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start import_global_module_data] export let data = 'data from module'; -globalThis.someGlobalVar = 100; \ No newline at end of file +globalThis.someGlobalVar = 100; +// [End import_global_module_data] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleUseGlobalVar.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleUseGlobalVar.ets index 1a27e4033f44c61dd0d478a98578118bc1c1d86a..b726221ea2d0e54934b0d82071ac5ecf76fce14d 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleUseGlobalVar.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleUseGlobalVar.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start import_global_module_data] +// [Start lazy_import_global_module_data] import lazy { data } from './module'; import lazy { dataOptimize, initialize } from './moduleOptimize'; @@ -25,6 +27,7 @@ struct moduleUseGlobalVar { build() { Column() { Row() { + // [StartExclude lazy_import_global_module_data] Button('LazyImportSideEffect') .width('40%') .height(30) @@ -33,6 +36,7 @@ struct moduleUseGlobalVar { this.message1 = 'SideEffect: ' + globalThis.someGlobalVar; console.log(data); // 使用到module模块的变量,此时module模块执行,someGlobalVar的值变为100 }) + // [EndExclude lazy_import_global_module_data] Divider() .vertical(true) .margin({ left: 8, right: 8 }) @@ -66,4 +70,6 @@ struct moduleUseGlobalVar { .height('100%') .width('100%') } -} \ No newline at end of file +} +// [End lazy_import_global_module_data] +// [End import_global_module_data] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/main.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/main.ets index 08dd8307b56d379a85d5d6123fa4f19a5ae5a5cc..e000c0c023b5ad1182418ca77e83c3d9212a8a56 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/main.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/main.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start import_change_global_var] import { data1 } from './module'; // 将全局变量someGlobalVar的值改为100 import { data2 } from './sideEffectModule'; // 又将全局变量someGlobalVar的值改为200 import { useGlobalVar } from './moduleUseGlobalVar'; @@ -24,6 +25,7 @@ function maybeNotCalledAtAll() { console.log(data1); console.log(data2); } +// [End import_change_global_var] function maybeNotCalledAtAllOptimize() { console.log(dataOptimize1); diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/module.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/module.ets index 0b9edc98a191c7def3160454c9fac5b78d8675a5..78c9caab64651ec67f1edfaa3218bbf684010c83 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/module.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/module.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start export_change_global_data_100] export let data1 = 'data from module'; -globalThis.someGlobalVar = 100; // 改变了全局状态 \ No newline at end of file +globalThis.someGlobalVar = 100; // 改变了全局状态 +// [End export_change_global_data_100] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVar.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVar.ets index 784d4c1c31765a9653b8bc83b6054cb2c23efd06..91c18c7516e5c64b92d3519fe94878b1a83d4189 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVar.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVar.ets @@ -13,9 +13,11 @@ * limitations under the License. */ +// [Start export_change_some_global_var] import { data1 } from './module'; // 此时可能预期全局变量someGlobalVar的值为100 export function useGlobalVar() { console.log(data1); console.log(globalThis.someGlobalVar); // 此时由于main.ets中加载了sideEffectModule模块,someGlobalVar的值已经被改为200 -} \ No newline at end of file +} +// [End export_change_some_global_var] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModule.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModule.ets index a101beca7bcdd7787a57f88cdd59d44af94744a7..1f401a0dfdccf84e16662d7bd38a18daa3ae29f8 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModule.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModule.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start export_change_global_data_200] export let data2 = 'data from side effect module'; -globalThis.someGlobalVar = 200; // 也变了全局状态 \ No newline at end of file +globalThis.someGlobalVar = 200; // 也变了全局状态 +// [End export_change_global_data_200] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/Index.ets index 3393ab0ce064a143bfaa5a00f2f239bc8a26846f..bd12a8a0a2886136879620db995e1c1bdb31d537 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/Index.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/Index.ets @@ -16,6 +16,7 @@ import { data } from './module'; // 将AppStorage中的SomeAppStorageVar改为200 import { dataOptimize } from './moduleOptimize'; +// [Start set_app_storage_var_200] @Entry @Component struct Index { @@ -59,6 +60,7 @@ struct Index { function maybeNotCalledAtAll() { console.log(data); } +// [End set_app_storage_var_200] function maybeNotCalledAtAllOptimize() { console.log(dataOptimize); diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/module.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/module.ets index f8f18ff872c35ebc439ec8c454926a4b6db618e3..8d84ffea4937a5161a0840123a26f27b6459e53f 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/module.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/module.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +// [Start set_app_storage_var] export let data = 'data from module'; -AppStorage.setOrCreate('SomeAppStorageVar1', 200); // 修改应用全局的UI状态 \ No newline at end of file +AppStorage.setOrCreate('SomeAppStorageVar1', 200); // 修改应用全局的UI状态 +// [End set_app_storage_var] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/a.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/a.ets index 5f4ebc64d3ee535c5cb7e070082d37b79c9b22cb..2d5fc12b0819cc5ea08d1b49435f701386dab24a 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/a.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/a.ets @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start module_cycle_dependence_a] import { b } from './b'; console.log('Module A: ', b); -export const a = 'A'; \ No newline at end of file +export const a = 'A'; +// [End module_cycle_dependence_a] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/b.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/b.ets index 95cb78fa443941dd6316118c51582d994c541bd5..106641288af9a5e5fe0fb47e006d1f2f50124bc7 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/b.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/b.ets @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start module_cycle_dependence_b] import { a } from './a'; console.log('Module B: ', a); -export const b = 'B'; \ No newline at end of file +export const b = 'B'; +// [End module_cycle_dependence_b] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/main.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/main.ets index 3dc293c62260fc2c2eb54eb39b59457da69abdbf..5a06290dd99809176464a385cf826c600b961725 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/main.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/main.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start call_modify_array_prototype_include] import { hilog } from '@kit.PerformanceAnalysisKit'; function resourceToString(resource: Resource) { @@ -70,4 +71,5 @@ struct main { .height('100%') .width('100%') } -} \ No newline at end of file +} +// [End call_modify_array_prototype_include] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/modifyPrototype.ts b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/modifyPrototype.ts index 86a995366ad31acc10cffc37b054c085f797d8bc..e67a9730726c1de2fc16c23abd5786c58bfb2943 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/modifyPrototype.ts +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/modifyPrototype.ts @@ -13,8 +13,10 @@ * limitations under the License. */ +// [Start array_prototype_include] export let data = 'data from modifyPrototype'; Array.prototype.includes = function (value) { return this.indexOf(value) == -1; }; +// [End array_prototype_include] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/main.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/main.ets index 696f15d26f1a8424b562788a023851e20f4d8e00..d327b4e0df14c133ba8fed5008dc9d68347b69ce 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/main.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/main.ets @@ -13,9 +13,11 @@ * limitations under the License. */ +// [Start import_put_console_log] import { data } from './topCodeModule'; // 导入时,module.ets中的console.log会执行,产生输出。 import { dataOptimizeOne } from './topCodeModuleOptimize'; import { dataOptimizeTwo } from './module'; +// [End import_put_console_log] @Entry @Component diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/module.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/module.ets index db345a6e210e4f81fb0948f87e8896a5fd9818fd..d83291a9749632fe4fed48fec4b3e90ca3097958 100755 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/module.ets +++ b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/module.ets @@ -13,8 +13,12 @@ * limitations under the License. */ +// [Start module_load_directly] export function initialize() { console.log('Module loaded!'); } +// [End module_load_directly] +// [Start module_load_optimize] export const dataOptimizeTwo = 1; +// [End module_load_optimize] diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/callback.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/callback.cpp index 1efb7bb64304a191872801990808bde21f08a0ea..a8f6b91fab1083322638a4df17c076a6451905e6 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/callback.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/callback.cpp @@ -15,6 +15,7 @@ #include "napi/native_api.h" +// [Start napi_create_queue_async_work] static constexpr int INT_ARGS_2 = 2; // 入参索引 struct CallbackData { @@ -24,12 +25,16 @@ struct CallbackData { double result = 0; }; +// [StartExclude napi_create_queue_async_work] +// [Start napi_async_first_call_back_work] static void ExecuteCB(napi_env env, void *data) { CallbackData *callbackData = reinterpret_cast(data); callbackData->result = callbackData->args[0] + callbackData->args[1]; } +// [End napi_async_first_call_back_work] +// [Start napi_async_second_call_back_work] static void CompleteCB(napi_env env, napi_status status, void *data) { CallbackData *callbackData = reinterpret_cast(data); @@ -47,6 +52,8 @@ static void CompleteCB(napi_env env, napi_status status, void *data) napi_delete_async_work(env, callbackData->asyncWork); delete callbackData; } +// [End napi_async_second_call_back_work] +// [EndExclude napi_create_queue_async_work] napi_value AsyncWork(napi_env env, napi_callback_info info) { @@ -68,7 +75,9 @@ napi_value AsyncWork(napi_env env, napi_callback_info info) napi_queue_async_work(env, asyncContext->asyncWork); return nullptr; } +// [End napi_create_queue_async_work] +// [Start napi_value_init] // 模块初始化 static napi_value Init(napi_env env, napi_value exports) { @@ -78,6 +87,7 @@ static napi_value Init(napi_env env, napi_value exports) napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); return exports; } +// [End napi_value_init] static napi_module demoModule = { .nm_version = 1, diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/napi_init.cpp index ea5f1cee10d72b39f017d5b722b7f7b86d446595..9ec67bd35e443d9eb0032d95bfa957d5fab7442b 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/napi_init.cpp @@ -15,6 +15,7 @@ #include "napi/native_api.h" +// [Start napi_create_async_work] struct CallbackData { napi_async_work asyncWork = nullptr; napi_deferred deferred = nullptr; @@ -23,12 +24,16 @@ struct CallbackData { double result = 0; }; +// [StartExclude napi_create_async_work] +// [Start napi_first_call_back_work] static void ExecuteCB(napi_env env, void *data) { CallbackData *callbackData = reinterpret_cast(data); callbackData->result = callbackData->args; } +// [End napi_first_call_back_work] +// [Start napi_second_call_back_main] static void CompleteCB(napi_env env, napi_status status, void *data) { CallbackData *callbackData = reinterpret_cast(data); @@ -43,6 +48,8 @@ static void CompleteCB(napi_env env, napi_status status, void *data) napi_delete_async_work(env, callbackData->asyncWork); delete callbackData; } +// [End napi_second_call_back_main] +// [EndExclude napi_create_async_work] static napi_value AsyncWork(napi_env env, napi_callback_info info) { @@ -67,6 +74,7 @@ static napi_value AsyncWork(napi_env env, napi_callback_info info) return promise; } +// [End napi_create_async_work] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/napi_init.cpp index 8ad42a351f37866a1e866f7893e294208f7c6894..bc1c616708d72f587cd7d5f551d40a7bf29169ab 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/napi_init.cpp @@ -16,6 +16,7 @@ #include #include "napi/native_api.h" +// [Start napi_create_array] static constexpr int INT_NUMBER_5 = 5; // 入参索引 static constexpr int INT_ARGS_2 = 2; // 入参索引 @@ -34,7 +35,9 @@ static napi_value CreateArray(napi_env env, napi_callback_info info) // 返回已创建好的数组 return jsArray; } +// [End napi_create_array] +// [Start napi_create_array_with_length] // 使用Node-API接口进行array相关开发 napi_create_array_with_length static napi_value CreateArrayWithLength(napi_env env, napi_callback_info info) { @@ -51,7 +54,9 @@ static napi_value CreateArrayWithLength(napi_env env, napi_callback_info info) // 返回数组 return jsArray; } +// [End napi_create_array_with_length] +// [Start napi_get_array_length] // 使用Node-API接口进行array相关开发 napi_get_array_length static napi_value GetArrayLength(napi_env env, napi_callback_info info) { @@ -73,7 +78,9 @@ static napi_value GetArrayLength(napi_env env, napi_callback_info info) napi_create_uint32(env, length, &result); return result; } +// [End napi_get_array_length] +// [Start napi_is_array] // 使用Node-API接口进行array相关开发 napi_is_array static napi_value IsArray(napi_env env, napi_callback_info info) { @@ -94,7 +101,9 @@ static napi_value IsArray(napi_env env, napi_callback_info info) return returnValue; } +// [End napi_is_array] +// [Start napi_set_element] // 使用Node-API接口进行array相关开发 napi_set_element static napi_value NapiSetElement(napi_env env, napi_callback_info info) { @@ -117,7 +126,9 @@ static napi_value NapiSetElement(napi_env env, napi_callback_info info) return nullptr; } +// [End napi_set_element] +// [Start napi_get_element] // 使用Node-API接口进行array相关开发 napi_get_element static napi_value NapiGetElement(napi_env env, napi_callback_info info) { @@ -134,7 +145,9 @@ static napi_value NapiGetElement(napi_env env, napi_callback_info info) return result; } +// [End napi_get_element] +// [Start napi_has_element] // 使用Node-API接口进行array相关开发 napi_has_element static napi_value NapiHasElement(napi_env env, napi_callback_info info) { @@ -153,7 +166,9 @@ static napi_value NapiHasElement(napi_env env, napi_callback_info info) napi_get_boolean(env, hasElement, &result); return result; } +// [End napi_has_element] +// [Start napi_delete_element] // 使用Node-API接口进行array相关开发 napi_delete_element static napi_value NapiDeleteElement(napi_env env, napi_callback_info info) { @@ -172,7 +187,9 @@ static napi_value NapiDeleteElement(napi_env env, napi_callback_info info) napi_get_boolean(env, deleted, &result); return result; } +// [End napi_delete_element] +// [Start napi_create_typed_array] // 使用Node-API接口进行array相关开发 napi_create_typedarray static napi_value CreateTypedArray(napi_env env, napi_callback_info info) { @@ -227,7 +244,9 @@ static napi_value CreateTypedArray(napi_env env, napi_callback_info info) napi_create_typedarray(env, arrayType, length, arrayBuffer, 0, &typedArray); return typedArray; } +// [End napi_create_typed_array] +// [Start napi_is_typed_array] // 使用Node-API接口进行array相关开发 napi_is_typedarray static napi_value IsTypedarray(napi_env env, napi_callback_info info) { @@ -248,7 +267,9 @@ static napi_value IsTypedarray(napi_env env, napi_callback_info info) return returnValue; } +// [End napi_is_typed_array] +// [Start napi_get_typed_array_info] // 使用Node-API接口进行array相关开发 napi_get_typedarray_info static napi_value GetTypedarrayInfo(napi_env env, napi_callback_info info) { @@ -298,7 +319,9 @@ static napi_value GetTypedarrayInfo(napi_env env, napi_callback_info info) } return result; } +// [End napi_get_typed_array_info] +// [Start napi_create_data_view] // 使用Node-API接口进行array相关开发 napi_create_dataview static napi_value CreateDataView(napi_env env, napi_callback_info info) { @@ -332,7 +355,9 @@ static napi_value CreateDataView(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_data_view] +// [Start napi_is_data_view] // 使用Node-API接口进行array相关开发 napi_is_dataview static napi_value IsDataView(napi_env env, napi_callback_info info) { @@ -354,7 +379,9 @@ static napi_value IsDataView(napi_env env, napi_callback_info info) return returnValue; } +// [End napi_is_data_view] +// [Start napi_get_data_view_info] // 使用Node-API接口进行array相关开发 napi_get_dataview_info static napi_value GetDataViewInfo(napi_env env, napi_callback_info info) { @@ -396,7 +423,9 @@ static napi_value GetDataViewInfo(napi_env env, napi_callback_info info) } return result; } +// [End napi_get_data_view_info] +// [Start change_use_napi_process] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) { @@ -431,6 +460,7 @@ static napi_value Init(napi_env env, napi_value exports) return exports; } EXTERN_C_END +// [End change_use_napi_process] static napi_module demoModule = { .nm_version = 1, diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/Index.d.ts index 029d6122165ce73a1ce2f474436527711aee401f..655f5726fddd983bb692c96b87b02df4a7b4572e 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,25 +13,42 @@ * limitations under the License. */ +// [Start napi_create_array_api] export const createArray: () => number[]; // 使用Node-API接口进行array相关开发 napi_create_array +// [End napi_create_array_api] +// [Start napi_create_array_with_length_api] export const createArrayWithLength: (length: number) => void[]; // 使用Node-API接口进行array相关开发 napi_create_array_with_length +// [End napi_create_array_with_length_api] +// [Start napi_get_array_length_api] export const getArrayLength: (arr: Array) => number | void; // 使用Node-API接口进行array相关开发 napi_get_array_length +// [End napi_get_array_length_api] +// [Start napi_is_array_api] export const isArray: (data: Array | T) => boolean | void; // 使用Node-API接口进行array相关开发 napi_is_array +// [End napi_is_array_api] +// [Start napi_set_element_api] export const napiSetElement: (arr: Array, index: number, value: T) => void; // 使用Node-API接口进行array相关开发 napi_set_element +// [End napi_set_element_api] +// [Start napi_get_element_api] export const napiGetElement: (arr: Array, index: number) => number | string | Object | boolean | undefined; // 使用Node-API接口进行array相关开发 napi_get_element +// [End napi_get_element_api] +// [Start napi_has_element_api] export const napiHasElement: (arr: Array, index: number) => boolean; // 使用Node-API接口进行array相关开发 napi_has_element +// [End napi_has_element_api] +// [Start napi_delete_element_api] export const napiDeleteElement: (arr: Array, index: number) => boolean; // 使用Node-API接口进行array相关开发 napi_delete_element +// [End napi_delete_element_api] +// [Start napi_create_typed_array_api] export const enum TypedArrayTypes { INT8_ARRAY = 0, UINT8_ARRAY, @@ -47,15 +64,26 @@ export const enum TypedArrayTypes { } export const createTypedArray: (type: TypedArrayTypes) => T; // 使用Node-API接口进行array相关开发 napi_create_typedarray +// [End napi_create_typed_array_api] +// [Start napi_is_typed_array_api] export const isTypedarray: (data: Object) => boolean | void; // 使用Node-API接口进行array相关开发 napi_is_typedarray +// [End napi_is_typed_array_api] +// [Start napi_get_typed_array_info_api] export const getTypedarrayInfo: (typeArray: T, infoType: number) => ArrayBuffer | number | boolean; // 使用Node-API接口进行array相关开发 napi_get_typedarray_info +// [End napi_get_typed_array_info_api] +// [Start napi_create_data_view_api] export const createDataView: (arraybuffer: ArrayBuffer) => DataView | void; // 使用Node-API接口进行array相关开发 napi_create_dataview +// [End napi_create_data_view_api] +// [Start napi_is_data_view_api] export const isDataView: (date: DataView | string) => boolean | void; // 使用Node-API接口进行array相关开发 napi_is_dataview +// [End napi_is_data_view_api] +// [Start napi_get_data_view_info_api] export const getDataViewInfo: (dataView: DataView, infoType: number) => ArrayBuffer | number; // 使用Node-API接口进行array相关开发 napi_get_dataview_info +// [End napi_get_data_view_info_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/pages/Index.ets index 5834bc1974d890398e6bea4b2e469ef9d5eebdac..c85ea228c169b9174c1f1b01c83b27c7bd507a8f 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/pages/Index.ets @@ -59,22 +59,29 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiCreateArray') { + // [Start ark_napi_create_array] //使用Node-API接口进行array相关开发 napi_create_array hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_array:%{public}s', JSON.stringify(testNapi.createArray())); + // [End ark_napi_create_array] this.result = 'napiCreateArraySuccess'; } else if (item === '2.napiCreateArrayWithLength') { + // [Start ark_napi_create_array_with_length] // 使用Node-API接口进行array相关开发 napi_create_array_with_length let array = testNapi.createArrayWithLength(6); hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_array_with_length:%{public}d', array.length); + // [End ark_napi_create_array_with_length] this.result = 'napiCreateArrayWithLengthSuccess'; } else if (item === '3.napiGetArrayLength') { + // [Start ark_napi_get_array_length] // 使用Node-API接口进行array相关开发 napi_get_array_length const arr = [0, 1, 2, 3, 4, 5]; hilog.info(0x0000, 'testTag', 'Test Node-API get_array_length:%{public}d', testNapi.getArrayLength(arr)); + // [End ark_napi_get_array_length] this.result = 'napiGetArrayLengthSuccess'; } else if (item === '4.napiIsArray') { + // [Start ark_napi_is_array] // 使用Node-API接口进行array相关开发 napi_is_array try { let value = new Array(1); @@ -83,12 +90,18 @@ struct Index { testNapi.isArray(value)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_array: %{public}s', testNapi.isArray(data)); + // [StartExclude ark_napi_is_array] this.result = 'napiIsArraySuccess'; + // [EndExclude ark_napi_is_array] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_array error: %{public}s', error.message); + // [StartExclude ark_napi_is_array] this.result = 'napiIsArrayFail'; + // [EndExclude ark_napi_is_array] } + // [End ark_napi_is_array] } else if (item === '5.napiSetElement') { + // [Start ark_napi_set_element] // 使用Node-API接口进行array相关开发 napi_set_element let arr = [10, 20, 30]; testNapi.napiSetElement(arr, 1, 'newElement'); @@ -108,8 +121,10 @@ struct Index { testNapi.napiSetElement(arr, 4, obj); let objAsString = JSON.stringify(arr[4]); hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_element arr[4]: %{public}s', objAsString); + // [End ark_napi_set_element] this.result = 'napiSetElementSuccess'; } else if (item === '6.napiGetElement') { + // [Start ark_napi_get_element] // 使用Node-API接口进行array相关开发 napi_get_element interface MyObject { first: number; @@ -133,16 +148,20 @@ struct Index { JSON.stringify(testNapi.napiGetElement(arr, 4))); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[null]: %{public}s', testNapi.napiGetElement(arr, 5)); + // [End ark_napi_get_element] this.result = 'napiGetElementSuccess'; } else if (item === '7.napiHasElement') { + // [Start ark_napi_has_element] // 使用Node-API接口进行array相关开发 napi_has_element let arr = [10, 'hello', null, 'world']; hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element arr[0]: %{public}s', testNapi.napiHasElement(arr, 0)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element arr[7]: %{public}s', testNapi.napiHasElement(arr, 7)); + // [End ark_napi_has_element] this.result = 'napiHasElementSuccess'; } else if (item === '8.napiDeleteElement') { + // [Start ark_napi_delete_element] // 使用Node-API接口进行array相关开发 napi_delete_element let arr = [10, 'hello', null, 'world']; hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element arr[0]: %{public}s', @@ -153,20 +172,28 @@ struct Index { testNapi.napiHasElement(arr, 0)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[0]: %{public}d', testNapi.napiGetElement(arr, 0)); + // [End ark_napi_delete_element] this.result = 'napiDeleteElementSuccess'; } else if (item === '9.napiCreateTypedArray') { + // [Start ark_napi_create_typed_array] // 使用Node-API接口进行array相关开发 napi_create_typedarray let typedArray = testNapi.createTypedArray(testNapi.TypedArrayTypes["INT8_ARRAY"]); if (typedArray instanceof Int8Array) { hilog.info(0x0000, 'testTag', ' Node-API napi_create_typedarray: Int8Array'); + // [StartExclude ark_napi_create_typed_array] this.result = 'napiCreateInt8ArraySuccess'; + // [EndExclude ark_napi_create_typed_array] } let uint8Array = testNapi.createTypedArray(testNapi.TypedArrayTypes["UINT8_ARRAY"]); if (uint8Array instanceof Uint8Array) { hilog.info(0x0000, 'testTag', ' Node-API napi_create_typedarray: Uint8Array'); + // [StartExclude ark_napi_create_typed_array] this.result = 'napiCreateUint8ArraySuccess'; + // [EndExclude ark_napi_create_typed_array] } + // [End ark_napi_create_typed_array] } else if (item === '10.napiIsTypedArray') { + // [Start ark_napi_is_typed_array] // 使用Node-API接口进行array相关开发 napi_is_typedarray try { let value = new Uint8Array([1, 2, 3, 4]); @@ -175,12 +202,18 @@ struct Index { testNapi.isTypedarray(value)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_typedarray: %{public}s', testNapi.isTypedarray(data)); + // [StartExclude ark_napi_is_typed_array] this.result = 'napiIsTypedArraySuccess'; + // [EndExclude ark_napi_is_typed_array] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_typedarray error: %{public}s', error.message); + // [StartExclude ark_napi_is_typed_array] this.result = 'napiIsTypedArrayFail'; + // [EndExclude ark_napi_is_typed_array] } + // [End ark_napi_is_typed_array] } else if (item === '11.napiGetTypedArrayInfo') { + // [Start ark_napi_get_typed_array_info] // 使用Node-API接口进行array相关开发 napi_get_typedarray_info // 传入TypedArray类型数据。TypedArray是一种用来描述二进制数据的类数组数据视图,没有直接构造器,可以用其子类构造类数组 // TypedArray的子类有: Int8Array Uint8Array Uint8ClampedArray Int16Array Int32Array等 @@ -202,15 +235,19 @@ struct Index { testNapi.getTypedarrayInfo(int8Array, InfoType.LENGTH)); hilog.info(0x0000, 'Node-API', 'get_typedarray_info_byte_offset: %{public}d', testNapi.getTypedarrayInfo(int8Array, InfoType.BYTE_OFFSET)); + // [End ark_napi_get_typed_array_info] this.result = 'napiGetTypedArrayInfoSuccess'; } else if (item === '12.napiCreateDataView') { + // [Start ark_napi_create_data_view] // 使用Node-API接口进行array相关开发 napi_create_dataview const arrayBuffer = new ArrayBuffer(16); const dataView = testNapi.createDataView(arrayBuffer) as DataView; hilog.info(0x0000, 'testTag', 'Test Node-API dataView:%{public}d', dataView.byteLength); hilog.info(0x0000, 'testTag', 'Test Node-API dataView第一个数据:%{public}d', dataView.getInt8(0)); + // [End ark_napi_create_data_view] this.result = 'napiCreateDataViewSuccess'; } else if (item === '13.napiIsDataView') { + // [Start ark_napi_is_data_view] // 使用Node-API接口进行array相关开发 napi_is_dataview try { let buffer = new ArrayBuffer(16); @@ -220,12 +257,18 @@ struct Index { testNapi.isDataView(dataView)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_dataview: %{public}s', testNapi.isDataView(data)); + // [StartExclude ark_napi_is_data_view] this.result = 'napiIsDataViewSuccess'; + // [EndExclude ark_napi_is_data_view] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_dataview error: %{public}s', error.message); + // [StartExclude ark_napi_is_data_view] this.result = 'napiIsDataViewFail'; + // [EndExclude ark_napi_is_data_view] } + // [End ark_napi_is_data_view] } else if (item === '14.napiGetDataViewInfo') { + // [Start ark_napi_get_data_view_info] // 使用Node-API接口进行array相关开发 napi_get_dataview_info // 创建一个ArrayBuffer let arrayBuffer = new Int8Array([2, 5]).buffer; @@ -248,6 +291,7 @@ struct Index { // 传入DataView类型参数查询DataView开始投影的数据缓冲区中的字节偏移量 hilog.info(0x0000, 'Node-API', 'get_dataview_info_byteoffset %{public}d', testNapi.getDataViewInfo(dataView, InfoType.BYTE_OFFSET)); + // [End ark_napi_get_data_view_info] this.result = 'napiGetDataViewInfoSuccess'; } }) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/napi_init.cpp index e7a8b5444a786210cb7f3871b953a175e7c43a3f..0371f4cf45ce542e5c06667d3c23c934e80949ff 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/napi_init.cpp @@ -15,6 +15,7 @@ #include "napi/native_api.h" +// [Start napi_is_arraybuffer] // napi_is_arraybuffer static napi_value IsArrayBuffer(napi_env env, napi_callback_info info) { @@ -34,7 +35,9 @@ static napi_value IsArrayBuffer(napi_env env, napi_callback_info info) napi_get_boolean(env, result, &returnValue); return returnValue; } +// [End napi_is_arraybuffer] +// [Start napi_get_arraybuffer_info] // napi_get_arraybuffer_info static napi_value GetArraybufferInfo(napi_env env, napi_callback_info info) { @@ -69,7 +72,9 @@ static napi_value GetArraybufferInfo(napi_env env, napi_callback_info info) napi_set_named_property(env, result, "buffer", bufferData); return result; } +// [End napi_get_arraybuffer_info] +// [Start napi_detach_arraybuffer] // napi_detach_arraybuffer static napi_value DetachedArraybuffer(napi_env env, napi_callback_info info) { @@ -98,7 +103,9 @@ static napi_value IsDetachedArraybuffer(napi_env env, napi_callback_info info) napi_get_boolean(env, result, &returnValue); return returnValue; } +// [End napi_detach_arraybuffer] +// [Start napi_create_arraybuffer] // napi_create_arraybuffer static napi_value CreateArraybuffer(napi_env env, napi_callback_info info) { @@ -121,6 +128,7 @@ static napi_value CreateArraybuffer(napi_env env, napi_callback_info info) // 返回ArrayBuffer return result; } +// [End napi_create_arraybuffer] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/Index.d.ts index 9f6763309a3f82247780debf8a994f9680283c51..3bcabf7866b12bc1291c2c8e68259966208b6934 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,17 +13,25 @@ * limitations under the License. */ +// [Start napi_is_arraybuffer_api] export const isArrayBuffer: (arrayBuffer: T) => boolean | void; // napi_is_arraybuffer +// [End napi_is_arraybuffer_api] +// [Start napi_get_arraybuffer_info_api] export class ArrayBufferInfo { byteLength: number; buffer: Object; } export const getArraybufferInfo: (data: ArrayBuffer) => ArrayBufferInfo | void; // napi_get_arraybuffer_info +// [End napi_get_arraybuffer_info_api] +// [Start napi_detach_arraybuffer_api] export const detachedArraybuffer: (buffer: ArrayBuffer) => ArrayBuffer; // napi_detach_arraybuffer export const isDetachedArraybuffer: (arrarBeffer: ArrayBuffer) => boolean; //napi_is_detached_arraybuffer +// [End napi_detach_arraybuffer_api] -export const createArraybuffer: (size: number) => ArrayBuffer; // napi_create_arraybuffer \ No newline at end of file +// [Start napi_create_arraybuffer_api] +export const createArraybuffer: (size: number) => ArrayBuffer; // napi_create_arraybuffer +// [End napi_create_arraybuffer_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/pages/Index.ets index 1256ffa0219532fc76d550fa94aed89ebb50bbdb..3b51abe806f5354d26375c1dbdcc9786614870d8 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/pages/Index.ets @@ -48,6 +48,7 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiIsArraybuffer') { + // [Start ark_napi_is_arraybuffer] // napi_is_arraybuffer try { let value = new ArrayBuffer(1); @@ -56,19 +57,27 @@ struct Index { testNapi.isArrayBuffer(value)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_arraybuffer: %{public}s', testNapi.isArrayBuffer(data)); + // [StartExclude ark_napi_is_arraybuffer] this.result = 'napiIsArraybufferSuccess'; + // [EndExclude ark_napi_is_arraybuffer] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_arraybuffer error: %{public}s', error.message); + // [StartExclude ark_napi_is_arraybuffer] this.result = 'napiIsArraybufferFail'; + // [EndExclude ark_napi_is_arraybuffer] } + // [End ark_napi_is_arraybuffer] } else if (item === '2.napiGetArraybufferInfo') { + // [Start ark_napi_get_arraybuffer_info // napi_get_arraybuffer_info const buffer = new ArrayBuffer(10); hilog.info(0x0000, 'testTag', 'Test Node-API get_arraybuffer_info:%{public}s ', JSON.stringify(testNapi.getArraybufferInfo(buffer))); + // [End ark_napi_get_arraybuffer_info] this.result = 'napiGetArraybufferInfoSuccess'; } else if (item === '3.napiDetachArraybuffer') { + // [Start ark_napi_detach_arraybuffer] // napi_detach_arraybuffer and napi_is_detached_arraybuffer try { const bufferArray = new ArrayBuffer(8); @@ -76,16 +85,23 @@ struct Index { testNapi.isDetachedArraybuffer(bufferArray)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_detached_arraybuffer two: %{public}s ', testNapi.isDetachedArraybuffer(testNapi.detachedArraybuffer(bufferArray))); + // [StartExclude ark_napi_detach_arraybuffer] this.result = 'napiDetachArraybufferSuccess'; + // [EndExclude ark_napi_detach_arraybuffer] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_detached_arraybuffer error: %{public}s', error.message); + // [StartExclude ark_napi_detach_arraybuffer] this.result = 'napiDetachArraybufferFail'; + // [EndExclude ark_napi_detach_arraybuffer] } + // [End ark_napi_detach_arraybuffer] } else if (item === '4.napiCreateArraybuffer') { + // [Start ark_napi_create_arraybuffer] // napi_create_arraybuffer hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_arraybuffer:%{public}s', testNapi.createArraybuffer(10).toString()); + // [End ark_napi_create_arraybuffer] this.result = 'napiCreateArraybufferSuccess'; } }) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/napi_init.cpp index ab8e421cfbb162c4cb8820bd8348d0b4ee6df768..e752683274f9874834d213a1ed4bd58aa24398b2 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/napi_init.cpp @@ -15,6 +15,7 @@ #include "napi/native_api.h" +// [Start napi_get_value_uint32] // napi_get_value_uint32 static napi_value GetValueUint32(napi_env env, napi_callback_info info) { @@ -36,7 +37,9 @@ static napi_value GetValueUint32(napi_env env, napi_callback_info info) napi_create_uint32(env, number, &result); return result; } +// [End napi_get_value_uint32] +// [Start napi_get_value_int32] // napi_get_value_int32 static napi_value GetValueInt32(napi_env env, napi_callback_info info) { @@ -56,7 +59,9 @@ static napi_value GetValueInt32(napi_env env, napi_callback_info info) napi_create_int32(env, result32, &napiResult32); return napiResult32; } +// [End napi_get_value_int32] +// [Start napi_get_value_int64] // napi_get_value_int64 static napi_value GetValueInt64(napi_env env, napi_callback_info info) { @@ -76,7 +81,9 @@ static napi_value GetValueInt64(napi_env env, napi_callback_info info) napi_create_int64(env, result64, &napiResult64); return napiResult64; } +// [End napi_get_value_int64] +// [Start napi_get_value_double] // napi_get_value_double static napi_value GetDouble(napi_env env, napi_callback_info info) { @@ -93,7 +100,9 @@ static napi_value GetDouble(napi_env env, napi_callback_info info) napi_create_double(env, value, &result); return result; } +// [End napi_get_value_double] +// [Start napi_create_int32] // napi_create_int32 static napi_value CreateInt32(napi_env env, napi_callback_info info) { @@ -109,7 +118,9 @@ static napi_value CreateInt32(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_int32] +// [Start napi_create_uint32] // napi_create_uint32 static napi_value CreateUInt32(napi_env env, napi_callback_info info) { @@ -127,7 +138,9 @@ static napi_value CreateUInt32(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_uint32] +// [Start napi_create_int64] // napi_create_int64 static napi_value CreateInt64(napi_env env, napi_callback_info info) { @@ -143,7 +156,9 @@ static napi_value CreateInt64(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_int64] +// [Start napi_create_double] // napi_create_double static napi_value CreateDouble(napi_env env, napi_callback_info info) { @@ -157,6 +172,7 @@ static napi_value CreateDouble(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_double] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/Index.d.ts index 920b4ba9aa69197d859f46ff8a3ff0debc49de91..1901dd8f17bf869c5e3357e4cbac52b5fbffebed 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,18 +13,34 @@ * limitations under the License. */ +// [Start napi_get_value_uint32_api] export const getValueUint32: (data: T) => number | void; // napi_get_value_uint32 +// [End napi_get_value_uint32_api] +// [Start napi_get_value_int32_api] export const getValueInt32: (value: number | string) => number | void; // napi_get_value_int32 +// [End napi_get_value_int32_api] +// [Start napi_get_value_int64_api] export const getValueInt64: (value: number | string) => number | void; // napi_get_value_int64 +// [End napi_get_value_int64_api] +// [Start napi_get_value_double_api] export const getDouble: (value: number | string) => number | void; // napi_get_value_double +// [End napi_get_value_double_api] +// [Start napi_create_int32_api] export const createInt32: () => number; // napi_create_int32 +// [End napi_create_int32_api] +// [Start napi_create_uint32_api] export const createUInt32: () => number; // napi_create_uint32 +// [End napi_create_uint32_api] +// [Start napi_create_int64_api] export const createInt64: () => number; // napi_create_int64 +// [End napi_create_int64_api] -export const createDouble: () => number; // napi_create_double \ No newline at end of file +// [Start napi_create_double_api] +export const createDouble: () => number; // napi_create_double +// [End napi_create_double_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/pages/Index.ets index 94a2a780f19dbe5e06483b92c45d25aa0e1bbf54..20023e52c93bdf946ccd234b71fc3af77213ccb4 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/pages/Index.ets @@ -52,6 +52,7 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiGetValueUint32') { + // [Start ark_napi_get_value_uint32] // napi_get_value_uint32 let value = testNapi.getValueUint32(111111111111); let data = testNapi.getValueUint32("sssss"); @@ -61,8 +62,10 @@ struct Index { // 传入uint32范围内的数字100时函数返回原数字 hilog.info(0x0000, 'Node-API', 'get_value_uint32_number %{public}d', testNapi.getValueUint32(100)); + // [End ark_napi_get_value_uint32] this.result = 'napiGetValueUint32Success'; } else if (item === '2.napiGetValueInt32') { + // [Start ark_napi_get_value_int32] // napi_get_value_int32 // 传入非数字“ss”时函数返回undefined hilog.info(0x0000, 'Node-API', 'get_value_int32_not_number %{public}s', testNapi.getValueInt32('ss')); @@ -80,8 +83,10 @@ struct Index { testNapi.getValueInt32(+Infinity)); hilog.info(0x0000, 'Node-API', 'get_value_int32_number_-Infinity %{public}d', testNapi.getValueInt32(-Infinity)); + // [End ark_napi_get_value_int32] this.result = 'napiGetValueInt32Success'; } else if (item === '3.napiGetValueInt64') { + // [Start ark_napi_get_value_int64] // napi_get_value_int64 // 输入不超过int64表示范围的数字,会返回该数字 hilog.info(0x0000, 'Node-API', 'get_value_int64_number %{public}d', testNapi.getValueInt64(80)); @@ -97,29 +102,40 @@ struct Index { testNapi.getValueInt64(+Infinity)); hilog.info(0x0000, 'Node-API', 'get_value_int64_number_-Infinity %{public}d', testNapi.getValueInt64(-Infinity)); + // [End ark_napi_get_value_int64] this.result = 'napiGetValueInt64Success'; } else if (item === '4.napiGetValueDouble') { + // [Start ark_napi_get_value_double] // napi_get_value_double // 输入数字,返回该数字 hilog.info(0x0000, 'Node-API', 'get_value_double_number %{public}d', testNapi.getDouble(80.885)); // 传入非数字,获得函数返回的值应为undefined hilog.info(0x0000, 'Node-API', 'get_value_double_not_number %{public}s', testNapi.getDouble('sAs')); + // [End ark_napi_get_value_double] this.result = 'napiGetValueDoubleSuccess'; } else if (item === '5.napiCreateInt32') { + // [Start ark_napi_create_int32] // napi_create_int32 hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_int32:' + testNapi.createInt32()); + // [End ark_napi_create_int32] this.result = 'napiCreateInt32Success'; } else if (item === '6.napiCreateUint32') { + // [Start ark_napi_create_uint32] // napi_create_uint32 hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_uint32: ' + testNapi.createUInt32()); + // [End ark_napi_create_uint32] this.result = 'napiCreateUint32Success'; } else if (item === '7.napiCreateInt64') { + // [Start ark_napi_create_int64] // napi_create_int64 hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_int64: ' + testNapi.createInt64()); + // [End ark_napi_create_int64] this.result = 'napiCreateInt64Success'; } else if (item === '8.napiCreateDouble') { + // [Start ark_napi_create_double] // napi_create_double hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_double: ' + testNapi.createDouble()); + // [End ark_napi_create_double] this.result = 'napiCreateDoubleSuccess'; } }) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/napi_init.cpp index 557e9203010ab377ac0ae5bf18f3f67434388565..0dc16e8bebe36cb06e4246d118b02851783dd24a 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/napi_init.cpp @@ -16,6 +16,7 @@ #include "napi/native_api.h" #include "hilog/log.h" +// [Start napi_create_bigint_int64] // napi_create_bigint_int64 static napi_value CreateBigintInt64t(napi_env env, napi_callback_info info) { @@ -26,7 +27,9 @@ static napi_value CreateBigintInt64t(napi_env env, napi_callback_info info) napi_create_bigint_int64(env, value, &returnValue); return returnValue; } +// [End napi_create_bigint_int64] +// [Start napi_create_bigint_uint64] // napi_create_bigint_uint64 static napi_value CreateBigintUint64t(napi_env env, napi_callback_info info) { @@ -37,7 +40,9 @@ static napi_value CreateBigintUint64t(napi_env env, napi_callback_info info) napi_create_bigint_uint64(env, value, &returnValue); return returnValue; } +// [End napi_create_bigint_uint64] +// [Start napi_create_bigint_words] // napi_create_bigint_words static napi_value CreateBigintWords(napi_env env, napi_callback_info info) { @@ -53,7 +58,9 @@ static napi_value CreateBigintWords(napi_env env, napi_callback_info info) } return returnValue; } +// [End napi_create_bigint_words] +// [Start napi_get_value_bigint_int64] // napi_get_value_bigint_int64 static napi_value GetValueBigintInt64t(napi_env env, napi_callback_info info) { @@ -74,7 +81,9 @@ static napi_value GetValueBigintInt64t(napi_env env, napi_callback_info info) napi_get_boolean(env, status == napi_ok, &returnValue); return returnValue; } +// [End napi_get_value_bigint_int64] +// [Start napi_get_value_bigint_uint64] // napi_get_value_bigint_uint64 static napi_value GetValueBigintUint64t(napi_env env, napi_callback_info info) { @@ -95,7 +104,9 @@ static napi_value GetValueBigintUint64t(napi_env env, napi_callback_info info) napi_get_boolean(env, status == napi_ok, &returnValue); return returnValue; } +// [End napi_get_value_bigint_uint64] +// [Start napi_get_value_bigint_words] // napi_get_value_bigint_words static napi_value GetValueBigintWords(napi_env env, napi_callback_info info) { @@ -121,6 +132,7 @@ static napi_value GetValueBigintWords(napi_env env, napi_callback_info info) napi_create_int32(env, signBit, &returnValue); return returnValue; } +// [End napi_get_value_bigint_words] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/Index.d.ts index c456f8f1c9d4f2895bf4bb923e0c445a3cfc37d4..9a160cff4e70a20d2556da8fe782d46ade730bde 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,14 +13,26 @@ * limitations under the License. */ +// [Start napi_create_bigint_int64_api] export const createBigintInt64t: () => bigint; // napi_create_bigint_int64 +// [End napi_create_bigint_int64_api] +// [Start napi_create_bigint_uint64_api] export const createBigintUint64t: () => bigint; // napi_create_bigint_uint64 +// [End napi_create_bigint_uint64_api] +// [Start napi_create_bigint_words_api] export const createBigintWords: () => bigint | void; // napi_create_bigint_words +// [End napi_create_bigint_words_api] +// [Start napi_get_value_bigint_int64_api] export const getValueBigintInt64t: (bigInt64: bigint) => boolean | void; // napi_get_value_bigint_int64 +// [End napi_get_value_bigint_int64_api] +// [Start napi_get_value_bigint_uint64_api] export const getValueBigintUint64t: (bigUint64: bigint) => boolean | void; // napi_get_value_bigint_uint64 +// [End napi_get_value_bigint_uint64_api] -export const getValueBigintWords: (bigIntWords: bigint) => bigint | void; // napi_get_value_bigint_words \ No newline at end of file +// [Start napi_get_value_bigint_words_api] +export const getValueBigintWords: (bigIntWords: bigint) => bigint | void; // napi_get_value_bigint_words +// [End napi_get_value_bigint_words_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/pages/Index.ets index 06d29338e9d9a75902100f91de76e377738d7e90..2da3dcf00cba72d736c8097bf2f17383edcd0fa4 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/pages/Index.ets @@ -52,48 +52,71 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiCreateBigintInt64') { + // [Start ark_napi_create_bigint_int64] // napi_create_bigint_int64 hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_int64: %{public}d', testNapi.createBigintInt64t()); + // [End ark_napi_create_bigint_int64] this.result = 'napiCreateBigintInt64Success'; } else if (item === '2.napiCreateBigintUint64') { + // [Start ark_napi_create_bigint_uint64] // napi_create_bigint_uint64 hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_uint64: %{public}d', testNapi.createBigintUint64t()); + // [End ark_napi_create_bigint_uint64] this.result = 'napiCreateBigintUint64Success'; } else if (item === '3.napiCreateBigintWords') { + // [Start ark_napi_create_bigint_words] // napi_create_bigint_words try { hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_words: %{public}d', testNapi.createBigintWords()); + // [StartExclude ark_napi_create_bigint_words] this.result = 'napiCreateBigintWordsSuccess'; + // [EndExclude ark_napi_create_bigint_words] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); + // [StartExclude ark_napi_create_bigint_words] this.result = 'napiCreateBigintWordsFail'; + // [EndExclude ark_napi_create_bigint_words] } + // [End ark_napi_create_bigint_words] } else if (item === '4.napiGetValueBigintInt64') { + // [Start ark_napi_get_value_bigint_int64] // napi_get_value_bigint_int64 let bigInt = BigInt(-5555555555555555); try { hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_int64: %{public}s', JSON.stringify(testNapi.getValueBigintInt64t(bigInt))); + // [StartExclude ark_napi_get_value_bigint_int64] this.result = 'napiGetValueBigintInt64Success'; + // [EndExclude ark_napi_get_value_bigint_int64] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); + // [StartExclude ark_napi_get_value_bigint_int64] this.result = 'napiGetValueBigintInt64Fail'; + // [EndExclude ark_napi_get_value_bigint_int64] } + // [End ark_napi_get_value_bigint_int64] } else if (item === '5.napiGetValueBigintUint64') { + // [Start ark_napi_get_value_bigint_uint64] // napi_get_value_bigint_uint64 let bigUint = BigInt(5555555555555555); try { hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_uint64: %{public}s', JSON.stringify(testNapi.getValueBigintUint64t(bigUint))); + // [StartExclude ark_napi_get_value_bigint_uint64] this.result = 'napiGetValueBigintUint64Success'; + // [EndExclude ark_napi_get_value_bigint_uint64] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); + // [StartExclude ark_napi_get_value_bigint_uint64] this.result = 'napiGetValueBigintUint64Fail'; + // [EndExclude ark_napi_get_value_bigint_uint64] } + // [End ark_napi_get_value_bigint_uint64] } else if (item === '6.napiGetValueBigintWords') { + // [Start ark_napi_get_value_bigint_words] // napi_get_value_bigint_words let bigInt = BigInt(-5555555555555555); let bigUint = BigInt(5555555555555555); @@ -102,11 +125,16 @@ struct Index { testNapi.getValueBigintWords(bigInt)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_words signBit is: %{public}d', testNapi.getValueBigintWords(bigUint)); + // [StartExclude ark_napi_get_value_bigint_words] this.result = 'napiGetValueBigintWordsSuccess'; + // [EndExclude ark_napi_get_value_bigint_words] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); + // [StartExclude ark_napi_get_value_bigint_words] this.result = 'napiGetValueBigintWordsFail'; + // [EndExclude ark_napi_get_value_bigint_words] } + // [End ark_napi_get_value_bigint_words] } }) } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/napi_init.cpp index d8cb01c5d61004bc7d417312010b5c6199177860..22f52d776fdf54e196c50fdda0816331708d6541 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/napi_init.cpp @@ -19,6 +19,7 @@ static constexpr int INT_ARG_18 = 18; // 入参索引 +// [Start napi_new_instance] // napi_new_instance static napi_value NewInstance(napi_env env, napi_callback_info info) { @@ -31,7 +32,9 @@ static napi_value NewInstance(napi_env env, napi_callback_info info) napi_new_instance(env, args[0], 1, &args[1], &result); return result; } +// [End napi_new_instance] +// [Start napi_wrap_unwrap_remove_wrap] struct Object { std::string name; int32_t age; @@ -89,6 +92,7 @@ static napi_value UnWrap(napi_env env, napi_callback_info info) OH_LOG_INFO(LOG_APP, "Node-API age: %{public}d", data->age); return nullptr; } +// [End napi_wrap_unwrap_remove_wrap] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/Index.d.ts index 3ba0ba16861ff0dfe9a9ac47fa2700df19dd7f33..9e0e5aa76de9946bc3dd33a0dfe55fd720debdae 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,10 +13,14 @@ * limitations under the License. */ +// [Start napi_new_instance_api] export const newInstance: (obj: Object, param: string) => Object // napi_new_instance +// [End napi_new_instance_api] +// [Start napi_wrap_unwrap_remove_wrap_api] export const wrap: (obj: Object) => Object; // napi_wrap export const unWrap: (obj: Object) => void; // napi_unwrap -export const removeWrap: (obj: Object) => void; // napi_remove_wrap \ No newline at end of file +export const removeWrap: (obj: Object) => void; // napi_remove_wrap +// [End napi_wrap_unwrap_remove_wrap_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/pages/Index.ets index 08f8b58942d22a7ee34bab386a938e4a8347507d..c3092dc54e1ef5f757bfc8e33bfbc259c3abd752 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/pages/Index.ets @@ -16,6 +16,7 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import testNapi from 'libentry.so'; +// [Start ark_napi_new_instance] class Fruit { name: string; @@ -24,6 +25,7 @@ class Fruit { } } +// [StartExclude ark_napi_new_instance] @Entry @Component struct Index { @@ -55,13 +57,16 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiNewInstance') { + // [EndExclude ark_napi_new_instance] // napi_new_instance // 调用函数,用变量obj接收函数返回的实例化对象 let obj = testNapi.newInstance(Fruit, 'test'); // 打印实例化对象obj的信息 hilog.info(0x0000, 'Node-API', 'napi_new_instance %{public}s', JSON.stringify(obj)); + // [End ark_napi_new_instance] this.result = 'napiNewInstanceSuccess'; } else if (item === '2.napiRemoveWrap') { + // [Start ark_napi_wrap_unwrap_remove_wrap] try { class Obj { } @@ -70,11 +75,16 @@ struct Index { testNapi.wrap(obj) // napi_wrap testNapi.unWrap(obj) // napi_unwrap testNapi.removeWrap(obj) // napi_remove_wrap + // [StartExclude ark_napi_wrap_unwrap_remove_wrap] this.result = 'napiRemoveWrapSuccess'; + // [EndExclude ark_napi_wrap_unwrap_remove_wrap] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API error: %{public}s', error.message); + // [StartExclude ark_napi_wrap_unwrap_remove_wrap] this.result = 'napiRemoveWrapFail'; + // [EndExclude ark_napi_wrap_unwrap_remove_wrap] } + // [End ark_napi_wrap_unwrap_remove_wrap] } }) } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/napi_init.cpp index a0433d5b336069522b75e890e4dbf8e54de82176..0d5588f21e2dbe152501dc27e5826b1c49bab53b 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/napi_init.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start napi_remove_add_env_cleanup_hook] #include #include #include @@ -29,10 +30,12 @@ typedef struct { void ExternalFinalize(napi_env env, void *finalizeData, void *finalizeHint) { Memory *wrapper = (Memory *)finalizeHint; + // [StartExclude napi_remove_add_env_cleanup_hook] if (wrapper == nullptr) { //处理内存分配失败的情况 return; } + // [EndExclude napi_remove_add_env_cleanup_hook] free(wrapper->data); free(wrapper); OH_LOG_INFO(LOG_APP, "Node-API napi_add_env_cleanup_hook ExternalFinalize"); @@ -51,10 +54,12 @@ static napi_value NapiEnvCleanUpHook(napi_env env, napi_callback_info info) // 分配内存并复制字符串数据到内存中 std::string str("Hello from Node-API!"); Memory *wrapper = (Memory *)malloc(sizeof(Memory)); + // [StartExclude napi_remove_add_env_cleanup_hook] if (wrapper == nullptr) { //处理内存分配失败的情况 return nullptr; } + // [End napi_remove_add_env_cleanup_hook] wrapper->data = static_cast(malloc(str.size())); strcpy(wrapper->data, str.c_str()); wrapper->size = str.size(); @@ -82,7 +87,9 @@ static napi_value NapiEnvCleanUpHook(napi_env env, napi_callback_info info) // 返回创建的外部缓冲区对象 return buffer; } +// [End napi_remove_add_env_cleanup_hook] +// [Start napi_add_remove_async_cleanup_hook] typedef struct { napi_env env; void *testData; @@ -135,10 +142,12 @@ static napi_value NapiAsyncCleanUpHook(napi_env env, napi_callback_info info) { // 分配AsyncContent内存 AsyncContent *data = reinterpret_cast(malloc(sizeof(AsyncContent))); + // StartExclude napi_add_remove_async_cleanup_hook] if (data == nullptr) { //处理内存分配失败的情况 return nullptr; } + // [EndExclude napi_add_remove_async_cleanup_hook] data->env = env; data->cleanupHandle = nullptr; // 分配内存并复制字符串数据 @@ -156,6 +165,7 @@ static napi_value NapiAsyncCleanUpHook(napi_env env, napi_callback_info info) napi_get_boolean(env, true, &result); return result; } +// [End napi_add_remove_async_cleanup_hook] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/Index.d.ts index 6766aa4cebff9796adab515b926d40e13bf1a0fe..b48f7cfd466f8f5e34d86a59e05f5460583af8bd 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,6 +13,10 @@ * limitations under the License. */ +// [Start napi_remove_add_env_cleanup_hook_api] export const napiEnvCleanUpHook: () => Object | void; +// [End napi_remove_add_env_cleanup_hook_api] -export const napiAsyncCleanUpHook: () => boolean | void; \ No newline at end of file +// [Start napi_add_remove_async_cleanup_hook_api] +export const napiAsyncCleanUpHook: () => boolean | void; +// [End napi_add_remove_async_cleanup_hook_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/pages/Index.ets index bb2ffec336f6bb07611b029f888373fc5a33ca3d..6b502b025668f190e817b190f1b240b3991498b4 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/pages/Index.ets @@ -48,6 +48,7 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiRemoveEnvCleanupHook') { + // [Start connect_with_worker] let wk = new worker.ThreadWorker('entry/ets/workers/worker.ts'); // 发送消息到worker线程 wk.postMessage('test NapiEnvCleanUpHook'); @@ -57,18 +58,25 @@ struct Index { JSON.stringify(message)); wk.terminate(); }; + // [End connect_with_worker] this.result = 'napiRemoveEnvCleanupHookSuccess'; } else if (item === '2.napiRemoveAsyncCleanupHook') { + // [Start ark_napi_remove_add_env_cleanup_hook] try { hilog.info(0x0000, 'testTag', 'Test Node-API napi_add_async_cleanup_hook: %{public}s', testNapi.napiAsyncCleanUpHook()); + // [StartExclude ark_napi_remove_add_env_cleanup_hook] this.result = 'napiRemoveAsyncCleanupHookSuccess'; + // [EndExclude ark_napi_remove_add_env_cleanup_hook] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_add_async_cleanup_hook error.message: %{public}s', error.message); + // [StartExclude ark_napi_remove_add_env_cleanup_hook] this.result = 'napiRemoveAsyncCleanupHookFail'; + // [EndExclude ark_napi_remove_add_env_cleanup_hook] } + // [End ark_napi_remove_add_env_cleanup_hook] } }) } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/workers/worker.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/workers/worker.ts index e73b154e151cec1c982f55bfd6ee852d29cf035d..263ec4cd73b5139daa1a52fa05fe5b7595ac9470 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/workers/worker.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/workers/worker.ts @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start connect_with_main_thread] import hilog from '@ohos.hilog'; import worker from '@ohos.worker'; import testNapi from 'libentry.so'; @@ -23,4 +24,5 @@ parent.onmessage = function(message) { hilog.info(0x0000, 'testTag', 'Test Node-API message from main thread: %{public}s', JSON.stringify(message)); // 发送消息到主线程 parent.postMessage('Test Node-API worker:' + testNapi.napiEnvCleanUpHook()); -} \ No newline at end of file +} +// [End connect_with_main_thread] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/napi_init.cpp index 79ab15c6723d8535dfe890ef516a9922a1ae868d..f4fc6dc4926ddf520cc70ff22c601d496f3698d3 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/napi_init.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start napi_create_date] #include #include "napi/native_api.h" @@ -26,7 +27,9 @@ static napi_value CreateDate(napi_env env, napi_callback_info info) napi_create_date(env, value, &returnValue); return returnValue; } +// [End napi_create_date] +// [Start napi_get_date_value] // napi_get_date_value static napi_value GetDateValue(napi_env env, napi_callback_info info) { @@ -50,7 +53,9 @@ static napi_value GetDateValue(napi_env env, napi_callback_info info) napi_create_double(env, value, &returnValue); return returnValue; } +// [End napi_get_date_value] +// [Start napi_is_date] // napi_is_date static napi_value IsDate(napi_env env, napi_callback_info info) { @@ -72,6 +77,7 @@ static napi_value IsDate(napi_env env, napi_callback_info info) return returnValue; } +// [End napi_is_date] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/Index.d.ts index aa417c78b8959a51abc3765e448db8309a127dee..8492f673288d7b15cfa02aa7134b9aca9866c4c2 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,8 +13,14 @@ * limitations under the License. */ +// [Start napi_create_date_api] export const createDate: () => Date; // napi_create_date +// [End napi_create_date_api] +// [Start napi_get_date_value_api] export const getDateValue: (date: Date) => number | void; // napi_get_date_value +// [End napi_get_date_value_api] -export const isDate: (date: T) => boolean | void; // napi_is_date \ No newline at end of file +// [Start napi_is_date_api] +export const isDate: (date: T) => boolean | void; // napi_is_date +// [End napi_is_date_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/pages/Index.ets index 77b014627730285610230e2347f3c24fdad23bbf..ef8032c3650b9ede7bfe73d4a8329d20a3521a71 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/pages/Index.ets @@ -48,35 +48,49 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiCreateDate') { + // [Start ark_napi_create_date] // napi_create_date hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_date: %{public}s', testNapi.createDate().toString()); + // [End ark_napi_create_date] this.result = 'napiCreateDateSuccess'; } else if (item === '2.napiGetDateValue') { + // [Start ark_napi_get_date_value] // napi_get_date_value try { const date = new Date(); hilog.info(0x0000, 'testTag', 'Node-API: output the Unix Time Stamp: %{public}d', date.getTime()); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_date_value: %{public}d', testNapi.getDateValue(date)); + // [StartExclude ark_napi_get_date_value] this.result = 'napiGetDateValueSuccess'; + // [EndExclude ark_napi_get_date_value] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_date_value error: %{public}s', error.message); + // [StartExclude ark_napi_get_date_value] this.result = 'napiGetDateValueFail'; + // [EndExclude ark_napi_get_date_value] } + // [End ark_napi_get_date_value] } else if (item === '3.napiIsDate') { + // [Start ark_napi_is_date] // napi_is_date try { let now: Date = new Date(); let date = "123"; hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_date: %{public}s', testNapi.isDate(now)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_date: %{public}s', testNapi.isDate(date)); + // [StartExclude ark_napi_is_date] this.result = 'napiIsDateSuccess'; + // [EndExclude ark_napi_is_date] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_date error: %{public}s', error.message); + // [StartExclude ark_napi_is_date] this.result = 'napiIsDateFail'; + // [EndExclude ark_napi_is_date] } + // [End ark_napi_is_date] } }) } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/napi_init.cpp index f6e441f7a7cec54d0e8d6310d1719ea6c400954c..4edf62a527fde6747aff0038f86a2bd53c8bc57a 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/napi_init.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start napi_set_instance_data] #include #include "napi/native_api.h" @@ -51,7 +52,9 @@ static napi_value SetInstanceData(napi_env env, napi_callback_info info) } return result; } +// [End napi_set_instance_data] +// [Start napi_get_instance_data] // napi_get_instance_data static napi_value GetInstanceData(napi_env env, napi_callback_info info) { @@ -62,6 +65,7 @@ static napi_value GetInstanceData(napi_env env, napi_callback_info info) napi_create_int32(env, resData->value, &result); return result; } +// [End napi_get_instance_data] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts index 5d22262414831bfe5a44b4c5b2fa33488eba5a48..2ed58066893cc90d6037199a635616821e58d221 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,6 +13,10 @@ * limitations under the License. */ +// [Start napi_set_instance_data_api] export const setInstanceData: (data: number) => boolean; // napi_set_instance_data +// [End napi_set_instance_data_api] -export const getInstanceData: () => number; // napi_get_instance_data \ No newline at end of file +// [Start napi_get_instance_data_api] +export const getInstanceData: () => number; // napi_get_instance_data +// [End napi_get_instance_data_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/pages/Index.ets index 020f9da88f1cfcfc4b3523915e5f09b7f83c2130..2d276e0e8d91fa7013602965df758ccb14403d08 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/pages/Index.ets @@ -47,17 +47,21 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiSetInstanceData') { + // [Start ark_napi_set_instance_data] // napi_set_instance_data let data = 5; let value = testNapi.setInstanceData(data); hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_instance_data:%{public}s', value); + // [End ark_napi_set_instance_data] this.result = 'napiSetInstanceDataSuccess'; } else if (item === '2.napiGetInstanceData') { + // [Start ark_napi_get_instance_data] // napi_get_instance_data let data = 5; testNapi.setInstanceData(data); let value = testNapi.getInstanceData(); hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_instance_data:%{public}d', value); + // [End ark_napi_get_instance_data] this.result = 'napiGetInstanceDataSuccess'; } }) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/napi_init.cpp index 6e11f230084f254744ce1ae1aca0b872c2b07ca1..e589bfa6570cacbe8cb7f9aa2018f6ac23f1699f 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/napi_init.cpp @@ -16,6 +16,7 @@ #include "hilog/log.h" #include "napi/native_api.h" +// [Start napi_get_last_error_info] // napi_get_last_error_info static napi_value GetLastErrorInfo(napi_env env, napi_callback_info info) { @@ -42,7 +43,9 @@ static napi_value GetLastErrorInfo(napi_env env, napi_callback_info info) napi_create_string_utf8(env, errorInfo->error_message, NAPI_AUTO_LENGTH, &result); return result; } +// [End napi_get_last_error_info] +// [Start napi_create_type_error] // napi_create_type_error static napi_value CreatTypeError(napi_env env, napi_callback_info info) { @@ -56,7 +59,9 @@ static napi_value CreatTypeError(napi_env env, napi_callback_info info) napi_create_type_error(env, errorCode, errorMessage, &error); return error; } +// [End napi_create_type_error] +// [Start napi_create_range_error] // napi_create_range_error static napi_value CreatRangeError(napi_env env, napi_callback_info info) { @@ -70,7 +75,9 @@ static napi_value CreatRangeError(napi_env env, napi_callback_info info) napi_create_range_error(env, errorCode, errorMessage, &error); return error; } +// [End napi_create_range_error] +// [Start napi_create_error] // napi_create_error and napi_throw static napi_value NapiThrow(napi_env env, napi_callback_info info) { @@ -88,7 +95,9 @@ static napi_value NapiThrow(napi_env env, napi_callback_info info) napi_throw(env, error); return nullptr; } +// [End napi_create_error] +// [Start napi_throw_error] // napi_throw_error // 这里直接抛出一个带有errorMessage的错误 static napi_value NapiThrowErrorMessage(napi_env env, napi_callback_info info) @@ -115,7 +124,9 @@ static napi_value NapiThrowError(napi_env env, napi_callback_info info) } return nullptr; } +// [End napi_throw_error] +// [Start napi_throw_type_error] // napi_throw_type_error // 这里直接抛出一个带有errorMessage的TypeError static napi_value ThrowTypeErrorMessage(napi_env env, napi_callback_info info) @@ -141,7 +152,9 @@ static napi_value ThrowTypeError(napi_env env, napi_callback_info info) } return nullptr; } +// [End napi_throw_type_error] +// [Start napi_throw_range_error] // napi_throw_range_error // 这里直接抛出一个带有errorMessage的RangeError static napi_value ThrowRangeErrorMessage(napi_env env, napi_callback_info info) @@ -173,7 +186,9 @@ static napi_value ThrowRangeError(napi_env env, napi_callback_info info) napi_create_double(env, result, &resultValue); return resultValue; } +// [End napi_throw_range_error] +// [Start napi_is_error] // napi_is_error static napi_value NapiIsError(napi_env env, napi_callback_info info) { @@ -190,7 +205,9 @@ static napi_value NapiIsError(napi_env env, napi_callback_info info) napi_get_boolean(env, result, &returnValue); return returnValue; } +// [End napi_is_error] +// [Start napi_get_and_clear_last_exception] // napi_get_and_clear_last_exception static napi_value GetAndClearLastException(napi_env env, napi_callback_info info) { @@ -204,7 +221,9 @@ static napi_value GetAndClearLastException(napi_env env, napi_callback_info info } return result; } +// [End napi_get_and_clear_last_exception] +// [Start napi_is_exception_pending] // napi_is_exception_pending static napi_value IsExceptionPending(napi_env env, napi_callback_info info) { @@ -229,7 +248,9 @@ static napi_value IsExceptionPending(napi_env env, napi_callback_info info) } return nullptr; } +// [End napi_is_exception_pending] +// [Start napi_fatal_error] // napi_fatal_error static napi_value FatalError(napi_env env, napi_callback_info info) { @@ -242,7 +263,9 @@ static napi_value FatalError(napi_env env, napi_callback_info info) } return nullptr; } +// [End napi_fatal_error] +// [Start napi_fatal_exception] // napi_fatal_exception static napi_value FatalException(napi_env env, napi_callback_info info) { @@ -261,6 +284,7 @@ static napi_value FatalException(napi_env env, napi_callback_info info) } return nullptr; } +// [End napi_fatal_exception] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/Index.d.ts index 26e38791920b4b89f885a7616fc7c83103026366..6458d55543619b58032d3e77de2462da0920af14 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,37 +13,63 @@ * limitations under the License. */ +// [Start napi_get_last_error_info_api] export const getLastErrorInfo: (str: string) => string; // napi_get_last_error_info +// [End napi_get_last_error_info_api] +// [Start napi_create_type_error_api] export const creatTypeError: () => Error; // napi_create_type_error +// [End napi_create_type_error_api] +// [Start napi_create_range_error_api] export const creatRangeError: () => Error; // napi_create_range_error +// [End napi_create_range_error_api] +// [Start napi_create_error_api] export const napiThrow: () => void; // napi_create_error and napi_throw +// [End napi_create_error_api] +// [Start napi_throw_error_api] export const napiThrowErrorMessage: () => void; // napi_throw_error export const napiThrowError: (dividend: number, divisor: number) => void; // napi_throw_error +// [End napi_throw_error_api] +// [Start napi_throw_type_error_api] export const throwTypeErrorMessage: () => void; // napi_throw_type_error export const throwTypeError: (message: string) => void; // napi_throw_type_error +// [End napi_throw_type_error_api] +// [Start napi_throw_range_error_api] export const throwRangeErrorMessage: () => void; // napi_throw_range_error export const throwRangeError: (num: number) => number | void; // napi_throw_range_error +// [End napi_throw_range_error_api] +// [Start napi_is_error_api] export const napiIsError: (obj: T) => boolean; // napi_is_error +// [End napi_is_error_api] +// [Start napi_get_and_clear_last_exception_api] export const getAndClearLastException: () => Error | void; // napi_get_and_clear_last_exception +// [End napi_get_and_clear_last_exception_api] +// [Start ark_napi_is_exception_pending_interface] export interface MyObject { code: string; message: string; } +// [End ark_napi_is_exception_pending_interface] +// [Start napi_is_exception_pending_api] export const isExceptionPending: () => Object | void; // napi_is_exception_pending +// [End napi_is_exception_pending_api] +// [Start napi_fatal_error_api] export const fatalError: () => void; // napi_fatal_error +// [End napi_fatal_error_api] -export const fatalException: (err: Error) => void; // napi_fatal_exception \ No newline at end of file +// [Start napi_fatal_exception_api] +export const fatalException: (err: Error) => void; // napi_fatal_exception +// [End napi_fatal_exception_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/pages/Index.ets index 85b5226b84ceb7556aacbd223ce90c5010198757..117809f4f7503145892a08e6cf735c32c33c8936 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/pages/Index.ets @@ -57,117 +57,174 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiGetLastErrorInfo') { + // [Start ark_napi_get_last_error_info] // napi_get_last_error_info try { hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_last_error_info: %{public}s', testNapi.getLastErrorInfo('message')); + // [StartExclude ark_napi_get_last_error_info] this.result = 'napiGetLastErrorInfoSuccess'; + // [EndExclude ark_napi_get_last_error_info] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_last_error_info error: %{public}s', error); + // [StartExclude ark_napi_get_last_error_info] this.result = 'napiGetLastErrorInfoFail'; + // [EndExclude ark_napi_get_last_error_info] } + // [End ark_napi_get_last_error_info] } else if (item === '2.napiCreateTypeError') { + // [Start ark_napi_create_type_error] try { + // [StartExclude ark_napi_create_type_error] this.result = 'napiCreateTypeErrorSuccess'; + // [EndExclude ark_napi_create_type_error] throw testNapi.creatTypeError(); } catch (error) { // napi_create_type_error hilog.error(0x0000, 'testTag', 'Test Node-API napi_create_type_error errorCode: %{public}s, errorMessage %{public}s', error.code, error.message); + // [StartExclude ark_napi_create_type_error] this.result = 'napiCreateTypeErrorFail'; + // [EndExclude ark_napi_create_type_error] } + // [End ark_napi_create_type_error] } else if (item === '3.napiCreateRangeError') { + // [Start ark_napi_create_range_error] // napi_create_range_error try { + // [StartExclude ark_napi_create_range_error] this.result = 'napiCreateRangeErrorSuccess'; + // [EndExclude ark_napi_create_range_error] throw testNapi.creatRangeError(); } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_create_range_error errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_create_range_error] this.result = 'napiCreateRangeErrorFail'; + // [EndExclude ark_napi_create_range_error] } + // [End ark_napi_create_range_error] } else if (item === '4.napiCreateErrorAndNapiThrow') { + // [Start ark_napi_create_error] // napi_create_error and napi_throw try { testNapi.napiThrow(); + // [StartExclude ark_napi_create_error] this.result = 'napiCreateErrorAndNapiThrowSuccess'; + // [EndExclude ark_napi_create_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_throw errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_create_error] this.result = 'napiCreateErrorAndNapiThrowFail'; + // [EndExclude ark_napi_create_error] } + // [End ark_napi_create_error] } else if (item === '5.napiThrowError') { + // [Start ark_napi_throw_error] // napi_throw_error try { testNapi.napiThrowErrorMessage(); + // [StartExclude ark_napi_throw_error] this.result = 'napiThrowErrorMessageSuccess'; + // [EndExclude ark_napi_throw_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_throw_error error code: %{public}s , message: %{public}s', error.code, error.message); + // [StartExclude ark_napi_throw_error] this.result = 'napiThrowErrorMessageFail'; + // [EndExclude ark_napi_throw_error] } try { testNapi.napiThrowError(5, 0); + // [StartExclude ark_napi_throw_error] this.result = 'napiThrowErrorSuccess'; + // [EndExclude ark_napi_throw_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_throw_error errorCode: %{public}s , errorManager: %{public}s', error.code, error.message); + // [StartExclude ark_napi_throw_error] this.result = 'napiThrowErrorFail'; + // [EndExclude ark_napi_throw_error] } + // [End ark_napi_throw_error] } else if (item === '6.napiThrowTypeError') { + // [Start ark_napi_throw_type_error] // napi_throw_type_error try { testNapi.throwTypeErrorMessage(); + // [StartExclude ark_napi_throw_type_error] this.result = 'throwTypeErrorMessageSuccess'; + // [EndExclude ark_napi_throw_type_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_throw_type_error errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_throw_type_error] this.result = 'throwTypeErrorMessageFail'; + // [EndExclude ark_napi_throw_type_error] } try { testNapi.throwTypeError('str'); + // [StartExclude ark_napi_throw_type_error] this.result = 'throwTypeErrorSuccess'; + // [EndExclude ark_napi_throw_type_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_throw_type_error errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_throw_type_error] this.result = 'throwTypeErrorFail'; + // [EndExclude ark_napi_throw_type_error] } + // [End ark_napi_throw_type_error] } else if (item === '7.napiThrowRangeError') { + // [Start ark_napi_throw_range_error] // napi_throw_range_error try { testNapi.throwRangeErrorMessage(); + // [StartExclude ark_napi_throw_range_error] this.result = 'throwRangeErrorMessageSuccess'; + // [EndExclude ark_napi_throw_range_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_throw_range_error errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_throw_range_error] this.result = 'throwRangeErrorMessageFail'; + // [EndExclude ark_napi_throw_range_error] } try { testNapi.throwRangeError(1); + // [StartExclude ark_napi_throw_range_error] this.result = 'throwRangeErrorSuccess'; + // [EndExclude ark_napi_throw_range_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_throw_range_error errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_throw_range_error] this.result = 'throwRangeErrorFail'; + // [EndExclude ark_napi_throw_range_error] } + // [End ark_napi_throw_range_error] } else if (item === '8.napiIsError') { + // [Start ark_napi_is_error] // napi_is_error try { + // [StartExclude ark_napi_is_error] this.result = 'napiIsErrorSuccess'; + // [EndExclude ark_napi_is_error] throw new Error("throwing an error"); } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_error error: %{public}s', @@ -176,43 +233,62 @@ struct Index { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_error error: %{public}s', testNapi.napiIsError(1) .toString()); + // [StartExclude ark_napi_is_error] this.result = 'napiIsErrorFail'; + // [EndExclude ark_napi_is_error] } + // [End ark_napi_is_error] } else if (item === '9.napiGetAndClearLastException') { + // [Start ark_napi_get_and_clear_last_exception] // napi_get_and_clear_last_exception // 这里获取到最后一个未处理的异常 hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_and_clear_last_exception, error.message: %{public}s', testNapi.getAndClearLastException()); + // [End ark_napi_get_and_clear_last_exception] this.result = 'napiGetAndClearLastExceptionSuccess'; } else if (item === '10.napiIsExceptionPending') { + // [Start ark_napi_is_exception_pending] // napi_is_exception_pending try { let result = testNapi.isExceptionPending() as MyObject; hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_exception_pending, error.Code: %{public}s, error.message: %{public}s', result.code, result.message); + // [StartExclude ark_napi_is_exception_pending] this.result = 'napiIsExceptionPendingSuccess'; + // [EndExclude ark_napi_is_exception_pending] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_exception_pending error'); + // [StartExclude ark_napi_is_exception_pending] this.result = 'napiIsExceptionPendingFail'; + // [EndExclude ark_napi_is_exception_pending] } + // [End ark_napi_is_exception_pending] } else if (item === '11.napiFatalError') { + // [Start ark_napi_fatal_error] // napi_fatal_error 请注意,使用napi_fatal_error函数会导致应用进程直接终止,因此应该谨慎使用,仅在遇到无法恢复的严重错误时才应该调用该函数 // 模拟一个致命错误条件 try { testNapi.fatalError(); + // [StartExclude ark_napi_fatal_error] this.result = 'napiFatalErrorSuccess'; + // [EndExclude ark_napi_fatal_error] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_fatal_error error'); + // [StartExclude ark_napi_fatal_error] this.result = 'napiFatalErrorFail'; + // [EndExclude ark_napi_fatal_error] } + // [End ark_napi_fatal_error] } else if (item === '12.napiFatalException') { // napi_fatal_exception 请注意,使用napi_fatal_error函数会导致应用进程直接终止,因此应该谨慎使用,仅在遇到无法恢复的严重错误时才应该调用该函数 // 模拟一个致命错误条件 try { + // [Start ark_napi_fatal_exception] const err = new Error("a fatal exception occurred"); testNapi.fatalException(err); + // [End ark_napi_fatal_exception] this.result = 'napiFatalExceptionSuccess'; } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_fatal_exception error'); diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/napi_init.cpp index 932f6bc8151962e01df519119f1e3294ba8e8ded..98fe63d9c102d4f90fe7242fdcad492a3e72b962 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/napi_init.cpp @@ -22,6 +22,7 @@ static constexpr int INT_ARG_100 = 100; // 入参索引 +// [Start node_api_module_add] // 模块加载 static napi_value Add(napi_env env, napi_callback_info info) { @@ -43,6 +44,9 @@ static napi_value Add(napi_env env, napi_callback_info info) return sum; } + +// [StartExclude node_api_module_add] +// [Start node_api_module_create_object_properties] // ArkTS Object相关 napi_create_object_with_properties static napi_value CreateObjectWithProperties(napi_env env, napi_callback_info info) { @@ -62,6 +66,8 @@ static napi_value CreateObjectWithProperties(napi_env env, napi_callback_info in return object; } } +// [End node_api_module_create_object_properties] +// [Start node_api_module_create_object_name_properties] // ArkTS Object相关 napi_create_object_with_named_properties static napi_value CreateObjectWithNameProperties(napi_env env, napi_callback_info info) { @@ -84,6 +90,8 @@ static napi_value CreateObjectWithNameProperties(napi_env env, napi_callback_inf } return obj; } +// [End node_api_module_create_object_name_properties] +// [Start node_api_module_run_script_path] // 运行指定abc文件 napi_run_script_path static napi_value RunScriptPath(napi_env env, napi_callback_info info) { @@ -101,7 +109,9 @@ static napi_value RunScriptPath(napi_env env, napi_callback_info info) } return returnValue; } +// [End node_api_module_run_script_path] // 给ArkTS对象绑定回调和回调所需的参数 napi_coerce_to_native_binding_object +// [Start napi_coerce_to_native_binding_object] class Object { public: Object() = default; @@ -264,6 +274,8 @@ napi_value AttachCallback(napi_env env, void *value, void *hint) napi_coerce_to_native_binding_object(env, object, DetachCallback, AttachCallback, value, hint); return object; } +// [StartExclude napi_coerce_to_native_binding_object] +// [Start napi_serialize_deserialize_delete_serialization_data] // 序列化和反序列化 static napi_value AboutSerialize(napi_env env, napi_callback_info info) { @@ -299,6 +311,8 @@ static napi_value AboutSerialize(napi_env env, napi_callback_info info) // 返回获取到的属性值 return number; } +// [End napi_serialize_deserialize_delete_serialization_data] +// [Start napi_is_sendable] // Sendable相关 napi_is_sendable static napi_value IsSendable(napi_env env, napi_callback_info info) { @@ -311,7 +325,9 @@ static napi_value IsSendable(napi_env env, napi_callback_info info) napi_get_boolean(env, isSendable, &result); return result; } +// [End napi_is_sendable] +// [Start napi_define_sendable_class] static napi_value func(napi_env env, napi_callback_info info) { napi_value val; @@ -353,6 +369,8 @@ static napi_value DefineSendableClass(napi_env env) return sendableClass; } +// [End napi_define_sendable_class] +// [Start napi_create_sendable_object_with_properties] // Sendable相关 napi_create_sendable_object_with_properties static napi_value GetSendableObject(napi_env env, napi_callback_info info) { @@ -365,6 +383,8 @@ static napi_value GetSendableObject(napi_env env, napi_callback_info info) napi_create_sendable_object_with_properties(env, 1, desc1, &obj); return obj; } +// [End napi_create_sendable_object_with_properties +// [Start napi_create_sendable_array] // Sendable相关 napi_create_sendable_array static napi_value GetSendableArray(napi_env env, napi_callback_info info) { @@ -372,6 +392,8 @@ static napi_value GetSendableArray(napi_env env, napi_callback_info info) napi_create_sendable_array(env, &result); return result; } +// [End napi_create_sendable_array] +// [Start napi_create_sendable_array_with_length] // Sendable相关 napi_create_sendable_array_with_length static napi_value GetSendableArrayWithLength(napi_env env, napi_callback_info info) { @@ -379,6 +401,8 @@ static napi_value GetSendableArrayWithLength(napi_env env, napi_callback_info in napi_create_sendable_array_with_length(env, 1, &result); return result; } +// End napi_create_sendable_array_with_length] +// [Start napi_create_sendable_arraybuffer] // Sendable相关 napi_create_sendable_arraybuffer static napi_value GetSendableArrayBuffer(napi_env env, napi_callback_info info) { @@ -391,6 +415,8 @@ static napi_value GetSendableArrayBuffer(napi_env env, napi_callback_info info) OH_LOG_INFO(LOG_APP, "isArrayBuffer: %{public}d", isArrayBuffer); return result; } +// [End napi_create_sendable_arraybuffer] +// [Start napi_create_sendable_typed_array] // Sendable相关 napi_create_sendable_typedarray static napi_value GetSendableTypedArray(napi_env env, napi_callback_info info) { @@ -407,6 +433,8 @@ static napi_value GetSendableTypedArray(napi_env env, napi_callback_info info) OH_LOG_INFO(LOG_APP, "isTypedArray: %{public}d", isTypedArray); return result; } +// [End napi_create_sendable_typed_array] +// [Start napi_wrap_sendable] // Sendable相关 napi_wrap_sendable static napi_value WrapSendable(napi_env env, napi_callback_info info) { @@ -424,6 +452,8 @@ static napi_value WrapSendable(napi_env env, napi_callback_info info) return nullptr; } +// [End napi_wrap_sendable] +// [Start napi_wrap_sendable_with_size] // Sendable相关 napi_wrap_sendable_with_size static napi_value WrapSendableWithSize(napi_env env, napi_callback_info info) { @@ -441,6 +471,8 @@ static napi_value WrapSendableWithSize(napi_env env, napi_callback_info info) return nullptr; } +// [End napi_wrap_sendable_with_size] +// [Start napi_unwrap_sendable] // Sendable相关 napi_unwrap_sendable static napi_value UnwrapSendable(napi_env env, napi_callback_info info) { @@ -462,6 +494,8 @@ static napi_value UnwrapSendable(napi_env env, napi_callback_info info) return nullptr; } +// [End napi_unwrap_sendable] +// [Start napi_remove_wrap_sendable] // Sendable相关 napi_remove_wrap_sendable static napi_value RemoveWrapSendable(napi_env env, napi_callback_info info) { @@ -483,6 +517,10 @@ static napi_value RemoveWrapSendable(napi_env env, napi_callback_info info) return nullptr; } +// [End napi_remove_wrap_sendable] +// [EndExclude napi_coerce_to_native_binding_object] +// [EndExclude node_api_module_add] + // C++函数Init用于初始化插件,用于将ArkTS层的函数或属性与C++层的函数进行关联 EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) @@ -522,7 +560,7 @@ static napi_value Init(napi_env env, napi_value exports) return exports; } EXTERN_C_END - + // 插件的初始化被定义在一个名为demoModule的结构体中,其中包含了模块的基本信息,比如模块的版本号、注册函数等 static napi_module demoModule = { .nm_version = 1, @@ -536,3 +574,5 @@ static napi_module demoModule = { // 在RegisterEntryModule函数中,使用napi_module_register函数注册并导出了这个插件 extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } +// [End node_api_module_add] + diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/Index.d.ts index 6108c3c906d846e99dd943ad292cc16d43b0d951..4f111a684b312d30bdbc185139a80dae0d9220e6 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,14 +13,22 @@ * limitations under the License. */ +// [Start node_api_module_add_api] export const add: (a: number, b: number) => number; // 模块加载 +// [End node_api_module_add_api] +// [Start node_api_module_create_object_properties_api] export const createObjectWithProperties: (data: string) => Object; // ArkTS Object相关 napi_create_object_with_properties +// [End node_api_module_create_object_properties_api] +// [Start node_api_module_create_object_name_properties_api] export const createObjectWithNameProperties: (data: string) => string | { name: string }; // ArkTS Object相关 napi_create_object_with_named_properties +// [End node_api_module_create_object_name_properties_api] +// [Start node_api_module_run_script_path_api] export const runScriptPath: () => boolean; // 运行指定abc文件 napi_run_script_path - +// [End node_api_module_run_script_path_api] +// [Start napi_coerce_to_native_binding_object_api] // 给ArkTS对象绑定回调和回调所需的参数 napi_coerce_to_native_binding_object export const getAddress: () => number; @@ -31,11 +39,17 @@ export const store: (a: number) => void; export const erase: (a: number) => void; export const clear: () => void; +// [End napi_coerce_to_native_binding_object_api] +// [Start napi_serialize_deserialize_delete_serialization_data_api] export const aboutSerialize: (obj: Object) => number; // 序列化和反序列化 +// [End napi_serialize_deserialize_delete_serialization_data_api] +// [Start napi_is_sendable_api] export const isSendable: (a: T) => boolean; // Sendable相关 napi_is_sendable +// [End napi_is_sendable_api] +// [Start napi_define_sendable_class_api] @Sendable export class SendableClass { static staticStr: string; @@ -43,22 +57,40 @@ export class SendableClass { str: string; func(): string; } // Sendable相关 napi_define_sendable_class +// [End napi_define_sendable_class_api] +// [Start napi_create_sendable_object_with_properties_api] export const getSendableObject: () => { x: true }; // Sendable相关 napi_create_sendable_object_with_properties +// [End napi_create_sendable_object_with_properties_api] +// [Start napi_create_sendable_array_api] export const getSendableArray: () => []; // Sendable相关 napi_create_sendable_array +// [End napi_create_sendable_array_api] +// [Start napi_create_sendable_array_with_length_api] export const getSendableArrayWithLength: () => []; // Sendable相关 napi_create_sendable_array_with_length +// [End napi_create_sendable_array_with_length_api] +// [Start napi_create_sendable_arraybuffer_api] export const getSendableArrayBuffer: () => void; // Sendable相关 napi_create_sendable_arraybuffer +// [End napi_create_sendable_arraybuffer_api] +// [Start napi_create_sendable_typed_array_api] export const getSendableTypedArray: () => void; // Sendable相关 napi_create_sendable_typedarray +// [End napi_create_sendable_typed_array_api] +// [Start napi_wrap_sendable_api] export const wrapSendable: () => void; // Sendable相关 napi_wrap_sendable +// [End napi_wrap_sendable_api] +// [Start napi_wrap_sendable_with_size_api] export const wrapSendableWithSize: () => void; // Sendable相关 napi_wrap_sendable_with_size +// [End napi_wrap_sendable_with_size_api] +// [Start napi_unwrap_sendable_api] export const unwrapSendable: () => void; // Sendable相关 napi_unwrap_sendable +// [End napi_unwrap_sendable_api] +// [Start napi_remove_wrap_sendable_api] export const removeWrapSendable: () => void; // Sendable相关 napi_remove_wrap_sendable - +// [End napi_remove_wrap_sendable_api] diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/pages/Index.ets index 8e0af9761ba8dd5f70fe5a7b148f32445fb45f5c..f1dc444030c2482a8a7d7531f058dee6c4d9d48d 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/pages/Index.ets @@ -13,10 +13,12 @@ * limitations under the License. */ + import { hilog } from '@kit.PerformanceAnalysisKit'; import testNapi from 'libentry.so'; import taskpool from '@ohos.taskpool'; +// [Start ark_napi_coerce_to_native_binding_object] @Concurrent function getAddress() { let address: number = testNapi.getAddress(); @@ -74,10 +76,13 @@ async function test01(): Promise { let task6 = new taskpool.Task(clear); await taskpool.execute(task6); } +// [End ark_napi_coerce_to_native_binding_object] +// [Start ark_napi_serialize_deserialize_delete_serialization_data] class Obj { numKey: number = 0; } +// [StartExclude ark_napi_serialize_deserialize_delete_serialization_data] @Entry @Component @@ -125,91 +130,127 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiLoadModule') { + // [Start ark_node_api_module_add] hilog.info(0x0000, 'testTag', 'Test Node-API 2 + 3 = %{public}d', testNapi.add(2, 3)); + // [End ark_node_api_module_add] this.result = 'napiLoadModuleSuccess'; } else if (item === '2.napiCreateObjectWithProperties') { + // [Start ark_node_api_module_create_object_properties] // ArkTS Object相关 napi_create_object_with_properties let value1 = testNapi.createObjectWithProperties('createObject'); hilog.info(0x0000, 'testTag', 'Node-API napi_create_object_with_properties:%{public}s', JSON.stringify(value1)); + // [End ark_node_api_module_create_object_properties] this.result = 'napiCreateObjectWithPropertiesSuccess'; } else if (item === '3.napiCreateObjectWithNamedProperties') { + // [Start ark_node_api_module_create_object_name_properties] // ArkTS Object相关 napi_create_object_with_named_properties let value2 = testNapi.createObjectWithNameProperties('ls'); hilog.info(0x0000, 'testTag', 'Node-API napi_create_object_with_named_properties:%{public}s', JSON.stringify(value2)); + // [End ark_node_api_module_create_object_name_properties] this.result = 'napiCreateObjectWithNamedPropertiesSuccess'; } else if (item === '4.napiRunScriptPath') { + // [Start ark_node_api_module_run_script_path] // 运行指定abc文件 napi_run_script_path try { // 在此处执行错误返回false,成功就返回true hilog.info(0x0000, 'testTag', 'Test Node-API napi_run_script_path: %{public}s', testNapi.runScriptPath()); + // [StartExclude ark_node_api_module_run_script_path] this.result = 'napiRunScriptPathSuccess'; + // [EndExclude ark_node_api_module_run_script_path] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_run_script_path errorMessage: %{public}s', error.message); + // [StartExclude ark_node_api_module_run_script_path] this.result = 'napiRunScriptPathFail'; + // [EndExclude ark_node_api_module_run_script_path] } + // [End ark_node_api_module_run_script_path] } else if (item === '5.napiCoerceToNativeBindingObject') { // 给ArkTS对象绑定回调和回调所需的参数 napi_coerce_to_native_binding_object test01(); this.result = 'napiCoerceToNativeBindingObjectSuccess'; } else if (item === '6.napiAboutSerialize') { + // [EndExclude ark_napi_serialize_deserialize_delete_serialization_data] // 序列化和反序列化 let obj: Obj = { numKey: 500 }; hilog.info(0x0000, 'testTag', ' Node-API aboutSerialize: %{public}d', testNapi.aboutSerialize(obj)); + // [End ark_napi_serialize_deserialize_delete_serialization_data] this.result = 'napiAboutSerializeSuccess'; } else if (item === '7.napiIsSendable') { + // [Start ark_napi_is_sendable] // Sendable相关 napi_is_sendable let value = testNapi.isSendable('createObject'); hilog.info(0x0000, 'testTag', 'Node-API napi_is_sendable: %{public}s', JSON.stringify(value)); + // [End ark_napi_is_sendable] this.result = 'napiIsSendableSuccess'; } else if (item === '8.napiDefineSendableClass') { + // [Start ark_napi_define_sendable_class] // Sendable相关 napi_define_sendable_class let value = new testNapi.SendableClass(); hilog.info(0x0000, 'testTag', 'Node-API napi_define_sendable_class: %{public}s', value.str); + // [End ark_napi_define_sendable_class] this.result = 'napiDefineSendableClassSuccess'; } else if (item === '9.napiCreateSendableObjectWithProperties') { + // [Start ark_napi_create_sendable_object_with_properties] // Sendable相关 napi_create_sendable_object_with_properties let value = testNapi.getSendableObject(); hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_object_with_properties: %{public}s', JSON.stringify(value)); + // [End ark_napi_create_sendable_object_with_properties] this.result = 'napiCreateSendableObjectWithPropertiesSuccess'; } else if (item === '10.napiCreateSendableArray') { + // [Start ark_napi_create_sendable_array] // Sendable相关 napi_create_sendable_array let value = testNapi.getSendableArray(); hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_array: %{public}s', JSON.stringify(value)); + // [End ark_napi_create_sendable_array] this.result = 'napiCreateSendableArraySuccess'; } else if (item === '11.napiCreateSendableArrayWithLength') { + // [Start ark_napi_create_sendable_array_with_length] // Sendable相关 napi_create_sendable_array_with_length let value = testNapi.getSendableArrayWithLength(); hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_array_with_length: %{public}s', JSON.stringify(value.length)); + // [End ark_napi_create_sendable_array_with_length] this.result = 'napiCreateSendableArrayWithLengthSuccess'; } else if (item === '12.napiCreateSendableArraybuffer') { + // [Start ark_napi_create_sendable_arraybuffer] // Sendable相关 napi_create_sendable_arraybuffer testNapi.getSendableArrayBuffer(); + // [End ark_napi_create_sendable_arraybuffer] this.result = 'napiCreateSendableArraybufferSuccess'; } else if (item === '13.napiCreateSendableTypedArray') { + // [Start ark_napi_create_sendable_typed_array] // Sendable相关 napi_create_sendable_typedarray testNapi.getSendableTypedArray(); + // [End ark_napi_create_sendable_typed_array] this.result = 'napiCreateSendableTypedArraySuccess'; } else if (item === '14.napiWrapSendable') { + // [Start ark_napi_wrap_sendable] // Sendable相关 napi_wrap_sendable testNapi.wrapSendable(); + // [End ark_napi_wrap_sendable] this.result = 'napiWrapSendableSuccess'; } else if (item === '15.napiWrapSendableWithSize') { + // [Start ark_napi_wrap_sendable_with_size] // Sendable相关 napi_wrap_sendable_with_size testNapi.wrapSendableWithSize(); + // [End ark_napi_wrap_sendable_with_size] this.result = 'napiWrapSendableWithSizeSuccess'; } else if (item === '16.napiUnwrapSendable') { + // [Start ark_napi_unwrap_sendable] // Sendable相关 napi_unwrap_sendable testNapi.unwrapSendable(); + // [End ark_napi_unwrap_sendable] this.result = 'napiUnwrapSendableSuccess'; } else if (item === '17.napiRemoveWrapSendable') { + // [Start ark_napi_remove_wrap_sendable] // Sendable相关 napi_remove_wrap_sendable testNapi.removeWrapSendable(); + // [End ark_napi_remove_wrap_sendable] this.result = 'napiRemoveWrapSendableSuccess'; } }) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/napi_init.cpp index c31af30060ffd248466e3b806cf7df3b859f9953..22cb880f7b51477e0721a2532696abb6d89ea750 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/napi_init.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start napi_get_cb_info] #include "napi/native_api.h" // napi_get_cb_info @@ -42,7 +43,9 @@ static napi_value GetCbContext(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, nullptr, nullptr, &thisArg, nullptr); return thisArg; } +// [End napi_get_cb_info] +// [Start napi_call_function] // napi_call_function static napi_value CallFunction(napi_env env, napi_callback_info info) { @@ -73,7 +76,9 @@ static napi_value ObjCallFunction(napi_env env, napi_callback_info info) napi_call_function(env, argv[0], argv[1], argc, argv, &result); return result; } +// [End napi_call_function] +// [Start napi_create_function] // napi_create_function static napi_value CalculateArea(napi_env env, napi_callback_info info) { @@ -89,6 +94,7 @@ static napi_value CalculateArea(napi_env env, napi_callback_info info) napi_create_double(env, width * height, &area); return area; } +// [End napi_create_function] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/Index.d.ts index 6cba5001afacca52dde5d68a6b603134706b729a..ceacdececee0e5fa1b91eef00e7d814a977edafa 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,16 +13,21 @@ * limitations under the License. */ +// [Start napi_get_cb_info_api] export const getCbArgs: (arg: T) => T; // napi_get_cb_info // getCbArgQuantity的入参由用户自定义,在此用例中,我们用两个入参,一个是string,一个是number export const getCbArgQuantity: (str: string, num: number) => number; export const getCbContext: () => Object; +// [End napi_get_cb_info_api] +// [Start napi_call_function_api] export const callFunction: (func: Function) => number; // napi_call_function export const objCallFunction: (obj: Object, func: Function) => number; +// [End napi_call_function_api] +// [Start napi_create_function_api] export const calculateArea: (width: number, height: number) => number; // napi_create_function - +// [End napi_create_function_api] diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/pages/Index.ets index 25b4b7a0295971a7e9c96cc78a012a53af10e2c1..1734ab6667ce6688a375971976dc3382d9f47505 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/pages/Index.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start ark_napi_get_cb_info] import { hilog } from '@kit.PerformanceAnalysisKit'; import testNapi from 'libentry.so'; @@ -40,6 +41,8 @@ class Student { } } +// [StartExclude ark_napi_get_cb_info] +// [Start ark_napi_call_function] function returnNumber() { return 10; } @@ -50,6 +53,7 @@ class Person { } } +// [StartExclude ark_napi_call_function] @Entry @Component struct Index { @@ -82,6 +86,7 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiGetCbInfo') { + // [EndExclude ark_napi_get_cb_info] // napi_get_cb_info let student = new Student('Alice', 18, 100); // 获取参数 @@ -103,19 +108,24 @@ struct Index { // 获取上下文 hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get thisArg:%{public}s ', testNapi.getCbContext().toString()); + // [End ark_napi_get_cb_info] this.result = 'napiGetCbInfoSuccess'; } else if (item === '2.napiCallFunction') { + // [EndExclude ark_napi_call_function] // napi_call_function const person = new Person(); hilog.info(0x0000, 'testTag', 'Test Node-API call_function:%{public}d', testNapi.callFunction(returnNumber)); hilog.info(0x0000, 'testTag', 'Test Node-API call_function:%{public}d', testNapi.objCallFunction(person, person.age)); + // [End ark_napi_call_function] this.result = 'napiCallFunctionSuccess'; } else if (item === '3.napiCreateFunction') { + // [Start ark_napi_create_function] // napi_create_function hilog.info(0x0000, 'testTag', 'Test Node-API create_function:%{public}d ', testNapi.calculateArea(1.2, 4)); + // [End ark_napi_create_function] this.result = 'napiCreateFunctionSuccess'; } }) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/napi_init.cpp index 72d771da59a2bf106e7eeb9125eaf6b4d0d542bf..cdc6424c3e792be4a362d4808b767d9d74594fb4 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/napi_init.cpp @@ -16,6 +16,7 @@ #include "hilog/log.h" #include "napi/native_api.h" +// [Start napi_open_close_handle_scope] // napi_open_handle_scope、napi_close_handle_scope static napi_value HandleScopeTest(napi_env env, napi_callback_info info) { @@ -57,7 +58,9 @@ static napi_value HandleScope(napi_env env, napi_callback_info info) napi_get_named_property(env, obj, "key", &result); return result; } +// [End napi_open_close_handle_scope] +// [Start napi_open_close_escapable_handle_scope] // napi_open_escapable_handle_scope、napi_close_escapable_handle_scope、napi_escape_handle static napi_value EscapableHandleScopeTest(napi_env env, napi_callback_info info) { @@ -82,7 +85,9 @@ static napi_value EscapableHandleScopeTest(napi_env env, napi_callback_info info napi_get_named_property(env, escapedObj, "key", &result); return result; } +// [End napi_open_close_escapable_handle_scope] +// [Start napi_create_delete_reference] // 创建一个指向napi_ref类型的指针,用于存储创建的引用。在调用napi_create_reference函数之前,你需要分配一个napi_ref类型的变量,并将其地址传递给result位置的参数 napi_ref g_ref; @@ -100,12 +105,14 @@ static napi_value CreateReference(napi_env env, napi_callback_info info) napi_create_string_utf8(env, "CreateReference", NAPI_AUTO_LENGTH, &value); // 将键值对添加到对象中 napi_set_named_property(env, obj, "key", value); + // [StartExclude napi_create_delete_reference] // 创建对ArkTS对象的引用 napi_status status = napi_create_reference(env, obj, 1, &g_ref); if (status != napi_ok) { napi_throw_error(env, nullptr, "napi_create_reference fail"); return nullptr; } + // [EndExclude napi_create_delete_reference] // 添加终结器 void *data = {}; napi_add_finalizer(env, obj, data, Finalizer, nullptr, &g_ref); @@ -158,6 +165,7 @@ static napi_value DeleteReference(napi_env env, napi_callback_info info) napi_create_string_utf8(env, "napi_delete_reference success", NAPI_AUTO_LENGTH, &returnResult); return returnResult; } +// [End napi_create_delete_reference] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts index 4ae102eb299c45825a6ebc23016f343a8ed28380..d1886bc913f35ffb10177099d09722454563eebc 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,14 +13,20 @@ * limitations under the License. */ +// [Start napi_open_close_handle_scope_api] export const handleScopeTest: () => string; // napi_open_handle_scope、napi_close_handle_scope export const handleScope: () => string; +// [End napi_open_close_handle_scope_api] +// [Start napi_open_close_escapable_handle_scope_api] export const escapableHandleScopeTest: () => string; // napi_open_escapable_handle_scope、napi_close_escapable_handle_scope、napi_escape_handle +// [End napi_open_close_escapable_handle_scope_api] +// [Start napi_create_delete_reference_api] export const createReference: () => Object | void; // napi_add_finalizer export const useReference: () => Object | void; -export const deleteReference: () => string | void; \ No newline at end of file +export const deleteReference: () => string | void; +// [End napi_create_delete_reference] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/pages/Index.ets index 0408fbb5ef31d11facd29124175beb3678323ff1..4d86ca8563117a28404d3a418541002143cdd23e 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/pages/Index.ets @@ -48,32 +48,45 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiOpenHandleScope') { + // [Start ark_napi_open_close_handle_scope] // napi_open_handle_scope napi_close_handle_scope try { hilog.info(0x0000, 'testTag', 'Test Node-API handleScopeTest: %{public}s', testNapi.handleScopeTest()); hilog.info(0x0000, 'testTag', 'Test Node-API handleScope: %{public}s', testNapi.handleScope()); + // [StartExclude ark_napi_open_close_handle_scope] this.result = 'napiOpenHandleScopeSuccess'; + // [EndExclude ark_napi_open_close_handle_scope] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API handleScopeTest errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_open_close_handle_scope] this.result = 'napiOpenHandleScopeFail'; + // [EndExclude ark_napi_open_close_handle_scope] } + // [End ark_napi_open_close_handle_scope] } else if (item === '2.napiOpenEscapableHandleScope') { + // [Start ark_napi_open_close_escapable_handle_scope] // napi_open_escapable_handle_scope napi_close_escapable_handle_scope、napi_escape_handle try { hilog.info(0x0000, 'testTag', 'Test Node-API EscapableHandleScopeTest: %{public}s', testNapi.escapableHandleScopeTest()); + // [StartExclude ark_napi_open_close_escapable_handle_scope] this.result = 'napiOpenEscapableHandleScopeSuccess'; + // [EndExclude ark_napi_open_close_escapable_handle_scope] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API EscapableHandleScopeTest errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_open_close_escapable_handle_scope] this.result = 'napiOpenEscapableHandleScopeFail'; + // [EndExclude ark_napi_open_close_escapable_handle_scope] } + // [End ark_napi_open_close_escapable_handle_scope] } else if (item === '3.napiAddFinalizer') { + // [Start ark_napi_create_delete_reference] // napi_add_finalizer try { hilog.info(0x0000, 'testTag', 'Test Node-API createReference: %{public}s', @@ -82,13 +95,18 @@ struct Index { JSON.stringify(testNapi.useReference())); hilog.info(0x0000, 'testTag', 'Test Node-API deleteReference: %{public}s', testNapi.deleteReference()); + // [StartExclude ark_napi_create_delete_reference] this.result = 'napiAddFinalizerSuccess'; + // [EndExclude ark_napi_create_delete_reference] } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API ReferenceTest errorCode: %{public}s, errorMessage: %{public}s', error.code, error.message); + // [StartExclude ark_napi_create_delete_reference] this.result = 'napiAddFinalizerFail'; + // [EndExclude ark_napi_create_delete_reference] } + // [End ark_napi_create_delete_reference] } }) } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/napi_init.cpp index 98e0e564652c9f752189fe23df752aa46e595271..be73865685ad6cd3b7a88416d748eceb1010747f 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/napi_init.cpp @@ -15,6 +15,7 @@ #include "napi/native_api.h" +// [Start napi_coerce_to_bool] // napi_coerce_to_bool static napi_value CoerceToBool(napi_env env, napi_callback_info info) { @@ -28,7 +29,9 @@ static napi_value CoerceToBool(napi_env env, napi_callback_info info) // 返回强转之后的ArkTS boolean值 return result; } +// [End napi_coerce_to_bool] +// [Start napi_coerce_to_number] // napi_coerce_to_number static napi_value CoerceToNumber(napi_env env, napi_callback_info info) { @@ -41,7 +44,9 @@ static napi_value CoerceToNumber(napi_env env, napi_callback_info info) napi_coerce_to_number(env, args[0], &result); return result; } +// [End napi_coerce_to_number] +// [Start napi_coerce_to_object] // napi_coerce_to_object static napi_value CoerceToObject(napi_env env, napi_callback_info info) { @@ -54,7 +59,9 @@ static napi_value CoerceToObject(napi_env env, napi_callback_info info) napi_coerce_to_object(env, args[0], &obj); return obj; } +// [End napi_coerce_to_object] +// [Start napi_coerce_to_string] // napi_coerce_to_string static napi_value CoerceToString(napi_env env, napi_callback_info info) { @@ -67,7 +74,9 @@ static napi_value CoerceToString(napi_env env, napi_callback_info info) napi_coerce_to_string(env, args[0], &str); return str; } +// [End napi_coerce_to_string] +// [Start napi_get_boolean] // napi_get_boolean static napi_value GetBoolean(napi_env env, napi_callback_info info) { @@ -87,7 +96,9 @@ static napi_value GetBoolean(napi_env env, napi_callback_info info) // 返回结果 return returnValue; } +// [End napi_get_boolean] +// [Start napi_get_value_bool] // napi_get_value_bool static napi_value GetValueBool(napi_env env, napi_callback_info info) { @@ -105,7 +116,9 @@ static napi_value GetValueBool(napi_env env, napi_callback_info info) napi_get_boolean(env, boolC, &boolNapi); return boolNapi; } +// [End napi_get_value_bool] +// [Start napi_get_global] // napi_get_global static napi_value GetGlobal(napi_env env, napi_callback_info info) { @@ -114,7 +127,9 @@ static napi_value GetGlobal(napi_env env, napi_callback_info info) napi_get_global(env, &global); return global; } +// [End napi_get_global] +// [Start napi_get_null] // napi_get_null static napi_value GetNull(napi_env env, napi_callback_info info) { @@ -122,7 +137,9 @@ static napi_value GetNull(napi_env env, napi_callback_info info) napi_get_null(env, &nullValue); return nullValue; } +// [End napi_get_null] +// [Start napi_get_undefined] // napi_get_undefined static napi_value GetUndefined(napi_env env, napi_callback_info info) { @@ -142,6 +159,7 @@ static napi_value GetUndefined(napi_env env, napi_callback_info info) napi_get_boolean(env, isEqual, &result); return result; } +// [End napi_get_undefined] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/Index.d.ts index 73c69c9ac1ff12ff6a71aae2a5627404b13e8052..c1f99a1279c4d6cfce7f73d6573b38e400db5a53 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,20 +13,38 @@ * limitations under the License. */ +// [Start napi_coerce_to_bool_api] export const coerceToBool: (data: T) => boolean; // napi_coerce_to_bool +// [End napi_coerce_to_bool_api] +// [Start napi_coerce_to_number_api] export const coerceToNumber: (data: T) => number; // napi_coerce_to_number +// [End napi_coerce_to_number_api] +// [Start napi_coerce_to_object_api] export const coerceToObject: (data: T) => Object; // napi_coerce_to_object +// [End napi_coerce_to_object_api] +// [Start napi_coerce_to_string_api] export const coerceToString: (data: T) => string; // napi_coerce_to_string +// [End napi_coerce_to_string_api] +// [Start napi_get_boolean_api] export const getBoolean: (data: T, value: String) => boolean; // napi_get_boolean +// [End napi_get_boolean_api] +// [Start napi_get_value_bool_api] export const getValueBool: (value: boolean | string) => boolean | void; // napi_get_value_bool +// [End napi_get_value_bool_api] +// [Start napi_get_global_api] export const getGlobal: () => Object; // napi_get_global +// [End napi_get_global_api] +// [Start napi_get_null_api] export const getNull: () => null; // napi_get_null +// [End napi_get_null_api] +// [Start napi_get_undefined_api] export const getUndefined: (value: undefined) => boolean; // napi_get_undefined +// [End napi_get_undefined_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/pages/Index.ets index 49d462c07a632f51e5f325d8a57437a27103a089..c2c5c922289138ffe28d225db64fc0f809134d35 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/pages/Index.ets @@ -54,6 +54,7 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiCoerceToBool') { + // [Start ark_napi_coerce_to_bool] // napi_coerce_to_bool let value = testNapi.coerceToBool(0); let str = testNapi.coerceToBool('111111111'); @@ -68,8 +69,10 @@ struct Index { hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_bool:%{public}s', res); // false hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_bool:%{public}s', result); + // [End ark_napi_coerce_to_bool] this.result = 'napiCoerceToBoolSuccess'; } else if (item === '2.napiCoerceToNumber') { + // [Start ark_napi_coerce_to_number] // napi_coerce_to_number let value = testNapi.coerceToNumber('2556'); let str = testNapi.coerceToNumber('sssss'); @@ -79,8 +82,10 @@ struct Index { hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_number:%{public}d', str); // 返回的是1 hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_number:%{public}d', bool); + // [End ark_napi_coerce_to_number] this.result = 'napiCoerceToNumberSuccess'; } else if (item === '3.napiCoerceToObject') { + // [Start ark_napi_coerce_to_object] // napi_coerce_to_object let value = testNapi.coerceToObject('222222'); let result = testNapi.coerceToObject(111); @@ -90,8 +95,10 @@ struct Index { } else { hilog.info(0x0000, 'testTag', 'Node-API The value is not an object.'); } + // [End ark_napi_coerce_to_object] this.result = 'napiCoerceToObjectSuccess'; } else if (item === '4.napiCoerceToString') { + // [Start ark_napi_coerce_to_string] // napi_coerce_to_string let value = testNapi.coerceToString(212); let obj = new Object(); @@ -100,39 +107,50 @@ struct Index { hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_string:%{public}s', value); hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_string:%{public}s', typeof res); hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_string:%{public}s', bool); + // [End ark_napi_coerce_to_string] this.result = 'napiCoerceToStringSuccess'; } else if (item === '5.napiGetBoolean') { + // [Start ark_napi_get_boolean] // napi_get_boolean let value = testNapi.getBoolean(1, '1'); let data = testNapi.getBoolean('sss', '1'); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_boolean:%{public}s', value); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_boolean:%{public}s', data); + // [End ark_napi_get_boolean] this.result = 'napiGetBooleanSuccess'; } else if (item === '6.napiGetValueBool') { + // [Start ark_napi_get_value_bool] // napi_get_value_bool // // 分别传入布尔值和非布尔值检测接口,传入布尔值将返回原布尔值,传入其他类型返回undefined hilog.info(0x0000, 'Node-API', 'get_value_bool_not_bool %{public}s', testNapi.getValueBool('你好123')); hilog.info(0x0000, 'Node-API', 'get_value_bool_true %{public}s', testNapi.getValueBool(true)); hilog.info(0x0000, 'Node-API', 'get_value_bool_false %{public}s', testNapi.getValueBool(false)); + // [End ark_napi_get_value_bool] this.result = 'napiGetValueBoolSuccess'; } else if (item === '7.napiGetGlobal') { + // [Start ark_napi_get_global] // napi_get_global let globalObj = testNapi.getGlobal(); // 判断获取的global是否具有global的自身属性 hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_global:%{public}s', globalObj.hasOwnProperty!("undefined")); + // [End ark_napi_get_global] this.result = 'napiGetGlobalSuccess'; } else if (item === '8.napiGetNull') { + // [Start ark_napi_get_null] // napi_get_null let value = testNapi.getNull(); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_null:%{public}s', value); + // [End ark_napi_get_null] this.result = 'napiGetNullSuccess'; } else if (item === '9.napiGetUndefined') { + // [Start ark_napi_get_undefined] // napi_get_undefined let data: undefined = undefined; let value = testNapi.getUndefined(data); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_undefined:%{public}s', value); + // [End ark_napi_get_undefined] this.result = 'napiGetUndefinedSuccess'; } }) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/napi_init.cpp index 468a9d0e107e1dacba12afa01010639fce6d4df4..9e72fdba12e91d25a44542b63a2d5088157c213d 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/napi_init.cpp @@ -17,6 +17,7 @@ static constexpr int INT_ARGS_2 = 2; // 入参索引 +// [Start napi_is_promise] // napi_is_promise static napi_value IsPromise(napi_env env, napi_callback_info info) { @@ -37,7 +38,9 @@ static napi_value IsPromise(napi_env env, napi_callback_info info) napi_get_boolean(env, isPromise, &result); return result; } +// [End napi_is_promise] +// [Start napi_resolve_reject_deferred] // napi_resolve_deferred & napi_reject_deferred static napi_value CreatePromise(napi_env env, napi_callback_info info) { @@ -85,7 +88,7 @@ static napi_value ResolveRejectDeferred(napi_env env, napi_callback_info info) // 返回设置了resolve或reject的Promise对象 return promise; } - +// [End napi_resolve_reject_deferred] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/Index.d.ts index 2080cc960b743ea2426541f1f3ac6a37e2a7f2e2..2f3624c69c21e659798cd3f64d9e4ae64ad26875 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,8 +13,12 @@ * limitations under the License. */ +// [Start napi_is_promise_api] export const isPromise: (value: T) => boolean; // napi_is_promise +// [End napi_is_promise_api] +// [Start napi_resolve_reject_deferred_api] export const createPromise: () => boolean | void; // napi_resolve_deferred & napi_reject_deferred -export const resolveRejectDeferred: (resolve: string, reject: string, status: boolean) => Promise | void; \ No newline at end of file +export const resolveRejectDeferred: (resolve: string, reject: string, status: boolean) => Promise | void; +// [End napi_resolve_reject_deferred_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/pages/Index.ets index 2eb40f9a96dbc567f80a494caf6f04cdd4cbbc9d..b9820ecdd9cb094126273774290fa8a5e235a283 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/pages/Index.ets @@ -47,13 +47,16 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiIsPromise') { + // [Start ark_napi_is_promise] // napi_is_promise let value = Promise.resolve(); // 传入的对象为Promise时,返回true,否则返回false hilog.info(0x0000, 'Node-API', 'napi_is_promise %{public}s', testNapi.isPromise(value)); hilog.info(0x0000, 'Node-API', 'napi_is_promise string %{public}s', testNapi.isPromise('')); + // [End ark_napi_is_promise] this.result = 'napiIsPromiseSuccess'; } else if (item === '2.napiDeferred') { + // [Start ark_napi_resolve_reject_deferred] // napi_resolve_deferred & napi_reject_deferred // 创建promise如果创建成功返回true,创建失败返回false hilog.info(0x0000, 'Node-API', 'napi_create_promise %{public}s', testNapi.createPromise()); @@ -63,21 +66,30 @@ struct Index { testNapi.resolveRejectDeferred('success', 'fail', true) as Promise; promiseSuccess.then((res) => { hilog.info(0x0000, 'Node-API', 'get_resolve_deferred resolve %{public}s', res) + // [StartExclude ark_napi_resolve_reject_deferred] this.result = 'napiDeferredSuccess'; + // [EndExclude ark_napi_resolve_reject_deferred] }).catch((err: Error) => { hilog.info(0x0000, 'Node-API', 'get_resolve_deferred reject %{public}s', err) + // [StartExclude ark_napi_resolve_reject_deferred] this.result = 'napiDeferredFail'; + // [EndExclude ark_napi_resolve_reject_deferred] }) // Promise状态为false时设置reject,返回结果在catch函数中获得 let promiseFail: Promise = testNapi.resolveRejectDeferred('success', 'fail', false) as Promise; promiseFail.then((res) => { hilog.info(0x0000, 'Node-API', 'get_resolve_deferred resolve %{public}s', res) + // [StartExclude ark_napi_resolve_reject_deferred] this.result = 'napiDeferredSuccess'; + // [EndExclude ark_napi_resolve_reject_deferred] }).catch((err: Error) => { hilog.info(0x0000, 'Node-API', 'get_resolve_deferred reject %{public}s', err) + // [StartExclude ark_napi_resolve_reject_deferred] this.result = 'napiDeferredFail'; + // [EndExclude ark_napi_resolve_reject_deferred] }) + // [End ark_napi_resolve_reject_deferred] } }) } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/napi_init.cpp index 715c6c91cb9d3664d858a61816225e9844cb8c11..115c9bd479733b830d009b59c79611da1a297993 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/napi_init.cpp @@ -18,6 +18,7 @@ static constexpr int INT_ARG_2 = 2; // 入参索引 +// [Start napi_get_property_names] // napi_get_property_names static napi_value GetPropertyNames(napi_env env, napi_callback_info info) { @@ -34,7 +35,9 @@ static napi_value GetPropertyNames(napi_env env, napi_callback_info info) } return result; } +// [End napi_get_property_names] +// [Start napi_set_property] // napi_set_property static napi_value SetProperty(napi_env env, napi_callback_info info) { @@ -54,7 +57,9 @@ static napi_value SetProperty(napi_env env, napi_callback_info info) // 返回设置成功的object对象 return args[0]; } +// [End napi_set_property] +// [Start napi_get_property] // napi_get_property static napi_value GetProperty(napi_env env, napi_callback_info info) { @@ -71,7 +76,9 @@ static napi_value GetProperty(napi_env env, napi_callback_info info) } return result; } +// [End napi_get_property] +// [Start napi_has_property] // napi_has_property static napi_value HasProperty(napi_env env, napi_callback_info info) { @@ -93,7 +100,9 @@ static napi_value HasProperty(napi_env env, napi_callback_info info) napi_get_boolean(env, result, &returnResult); return returnResult; } +// [End napi_has_property] +// [Start napi_delete_property] // napi_delete_property // 从传入的Object对象中删除指定属性,返回是否删除成功的bool结果值 static napi_value DeleteProperty(napi_env env, napi_callback_info info) @@ -121,7 +130,9 @@ static napi_value DeleteProperty(napi_env env, napi_callback_info info) napi_get_boolean(env, result, &ret); return ret; } +// [End napi_delete_property] +// [Start napi_has_own_property] // napi_has_own_property static napi_value NapiHasOwnProperty(napi_env env, napi_callback_info info) { @@ -155,7 +166,9 @@ static napi_value NapiHasOwnProperty(napi_env env, napi_callback_info info) napi_get_boolean(env, hasProperty, &result); return result; } +// [End napi_has_own_property] +// [Start napi_set_named_property] // napi_set_named_property static napi_value NapiSetNamedProperty(napi_env env, napi_callback_info info) { @@ -184,7 +197,9 @@ static napi_value NapiSetNamedProperty(napi_env env, napi_callback_info info) // 返回设置了命名属性的对象newObj return newObj; } +// [End napi_set_named_property] +// [Start napi_get_named_property] // napi_get_named_property static napi_value NapiGetNamedProperty(napi_env env, napi_callback_info info) { @@ -207,7 +222,9 @@ static napi_value NapiGetNamedProperty(napi_env env, napi_callback_info info) // 返回result return result; } +// [End napi_get_named_property] +// [Start napi_has_named_property] // napi_has_named_property static napi_value NapiHasNamedProperty(napi_env env, napi_callback_info info) { @@ -232,7 +249,9 @@ static napi_value NapiHasNamedProperty(napi_env env, napi_callback_info info) napi_get_boolean(env, hasProperty, &result); return result; } +// [End napi_has_named_property] +// [Start napi_define_properties] // napi_define_properties static napi_value DefineMethodPropertiesExample(napi_env env, napi_callback_info info) { @@ -311,7 +330,9 @@ static napi_value CreateStringWithGetterSetter(napi_env env, napi_callback_info napi_define_properties(env, obj, 1, &desc); return obj; } +// [End napi_define_properties] +// [Start napi_get_all_property_names] // napi_get_all_property_names static napi_value GetAllPropertyNames(napi_env env, napi_callback_info info) { @@ -332,6 +353,7 @@ static napi_value GetAllPropertyNames(napi_env env, napi_callback_info info) return result; } +// [End napi_get_all_property_names] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/Index.d.ts index 1c243cbc39b5bc6ef4c63ed37fecfedb82b2ce88..e2f3372d4c6df3002b515aaf21c5747252096900 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,25 +13,44 @@ * limitations under the License. */ +// [Start napi_get_property_names_api] export const getPropertyNames: (obj: Object) => Array | void; // napi_get_property_names +// [End napi_get_property_names_api] +// [Start napi_set_property_api] export const setProperty: (obj: Object, key: String, value: string) => Object | void; // napi_set_property +// [End napi_set_property_api] +// [Start napi_get_property_api] export const getProperty: (obj: Object, key: string) => string | void; // napi_get_property +// [End napi_get_property_api] +// [Start napi_has_property_api] export const hasProperty: (obj: Object, key: number | string) => boolean | void; // napi_has_property +// [End napi_has_property_api] +// [Start napi_delete_property_api] export const deleteProperty: (obj: Object, key: string) => boolean; // napi_delete_property +// [End napi_delete_property_api] +// [Start napi_has_own_property_api] export const napiHasOwnProperty: (obj: Object, key: string) => boolean | void; // napi_has_own_property +// [End napi_has_own_property_api] +// [Start napi_set_named_property_api] export const napiSetNamedProperty: (key: string) => Object | void; // napi_set_named_property +// [End napi_set_named_property_api] +// [Start napi_get_named_property_api] export const napiGetNamedProperty: (obj: Object, key: string) => boolean | number | string | Object | void; // napi_get_named_property +// [End napi_get_named_property_api] +// [Start napi_has_named_property_api] export const napiHasNamedProperty: (obj: Object, key: string) => boolean | void; // napi_has_named_property +// [End napi_has_named_property_api] +// [Start napi_define_properties_api] export class DefineMethodObj { defineMethodPropertiesExample: Function; } @@ -50,5 +69,8 @@ export const defineMethodProperties: () => DefineMethodObj; // napi_define_prope export const defineStringProperties: () => DefineStringObj; export const createStringWithGetterSetter: () => DefineGetterSetterObj; +// [End napi_define_properties_api] -export const getAllPropertyNames: (obj: Object) => Array | void; // napi_get_all_property_names \ No newline at end of file +// [Start napi_get_all_property_names_api] +export const getAllPropertyNames: (obj: Object) => Array | void; // napi_get_all_property_names +// [End napi_get_all_property_names_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/Index.ets index 1c7881dd93a22cea2c79c03bdd6cfbb9c8c5e88d..a8e26c51f7a544c359f25a21fbaad99fec02da59 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/Index.ets @@ -58,6 +58,7 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiGetPropertyNames') { + // [Start ark_napi_get_property_names] // napi_get_property_names try { class Obj { @@ -72,14 +73,20 @@ struct Index { propertyNames[0]); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_property_names: %{public}s', propertyNames[1]); + // [StartExclude ark_napi_get_property_names] this.result = 'napiGetPropertyNamesSuccess'; + // [EndExclude ark_napi_get_property_names] } } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_property_names error: %{public}s', error.message); + // [StartExclude ark_napi_get_property_names] this.result = 'napiGetPropertyNamesFail'; + // [EndExclude ark_napi_get_property_names] } + // [End ark_napi_get_property_names] } else if (item === '2.napiSetProperty') { + // [Start ark_napi_set_property] // napi_set_property try { class Obj { @@ -91,12 +98,18 @@ struct Index { let result = testNapi.setProperty(obj, 'code', 'hi'); hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_property: %{public}s', JSON.stringify(result)); + // [StartExclude ark_napi_set_property] this.result = 'napiSetPropertySuccess'; + // [EndExclude ark_napi_set_property] } catch (error) { hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_property error: %{public}s', error.message); + // [StartExclude ark_napi_set_property] this.result = 'napiSetPropertyFail'; + // [EndExclude ark_napi_set_property] } + // [End ark_napi_set_property] } else if (item === '3.napiGetProperty') { + // [Start ark_napi_get_property] // napi_get_property try { class Obj { @@ -107,12 +120,18 @@ struct Index { let obj: Obj = { data: 0, message: 'hello world' }; hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_property: %{public}s', testNapi.getProperty(obj, 'message')); + // [StartExclude ark_napi_get_property] this.result = 'napiGetPropertySuccess'; + // [EndExclude ark_napi_get_property] } catch (error) { hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_property error: %{public}s', error.message); + // [StartExclude ark_napi_get_property] this.result = 'napiGetPropertyFail'; + // [EndExclude ark_napi_get_property] } + // [End ark_napi_get_property] } else if (item === '4.napiHasProperty') { + // [Start ark_napi_has_property] // napi_has_property try { class Obj { @@ -127,11 +146,16 @@ struct Index { JSON.stringify(resultFalse)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_property: %{public}s', JSON.stringify(resultTrue)); + // [StartExclude ark_napi_has_property] this.result = 'napiHasPropertySuccess'; + // [EndExclude ark_napi_has_property] } catch (error) { hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_property error: %{public}s', error.message); + // [StartExclude ark_napi_has_property] this.result = 'napiHasPropertyFail'; + // [EndExclude ark_napi_has_property] } + // [End ark_napi_has_property] } else if (item === '5.napiDeleteProperty') { // napi_delete_property napiDeleteProperty(); @@ -141,12 +165,15 @@ struct Index { napiHasOwnProperty(); this.result = 'napiHasOwnPropertySuccess'; } else if (item === '7.napiSetNamedProperty') { + // [Start ark_napi_set_named_property] // napi_set_named_property let obj = testNapi.napiSetNamedProperty('myProperty'); let objAsString = JSON.stringify(obj); hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_named_property: %{public}s', objAsString); + // [End ark_napi_set_named_property] this.result = 'napiSetNamedPropertySuccess'; } else if (item === '8.napiGetNamedProperty') { + // [Start ark_napi_get_named_property] // napi_get_named_property interface NestedObj { nestedStr: string; @@ -177,8 +204,10 @@ struct Index { hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_named_property : %{public}s', objAsString); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_named_property : %{public}s', testNapi.napiGetNamedProperty(obj, 'null')); + // [End ark_napi_get_named_property] this.result = 'napiGetNamedPropertySuccess'; } else if (item === '9.napiHasNamedProperty') { + // [Start ark_napi_has_named_property] // napi_has_named_property interface NestedObj { nestedStr: string; @@ -204,8 +233,10 @@ struct Index { testNapi.napiHasNamedProperty(obj, 'nestedStr')); hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_named_property : %{public}s', testNapi.napiHasNamedProperty(obj, 'bol')); + // [End ark_napi_has_named_property] this.result = 'napiHasNamedPropertySuccess'; } else if (item === '10.napiDefineProperties') { + // [Start ark_napi_define_properties] // napi_define_properties // 定义method类型的属性 hilog.info(0x0000, 'testTag', 'Test Node-API define_method_properties:%{public}d', @@ -222,8 +253,10 @@ struct Index { hilog.info(0x0000, 'testTag', 'Test Node-API setter::%{public}s ', testNapi.createStringWithGetterSetter() .setterCallback('set data')); + // [End ark_napi_define_properties] this.result = 'napiDefinePropertiesSuccess'; } else if (item === '11.napiGetAllPropertyNames') { + // [Start ark_napi_get_all_property_names] // napi_get_all_property_names try { class Obj { @@ -235,12 +268,17 @@ struct Index { let propertyNames = testNapi.getAllPropertyNames(obj); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_all_property_names: %{public}s', JSON.stringify(propertyNames)); + // [StartExclude ark_napi_get_all_property_names] this.result = 'napiGetAllPropertyNamesSuccess'; + // [EndExclude ark_napi_get_all_property_names] } catch (error) { hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_all_property_names error: %{public}s', error.message); + // [StartExclude ark_napi_get_all_property_names] this.result = 'napiGetAllPropertyNamesFail'; + // [EndExclude ark_napi_get_all_property_names] } + // [End ark_napi_get_all_property_names] } }) } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiDeleteProperty.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiDeleteProperty.ts index a0d21ac804a9d932b7044f2c2aef4121fa31ea18..9c3a8b3383117625d4b182f8fe8f8895c6309f6b 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiDeleteProperty.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiDeleteProperty.ts @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start ark_napi_delete_property] import testNapi from 'libentry.so'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -32,4 +33,5 @@ export function napiDeleteProperty() { }) hilog.info(0x0000, 'testTag', 'Test Node-API napi_delete_property config: %{public}s', testNapi.deleteProperty(obj, 'config')); -} \ No newline at end of file +} +// [End ark_napi_delete_property] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiHasOwnProperty.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiHasOwnProperty.ts index 9fdde4e8ca393f394f24a30f630275d5aa094ffa..ada41ab3209c4e78b75f9ff8473af5c9380463bc 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiHasOwnProperty.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiHasOwnProperty.ts @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start ark_napi_has_own_property] import { hilog } from '@kit.PerformanceAnalysisKit'; import testNapi from 'libentry.so'; @@ -25,4 +26,5 @@ export function napiHasOwnProperty() { testNapi.napiHasOwnProperty(myObj, 'myProperty')); hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_own_property inherited: %{public}s', testNapi.napiHasOwnProperty(myObj, 'inheritedProperty')); -} \ No newline at end of file +} +// [End ark_napi_has_own_property] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/napi_init.cpp index 6d5f43fc01f0dc95ae2361fccf10889b16690903..40da20536c6dd2181b10e5c06b7ec00d6586cc45 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/napi_init.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start napi_async_open_close_callback_scope] #include "napi/native_api.h" static constexpr int INT_ARG_3 = 3; // 入参索引 @@ -68,6 +69,7 @@ static napi_value AsynchronousWork(napi_env env, napi_callback_info info) napi_async_destroy(env, context); return result; } +// [End napi_async_open_close_callback_scope] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/Index.d.ts index 54873ce49e5628c1772897b21d0ee58ca53cd446..9c9248788fc85a8c6867c39e5eaf52d45dae4874 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,4 +13,6 @@ * limitations under the License. */ -export const asynchronousWork: (object: Object, obj: Object, fun: Function, num: number) => number | void; \ No newline at end of file +// [Start napi_async_open_close_callback_scope_api] +export const asynchronousWork: (object: Object, obj: Object, fun: Function, num: number) => number | void; +// [End napi_async_open_close_callback_scope_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/pages/Index.ets index b1cb7da5da5f89f997c3f9353009a00d0cdfff1e..e4e96d5ce3e21044466eabdc935a27907f9ee299 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/pages/Index.ets @@ -13,10 +13,12 @@ * limitations under the License. */ +// [Start ark_napi_async_open_close_callback_scope] import { hilog } from '@kit.PerformanceAnalysisKit'; import testNapi from 'libentry.so'; import process from '@ohos.process'; +// [StartExclude ark_napi_async_open_close_callback_scope] @Entry @Component struct Index { @@ -39,6 +41,7 @@ struct Index { .borderRadius(30) .backgroundColor(Color.White) .onClick(() => { + // [EndExclude ark_napi_async_open_close_callback_scope] try { hilog.info(0x0000, 'testTag', 'Test Node-API asynchronousWork: %{public}d', testNapi.asynchronousWork({}, process.ProcessManager, (num: number) => { @@ -49,6 +52,7 @@ struct Index { hilog.error(0x0000, 'testTag', 'Test Node-API asynchronousWork error: %{public}s', error.message); this.result = 'customAsyncFail'; } + // [End ark_napi_async_open_close_callback_scope] }) } }.scrollBar(BarState.Off) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/napi_init.cpp index 065c0919da52c0449300201f11b71bbcf21a41c0..ca0393188e61dae127322c2ddb3d6b6b61010a94 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/napi_init.cpp @@ -19,6 +19,7 @@ static const int MAX_BUFFER_SIZE = 128; +// [Start napi_get_value_string_utf8] static napi_value GetValueStringUtf8(napi_env env, napi_callback_info info) { size_t argc = 1; @@ -43,7 +44,9 @@ static napi_value GetValueStringUtf8(napi_env env, napi_callback_info info) }; return result; } +// [End napi_get_value_string_utf8] +// [Start napi_create_string_utf8] static napi_value CreateStringUtf8(napi_env env, napi_callback_info info) { const char *str = u8"你好, World!, successes to create UTF-8 string! 111"; @@ -56,7 +59,9 @@ static napi_value CreateStringUtf8(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_string_utf8] +// [Start napi_get_value_string_utf16] static napi_value GetValueStringUtf16(napi_env env, napi_callback_info info) { size_t argc = 1; @@ -76,7 +81,9 @@ static napi_value GetValueStringUtf16(napi_env env, napi_callback_info info) // 返回结果 return result; } +// [End napi_get_value_string_utf16] +// [Start napi_create_string_utf16] static napi_value CreateStringUtf16(napi_env env, napi_callback_info info) { const char16_t *str = u"你好, World!, successes to create UTF-16 string! 111"; @@ -89,7 +96,9 @@ static napi_value CreateStringUtf16(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_string_utf16] +// [Start napi_get_value_string_latin1] static napi_value GetValueStringLatin1(napi_env env, napi_callback_info info) { size_t argc = 1; @@ -106,7 +115,9 @@ static napi_value GetValueStringLatin1(napi_env env, napi_callback_info info) napi_create_string_latin1(env, buf, length, &napi_Res); return napi_Res; } +// [End napi_get_value_string_latin1] +// [Start napi_create_string_latin1] static napi_value CreateStringLatin1(napi_env env, napi_callback_info info) { const char *str = "Hello, World! éçñ, successes to create Latin1 string! 111"; @@ -120,6 +131,7 @@ static napi_value CreateStringLatin1(napi_env env, napi_callback_info info) } return result; } +// [End napi_create_string_latin1] EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/Index.d.ts index 6f4af695d6c8a1811f7d3c081c34871898bf44f3..905a15b94b99fd538f941e31bf2548463e4df799 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,14 +13,26 @@ * limitations under the License. */ +// [Start napi_get_value_string_utf8_api] export const getValueStringUtf8: (param: string | number) => string | void; +// [End napi_get_value_string_utf8_api] +// [Start napi_create_string_utf8_api] export const createStringUtf8: () => string | void; +// [End napi_create_string_utf8_api] +// [Start napi_get_value_string_utf16_api] export const getValueStringUtf16: (data: string) => string; +// [End napi_get_value_string_utf16_api] +// [Start napi_create_string_utf16_api] export const createStringUtf16: () => string | void; +// [End napi_create_string_utf16_api] +// [Start napi_get_value_string_latin1_api] export const getValueStringLatin1: (param: number | string) => string | void; +// [End napi_get_value_string_latin1_api] -export const createStringLatin1: () => string | void; \ No newline at end of file +// [Start napi_create_string_latin1_api] +export const createStringLatin1: () => string | void; +// [End napi_create_string_latin1_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/pages/Index.ets index 9542523cea693e9080afc43d94434c6d02d5e4db..01466b983d3f514bf81df8212e8e56e4c1628540 100755 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/pages/Index.ets @@ -46,17 +46,26 @@ struct Index { if (item === 'Reset Result Message') { this.result = ''; } else if (item === '1.napiString') { + // [Start ark_napi_get_value_string_utf8] // 分别传入字符和非字符检测接口,传入字符串类型的数据将返回原字符串,传入其他类型返回undefined hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_utf8_string %{public}s', testNapi.getValueStringUtf8('aaBC+-$%^你好123')); hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_utf8_not_string %{public}s', testNapi.getValueStringUtf8(50)); + // [End ark_napi_get_value_string_utf8] + // [Start ark_napi_create_string_utf8] hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_utf8:%{public}s', testNapi.createStringUtf8()); + // [End ark_napi_create_string_utf8] + // [Start ark_napi_get_value_string_utf16] let result = testNapi.getValueStringUtf16('hello,'); hilog.info(0x0000, 'testTag', 'Node-API napi_get_value_string_utf16:%{public}s', result); + // [End ark_napi_get_value_string_utf16] + // [Start ark_napi_create_string_utf16] hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_utf16:%{public}s ', testNapi.createStringUtf16()); + // [End ark_napi_create_string_utf16] + // [Start ark_napi_get_value_string_latin1] // 传入非字符型数据,函数返回undefined hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_latin1_not_string %{public}s', testNapi.getValueStringLatin1(10)); @@ -66,8 +75,11 @@ struct Index { // 传入其他字符,不会乱码 hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_latin1_string %{public}s', testNapi.getValueStringLatin1('abo ABP=-&*/')); + // [End ark_napi_get_value_string_latin1] + // [Start ark_napi_create_string_latin1] hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_latin1:%{public}s', testNapi.createStringLatin1()); + // End ark_napi_create_string_latin1] this.result = 'napiStringSuccess'; } }) diff --git a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets index b47e7359122f2fce22ae618f984455637a45f77c..8cb5d2a71f9063a82cbfcc6dbb2e9728cd728b52 100644 --- a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets +++ b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets @@ -21,6 +21,7 @@ export struct CreateButton { return getContext(this).resourceManager.getStringSync(resource); } + // [Start create_button] build() { NavDestination() { Column({ space: 12 }) { @@ -51,4 +52,5 @@ export struct CreateButton { .backgroundColor('#f1f2f3') .title(this.resourceToString($r('app.string.CreateButton_title'))) } + // [End create_button] } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets index 243cffb38a64025a7e1a1c7e818843adca7d1c99..a1d19f4f9910a3ed9f50198bb9ef855ae2c4abd6 100644 --- a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets +++ b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets @@ -31,40 +31,50 @@ export struct SetButtonType { title: $r('app.string.SetButtonType_titleOne'), description: $r('app.string.SetButtonType_descriptionOne') }) { + // [Start set_button_type_capsule] Button('Button', { type: ButtonType.Capsule }) .id('Capsule') + // [End set_button_type_capsule] } ComponentCard({ title: $r('app.string.SetButtonType_titleTwo'), description: $r('app.string.SetButtonType_descriptionTwo') }) { + // [Start set_button_type_circle] Button('Button', { type: ButtonType.Circle }) .id('Circle') .width(80) + // [End set_button_type_circle] } ComponentCard({ title: $r('app.string.SetButtonType_titleThree'), description: $r('app.string.SetButtonType_descriptionThree') }) { + // [Start set_button_type_normal] Button('Button', { type: ButtonType.Normal }) .id('Normal') + // [End set_button_type_normal] } ComponentCard({ title: $r('app.string.SetButtonType_titleFour'), description: $r('app.string.SetButtonType_descriptionFour') }) { + // [Start set_button_type_four] Button('Button', { type: ButtonType.ROUNDED_RECTANGLE }) .id('Round') + // [End set_button_type_four] } } .width('100%') .height('100%') .padding({ left: 12, right: 12 }) } + // [Start set_button_type_title] .backgroundColor('#f1f2f3') .title(this.resourceToString($r('app.string.SetButtonType_title'))) + // [End set_button_type_title] } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/radio/RadioSample.ets b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/radio/RadioSample.ets index f6285254271822fc892a8d4964550e0205f0e2ae..e0e81c3aaa99a2f352e979ba91b2f34fcd33d97c 100644 --- a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/radio/RadioSample.ets +++ b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/radio/RadioSample.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start set_radio_event] import { promptAction } from '@kit.ArkUI'; @Entry @@ -83,4 +84,5 @@ export struct RadioSample { .backgroundColor('#f1f2f3') .title(this.resourceToString($r('app.string.RadioSample_title'))) } -} \ No newline at end of file +} +// [End set_radio_event] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/CreateToggle.ets b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/CreateToggle.ets index 91dd2d56afcdbd750cbaad73f9cf1911d853ba19..689e07ceb72a6c59ee96949cd83d9fee744deb22 100644 --- a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/CreateToggle.ets +++ b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/CreateToggle.ets @@ -30,20 +30,25 @@ export struct CreateToggle { ComponentCard({ title: 'ToggleType is Checkbox', }) { + // [Start create_checkbox_without_components] Toggle({ type: ToggleType.Checkbox, isOn: false }).id('toggle1') Toggle({ type: ToggleType.Checkbox, isOn: true }).id('toggle2') + // [End create_checkbox_without_components] } ComponentCard({ title: 'ToggleType is Switch', }) { + // [Start create_switch_without_components] Toggle({ type: ToggleType.Switch, isOn: false }).id('toggle3') Toggle({ type: ToggleType.Switch, isOn: true }).id('toggle4') + // [End create_switch_without_components] } ComponentCard({ title: 'ToggleType is Button', }) { + // [Start create_button_components] Toggle({ type: ToggleType.Button, isOn: false }) { Text('status button') .fontColor('#182431') @@ -55,6 +60,7 @@ export struct CreateToggle { .fontColor('#182431') .fontSize(12) }.width(100).id('toggle6') + // [End create_button_components] } } .width('100%') diff --git a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCaseExample.ets b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCaseExample.ets index 4fe1617145d6ff43543388050bf3a63eb649c8d6..002028d643c6c2a8a61556559fcf4f1f6b4a4c4d 100644 --- a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCaseExample.ets +++ b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCaseExample.ets @@ -25,6 +25,7 @@ export struct ToggleSample { return getContext(this).resourceManager.getStringSync(resource); } + // [Start create_toggle_events] build() { NavDestination() { Column({ space: 8 }) { @@ -60,4 +61,5 @@ export struct ToggleSample { .backgroundColor('#f1f2f3') .title(this.resourceToString($r('app.string.ToggleCaseExample_title'))) } + // [End create_toggle_events] } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCustomStyle.ets b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCustomStyle.ets index c6a8d8ffb1982525211d93a7d5d75e383821a205..7a091ed85163290138733388814c91806537f60d 100644 --- a/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCustomStyle.ets +++ b/code/DocsSample/ArkUISample/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCustomStyle.ets @@ -31,32 +31,46 @@ export struct CustomStyle { title: $r('app.string.ToggleCustomStyle_titleOne'), description: $r('app.string.ToggleCustomStyle_descriptionOne') }) { + // [Start set_toggle_background_color] Toggle({ type: ToggleType.Button, isOn: true }) { Text('status button') .fontColor(Color.White) .fontSize(12) }.width(100) .selectedColor(Color.Pink) + // [StartExclude set_toggle_background_color] .id('toggle1') + // [EndExclude set_toggle_background_color] Toggle({ type: ToggleType.Checkbox, isOn: true }) .selectedColor(Color.Pink) + // [StartExclude set_toggle_background_color] .id('toggle2') + // [EndExclude set_toggle_background_color] Toggle({ type: ToggleType.Switch, isOn: true }) .selectedColor(Color.Pink) + // [StartExclude set_toggle_background_color] .id('toggle3') + // [EndExclude set_toggle_background_color] + // [End set_toggle_background_color] } ComponentCard({ title: $r('app.string.ToggleCustomStyle_titleTwo'), description: $r('app.string.ToggleCustomStyle_descriptionTwo') }) { + // [Start set_switch_point_color] Toggle({ type: ToggleType.Switch, isOn: false }) .switchPointColor(Color.Pink) + // [StartExclude set_switch_point_color] .id('toggle4') + // [EndExclude set_switch_point_color] Toggle({ type: ToggleType.Switch, isOn: true }) .switchPointColor(Color.Pink) + // [StartExclude set_switch_point_color] .id('toggle5') + // [EndExclude set_switch_point_color] + // [End set_switch_point_color] } } .width('100%') diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/CreateCustomDialog.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/CreateCustomDialog.ets index c249fbd4d283c2a6c3ec8dd0be63aca6e69112ab..38b3a3a7cf3802f039e01bddc54aa7f4d87f4fda 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/CreateCustomDialog.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/CreateCustomDialog.ets @@ -16,6 +16,7 @@ import { PromptActionClass } from '../../common/PromptActionClass'; import { ComponentContent } from '@kit.ArkUI'; +// [Start create_custom_dialog_01] @CustomDialog struct CustomDialogExample { controller: CustomDialogController = new CustomDialogController({ @@ -34,7 +35,9 @@ struct CustomDialogExample { }) } } +// [End create_custom_dialog_01] +// [Start click_event_pop_dialog] @Entry @Component export struct CreateDialog { @@ -61,4 +64,5 @@ export struct CreateDialog { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_create')) } + // [End click_event_pop_dialog] } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogAnimation.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogAnimation.ets index 09484b44ad3ea2d790a59074ad3274a93b8bb683..ef1db50a608622474ab3f5bb6ee194aef17914cf 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogAnimation.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogAnimation.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start set_dialog_animation] @CustomDialog struct CustomDialogExample { controller?: CustomDialogController; @@ -74,4 +75,5 @@ export struct DialogAnimation { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_Animation1')) } -} \ No newline at end of file +} +// [End set_dialog_animation] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction.ets index 9cd96af5b2b776050e930f6fc3c97fbd4c1fdead..825f321088c3ab12c74b8c2e2da45d79afc7a1c1 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction.ets @@ -16,6 +16,7 @@ import { PromptActionClass } from '../../common/PromptActionClass'; import { ComponentContent } from '@kit.ArkUI'; +// [Start custom_dialog_build_button] @CustomDialog struct CustomDialogExample { cancel?: () => void; @@ -62,7 +63,9 @@ struct CustomDialogExample { } } +// [End custom_dialog_build_button] +// [Start dialog_constructor_accept] @Entry @Component export struct DialogInteraction { @@ -104,4 +107,5 @@ export struct DialogInteraction { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_interaction')) } + // [End dialog_constructor_accept] } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction1.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction1.ets index b9080bc7ef59d1c420e3d8991f766bd6867d8a0d..3cacbb789607cf2a6600caf083824e45f95a2e68 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction1.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogInteraction1.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start dialog_route_jump] @CustomDialog struct CustomDialogExample { @Link textValue: string; @@ -147,4 +148,5 @@ export struct DialogInteraction1 { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_interaction1')) } -} \ No newline at end of file +} +// [End dialog_route_jump] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogStyle.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogStyle.ets index 2475a81a05c5a6aa8f3d4b26c3b0bd76d1710641..0c5de5322fb338d46f715839f40a9b362098e301 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogStyle.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/DialogStyle.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start set_dialog_style] @CustomDialog struct CustomDialogExample { controller?: CustomDialogController; @@ -82,4 +83,5 @@ export struct DialogStyle { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_style')) } -} \ No newline at end of file +} +// [End set_dialog_style] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/NestDialog.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/NestDialog.ets index 32f1356c419d36b2e168e9641b3bc27b8d83cb3e..5ce2b1ffb785052718478ba3a1b73d2d725860ba 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/NestDialog.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/customdialog/NestDialog.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start set_dialog_nest] @CustomDialog struct CustomDialogExampleTwo { controllerTwo?: CustomDialogController; @@ -167,4 +168,5 @@ export struct NestDialog { .backgroundColor('#f1f2f3') .title($r('app.string.CustomDialog_nest')) } -} \ No newline at end of file +} +// [End set_dialog_nest] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/opencustomdialog/openCustomDialog.ets b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/opencustomdialog/openCustomDialog.ets index f2b78545ff9d8a63af5c764800da8daa8531f188..de6e72542c5bd4ab2a75463402557a7b3ed7c507 100644 --- a/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/opencustomdialog/openCustomDialog.ets +++ b/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/opencustomdialog/openCustomDialog.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start open_close_component_content] import { PromptActionClass } from '../../common/PromptActionClass'; import { ComponentContent } from '@kit.ArkUI'; @@ -126,4 +127,5 @@ export struct openCustomDialog { .backgroundColor('#f1f2f3') .title($r('app.string.open_customDialog')) } -} \ No newline at end of file +} +// [End open_close_component_content] \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/Bluetooth/SerialCommunication/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ConnectivityKit/Bluetooth/SerialCommunication/entry/src/main/ets/pages/Index.ets index cea579ee8f92c9b5a23085e0ce5503c1382d2b84..6de803f0c4db13a20fa302aea057ac35bd7c4ee5 100644 --- a/code/DocsSample/ConnectivityKit/Bluetooth/SerialCommunication/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ConnectivityKit/Bluetooth/SerialCommunication/entry/src/main/ets/pages/Index.ets @@ -67,6 +67,7 @@ struct serialCommunication { }).height('40vp').width('70%') }.width('80%') + // [Start server_write_client] Button('listenSocket') .width('50%') .id('listenSocket') @@ -251,9 +252,10 @@ struct serialCommunication { console.info(TAG, 'sppCloseClientSocket success'); this.toastReport.showResult('sppCloseClientSocket success'); }) + // [End server_write_client] } .width('100%') .height('100%') .backgroundColor('#E6F7FF') } -} \ No newline at end of file +} diff --git a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets index fc8b1e1d4bbbe74e6166bcf6340d8b91cd92a628..ed4ff024c6904ff5b27a5850119cb7f1bebe22f2 100644 --- a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +// [Start front_hce_swipe] import { cardEmulation } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -92,4 +93,5 @@ export default class EntryAbility extends UIAbility { } } } -} \ No newline at end of file +} +// [End front_hce_swipe] \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/module.json5 b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/module.json5 index 53fd0f2b1275fb7d8c81dc86c96d37504fd2eaa8..2cfceef20355988871217991d41ec936ddcfd544 100644 --- a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/module.json5 +++ b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry/src/main/module.json5 @@ -27,6 +27,7 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + // [Start front_hce_swipe] "abilities": [ { "name": "EntryAbility", @@ -59,6 +60,7 @@ "reason": "$string:app_name", } ], + // [End front_hce_swipe] "extensionAbilities": [ { "name": "EntryBackupAbility", diff --git a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/ets/entry1ability/Entry1Ability.ets b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/ets/entry1ability/Entry1Ability.ets index aa74877badfb699324f5477a5c4f9b77f3b0ddf7..8dbec8e68ed84802e8029d0fb3cf673d770ecb7b 100644 --- a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/ets/entry1ability/Entry1Ability.ets +++ b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/ets/entry1ability/Entry1Ability.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start back_hce_swipe] import { cardEmulation } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -82,4 +83,5 @@ export default class EntryAbility extends UIAbility { } } } -} \ No newline at end of file +} +// [Start back_hce_swipe] \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/module.json5 b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/module.json5 index c6ada203f0ae8ef00a8695e418396459bf0c42d5..38684d0ac45a6f49987eb05e5d7a1827318f0e02 100644 --- a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/module.json5 +++ b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/entry1/src/main/module.json5 @@ -25,6 +25,7 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + // [Start back_hce_swipe] "abilities": [ { "name": "Entry1Ability", @@ -67,6 +68,7 @@ "reason": "$string:app_name", } ], + // [End back_hce_swipe] "extensionAbilities": [ { "name": "Entry1BackupAbility", diff --git a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/ets/entryability/EntryAbility.ets index 7a39747af998d8dc03073665e467c4ed96d9371b..34f99d8764b89ca38873ff28cf9322461d6ad008 100644 --- a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/ets/entryability/EntryAbility.ets @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +// [Start front_get_nfc_tag] import { tag } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -131,4 +132,5 @@ export default class EntryAbility extends UIAbility { } } } -} \ No newline at end of file +} +// [End front_get_nfc_tag] \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/module.json5 b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/module.json5 index 36701bff5e4b7db3e40fd98912cc9669f79317d0..87decab6f7ac9bda49589578fa100e0cdafbdb89 100644 --- a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/module.json5 +++ b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry/src/main/module.json5 @@ -27,6 +27,7 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + // {Start front_get_nfc_tag] "abilities": [ { "name": "EntryAbility", @@ -57,6 +58,7 @@ "reason": "$string:app_name", } ], + // [End front_get_nfc_tag] "extensionAbilities": [ { "name": "EntryBackupAbility", diff --git a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/ets/entryability/EntryAbility.ets index 199867b3f18085135137566ba976baabcdca8cc9..b04899d90fe30abc7c97265ce74ed137507d148c 100644 --- a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/ets/entryability/EntryAbility.ets @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +// [Start back_get_nfc_tag] import { tag } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -89,4 +90,5 @@ export default class EntryAbility extends UIAbility { return; } } -} \ No newline at end of file +} +// [End back_get_nfc_tag] \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/module.json5 b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/module.json5 index 734f2658cb744d2fdfdca02c2672b0bf23469ec1..22892b5f3d62846171900494d250662792c59271 100644 --- a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/module.json5 +++ b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/entry1/src/main/module.json5 @@ -25,6 +25,7 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + // [Start back_get_nfc_tag] "abilities": [ { "name": "EntryAbility", @@ -65,6 +66,7 @@ "reason": "$string:app_name", } ], + // [End back_get_nfc_tag] "extensionAbilities": [ { "name": "Entry1BackupAbility", diff --git a/code/DocsSample/ConnectivityKit/NFC/SecureElement/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ConnectivityKit/NFC/SecureElement/entry/src/main/ets/entryability/EntryAbility.ets index 0a6a087ff5d5077714e4fe4888b39d202b356b33..a680111a4717a0a59153a21b5a944793178513f0 100644 --- a/code/DocsSample/ConnectivityKit/NFC/SecureElement/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ConnectivityKit/NFC/SecureElement/entry/src/main/ets/entryability/EntryAbility.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start access_security_unit] import { omapi } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -120,3 +121,4 @@ export default class EntryAbility extends UIAbility { } } +// [End access_security_unit] diff --git a/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pConnect.ets b/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pConnect.ets index 708757a74a1712f7b2421c58de005f5a01540213..d71da61e3784d8725ee5039d23ed59ee01b816e2 100644 --- a/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pConnect.ets +++ b/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pConnect.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start create_p2p_connect] import { wifiManager } from '@kit.ConnectivityKit'; export class P2PConnectMananger { @@ -79,3 +80,4 @@ export class P2PConnectMananger { let p2pConnectManager = new P2PConnectMananger(); export default p2pConnectManager as P2PConnectMananger; +// [End create_p2p_connect] diff --git a/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pability.ets b/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pability.ets index 01c764fd88c4294b683043da62772251f15a0f05..d3c62deba090a1088bcb3cb05fcfbd7964cc776c 100644 --- a/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pability.ets +++ b/code/DocsSample/ConnectivityKit/Wlan/entry/src/main/ets/entryability/p2pability.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start create_delete_p2p_group] import { wifiManager } from '@kit.ConnectivityKit'; export class P2PManager { @@ -51,4 +52,5 @@ export class P2PManager { // 默认导出let let p2pManager = new P2PManager(); -export default p2pManager as P2PManager; \ No newline at end of file +export default p2pManager as P2PManager; +// [End create_delete_p2p_group] \ No newline at end of file diff --git a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothAdvertising.ets b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothAdvertising.ets index 0c1f374b6e9cfd99f8274fa0fdf9f7be8e4421fa..bcba2b8db0f36d93056e5cad460cf48707182874 100644 --- a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothAdvertising.ets +++ b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothAdvertising.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start open_close_advertising] import { ble } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { ToastReport } from '../common/ToastReport'; @@ -179,4 +180,5 @@ export class BleAdvertisingManager { let bleAdvertisingManager = new BleAdvertisingManager(); -export default bleAdvertisingManager as BleAdvertisingManager; \ No newline at end of file +export default bleAdvertisingManager as BleAdvertisingManager; +// [End open_close_advertising] \ No newline at end of file diff --git a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothScan.ets b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothScan.ets index b590b6a95ff5d30474ade362e5859db49bd8f78c..8aa2cecd90b87c3bae89f8d6fc682c9d145093e4 100644 --- a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothScan.ets +++ b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothScan.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start open_close_scan] import { ble } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { ScanData } from '../common/ScanData'; @@ -76,11 +77,13 @@ export class BleScanManager { if (data.length > 0) { console.info(TAG, 'BLE scan result = ' + data[0].deviceId); this.parseScanResult(data[0].data); + // [StartExclude open_close_scan] this.toastReport.showResult(data[0].deviceId); if (!this.scanDataList.some(item => item.getDeviceName() === data[0].deviceName)) { this.scanDataList.push(new ScanData(data[0].deviceId, data[0].deviceName, data[0].rssi, data[0].connectable, new Uint8Array(data[0].data))); } + // [EndExclude open_close_scan] } }); } @@ -232,6 +235,7 @@ export class BleScanManager { // manufactureData: manufactureData.buffer, manufactureDataMask: manufactureDataMask.buffer, }; + // [StartExclude open_close_scan] if (this.deviceName) { console.info('===lyk=== deviceName is not null ' + this.deviceName) scanFilter.name = this.deviceName; @@ -239,6 +243,8 @@ export class BleScanManager { if (this.deviceId) { scanFilter.deviceId = this.deviceId; } + // [EndExclude open_close_scan] + // 2.2 构造扫描参数 let scanOptions: ble.ScanOptions = { interval: this.interval, @@ -246,13 +252,19 @@ export class BleScanManager { matchMode: ble.MatchMode.MATCH_MODE_AGGRESSIVE, } try { + // [StartExclude open_close_scan] this.scanDataList = []; + // [EndExclude open_close_scan] this.onScanResult(); // 订阅扫描结果 ble.startBLEScan([scanFilter], scanOptions); + // [StartExclude open_close_scan] this.toastReport.showResult('startBleScan success'); + // [EndExclude open_close_scan] console.info(TAG, 'startBleScan success'); } catch (err) { + // [StartExclude open_close_scan] this.toastReport.showResult('startBleScan fail'); + // [EndExclude open_close_scan] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -264,10 +276,14 @@ export class BleScanManager { console.info(TAG, 'off success'); }); ble.stopBLEScan(); + // [StartExclude open_close_scan] this.toastReport.showResult('stopBleScan success'); + // [EndExclude open_close_scan] console.info(TAG, 'stopBleScan success'); } catch (err) { + // [StartExclude open_close_scan] this.toastReport.showResult('stopBleScan fail'); + // [EndExclude open_close_scan] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -276,3 +292,4 @@ export class BleScanManager { let bleScanManager = new BleScanManager(); export default bleScanManager as BleScanManager; +// [End open_close_scan] diff --git a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothSwitch.ets b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothSwitch.ets index bb3829f54eaf2e3f55d52304f1224bd2a78772c2..5b10dd2adb8c4e4c2203f8d15408b98ee53e5e2e 100644 --- a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothSwitch.ets +++ b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/BluetoothSwitch.ets @@ -12,11 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +// [Start open_close_bluetooth] import { access } from '@kit.ConnectivityKit'; export class BluetoothSwitch { public openBluetooth() { + access.off('stateChange'); access.enableBluetooth(); access.on('stateChange', (data) => { @@ -52,7 +53,6 @@ export class BluetoothSwitch { } console.info('bluetooth statues: ' + btStateMessage); }); - } public closeBluetooth() { @@ -92,3 +92,4 @@ export class BluetoothSwitch { }); } } +// [End open_close_bluetooth] \ No newline at end of file diff --git a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattClientManager.ets b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattClientManager.ets index f4eef513ec16857e6f4fac81b671e7b0d9a2770e..745998b1d900c8c1ac7fe3bd76253b7cadac20af 100644 --- a/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattClientManager.ets +++ b/code/DocsSample/bluetoothSample/entry/src/main/ets/bluetoothService/GattClientManager.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +// [Start generic_attribute] import { ble } from '@kit.ConnectivityKit'; import { constant } from '@kit.ConnectivityKit'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -20,7 +21,9 @@ import { ToastReport } from '../common/ToastReport'; import util from '@ohos.util'; const TAG: string = 'GattClientManager'; +// [StartExclude generic_attribute] let encoder = new util.TextEncoder(); +// [EndExclude generic_attribute] export class GattData { public serviceUuid: string = '00001810-0000-1000-8000-00805F9B34FB'; @@ -83,7 +86,9 @@ export class GattClientManager { message += value[i] + ' '; } console.info(TAG, message); + // [StartExclude generic_attribute] this.toastReport.showResult(message); + // [EndExclude generic_attribute] } private logDescriptor(des: ble.BLEDescriptor) { @@ -94,7 +99,9 @@ export class GattClientManager { message += value[i] + ' '; } console.info(TAG, message); + // [StartExclude generic_attribute] this.toastReport.showResult(message); + // [EndExclude generic_attribute] } private checkService(services: Array): boolean { @@ -179,10 +186,14 @@ export class GattClientManager { try { this.onGattClientStateChange(); // 2.2 订阅连接状态 this.gattClient.connect(); // 2.3 发起连接 + // [StartExclude generic_attribute] this.toastReport.showResult('startConnect success'); console.info(TAG, 'startConnect success'); + // [EndExclude generic_attribute] } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('startConnect fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -197,12 +208,16 @@ export class GattClientManager { try { await this.gattClient.getServices().then((result: Array) => { console.info(TAG, 'getServices success: ' + JSON.stringify(result)); + // [StartExclude generic_attribute] this.serviceResult = JSON.stringify(result); this.toastReport.showResult('getServices success: ' + JSON.stringify(result)); + // [EndExclude generic_attribute] this.found = this.checkService(result); // 要确保server端的服务内容有业务所需要的服务 }); } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('getServices fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -211,12 +226,16 @@ export class GattClientManager { public readCharacteristicValue() { if (!this.gattClient || this.connectState != constant.ProfileConnectionState.STATE_CONNECTED) { console.error(TAG, 'no gattClient or not connected'); + // [StartExclude generic_attribute] this.toastReport.showResult('no gattClient or not connected'); + // [EndExclude generic_attribute] return; } if (!this.found) { // 要确保server端有对应的characteristic console.error(TAG, 'no characteristic from server'); + // [StartExclude generic_attribute] this.toastReport.showResult('no characteristic from server'); + // [EndExclude generic_attribute] return; } @@ -226,9 +245,13 @@ export class GattClientManager { this.gattClient.readCharacteristicValue(characteristic).then((outData: ble.BLECharacteristic) => { this.logCharacteristic(outData); }) + // [StartExclude generic_attribute] this.toastReport.showResult('readCharacteristicValue success'); + // [EndExclude generic_attribute] } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('readCharacteristicValue fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -237,12 +260,16 @@ export class GattClientManager { public writeCharacteristicValue() { if (!this.gattClient || this.connectState != constant.ProfileConnectionState.STATE_CONNECTED) { console.error(TAG, 'no gattClient or not connected'); + // [StartExclude generic_attribute] this.toastReport.showResult('no gattClient or not connected'); + // [EndExclude generic_attribute] return; } if (!this.found) { // 要确保server端有对应的characteristic console.error(TAG, 'no characteristic from server'); + // [StartExclude generic_attribute] this.toastReport.showResult('no characteristic from server'); + // [EndExclude generic_attribute] return; } @@ -255,12 +282,16 @@ export class GattClientManager { 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); return; } + // [StartExclude generic_attribute] this.toastReport.showResult('writeCharacteristicValue success'); + // [EndExclude generic_attribute] console.info(TAG, 'writeCharacteristicValue success'); }); } catch (err) { + // [StartExclude generic_attribute] console.info(TAG, 'writeCharacteristicValue fail'); this.toastReport.showResult('writeCharacteristicValue fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -269,12 +300,16 @@ export class GattClientManager { public readDescriptorValue() { if (!this.gattClient || this.connectState != constant.ProfileConnectionState.STATE_CONNECTED) { console.error(TAG, 'no gattClient or not connected'); + // [StartExclude generic_attribute] this.toastReport.showResult('no gattClient or not connected'); + // [EndExclude generic_attribute] return; } if (!this.found) { // 要确保server端有对应的descriptor console.error(TAG, 'no descriptor from server'); + // [StartExclude generic_attribute] this.toastReport.showResult('no descriptor from server'); + // [EndExclude generic_attribute] return; } @@ -285,9 +320,13 @@ export class GattClientManager { this.gattClient.readDescriptorValue(descriptor).then((outData: ble.BLEDescriptor) => { this.logDescriptor(outData); }); + // [StartExclude generic_attribute] this.toastReport.showResult('readDescriptorValue success'); + // [EndExclude generic_attribute] } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('readDescriptorValue fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -296,12 +335,16 @@ export class GattClientManager { public writeDescriptorValue() { if (!this.gattClient || this.connectState != constant.ProfileConnectionState.STATE_CONNECTED) { console.error(TAG, 'no gattClient or not connected'); + // [StartExclude generic_attribute] this.toastReport.showResult('no gattClient or not connected'); + // [EndExclude generic_attribute] return; } if (!this.found) { // 要确保server端有对应的descriptor console.error(TAG, 'no descriptor from server'); + // [StartExclude generic_attribute] this.toastReport.showResult('no descriptor from server'); + // [EndExclude generic_attribute] return; } @@ -319,10 +362,14 @@ export class GattClientManager { return; } console.info(TAG, 'writeDescriptorValue success'); + // [StartExclude generic_attribute] this.toastReport.showResult('writeDescriptorValue success'); + // [EndExclude generic_attribute] }); } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('writeDescriptorValue fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -340,9 +387,13 @@ export class GattClientManager { this.gattClient.off('BLEConnectionStateChange', (stateInfo: ble.BLEConnectionChangeState) => { }); this.gattClient.close() // 8.2 如果不再使用此gattClient,则需要close + // [StartExclude generic_attribute] this.toastReport.showResult('stopConnect success'); + // [EndExclude generic_attribute] } catch (err) { + // [StartExclude generic_attribute] this.toastReport.showResult('stopConnect fail'); + // [EndExclude generic_attribute] console.error(TAG, 'errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } } @@ -350,4 +401,5 @@ export class GattClientManager { let gattClientManager = new GattClientManager(); -export default gattClientManager as GattClientManager; \ No newline at end of file +export default gattClientManager as GattClientManager; +// [End generic_attribute] \ No newline at end of file