• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 
16 #ifndef OHOS_ABILITY_RUNTIME_CHILD_PROCESS_RECORD_H
17 #define OHOS_ABILITY_RUNTIME_CHILD_PROCESS_RECORD_H
18 
19 #include <memory>
20 #include <string>
21 #include <sys/types.h>
22 
23 #include "app_death_recipient.h"
24 #include "child_scheduler_interface.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 class AppRunningRecord;
29 
30 class ChildProcessRecord {
31 public:
32     ChildProcessRecord(pid_t hostPid, const std::string &srcEntry, const std::shared_ptr<AppRunningRecord> hostRecord);
33     virtual ~ChildProcessRecord();
34 
35     static std::shared_ptr<ChildProcessRecord> CreateChildProcessRecord(pid_t hostPid, const std::string &srcEntry,
36         const std::shared_ptr<AppRunningRecord> hostRecord);
37 
38     void SetPid(pid_t pid);
39     pid_t GetPid() const;
40     pid_t GetHostPid() const;
41     void SetUid(int32_t uid);
42     int32_t GetUid() const;
43     std::string GetProcessName() const;
44     std::string GetSrcEntry() const;
45     std::shared_ptr<AppRunningRecord> GetHostRecord() const;
46     void SetScheduler(const sptr<IChildScheduler> &scheduler);
47     sptr<IChildScheduler> GetScheduler() const;
48     void SetDeathRecipient(const sptr<AppDeathRecipient> recipient);
49     void RegisterDeathRecipient();
50     void RemoveDeathRecipient();
51     void ScheduleExitProcessSafely();
52 
53 private:
54     void MakeProcessName(const std::shared_ptr<AppRunningRecord> hostRecord);
55 
56     pid_t pid_ = 0;
57     pid_t hostPid_ = 0;
58     int32_t uid_ = 0;
59     std::string processName_;
60     std::string srcEntry_;
61     std::weak_ptr<AppRunningRecord> hostRecord_;
62     sptr<IChildScheduler> scheduler_ = nullptr;
63     sptr<AppDeathRecipient> deathRecipient_ = nullptr;
64 };
65 }  // namespace AppExecFwk
66 }  // namespace OHOS
67 #endif  // OHOS_ABILITY_RUNTIME_CHILD_PROCESS_RECORD_H
68