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 HIDUMPER_SERVICES_DUMP_RAW_PARAM_H 16 #define HIDUMPER_SERVICES_DUMP_RAW_PARAM_H 17 #include <set> 18 #include <string_ex.h> 19 #include <vector> 20 #include "dump_controller.h" 21 #include "idump_broker.h" 22 namespace OHOS { 23 namespace HiviewDFX { 24 class DumpManagerService; 25 class DumpManagerServiceClient; 26 class RawParam { 27 public: 28 RawParam(int calllingUid, int calllingPid, uint32_t reqId, std::vector<std::u16string>& args, int outfd); 29 ~RawParam(); 30 int GetArgc(); 31 char** GetArgv(); 32 int GetUid(); 33 int GetPid(); 34 uint32_t GetRequestId(); 35 bool IsCanceled(); 36 bool IsFinished(); 37 bool HasError(); 38 int GetCallerPpid(); 39 public: 40 void Cancel(); 41 void UpdateStatus(uint32_t status, bool force = false); 42 void SetProgressEnabled(bool enable); 43 bool IsProgressEnabled() const; 44 void UpdateProgress(uint32_t total, uint32_t current); 45 void UpdateProgress(uint64_t progress); 46 int& GetOutputFd(); 47 void CloseOutputFd(); 48 bool Init(std::vector<std::u16string>& args); 49 void Uninit(); 50 void SetTitle(const std::string &path); 51 void SetFolder(const std::string &folder); 52 std::string GetFolder(); 53 private: 54 void Dump() const; 55 void SetCallerPpid(const std::string &ppid); 56 class ClientDeathRecipient : public IRemoteObject::DeathRecipient { 57 public: 58 ClientDeathRecipient(uint32_t reqId, bool& deathed); 59 virtual ~ClientDeathRecipient() = default; 60 public: 61 virtual void OnRemoteDied(const wptr<IRemoteObject>& remote); 62 private: 63 uint32_t reqId_; 64 bool& deathed_; 65 }; 66 private: 67 struct ArgValue { 68 char value[SINGLE_ARG_MAXLEN + 1] = {0}; 69 }; 70 std::mutex mutex_; 71 int uid_ {-1}; 72 int pid_ {-1}; 73 int callerPpid_ {-1}; 74 bool canceled_ {false}; 75 bool finished_ {false}; 76 bool hasError_ {false}; 77 uint32_t reqId_ {0}; 78 char* argHead_[ARG_MAX_COUNT + 1] = {nullptr}; 79 std::unique_ptr<ArgValue> argValues_[ARG_MAX_COUNT + 1] = {nullptr}; 80 int outfd_ {-1}; 81 sptr<IRemoteObject::DeathRecipient> deathRecipient_; 82 bool progressEnabled_ {false}; 83 uint32_t progressTick_ {0}; 84 uint64_t progress_ {0}; 85 std::string path_; 86 std::string folder_; 87 const uint64_t FINISH = 100; 88 }; 89 } // namespace HiviewDFX 90 } // namespace OHOS 91 #endif // HIDUMPER_SERVICES_DUMP_RAW_PARAM_H 92