• 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 
16 #include "content_sensor_manager.h"
17 
18 #include "device_info_collector.h"
19 #include "device_profile_log.h"
20 #include "system_info_collector.h"
21 
22 namespace OHOS {
23 namespace DeviceProfile {
24 namespace {
25 const std::string TAG = "ContentSensorManager";
26 }
27 
28 IMPLEMENT_SINGLE_INSTANCE(ContentSensorManager);
29 
Init()30 bool ContentSensorManager::Init()
31 {
32     auto runner = AppExecFwk::EventRunner::Create("csCollector");
33     csCollectorHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
34     if (csCollectorHandler_ == nullptr) {
35         return false;
36     }
37     return Collect();
38 }
39 
Collect()40 bool ContentSensorManager::Collect()
41 {
42     auto csTask = []() {
43         HILOGI("ContentSensorManager Collect");
44         std::list<std::shared_ptr<ContentCollector>> taskList;
45         taskList.push_back(std::make_shared<DeviceInfoCollector>());
46         taskList.push_back(std::make_shared<SystemInfoCollector>());
47         for (auto& task : taskList) {
48             ServiceCharacteristicProfile profileData;
49             task->ConvertToProfileData(profileData);
50             task->DoCollect(profileData);
51         }
52     };
53     if (!csCollectorHandler_->PostTask(csTask)) {
54         HILOGE("post task failed");
55         return false;
56     }
57     return true;
58 }
59 } // namespace DeviceProfile
60 } // namespace OHOS