summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjunkyu han <junkyu.han@samsung.com>2018-06-23 11:12:33 +0900
committerjunkyu han <junkyu.han@samsung.com>2018-06-25 16:38:56 +0900
commit2ad9c9f1aad0b445079ce10ef9f8e43b5bb2f140 (patch)
tree35690f88b3fbf210a3730fdb5d97d46338539950
parent81af3490d0423208a34faf0d883e44e0ae437fe6 (diff)
downloadttsd-worker-package-2ad9c9f1aad0b445079ce10ef9f8e43b5bb2f140.tar.gz
ttsd-worker-package-2ad9c9f1aad0b445079ce10ef9f8e43b5bb2f140.tar.bz2
ttsd-worker-package-2ad9c9f1aad0b445079ce10ef9f8e43b5bb2f140.zip
Apply ttd-worker-dbus API
Change-Id: I45657b5687a23e8c561372d2eb284f6954d7376a
-rw-r--r--CMakeLists.txt3
-rw-r--r--inc/log.h8
-rw-r--r--inc/package_worker.h14
-rw-r--r--inc/package_worker_pkgmgr.h23
-rw-r--r--inc/package_worker_report.h33
-rw-r--r--packaging/package-manager-worker.spec8
-rw-r--r--src/package_worker.c195
-rw-r--r--src/package_worker_pkgmgr.c96
-rw-r--r--src/package_worker_report.c155
9 files changed, 411 insertions, 124 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cccaa71..285b71a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -10,6 +10,7 @@ pkg_check_modules(APP_PKGS REQUIRED
glib-2.0
json-glib-1.0
libcurl
+ things-service-worker
)
FOREACH (flag ${APP_PKGS_CFLAGS})
@@ -26,7 +27,7 @@ FILE(GLOB PACKAGE_WORKER_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
ADD_EXECUTABLE(${PROJECT_NAME} ${PACKAGE_WORKER_SOURCE})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -lm ${APP_PKGS_LDFLAGS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${APP_PKGS_LDFLAGS} -lm)
SET(VENDOR "tizen")
SET(PACKAGE ${PROJECT_NAME})
diff --git a/inc/log.h b/inc/log.h
index 5ab0f8e..de2e7e7 100644
--- a/inc/log.h
+++ b/inc/log.h
@@ -14,15 +14,15 @@
* limitations under the License.
*/
-#ifndef __PACKAGE_MANAGER_WORKER_LOG_H__
-#define __PACKAGE_MANAGER_WORKER_LOG_H__
+#ifndef __PACKAGE_WORKER_LOG_H__
+#define __PACKAGE_WORKER_LOG_H__
#include <dlog.h>
#ifdef LOG_TAG
#undef LOG_TAG
#endif
-#define LOG_TAG "PKG_MANAGER_WORKER"
+#define LOG_TAG "TTSD_PACKAGE"
#if !defined(_V)
#define _V(fmt, arg...) dlog_print(DLOG_VERBOSE, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
@@ -95,4 +95,4 @@
} \
}
-#endif /* __PACKAGE_MANAGER_WORKER_LOG_H__*/
+#endif /* __PACKAGE_WORKER_LOG_H__*/
diff --git a/inc/package_worker.h b/inc/package_worker.h
index f778178..34be608 100644
--- a/inc/package_worker.h
+++ b/inc/package_worker.h
@@ -22,7 +22,19 @@
#define PACKAGE "package"
#define APPLICATION "application"
-void pm_worker_report_result(const char *report);
+typedef enum {
+ OPERATION_UNKNOWN = -1,
+ OPERATION_INSTALL = 0,
+ OPERATION_REMOVE,
+ OPERATION_PACKAGE,
+ OPERATION_APPLICATION,
+} operation_type_e;
+
+typedef enum {
+ WORK_RESULT_WORKING = 0,
+ WORK_RESULT_SUCCESS,
+ WORK_RESULT_FAIL,
+} work_result_e;
#endif /* __PACKAGE_WORKER_H__ */
diff --git a/inc/package_worker_pkgmgr.h b/inc/package_worker_pkgmgr.h
index 72e92a1..8e75a35 100644
--- a/inc/package_worker_pkgmgr.h
+++ b/inc/package_worker_pkgmgr.h
@@ -17,27 +17,12 @@
#ifndef __PACKAGE_WORKER_PKGMGR_H__
#define __PACKAGE_WORKER_PKGMGR_H__
-typedef enum {
- PKGMGR_INSTALL = 0,
- PKGMGR_REMOVE,
- PKGMGR_MANAGE_MAX,
-} pkgmgr_manage_type_e;
+#include "package_worker.h"
-typedef enum {
- PKGMGR_PACKAGE = 0,
- PKGMGR_APPLICATION,
- PKGMGR_LIST_MAX,
-} pkgmgr_list_type_e;
-
-typedef enum {
- REQUEST_SUCCESS = 0,
- REQUEST_FAIL,
-} request_result_e;
-
-typedef void (*request_result_cb)(const char *package, pkgmgr_manage_type_e type, request_result_e result, void *user_data);
+typedef void (*request_result_cb)(const char *package, operation_type_e op_type, work_result_e result, void *user_data);
int package_worker_pkgmgr_manage_package_by_type(const char *package,
- pkgmgr_manage_type_e type, request_result_cb result_cb, void *cb_data);
-char *package_worker_pkgmgr_get_installed_list_by_type(pkgmgr_list_type_e type);
+ operation_type_e op_type, request_result_cb result_cb, void *cb_data);
+char *package_worker_pkgmgr_get_installed_list_by_type(operation_type_e op_type);
#endif /* __PACKAGE_WORKER_PKGMGR_H__ */
diff --git a/inc/package_worker_report.h b/inc/package_worker_report.h
new file mode 100644
index 0000000..fdc4f66
--- /dev/null
+++ b/inc/package_worker_report.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+#ifndef __PACKAGE_WORKER_REPORT_H__
+#define __PACKAGE_WORKER_REPORT_H__
+
+#include "package_worker.h"
+
+typedef void(*report_completed_cb)(work_result_e result, void *user_data);
+
+int package_worker_report_init(const char *cmd_id);
+void package_worker_report_fini(void);
+
+int package_worker_report_submit_report(const char *report,
+ operation_type_e op_type,
+ work_result_e result,
+ report_completed_cb completed_cb,
+ void *cb_data);
+
+#endif /* __PACKAGE_WORKER_REPORT_H__ */
diff --git a/packaging/package-manager-worker.spec b/packaging/package-manager-worker.spec
index a29f815..637025d 100644
--- a/packaging/package-manager-worker.spec
+++ b/packaging/package-manager-worker.spec
@@ -12,14 +12,16 @@ Source0: %{name}-%{version}.tar.gz
BuildRequires: cmake
BuildRequires: hash-signer
-BuildRequires: pkgconfig(libtzplatform-config)
-BuildRequires: pkgconfig(dlog)
+
BuildRequires: pkgconfig(capi-appfw-service-application)
BuildRequires: pkgconfig(capi-appfw-package-manager)
BuildRequires: pkgconfig(capi-appfw-app-manager)
-BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(things-service-worker)
+BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(json-glib-1.0)
+BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(libcurl)
+BuildRequires: pkgconfig(dlog)
%description
TTSD Worker that manages packages - will be installed & was installed.
diff --git a/src/package_worker.c b/src/package_worker.c
index 1b1c551..0c09578 100644
--- a/src/package_worker.c
+++ b/src/package_worker.c
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
@@ -21,63 +22,82 @@
#include "log.h"
#include "package_worker.h"
#include "package_worker_http.h"
+#include "package_worker_report.h"
#include "package_worker_pkgmgr.h"
#include "package_worker_checksum.h"
#include "package_worker_metadata.h"
#define TEST_STR "{\"id\": \"test-page1524536333414p\",\"filename\": \"org.tizen.example.CustomRenderer.Tizen.Mobile-1.0.0.tpk\",\"url\": \"https://d3d0p8vzmg5wus.cloudfront.net/test-page1524536333414p/org.tizen.example.CustomRenderer.Tizen.Mobile-1.0.0.tpk?Expires=1525141135&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9kM2QwcDh2em1nNXd1cy5jbG91ZGZyb250Lm5ldC90ZXN0LXBhZ2UxNTI0NTM2MzMzNDE0cC9vcmcudGl6ZW4uZXhhbXBsZS5DdXN0b21SZW5kZXJlci5UaXplbi5Nb2JpbGUtMS4wLjAudHBrIiwiQ29uZGl0aW9uIjp7IkRhdGVMZXNzVGhhbiI6eyJBV1M6RXBvY2hUaW1lIjoxNTI1MTQxMTM1fX19XX0_&Signature=cmx0DdSSU~fA3qyq0amdNa8mD2lSxHTnwoolAn1GimetKer7qThcvfCjlGB6bCe2b4sEinxaSVPmsKfewLFrlsa8W1yZeFLzJlIi1bBywgAeYUfut3~OgnMUqlWsByzitxcjJk4f6Wpdm5gJmkPMDXS4YnmyolAZZFEM5npVCtxbSObaaPJ~IgmiuCbHzioIbs~DBKw1-zfECkB~yKRi7exCat-zELDtj8i28M~~qlDNDOLm5PI3~Qkbem4najid4xKlgGnn3hnlSxqeJYbCGNzbt4dwwJ9kRIT7MB8ul~V3t0IY9cfxqEVA61MwTjHrJnYbMP3J43fYQpDY~XWGhw__&Key-Pair-Id=APKAIKWABALTNMYO2CWA\",\"hash\": \"64d16fa812b967e40ae02f27489aefae\"}"
-#define TEMP_REPORT_FILE "/tmp/pmw-report.json"
+#define UNINSTALL_PACKAGE_NAME "ttsd-worker-system"
-static void __temp_report_result_internal(const char *report)
+static void __report_completed_cb(work_result_e result, void *user_data)
{
- FILE *fp = NULL;
- ret_if(!report);
-
- fp = fopen(TEMP_REPORT_FILE, "w");
-
- if (!fp) {
- _E("Failed to open file: %s", TEMP_REPORT_FILE);
- return;
- }
+ _D("Report completed[%d]", result);
- fprintf(fp, "%s\n", report);
- fclose(fp);
-}
+ package_worker_report_fini();
-void pm_worker_report_result(const char *report)
-{
- __temp_report_result_internal(report);
- /* TODO : report result to daemon, and notify it */
+ service_app_exit();
}
-static void __request_result_cb(const char *package, pkgmgr_manage_type_e type,
- request_result_e result, void *user_data)
+static void __request_completed_cb(const char *package, operation_type_e op_type,
+ work_result_e result, void *user_data)
{
- /* Submit report with result */
+ int ret = 0;
const char *report = NULL;
- ret_if(type >= PKGMGR_MANAGE_MAX);
-
- if (type == PKGMGR_INSTALL) {
- if (result == REQUEST_SUCCESS)
- report = "Install Successed";
+ switch (op_type)
+ {
+ case OPERATION_INSTALL:
+ if (result == WORK_RESULT_SUCCESS)
+ report = "Install successed";
+ else if (result == WORK_RESULT_FAIL)
+ report = "Install failed";
else
- report = "Install Failed";
- } else {
- if (result == REQUEST_SUCCESS)
- report = "Uninstall Successed";
+ report = "Install still working";
+ break;
+ case OPERATION_REMOVE:
+ if (result == WORK_RESULT_SUCCESS)
+ report = "Remove successed";
+ else if (result == WORK_RESULT_FAIL)
+ report = "Remove failed";
else
- report = "Uninstall Failed";
+ report = "Remove still working";
+ break;
+ case OPERATION_PACKAGE:
+ case OPERATION_APPLICATION:
+ default:
+ _E("Something wrong operation");
+ goto DONE;
}
+ /* Submit Report here */
+ ret = package_worker_report_submit_report(report, op_type,
+ result, __report_completed_cb, NULL);
- _D("Request result[%s]", report);
+ if (!ret)
+ return;
- /* Submit Report here */
+DONE:
+ _E("Failed to Submit Report");
+ package_worker_report_fini();
service_app_exit();
}
+static operation_type_e __get_operation_type_from_str(const char *operation)
+{
+ if (!g_strcmp0(operation, "install"))
+ return OPERATION_INSTALL;
+ else if (!g_strcmp0(operation, "remove"))
+ return OPERATION_REMOVE;
+ else if (!g_strcmp0(operation, "package"))
+ return OPERATION_PACKAGE;
+ else if (!g_strcmp0(operation, "application"))
+ return OPERATION_APPLICATION;
+ else
+ return OPERATION_UNKNOWN;
+}
+
static bool service_app_create(void *data)
{
// Todo: add your code here.
@@ -98,72 +118,121 @@ static void service_app_control(app_control_h app_control, void *data)
int ret = 0;
bool valid = false;
char *report = NULL;
+ char *cmd_id = NULL;
char *operation = NULL;
metadata_s *metadata = NULL;
+ operation_type_e op_type = OPERATION_UNKNOWN;
+ work_result_e result = WORK_RESULT_SUCCESS;
+
+ ret = app_control_get_extra_data(app_control, "id", &cmd_id);
+ if (ret != APP_CONTROL_ERROR_NONE)
+ service_app_exit();
+
+ ret = package_worker_report_init(cmd_id);
+ if (ret < 0)
+ service_app_exit();
ret = app_control_get_extra_data(app_control, "operation", &operation);
if (ret != APP_CONTROL_ERROR_NONE) {
_E("Cannot get operation from app control");
- /* Submit result as report */
- return;
+
+ report = g_strdup("Cannot get operation from app control");
+ result = WORK_RESULT_FAIL;
+ goto SUBMIT_REPORT;
}
- if (!g_strcmp0(operation, INSTALL)) {
+ op_type = __get_operation_type_from_str(operation);
+
+ switch (op_type)
+ {
+ case OPERATION_INSTALL:
metadata = package_worker_metadata_parse_json(TEST_STR);
if (!metadata) {
- /* Submit result as report */
_E("cannot get metadata");
- return;
+
+ report = g_strdup("Cannot get META DATA");
+ result = WORK_RESULT_FAIL;
+ goto SUBMIT_REPORT;
}
ret = package_worker_http_download_file(package_worker_metadata_get_url(metadata),
package_worker_metadata_get_file_path(metadata));
if (ret < 0) {
_E("Failed to Down load file");
- /* Submit result as report */
- goto DONE;
+
+ report = g_strdup("Failed to DownLoad Package File");
+ result = WORK_RESULT_FAIL;
+ goto SUBMIT_REPORT;
}
valid = package_worker_checksum_check_validity(package_worker_metadata_get_hash(metadata),
package_worker_metadata_get_file_path(metadata));
if (!valid) {
_E("This file[%s] is not valid");
- /* Submit result as report */
- goto DONE;
+ report = g_strdup("This Package is not valid");
+ result = WORK_RESULT_FAIL;
+ goto SUBMIT_REPORT;
}
ret = package_worker_pkgmgr_manage_package_by_type(package_worker_metadata_get_file_path(metadata),
- PKGMGR_INSTALL, __request_result_cb, NULL);
+ OPERATION_INSTALL, __request_completed_cb, NULL);
if (ret < 0) {
_D("Install Request is failed");
- /* Submit result as report */
- }
- } else if (!strcmp(operation, "uninstall")) {
- /*Todo: pkg_name */
- char * pkg_name = "org.tizen.example.CustomRenderer.Tizen.Mobile";
- ret = package_worker_pkgmgr_manage_package_by_type(pkg_name, PKGMGR_REMOVE,
- __request_result_cb, NULL);
+ report = g_strdup("Request Install is Failed");
+ result = WORK_RESULT_FAIL;
+ goto SUBMIT_REPORT;
+ }
+ goto DONE;
+ case OPERATION_REMOVE:
+ ret = package_worker_pkgmgr_manage_package_by_type(UNINSTALL_PACKAGE_NAME, OPERATION_REMOVE,
+ __request_completed_cb, NULL);
if (ret < 0) {
_E("Uninstall Request is failed");
- /* Submit result as report */
+
+ report = g_strdup("Request Uninstall is Failed");
+ result = WORK_RESULT_FAIL;
+ goto SUBMIT_REPORT;
+ }
+ goto DONE;
+ case OPERATION_PACKAGE:
+ report = package_worker_pkgmgr_get_installed_list_by_type(OPERATION_PACKAGE);
+ if (!report) {
+ _E("Failed to get Installed Package List");
+
+ report = g_strdup("Failed to get Installed Package List");
+ result = WORK_RESULT_FAIL;
}
- } else if(!strcmp(operation, "package")) {
- report = package_worker_pkgmgr_get_installed_list_by_type(PKGMGR_PACKAGE);
- /* Submit result as report */
- _D("Package List: %s", report);
- } else if(!strcmp(operation, "application")) {
- report = package_worker_pkgmgr_get_installed_list_by_type(PKGMGR_APPLICATION);
- /* Submit result as report */
- _D("Application List: %s", report);
+ break;
+ case OPERATION_APPLICATION:
+ report = package_worker_pkgmgr_get_installed_list_by_type(OPERATION_APPLICATION);
+ if (!report) {
+ _E("Failed to get Installed Package List");
+
+ report = g_strdup("Failed to get Installed Package List");
+ result = WORK_RESULT_FAIL;
+ }
+ break;
+ default:
+ break;
}
-DONE:
- package_worker_metadata_free(metadata);
+SUBMIT_REPORT:
+ ret = package_worker_report_submit_report(report, op_type,
+ result, __report_completed_cb, NULL);
+ g_free(report);
+ if (ret < 0) {
+ _E("Failed to Submit Report");
+ package_worker_report_fini();
- /* Sumit report */
+ service_app_exit();
+ }
- g_free(report);
+DONE:
+ g_free(cmd_id);
+ g_free(operation);
+
+ package_worker_metadata_free(metadata);
return;
}
diff --git a/src/package_worker_pkgmgr.c b/src/package_worker_pkgmgr.c
index f878c14..92fe570 100644
--- a/src/package_worker_pkgmgr.c
+++ b/src/package_worker_pkgmgr.c
@@ -20,6 +20,7 @@
#include <json-glib/json-glib.h>
#include "log.h"
+#include "package_worker.h"
#include "package_worker_pkgmgr.h"
typedef struct _request_h {
@@ -33,78 +34,97 @@ static void _request_cb(int id, const char *type, const char *package,
package_manager_event_state_e event_state, int progress,
package_manager_error_e error, void *user_data)
{
- pkgmgr_manage_type_e request_type = PKGMGR_INSTALL;
- request_result_e result = REQUEST_SUCCESS;
+ operation_type_e op_type = OPERATION_INSTALL;
+ work_result_e result = WORK_RESULT_SUCCESS;
request_h *handle = user_data;
ret_if(!handle);
if (event_type == PACKAGE_MANAGER_EVENT_TYPE_INSTALL ||
event_type == PACKAGE_MANAGER_EVENT_TYPE_UPDATE) {
- if (event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED)
+ if (event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED) {
_D("Install Successed");
- else if (event_state == PACKAGE_MANAGER_EVENT_STATE_FAILED) {
+ goto DONE;
+ } else if (event_state == PACKAGE_MANAGER_EVENT_STATE_FAILED) {
_E("Install Failed (%d)", error);
- result = REQUEST_FAIL;
+ result = WORK_RESULT_FAIL;
+ goto DONE;
}
- /* Should we deal the progress state until finished? like 10% 20%.. */
+ /* Should we deal the progress state until finished? like 10% 20%..?? */
} else if (event_type == PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL) {
- request_type = PKGMGR_REMOVE;
+ op_type = OPERATION_REMOVE;
- if (event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED)
+ if (event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED) {
_D("Uninstall Successed");
- else if (event_state == PACKAGE_MANAGER_EVENT_STATE_FAILED) {
+ goto DONE;
+ } else if (event_state == PACKAGE_MANAGER_EVENT_STATE_FAILED) {
_E("Uninstall Failed (%d)", error);
- result = REQUEST_FAIL;
+ result = WORK_RESULT_FAIL;
+ goto DONE;
}
}
+ return;
+
+DONE:
if (handle->result_cb)
- handle->result_cb(package, request_type, result, handle->cb_data);
+ handle->result_cb(package, op_type, result, handle->cb_data);
package_manager_request_destroy(handle->pkgmgr_h);
g_free(handle);
}
-int package_worker_pkgmgr_manage_package_by_type(const char *package, pkgmgr_manage_type_e type,
+int package_worker_pkgmgr_manage_package_by_type(const char *package, operation_type_e op_type,
request_result_cb result_cb, void *cb_data)
{
int ret = PACKAGE_MANAGER_ERROR_NONE;
package_manager_request_h pkgmgr_h;
request_h *handle;
+ int id = 0;
retv_if(!package, -1);
- retv_if(type >= PKGMGR_MANAGE_MAX, -1);
-
- handle = g_try_malloc0(sizeof(request_h));
- retv_if(!handle, -1);
ret = package_manager_request_create(&pkgmgr_h);
if (ret != PACKAGE_MANAGER_ERROR_NONE) {
_E("Failed to create package manager request handle");
- goto ERROR;
+ return -1;
}
+ handle = g_try_malloc0(sizeof(request_h));
+ if (!handle)
+ goto ERROR;
+
handle->pkgmgr_h = pkgmgr_h;
handle->result_cb = result_cb;
handle->cb_data = cb_data;
- if (type == PKGMGR_INSTALL)
+ switch (op_type)
+ {
+ case OPERATION_INSTALL:
ret = package_manager_request_install_with_cb(pkgmgr_h, package,
- _request_cb, handle, NULL);
- else
+ _request_cb, handle, &id);
+ break;
+ case OPERATION_REMOVE:
ret = package_manager_request_uninstall_with_cb(pkgmgr_h, package,
- _request_cb, handle, NULL);
+ _request_cb, handle, &id);
+ break;
+ case OPERATION_PACKAGE:
+ case OPERATION_APPLICATION:
+ default:
+ _E("Something wrong type for this function");
+ goto ERROR;
+ }
if (ret != PACKAGE_MANAGER_ERROR_NONE) {
- _E("Failed to request [%d]", type);
- package_manager_request_destroy(pkgmgr_h);
+ _E("Failed to request [%d]", op_type);
goto ERROR;
}
return 0;
ERROR:
+ package_manager_request_destroy(pkgmgr_h);
+
g_free(handle);
return -1;
@@ -152,11 +172,8 @@ static bool _application_list_foreach_cb(app_info_h app_info, void *user_data)
retv_if(!builder, FALSE);
- if (app_info_get_app_id(app_info, &id))
- return FALSE;
-
- if (app_info_get_label(app_info, &label))
- return FALSE;
+ app_info_get_app_id(app_info, &id);
+ app_info_get_label(app_info, &label);
json_builder_begin_object(builder);
json_builder_set_member_name(builder, "applicationID");
@@ -171,7 +188,7 @@ static bool _application_list_foreach_cb(app_info_h app_info, void *user_data)
return TRUE;
}
-char *package_worker_pkgmgr_get_installed_list_by_type(pkgmgr_list_type_e type)
+char *package_worker_pkgmgr_get_installed_list_by_type(operation_type_e op_type)
{
unsigned int len;
JsonNode *root = NULL;
@@ -179,8 +196,6 @@ char *package_worker_pkgmgr_get_installed_list_by_type(pkgmgr_list_type_e type)
char *installed_list = NULL;
JsonBuilder *builder = NULL;
- retv_if(type >= PKGMGR_LIST_MAX, NULL);
-
builder = json_builder_new();
json_builder_begin_object(builder);
@@ -188,10 +203,20 @@ char *package_worker_pkgmgr_get_installed_list_by_type(pkgmgr_list_type_e type)
json_builder_set_member_name(builder, "applicationList");
json_builder_begin_array(builder);
- if (type == PKGMGR_PACKAGE)
+ switch (op_type)
+ {
+ case OPERATION_PACKAGE:
package_manager_foreach_package_info(_package_list_foreach_cb, builder);
- else
+ break;
+ case OPERATION_APPLICATION:
app_manager_foreach_app_info(_application_list_foreach_cb, builder);
+ break;
+ case OPERATION_INSTALL:
+ case OPERATION_REMOVE:
+ default:
+ _E("Something wrong operation for this function");
+ goto DONE;
+ }
json_builder_end_array(builder);
json_builder_end_object(builder);
@@ -208,5 +233,10 @@ char *package_worker_pkgmgr_get_installed_list_by_type(pkgmgr_list_type_e type)
g_object_unref(gen);
return installed_list;
+
+DONE:
+ g_object_unref(builder);
+
+ return NULL;
}
diff --git a/src/package_worker_report.c b/src/package_worker_report.c
new file mode 100644
index 0000000..e8d7f1a
--- /dev/null
+++ b/src/package_worker_report.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+#include <glib.h>
+#include <ttd-worker-lib.h>
+#include <json-glib/json-glib.h>
+
+#include "log.h"
+#include "package_worker_report.h"
+
+typedef struct __report_h {
+ ttd_worker_report *report;
+ report_completed_cb report_cb;
+ void *cb_data;
+} _report_h;
+
+static _report_h *report_h = NULL;
+
+static char *__get_json_report_from_str(const char *report)
+{
+ unsigned int len;
+ JsonNode *root = NULL;
+ char *json_report = NULL;
+ JsonGenerator *gen = NULL;
+ JsonBuilder *builder = json_builder_new();
+
+ json_builder_begin_object(builder);
+ json_builder_set_member_name(builder, "result_detail");
+ json_builder_add_string_value(builder, report);
+ json_builder_end_object(builder);
+
+ gen = json_generator_new();
+
+ root = json_builder_get_root(builder);
+ g_object_unref(builder);
+
+ json_generator_set_root(gen, root);
+ json_report = json_generator_to_data(gen, &len);
+
+ json_node_unref(root);
+ g_object_unref(gen);
+
+ return json_report;
+}
+
+static void __submit_completed_cb(ttd_worker_submit_result_e result, ttd_worker_report *report, void *user_data)
+{
+ _D("Submit is completed[%d]", result);
+ _report_h *handle = user_data;
+
+ if (handle->report_cb)
+ handle->report_cb(result, handle->cb_data);
+ else
+ package_worker_report_fini();
+}
+
+int package_worker_report_init(const char *cmd_id)
+{
+ retv_if(!cmd_id, -1);
+
+ if (report_h)
+ package_worker_report_fini();
+
+ report_h = g_try_malloc0(sizeof(report_h));
+ retv_if(!report_h, -1);
+
+ report_h->report = ttd_worker_report_new_by_cmd_id(cmd_id);
+ if (!report_h->report) {
+ _E("Failed to new report by command id");
+ g_free(report_h);
+ return -1;
+ }
+
+ return 0;
+}
+
+void package_worker_report_fini(void)
+{
+ ttd_worker_report_free(report_h->report);
+
+ g_free(report_h);
+
+ report_h = NULL;
+}
+
+int package_worker_report_submit_report(const char *report,
+ operation_type_e op_type,
+ work_result_e result,
+ report_completed_cb completed_cb,
+ void *cb_data)
+{
+ int ret = 0;
+ char *json_report = NULL;
+
+ retv_if(!report_h->report, -1);
+
+ ret = ttd_worker_report_set_working_state(report_h->report, result);
+ if (ret < 0) {
+ _E("Failed to set report working state");
+ goto ERROR;
+ }
+
+ switch (op_type)
+ {
+ case OPERATION_UNKNOWN:
+ case OPERATION_INSTALL:
+ case OPERATION_REMOVE:
+ json_report = __get_json_report_from_str(report);
+ break;
+ case OPERATION_PACKAGE:
+ case OPERATION_APPLICATION:
+ json_report = g_strdup(report);
+ break;
+ default:
+ _E("Something Wrong Operation type");
+ goto ERROR;
+ }
+
+ ret = ttd_worker_report_set_report_data(report_h->report, json_report);
+ if (ret < 0) {
+ _E("Failed to set report data");
+ goto ERROR;
+ }
+
+ if (completed_cb) {
+ report_h->report_cb = completed_cb;
+ report_h->cb_data = cb_data;
+ }
+
+ ret = ttd_worker_submit_report(report_h->report, __submit_completed_cb, report_h);
+ if (ret < 0) {
+ _E("Failed to submit report");
+ goto ERROR;
+ }
+
+ return 0;
+
+ERROR:
+ package_worker_report_fini();
+
+ return -1;
+}