Refactor slp-pkgmgr with tidl
[platform/core/appfw/slp-pkgmgr.git] / client / src / connector.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_CONNECTOR_H_
19 #define CLIENT_SRC_CONNECTOR_H_
20
21 #include <sys/un.h>
22
23 #include <memory>
24 #include <string>
25 #include <vector>
26
27 #include "PkgMgrProxy.h"
28
29 #include "connection_event_listener.hh"
30 #include "signal_receiver.hh"
31
32 namespace pkgmgr {
33 namespace client {
34
35 namespace pkg_proxy = rpc_port::PkgMgrProxy::proxy;
36 namespace pp = rpc_port::PkgMgrProxy;
37
38 class Connector {
39  public:
40   Connector(pkgmgr_client_type pc_type) : pc_type_(pc_type) {}
41   virtual ~Connector();
42
43   virtual pkg_proxy::PkgMgrAdmin* GetAdminProxy();
44   virtual pkg_proxy::PkgMgr* GetInfoProxy();
45   virtual pkg_proxy::PkgMgrForClearCache* GetCacheProxy();
46   virtual pkg_proxy::DelayedResult* GetDelayedResultProxy();
47   virtual const std::unique_ptr<SignalReceiver>& GetSignalReceiver();
48   std::string GenerateRequestId() const;
49   void SetTep(std::string tep_path, bool tep_move);
50   void SetTepArgs();
51   void SetDebugMode();
52   void SetSkipOptimization();
53   const std::vector<std::string>& GetArgv() const;
54   pkgmgr_client_type GetPcType() const;
55   std::vector<std::string>& GetResRemovePath();
56   std::vector<std::string>& GetResCreateDir();
57   std::vector<pp::ResPath>& GetResCopyPath();
58   const std::string& GetTepPath();
59   bool GetTepMove();
60
61  private:
62   bool ConnectForAdmin();
63   bool ConnectForInfo();
64   bool ConnectForCache();
65   bool ConnectForDelayedResult();
66
67  private:
68   class Activator {
69    public:
70     Activator() : fd_(-1), addr_{} {}
71
72     bool Connect();
73     bool Create();
74     void SetTimeout(int timeout_msec);
75     int TryConnect();
76     bool ReceiveReady();
77
78    private:
79     int fd_;
80     sockaddr_un addr_;
81   };
82
83   pkgmgr_client_type pc_type_;
84   std::unique_ptr<pkg_proxy::PkgMgr> info_proxy_;
85   std::unique_ptr<pkg_proxy::PkgMgrForClearCache> cache_proxy_;
86   std::unique_ptr<pkg_proxy::PkgMgrAdmin> admin_proxy_;
87   std::unique_ptr<pkg_proxy::DelayedResult> delayed_result_proxy_;
88   std::vector<std::string> argv_;
89   ConnectionEventListener<pkg_proxy::PkgMgrAdmin> conn_admin_listener_;
90   ConnectionEventListener<pkg_proxy::PkgMgr> conn_info_listener_;
91   ConnectionEventListener<pkg_proxy::PkgMgrForClearCache> conn_cache_listener_;
92   ConnectionEventListener<pkg_proxy::DelayedResult> conn_delayed_result_listener_;
93   std::unique_ptr<SignalReceiver> signal_receiver_;
94   std::vector<std::string> res_remove_path_;
95   std::vector<std::string> res_create_dir_;
96   std::vector<pp::ResPath> res_copy_path_;
97   std::string tep_path_;
98   bool tep_move_ = false;
99   Activator activator_;
100 };
101
102 }  // namespace client
103 }  // namespace pkgmgr
104
105 #endif  // CLIENT_SRC_CONNECTOR_H_