Add TIDL code for signal transmisstion
[platform/core/appfw/slp-pkgmgr.git] / client / src / signal_receiver.hh
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #ifndef CLIENT_SRC_SIGNAL_RECEIVER_H_
19 #define CLIENT_SRC_SIGNAL_RECEIVER_H_
20
21 #include "package-manager.h"
22
23 #include <map>
24 #include <memory>
25 #include <string>
26 #include <tuple>
27
28 #include "PkgSignal.h"
29
30
31 namespace pkgmgr {
32 namespace client {
33
34 namespace pkg_group = rpc_port::PkgSignal::group;
35 namespace pkg_signal = rpc_port::PkgSignal;
36
37 class SignalReceiver : public pkg_group::PkgSignal {
38  public:
39   SignalReceiver(bool is_system);
40   virtual ~SignalReceiver();
41
42   void OnAsyncResult(std::string signal, int targetUid, std::string reqId,
43       std::vector<pkg_signal::PkgInfo> pkgs, std::string key,
44       std::string val) override;
45
46   void OnAsyncResultForResource(std::string signal, int targetUid,
47       std::string reqId, std::string pkgid, std::string status,
48       pkg_signal::ExtraData extra) override;
49
50   int AddEventHandler(std::string req_key, pkgmgr_handler event_cb, void* data);
51   int AddEventHandler(std::string req_key, pkgmgr_app_handler app_event_cb,
52       void* data);
53   int AddEventHandler(std::string req_key,
54       pkgmgr_pkg_size_info_receive_cb event_cb, void* pc, void* data);
55   int AddEventHandler(std::string req_key, pkgmgr_res_handler event_cb,
56       void* data);
57
58  private:
59   static int GetRequestId();
60   int AddEventHandler(std::string req_key, pkgmgr_handler event_cb,
61       pkgmgr_app_handler app_event_cb, void* data);
62   void HandleHandler(int targetUid, const std::string& reqId,
63       const std::vector<pkg_signal::PkgInfo>& pkgs, const std::string& key,
64       const std::string& val) const;
65   void HandleGlobalHandler(int targetUid, const std::string& reqId,
66       const std::vector<pkg_signal::PkgInfo>& pkgs, const std::string& key,
67       const std::string& val) const;
68   void HandleResHandler(const std::string& signal, int targetUid,
69       const std::string& reqId, const std::string& pkgid,
70       const std::string& status, pkg_signal::ExtraData& extra) const;
71   void HandleGlobalResHandler(const std::string& signal, int targetUid,
72       const std::string& reqId, const std::string& pkgid,
73       const std::string& status, pkg_signal::ExtraData& extra) const;
74   void HandleSizeInfoHandler(const std::string& reqId,
75       const std::vector<pkg_signal::PkgInfo>& pkgs,
76       const std::string& key, const std::string& val) const;
77
78  private:
79   static inline int request_id_;
80   std::map<std::string, std::tuple<int, pkgmgr_handler, pkgmgr_app_handler,
81       void*>> handlers_;
82   std::list<std::tuple<int, pkgmgr_handler, pkgmgr_app_handler, void*>> global_handlers_;
83   std::map<std::string,
84       std::tuple<int, pkgmgr_res_handler, void*>> res_handlers_;
85   std::list<std::tuple<int, pkgmgr_res_handler, void*>> global_res_handlers_;
86   std::map<std::string,
87       std::tuple<int, pkgmgr_pkg_size_info_receive_cb, void*, void*>> size_info_handlers_;
88   std::list<std::tuple<int, pkgmgr_pkg_size_info_receive_cb, void*, void*>> global_size_info_handlers_;
89 };
90
91 }  // namespace client
92 }  // namespace pkgmgr
93
94 #endif  // CLIENT_SRC_CONNECTOR_H_