• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 #ifndef OHOS_SHARING_EVENT_BASE_H
17 #define OHOS_SHARING_EVENT_BASE_H
18 
19 #include <list>
20 #include <memory>
21 #include <string>
22 #include "common/event_comm.h"
23 
24 namespace OHOS {
25 namespace Sharing {
26 
27 class EventEmitter {
28 public:
29     virtual ~EventEmitter() = default;
30 
31     virtual int32_t SendEvent(SharingEvent &event);
32     virtual int32_t SendSyncEvent(SharingEvent &event);
33 
34 protected:
35     ClassType classType_ = CLASS_TYPE_SCHEDULER;
36 };
37 
38 class EventListener : public std::enable_shared_from_this<EventListener> {
39 public:
40     virtual ~EventListener() = default;
41 
42     virtual int32_t Register();
43     virtual int32_t UnRegister();
44     virtual int32_t OnEvent(SharingEvent &event) = 0;
45 
46     virtual bool IsAcceptType(EventType eventType);
47     virtual void SetListenerClassType(ClassType classType);
48     virtual int32_t AddAcceptEventType(EventType eventType);
49     virtual int32_t DelAcceptEventType(EventType eventType);
50 
51     virtual std::list<EventType> GetAcceptTypes();
52     virtual ClassType GetListenerClassType();
53 
54 protected:
55     std::list<EventType> acceptEvents_;
56     ClassType classType_ = CLASS_TYPE_SCHEDULER;
57 };
58 
59 class EventChecker {
60 public:
61     static void CheckEvent(EventMsg::Ptr eventMsg);
62 };
63 
64 } // namespace Sharing
65 } // namespace OHOS
66 #endif