1cc290419Sopenharmony_ci/*
2cc290419Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
3cc290419Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4cc290419Sopenharmony_ci * you may not use this file except in compliance with the License.
5cc290419Sopenharmony_ci * You may obtain a copy of the License at
6cc290419Sopenharmony_ci *
7cc290419Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8cc290419Sopenharmony_ci *
9cc290419Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10cc290419Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11cc290419Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cc290419Sopenharmony_ci * See the License for the specific language governing permissions and
13cc290419Sopenharmony_ci * limitations under the License.
14cc290419Sopenharmony_ci */
15cc290419Sopenharmony_ci#ifndef HDC_TASK_H
16cc290419Sopenharmony_ci#define HDC_TASK_H
17cc290419Sopenharmony_ci#include "common.h"
18cc290419Sopenharmony_ci
19cc290419Sopenharmony_cinamespace Hdc {
20cc290419Sopenharmony_ci// Only allow inheritance
21cc290419Sopenharmony_ciclass HdcTaskBase {
22cc290419Sopenharmony_cipublic:
23cc290419Sopenharmony_ci    HdcTaskBase(HTaskInfo hTaskInfo);
24cc290419Sopenharmony_ci    virtual ~HdcTaskBase();
25cc290419Sopenharmony_ci    virtual bool CommandDispatch(const uint16_t command, uint8_t *payload, const int payloadSize)
26cc290419Sopenharmony_ci    {
27cc290419Sopenharmony_ci        return true;
28cc290419Sopenharmony_ci    }
29cc290419Sopenharmony_ci    // The following two functions are used to clean up. To ensure that subclasses are safely cleaned, each subclass is
30cc290419Sopenharmony_ci    // directly instantified of these two virtual functions.
31cc290419Sopenharmony_ci    virtual void StopTask()
32cc290419Sopenharmony_ci    {
33cc290419Sopenharmony_ci        singalStop = true;  // default operation
34cc290419Sopenharmony_ci    }
35cc290419Sopenharmony_ci    virtual bool ReadyForRelease();
36cc290419Sopenharmony_ci    void TaskFinish();
37cc290419Sopenharmony_ci
38cc290419Sopenharmony_ciprotected:                                                                        // D/S==daemon/server
39cc290419Sopenharmony_ci    bool SendToAnother(const uint16_t command, uint8_t *bufPtr, const int size);  // D / S corresponds to the Task class
40cc290419Sopenharmony_ci    void LogMsg(MessageLevel level, const char *msg, ...);                        // D / S log Send to Client
41cc290419Sopenharmony_ci    bool ServerCommand(const uint16_t command, uint8_t *bufPtr, const int size);  // D / s command is sent to Server
42cc290419Sopenharmony_ci    int ThreadCtrlCommunicate(const uint8_t *bufPtr, const int size);             // main thread and session thread
43cc290419Sopenharmony_ci
44cc290419Sopenharmony_ci    uv_loop_t *loopTask;  // childuv pointer
45cc290419Sopenharmony_ci    void *clsSession;
46cc290419Sopenharmony_ci    // Task has stopped running. When Task is officially running, set True as soon as possible, set FALSE after the last
47cc290419Sopenharmony_ci    // step, when the value is false, the Task class will be destructured as soon as possible
48cc290419Sopenharmony_ci    bool childReady;  // Subcompulents have been prepared
49cc290419Sopenharmony_ci    bool singalStop;  // Request stop signal
50cc290419Sopenharmony_ci    HTaskInfo taskInfo;
51cc290419Sopenharmony_ci    uint32_t refCount;
52cc290419Sopenharmony_ci
53cc290419Sopenharmony_ciprivate:
54cc290419Sopenharmony_ci};
55cc290419Sopenharmony_ci}  // namespace Hdc
56cc290419Sopenharmony_ci
57cc290419Sopenharmony_ci#endif