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 #include "common_event_manager_service_ability.h"
17
18 #include "event_log_wrapper.h"
19
20 namespace OHOS {
21 namespace EventFwk {
22 namespace {
23 REGISTER_SYSTEM_ABILITY_BY_ID(CommonEventManagerServiceAbility, COMMON_EVENT_SERVICE_ID, true);
24 }
25
CommonEventManagerServiceAbility(const int32_t systemAbilityId,bool runOnCreate)26 CommonEventManagerServiceAbility::CommonEventManagerServiceAbility(const int32_t systemAbilityId, bool runOnCreate)
27 : SystemAbility(systemAbilityId, runOnCreate), service_(nullptr)
28 {}
29
~CommonEventManagerServiceAbility()30 CommonEventManagerServiceAbility::~CommonEventManagerServiceAbility()
31 {}
32
OnStart()33 void CommonEventManagerServiceAbility::OnStart()
34 {
35 EVENT_LOGD("OnStart called.");
36 if (service_ != nullptr) {
37 EVENT_LOGD("The CommonEventManagerService has existed.");
38 return;
39 }
40
41 service_ = DelayedSingleton<CommonEventManagerService>::GetInstance();
42 ErrCode errorCode = service_->Init();
43 if (errorCode != ERR_OK) {
44 EVENT_LOGE("Failed to init the commonEventManagerService instance.");
45 return;
46 }
47
48 if (!Publish(service_.get())) {
49 EVENT_LOGE("Failed to publish CommonEventManagerService to SystemAbilityMgr");
50 return;
51 }
52 }
53
OnStop()54 void CommonEventManagerServiceAbility::OnStop()
55 {
56 EVENT_LOGD("onStop called.");
57 service_ = nullptr;
58 }
59 } // namespace EventFwk
60 } // namespace OHOS