mirror of
https://github.com/openharmony/applications_sample_wifi_iot.git
synced 2026-07-01 10:37:28 -04:00
code review fixes
Signed-off-by: Caoruihong <crh.cao@huawei.com> Change-Id: I74050d19a0937d6f61f922780362c70ab0957d75
This commit is contained in:
Executable → Regular
Executable → Regular
+18
-20
@@ -1,20 +1,18 @@
|
||||
# Copyright (c) 2020 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("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
lite_component("app") {
|
||||
features = [
|
||||
"startup",
|
||||
]
|
||||
}
|
||||
# Copyright (c) 2020-2022 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("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
lite_component("app") {
|
||||
features = [ "startup" ]
|
||||
}
|
||||
|
||||
Executable → Regular
+21
-23
@@ -1,23 +1,21 @@
|
||||
# Copyright (c) 2020 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.
|
||||
|
||||
static_library("example_demolink") {
|
||||
sources = [
|
||||
"helloworld.c"
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//utils/native/lite/include",
|
||||
"//domains/iot/link/libbuild"
|
||||
]
|
||||
}
|
||||
# Copyright (c) 2020-2022 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.
|
||||
|
||||
static_library("example_demolink") {
|
||||
sources = [ "helloworld.c" ]
|
||||
|
||||
include_dirs = [
|
||||
"//utils/native/lite/include",
|
||||
"//domains/iot/link/libbuild",
|
||||
]
|
||||
}
|
||||
|
||||
Executable → Regular
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2020-2022 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
|
||||
|
||||
Executable → Regular
+22
-24
@@ -1,24 +1,22 @@
|
||||
# Copyright (c) 2020 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.
|
||||
|
||||
static_library("led_example") {
|
||||
sources = [
|
||||
"led_example.c"
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//utils/native/lite/include",
|
||||
"//kernel/liteos_m/kal/cmsis",
|
||||
"//base/iot_hardware/peripheral/interfaces/kits",
|
||||
]
|
||||
}
|
||||
# Copyright (c) 2020-2022 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.
|
||||
|
||||
static_library("led_example") {
|
||||
sources = [ "led_example.c" ]
|
||||
|
||||
include_dirs = [
|
||||
"//utils/native/lite/include",
|
||||
"//kernel/liteos_m/kal/cmsis",
|
||||
"//base/iot_hardware/peripheral/interfaces/kits",
|
||||
]
|
||||
}
|
||||
|
||||
Executable → Regular
+83
-84
@@ -1,84 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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>
|
||||
|
||||
#include "ohos_init.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "iot_gpio.h"
|
||||
|
||||
#define LED_INTERVAL_TIME_US 300000
|
||||
#define LED_TASK_STACK_SIZE 512
|
||||
#define LED_TASK_PRIO 25
|
||||
#define LED_TEST_GPIO 9 // for hispark_pegasus
|
||||
enum LedState {
|
||||
LED_ON = 0,
|
||||
LED_OFF,
|
||||
LED_SPARK,
|
||||
};
|
||||
|
||||
enum LedState g_ledState = LED_SPARK;
|
||||
|
||||
static void *LedTask(const char *arg)
|
||||
{
|
||||
(void)arg;
|
||||
while (1) {
|
||||
switch (g_ledState) {
|
||||
case LED_ON:
|
||||
IoTGpioSetOutputVal(LED_TEST_GPIO, 1);
|
||||
usleep(LED_INTERVAL_TIME_US);
|
||||
break;
|
||||
case LED_OFF:
|
||||
IoTGpioSetOutputVal(LED_TEST_GPIO, 0);
|
||||
usleep(LED_INTERVAL_TIME_US);
|
||||
break;
|
||||
case LED_SPARK:
|
||||
IoTGpioSetOutputVal(LED_TEST_GPIO, 0);
|
||||
usleep(LED_INTERVAL_TIME_US);
|
||||
IoTGpioSetOutputVal(LED_TEST_GPIO, 1);
|
||||
usleep(LED_INTERVAL_TIME_US);
|
||||
break;
|
||||
default:
|
||||
usleep(LED_INTERVAL_TIME_US);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void LedExampleEntry(void)
|
||||
{
|
||||
osThreadAttr_t attr;
|
||||
|
||||
IoTGpioInit(LED_TEST_GPIO);
|
||||
IoTGpioSetDir(LED_TEST_GPIO, IOT_GPIO_DIR_OUT);
|
||||
|
||||
attr.name = "LedTask";
|
||||
attr.attr_bits = 0U;
|
||||
attr.cb_mem = NULL;
|
||||
attr.cb_size = 0U;
|
||||
attr.stack_mem = NULL;
|
||||
attr.stack_size = LED_TASK_STACK_SIZE;
|
||||
attr.priority = LED_TASK_PRIO;
|
||||
|
||||
if (osThreadNew((osThreadFunc_t)LedTask, NULL, &attr) == NULL) {
|
||||
printf("[LedExample] Falied to create LedTask!\n");
|
||||
}
|
||||
}
|
||||
|
||||
SYS_RUN(LedExampleEntry);
|
||||
/*
|
||||
* Copyright (c) 2020-2022 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>
|
||||
#include "ohos_init.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "iot_gpio.h"
|
||||
|
||||
#define LED_INTERVAL_TIME_US 300000
|
||||
#define LED_TASK_STACK_SIZE 512
|
||||
#define LED_TASK_PRIO 25
|
||||
#define LED_TEST_GPIO 9 // for hispark_pegasus
|
||||
|
||||
enum LedState {
|
||||
LED_ON = 0,
|
||||
LED_OFF,
|
||||
LED_SPARK,
|
||||
};
|
||||
|
||||
enum LedState g_ledState = LED_SPARK;
|
||||
|
||||
static void *LedTask(const char *arg)
|
||||
{
|
||||
(void)arg;
|
||||
while (1) {
|
||||
switch (g_ledState) {
|
||||
case LED_ON:
|
||||
IoTGpioSetOutputVal(LED_TEST_GPIO, 1);
|
||||
usleep(LED_INTERVAL_TIME_US);
|
||||
break;
|
||||
case LED_OFF:
|
||||
IoTGpioSetOutputVal(LED_TEST_GPIO, 0);
|
||||
usleep(LED_INTERVAL_TIME_US);
|
||||
break;
|
||||
case LED_SPARK:
|
||||
IoTGpioSetOutputVal(LED_TEST_GPIO, 0);
|
||||
usleep(LED_INTERVAL_TIME_US);
|
||||
IoTGpioSetOutputVal(LED_TEST_GPIO, 1);
|
||||
usleep(LED_INTERVAL_TIME_US);
|
||||
break;
|
||||
default:
|
||||
usleep(LED_INTERVAL_TIME_US);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void LedExampleEntry(void)
|
||||
{
|
||||
osThreadAttr_t attr;
|
||||
|
||||
IoTGpioInit(LED_TEST_GPIO);
|
||||
IoTGpioSetDir(LED_TEST_GPIO, IOT_GPIO_DIR_OUT);
|
||||
|
||||
attr.name = "LedTask";
|
||||
attr.attr_bits = 0U;
|
||||
attr.cb_mem = NULL;
|
||||
attr.cb_size = 0U;
|
||||
attr.stack_mem = NULL;
|
||||
attr.stack_size = LED_TASK_STACK_SIZE;
|
||||
attr.priority = LED_TASK_PRIO;
|
||||
|
||||
if (osThreadNew((osThreadFunc_t)LedTask, NULL, &attr) == NULL) {
|
||||
printf("[LedExample] Failed to create LedTask!\n");
|
||||
}
|
||||
}
|
||||
|
||||
SYS_RUN(LedExampleEntry);
|
||||
|
||||
Executable → Regular
+36
-36
@@ -1,36 +1,36 @@
|
||||
# Copyright (c) 2020 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.
|
||||
|
||||
static_library("example_samgr") {
|
||||
sources = [
|
||||
"//test/xts/acts/distributed_schedule_lite/samgr_hal/utils/samgr_maintenance.c",
|
||||
"bootstrap_example.c",
|
||||
"broadcast_example.c",
|
||||
"feature_example.c",
|
||||
"maintenance_example.c",
|
||||
"service_example.c",
|
||||
"service_recovery_example.c",
|
||||
"specified_task_example.c",
|
||||
"task_example.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//utils/native/lite/include",
|
||||
"//kernel/liteos_m/components/cmsis",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/communication/broadcast",
|
||||
"//foundation/distributedschedule/samgr_lite/samgr/adapter",
|
||||
"//foundation/distributedschedule/samgr_lite/samgr/source",
|
||||
"//test/xts/acts/distributed_schedule_lite/samgr_hal/utils",
|
||||
]
|
||||
}
|
||||
# Copyright (c) 2020-2022 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.
|
||||
|
||||
static_library("example_samgr") {
|
||||
sources = [
|
||||
"//test/xts/acts/distributed_schedule_lite/samgr_hal/utils/samgr_maintenance.c",
|
||||
"bootstrap_example.c",
|
||||
"broadcast_example.c",
|
||||
"feature_example.c",
|
||||
"maintenance_example.c",
|
||||
"service_example.c",
|
||||
"service_recovery_example.c",
|
||||
"specified_task_example.c",
|
||||
"task_example.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//utils/native/lite/include",
|
||||
"//kernel/liteos_m/components/cmsis",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/communication/broadcast",
|
||||
"//foundation/distributedschedule/samgr_lite/samgr/adapter",
|
||||
"//foundation/distributedschedule/samgr_lite/samgr/source",
|
||||
"//test/xts/acts/distributed_schedule_lite/samgr_hal/utils",
|
||||
]
|
||||
}
|
||||
|
||||
Executable → Regular
+241
-223
@@ -1,223 +1,241 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "example.h"
|
||||
#include <feature.h>
|
||||
#include <securec.h>
|
||||
#include <ohos_init.h>
|
||||
#include <samgr_lite.h>
|
||||
#include <cmsis_os.h>
|
||||
#include "time_adapter.h"
|
||||
|
||||
typedef struct BootTestExample {
|
||||
Service service;
|
||||
Feature feature;
|
||||
} BootTestExample;
|
||||
static const char *GetName(Service *service);
|
||||
static BOOL Initialize(Service *service, Identity identity);
|
||||
static BOOL MessageHandle(Service *service, Request *msg);
|
||||
static TaskConfig GetTaskConfig(Service *service);
|
||||
static const char *FEATURE_GetName(Feature *feature);
|
||||
static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity);
|
||||
static void FEATURE_OnStop(Feature *feature, Identity identity);
|
||||
static BOOL FEATURE_OnMessage(Feature *feature, Request *request);
|
||||
static BootTestExample g_example[] = {
|
||||
{
|
||||
.service = {GetName, Initialize, MessageHandle, GetTaskConfig},
|
||||
.feature = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage}
|
||||
}, {
|
||||
.service = {GetName, Initialize, MessageHandle, GetTaskConfig},
|
||||
.feature = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage}
|
||||
}, {
|
||||
.service = {GetName, Initialize, MessageHandle, GetTaskConfig},
|
||||
.feature = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage}
|
||||
}, {
|
||||
.service = {GetName, Initialize, MessageHandle, GetTaskConfig},
|
||||
.feature = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage}
|
||||
}
|
||||
};
|
||||
static int g_initIndex = 0;
|
||||
static const char *FEATURE_GetName(Feature *feature)
|
||||
{
|
||||
// test cases service 0
|
||||
if (feature == &g_example[0].feature) {
|
||||
return BOOT_SYS_FEATURE1;
|
||||
}
|
||||
// test cases service 1
|
||||
if (feature == &g_example[1].feature) {
|
||||
return BOOT_SYS_FEATURE2;
|
||||
}
|
||||
// test cases service 2
|
||||
if (feature == &g_example[2].feature) {
|
||||
return BOOT_SYSEX_FEATURE1;
|
||||
}
|
||||
// test cases service 3
|
||||
if (feature == &g_example[3].feature) {
|
||||
return BOOT_SYSEX_FEATURE2;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity)
|
||||
{
|
||||
(void)identity;
|
||||
printf("[Boot Test][TaskID:%p][Step:%d][Reg Finish S:%s, F:%s]Time: %llu!\n",
|
||||
osThreadGetId(), g_initIndex++, parent->GetName(parent), feature->GetName(feature), SAMGR_GetProcessTime());
|
||||
}
|
||||
|
||||
static void FEATURE_OnStop(Feature *feature, Identity identity)
|
||||
{
|
||||
(void)feature;
|
||||
(void)identity;
|
||||
}
|
||||
|
||||
static BOOL FEATURE_OnMessage(Feature *feature, Request *request)
|
||||
{
|
||||
printf("[Boot Test][TaskID:%p][Step:%d][F:%s] msgId<%d> \n",
|
||||
osThreadGetId(), g_initIndex++, feature->GetName(feature), request->msgId);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static const char *GetName(Service *service)
|
||||
{
|
||||
// test cases service 0
|
||||
if (service == &g_example[0].service) {
|
||||
return BOOT_SYS_SERVICE1;
|
||||
}
|
||||
// test cases service 1
|
||||
if (service == &g_example[1].service) {
|
||||
return BOOT_SYS_SERVICE2;
|
||||
}
|
||||
// test cases service 2
|
||||
if (service == &g_example[2].service) {
|
||||
return BOOT_SYSEX_SERVICE1;
|
||||
}
|
||||
// test cases service 3
|
||||
if (service == &g_example[3].service) {
|
||||
return BOOT_SYSEX_SERVICE2;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BOOL Initialize(Service *service, Identity identity)
|
||||
{
|
||||
(void)identity;
|
||||
printf("[Boot Test][TaskID:%p][Step:%d][Reg Finish S:%s]Time: %llu!\n",
|
||||
osThreadGetId(), g_initIndex++, service->GetName(service), SAMGR_GetProcessTime());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MessageHandle(Service *service, Request *msg)
|
||||
{
|
||||
printf("[Boot Test][TaskID:%p][Step:%d][S:%s] msgId<%d> \n",
|
||||
osThreadGetId(), g_initIndex++, service->GetName(service), msg->msgId);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static TaskConfig GetTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL,
|
||||
0x400, 2, SHARED_TASK};
|
||||
return config;
|
||||
}
|
||||
static void MInit(void)
|
||||
{
|
||||
printf("[Boot Test][TaskID:%p][Step:%d][CORE INIT]Time: %llu!\n",
|
||||
osThreadGetId(), g_initIndex++, SAMGR_GetProcessTime());
|
||||
}
|
||||
static void MRun(void)
|
||||
{
|
||||
printf("[Boot Test][TaskID:%p][Step:%d][SYS RUN]Time: %llu!\n",
|
||||
osThreadGetId(), g_initIndex++, SAMGR_GetProcessTime());
|
||||
}
|
||||
static void SInit(BootTestExample *demo)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterService(&demo->service);
|
||||
|
||||
// test cases service 2
|
||||
printf((demo < &g_example[2]) ?
|
||||
"[Boot Test][TaskID:%p][Step:%d][SYS Reg S:%s]Time: %llu!\n" :
|
||||
"[Boot Test][TaskID:%p][Step:%d][SYSEX Reg S:%s]Time: %llu!\n",
|
||||
osThreadGetId(), g_initIndex++, demo->service.GetName(&demo->service), SAMGR_GetProcessTime());
|
||||
}
|
||||
static void FInit(BootTestExample *demo)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterFeature(demo->service.GetName(&demo->service), &demo->feature);
|
||||
|
||||
// test cases service 2
|
||||
printf((demo < &g_example[2]) ?
|
||||
"[Boot Test][TaskID:%p][Step:%d][SYS Reg S:%s, F:%s]Time: %llu!\n" :
|
||||
"[Boot Test][TaskID:%p][Step:%d][SYSEX Reg S:%s, F:%s]Time: %llu!\n",
|
||||
osThreadGetId(), g_initIndex++, demo->service.GetName(&demo->service), demo->feature.GetName(&demo->feature),
|
||||
SAMGR_GetProcessTime());
|
||||
}
|
||||
static void S1Init(void)
|
||||
{
|
||||
// test cases service 0
|
||||
SInit(&g_example[0]);
|
||||
}
|
||||
static void S2Init(void)
|
||||
{
|
||||
// test cases service 1
|
||||
SInit(&g_example[1]);
|
||||
}
|
||||
static void F1Init(void)
|
||||
{
|
||||
// test cases feature 0
|
||||
FInit(&g_example[0]);
|
||||
}
|
||||
static void F2Init(void)
|
||||
{
|
||||
// test cases feature 1
|
||||
FInit(&g_example[1]);
|
||||
}
|
||||
static void S3Init(void)
|
||||
{
|
||||
// test cases service 2
|
||||
SInit(&g_example[2]);
|
||||
}
|
||||
static void S4Init(void)
|
||||
{
|
||||
// test cases service 3
|
||||
SInit(&g_example[3]);
|
||||
}
|
||||
static void F3Init(void)
|
||||
{
|
||||
// test cases feature 2
|
||||
FInit(&g_example[2]);
|
||||
}
|
||||
static void F4Init(void)
|
||||
{
|
||||
// test cases feature 3
|
||||
FInit(&g_example[3]);
|
||||
}
|
||||
CORE_INIT(MInit);
|
||||
SYS_RUN(MRun);
|
||||
// init pri first
|
||||
SYS_SERVICE_INIT_PRI(S1Init, 0);
|
||||
// init pri second
|
||||
SYS_SERVICE_INIT_PRI(S2Init, 1);
|
||||
// init pri first
|
||||
SYS_FEATURE_INIT_PRI(F1Init, 0);
|
||||
// init pri second
|
||||
SYS_FEATURE_INIT_PRI(F2Init, 1);
|
||||
// init pri first
|
||||
SYSEX_SERVICE_INIT_PRI(S3Init, 0);
|
||||
// init pri second
|
||||
SYSEX_SERVICE_INIT_PRI(S4Init, 1);
|
||||
// init pri first
|
||||
SYSEX_FEATURE_INIT_PRI(F3Init, 0);
|
||||
// init pri second
|
||||
SYSEX_FEATURE_INIT_PRI(F4Init, 1);
|
||||
/*
|
||||
* Copyright (c) 2020-2022 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 "example.h"
|
||||
#include <stdint.h>
|
||||
#include <feature.h>
|
||||
#include <securec.h>
|
||||
#include <ohos_init.h>
|
||||
#include <samgr_lite.h>
|
||||
#include <cmsis_os.h>
|
||||
#include "time_adapter.h"
|
||||
|
||||
typedef struct BootTestExample {
|
||||
Service service;
|
||||
Feature feature;
|
||||
} BootTestExample;
|
||||
|
||||
static const char *GetName(Service *service);
|
||||
static BOOL Initialize(Service *service, Identity identity);
|
||||
static BOOL MessageHandle(Service *service, Request *msg);
|
||||
static TaskConfig GetTaskConfig(Service *service);
|
||||
static const char *FEATURE_GetName(Feature *feature);
|
||||
static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity);
|
||||
static void FEATURE_OnStop(Feature *feature, Identity identity);
|
||||
static BOOL FEATURE_OnMessage(Feature *feature, Request *request);
|
||||
static BootTestExample g_example[] = {
|
||||
{
|
||||
.service = {GetName, Initialize, MessageHandle, GetTaskConfig},
|
||||
.feature = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage}
|
||||
}, {
|
||||
.service = {GetName, Initialize, MessageHandle, GetTaskConfig},
|
||||
.feature = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage}
|
||||
}, {
|
||||
.service = {GetName, Initialize, MessageHandle, GetTaskConfig},
|
||||
.feature = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage}
|
||||
}, {
|
||||
.service = {GetName, Initialize, MessageHandle, GetTaskConfig},
|
||||
.feature = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage}
|
||||
}
|
||||
};
|
||||
|
||||
static uint32_t g_initIndex = 0;
|
||||
|
||||
static const char *FEATURE_GetName(Feature *feature)
|
||||
{
|
||||
// test cases service 0
|
||||
if (feature == &g_example[0].feature) {
|
||||
return BOOT_SYS_FEATURE1;
|
||||
}
|
||||
// test cases service 1
|
||||
if (feature == &g_example[1].feature) {
|
||||
return BOOT_SYS_FEATURE2;
|
||||
}
|
||||
// test cases service 2
|
||||
if (feature == &g_example[2].feature) {
|
||||
return BOOT_SYSEX_FEATURE1;
|
||||
}
|
||||
// test cases service 3
|
||||
if (feature == &g_example[3].feature) {
|
||||
return BOOT_SYSEX_FEATURE2;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity)
|
||||
{
|
||||
(void)identity;
|
||||
printf("[Boot Test][TaskID:%u][Step:%u][Reg Finish S:%s, F:%s]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_initIndex++, parent->GetName(parent), feature->GetName(feature),
|
||||
SAMGR_GetProcessTime());
|
||||
}
|
||||
|
||||
static void FEATURE_OnStop(Feature *feature, Identity identity)
|
||||
{
|
||||
(void)feature;
|
||||
(void)identity;
|
||||
}
|
||||
|
||||
static BOOL FEATURE_OnMessage(Feature *feature, Request *request)
|
||||
{
|
||||
printf("[Boot Test][TaskID:%u][Step:%u][F:%s] msgId<%d> \n",
|
||||
(int)osThreadGetId(), g_initIndex++, feature->GetName(feature), request->msgId);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static const char *GetName(Service *service)
|
||||
{
|
||||
// test cases service 0
|
||||
if (service == &g_example[0].service) {
|
||||
return BOOT_SYS_SERVICE1;
|
||||
}
|
||||
// test cases service 1
|
||||
if (service == &g_example[1].service) {
|
||||
return BOOT_SYS_SERVICE2;
|
||||
}
|
||||
// test cases service 2
|
||||
if (service == &g_example[2].service) {
|
||||
return BOOT_SYSEX_SERVICE1;
|
||||
}
|
||||
// test cases service 3
|
||||
if (service == &g_example[3].service) {
|
||||
return BOOT_SYSEX_SERVICE2;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BOOL Initialize(Service *service, Identity identity)
|
||||
{
|
||||
(void)identity;
|
||||
printf("[Boot Test][TaskID:%u][Step:%u][Reg Finish S:%s]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_initIndex++, service->GetName(service), SAMGR_GetProcessTime());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MessageHandle(Service *service, Request *msg)
|
||||
{
|
||||
printf("[Boot Test][TaskID:%u][Step:%u][S:%s] msgId<%d> \n",
|
||||
(int)osThreadGetId(), g_initIndex++, service->GetName(service), msg->msgId);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static TaskConfig GetTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL,
|
||||
0x400, 2, SHARED_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
static void MInit(void)
|
||||
{
|
||||
printf("[Boot Test][TaskID:%u][Step:%u][CORE INIT]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_initIndex++, SAMGR_GetProcessTime());
|
||||
}
|
||||
static void MRun(void)
|
||||
{
|
||||
printf("[Boot Test][TaskID:%u][Step:%u][SYS RUN]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_initIndex++, SAMGR_GetProcessTime());
|
||||
}
|
||||
|
||||
static void SInit(BootTestExample *demo)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterService(&demo->service);
|
||||
|
||||
// test cases service 2
|
||||
printf((demo < &g_example[2]) ?
|
||||
"[Boot Test][TaskID:%u][Step:%u][SYS Reg S:%s]Time: %llu!\n" :
|
||||
"[Boot Test][TaskID:%u][Step:%u][SYSEX Reg S:%s]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_initIndex++, demo->service.GetName(&demo->service), SAMGR_GetProcessTime());
|
||||
}
|
||||
|
||||
static void FInit(BootTestExample *demo)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterFeature(demo->service.GetName(&demo->service), &demo->feature);
|
||||
|
||||
// test cases service 2
|
||||
printf((demo < &g_example[2]) ?
|
||||
"[Boot Test][TaskID:%u][Step:%u][SYS Reg S:%s, F:%s]Time: %llu!\n" :
|
||||
"[Boot Test][TaskID:%u][Step:%u][SYSEX Reg S:%s, F:%s]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_initIndex++, demo->service.GetName(&demo->service),
|
||||
demo->feature.GetName(&demo->feature), SAMGR_GetProcessTime());
|
||||
}
|
||||
|
||||
static void S1Init(void)
|
||||
{
|
||||
// test cases service 0
|
||||
SInit(&g_example[0]);
|
||||
}
|
||||
|
||||
static void S2Init(void)
|
||||
{
|
||||
// test cases service 1
|
||||
SInit(&g_example[1]);
|
||||
}
|
||||
|
||||
static void F1Init(void)
|
||||
{
|
||||
// test cases feature 0
|
||||
FInit(&g_example[0]);
|
||||
}
|
||||
|
||||
static void F2Init(void)
|
||||
{
|
||||
// test cases feature 1
|
||||
FInit(&g_example[1]);
|
||||
}
|
||||
|
||||
static void S3Init(void)
|
||||
{
|
||||
// test cases service 2
|
||||
SInit(&g_example[2]);
|
||||
}
|
||||
|
||||
static void S4Init(void)
|
||||
{
|
||||
// test cases service 3
|
||||
SInit(&g_example[3]);
|
||||
}
|
||||
|
||||
static void F3Init(void)
|
||||
{
|
||||
// test cases feature 2
|
||||
FInit(&g_example[2]);
|
||||
}
|
||||
|
||||
static void F4Init(void)
|
||||
{
|
||||
// test cases feature 3
|
||||
FInit(&g_example[3]);
|
||||
}
|
||||
|
||||
CORE_INIT(MInit);
|
||||
SYS_RUN(MRun);
|
||||
// init pri first
|
||||
SYS_SERVICE_INIT_PRI(S1Init, 0);
|
||||
// init pri second
|
||||
SYS_SERVICE_INIT_PRI(S2Init, 1);
|
||||
// init pri first
|
||||
SYS_FEATURE_INIT_PRI(F1Init, 0);
|
||||
// init pri second
|
||||
SYS_FEATURE_INIT_PRI(F2Init, 1);
|
||||
// init pri first
|
||||
SYSEX_SERVICE_INIT_PRI(S3Init, 0);
|
||||
// init pri second
|
||||
SYSEX_SERVICE_INIT_PRI(S4Init, 1);
|
||||
// init pri first
|
||||
SYSEX_FEATURE_INIT_PRI(F3Init, 0);
|
||||
// init pri second
|
||||
SYSEX_FEATURE_INIT_PRI(F4Init, 1);
|
||||
|
||||
Executable → Regular
+241
-224
@@ -1,224 +1,241 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "samgr_lite.h"
|
||||
#include "broadcast_interface.h"
|
||||
#include <ohos_init.h>
|
||||
#include <securec.h>
|
||||
#include <los_base.h>
|
||||
#include <cmsis_os.h>
|
||||
#include "time_adapter.h"
|
||||
|
||||
#define TEST_LEN 10
|
||||
#define WAIT_PUB_PROC 1000
|
||||
#define BROADCASR_TEST_SERVICE "broadcast test"
|
||||
|
||||
static uint32 g_callbackStep = 0;
|
||||
static void C1Callback(Consumer *consumer, const Topic *topic, const Request *request)
|
||||
{
|
||||
(void)consumer;
|
||||
(void)topic;
|
||||
printf("[Broadcast Test][TaskID:%p][Step:%d][C1 Callback]c1 is being called data is :%s \n",
|
||||
osThreadGetId(), g_callbackStep++, (char *)request->data);
|
||||
}
|
||||
|
||||
static void C2Callback(Consumer *consumer, const Topic *topic, const Request *request)
|
||||
{
|
||||
(void)consumer;
|
||||
(void)topic;
|
||||
printf("[Broadcast Test][TaskID:%p][Step:%d][C2 Callback]c2 is being called data is :%s \n",
|
||||
osThreadGetId(), g_callbackStep++, (char *)request->data);
|
||||
}
|
||||
|
||||
static BOOL Equal(const Consumer *current, const Consumer *other)
|
||||
{
|
||||
return (current->Notify == other->Notify);
|
||||
}
|
||||
|
||||
static const char *GetName(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
return BROADCASR_TEST_SERVICE;
|
||||
};
|
||||
|
||||
static Identity g_identity = { -1, -1, NULL};
|
||||
static volatile uint32 g_broadcastStep = 0;
|
||||
static BOOL Initialize(Service *service, Identity identity)
|
||||
{
|
||||
g_identity = identity;
|
||||
(void)service;
|
||||
printf("[Broadcast Test][TaskID:%p][Step:%d][Reg Finish S:%s]Time: %llu!\n",
|
||||
osThreadGetId(), g_broadcastStep++, BROADCASR_TEST_SERVICE, SAMGR_GetProcessTime());
|
||||
return TRUE;
|
||||
};
|
||||
|
||||
static BOOL MessageHandle(Service *service, Request *msg)
|
||||
{
|
||||
printf("[Broadcast Test][TaskID: %p] msgId<%d>: %s \n", osThreadGetId(), msg->msgId, (char *)msg->data);
|
||||
(void)service;
|
||||
return FALSE;
|
||||
};
|
||||
|
||||
static TaskConfig GetTaskConfig(Service *service)
|
||||
{
|
||||
TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL, 0x800, 20, SHARED_TASK};
|
||||
(void)service;
|
||||
return config;
|
||||
};
|
||||
|
||||
static Service g_testService = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
static void Init(void)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterService(&g_testService);
|
||||
printf("[Broadcast Test][TaskID:%p][Step:%d][Reg S:%s]Time: %llu!\n",
|
||||
osThreadGetId(), g_broadcastStep++, BROADCASR_TEST_SERVICE, SAMGR_GetProcessTime());
|
||||
}
|
||||
SYSEX_SERVICE_INIT(Init);
|
||||
|
||||
static PubSubInterface *CASE_GetIUnknown(void)
|
||||
{
|
||||
PubSubInterface *fapi = NULL;
|
||||
printf("[Broadcast Test][TaskID:%p][Step:%d][GetIUnknown S:%s]: BEGIN\n",
|
||||
osThreadGetId(), g_broadcastStep++, BROADCASR_TEST_SERVICE);
|
||||
IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE, PUB_SUB_FEATURE);
|
||||
if (iUnknown == NULL) {
|
||||
printf("[Broadcast Test][TaskID:%p][Step:%d][GetDefaultFeatureApi S:%s]Error is NULL!\n",
|
||||
osThreadGetId(), g_broadcastStep++, BROADCASR_TEST_SERVICE);
|
||||
goto END;
|
||||
}
|
||||
|
||||
int result = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&fapi);
|
||||
if (result != 0 || fapi == NULL) {
|
||||
printf("[Broadcast Test][TaskID:%p][Step:%d][QueryInterface S:%s]Error is NULL!\n",
|
||||
osThreadGetId(), g_broadcastStep++, BROADCASR_TEST_SERVICE);
|
||||
goto END;
|
||||
}
|
||||
printf("[Broadcast Test][TaskID:%p][Step:%d][GetIUnknown S:%s]Success\n",
|
||||
osThreadGetId(), g_broadcastStep++, BROADCASR_TEST_SERVICE);
|
||||
END:
|
||||
printf("[Broadcast Test][TaskID:%p][Step:%d][GetIUnknown S:%s]: END\n",
|
||||
osThreadGetId(), g_broadcastStep++, BROADCASR_TEST_SERVICE);
|
||||
return fapi;
|
||||
}
|
||||
|
||||
static uint32 g_addTopicStep = 0;
|
||||
static uint32 g_unsubscribeTopicStep = 0;
|
||||
static void CASE_AddAndUnsubscribeTopic(PubSubInterface *fapi)
|
||||
{
|
||||
Subscriber *subscriber = &fapi->subscriber;
|
||||
Provider *provider = &fapi->provider;
|
||||
static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal};
|
||||
static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal};
|
||||
// add topic test
|
||||
printf("[Topic Test][TaskID:%p][Step:%d][Add Topic]: BEGIN\n", osThreadGetId(), g_addTopicStep++);
|
||||
Topic topic0 = 0;
|
||||
subscriber->AddTopic((IUnknown *)fapi, &topic0);
|
||||
subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1);
|
||||
subscriber->Subscribe((IUnknown *)fapi, &topic0, &c2);
|
||||
provider->Publish((IUnknown *)fapi, &topic0, (uint8_t *) "==>111<==", TEST_LEN);
|
||||
Topic topic1 = 0x10000;
|
||||
subscriber->AddTopic((IUnknown *)fapi, &topic1);
|
||||
subscriber->Subscribe((IUnknown *)fapi, &topic1, &c1);
|
||||
subscriber->Subscribe((IUnknown *)fapi, &topic1, &c2);
|
||||
provider->Publish((IUnknown *)fapi, &topic1, (uint8_t *) "==>444<==", TEST_LEN);
|
||||
printf("[Topic Test][TaskID:%p][Step:%d][Add Topic]: Success!\n", osThreadGetId(), g_addTopicStep++);
|
||||
printf("[Topic Test][TaskID:%p][Step:%d][Add Topic]: END\n", osThreadGetId(), g_addTopicStep++);
|
||||
// unsubscribe topic0 test
|
||||
printf("[Topic Test][TaskID:%p][Step:%d][Unsubscribe Topic]: BEGIN\n", osThreadGetId(), g_unsubscribeTopicStep++);
|
||||
LOS_Msleep(WAIT_PUB_PROC);
|
||||
subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1);
|
||||
provider->Publish((IUnknown *)fapi, &topic0, (uint8_t *) "@@@222@@@", TEST_LEN);
|
||||
LOS_Msleep(WAIT_PUB_PROC);
|
||||
subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c2);
|
||||
provider->Publish((IUnknown *)fapi, &topic0, (uint8_t *) "@@@333@@@", TEST_LEN);
|
||||
provider->Publish((IUnknown *)fapi, &topic1, (uint8_t *) "@@@444@@@", TEST_LEN);
|
||||
printf("[Topic Test][TaskID:%p][Step:%d][Unsubscribe Topic]: Success!\n",
|
||||
osThreadGetId(), g_unsubscribeTopicStep++);
|
||||
printf("[Topic Test][TaskID:%p][Step:%d][Unsubscribe Topic]: END\n", osThreadGetId(), g_unsubscribeTopicStep++);
|
||||
}
|
||||
|
||||
static uint32 g_modifyConsumerStep = 0;
|
||||
static void CASE_ModifyConsumer(PubSubInterface *fapi)
|
||||
{
|
||||
Subscriber *subscriber = &fapi->subscriber;
|
||||
Provider *provider = &fapi->provider;
|
||||
static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal};
|
||||
static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal};
|
||||
// modify consumer test
|
||||
printf("[Topic Test][TaskID:%p][Step:%d][Modify Consumer]: BEGIN\n", osThreadGetId(), g_modifyConsumerStep++);
|
||||
Topic topic2 = 0x100;
|
||||
subscriber->AddTopic((IUnknown *)fapi, &topic2);
|
||||
subscriber->Subscribe((IUnknown *)fapi, &topic2, &c1);
|
||||
provider->Publish((IUnknown *)fapi, &topic2, (uint8_t *) "==>555<==", TEST_LEN);
|
||||
LOS_Msleep(WAIT_PUB_PROC);
|
||||
subscriber->ModifyConsumer((IUnknown *)fapi, &topic2, &c1, &c2);
|
||||
provider->Publish((IUnknown *)fapi, &topic2, (uint8_t *) "@@@555@@@", TEST_LEN);
|
||||
printf("[Topic Test][TaskID:%p][Step:%d][Modify Consumer]: Success!\n", osThreadGetId(), g_modifyConsumerStep++);
|
||||
printf("[Topic Test][TaskID:%p][Step:%d][Modify Consumer]: END\n", osThreadGetId(), g_modifyConsumerStep++);
|
||||
}
|
||||
|
||||
static uint32 g_reUnsubscribeTopic = 0;
|
||||
static void CASE_ReUnsubscribeTopic(PubSubInterface *fapi)
|
||||
{
|
||||
Subscriber *subscriber = &fapi->subscriber;
|
||||
Provider *provider = &fapi->provider;
|
||||
static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal};
|
||||
printf("[Topic Test][TaskID:%p][Step:%d][ReUnsubscribe Topic]: BEGIN\n", osThreadGetId(), g_reUnsubscribeTopic++);
|
||||
Topic topic3 = 0x1000;
|
||||
subscriber->AddTopic((IUnknown *)fapi, &topic3);
|
||||
subscriber->Subscribe((IUnknown *)fapi, &topic3, &c1);
|
||||
provider->Publish((IUnknown *)fapi, &topic3, (uint8_t *) "==>666<==", TEST_LEN);
|
||||
LOS_Msleep(WAIT_PUB_PROC);
|
||||
Consumer *retConsumer = subscriber->Unsubscribe((IUnknown *)fapi, &topic3, &c1);
|
||||
if (retConsumer == NULL) {
|
||||
printf("[Topic Test][TaskID:%p][Step:%d][ReUnsubscribe Topic]: Unsubscribe Topic lead to NULL return value\n",
|
||||
osThreadGetId(), g_reUnsubscribeTopic++);
|
||||
}
|
||||
retConsumer = subscriber->Unsubscribe((IUnknown *)fapi, &topic3, &c1);
|
||||
if (retConsumer == NULL) {
|
||||
printf("[Topic Test][TaskID:%p][Step:%d][ReUnsubscribe Topic]: ReUnsubscribe Topic lead to NULL return value\n",
|
||||
osThreadGetId(), g_reUnsubscribeTopic++);
|
||||
}
|
||||
provider->Publish((IUnknown *)fapi, &topic3, (uint8_t *) "@@@666@@@", TEST_LEN);
|
||||
printf("[Topic Test][TaskID:%p][Step:%d][ReUnsubscribe Topic]: Success!\n",
|
||||
osThreadGetId(), g_reUnsubscribeTopic++);
|
||||
printf("[Topic Test][TaskID:%p][Step:%d][ReUnsubscribe Topic]: END\n", osThreadGetId(), g_reUnsubscribeTopic++);
|
||||
}
|
||||
|
||||
static void CASE_ReleaseIUnknown(PubSubInterface *fapi)
|
||||
{
|
||||
printf("[Broadcast Test][TaskID:%p][Step:%d][ReleaseIUnknown S:%s]: BEGIN\n",
|
||||
osThreadGetId(), g_broadcastStep++, BROADCASR_TEST_SERVICE);
|
||||
int32 ref = fapi->Release((IUnknown *)fapi);
|
||||
if (ref <= 0) {
|
||||
printf("[Broadcast Test][TaskID:%p][Step:%d][ReleaseIUnknown S:%s]Error ref is %d!\n",
|
||||
osThreadGetId(), g_broadcastStep++, BROADCASR_TEST_SERVICE, ref);
|
||||
goto END;
|
||||
}
|
||||
printf("[Broadcast Test][TaskID:%p][Step:%d][ReleaseIUnknown S:%s]Success\n",
|
||||
osThreadGetId(), g_broadcastStep++, BROADCASR_TEST_SERVICE);
|
||||
END:
|
||||
printf("[Broadcast Test][TaskID:%p][Step:%d][ReleaseIUnknown S:%s]: END\n",
|
||||
osThreadGetId(), g_broadcastStep++, BROADCASR_TEST_SERVICE);
|
||||
}
|
||||
|
||||
static void RunTestCase(void)
|
||||
{
|
||||
PubSubInterface *fapi = CASE_GetIUnknown();
|
||||
CASE_AddAndUnsubscribeTopic(fapi);
|
||||
CASE_ModifyConsumer(fapi);
|
||||
CASE_ReUnsubscribeTopic(fapi);
|
||||
CASE_ReleaseIUnknown(fapi);
|
||||
}
|
||||
LAYER_INITCALL_DEF(RunTestCase, test, "test");
|
||||
/*
|
||||
* Copyright (c) 2020-2022 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 <stdint.h>
|
||||
#include "samgr_lite.h"
|
||||
#include "broadcast_interface.h"
|
||||
#include <ohos_init.h>
|
||||
#include <securec.h>
|
||||
#include <los_base.h>
|
||||
#include <cmsis_os.h>
|
||||
#include "time_adapter.h"
|
||||
|
||||
#define TEST_LEN 10
|
||||
#define WAIT_PUB_PROC 1000
|
||||
#define BROADCAST_TEST_SERVICE "broadcast test"
|
||||
|
||||
static uint32_t g_callbackStep = 0;
|
||||
|
||||
static void C1Callback(Consumer *consumer, const Topic *topic, const Request *request)
|
||||
{
|
||||
(void)consumer;
|
||||
(void)topic;
|
||||
printf("[Broadcast Test][TaskID:%u][Step:%u][C1 Callback]c1 is being called data is :%s \n",
|
||||
(int)osThreadGetId(), g_callbackStep++, (char *)request->data);
|
||||
}
|
||||
|
||||
static void C2Callback(Consumer *consumer, const Topic *topic, const Request *request)
|
||||
{
|
||||
(void)consumer;
|
||||
(void)topic;
|
||||
printf("[Broadcast Test][TaskID:%u][Step:%u][C2 Callback]c2 is being called data is :%s \n",
|
||||
(int)osThreadGetId(), g_callbackStep++, (char *)request->data);
|
||||
}
|
||||
|
||||
static BOOL Equal(const Consumer *current, const Consumer *other)
|
||||
{
|
||||
return (current->Notify == other->Notify);
|
||||
}
|
||||
|
||||
static const char *GetName(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
return BROADCAST_TEST_SERVICE;
|
||||
};
|
||||
|
||||
static Identity g_identity = { -1, -1, NULL};
|
||||
static volatile uint32_t g_broadcastStep = 0;
|
||||
|
||||
static BOOL Initialize(Service *service, Identity identity)
|
||||
{
|
||||
g_identity = identity;
|
||||
(void)service;
|
||||
printf("[Broadcast Test][TaskID:%u][Step:%u][Reg Finish S:%s]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_broadcastStep++, BROADCAST_TEST_SERVICE, SAMGR_GetProcessTime());
|
||||
return TRUE;
|
||||
};
|
||||
|
||||
static BOOL MessageHandle(Service *service, Request *msg)
|
||||
{
|
||||
printf("[Broadcast Test][TaskID:%u] msgId<%d>: %s \n", (int)osThreadGetId(), msg->msgId, (char *)msg->data);
|
||||
(void)service;
|
||||
return FALSE;
|
||||
};
|
||||
|
||||
static TaskConfig GetTaskConfig(Service *service)
|
||||
{
|
||||
TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL, 0x800, 20, SHARED_TASK};
|
||||
(void)service;
|
||||
return config;
|
||||
};
|
||||
|
||||
static Service g_testService = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
|
||||
static void Init(void)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterService(&g_testService);
|
||||
printf("[Broadcast Test][TaskID:%u][Step:%u][Reg S:%s]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_broadcastStep++, BROADCAST_TEST_SERVICE, SAMGR_GetProcessTime());
|
||||
}
|
||||
|
||||
SYSEX_SERVICE_INIT(Init);
|
||||
|
||||
static PubSubInterface *CASE_GetIUnknown(void)
|
||||
{
|
||||
PubSubInterface *fapi = NULL;
|
||||
printf("[Broadcast Test][TaskID:%u][Step:%u][GetIUnknown S:%s]: BEGIN\n",
|
||||
(int)osThreadGetId(), g_broadcastStep++, BROADCAST_TEST_SERVICE);
|
||||
IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE, PUB_SUB_FEATURE);
|
||||
if (iUnknown == NULL) {
|
||||
printf("[Broadcast Test][TaskID:%u][Step:%u][GetDefaultFeatureApi S:%s]Error is NULL!\n",
|
||||
(int)osThreadGetId(), g_broadcastStep++, BROADCAST_TEST_SERVICE);
|
||||
goto END;
|
||||
}
|
||||
|
||||
int result = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&fapi);
|
||||
if (result != 0 || fapi == NULL) {
|
||||
printf("[Broadcast Test][TaskID:%u][Step:%u][QueryInterface S:%s]Error is NULL!\n",
|
||||
(int)osThreadGetId(), g_broadcastStep++, BROADCAST_TEST_SERVICE);
|
||||
goto END;
|
||||
}
|
||||
printf("[Broadcast Test][TaskID:%u][Step:%u][GetIUnknown S:%s]Success\n",
|
||||
(int)osThreadGetId(), g_broadcastStep++, BROADCAST_TEST_SERVICE);
|
||||
END:
|
||||
printf("[Broadcast Test][TaskID:%u][Step:%u][GetIUnknown S:%s]: END\n",
|
||||
(int)osThreadGetId(), g_broadcastStep++, BROADCAST_TEST_SERVICE);
|
||||
return fapi;
|
||||
}
|
||||
|
||||
static uint32_t g_addTopicStep = 0;
|
||||
static uint32_t g_unsubscribeTopicStep = 0;
|
||||
|
||||
static void CASE_AddAndUnsubscribeTopic(PubSubInterface *fapi)
|
||||
{
|
||||
Subscriber *subscriber = &fapi->subscriber;
|
||||
Provider *provider = &fapi->provider;
|
||||
static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal};
|
||||
static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal};
|
||||
// add topic test
|
||||
printf("[Topic Test][TaskID:%u][Step:%u][Add Topic]: BEGIN\n", (int)osThreadGetId(), g_addTopicStep++);
|
||||
Topic topic0 = 0;
|
||||
subscriber->AddTopic((IUnknown *)fapi, &topic0);
|
||||
subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1);
|
||||
subscriber->Subscribe((IUnknown *)fapi, &topic0, &c2);
|
||||
provider->Publish((IUnknown *)fapi, &topic0, (uint8_t *) "==>111<==", TEST_LEN);
|
||||
Topic topic1 = 0x10000;
|
||||
subscriber->AddTopic((IUnknown *)fapi, &topic1);
|
||||
subscriber->Subscribe((IUnknown *)fapi, &topic1, &c1);
|
||||
subscriber->Subscribe((IUnknown *)fapi, &topic1, &c2);
|
||||
provider->Publish((IUnknown *)fapi, &topic1, (uint8_t *) "==>444<==", TEST_LEN);
|
||||
printf("[Topic Test][TaskID:%u][Step:%u][Add Topic]: Success!\n", (int)osThreadGetId(), g_addTopicStep++);
|
||||
printf("[Topic Test][TaskID:%u][Step:%u][Add Topic]: END\n", (int)osThreadGetId(), g_addTopicStep++);
|
||||
// unsubscribe topic0 test
|
||||
printf("[Topic Test][TaskID:%u][Step:%u][Unsubscribe Topic]: BEGIN\n", (int)osThreadGetId(),
|
||||
g_unsubscribeTopicStep++);
|
||||
LOS_Msleep(WAIT_PUB_PROC);
|
||||
subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1);
|
||||
provider->Publish((IUnknown *)fapi, &topic0, (uint8_t *) "@@@222@@@", TEST_LEN);
|
||||
LOS_Msleep(WAIT_PUB_PROC);
|
||||
subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c2);
|
||||
provider->Publish((IUnknown *)fapi, &topic0, (uint8_t *) "@@@333@@@", TEST_LEN);
|
||||
provider->Publish((IUnknown *)fapi, &topic1, (uint8_t *) "@@@444@@@", TEST_LEN);
|
||||
printf("[Topic Test][TaskID:%u][Step:%u][Unsubscribe Topic]: Success!\n",
|
||||
(int)osThreadGetId(), g_unsubscribeTopicStep++);
|
||||
printf("[Topic Test][TaskID:%u][Step:%u][Unsubscribe Topic]: END\n", (int)osThreadGetId(),
|
||||
g_unsubscribeTopicStep++);
|
||||
}
|
||||
|
||||
static uint32_t g_modifyConsumerStep = 0;
|
||||
|
||||
static void CASE_ModifyConsumer(PubSubInterface *fapi)
|
||||
{
|
||||
Subscriber *subscriber = &fapi->subscriber;
|
||||
Provider *provider = &fapi->provider;
|
||||
static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal};
|
||||
static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal};
|
||||
// modify consumer test
|
||||
printf("[Topic Test][TaskID:%u][Step:%u][Modify Consumer]: BEGIN\n", (int)osThreadGetId(),
|
||||
g_modifyConsumerStep++);
|
||||
Topic topic2 = 0x100;
|
||||
subscriber->AddTopic((IUnknown *)fapi, &topic2);
|
||||
subscriber->Subscribe((IUnknown *)fapi, &topic2, &c1);
|
||||
provider->Publish((IUnknown *)fapi, &topic2, (uint8_t *) "==>555<==", TEST_LEN);
|
||||
LOS_Msleep(WAIT_PUB_PROC);
|
||||
subscriber->ModifyConsumer((IUnknown *)fapi, &topic2, &c1, &c2);
|
||||
provider->Publish((IUnknown *)fapi, &topic2, (uint8_t *) "@@@555@@@", TEST_LEN);
|
||||
printf("[Topic Test][TaskID:%u][Step:%u][Modify Consumer]: Success!\n", (int)osThreadGetId(),
|
||||
g_modifyConsumerStep++);
|
||||
printf("[Topic Test][TaskID:%u][Step:%u][Modify Consumer]: END\n", (int)osThreadGetId(),
|
||||
g_modifyConsumerStep++);
|
||||
}
|
||||
|
||||
static uint32_t g_reUnsubscribeTopic = 0;
|
||||
|
||||
static void CASE_ReUnsubscribeTopic(PubSubInterface *fapi)
|
||||
{
|
||||
Subscriber *subscriber = &fapi->subscriber;
|
||||
Provider *provider = &fapi->provider;
|
||||
static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal};
|
||||
printf("[Topic Test][TaskID:%u][Step:%u][ReUnsubscribe Topic]: BEGIN\n", (int)osThreadGetId(),
|
||||
g_reUnsubscribeTopic++);
|
||||
Topic topic3 = 0x1000;
|
||||
subscriber->AddTopic((IUnknown *)fapi, &topic3);
|
||||
subscriber->Subscribe((IUnknown *)fapi, &topic3, &c1);
|
||||
provider->Publish((IUnknown *)fapi, &topic3, (uint8_t *) "==>666<==", TEST_LEN);
|
||||
LOS_Msleep(WAIT_PUB_PROC);
|
||||
Consumer *retConsumer = subscriber->Unsubscribe((IUnknown *)fapi, &topic3, &c1);
|
||||
if (retConsumer == NULL) {
|
||||
printf("[Topic Test][TaskID:%u][Step:%u][ReUnsubscribe Topic]: Unsubscribe Topic lead to NULL return value\n",
|
||||
(int)osThreadGetId(), g_reUnsubscribeTopic++);
|
||||
}
|
||||
retConsumer = subscriber->Unsubscribe((IUnknown *)fapi, &topic3, &c1);
|
||||
if (retConsumer == NULL) {
|
||||
printf("[Topic Test][TaskID:%u][Step:%u][ReUnsubscribe Topic]: ReUnsubscribe Topic lead to NULL return value\n",
|
||||
(int)osThreadGetId(), g_reUnsubscribeTopic++);
|
||||
}
|
||||
provider->Publish((IUnknown *)fapi, &topic3, (uint8_t *) "@@@666@@@", TEST_LEN);
|
||||
printf("[Topic Test][TaskID:%u][Step:%u][ReUnsubscribe Topic]: Success!\n",
|
||||
(int)osThreadGetId(), g_reUnsubscribeTopic++);
|
||||
printf("[Topic Test][TaskID:%u][Step:%u][ReUnsubscribe Topic]: END\n", (int)osThreadGetId(),
|
||||
g_reUnsubscribeTopic++);
|
||||
}
|
||||
|
||||
static void CASE_ReleaseIUnknown(PubSubInterface *fapi)
|
||||
{
|
||||
printf("[Broadcast Test][TaskID:%u][Step:%u][ReleaseIUnknown S:%s]: BEGIN\n",
|
||||
(int)osThreadGetId(), g_broadcastStep++, BROADCAST_TEST_SERVICE);
|
||||
int32 ref = fapi->Release((IUnknown *)fapi);
|
||||
if (ref <= 0) {
|
||||
printf("[Broadcast Test][TaskID:%u][Step:%u][ReleaseIUnknown S:%s]Error ref is %d!\n",
|
||||
(int)osThreadGetId(), g_broadcastStep++, BROADCAST_TEST_SERVICE, ref);
|
||||
goto END;
|
||||
}
|
||||
printf("[Broadcast Test][TaskID:%u][Step:%u][ReleaseIUnknown S:%s]Success\n",
|
||||
(int)osThreadGetId(), g_broadcastStep++, BROADCAST_TEST_SERVICE);
|
||||
END:
|
||||
printf("[Broadcast Test][TaskID:%u][Step:%u][ReleaseIUnknown S:%s]: END\n",
|
||||
(int)osThreadGetId(), g_broadcastStep++, BROADCAST_TEST_SERVICE);
|
||||
}
|
||||
|
||||
static void RunTestCase(void)
|
||||
{
|
||||
PubSubInterface *fapi = CASE_GetIUnknown();
|
||||
CASE_AddAndUnsubscribeTopic(fapi);
|
||||
CASE_ModifyConsumer(fapi);
|
||||
CASE_ReUnsubscribeTopic(fapi);
|
||||
CASE_ReleaseIUnknown(fapi);
|
||||
}
|
||||
|
||||
LAYER_INITCALL_DEF(RunTestCase, test, "test");
|
||||
|
||||
Executable → Regular
+36
-44
@@ -1,44 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 LITE_EXAMPLE_H
|
||||
#define LITE_EXAMPLE_H
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
#define EXAMPLE_SERVICE "example"
|
||||
#define EXAMPLE_FEATURE "example"
|
||||
|
||||
#define BOOT_SYS_SERVICE1 "sys_s1"
|
||||
#define BOOT_SYS_SERVICE2 "sys_s2"
|
||||
#define BOOT_SYS_FEATURE1 "sys_f1"
|
||||
#define BOOT_SYS_FEATURE2 "sys_f2"
|
||||
|
||||
#define BOOT_SYSEX_SERVICE1 "sysex_s1"
|
||||
#define BOOT_SYSEX_SERVICE2 "sysex_s2"
|
||||
#define BOOT_SYSEX_FEATURE1 "sysex_f1"
|
||||
#define BOOT_SYSEX_FEATURE2 "sysex_f2"
|
||||
|
||||
#define TASK_SERVICE1 "task_s1"
|
||||
#define TASK_SERVICE2 "task_s2"
|
||||
#define TASK_SERVICE3 "task_s3"
|
||||
#define TASK_SERVICE4 "task_s4"
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif // LITE_EXAMPLE_H
|
||||
/*
|
||||
* Copyright (c) 2020-2022 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 LITE_EXAMPLE_H
|
||||
#define LITE_EXAMPLE_H
|
||||
|
||||
#define EXAMPLE_SERVICE "example"
|
||||
#define EXAMPLE_FEATURE "example"
|
||||
|
||||
#define BOOT_SYS_SERVICE1 "sys_s1"
|
||||
#define BOOT_SYS_SERVICE2 "sys_s2"
|
||||
#define BOOT_SYS_FEATURE1 "sys_f1"
|
||||
#define BOOT_SYS_FEATURE2 "sys_f2"
|
||||
|
||||
#define BOOT_SYSEX_SERVICE1 "sysex_s1"
|
||||
#define BOOT_SYSEX_SERVICE2 "sysex_s2"
|
||||
#define BOOT_SYSEX_FEATURE1 "sysex_f1"
|
||||
#define BOOT_SYSEX_FEATURE2 "sysex_f2"
|
||||
|
||||
#define TASK_SERVICE1 "task_s1"
|
||||
#define TASK_SERVICE2 "task_s2"
|
||||
#define TASK_SERVICE3 "task_s3"
|
||||
#define TASK_SERVICE4 "task_s4"
|
||||
|
||||
#endif // LITE_EXAMPLE_H
|
||||
|
||||
Executable → Regular
+320
-305
@@ -1,305 +1,320 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "example.h"
|
||||
#include <ohos_init.h>
|
||||
#include <securec.h>
|
||||
#include <los_base.h>
|
||||
#include <cmsis_os.h>
|
||||
#include <samgr_maintenance.h>
|
||||
#include "iunknown.h"
|
||||
#include "feature.h"
|
||||
#include "service.h"
|
||||
#include "samgr_lite.h"
|
||||
#include "time_adapter.h"
|
||||
|
||||
#define WAIT_FEATURE_PROC 1000
|
||||
enum MessageId {
|
||||
MSG_PROC,
|
||||
MSG_TIME_PROC,
|
||||
};
|
||||
|
||||
struct Payload {
|
||||
int id;
|
||||
const char *name;
|
||||
int value;
|
||||
};
|
||||
|
||||
typedef struct DemoApi {
|
||||
INHERIT_IUNKNOWN;
|
||||
BOOL (*AsyncCall)(IUnknown *iUnknown, const char *buff);
|
||||
BOOL (*AsyncTimeCall)(IUnknown *iUnknown);
|
||||
BOOL (*SyncCall)(IUnknown *iUnknown, struct Payload *payload);
|
||||
BOOL (*AsyncCallBack)(IUnknown *iUnknown, const char *buff, Handler handler);
|
||||
} DemoApi;
|
||||
|
||||
typedef struct DemoFeature {
|
||||
INHERIT_FEATURE;
|
||||
INHERIT_IUNKNOWNENTRY(DemoApi);
|
||||
Identity identity;
|
||||
} DemoFeature;
|
||||
|
||||
static BOOL AsyncCall(IUnknown *iUnknown, const char *body);
|
||||
static BOOL AsyncTimeCall(IUnknown *iUnknown);
|
||||
static BOOL SyncCall(IUnknown *iUnknown, struct Payload *payload);
|
||||
static BOOL AsyncCallBack(IUnknown *iUnknown, const char *body, Handler handler);
|
||||
static const char *FEATURE_GetName(Feature *feature);
|
||||
static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity);
|
||||
static void FEATURE_OnStop(Feature *feature, Identity identity);
|
||||
static BOOL FEATURE_OnMessage(Feature *feature, Request *request);
|
||||
static DemoFeature g_example = {
|
||||
.GetName = FEATURE_GetName,
|
||||
.OnInitialize = FEATURE_OnInitialize,
|
||||
.OnStop = FEATURE_OnStop,
|
||||
.OnMessage = FEATURE_OnMessage,
|
||||
DEFAULT_IUNKNOWN_ENTRY_BEGIN,
|
||||
.AsyncCall = AsyncCall,
|
||||
.AsyncTimeCall = AsyncTimeCall,
|
||||
.SyncCall = SyncCall,
|
||||
.AsyncCallBack = AsyncCallBack,
|
||||
DEFAULT_IUNKNOWN_ENTRY_END,
|
||||
.identity = {-1, -1, NULL},
|
||||
};
|
||||
static int g_regStep = 0;
|
||||
static const char *FEATURE_GetName(Feature *feature)
|
||||
{
|
||||
(void)feature;
|
||||
return EXAMPLE_FEATURE;
|
||||
}
|
||||
|
||||
static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity)
|
||||
{
|
||||
DemoFeature *demoFeature = (DemoFeature *)feature;
|
||||
demoFeature->identity = identity;
|
||||
printf("[Register Test][TaskID:%p][Step:%d][Reg Finish S:%s, F:%s]Time: %llu!\n",
|
||||
osThreadGetId(), g_regStep++, parent->GetName(parent), feature->GetName(feature), SAMGR_GetProcessTime());
|
||||
}
|
||||
|
||||
static void FEATURE_OnStop(Feature *feature, Identity identity)
|
||||
{
|
||||
(void)feature;
|
||||
(void)identity;
|
||||
g_example.identity.queueId = NULL;
|
||||
g_example.identity.featureId = -1;
|
||||
g_example.identity.serviceId = -1;
|
||||
}
|
||||
|
||||
static volatile uint32 g_asyncStep = 0;
|
||||
static BOOL FEATURE_OnMessage(Feature *feature, Request *request)
|
||||
{
|
||||
(void)feature;
|
||||
if (request->msgId == MSG_PROC) {
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][OnMessage: S:%s, F:%s] msgId<MSG_PROC> %s \n",
|
||||
osThreadGetId(), g_asyncStep++, EXAMPLE_SERVICE, feature->GetName(feature), (char *)request->data);
|
||||
Response response = {.data = "Yes, you did!", .len = 0};
|
||||
SAMGR_SendResponse(request, &response);
|
||||
return TRUE;
|
||||
} else {
|
||||
if (request->msgId == MSG_TIME_PROC) {
|
||||
LOS_Msleep(WAIT_FEATURE_PROC * 11); // sleep 11 seconds
|
||||
printf("[LPC Test][TaskID:%p][OnMessage: S:%s, F:%s] Time Message Get Value<%s>!",
|
||||
osThreadGetId(), EXAMPLE_SERVICE, feature->GetName(feature), request->msgValue ? "TRUE" : "FALSE");
|
||||
AsyncTimeCall(GET_IUNKNOWN(g_example));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][OnMessage S:%s, F:%s] Inner Error! \n",
|
||||
osThreadGetId(), g_asyncStep++, EXAMPLE_SERVICE, feature->GetName(feature));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOL SyncCall(IUnknown *iUnknown, struct Payload *payload)
|
||||
{
|
||||
(void)iUnknown;
|
||||
if (payload != NULL && payload->id >= 0 && payload->name != NULL) {
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][SyncCall API] Id:%d, name:%s, value:%d \n",
|
||||
osThreadGetId(), g_asyncStep++, payload->id, payload->name, payload->value);
|
||||
return TRUE;
|
||||
}
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][SyncCall API] Input Error! \n", osThreadGetId(), g_asyncStep++);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOL AsyncCall(IUnknown *iUnknown, const char *body)
|
||||
{
|
||||
Request request = {.msgId = MSG_PROC, .msgValue = 0};
|
||||
request.len = (uint32_t)(strlen(body) + 1);
|
||||
request.data = malloc(request.len);
|
||||
if (request.data == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
if (strcpy_s(request.data, request.len, body) != EOK) {
|
||||
free(request.data);
|
||||
return FALSE;
|
||||
}
|
||||
DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown);
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][AsyncCall API] Send request! \n", osThreadGetId(), g_asyncStep++);
|
||||
return SAMGR_SendRequest(&feature->identity, &request, NULL);
|
||||
}
|
||||
static BOOL AsyncTimeCall(IUnknown *iUnknown)
|
||||
{
|
||||
static int8 cnt = 0;
|
||||
cnt = (cnt + 1) % 2; // mod 2 to get async status
|
||||
Request request = {.msgId = MSG_TIME_PROC, .msgValue = cnt};
|
||||
DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown);
|
||||
return SAMGR_SendRequest(&feature->identity, &request, NULL);
|
||||
}
|
||||
static BOOL AsyncCallBack(IUnknown *iUnknown, const char *body, Handler handler)
|
||||
{
|
||||
Request request = {.msgId = MSG_PROC, .msgValue = 0};
|
||||
request.len = (uint32_t)(strlen(body) + 1);
|
||||
request.data = malloc(request.len);
|
||||
if (request.data == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
if (strcpy_s(request.data, request.len, body) != EOK) {
|
||||
free(request.data);
|
||||
return FALSE;
|
||||
}
|
||||
DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown);
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][AsyncCallBack API] Send request! \n",
|
||||
osThreadGetId(), g_asyncStep++);
|
||||
return SAMGR_SendRequest(&feature->identity, &request, handler);
|
||||
}
|
||||
|
||||
static void Init(void)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterFeature(EXAMPLE_SERVICE, (Feature *)&g_example);
|
||||
SAMGR_GetInstance()->RegisterFeatureApi(EXAMPLE_SERVICE, EXAMPLE_FEATURE, GET_IUNKNOWN(g_example));
|
||||
printf("[Register Test][TaskID:%p][Step:%d][Reg S:%s, F:%s]Time: %llu!\n",
|
||||
osThreadGetId(), g_regStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE, SAMGR_GetProcessTime());
|
||||
}
|
||||
SYSEX_FEATURE_INIT(Init);
|
||||
static int g_discoverStep = 0;
|
||||
static DemoApi *CASE_GetIUnknown(void)
|
||||
{
|
||||
DemoApi *demoApi = NULL;
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][GetIUnknown S:%s, F:%s]: BEGIN\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
if (iUnknown == NULL) {
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][GetFeatureApi S:%s, F:%s]Error is NULL!\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
goto END;
|
||||
}
|
||||
int result = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&demoApi);
|
||||
if (result != 0 || demoApi == NULL) {
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][QueryInterface S:%s, F:%s]Error is NULL!\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
goto END;
|
||||
}
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][GetIUnknown S:%s, F:%s]Success\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
END:
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][GetIUnknown S:%s, F:%s]: END\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
return demoApi;
|
||||
}
|
||||
|
||||
static void CASE_SyncCall(DemoApi *demoApi)
|
||||
{
|
||||
if (demoApi->SyncCall == NULL) {
|
||||
return;
|
||||
}
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][SyncCall]: BEGIN! \n", osThreadGetId(), g_asyncStep++);
|
||||
struct Payload payload = {
|
||||
.id = 0,
|
||||
.name = "I wanna sync call good result!",
|
||||
.value = 1
|
||||
};
|
||||
if (!demoApi->SyncCall((IUnknown *)demoApi, &payload)) {
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][SyncCall]Error return false! \n",
|
||||
osThreadGetId(), g_asyncStep++);
|
||||
goto END;
|
||||
}
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][SyncCall]Success!\n",
|
||||
osThreadGetId(), g_asyncStep++);
|
||||
END:
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][SyncCall]: END\n",
|
||||
osThreadGetId(), g_asyncStep++);
|
||||
}
|
||||
|
||||
|
||||
static void CASE_AsyncCall(DemoApi *demoApi)
|
||||
{
|
||||
if (demoApi->AsyncCall == NULL) {
|
||||
return;
|
||||
}
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][AsyncCall]: BEGIN! \n", osThreadGetId(), g_asyncStep++);
|
||||
uint32 count = g_asyncStep;
|
||||
demoApi->AsyncCall((IUnknown *)demoApi, "I wanna async call good result!");
|
||||
LOS_Msleep(WAIT_FEATURE_PROC);
|
||||
if (count == g_asyncStep) {
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][AsyncCall] result is faild! \n", osThreadGetId(), g_asyncStep++);
|
||||
goto END;
|
||||
}
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][AsyncCall]Success! \n", osThreadGetId(), g_asyncStep++);
|
||||
END:
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][AsyncCall]: END! \n", osThreadGetId(), g_asyncStep++);
|
||||
}
|
||||
|
||||
static void CASE_AsyncTimeCall(DemoApi *demoApi)
|
||||
{
|
||||
if (demoApi->AsyncCall == NULL) {
|
||||
return;
|
||||
}
|
||||
demoApi->AsyncTimeCall((IUnknown *)demoApi);
|
||||
}
|
||||
|
||||
void AsyncHandler(const Request *request, const Response *response)
|
||||
{
|
||||
(void)request;
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][AsyncCallBack]Success! Response:%s \n",
|
||||
osThreadGetId(), g_asyncStep++, (char *)response->data);
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][AsyncCallBack]: END! \n", osThreadGetId(), g_asyncStep++);
|
||||
}
|
||||
|
||||
static void CASE_AsyncCallBack(DemoApi *demoApi)
|
||||
{
|
||||
if (demoApi->AsyncCallBack == NULL) {
|
||||
return;
|
||||
}
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][AsyncCallBack]: BEGIN! \n", osThreadGetId(), g_asyncStep++);
|
||||
demoApi->AsyncCallBack((IUnknown *)demoApi, "I wanna async call callback good result!", AsyncHandler);
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][AsyncCallBack]Wait for response! \n",
|
||||
osThreadGetId(), g_asyncStep++);
|
||||
}
|
||||
|
||||
static void CASE_ReleaseIUnknown(DemoApi *demoApi)
|
||||
{
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][ReleaseIUnknown S:%s, F:%s]: BEGIN\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
int32 ref = demoApi->Release((IUnknown *)demoApi);
|
||||
if (ref <= 0) {
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][ReleaseIUnknown S:%s, F:%s]Error ref is %d!\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE, ref);
|
||||
goto END;
|
||||
}
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][ReleaseIUnknown S:%s, F:%s]Success\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
END:
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][ReleaseIUnknown S:%s, F:%s]: END\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
}
|
||||
|
||||
static void RunTestCase(void)
|
||||
{
|
||||
DemoApi *demoApi = CASE_GetIUnknown();
|
||||
CASE_SyncCall(demoApi);
|
||||
CASE_AsyncCall(demoApi);
|
||||
CASE_AsyncCallBack(demoApi);
|
||||
CASE_AsyncTimeCall(demoApi);
|
||||
CASE_ReleaseIUnknown(demoApi);
|
||||
}
|
||||
LAYER_INITCALL_DEF(RunTestCase, test, "test");
|
||||
/*
|
||||
* Copyright (c) 2020-2022 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 "example.h"
|
||||
#include <stdint.h>
|
||||
#include <ohos_init.h>
|
||||
#include <securec.h>
|
||||
#include <los_base.h>
|
||||
#include <cmsis_os.h>
|
||||
#include <samgr_maintenance.h>
|
||||
#include "iunknown.h"
|
||||
#include "feature.h"
|
||||
#include "service.h"
|
||||
#include "samgr_lite.h"
|
||||
#include "time_adapter.h"
|
||||
|
||||
#define WAIT_FEATURE_PROC 1000
|
||||
|
||||
enum MessageId {
|
||||
MSG_PROC,
|
||||
MSG_TIME_PROC,
|
||||
};
|
||||
|
||||
struct Payload {
|
||||
int id;
|
||||
const char *name;
|
||||
int value;
|
||||
};
|
||||
|
||||
typedef struct DemoApi {
|
||||
INHERIT_IUNKNOWN;
|
||||
BOOL (*AsyncCall)(IUnknown *iUnknown, const char *buff);
|
||||
BOOL (*AsyncTimeCall)(IUnknown *iUnknown);
|
||||
BOOL (*SyncCall)(IUnknown *iUnknown, struct Payload *payload);
|
||||
BOOL (*AsyncCallBack)(IUnknown *iUnknown, const char *buff, Handler handler);
|
||||
} DemoApi;
|
||||
|
||||
typedef struct DemoFeature {
|
||||
INHERIT_FEATURE;
|
||||
INHERIT_IUNKNOWNENTRY(DemoApi);
|
||||
Identity identity;
|
||||
} DemoFeature;
|
||||
|
||||
static BOOL AsyncCall(IUnknown *iUnknown, const char *body);
|
||||
static BOOL AsyncTimeCall(IUnknown *iUnknown);
|
||||
static BOOL SyncCall(IUnknown *iUnknown, struct Payload *payload);
|
||||
static BOOL AsyncCallBack(IUnknown *iUnknown, const char *body, Handler handler);
|
||||
static const char *FEATURE_GetName(Feature *feature);
|
||||
static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity);
|
||||
static void FEATURE_OnStop(Feature *feature, Identity identity);
|
||||
static BOOL FEATURE_OnMessage(Feature *feature, Request *request);
|
||||
static DemoFeature g_example = {
|
||||
.GetName = FEATURE_GetName,
|
||||
.OnInitialize = FEATURE_OnInitialize,
|
||||
.OnStop = FEATURE_OnStop,
|
||||
.OnMessage = FEATURE_OnMessage,
|
||||
DEFAULT_IUNKNOWN_ENTRY_BEGIN,
|
||||
.AsyncCall = AsyncCall,
|
||||
.AsyncTimeCall = AsyncTimeCall,
|
||||
.SyncCall = SyncCall,
|
||||
.AsyncCallBack = AsyncCallBack,
|
||||
DEFAULT_IUNKNOWN_ENTRY_END,
|
||||
.identity = {-1, -1, NULL},
|
||||
};
|
||||
static uint32_t g_regStep = 0;
|
||||
|
||||
static const char *FEATURE_GetName(Feature *feature)
|
||||
{
|
||||
(void)feature;
|
||||
return EXAMPLE_FEATURE;
|
||||
}
|
||||
|
||||
static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity)
|
||||
{
|
||||
DemoFeature *demoFeature = (DemoFeature *)feature;
|
||||
demoFeature->identity = identity;
|
||||
printf("[Register Test][TaskID:%u][Step:%u][Reg Finish S:%s, F:%s]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_regStep++, parent->GetName(parent), feature->GetName(feature),
|
||||
SAMGR_GetProcessTime());
|
||||
}
|
||||
|
||||
static void FEATURE_OnStop(Feature *feature, Identity identity)
|
||||
{
|
||||
(void)feature;
|
||||
(void)identity;
|
||||
g_example.identity.queueId = NULL;
|
||||
g_example.identity.featureId = -1;
|
||||
g_example.identity.serviceId = -1;
|
||||
}
|
||||
|
||||
static volatile uint32 g_asyncStep = 0;
|
||||
|
||||
static BOOL FEATURE_OnMessage(Feature *feature, Request *request)
|
||||
{
|
||||
(void)feature;
|
||||
if (request->msgId == MSG_PROC) {
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][OnMessage: S:%s, F:%s] msgId<MSG_PROC> %s \n",
|
||||
(int)osThreadGetId(), g_asyncStep++, EXAMPLE_SERVICE, feature->GetName(feature),
|
||||
(char *)request->data);
|
||||
Response response = {.data = "Yes, you did!", .len = 0};
|
||||
SAMGR_SendResponse(request, &response);
|
||||
return TRUE;
|
||||
} else {
|
||||
if (request->msgId == MSG_TIME_PROC) {
|
||||
LOS_Msleep(WAIT_FEATURE_PROC * 11); // sleep 11 seconds
|
||||
printf("[LPC Test][TaskID:%u][OnMessage: S:%s, F:%s] Time Message Get Value<%s>!",
|
||||
(int)osThreadGetId(), EXAMPLE_SERVICE, feature->GetName(feature),
|
||||
request->msgValue ? "TRUE" : "FALSE");
|
||||
AsyncTimeCall(GET_IUNKNOWN(g_example));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][OnMessage S:%s, F:%s] Inner Error! \n",
|
||||
(int)osThreadGetId(), g_asyncStep++, EXAMPLE_SERVICE, feature->GetName(feature));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOL SyncCall(IUnknown *iUnknown, struct Payload *payload)
|
||||
{
|
||||
(void)iUnknown;
|
||||
if (payload != NULL && payload->id >= 0 && payload->name != NULL) {
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][SyncCall API] Id:%d, name:%s, value:%d \n",
|
||||
(int)osThreadGetId(), g_asyncStep++, payload->id, payload->name, payload->value);
|
||||
return TRUE;
|
||||
}
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][SyncCall API] Input Error! \n", (int)osThreadGetId(), g_asyncStep++);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOL AsyncCall(IUnknown *iUnknown, const char *body)
|
||||
{
|
||||
Request request = {.msgId = MSG_PROC, .msgValue = 0};
|
||||
request.len = (uint32_t)(strlen(body) + 1);
|
||||
request.data = malloc(request.len);
|
||||
if (request.data == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
if (strcpy_s(request.data, request.len, body) != EOK) {
|
||||
free(request.data);
|
||||
return FALSE;
|
||||
}
|
||||
DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown);
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][AsyncCall API] Send request! \n", (int)osThreadGetId(), g_asyncStep++);
|
||||
return SAMGR_SendRequest(&feature->identity, &request, NULL);
|
||||
}
|
||||
|
||||
static BOOL AsyncTimeCall(IUnknown *iUnknown)
|
||||
{
|
||||
static int8 cnt = 0;
|
||||
cnt = (cnt + 1) % 2; // mod 2 to get async status
|
||||
Request request = {.msgId = MSG_TIME_PROC, .msgValue = cnt};
|
||||
DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown);
|
||||
return SAMGR_SendRequest(&feature->identity, &request, NULL);
|
||||
}
|
||||
|
||||
static BOOL AsyncCallBack(IUnknown *iUnknown, const char *body, Handler handler)
|
||||
{
|
||||
Request request = {.msgId = MSG_PROC, .msgValue = 0};
|
||||
request.len = (uint32_t)(strlen(body) + 1);
|
||||
request.data = malloc(request.len);
|
||||
if (request.data == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
if (strcpy_s(request.data, request.len, body) != EOK) {
|
||||
free(request.data);
|
||||
return FALSE;
|
||||
}
|
||||
DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown);
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][AsyncCallBack API] Send request! \n",
|
||||
(int)osThreadGetId(), g_asyncStep++);
|
||||
return SAMGR_SendRequest(&feature->identity, &request, handler);
|
||||
}
|
||||
|
||||
static void Init(void)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterFeature(EXAMPLE_SERVICE, (Feature *)&g_example);
|
||||
SAMGR_GetInstance()->RegisterFeatureApi(EXAMPLE_SERVICE, EXAMPLE_FEATURE, GET_IUNKNOWN(g_example));
|
||||
printf("[Register Test][TaskID:%u][Step:%u][Reg S:%s, F:%s]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_regStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE, SAMGR_GetProcessTime());
|
||||
}
|
||||
|
||||
SYSEX_FEATURE_INIT(Init);
|
||||
|
||||
static uint32_t g_discoverStep = 0;
|
||||
|
||||
static DemoApi *CASE_GetIUnknown(void)
|
||||
{
|
||||
DemoApi *demoApi = NULL;
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][GetIUnknown S:%s, F:%s]: BEGIN\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
if (iUnknown == NULL) {
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][GetFeatureApi S:%s, F:%s]Error is NULL!\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
goto END;
|
||||
}
|
||||
int result = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&demoApi);
|
||||
if (result != 0 || demoApi == NULL) {
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][QueryInterface S:%s, F:%s]Error is NULL!\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
goto END;
|
||||
}
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][GetIUnknown S:%s, F:%s]Success\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
END:
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][GetIUnknown S:%s, F:%s]: END\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
return demoApi;
|
||||
}
|
||||
|
||||
static void CASE_SyncCall(DemoApi *demoApi)
|
||||
{
|
||||
if (demoApi->SyncCall == NULL) {
|
||||
return;
|
||||
}
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][SyncCall]: BEGIN! \n", (int)osThreadGetId(), g_asyncStep++);
|
||||
struct Payload payload = {
|
||||
.id = 0,
|
||||
.name = "I want to sync call good result!",
|
||||
.value = 1
|
||||
};
|
||||
if (!demoApi->SyncCall((IUnknown *)demoApi, &payload)) {
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][SyncCall]Error return false! \n",
|
||||
(int)osThreadGetId(), g_asyncStep++);
|
||||
goto END;
|
||||
}
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][SyncCall]Success!\n",
|
||||
(int)osThreadGetId(), g_asyncStep++);
|
||||
END:
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][SyncCall]: END\n",
|
||||
(int)osThreadGetId(), g_asyncStep++);
|
||||
}
|
||||
|
||||
|
||||
static void CASE_AsyncCall(DemoApi *demoApi)
|
||||
{
|
||||
if (demoApi->AsyncCall == NULL) {
|
||||
return;
|
||||
}
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][AsyncCall]: BEGIN! \n", (int)osThreadGetId(), g_asyncStep++);
|
||||
uint32 count = g_asyncStep;
|
||||
demoApi->AsyncCall((IUnknown *)demoApi, "I want to async call good result!");
|
||||
LOS_Msleep(WAIT_FEATURE_PROC);
|
||||
if (count == g_asyncStep) {
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][AsyncCall] result is failed! \n", (int)osThreadGetId(),
|
||||
g_asyncStep++);
|
||||
goto END;
|
||||
}
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][AsyncCall]Success! \n", (int)osThreadGetId(), g_asyncStep++);
|
||||
END:
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][AsyncCall]: END! \n", (int)osThreadGetId(), g_asyncStep++);
|
||||
}
|
||||
|
||||
static void CASE_AsyncTimeCall(DemoApi *demoApi)
|
||||
{
|
||||
if (demoApi->AsyncCall == NULL) {
|
||||
return;
|
||||
}
|
||||
demoApi->AsyncTimeCall((IUnknown *)demoApi);
|
||||
}
|
||||
|
||||
void AsyncHandler(const Request *request, const Response *response)
|
||||
{
|
||||
(void)request;
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][AsyncCallBack]Success! Response:%s \n",
|
||||
(int)osThreadGetId(), g_asyncStep++, (char *)response->data);
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][AsyncCallBack]: END! \n", (int)osThreadGetId(), g_asyncStep++);
|
||||
}
|
||||
|
||||
static void CASE_AsyncCallBack(DemoApi *demoApi)
|
||||
{
|
||||
if (demoApi->AsyncCallBack == NULL) {
|
||||
return;
|
||||
}
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][AsyncCallBack]: BEGIN! \n", (int)osThreadGetId(), g_asyncStep++);
|
||||
demoApi->AsyncCallBack((IUnknown *)demoApi, "I want to async call callback good result!", AsyncHandler);
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][AsyncCallBack]Wait for response! \n",
|
||||
(int)osThreadGetId(), g_asyncStep++);
|
||||
}
|
||||
|
||||
static void CASE_ReleaseIUnknown(DemoApi *demoApi)
|
||||
{
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][ReleaseIUnknown S:%s, F:%s]: BEGIN\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
int32 ref = demoApi->Release((IUnknown *)demoApi);
|
||||
if (ref <= 0) {
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][ReleaseIUnknown S:%s, F:%s]Error ref is %d!\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE, ref);
|
||||
goto END;
|
||||
}
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][ReleaseIUnknown S:%s, F:%s]Success\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
END:
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][ReleaseIUnknown S:%s, F:%s]: END\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, EXAMPLE_FEATURE);
|
||||
}
|
||||
|
||||
static void RunTestCase(void)
|
||||
{
|
||||
DemoApi *demoApi = CASE_GetIUnknown();
|
||||
CASE_SyncCall(demoApi);
|
||||
CASE_AsyncCall(demoApi);
|
||||
CASE_AsyncCallBack(demoApi);
|
||||
CASE_AsyncTimeCall(demoApi);
|
||||
CASE_ReleaseIUnknown(demoApi);
|
||||
}
|
||||
|
||||
LAYER_INITCALL_DEF(RunTestCase, test, "test");
|
||||
|
||||
Executable → Regular
+179
-171
@@ -1,171 +1,179 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 <securec.h>
|
||||
#include <ohos_init.h>
|
||||
#include <cmsis_os.h>
|
||||
#include <samgr_maintenance.h>
|
||||
#include "service.h"
|
||||
#include "feature.h"
|
||||
#include "samgr_lite.h"
|
||||
|
||||
#define MAINTEN_SERVICE1 "mntn_s1"
|
||||
#define MAINTEN_SERVICE2 "mntn_s2"
|
||||
#define MAINTEN_SERVICE3 "mntn_s3"
|
||||
#define MAINTEN_SERVICE4 "mntn_s4"
|
||||
#define MAINTEN_FEATURE1 "mntn_f1"
|
||||
#define MAINTEN_FEATURE2 "mntn_f2"
|
||||
static const char *GetName(Service *service);
|
||||
static BOOL Initialize(Service *service, Identity identity);
|
||||
static BOOL MessageHandle(Service *service, Request *msg);
|
||||
static TaskConfig GetTaskConfig(Service *service);
|
||||
static const char *FEATURE_GetName(Feature *feature);
|
||||
static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity);
|
||||
static void FEATURE_OnStop(Feature *feature, Identity identity);
|
||||
static BOOL FEATURE_OnMessage(Feature *feature, Request *request);
|
||||
Service g_maintenExample1 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
Service g_maintenExample2 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
Service g_maintenExample3 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
Service g_maintenExample4 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
Feature g_maintenFeature1 = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage};
|
||||
Feature g_maintenFeature2 = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage};
|
||||
IUnknownEntry g_demoApi = {DEFAULT_IUNKNOWN_ENTRY_BEGIN, DEFAULT_IUNKNOWN_ENTRY_END};
|
||||
|
||||
static const char *FEATURE_GetName(Feature *feature)
|
||||
{
|
||||
if (feature == &g_maintenFeature1) {
|
||||
return MAINTEN_FEATURE1;
|
||||
}
|
||||
if (feature == &g_maintenFeature2) {
|
||||
return MAINTEN_FEATURE2;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity)
|
||||
{
|
||||
(void)feature;
|
||||
(void)parent;
|
||||
(void)identity;
|
||||
}
|
||||
|
||||
static void FEATURE_OnStop(Feature *feature, Identity identity)
|
||||
{
|
||||
(void)feature;
|
||||
(void)identity;
|
||||
}
|
||||
|
||||
static BOOL FEATURE_OnMessage(Feature *feature, Request *request)
|
||||
{
|
||||
(void)feature;
|
||||
(void)request;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static const char *GetName(Service *service)
|
||||
{
|
||||
if (service == &g_maintenExample1) {
|
||||
return MAINTEN_SERVICE1;
|
||||
}
|
||||
if (service == &g_maintenExample2) {
|
||||
return MAINTEN_SERVICE2;
|
||||
}
|
||||
if (service == &g_maintenExample3) {
|
||||
return MAINTEN_SERVICE3;
|
||||
}
|
||||
if (service == &g_maintenExample4) {
|
||||
return MAINTEN_SERVICE4;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BOOL Initialize(Service *service, Identity identity)
|
||||
{
|
||||
(void)identity;
|
||||
(void)service;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MessageHandle(Service *service, Request *msg)
|
||||
{
|
||||
(void)service;
|
||||
(void)msg;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static TaskConfig GetTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
TaskConfig config = {LEVEL_HIGH, PRI_NORMAL,
|
||||
0x800, 16, SHARED_TASK};
|
||||
if (service == &g_maintenExample4) {
|
||||
config.priority = PRI_ABOVE_NORMAL;
|
||||
config.stackSize = 0x400;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
static void SInit(Service *service)
|
||||
{
|
||||
if (service == &g_maintenExample4) {
|
||||
printf("[Maintenance Test][Before App Service Init]Print Uninitialized App Service\n");
|
||||
SAMGR_PrintServices();
|
||||
}
|
||||
SAMGR_GetInstance()->RegisterService(service);
|
||||
}
|
||||
|
||||
static void FInit(Feature *feature)
|
||||
{
|
||||
if (feature == &g_maintenFeature1) {
|
||||
SAMGR_GetInstance()->RegisterFeature(MAINTEN_SERVICE1, feature);
|
||||
SAMGR_GetInstance()->RegisterFeatureApi(MAINTEN_SERVICE1, MAINTEN_FEATURE1, GET_IUNKNOWN(g_demoApi));
|
||||
}
|
||||
if (feature == &g_maintenFeature2) {
|
||||
SAMGR_GetInstance()->RegisterFeature(MAINTEN_SERVICE2, feature);
|
||||
SAMGR_GetInstance()->RegisterDefaultFeatureApi(MAINTEN_SERVICE2, GET_IUNKNOWN(g_demoApi));
|
||||
}
|
||||
}
|
||||
|
||||
static void S1Init(void)
|
||||
{
|
||||
SInit(&g_maintenExample1);
|
||||
}
|
||||
static void S2Init(void)
|
||||
{
|
||||
SInit(&g_maintenExample2);
|
||||
}
|
||||
static void S3Init(void)
|
||||
{
|
||||
SInit(&g_maintenExample3);
|
||||
}
|
||||
static void S4Init(void)
|
||||
{
|
||||
SInit(&g_maintenExample4);
|
||||
}
|
||||
static void F1Init(void)
|
||||
{
|
||||
FInit(&g_maintenFeature1);
|
||||
}
|
||||
static void F2Init(void)
|
||||
{
|
||||
FInit(&g_maintenFeature2);
|
||||
}
|
||||
|
||||
SYSEX_SERVICE_INIT(S1Init);
|
||||
SYSEX_SERVICE_INIT(S2Init);
|
||||
SYSEX_SERVICE_INIT(S3Init);
|
||||
SYSEX_SERVICE_INIT(S4Init);
|
||||
SYSEX_FEATURE_INIT(F1Init);
|
||||
SYSEX_FEATURE_INIT(F2Init);
|
||||
/*
|
||||
* Copyright (c) 2020-2022 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 <stdint.h>
|
||||
#include <securec.h>
|
||||
#include <ohos_init.h>
|
||||
#include <cmsis_os.h>
|
||||
#include <samgr_maintenance.h>
|
||||
#include "service.h"
|
||||
#include "feature.h"
|
||||
#include "samgr_lite.h"
|
||||
|
||||
#define MAINTEN_SERVICE1 "mntn_s1"
|
||||
#define MAINTEN_SERVICE2 "mntn_s2"
|
||||
#define MAINTEN_SERVICE3 "mntn_s3"
|
||||
#define MAINTEN_SERVICE4 "mntn_s4"
|
||||
#define MAINTEN_FEATURE1 "mntn_f1"
|
||||
#define MAINTEN_FEATURE2 "mntn_f2"
|
||||
|
||||
static const char *GetName(Service *service);
|
||||
static BOOL Initialize(Service *service, Identity identity);
|
||||
static BOOL MessageHandle(Service *service, Request *msg);
|
||||
static TaskConfig GetTaskConfig(Service *service);
|
||||
static const char *FEATURE_GetName(Feature *feature);
|
||||
static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity);
|
||||
static void FEATURE_OnStop(Feature *feature, Identity identity);
|
||||
static BOOL FEATURE_OnMessage(Feature *feature, Request *request);
|
||||
|
||||
Service g_maintenExample1 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
Service g_maintenExample2 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
Service g_maintenExample3 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
Service g_maintenExample4 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
Feature g_maintenFeature1 = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage};
|
||||
Feature g_maintenFeature2 = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage};
|
||||
IUnknownEntry g_demoApi = {DEFAULT_IUNKNOWN_ENTRY_BEGIN, DEFAULT_IUNKNOWN_ENTRY_END};
|
||||
|
||||
static const char *FEATURE_GetName(Feature *feature)
|
||||
{
|
||||
if (feature == &g_maintenFeature1) {
|
||||
return MAINTEN_FEATURE1;
|
||||
}
|
||||
if (feature == &g_maintenFeature2) {
|
||||
return MAINTEN_FEATURE2;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity)
|
||||
{
|
||||
(void)feature;
|
||||
(void)parent;
|
||||
(void)identity;
|
||||
}
|
||||
|
||||
static void FEATURE_OnStop(Feature *feature, Identity identity)
|
||||
{
|
||||
(void)feature;
|
||||
(void)identity;
|
||||
}
|
||||
|
||||
static BOOL FEATURE_OnMessage(Feature *feature, Request *request)
|
||||
{
|
||||
(void)feature;
|
||||
(void)request;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static const char *GetName(Service *service)
|
||||
{
|
||||
if (service == &g_maintenExample1) {
|
||||
return MAINTEN_SERVICE1;
|
||||
}
|
||||
if (service == &g_maintenExample2) {
|
||||
return MAINTEN_SERVICE2;
|
||||
}
|
||||
if (service == &g_maintenExample3) {
|
||||
return MAINTEN_SERVICE3;
|
||||
}
|
||||
if (service == &g_maintenExample4) {
|
||||
return MAINTEN_SERVICE4;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BOOL Initialize(Service *service, Identity identity)
|
||||
{
|
||||
(void)identity;
|
||||
(void)service;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MessageHandle(Service *service, Request *msg)
|
||||
{
|
||||
(void)service;
|
||||
(void)msg;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static TaskConfig GetTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
TaskConfig config = {LEVEL_HIGH, PRI_NORMAL,
|
||||
0x800, 16, SHARED_TASK};
|
||||
if (service == &g_maintenExample4) {
|
||||
config.priority = PRI_ABOVE_NORMAL;
|
||||
config.stackSize = 0x400;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
static void SInit(Service *service)
|
||||
{
|
||||
if (service == &g_maintenExample4) {
|
||||
printf("[Maintenance Test][Before App Service Init]Print Uninitialized App Service\n");
|
||||
SAMGR_PrintServices();
|
||||
}
|
||||
SAMGR_GetInstance()->RegisterService(service);
|
||||
}
|
||||
|
||||
static void FInit(Feature *feature)
|
||||
{
|
||||
if (feature == &g_maintenFeature1) {
|
||||
SAMGR_GetInstance()->RegisterFeature(MAINTEN_SERVICE1, feature);
|
||||
SAMGR_GetInstance()->RegisterFeatureApi(MAINTEN_SERVICE1, MAINTEN_FEATURE1, GET_IUNKNOWN(g_demoApi));
|
||||
}
|
||||
if (feature == &g_maintenFeature2) {
|
||||
SAMGR_GetInstance()->RegisterFeature(MAINTEN_SERVICE2, feature);
|
||||
SAMGR_GetInstance()->RegisterDefaultFeatureApi(MAINTEN_SERVICE2, GET_IUNKNOWN(g_demoApi));
|
||||
}
|
||||
}
|
||||
|
||||
static void S1Init(void)
|
||||
{
|
||||
SInit(&g_maintenExample1);
|
||||
}
|
||||
|
||||
static void S2Init(void)
|
||||
{
|
||||
SInit(&g_maintenExample2);
|
||||
}
|
||||
|
||||
static void S3Init(void)
|
||||
{
|
||||
SInit(&g_maintenExample3);
|
||||
}
|
||||
|
||||
static void S4Init(void)
|
||||
{
|
||||
SInit(&g_maintenExample4);
|
||||
}
|
||||
|
||||
static void F1Init(void)
|
||||
{
|
||||
FInit(&g_maintenFeature1);
|
||||
}
|
||||
|
||||
static void F2Init(void)
|
||||
{
|
||||
FInit(&g_maintenFeature2);
|
||||
}
|
||||
|
||||
SYSEX_SERVICE_INIT(S1Init);
|
||||
SYSEX_SERVICE_INIT(S2Init);
|
||||
SYSEX_SERVICE_INIT(S3Init);
|
||||
SYSEX_SERVICE_INIT(S4Init);
|
||||
SYSEX_FEATURE_INIT(F1Init);
|
||||
SYSEX_FEATURE_INIT(F2Init);
|
||||
|
||||
Executable → Regular
+187
-173
@@ -1,173 +1,187 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "example.h"
|
||||
#include <ohos_init.h>
|
||||
#include <securec.h>
|
||||
#include <los_base.h>
|
||||
#include <cmsis_os.h>
|
||||
#include "iunknown.h"
|
||||
#include "feature.h"
|
||||
#include "service.h"
|
||||
#include "samgr_lite.h"
|
||||
#include "time_adapter.h"
|
||||
|
||||
typedef struct DefaultFeatureApi {
|
||||
INHERIT_IUNKNOWN;
|
||||
void (*SyncCall)(IUnknown *iUnknown);
|
||||
} DefaultFeatureApi;
|
||||
|
||||
typedef struct ExampleService {
|
||||
INHERIT_SERVICE;
|
||||
INHERIT_IUNKNOWNENTRY(DefaultFeatureApi);
|
||||
Identity identity;
|
||||
} ExampleService;
|
||||
|
||||
static const char *GetName(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
return EXAMPLE_SERVICE;
|
||||
}
|
||||
static int g_regStep = 0;
|
||||
static BOOL Initialize(Service *service, Identity identity)
|
||||
{
|
||||
ExampleService *example = (ExampleService *)service;
|
||||
example->identity = identity;
|
||||
printf("[Register Test][TaskID:%p][Step:%d][Reg Finish S:%s]Time: %llu!\n",
|
||||
osThreadGetId(), g_regStep++, service->GetName(service), SAMGR_GetProcessTime());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MessageHandle(Service *service, Request *msg)
|
||||
{
|
||||
printf("[LPC Test][TaskID: %p] msgId<%d>: %s \n", osThreadGetId(), msg->msgId, (char *)msg->data);
|
||||
(void)service;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static TaskConfig GetTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL,
|
||||
0x800, 20, SHARED_TASK};
|
||||
return config;
|
||||
}
|
||||
static volatile uint32 g_asyncStep = 0;
|
||||
static void SyncCall(IUnknown *iUnknown)
|
||||
{
|
||||
(void)iUnknown;
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][SyncCall API] Default Success!\n", osThreadGetId(), g_asyncStep++);
|
||||
}
|
||||
static ExampleService g_example = {
|
||||
.GetName = GetName,
|
||||
.Initialize = Initialize,
|
||||
.MessageHandle = MessageHandle,
|
||||
.GetTaskConfig = GetTaskConfig,
|
||||
DEFAULT_IUNKNOWN_ENTRY_BEGIN,
|
||||
.SyncCall = SyncCall,
|
||||
DEFAULT_IUNKNOWN_ENTRY_END,
|
||||
};
|
||||
|
||||
static void Init(void)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterService((Service *)&g_example);
|
||||
SAMGR_GetInstance()->RegisterDefaultFeatureApi(EXAMPLE_SERVICE, GET_IUNKNOWN(g_example));
|
||||
printf("[Register Test][TaskID:%p][Step:%d][Reg S:%s]Time: %llu!\n",
|
||||
osThreadGetId(), g_regStep++, EXAMPLE_SERVICE, SAMGR_GetProcessTime());
|
||||
}
|
||||
SYSEX_SERVICE_INIT(Init);
|
||||
|
||||
static int g_discoverStep = 0;
|
||||
static DefaultFeatureApi *CASE_GetIUnknown(void)
|
||||
{
|
||||
DefaultFeatureApi *demoApi = NULL;
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][GetIUnknown S:%s]: BEGIN\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(EXAMPLE_SERVICE);
|
||||
if (iUnknown == NULL) {
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][GetDefaultFeatureApi S:%s]Error is NULL!\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
goto END;
|
||||
}
|
||||
int result = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&demoApi);
|
||||
if (result != 0 || demoApi == NULL) {
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][QueryInterface S:%s]Error is NULL!\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
goto END;
|
||||
}
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][GetIUnknown S:%s]Success\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
END:
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][GetIUnknown S:%s]: END\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
return demoApi;
|
||||
}
|
||||
|
||||
|
||||
static void CASE_SyncCall(DefaultFeatureApi *defaultApi)
|
||||
{
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][DefaultFeature SyncCall]: BEGIN\n", osThreadGetId(), g_asyncStep++);
|
||||
defaultApi->SyncCall((IUnknown *)defaultApi);
|
||||
printf("[LPC Test][TaskID:%p][Step:%d][DefaultFeature SyncCall]: END\n", osThreadGetId(), g_asyncStep++);
|
||||
}
|
||||
|
||||
static void CASE_ReleaseIUnknown(DefaultFeatureApi *demoApi)
|
||||
{
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][ReleaseIUnknown S:%s]: BEGIN\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
int32 ref = demoApi->Release((IUnknown *)demoApi);
|
||||
if (ref <= 0) {
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][ReleaseIUnknown S:%s]Error ref is %d!\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, ref);
|
||||
goto END;
|
||||
}
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][ReleaseIUnknown S:%s]Success\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
END:
|
||||
printf("[Discover Test][TaskID:%p][Step:%d][ReleaseIUnknown S:%s]: END\n",
|
||||
osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
}
|
||||
static void CASE_RegisterInvalidService(void)
|
||||
{
|
||||
Service service = {.GetName = NULL, .GetTaskConfig = NULL, .Initialize = NULL, .MessageHandle = NULL};
|
||||
BOOL ret = SAMGR_GetInstance()->RegisterService(&service);
|
||||
printf("Register Invalid Service %s\n", ret ? "TRUE" : "FALSE");
|
||||
|
||||
Feature feature = {.GetName = NULL, .OnInitialize = NULL, .OnMessage = NULL, .OnStop = NULL};
|
||||
ret = SAMGR_GetInstance()->RegisterFeature(EXAMPLE_SERVICE, &feature);
|
||||
printf("Register Invalid Feature %s\n", ret ? "TRUE" : "FALSE");
|
||||
|
||||
IUnknownEntry entry = {
|
||||
.ver = DEFAULT_VERSION,
|
||||
.ref = 1,
|
||||
.iUnknown = {
|
||||
.QueryInterface = NULL,
|
||||
.Release = NULL,
|
||||
.AddRef = NULL
|
||||
}
|
||||
};
|
||||
ret = SAMGR_GetInstance()->RegisterDefaultFeatureApi(EXAMPLE_SERVICE, GET_IUNKNOWN(entry));
|
||||
printf("Register Invalid Default Api %s\n", ret ? "TRUE" : "FALSE");
|
||||
|
||||
ret = SAMGR_GetInstance()->RegisterFeatureApi(EXAMPLE_SERVICE, EXAMPLE_FEATURE "2", GET_IUNKNOWN(entry));
|
||||
printf("Register Invalid " EXAMPLE_FEATURE "2 Api %s\n", ret ? "TRUE" : "FALSE");
|
||||
}
|
||||
static void RunTestCase(void)
|
||||
{
|
||||
DefaultFeatureApi *defaultApi = CASE_GetIUnknown();
|
||||
CASE_RegisterInvalidService();
|
||||
CASE_SyncCall(defaultApi);
|
||||
CASE_ReleaseIUnknown(defaultApi);
|
||||
}
|
||||
LAYER_INITCALL_DEF(RunTestCase, test, "test");
|
||||
/*
|
||||
* Copyright (c) 2020-2022 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 "example.h"
|
||||
#include <stdint.h>
|
||||
#include <ohos_init.h>
|
||||
#include <securec.h>
|
||||
#include <los_base.h>
|
||||
#include <cmsis_os.h>
|
||||
#include "iunknown.h"
|
||||
#include "feature.h"
|
||||
#include "service.h"
|
||||
#include "samgr_lite.h"
|
||||
#include "time_adapter.h"
|
||||
|
||||
typedef struct DefaultFeatureApi {
|
||||
INHERIT_IUNKNOWN;
|
||||
void (*SyncCall)(IUnknown *iUnknown);
|
||||
} DefaultFeatureApi;
|
||||
|
||||
typedef struct ExampleService {
|
||||
INHERIT_SERVICE;
|
||||
INHERIT_IUNKNOWNENTRY(DefaultFeatureApi);
|
||||
Identity identity;
|
||||
} ExampleService;
|
||||
|
||||
static const char *GetName(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
return EXAMPLE_SERVICE;
|
||||
}
|
||||
|
||||
static uint32_t g_regStep = 0;
|
||||
|
||||
static BOOL Initialize(Service *service, Identity identity)
|
||||
{
|
||||
ExampleService *example = (ExampleService *)service;
|
||||
example->identity = identity;
|
||||
printf("[Register Test][TaskID:%u][Step:%u][Reg Finish S:%s]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_regStep++, service->GetName(service), SAMGR_GetProcessTime());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MessageHandle(Service *service, Request *msg)
|
||||
{
|
||||
printf("[LPC Test][TaskID:%u] msgId<%d>: %s \n", (int)osThreadGetId(), msg->msgId, (char *)msg->data);
|
||||
(void)service;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static TaskConfig GetTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL,
|
||||
0x800, 20, SHARED_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
static volatile uint32 g_asyncStep = 0;
|
||||
|
||||
static void SyncCall(IUnknown *iUnknown)
|
||||
{
|
||||
(void)iUnknown;
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][SyncCall API] Default Success!\n", (int)osThreadGetId(),
|
||||
g_asyncStep++);
|
||||
}
|
||||
|
||||
static ExampleService g_example = {
|
||||
.GetName = GetName,
|
||||
.Initialize = Initialize,
|
||||
.MessageHandle = MessageHandle,
|
||||
.GetTaskConfig = GetTaskConfig,
|
||||
DEFAULT_IUNKNOWN_ENTRY_BEGIN,
|
||||
.SyncCall = SyncCall,
|
||||
DEFAULT_IUNKNOWN_ENTRY_END,
|
||||
};
|
||||
|
||||
static void Init(void)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterService((Service *)&g_example);
|
||||
SAMGR_GetInstance()->RegisterDefaultFeatureApi(EXAMPLE_SERVICE, GET_IUNKNOWN(g_example));
|
||||
printf("[Register Test][TaskID:%u][Step:%u][Reg S:%s]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_regStep++, EXAMPLE_SERVICE, SAMGR_GetProcessTime());
|
||||
}
|
||||
|
||||
SYSEX_SERVICE_INIT(Init);
|
||||
|
||||
static uint32_t g_discoverStep = 0;
|
||||
|
||||
static DefaultFeatureApi *CASE_GetIUnknown(void)
|
||||
{
|
||||
DefaultFeatureApi *demoApi = NULL;
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][GetIUnknown S:%s]: BEGIN\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(EXAMPLE_SERVICE);
|
||||
if (iUnknown == NULL) {
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][GetDefaultFeatureApi S:%s]Error is NULL!\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
goto END;
|
||||
}
|
||||
int result = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&demoApi);
|
||||
if (result != 0 || demoApi == NULL) {
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][QueryInterface S:%s]Error is NULL!\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
goto END;
|
||||
}
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][GetIUnknown S:%s]Success\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
END:
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][GetIUnknown S:%s]: END\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
return demoApi;
|
||||
}
|
||||
|
||||
static void CASE_SyncCall(DefaultFeatureApi *defaultApi)
|
||||
{
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][DefaultFeature SyncCall]: BEGIN\n", (int)osThreadGetId(),
|
||||
g_asyncStep++);
|
||||
defaultApi->SyncCall((IUnknown *)defaultApi);
|
||||
printf("[LPC Test][TaskID:%u][Step:%u][DefaultFeature SyncCall]: END\n", (int)osThreadGetId(),
|
||||
g_asyncStep++);
|
||||
}
|
||||
|
||||
static void CASE_ReleaseIUnknown(DefaultFeatureApi *demoApi)
|
||||
{
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][ReleaseIUnknown S:%s]: BEGIN\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
int32 ref = demoApi->Release((IUnknown *)demoApi);
|
||||
if (ref <= 0) {
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][ReleaseIUnknown S:%s]Error ref is %d!\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE, ref);
|
||||
goto END;
|
||||
}
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][ReleaseIUnknown S:%s]Success\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
END:
|
||||
printf("[Discover Test][TaskID:%u][Step:%u][ReleaseIUnknown S:%s]: END\n",
|
||||
(int)osThreadGetId(), g_discoverStep++, EXAMPLE_SERVICE);
|
||||
}
|
||||
|
||||
static void CASE_RegisterInvalidService(void)
|
||||
{
|
||||
Service service = {.GetName = NULL, .GetTaskConfig = NULL, .Initialize = NULL, .MessageHandle = NULL};
|
||||
BOOL ret = SAMGR_GetInstance()->RegisterService(&service);
|
||||
printf("Register Invalid Service %s\n", ret ? "TRUE" : "FALSE");
|
||||
|
||||
Feature feature = {.GetName = NULL, .OnInitialize = NULL, .OnMessage = NULL, .OnStop = NULL};
|
||||
ret = SAMGR_GetInstance()->RegisterFeature(EXAMPLE_SERVICE, &feature);
|
||||
printf("Register Invalid Feature %s\n", ret ? "TRUE" : "FALSE");
|
||||
|
||||
IUnknownEntry entry = {
|
||||
.ver = DEFAULT_VERSION,
|
||||
.ref = 1,
|
||||
.iUnknown = {
|
||||
.QueryInterface = NULL,
|
||||
.Release = NULL,
|
||||
.AddRef = NULL
|
||||
}
|
||||
};
|
||||
ret = SAMGR_GetInstance()->RegisterDefaultFeatureApi(EXAMPLE_SERVICE, GET_IUNKNOWN(entry));
|
||||
printf("Register Invalid Default Api %s\n", ret ? "TRUE" : "FALSE");
|
||||
|
||||
ret = SAMGR_GetInstance()->RegisterFeatureApi(EXAMPLE_SERVICE, EXAMPLE_FEATURE "2", GET_IUNKNOWN(entry));
|
||||
printf("Register Invalid " EXAMPLE_FEATURE "2 Api %s\n", ret ? "TRUE" : "FALSE");
|
||||
}
|
||||
|
||||
static void RunTestCase(void)
|
||||
{
|
||||
DefaultFeatureApi *defaultApi = CASE_GetIUnknown();
|
||||
CASE_RegisterInvalidService();
|
||||
CASE_SyncCall(defaultApi);
|
||||
CASE_ReleaseIUnknown(defaultApi);
|
||||
}
|
||||
|
||||
LAYER_INITCALL_DEF(RunTestCase, test, "test");
|
||||
|
||||
Executable → Regular
+119
-113
@@ -1,113 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 <los_base.h>
|
||||
#include <securec.h>
|
||||
#include <ohos_init.h>
|
||||
#include <cmsis_os.h>
|
||||
#include "service.h"
|
||||
#include "samgr_lite.h"
|
||||
|
||||
#define TIME_UNLIMITED_CASE 0
|
||||
#define WAIT_BOOT_PROC ((1000) * (11))
|
||||
#define TEST_SYS_SERVICE1 "tst_sys1"
|
||||
#define TEST_SYS_SERVICE2 "tst_sys2"
|
||||
#define TEST_APP_SERVICE1 "tst_app1"
|
||||
#define TEST_APP_SERVICE2 "tst_app2"
|
||||
static const char *GetName(Service *service);
|
||||
static BOOL Initialize(Service *service, Identity identity);
|
||||
static BOOL MessageHandle(Service *service, Request *msg);
|
||||
static TaskConfig GetTaskConfig(Service *service);
|
||||
static Service g_testSys1 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
static Service g_testSys2 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
static Service g_testApp1 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
static Service g_testApp2 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
|
||||
static const char *GetName(Service *service)
|
||||
{
|
||||
if (service == &g_testSys1) {
|
||||
return TEST_SYS_SERVICE1;
|
||||
}
|
||||
if (service == &g_testSys2) {
|
||||
return TEST_SYS_SERVICE2;
|
||||
}
|
||||
if (service == &g_testApp1) {
|
||||
return TEST_APP_SERVICE1;
|
||||
}
|
||||
if (service == &g_testApp2) {
|
||||
return TEST_APP_SERVICE2;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BOOL Initialize(Service *service, Identity identity)
|
||||
{
|
||||
(void)identity;
|
||||
if (service == &g_testSys1 || service == &g_testApp1) {
|
||||
printf("[Recovery Test][Initialize]Time Out Case Running\n");
|
||||
LOS_Msleep(WAIT_BOOT_PROC);
|
||||
return TRUE;
|
||||
}
|
||||
#if TIME_UNLIMITED_CASE
|
||||
if (service == &g_testSys2 || service == &g_testApp2) {
|
||||
printf("[Recovery Test][Initialize]Time Unlimited Case Running\n\n");
|
||||
while (1) {
|
||||
(void)identity;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MessageHandle(Service *service, Request *msg)
|
||||
{
|
||||
(void)service;
|
||||
(void)msg;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static TaskConfig GetTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
TaskConfig config = {LEVEL_HIGH, PRI_NORMAL,
|
||||
0x400, 16, SHARED_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
static void SInit(Service *demo)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterService(demo);
|
||||
}
|
||||
|
||||
static void SS1Init(void)
|
||||
{
|
||||
SInit(&g_testSys1);
|
||||
}
|
||||
static void SS2Init(void)
|
||||
{
|
||||
SInit(&g_testSys2);
|
||||
}
|
||||
static void AS1Init(void)
|
||||
{
|
||||
SInit(&g_testApp1);
|
||||
}
|
||||
static void AS2Init(void)
|
||||
{
|
||||
SInit(&g_testApp2);
|
||||
}
|
||||
SYS_SERVICE_INIT(SS1Init);
|
||||
SYS_SERVICE_INIT(SS2Init);
|
||||
SYSEX_SERVICE_INIT(AS1Init);
|
||||
SYSEX_SERVICE_INIT(AS2Init);
|
||||
/*
|
||||
* Copyright (c) 2020-2022 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 <los_base.h>
|
||||
#include <securec.h>
|
||||
#include <ohos_init.h>
|
||||
#include <cmsis_os.h>
|
||||
#include "service.h"
|
||||
#include "samgr_lite.h"
|
||||
|
||||
#define TIME_UNLIMITED_CASE 0
|
||||
#define WAIT_BOOT_PROC ((1000) * (11))
|
||||
#define TEST_SYS_SERVICE1 "tst_sys1"
|
||||
#define TEST_SYS_SERVICE2 "tst_sys2"
|
||||
#define TEST_APP_SERVICE1 "tst_app1"
|
||||
#define TEST_APP_SERVICE2 "tst_app2"
|
||||
|
||||
static const char *GetName(Service *service);
|
||||
static BOOL Initialize(Service *service, Identity identity);
|
||||
static BOOL MessageHandle(Service *service, Request *msg);
|
||||
static TaskConfig GetTaskConfig(Service *service);
|
||||
static Service g_testSys1 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
static Service g_testSys2 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
static Service g_testApp1 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
static Service g_testApp2 = {GetName, Initialize, MessageHandle, GetTaskConfig};
|
||||
|
||||
static const char *GetName(Service *service)
|
||||
{
|
||||
if (service == &g_testSys1) {
|
||||
return TEST_SYS_SERVICE1;
|
||||
}
|
||||
if (service == &g_testSys2) {
|
||||
return TEST_SYS_SERVICE2;
|
||||
}
|
||||
if (service == &g_testApp1) {
|
||||
return TEST_APP_SERVICE1;
|
||||
}
|
||||
if (service == &g_testApp2) {
|
||||
return TEST_APP_SERVICE2;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BOOL Initialize(Service *service, Identity identity)
|
||||
{
|
||||
(void)identity;
|
||||
if (service == &g_testSys1 || service == &g_testApp1) {
|
||||
printf("[Recovery Test][Initialize]Time Out Case Running\n");
|
||||
LOS_Msleep(WAIT_BOOT_PROC);
|
||||
return TRUE;
|
||||
}
|
||||
#if TIME_UNLIMITED_CASE
|
||||
if (service == &g_testSys2 || service == &g_testApp2) {
|
||||
printf("[Recovery Test][Initialize]Time Unlimited Case Running\n\n");
|
||||
while (1) {
|
||||
(void)identity;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MessageHandle(Service *service, Request *msg)
|
||||
{
|
||||
(void)service;
|
||||
(void)msg;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static TaskConfig GetTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
TaskConfig config = {LEVEL_HIGH, PRI_NORMAL,
|
||||
0x400, 16, SHARED_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
static void SInit(Service *demo)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterService(demo);
|
||||
}
|
||||
|
||||
static void SS1Init(void)
|
||||
{
|
||||
SInit(&g_testSys1);
|
||||
}
|
||||
|
||||
static void SS2Init(void)
|
||||
{
|
||||
SInit(&g_testSys2);
|
||||
}
|
||||
|
||||
static void AS1Init(void)
|
||||
{
|
||||
SInit(&g_testApp1);
|
||||
}
|
||||
|
||||
static void AS2Init(void)
|
||||
{
|
||||
SInit(&g_testApp2);
|
||||
}
|
||||
|
||||
SYS_SERVICE_INIT(SS1Init);
|
||||
SYS_SERVICE_INIT(SS2Init);
|
||||
SYSEX_SERVICE_INIT(AS1Init);
|
||||
SYSEX_SERVICE_INIT(AS2Init);
|
||||
|
||||
Executable → Regular
+227
-223
@@ -1,223 +1,227 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 <securec.h>
|
||||
#include <ohos_init.h>
|
||||
#include <cmsis_os.h>
|
||||
#include "service.h"
|
||||
#include "samgr_lite.h"
|
||||
#include "time_adapter.h"
|
||||
|
||||
#define TOTAL_SPEC_TASK_NUM 19
|
||||
static const char *g_specTaskService[] = {
|
||||
"ltsk_s1", "ltsk_s2", "ltsk_s3",
|
||||
"otsk_s1", "otsk_s2", "otsk_s3", "otsk_s4",
|
||||
"otsk_s5", "otsk_s6", "otsk_s7", "otsk_s8",
|
||||
"otsk_s9", "otsk_s10", "otsk_s11", "otsk_s12",
|
||||
"otsk_s13", "otsk_s14", "otsk_s15", "otsk_s16",
|
||||
};
|
||||
static const char *g_specServiceName1[] = {
|
||||
"l6tsk_s1", "l6tsk_s2"
|
||||
};
|
||||
static const char *g_specServiceName2[] = {
|
||||
"l7tsk_s1", "l7tsk_s2", "l7tsk_s3"
|
||||
};
|
||||
static const char *g_specServiceName3[] = {
|
||||
"l8tsk_s1", "l8tsk_s2", "l8tsk_s3", "l8tsk_s4"
|
||||
};
|
||||
static const char *GetName(Service *service);
|
||||
static const char *GetSpec1Name(Service *service);
|
||||
static const char *GetSpec2Name(Service *service);
|
||||
static const char *GetSpec3Name(Service *service);
|
||||
static BOOL Initialize(Service *service, Identity identity);
|
||||
static BOOL MessageHandle(Service *service, Request *msg);
|
||||
static TaskConfig GetLowTagTaskConfig(Service *service);
|
||||
static TaskConfig GetHighTagTaskConfig(Service *service);
|
||||
static TaskConfig GetSpec1TagTaskConfig(Service *service);
|
||||
static TaskConfig GetSpec2TagTaskConfig(Service *service);
|
||||
static TaskConfig GetSpec3TagTaskConfig(Service *service);
|
||||
static Service g_example[] = {
|
||||
{GetName, Initialize, MessageHandle, GetLowTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetLowTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetLowTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig}
|
||||
};
|
||||
static Service g_exampleSpec1[] = {
|
||||
{GetSpec1Name, Initialize, MessageHandle, GetSpec1TagTaskConfig},
|
||||
{GetSpec1Name, Initialize, MessageHandle, GetSpec1TagTaskConfig}
|
||||
};
|
||||
static Service g_exampleSpec2[] = {
|
||||
{GetSpec2Name, Initialize, MessageHandle, GetSpec2TagTaskConfig},
|
||||
{GetSpec2Name, Initialize, MessageHandle, GetSpec2TagTaskConfig},
|
||||
{GetSpec2Name, Initialize, MessageHandle, GetSpec2TagTaskConfig}
|
||||
};
|
||||
static Service g_exampleSpec3[] = {
|
||||
{GetSpec3Name, Initialize, MessageHandle, GetSpec3TagTaskConfig},
|
||||
{GetSpec3Name, Initialize, MessageHandle, GetSpec3TagTaskConfig},
|
||||
{GetSpec3Name, Initialize, MessageHandle, GetSpec3TagTaskConfig},
|
||||
{GetSpec3Name, Initialize, MessageHandle, GetSpec3TagTaskConfig}
|
||||
};
|
||||
static int g_initIndex = 0;
|
||||
|
||||
static const char *GetName(Service *service)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < TOTAL_SPEC_TASK_NUM; ++i) {
|
||||
if (service == &g_example[i]) {
|
||||
return g_specTaskService[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *GetSpec1Name(Service *service)
|
||||
{
|
||||
int i;
|
||||
// g_exampleSpec1 has 2 services
|
||||
for (i = 0; i < 2; ++i) {
|
||||
if (service == &g_exampleSpec1[i]) {
|
||||
return g_specServiceName1[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *GetSpec2Name(Service *service)
|
||||
{
|
||||
int i;
|
||||
// g_exampleSpec2 has 3 services
|
||||
for (i = 0; i < 3; ++i) {
|
||||
if (service == &g_exampleSpec2[i]) {
|
||||
return g_specServiceName2[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *GetSpec3Name(Service *service)
|
||||
{
|
||||
int i;
|
||||
// g_exampleSpec3 has 4 services
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (service == &g_exampleSpec3[i]) {
|
||||
return g_specServiceName3[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BOOL Initialize(Service *service, Identity identity)
|
||||
{
|
||||
(void)identity;
|
||||
printf("[Specified Task Test][TaskID:%p][Step:%d][Reg Finish S:%s]Time: %llu!\n",
|
||||
osThreadGetId(), g_initIndex++, service->GetName(service), SAMGR_GetProcessTime());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MessageHandle(Service *service, Request *msg)
|
||||
{
|
||||
printf("[Specified Task Test][TaskID:%p][Step:%d][S:%s] msgId<%d> \n",
|
||||
osThreadGetId(), g_initIndex++, service->GetName(service), msg->msgId);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static TaskConfig GetLowTagTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
int16 customLevelLow = LEVEL_CUSTOM_BEGIN + 1;
|
||||
TaskConfig config = {customLevelLow, PRI_NORMAL,
|
||||
0x400, 16, SPECIFIED_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
static TaskConfig GetHighTagTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
int16 customLevelHigh = LEVEL_CUSTOM_BEGIN + 2; // Custom level 2
|
||||
TaskConfig config = {customLevelHigh, PRI_NORMAL,
|
||||
0x400, 16, SPECIFIED_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
static TaskConfig GetSpec1TagTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
int16 customLevelSpec1 = LEVEL_CUSTOM_BEGIN + 3; // Custom level 3
|
||||
TaskConfig config = {customLevelSpec1, PRI_NORMAL,
|
||||
0x400, 16, SPECIFIED_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
static TaskConfig GetSpec2TagTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
int16 customLevelSpec2 = LEVEL_CUSTOM_BEGIN + 4; // Custom level 4
|
||||
TaskConfig config = {customLevelSpec2, PRI_NORMAL,
|
||||
0x400, 16, SPECIFIED_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
static TaskConfig GetSpec3TagTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
int16 customLevelSpec3 = LEVEL_CUSTOM_BEGIN + 5; // Custom level 5
|
||||
TaskConfig config = {customLevelSpec3, PRI_NORMAL,
|
||||
0x400, 16, SPECIFIED_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
static void SInit(Service *demo)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterService(demo);
|
||||
|
||||
printf("[Specified Task Test][TaskID:%p][Step:%d][SYSEX Reg S:%s]Time: %llu!\n",
|
||||
osThreadGetId(), g_initIndex++, demo->GetName(demo), SAMGR_GetProcessTime());
|
||||
}
|
||||
static void SSInit(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < TOTAL_SPEC_TASK_NUM; ++i) {
|
||||
SInit(&g_example[i]);
|
||||
}
|
||||
|
||||
// g_exampleSpec1 has 2 services
|
||||
for (i = 0; i < 2; ++i) {
|
||||
SInit(&g_exampleSpec1[i]);
|
||||
}
|
||||
// g_exampleSpec2 has 3 services
|
||||
for (i = 0; i < 3; ++i) {
|
||||
SInit(&g_exampleSpec2[i]);
|
||||
}
|
||||
// g_exampleSpec3 has 4 services
|
||||
for (i = 0; i < 4; ++i) {
|
||||
SInit(&g_exampleSpec3[i]);
|
||||
}
|
||||
}
|
||||
SYSEX_SERVICE_INIT(SSInit);
|
||||
/*
|
||||
* Copyright (c) 2020-2022 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 <stdint.h>
|
||||
#include <securec.h>
|
||||
#include <ohos_init.h>
|
||||
#include <cmsis_os.h>
|
||||
#include "service.h"
|
||||
#include "samgr_lite.h"
|
||||
#include "time_adapter.h"
|
||||
|
||||
#define TOTAL_SPEC_TASK_NUM 19
|
||||
|
||||
static const char *g_specTaskService[] = {
|
||||
"ltsk_s1", "ltsk_s2", "ltsk_s3",
|
||||
"otsk_s1", "otsk_s2", "otsk_s3", "otsk_s4",
|
||||
"otsk_s5", "otsk_s6", "otsk_s7", "otsk_s8",
|
||||
"otsk_s9", "otsk_s10", "otsk_s11", "otsk_s12",
|
||||
"otsk_s13", "otsk_s14", "otsk_s15", "otsk_s16",
|
||||
};
|
||||
static const char *g_specServiceName1[] = {
|
||||
"l6tsk_s1", "l6tsk_s2"
|
||||
};
|
||||
static const char *g_specServiceName2[] = {
|
||||
"l7tsk_s1", "l7tsk_s2", "l7tsk_s3"
|
||||
};
|
||||
static const char *g_specServiceName3[] = {
|
||||
"l8tsk_s1", "l8tsk_s2", "l8tsk_s3", "l8tsk_s4"
|
||||
};
|
||||
static const char *GetName(Service *service);
|
||||
static const char *GetSpec1Name(Service *service);
|
||||
static const char *GetSpec2Name(Service *service);
|
||||
static const char *GetSpec3Name(Service *service);
|
||||
static BOOL Initialize(Service *service, Identity identity);
|
||||
static BOOL MessageHandle(Service *service, Request *msg);
|
||||
static TaskConfig GetLowTagTaskConfig(Service *service);
|
||||
static TaskConfig GetHighTagTaskConfig(Service *service);
|
||||
static TaskConfig GetSpec1TagTaskConfig(Service *service);
|
||||
static TaskConfig GetSpec2TagTaskConfig(Service *service);
|
||||
static TaskConfig GetSpec3TagTaskConfig(Service *service);
|
||||
static Service g_example[] = {
|
||||
{GetName, Initialize, MessageHandle, GetLowTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetLowTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetLowTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetHighTagTaskConfig}
|
||||
};
|
||||
static Service g_exampleSpec1[] = {
|
||||
{GetSpec1Name, Initialize, MessageHandle, GetSpec1TagTaskConfig},
|
||||
{GetSpec1Name, Initialize, MessageHandle, GetSpec1TagTaskConfig}
|
||||
};
|
||||
static Service g_exampleSpec2[] = {
|
||||
{GetSpec2Name, Initialize, MessageHandle, GetSpec2TagTaskConfig},
|
||||
{GetSpec2Name, Initialize, MessageHandle, GetSpec2TagTaskConfig},
|
||||
{GetSpec2Name, Initialize, MessageHandle, GetSpec2TagTaskConfig}
|
||||
};
|
||||
static Service g_exampleSpec3[] = {
|
||||
{GetSpec3Name, Initialize, MessageHandle, GetSpec3TagTaskConfig},
|
||||
{GetSpec3Name, Initialize, MessageHandle, GetSpec3TagTaskConfig},
|
||||
{GetSpec3Name, Initialize, MessageHandle, GetSpec3TagTaskConfig},
|
||||
{GetSpec3Name, Initialize, MessageHandle, GetSpec3TagTaskConfig}
|
||||
};
|
||||
static uint32_t g_initIndex = 0;
|
||||
|
||||
static const char *GetName(Service *service)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < TOTAL_SPEC_TASK_NUM; ++i) {
|
||||
if (service == &g_example[i]) {
|
||||
return g_specTaskService[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *GetSpec1Name(Service *service)
|
||||
{
|
||||
int i;
|
||||
// g_exampleSpec1 has 2 services
|
||||
for (i = 0; i < 2; ++i) {
|
||||
if (service == &g_exampleSpec1[i]) {
|
||||
return g_specServiceName1[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *GetSpec2Name(Service *service)
|
||||
{
|
||||
int i;
|
||||
// g_exampleSpec2 has 3 services
|
||||
for (i = 0; i < 3; ++i) {
|
||||
if (service == &g_exampleSpec2[i]) {
|
||||
return g_specServiceName2[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *GetSpec3Name(Service *service)
|
||||
{
|
||||
int i;
|
||||
// g_exampleSpec3 has 4 services
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (service == &g_exampleSpec3[i]) {
|
||||
return g_specServiceName3[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BOOL Initialize(Service *service, Identity identity)
|
||||
{
|
||||
(void)identity;
|
||||
printf("[Specified Task Test][TaskID:%u][Step:%u][Reg Finish S:%s]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_initIndex++, service->GetName(service), SAMGR_GetProcessTime());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MessageHandle(Service *service, Request *msg)
|
||||
{
|
||||
printf("[Specified Task Test][TaskID:%u][Step:%u][S:%s] msgId<%d> \n",
|
||||
(int)osThreadGetId(), g_initIndex++, service->GetName(service), msg->msgId);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static TaskConfig GetLowTagTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
int16 customLevelLow = LEVEL_CUSTOM_BEGIN + 1;
|
||||
TaskConfig config = {customLevelLow, PRI_NORMAL,
|
||||
0x400, 16, SPECIFIED_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
static TaskConfig GetHighTagTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
int16 customLevelHigh = LEVEL_CUSTOM_BEGIN + 2; // Custom level 2
|
||||
TaskConfig config = {customLevelHigh, PRI_NORMAL,
|
||||
0x400, 16, SPECIFIED_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
static TaskConfig GetSpec1TagTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
int16 customLevelSpec1 = LEVEL_CUSTOM_BEGIN + 3; // Custom level 3
|
||||
TaskConfig config = {customLevelSpec1, PRI_NORMAL,
|
||||
0x400, 16, SPECIFIED_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
static TaskConfig GetSpec2TagTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
int16 customLevelSpec2 = LEVEL_CUSTOM_BEGIN + 4; // Custom level 4
|
||||
TaskConfig config = {customLevelSpec2, PRI_NORMAL,
|
||||
0x400, 16, SPECIFIED_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
static TaskConfig GetSpec3TagTaskConfig(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
int16 customLevelSpec3 = LEVEL_CUSTOM_BEGIN + 5; // Custom level 5
|
||||
TaskConfig config = {customLevelSpec3, PRI_NORMAL,
|
||||
0x400, 16, SPECIFIED_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
static void SInit(Service *demo)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterService(demo);
|
||||
|
||||
printf("[Specified Task Test][TaskID:%u][Step:%u][SYSEX Reg S:%s]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_initIndex++, demo->GetName(demo), SAMGR_GetProcessTime());
|
||||
}
|
||||
|
||||
static void SSInit(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < TOTAL_SPEC_TASK_NUM; ++i) {
|
||||
SInit(&g_example[i]);
|
||||
}
|
||||
|
||||
// g_exampleSpec1 has 2 services
|
||||
for (i = 0; i < 2; ++i) {
|
||||
SInit(&g_exampleSpec1[i]);
|
||||
}
|
||||
// g_exampleSpec2 has 3 services
|
||||
for (i = 0; i < 3; ++i) {
|
||||
SInit(&g_exampleSpec2[i]);
|
||||
}
|
||||
// g_exampleSpec3 has 4 services
|
||||
for (i = 0; i < 4; ++i) {
|
||||
SInit(&g_exampleSpec3[i]);
|
||||
}
|
||||
}
|
||||
|
||||
SYSEX_SERVICE_INIT(SSInit);
|
||||
|
||||
Executable → Regular
+123
-115
@@ -1,115 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "example.h"
|
||||
#include <feature.h>
|
||||
#include <securec.h>
|
||||
#include <ohos_init.h>
|
||||
#include <samgr_lite.h>
|
||||
#include <cmsis_os.h>
|
||||
#include "time_adapter.h"
|
||||
|
||||
static const char *GetName(Service *service);
|
||||
static BOOL Initialize(Service *service, Identity identity);
|
||||
static BOOL MessageHandle(Service *service, Request *msg);
|
||||
static TaskConfig GetTaskConfig(Service *service);
|
||||
static Service g_example[] = {
|
||||
{GetName, Initialize, MessageHandle, GetTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetTaskConfig}
|
||||
};
|
||||
static int g_initIndex = 0;
|
||||
static const char *GetName(Service *service)
|
||||
{
|
||||
// test cases demo 0
|
||||
if (service == &g_example[0]) {
|
||||
return TASK_SERVICE1;
|
||||
}
|
||||
// test cases demo 1
|
||||
if (service == &g_example[1]) {
|
||||
return TASK_SERVICE2;
|
||||
}
|
||||
// test cases demo 2
|
||||
if (service == &g_example[2]) {
|
||||
return TASK_SERVICE3;
|
||||
}
|
||||
// test cases demo 3
|
||||
if (service == &g_example[3]) {
|
||||
return TASK_SERVICE4;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BOOL Initialize(Service *service, Identity identity)
|
||||
{
|
||||
(void)identity;
|
||||
printf("[Task Test][TaskID:%p][Step:%d][Reg Finish S:%s]Time: %llu!\n",
|
||||
osThreadGetId(), g_initIndex++, service->GetName(service), SAMGR_GetProcessTime());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MessageHandle(Service *service, Request *msg)
|
||||
{
|
||||
printf("[Task Test][TaskID:%p][Step:%d][S:%s] msgId<%d> \n",
|
||||
osThreadGetId(), g_initIndex++, service->GetName(service), msg->msgId);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static TaskConfig GetTaskConfig(Service *service)
|
||||
{
|
||||
TaskConfig config = {LEVEL_HIGH, PRI_NORMAL,
|
||||
0x800, 5, SHARED_TASK};
|
||||
// test cases demo 0
|
||||
if (service == &g_example[0]) {
|
||||
config.taskFlags = SINGLE_TASK;
|
||||
}
|
||||
// test cases demo 3
|
||||
if (service == &g_example[3]) {
|
||||
config.priority = PRI_ABOVE_NORMAL;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
static void SInit(Service *demo)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterService(demo);
|
||||
|
||||
printf("[Task Test][TaskID:%p][Step:%d][SYSEX Reg S:%s]Time: %llu!\n",
|
||||
osThreadGetId(), g_initIndex++, demo->GetName(demo), SAMGR_GetProcessTime());
|
||||
}
|
||||
static void S1Init(void)
|
||||
{
|
||||
// test cases demo 0
|
||||
SInit(&g_example[0]);
|
||||
}
|
||||
static void S2Init(void)
|
||||
{
|
||||
// test cases demo 1
|
||||
SInit(&g_example[1]);
|
||||
}
|
||||
static void S3Init(void)
|
||||
{
|
||||
// test cases demo 2
|
||||
SInit(&g_example[2]);
|
||||
}
|
||||
static void S4Init(void)
|
||||
{
|
||||
// test cases demo 3
|
||||
SInit(&g_example[3]);
|
||||
}
|
||||
SYSEX_SERVICE_INIT(S1Init);
|
||||
SYSEX_SERVICE_INIT(S2Init);
|
||||
SYSEX_SERVICE_INIT(S3Init);
|
||||
SYSEX_SERVICE_INIT(S4Init);
|
||||
/*
|
||||
* Copyright (c) 2020-2022 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 "example.h"
|
||||
#include <stdint.h>
|
||||
#include <feature.h>
|
||||
#include <securec.h>
|
||||
#include <ohos_init.h>
|
||||
#include <samgr_lite.h>
|
||||
#include <cmsis_os.h>
|
||||
#include "time_adapter.h"
|
||||
|
||||
static const char *GetName(Service *service);
|
||||
static BOOL Initialize(Service *service, Identity identity);
|
||||
static BOOL MessageHandle(Service *service, Request *msg);
|
||||
static TaskConfig GetTaskConfig(Service *service);
|
||||
static Service g_example[] = {
|
||||
{GetName, Initialize, MessageHandle, GetTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetTaskConfig},
|
||||
{GetName, Initialize, MessageHandle, GetTaskConfig}
|
||||
};
|
||||
static int g_initIndex = 0;
|
||||
|
||||
static const char *GetName(Service *service)
|
||||
{
|
||||
// test cases demo 0
|
||||
if (service == &g_example[0]) {
|
||||
return TASK_SERVICE1;
|
||||
}
|
||||
// test cases demo 1
|
||||
if (service == &g_example[1]) {
|
||||
return TASK_SERVICE2;
|
||||
}
|
||||
// test cases demo 2
|
||||
if (service == &g_example[2]) {
|
||||
return TASK_SERVICE3;
|
||||
}
|
||||
// test cases demo 3
|
||||
if (service == &g_example[3]) {
|
||||
return TASK_SERVICE4;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BOOL Initialize(Service *service, Identity identity)
|
||||
{
|
||||
(void)identity;
|
||||
printf("[Task Test][TaskID:%u][Step:%u][Reg Finish S:%s]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_initIndex++, service->GetName(service), SAMGR_GetProcessTime());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MessageHandle(Service *service, Request *msg)
|
||||
{
|
||||
printf("[Task Test][TaskID:%u][Step:%u][S:%s] msgId<%d> \n",
|
||||
(int)osThreadGetId(), g_initIndex++, service->GetName(service), msg->msgId);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static TaskConfig GetTaskConfig(Service *service)
|
||||
{
|
||||
TaskConfig config = {LEVEL_HIGH, PRI_NORMAL,
|
||||
0x800, 5, SHARED_TASK};
|
||||
// test cases demo 0
|
||||
if (service == &g_example[0]) {
|
||||
config.taskFlags = SINGLE_TASK;
|
||||
}
|
||||
// test cases demo 3
|
||||
if (service == &g_example[3]) {
|
||||
config.priority = PRI_ABOVE_NORMAL;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
static void SInit(Service *demo)
|
||||
{
|
||||
SAMGR_GetInstance()->RegisterService(demo);
|
||||
|
||||
printf("[Task Test][TaskID:%u][Step:%u][SYSEX Reg S:%s]Time: %llu!\n",
|
||||
(int)osThreadGetId(), g_initIndex++, demo->GetName(demo), SAMGR_GetProcessTime());
|
||||
}
|
||||
|
||||
static void S1Init(void)
|
||||
{
|
||||
// test cases demo 0
|
||||
SInit(&g_example[0]);
|
||||
}
|
||||
|
||||
static void S2Init(void)
|
||||
{
|
||||
// test cases demo 1
|
||||
SInit(&g_example[1]);
|
||||
}
|
||||
|
||||
static void S3Init(void)
|
||||
{
|
||||
// test cases demo 2
|
||||
SInit(&g_example[2]);
|
||||
}
|
||||
|
||||
static void S4Init(void)
|
||||
{
|
||||
// test cases demo 3
|
||||
SInit(&g_example[3]);
|
||||
}
|
||||
|
||||
SYSEX_SERVICE_INIT(S1Init);
|
||||
SYSEX_SERVICE_INIT(S2Init);
|
||||
SYSEX_SERVICE_INIT(S3Init);
|
||||
SYSEX_SERVICE_INIT(S4Init);
|
||||
|
||||
Executable → Regular
+18
-20
@@ -1,20 +1,18 @@
|
||||
# Copyright (c) 2020 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.
|
||||
|
||||
source_set("startup") {
|
||||
sources = [
|
||||
|
||||
]
|
||||
|
||||
include_dirs = [ ]
|
||||
}
|
||||
# Copyright (c) 2020-2022 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.
|
||||
|
||||
source_set("startup") {
|
||||
sources = []
|
||||
|
||||
include_dirs = []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user