• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "app_event_block.h"
16 
17 #include "app_event_cache_common.h"
18 
19 using namespace OHOS::HiviewDFX::AppEventCacheCommon;
20 namespace OHOS {
21 namespace HiviewDFX {
AppEventBlock(std::shared_ptr<AppEventStore> store,const std::string & name)22 AppEventBlock::AppEventBlock(std::shared_ptr<AppEventStore> store, const std::string& name)
23 {
24     blockDao_ = std::make_shared<AppEventBlockDao>(store, name);
25 }
26 
GetStat(std::pair<int,int64_t> & statPair)27 int AppEventBlock::GetStat(std::pair<int, int64_t>& statPair)
28 {
29     return blockDao_->CountPackages(statPair.first, statPair.second);
30 }
31 
Add(const std::string & package)32 int AppEventBlock::Add(const std::string& package)
33 {
34     return blockDao_->InsertPackage(package);
35 }
36 
Remove(int num)37 int AppEventBlock::Remove(int num)
38 {
39     return blockDao_->DeletePackageByNum(num);
40 }
41 
Take(int size,std::vector<std::string> & packages)42 int AppEventBlock::Take(int size, std::vector<std::string>& packages)
43 {
44     int64_t seq = 0;
45     int result = blockDao_->GetPackagesBySize(size, packages, seq);
46     if (result == 0) {
47         return DB_SUCC;
48     } else if (result > 0 && blockDao_->DeletePackageBySeq(seq) == DB_SUCC) {
49         return result;
50     }
51     return DB_FAILED;
52 }
53 } // namespace HiviewDFX
54 } // namespace OHOS
55