hnpsample code upload

Signed-off-by: 郭桦炜 <guohuawei1@huawei.com>
This commit is contained in:
郭桦炜 2024-03-27 16:19:09 +00:00
parent e10d32d37c
commit 4aece17410
6 changed files with 181 additions and 0 deletions

View File

@ -66,6 +66,7 @@ group("moduletest") {
testonly = true
deps = [ ":AppSpawnModuleTest" ]
deps += [ "hnp_sample:hnpsample" ]
if (appspawn_test_cmd) {
deps += [ ":AppSpawnTest" ]
}

View File

@ -0,0 +1,50 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/startup/appspawn/appspawn.gni")
import("//build/test.gni")
ohos_executable("hnpsample") {
sources = [ "src/hnpsample/hnpsample.c" ]
ldflags = [
"-Wl,-rpath=../lib",
"-Wl,--disable-new-dtags",
]
include_dirs = []
configs = []
deps = [ ":hnpsamplelib" ]
external_deps = []
install_enable = true
subsystem_name = "${subsystem_name}"
part_name = "${part_name}"
}
ohos_shared_library("hnpsamplelib") {
include_dirs = []
sources = [ "src/hnpsample/hnpsamplelib.c" ]
configs = []
defines = []
cflags = []
external_deps = []
install_enable = true
subsystem_name = "${subsystem_name}"
part_name = "${part_name}"
}

View File

@ -0,0 +1 @@
This is hnp sample config file.

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include "hnpsamplelib.h"
#ifdef __cplusplus
extern "C" {
#endif
#define HNPSAMPLE_INDEX_2 2
#define MAX_DELAY_TIME 60
// hnpsample软件功能包括读取cfg文件并打印内容执行依赖的so函数。通过argv[1]参数控制运行的时间单位s
int main(int argc, char *argv[])
{
int sectime = 0;
int ch;
printf("\nstart hnp sample");
if (argc == HNPSAMPLE_INDEX_2) {
sectime = atoi(argv[1]);
if (sectime > MAX_DELAY_TIME) {
sectime = 0;
}
}
// 读取配置文件内容并打印
FILE *file = fopen("../cfg/hnpsample.cfg", "r");
if (file != NULL) {
printf("\ncfg file content:\n");
while ((ch = fgetc(file)) != EOF) {
putchar(ch);
}
printf("\ncfg file end.");
fclose(file);
} else {
printf("\n open cfg=../cfg/hnpsample.cfg failed.");
}
// 调用依赖so的函数并进行相应延时处理
HnpSampleLibDelay(sectime);
printf("\nhnp sample end");
return 0;
}
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <unistd.h>
#ifdef __cplusplus
extern "C" {
#endif
void HnpSampleLibDelay(int sectime)
{
printf("\nhnp sample lib delay time=%d.start", sectime);
sleep(sectime);
printf("\nhnp sample lib delay end");
return;
}
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HNP_SAMPLELIB_H
#define HNP_SAMPLELIB_H
#ifdef __cplusplus
extern "C" {
#endif
void HnpSampleLibDelay(int sectime);
#ifdef __cplusplus
}
#endif
#endif