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 "mock_common_event_stub.h"
17
18 using namespace OHOS::EventFwk;
19
PublishCommonEvent(const CommonEventData & event,const CommonEventPublishInfo & publishinfo,const sptr<IRemoteObject> & commonEventListener,const int32_t & userId)20 int32_t MockCommonEventStub::PublishCommonEvent(const CommonEventData &event, const CommonEventPublishInfo &publishinfo,
21 const sptr<IRemoteObject> &commonEventListener, const int32_t &userId)
22 {
23 EVENT_LOGI("enter");
24
25 return ERR_OK;
26 }
27
SubscribeCommonEvent(const CommonEventSubscribeInfo & subscribeInfo,const sptr<IRemoteObject> & commonEventListener)28 int32_t MockCommonEventStub::SubscribeCommonEvent(
29 const CommonEventSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &commonEventListener)
30 {
31 EVENT_LOGI("enter");
32
33 subscribeInfoPtr = std::make_shared<CommonEventSubscribeInfo>(subscribeInfo);
34
35 return ERR_OK;
36 }
37
DumpState(const uint8_t & dumpType,const std::string & event,const int32_t & userId,std::vector<std::string> & state)38 bool MockCommonEventStub::DumpState(const uint8_t &dumpType, const std::string &event, const int32_t &userId,
39 std::vector<std::string> &state)
40 {
41 EVENT_LOGI("enter");
42
43 if (subscribeInfoPtr) {
44 // get matchingSkills
45 auto matchingSkills = subscribeInfoPtr->GetMatchingSkills();
46 // get events
47 auto events = matchingSkills.GetEvents();
48
49 for (auto it : events) {
50 state.emplace_back(it);
51 }
52 } else {
53 // do nothing
54 }
55
56 subscribeInfoPtr = nullptr;
57
58 return true;
59 }
60