• 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 HIVIEWDFX_FAULTLOGGER_SERVICE_OHOS_H
16 #define HIVIEWDFX_FAULTLOGGER_SERVICE_OHOS_H
17 #include <cstdint>
18 #include <map>
19 #include <mutex>
20 #include <string>
21 #include <vector>
22 
23 #include "system_ability.h"
24 
25 #include "faultlogger_service_stub.h"
26 #include "faultlog_info_ohos.h"
27 #include "faultlog_query_result_ohos.h"
28 #include "faultlogger.h"
29 
30 namespace OHOS {
31 namespace HiviewDFX {
32 class FaultloggerServiceOhos : public SystemAbility,
33                             public FaultLoggerServiceStub {
34     DECLARE_SYSTEM_ABILITY(FaultloggerServiceOhos);
35 public:
FaultloggerServiceOhos()36     FaultloggerServiceOhos() {};
~FaultloggerServiceOhos()37     virtual ~FaultloggerServiceOhos() {};
38 
39     static void StartService(OHOS::HiviewDFX::Faultlogger *service);
40     static OHOS::HiviewDFX::Faultlogger *GetOrSetFaultlogger(
41         OHOS::HiviewDFX::Faultlogger *service = nullptr);
42     int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override;
43 
44     void AddFaultLog(const FaultLogInfoOhos& info) override;
45     sptr<IRemoteObject> QuerySelfFaultLog(int32_t faultType, int32_t maxNum) override;
46     void Destroy() override;
47 
48 private:
49     struct FaultLogQuery {
50         int32_t pid = -1;
51         sptr<FaultLogQueryResultOhos> ptr = nullptr;
52     };
53 
54 private:
55     void ClearQueryStub(int32_t uid);
56 
57     std::map<int32_t, std::unique_ptr<FaultLogQuery>> queries_;
58     std::mutex mutex_;
59 };
60 };      // namespace HiviewDFX
61 };      // namespace OHOS
62 #endif  // HIVIEWDFX_FAULTLOGGER_SERVICE_OHOS_H
63