提交 fb30d730 编写于 作者: W wenjun

add OpenHarmony 1.0 baseline

上级 d327251a
### 该问题是怎么引起的?
### 重现步骤
### 报错信息
### 相关的Issue
### 原因(目的、解决的问题等)
### 描述(做了什么,变更了什么)
### 测试用例(新增、改动、可能影响的功能)
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
\ No newline at end of file
# 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 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 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 "ohos_init.h"
#include "demosdk.h"
void DemoSdkMain(void)
{
DemoSdkEntry();
}
SYS_RUN(DemoSdkMain);
# 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/components/cmsis/2.0",
"//base/iot_hardware/interfaces/kits/wifiiot_lite",
]
}
/*
* 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 "wifiiot_gpio.h"
#include "wifiiot_gpio_ex.h"
#define LED_INTERVAL_TIME_US 300000
#define LED_TASK_STACK_SIZE 512
#define LED_TASK_PRIO 25
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:
GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, 1);
usleep(LED_INTERVAL_TIME_US);
break;
case LED_OFF:
GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, 0);
usleep(LED_INTERVAL_TIME_US);
break;
case LED_SPARK:
GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, 0);
usleep(LED_INTERVAL_TIME_US);
GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, 1);
usleep(LED_INTERVAL_TIME_US);
break;
default:
usleep(LED_INTERVAL_TIME_US);
break;
}
}
return NULL;
}
static void LedExampleEntry(void)
{
osThreadAttr_t attr;
GpioInit();
IoSetFunc(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_IO_FUNC_GPIO_9_GPIO);
GpioSetDir(WIFI_IOT_IO_NAME_GPIO_9, WIFI_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);
\ No newline at end of file
# 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 = [
"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/interfaces/kits/samgr_lite/samgr",
"//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast",
]
}
\ No newline at end of file
/*
* 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>
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 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>
#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);
}
TEST_INIT(RunTestCase);
/*
* 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 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"
#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
if (request->msgValue) {
SAMGR_PrintServices();
} else {
SAMGR_PrintOperations();
}
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);
}
TEST_INIT(RunTestCase);
/*
* 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_HIGH;
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 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"
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);
}
TEST_INIT(RunTestCase);
\ No newline at end of file
/*
* 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);
\ No newline at end of file
/*
* 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"
#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);
\ No newline at end of file
/*
* 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>
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 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 = [ ]
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册