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