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