1 /*
2  * Copyright (C) 2022 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 WORK_RECORD_H
17 #define WORK_RECORD_H
18 
19 #include <mutex>
20 #include <parcel.h>
21 #include <string>
22 #include <vector>
23 
24 #include "request.h"
25 
26 namespace OHOS {
27 namespace Location {
28 class WorkRecord : public Parcelable {
29 public:
30     WorkRecord();
31     ~WorkRecord() override = default;
32     bool Add(const std::shared_ptr<Request>& request);
33     bool Add(WorkRecord &workRecord, int32_t index);
34     bool Remove(int uid, int pid, std::string name, std::string uuid);
35     bool Find(int uid, std::string name, std::string uuid);
36     std::string GetPackageNameByUuid(std::string uuid);
37     void Clear();
38     void Set(WorkRecord &workRecord);
39     bool Remove(std::string name);
40     std::string GetDeviceId();
41     void SetDeviceId(std::string deviceId);
42     int Size();
43     bool IsEmpty();
44     std::string GetName(int index);
45     int GetUid(int index);
46     int GetPid(int index);
47     int GetTimeInterval(int index);
48     int GetNlpRequestType(int index);
49     std::string GetUuid(int index);
50     void ReadFromParcel(Parcel& parcel);
51     bool Marshalling(Parcel& parcel) const override;
52     bool MarshallingWorkRecord(Parcel& parcel) const;
53     static std::unique_ptr<WorkRecord> Unmarshalling(Parcel& parcel);
54     std::string ToString();
55 private:
56     int num_;
57     std::vector<int> uids_;
58     std::vector<int> pids_;
59     std::vector<std::string> names_;
60     std::vector<int> timeInterval_;
61     std::vector<std::string> uuid_;
62     std::vector<int> nlpRequestType_;
63     std::string deviceId_;
64     mutable std::mutex workRecordMutex_;
65 };
66 } // namespace Location
67 } // namespace OHOS
68 #endif // WORK_RECORD_H
69