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 public: 39 void Cancel(); 40 void UpdateStatus(uint32_t status, bool force = false); 41 void SetProgressEnabled(bool enable); 42 bool IsProgressEnabled() const; 43 void UpdateProgress(uint32_t total, uint32_t current); 44 void UpdateProgress(uint64_t progress); 45 int& GetOutputFd(); 46 void CloseOutputFd(); 47 bool Init(std::vector<std::u16string>& args); 48 void Uninit(); 49 void SetTitle(const std::string &path); 50 void SetFolder(const std::string &folder); 51 std::string GetFolder(); 52 private: 53 void Dump() const; 54 class ClientDeathRecipient : public IRemoteObject::DeathRecipient { 55 public: 56 ClientDeathRecipient(uint32_t reqId, bool& deathed); 57 virtual ~ClientDeathRecipient() = default; 58 public: 59 virtual void OnRemoteDied(const wptr<IRemoteObject>& remote); 60 private: 61 uint32_t reqId_; 62 bool& deathed_; 63 }; 64 private: 65 struct ArgValue { 66 char value[SINGLE_ARG_MAXLEN + 1] = {0}; 67 }; 68 std::mutex mutex_; 69 int uid_ {-1}; 70 int pid_ {-1}; 71 bool canceled_ {false}; 72 bool finished_ {false}; 73 bool hasError_ {false}; 74 uint32_t reqId_ {0}; 75 char* argHead_[ARG_MAX_COUNT + 1] = {nullptr}; 76 std::unique_ptr<ArgValue> argValues_[ARG_MAX_COUNT + 1] = {nullptr}; 77 int outfd_ {-1}; 78 sptr<IRemoteObject::DeathRecipient> deathRecipient_; 79 bool progressEnabled_ {false}; 80 uint32_t progressTick_ {0}; 81 uint64_t progress_ {0}; 82 std::string path_; 83 std::string folder_; 84 const uint64_t FINISH = 100; 85 }; 86 } // namespace HiviewDFX 87 } // namespace OHOS 88 #endif // HIDUMPER_SERVICES_DUMP_RAW_PARAM_H 89