2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "connector.hh"
22 #include <sys/socket.h>
26 #define REGULAR_USER 5000
30 constexpr const char SERVER_PROC_NAME[] = "d::org.tizen.appfw.pkgmgr";
32 static int _is_system_user(void)
36 if (uid < REGULAR_USER)
42 static bool __is_system_type(pkgmgr_client_type type)
44 if (type == PC_REQUEST || _is_system_user())
55 Connector::~Connector() = default;
57 std::string Connector::GenerateRequestId() const {
59 gettimeofday(&tv, NULL);
60 long curtime = tv.tv_sec * 1000000 + tv.tv_usec;
62 return std::to_string(getpid()) + "_" + std::to_string(curtime);
65 void Connector::SetTep(std::string tep_path, bool tep_move) {
66 tep_path_ = std::move(tep_path);
70 void Connector::SetTepArgs() {
71 argv_.push_back("-e");
72 argv_.push_back(tep_path_);
73 argv_.push_back("-M");
74 argv_.push_back(tep_move_ ? "tep_move" : "tep_copy");
77 void Connector::SetDebugMode() {
78 argv_.push_back("-G");
81 void Connector::SetSkipOptimization() {
82 argv_.push_back("-S");
85 const std::vector<std::string>& Connector::GetArgv() const {
89 pkg_proxy::PkgMgrAdmin* Connector::GetAdminProxy() {
90 if (!ConnectForAdmin())
93 return admin_proxy_.get();
96 pkg_proxy::PkgMgr* Connector::GetInfoProxy() {
97 if (!ConnectForInfo())
100 return info_proxy_.get();
103 pkg_proxy::PkgMgrForClearCache* Connector::GetCacheProxy() {
104 if (!ConnectForCache())
107 return cache_proxy_.get();
110 pkg_proxy::DelayedResult* Connector::GetDelayedResultProxy() {
111 if (!ConnectForDelayedResult())
114 return delayed_result_proxy_.get();
117 bool Connector::ConnectForAdmin() {
119 admin_proxy_.reset(new pkg_proxy::PkgMgrAdmin(&conn_admin_listener_,
123 if (conn_admin_listener_.GetState() == ConnectionState::Connected)
127 admin_proxy_->Connect(true);
128 } catch (const pkg_proxy::Exception& e) {
135 bool Connector::ConnectForInfo() {
137 info_proxy_.reset(new pkg_proxy::PkgMgr(&conn_info_listener_,
141 if (conn_info_listener_.GetState() == ConnectionState::Connected)
145 info_proxy_->Connect(true);
146 } catch (const pkg_proxy::Exception& e) {
153 bool Connector::ConnectForCache() {
155 cache_proxy_.reset(new pkg_proxy::PkgMgrForClearCache(&conn_cache_listener_,
159 if (conn_cache_listener_.GetState() == ConnectionState::Connected)
163 cache_proxy_->Connect(true);
164 } catch (const pkg_proxy::Exception& e) {
171 bool Connector::ConnectForDelayedResult() {
172 if (!delayed_result_proxy_) {
173 delayed_result_proxy_.reset(new pkg_proxy::DelayedResult(
174 &conn_delayed_result_listener_, SERVER_PROC_NAME));
177 if (conn_delayed_result_listener_.GetState() == ConnectionState::Connected)
181 delayed_result_proxy_->Connect(true);
182 } catch (const pkg_proxy::Exception& e) {
189 //const std::unique_ptr<SignalReceiver>& Connector::GetSignalReceiver() {
190 // if (!signal_receiver_)
191 // signal_receiver_.reset(new SignalReceiver(__is_system_type(pc_type_)));
193 // return signal_receiver_;
196 pkgmgr_client_type Connector::GetPcType() const {
200 std::vector<std::string>& Connector::GetResRemovePath() {
201 return res_remove_path_;
204 std::vector<std::string>& Connector::GetResCreateDir() {
205 return res_create_dir_;
208 std::vector<pp::ResPath>& Connector::GetResCopyPath() {
209 return res_copy_path_;
212 const std::string& Connector::GetTepPath() {
216 bool Connector::GetTepMove() {
220 pkgmgr_client_t* Connector::GetRawPc() {
224 } // namespace client
225 } // namespace pkgmgr