// // Open Service Platform // Copyright (c) 2012 Samsung Electronics Co., Ltd. // // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // /** * @file backend.cpp */ #include #include #include #include #include #include #include #include #include "InstallerManager.h" #include "InstallerDefs.h" #include "InstallerUtil.h" using namespace Tizen::Base; using namespace Tizen::App; extern "C" void Osp_Initialize(); static bool __osp_installer_report_result(const Tizen::App::PackageId& packageId, int errorType); static pkgmgr_installer *_pi = null; int main(int argc, char **argv) { int ret = 0; const char *pkg_info = NULL; char* pkg_path = NULL; String path; PackageId packageId; int errorType = 0; pkgmgr_installer *pi = null; int req_type = 0; Osp_Initialize(); char buf[1024]; memset(buf, 0, sizeof(buf)); for (int i = 0; i < argc; i++) { strcat(buf, argv[i]); if (i != argc - 1) { strcat(buf, " "); } } int emul = 0; #ifdef _OSP_EMUL_ emul = 1; #endif fprintf(stderr, " ## osp-installer: %s[%s] cmd=[%s]\n", OSP_INSTALLER_VERSION, emul?"Emulator":"Target", buf); if (argc == TEST_ARG_COUNT) { errorType = InstallerManager::ReqeustByTest(); goto CATCH; } else if (argc == COMMAND_ARG_COUNT) { errorType = InstallerManager::RequestByCommand(argc, argv); goto CATCH; } pi = pkgmgr_installer_new(); _pi = pi; pkgmgr_installer_receive_request(pi, argc, argv); req_type = pkgmgr_installer_get_request_type(pi); if (PKGMGR_REQ_INVALID >= req_type) { goto CATCH; } pkg_info = pkgmgr_installer_get_request_info(pi); pkg_path = (const_cast(pkg_info)); AppLog(" # path = [%s]", pkg_path); path = pkg_path; switch (req_type) { case PKGMGR_REQ_INSTALL: { errorType = InstallerManager::Request(path, INSTALLER_OPERATION_INSTALL, INSTALLER_OPTION_NORMAL, packageId); if (_pi != 0) { char resultBuf[128] = {0}; snprintf(resultBuf, sizeof(resultBuf), "%ls", packageId.GetPointer()); pkgmgr_installer_send_signal(_pi, "tpk", resultBuf, "start", "install"); // temp pkgmgr_installer_send_signal(_pi, "tpk", resultBuf, "install_percent", "0"); usleep(50000); pkgmgr_installer_send_signal(_pi, "tpk", resultBuf, "install_percent", "30"); usleep(50000); } else { AppLog("_pi is null"); } // if (errorType != 0) // { // manager.RemoveGarbage(path); // } __osp_installer_report_result(packageId, errorType); } break; case PKGMGR_REQ_UNINSTALL: { PackageId reqeustPackageId; path.SubString(0, PACKAGE_ID_LENGTH, reqeustPackageId); AppLog("reqeustPackageId = %ls", reqeustPackageId.GetPointer()); ret = InstallerManager::Request(reqeustPackageId, INSTALLER_OPERATION_UNINSTALL, INSTALLER_OPTION_NORMAL, packageId); if (_pi != 0) { char resultBuf[128] = {0}; snprintf(resultBuf, sizeof(resultBuf), "%ls", packageId.GetPointer()); pkgmgr_installer_send_signal(_pi, "tpk", resultBuf, "start", "uninstall"); } else { AppLog("_pi is null"); } __osp_installer_report_result(packageId, errorType); } break; case PKGMGR_REQ_MOVE: { if (_pi != 0) { int moveType = -1; moveType = pkgmgr_installer_get_move_type(_pi); InstallerManager::RequestMove(path, moveType); } else { AppLog("_pi is null"); } } break; default: ret = -1; break; } if (ret == -1) { goto CATCH; } CATCH: return errorType; } bool __osp_installer_send_error(int errorType) { char errorMsg[11] = {0}; int error = 0; if (errorType >= INSTALLER_ERROR_USER_CANCEL) { error = INSTALLER_ERROR_FATAL_ERROR; } else { error = errorType; } snprintf(errorMsg, sizeof(errorMsg) - 1, "%d", error); pkgmgr_installer_send_signal(_pi, "tpk", "", "error", errorMsg); return true; } bool __osp_installer_report_result(const PackageId& packageId, int errorType) { int ret = 0; char resultBuf[128] = {0}; InstallerManager manager; const char* pPkgType = "tpk"; const char* pKey = "end"; const char* pValue = null; AppLog("------------------------------------------"); AppLog("osp_installer_report_result"); AppLog(" # request_type = [%d]", pkgmgr_installer_get_request_type(_pi)); AppLog(" # request_info = [%s]", pkgmgr_installer_get_request_info(_pi)); AppLog(" # session_id = [%s]", pkgmgr_installer_get_session_id(_pi)); AppLog("------------------------------------------"); if (_pi == 0) { AppLog("_pi is null"); return false; } if (errorType == 0) { pValue = "ok"; } else { pValue = "fail"; __osp_installer_send_error(errorType); } if (packageId.IsEmpty() == false) { snprintf(resultBuf, sizeof(resultBuf), "%ls", packageId.GetPointer()); } // temp pkgmgr_installer_send_signal(_pi, pPkgType, resultBuf, "install_percent", "65"); usleep(50000); pkgmgr_installer_send_signal(_pi, pPkgType, resultBuf, "install_percent", "100"); usleep(50000); ret = pkgmgr_installer_send_signal(_pi, pPkgType, resultBuf, pKey, pValue); AppLog("------------------------------------------"); AppLog("pkgmgr_installer_send_signal"); AppLog(" # type = [%s]", pPkgType); AppLog(" # pkg id = [%s]", resultBuf); AppLog(" # key = [%s]", pKey); AppLog(" # val = [%s]", pValue); AppLog(" # ret = [%s]", (ret == 0)?"success":"failure"); AppLog("------------------------------------------"); pkgmgr_installer_free(_pi); _pi = null; return true; }