• 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 #ifndef COOPERATE_EVENT_MANAGER_H
17 #define COOPERATE_EVENT_MANAGER_H
18 
19 #include <list>
20 #include <mutex>
21 #include <string>
22 
23 #include "nocopyable.h"
24 #include "refbase.h"
25 #include "singleton.h"
26 #include "uds_session.h"
27 
28 #include "cooperation_message.h"
29 
30 namespace OHOS {
31 namespace MMI {
32 class CooperateEventManager final {
33     DECLARE_DELAYED_SINGLETON(CooperateEventManager);
34 public:
35     DISALLOW_COPY_AND_MOVE(CooperateEventManager);
36 
37     enum EventType { LISTENER, ENABLE, START, STOP, STATE };
38 
39     struct EventInfo : public RefBase {
40         EventType type;
41         SessionPtr sess;
42         MmiMessageId msgId;
43         int32_t userData;
44         std::string deviceId;
45         CooperationMessage msg;
46         bool state;
47     };
48 
49     void AddCooperationEvent(sptr<EventInfo> event);
50     void RemoveCooperationEvent(sptr<EventInfo> event);
51     int32_t OnCooperateMessage(CooperationMessage msg, const std::string &deviceId = "");
52     void OnEnable(CooperationMessage msg, const std::string &deviceId = "");
53     void OnStart(CooperationMessage msg, const std::string &deviceId = "");
54     void OnStop(CooperationMessage msg, const std::string &deviceId = "");
55     void OnGetState(bool state);
56     void OnErrorMessage(EventType type, CooperationMessage msg);
57 
58 private:
59     void NotifyCooperateMessage(SessionPtr sess, MmiMessageId msgId, int32_t userData,
60         const std::string &deviceId, CooperationMessage msg);
61     void NotifyCooperateState(SessionPtr sess, MmiMessageId msgId, int32_t userData, bool state);
62 
63 private:
64     std::mutex lock_;
65     std::list<sptr<EventInfo>> remoteCooperateCallbacks_;
66     std::map<EventType, sptr<EventInfo>> cooperateCallbacks_ {
67         {EventType::ENABLE, nullptr},
68         {EventType::START, nullptr},
69         {EventType::STOP, nullptr},
70         {EventType::STATE, nullptr}
71     };
72 };
73 
74 #define CooperateEventMgr ::OHOS::DelayedSingleton<CooperateEventManager>::GetInstance()
75 } // namespace MMI
76 } // namespace OHOS
77 #endif // COOPERATE_EVENT_MANAGER_H
78