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() {
57 signal_receiver_->StopReceiving();
60 std::string Connector::GenerateRequestId() const {
62 gettimeofday(&tv, NULL);
63 long curtime = tv.tv_sec * 1000000 + tv.tv_usec;
65 return std::to_string(getpid()) + "_" + std::to_string(curtime);
68 void Connector::SetTep(std::string tep_path, bool tep_move) {
69 tep_path_ = std::move(tep_path);
73 void Connector::SetTepArgs() {
74 argv_.push_back("-e");
75 argv_.push_back(tep_path_);
76 argv_.push_back("-M");
77 argv_.push_back(tep_move_ ? "tep_move" : "tep_copy");
80 void Connector::SetDebugMode() {
81 argv_.push_back("-G");
84 void Connector::SetSkipOptimization() {
85 argv_.push_back("-S");
88 void Connector::SetStatusType(int status_type) {
89 status_type_ = status_type;
92 const std::vector<std::string>& Connector::GetArgv() const {
96 pkg_proxy::PkgMgrAdmin* Connector::GetAdminProxy() {
97 if (!ConnectForAdmin())
100 return admin_proxy_.get();
103 pkg_proxy::PkgMgr* Connector::GetInfoProxy() {
104 if (!ConnectForInfo())
107 return info_proxy_.get();
110 pkg_proxy::PkgMgrForClearCache* Connector::GetCacheProxy() {
111 if (!ConnectForCache())
114 return cache_proxy_.get();
117 pkg_proxy::DelayedResult* Connector::GetDelayedResultProxy() {
118 if (!ConnectForDelayedResult())
121 return delayed_result_proxy_.get();
124 bool Connector::ConnectForAdmin() {
126 admin_proxy_.reset(new pkg_proxy::PkgMgrAdmin(&conn_admin_listener_,
130 if (conn_admin_listener_.GetState() == ConnectionState::Connected)
134 admin_proxy_->Connect(true);
135 } catch (const pkg_proxy::Exception& e) {
142 bool Connector::ConnectForInfo() {
144 info_proxy_.reset(new pkg_proxy::PkgMgr(&conn_info_listener_,
148 if (conn_info_listener_.GetState() == ConnectionState::Connected)
152 info_proxy_->Connect(true);
153 } catch (const pkg_proxy::Exception& e) {
160 bool Connector::ConnectForCache() {
162 cache_proxy_.reset(new pkg_proxy::PkgMgrForClearCache(&conn_cache_listener_,
166 if (conn_cache_listener_.GetState() == ConnectionState::Connected)
170 cache_proxy_->Connect(true);
171 } catch (const pkg_proxy::Exception& e) {
178 bool Connector::ConnectForDelayedResult() {
179 if (!delayed_result_proxy_) {
180 delayed_result_proxy_.reset(new pkg_proxy::DelayedResult(
181 &conn_delayed_result_listener_, SERVER_PROC_NAME));
184 if (conn_delayed_result_listener_.GetState() == ConnectionState::Connected)
188 delayed_result_proxy_->Connect(true);
189 } catch (const pkg_proxy::Exception& e) {
196 const std::shared_ptr<SignalReceiver>& Connector::GetSignalReceiver() {
197 if (!signal_receiver_)
198 signal_receiver_ = SignalReceiver::Create(
199 __is_system_type(pc_type_), status_type_);
201 return signal_receiver_;
204 void Connector::RemoveSignalReceiver() {
205 if (signal_receiver_)
206 signal_receiver_.reset();
209 pkgmgr_client_type Connector::GetPcType() const {
213 std::vector<std::string>& Connector::GetResRemovePath() {
214 return res_remove_path_;
217 std::vector<std::string>& Connector::GetResCreateDir() {
218 return res_create_dir_;
221 std::vector<pp::ResPath>& Connector::GetResCopyPath() {
222 return res_copy_path_;
225 const std::string& Connector::GetTepPath() {
229 bool Connector::GetTepMove() {
233 } // namespace client
234 } // namespace pkgmgr