diff options
author | Sehong Na <sehong.na@samsung.com> | 2014-05-31 12:35:58 +0900 |
---|---|---|
committer | Sehong Na <sehong.na@samsung.com> | 2014-05-31 12:35:58 +0900 |
commit | 335597a2db0a33a96684c052e4cf8a0736918fcf (patch) | |
tree | e70ebd40424b0c5f9969d3cc663ec6b6b5c3cf26 /provider/include | |
download | download-provider-335597a2db0a33a96684c052e4cf8a0736918fcf.tar.gz download-provider-335597a2db0a33a96684c052e4cf8a0736918fcf.tar.bz2 download-provider-335597a2db0a33a96684c052e4cf8a0736918fcf.zip |
Initialize Tizen 2.3submit/tizen_2.3/20140531.0654422.3a_release
Diffstat (limited to 'provider/include')
-rwxr-xr-x | provider/include/download-provider-config.h | 46 | ||||
-rwxr-xr-x | provider/include/download-provider-da-interface.h | 29 | ||||
-rwxr-xr-x | provider/include/download-provider-db.h | 243 | ||||
-rwxr-xr-x | provider/include/download-provider-defs.h | 93 | ||||
-rwxr-xr-x | provider/include/download-provider-log.h | 58 | ||||
-rwxr-xr-x | provider/include/download-provider-network.h | 34 | ||||
-rwxr-xr-x | provider/include/download-provider-notification.h | 27 | ||||
-rwxr-xr-x | provider/include/download-provider-pthread.h | 96 | ||||
-rwxr-xr-x | provider/include/download-provider-queue.h | 23 | ||||
-rwxr-xr-x | provider/include/download-provider-request.h | 58 | ||||
-rwxr-xr-x | provider/include/download-provider-slots.h | 90 | ||||
-rwxr-xr-x | provider/include/download-provider-socket.h | 43 | ||||
-rwxr-xr-x | provider/include/download-provider.h | 120 |
13 files changed, 960 insertions, 0 deletions
diff --git a/provider/include/download-provider-config.h b/provider/include/download-provider-config.h new file mode 100755 index 0000000..96862ec --- /dev/null +++ b/provider/include/download-provider-config.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef DOWNLOAD_PROVIDER2_CONFIG_H +#define DOWNLOAD_PROVIDER2_CONFIG_H + +#include <download-provider.h> +#include <download-provider-slots.h> + +#include <net_connection.h> + +#define DP_LOCK_PID "/tmp/download-provider.lock" + +#define DP_CARE_CLIENT_MIN_INTERVAL 5 +#define DP_CARE_CLIENT_MAX_INTERVAL 120 + +// check this value should be lower than DP_MAX_REQUEST +#define DP_MAX_DOWNLOAD_AT_ONCE 50 + +#define DP_LOG_DB_LIMIT_ROWS 1000 +#define DP_LOG_DB_CLEAR_LIMIT_ONE_TIME 100 + +// Share the structure for all threads +typedef struct { + int listen_fd; + int is_connected_wifi_direct; + connection_h connection; + dp_network_type network_status; + dp_group_slots *groups; + dp_request_slots *requests; +} dp_privates; + +#endif diff --git a/provider/include/download-provider-da-interface.h b/provider/include/download-provider-da-interface.h new file mode 100755 index 0000000..ab6e716 --- /dev/null +++ b/provider/include/download-provider-da-interface.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef DOWNLOAD_PROVIDER2_DA_INTERFACE_H +#define DOWNLOAD_PROVIDER2_DA_INTERFACE_H + +int dp_is_file_exist(const char *file_path); +int dp_init_agent(); +void dp_deinit_agent(); +dp_error_type dp_start_agent_download(dp_request_slots *request); +dp_error_type dp_resume_agent_download(int req_id); +dp_error_type dp_pause_agent_download(int req_id); +dp_error_type dp_cancel_agent_download(int req_id); +int dp_is_alive_download(int req_id); + +#endif diff --git a/provider/include/download-provider-db.h b/provider/include/download-provider-db.h new file mode 100755 index 0000000..24a7d27 --- /dev/null +++ b/provider/include/download-provider-db.h @@ -0,0 +1,243 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef DOWNLOAD_PROVIDER2_DB_H +#define DOWNLOAD_PROVIDER2_DB_H + +#include "download-provider-config.h" +#include "download-provider-slots.h" + +/* + * Memory ( sync with logging ) : id, state, errorcode, startcount, packagename + * DB TABLES + * logging : id, state, errorcode, startcount, createtime, accesstime, packagename + * requestinfo : id, auto_download, network_type, filename, destination, url + * downloadinfo : id, http_status, content_size, mimetype, contentname, saved_path, tmp_saved_path, etag + * httpheaders : id, header_field, header_data + * notification : id, noti_enable, extra_key, extra_data + */ +/* +CREATE TABLE IF NOT EXISTS groups +( + id INTEGER UNIQUE PRIMARY KEY, + uid INTEGER DEFAULT 0, + gid INTEGER DEFAULT 0, + extra_int INTEGER DEFAULT 0, + packagename TEXT DEFAULT NULL, + smack_label TEXT DEFAULT NULL, + extra TEXT DEFAULT NULL, + date_first_connected DATE, + date_last_connected DATE +); + +CREATE TABLE logging +( + id INTEGER UNIQUE PRIMARY KEY, + state INTEGER DEFAULT 0, + errorcode INTEGER DEFAULT 0, + startcount INTEGER DEFAULT 0, + packagename TEXT DEFAULT NULL, + createtime DATE, + accesstime DATE +); + +CREATE TABLE requestinfo +( + id INTEGER UNIQUE PRIMARY KEY, + auto_download BOOLEAN DEFAULT 0, + state_event BOOLEAN DEFAULT 0, + progress_event BOOLEAN DEFAULT 0, + network_type TINYINT DEFAULT 0, + filename TEXT DEFAULT NULL, + destination TEXT DEFAULT NULL, + url TEXT DEFAULT NULL, + FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE +); + +CREATE TABLE downloadinfo +( + id INTEGER UNIQUE PRIMARY KEY, + http_status INTEGER DEFAULT 0, + content_size UNSIGNED BIG INT DEFAULT 0, + mimetype VARCHAR(64) DEFAULT NULL, + content_name TEXT DEFAULT NULL, + saved_path TEXT DEFAULT NULL, + tmp_saved_path TEXT DEFAULT NULL, + etag TEXT DEFAULT NULL, + FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE +); + +CREATE TABLE httpheaders +( + id INTEGER NOT NULL, + header_field TEXT DEFAULT NULL, + header_data TEXT DEFAULT NULL, + FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE +); + +CREATE TABLE notification +( + id INTEGER UNIQUE PRIMARY KEY, + noti_enable BOOLEAN DEFAULT 0, + extra_key TEXT DEFAULT NULL, + extra_data TEXT DEFAULT NULL, + FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE +); + +CREATE UNIQUE INDEX requests_index ON logging (id, state, errorcode, packagename, createtime, accesstime); +*/ + +#define DP_DB_TABLE_GROUPS "groups" +#define DP_DB_TABLE_LOG "logging" +#define DP_DB_TABLE_REQUEST_INFO "requestinfo" +#define DP_DB_TABLE_DOWNLOAD_INFO "downloadinfo" +#define DP_DB_TABLE_HTTP_HEADERS "httpheaders" +#define DP_DB_TABLE_NOTIFICATION "notification" + +#define DP_DB_COL_ID "id" +#define DP_DB_COL_STATE "state" +#define DP_DB_COL_ERRORCODE "errorcode" +#define DP_DB_COL_NETWORK_TYPE "network_type" +#define DP_DB_COL_HTTP_STATUS "http_status" +#define DP_DB_COL_AUTO_DOWNLOAD "auto_download" +#define DP_DB_COL_STATE_EVENT "state_event" +#define DP_DB_COL_PROGRESS_EVENT "progress_event" +#define DP_DB_COL_CONTENT_SIZE "content_size" +#define DP_DB_COL_CREATE_TIME "createtime" +#define DP_DB_COL_ACCESS_TIME "accesstime" +#define DP_DB_COL_STARTCOUNT "startcount" +#define DP_DB_COL_PACKAGENAME "packagename" +#define DP_DB_COL_DESTINATION "destination" +#define DP_DB_COL_FILENAME "filename" +#define DP_DB_COL_CONTENT_NAME "content_name" +#define DP_DB_COL_MIMETYPE "mimetype" +#define DP_DB_COL_ETAG "etag" +#define DP_DB_COL_SAVED_PATH "saved_path" +#define DP_DB_COL_TMP_SAVED_PATH "tmp_saved_path" +#define DP_DB_COL_URL "url" +#define DP_DB_COL_HEADER_FIELD "header_field" +#define DP_DB_COL_HEADER_DATA "header_data" +#define DP_DB_COL_NOTIFICATION_ENABLE "noti_enable" +#define DP_DB_COL_EXTRA_KEY "extra_key" +#define DP_DB_COL_DISTINCT_EXTRA_KEY "DISTINCT extra_key" +#define DP_DB_COL_EXTRA_VALUE "extra_data" +#define DP_DB_COL_RAW_BUNDLE_ONGOING "raw_bundle_data_ongoing_state" +#define DP_DB_COL_RAW_BUNDLE_COMPLETE "raw_bundle_data_complete_state" +#define DP_DB_COL_RAW_BUNDLE_FAIL "raw_bundle_data_fail_state" +#define DP_DB_COL_TITLE "title" +#define DP_DB_COL_DESCRIPTION "description" +#define DP_DB_COL_NOTI_TYPE "noti_type" + +#define DP_DB_GROUPS_COL_UID "uid" +#define DP_DB_GROUPS_COL_GID "gid" +#define DP_DB_GROUPS_COL_PKG "packagename" +#define DP_DB_GROUPS_COL_SMACK_LABEL "smack_label" + + +typedef enum { + DP_DB_COL_TYPE_NONE = 0, + DP_DB_COL_TYPE_INT = 10, + DP_DB_COL_TYPE_INT64 = 20, + DP_DB_COL_TYPE_TEXT = 30 +} db_column_data_type; + +typedef struct { + char *column; + db_column_data_type type; + int is_like; + void *value; +} db_conds_list_fmt; + +int dp_db_open(); +void dp_db_close(); + +int dp_db_is_full_error(); + +int dp_db_remove_all(int id); +int dp_db_remove(int id, char *table); +int dp_db_insert_column(int id, char *table, char *column, + db_column_data_type datatype, void *value); +int dp_db_insert_blob_column(int id, char *table, char *column, + void *value, unsigned length); +int dp_db_set_column(int id, char *table, char *column, + db_column_data_type datatype, void *value); +int dp_db_set_blob_column(int id, char *table, char *column, + void *value, unsigned length); +int dp_db_replace_column(int id, char *table, char *column, + db_column_data_type datatype, void *value); +int dp_db_replace_blob_column(int id, char *table, char *column, + void *value, unsigned length); +char *dp_db_get_text_column(int id, char *table, char *column); +void *dp_db_get_blob_column(int id, char *table, char *column, int *length); +int dp_db_get_int_column(int id, char *table, char *column); +long long dp_db_get_int64_column(int id, char *table, char *column); +int dp_db_update_date(int id, char *table, char *column); + +// cond : id & cond +int dp_db_cond_set_column(int id, char *table, char *column, + db_column_data_type datatype, void *value, + char *condcolumn, db_column_data_type condtype, + void *condvalue); +char *dp_db_cond_get_text_column(int id, char *table, char *column, + char *condcolumn, db_column_data_type condtype, + void *condvalue); +int dp_db_cond_remove(int id, char *table, + char *condcolumn, db_column_data_type condtype, + void *condvalue); +int dp_db_get_cond_rows_count(int id, char *table, + char *condcolumn, db_column_data_type condtype, + void *condvalue); + +char *dp_db_cond_get_text(char *table, char *column, char *condcolumn, + db_column_data_type condtype, void *condvalue); +int dp_db_cond_get_int(char *table, char *column, char *condcolumn, + db_column_data_type condtype, void *condvalue); + +// Special API for http headers +int dp_db_get_http_headers_list(int id, char **headers); + +// For auto-download in booting time +int dp_db_crashed_list(dp_request_slots *requests, int limit); + +// For loading to memory when no in memory +dp_request *dp_db_load_logging_request(int id); + +// For limitation by 48 hours & 1000 rows +int dp_db_limit_rows(int limit); +int dp_db_get_count_by_limit_time(); +int dp_db_get_list_by_limit_time(dp_request_slots *requests, int limit); + +int dp_db_insert_columns(char *table, int column_count, + db_conds_list_fmt *columns); +int dp_db_update_columns(int id, char *table, int column_count, + db_conds_list_fmt *columns); + +int dp_db_get_conds_rows_count(char *table, char *getcolumn, char *op, + int conds_count, db_conds_list_fmt *conds); + +int dp_db_get_conds_list(char *table, char *getcolumn, + db_column_data_type gettype, void **list, + int rowslimit, int rowsoffset, + char *ordercolumn, char *ordering, + char *op, int conds_count, + db_conds_list_fmt *conds); + +int dp_db_request_new_logging(const int id, const int state, const char *pkgname); +int dp_db_request_update_status(const int id, const int state, const int download_error); +int dp_db_get_state(int id); +int dp_db_request_new_logging(const int id, + const int state, const char *pkgname); +#endif diff --git a/provider/include/download-provider-defs.h b/provider/include/download-provider-defs.h new file mode 100755 index 0000000..af166fd --- /dev/null +++ b/provider/include/download-provider-defs.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef DOWNLOAD_PROVIDER_DEFS_H +#define DOWNLOAD_PROVIDER_DEFS_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + DP_STATE_NONE = 0, + DP_STATE_READY = DP_STATE_NONE + 5, // created id, set some info. + DP_STATE_QUEUED = DP_STATE_NONE + 10, // request to start + DP_STATE_CONNECTING = DP_STATE_NONE + 15, // try to connect to url + DP_STATE_DOWNLOADING = DP_STATE_NONE + 20, // started + DP_STATE_PAUSE_REQUESTED = DP_STATE_NONE + 25, + DP_STATE_PAUSED = DP_STATE_NONE + 30, // paused actually + DP_STATE_COMPLETED = DP_STATE_NONE + 40, + DP_STATE_CANCELED = DP_STATE_NONE + 45, // stopped with error + DP_STATE_FAILED = DP_STATE_NONE + 50 // failed with error +} dp_state_type; + +typedef enum { + DP_ERROR_NONE = 10, + DP_ERROR_INVALID_PARAMETER = DP_ERROR_NONE + 1, + DP_ERROR_OUT_OF_MEMORY = DP_ERROR_NONE + 2, + DP_ERROR_IO_ERROR = DP_ERROR_NONE + 3, + DP_ERROR_NETWORK_UNREACHABLE = DP_ERROR_NONE + 4, + DP_ERROR_CONNECTION_TIMED_OUT = DP_ERROR_NONE + 5, + DP_ERROR_NO_SPACE = DP_ERROR_NONE + 6, + DP_ERROR_FIELD_NOT_FOUND = DP_ERROR_NONE + 7, + DP_ERROR_INVALID_STATE = DP_ERROR_NONE + 8, + DP_ERROR_CONNECTION_FAILED = DP_ERROR_NONE + 9, + DP_ERROR_INVALID_URL = DP_ERROR_NONE + 10, + DP_ERROR_INVALID_DESTINATION = DP_ERROR_NONE + 11, + DP_ERROR_QUEUE_FULL = DP_ERROR_NONE + 12, + DP_ERROR_ALREADY_COMPLETED = DP_ERROR_NONE + 13, + DP_ERROR_FILE_ALREADY_EXISTS = DP_ERROR_NONE + 14, + DP_ERROR_TOO_MANY_DOWNLOADS = DP_ERROR_NONE + 15, + DP_ERROR_NO_DATA = DP_ERROR_NONE + 17, + DP_ERROR_UNHANDLED_HTTP_CODE = DP_ERROR_NONE + 18, + DP_ERROR_CANNOT_RESUME = DP_ERROR_NONE + 19, + DP_ERROR_PERMISSION_DENIED = DP_ERROR_NONE + 20, + DP_ERROR_RESPONSE_TIMEOUT = DP_ERROR_NONE + 50, + DP_ERROR_REQUEST_TIMEOUT = DP_ERROR_NONE + 55, + DP_ERROR_SYSTEM_DOWN = DP_ERROR_NONE + 60, + DP_ERROR_CLIENT_DOWN = DP_ERROR_NONE + 65, + DP_ERROR_ID_NOT_FOUND = DP_ERROR_NONE + 90, + DP_ERROR_IO_EAGAIN = DP_ERROR_NONE + 97, + DP_ERROR_IO_EINTR = DP_ERROR_NONE + 98, + DP_ERROR_IO_TIMEOUT = DP_ERROR_NONE + 99, + DP_ERROR_UNKNOWN = DP_ERROR_NONE + 100 +} dp_error_type; + +typedef enum { + DP_NETWORK_TYPE_OFF = -1, + DP_NETWORK_TYPE_ALL = 0, + DP_NETWORK_TYPE_WIFI = 1, + DP_NETWORK_TYPE_DATA_NETWORK = 2, + DP_NETWORK_TYPE_ETHERNET = 3, + DP_NETWORK_TYPE_WIFI_DIRECT = 4 +} dp_network_type; + +typedef enum { + DP_NOTIFICATION_BUNDLE_TYPE_ONGOING = 0, // Ongoing, Failed + DP_NOTIFICATION_BUNDLE_TYPE_COMPLETE, // Completed + DP_NOTIFICATION_BUNDLE_TYPE_FAILED // Failed +} dp_notification_bundle_type; + +typedef enum { + DP_NOTIFICATION_TYPE_NONE = 0, // Not register Noti. + DP_NOTIFICATION_TYPE_COMPLETE_ONLY, // Success, Failed + DP_NOTIFICATION_TYPE_ALL // Ongoing, Success, Failed +} dp_notification_type; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/provider/include/download-provider-log.h b/provider/include/download-provider-log.h new file mode 100755 index 0000000..e828905 --- /dev/null +++ b/provider/include/download-provider-log.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef DOWNLOAD_PROVIDER2_LOG_H +#define DOWNLOAD_PROVIDER2_LOG_H + +#ifdef SUPPORT_LOG_MESSAGE +#include <errno.h> +#include <dlog.h> +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "DOWNLOAD_PROVIDER" +#define TRACE_DEBUG(format, ARG...) LOGD(format, ##ARG) +#define TRACE_ERROR(format, ARG...) LOGE(format, ##ARG) +#define TRACE_STRERROR(format, ARG...) LOGE(format" [%s]", ##ARG, strerror(errno)) +#define TRACE_INFO(format, ARG...) LOGI(format, ##ARG) + +#ifdef SECURE_LOGD +#define TRACE_SECURE_DEBUG(format, ARG...) SECURE_LOGD(format, ##ARG) +#else +#define TRACE_SECURE_DEBUG(...) do { } while(0) +#endif +#ifdef SECURE_LOGI +#define TRACE_SECURE_INFO(format, ARG...) SECURE_LOGI(format, ##ARG) +#else +#define TRACE_SECURE_INFO(...) do { } while(0) +#endif +#ifdef SECURE_LOGE +#define TRACE_SECURE_ERROR(format, ARG...) SECURE_LOGE(format, ##ARG) +#else +#define TRACE_SECURE_ERROR(...) do { } while(0) +#endif + +#else +#define TRACE_DEBUG(...) do { } while(0) +#define TRACE_ERROR(...) do { } while(0) +#define TRACE_STRERROR(...) do { } while(0) +#define TRACE_INFO(...) do { } while(0) +#define TRACE_SECURE_DEBUG(...) do { } while(0) +#define TRACE_SECURE_INFO(...) do { } while(0) +#define TRACE_SECURE_ERROR(...) do { } while(0) +#endif + +#endif diff --git a/provider/include/download-provider-network.h b/provider/include/download-provider-network.h new file mode 100755 index 0000000..98a9b43 --- /dev/null +++ b/provider/include/download-provider-network.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef DOWNLOAD_PROVIDER2_NETWORK_H +#define DOWNLOAD_PROVIDER2_NETWORK_H + +#include <net_connection.h> + +#include "download-provider.h" + +dp_network_type dp_get_network_connection_status(connection_h connection, connection_type_e type); +void dp_network_connection_type_changed_cb(connection_type_e type, void *data); +int dp_network_connection_init(dp_privates *privates); +void dp_network_connection_destroy(connection_h connection); +dp_network_type dp_get_network_connection_instant_status(); + +#ifdef SUPPORT_WIFI_DIRECT +int dp_network_wifi_direct_is_connected(); +#endif + +#endif diff --git a/provider/include/download-provider-notification.h b/provider/include/download-provider-notification.h new file mode 100755 index 0000000..5a9f5b9 --- /dev/null +++ b/provider/include/download-provider-notification.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef DOWNLOAD_PROVIDER2_NOTIFICATION_H +#define DOWNLOAD_PROVIDER2_NOTIFICATION_H + +#include "download-provider-config.h" + +int dp_set_downloadinginfo_notification(int id, char *packagename); +int dp_set_downloadedinfo_notification(int priv_id, int id, char *packagename, dp_state_type state); +void dp_update_downloadinginfo_notification(int priv_id, double received_size, double file_size); +void dp_clear_downloadinginfo_notification(void); + +#endif diff --git a/provider/include/download-provider-pthread.h b/provider/include/download-provider-pthread.h new file mode 100755 index 0000000..8c02c59 --- /dev/null +++ b/provider/include/download-provider-pthread.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef DOWNLOAD_PROVIDER2_PTHREAD_H +#define DOWNLOAD_PROVIDER2_PTHREAD_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <unistd.h> +#include <pthread.h> +#include <errno.h> + +// download-provider use default style mutex. + +#define CLIENT_MUTEX_LOCK(mutex_add) {\ + int ret = 0;\ + ret = pthread_mutex_lock(mutex_add);\ + if (EINVAL == ret) {\ + TRACE_STRERROR("ERR:pthread_mutex_lock FAIL with EINVAL.");\ + } else if (EDEADLK == ret) {\ + TRACE_STRERROR("ERR:pthread_mutex_lock FAIL with EDEADLK.");\ + } else if (ret != 0) {\ + TRACE_STRERROR("ERR:pthread_mutex_lock FAIL with %d.", ret);\ + } \ +} + +#define CLIENT_MUTEX_UNLOCK(mutex_add) {\ + int ret = 0;\ + ret = pthread_mutex_unlock(mutex_add);\ + if (EINVAL == ret) {\ + TRACE_STRERROR("ERR:pthread_mutex_unlock FAIL with EINVAL.");\ + } else if (EDEADLK == ret) {\ + TRACE_STRERROR("ERR:pthread_mutex_unlock FAIL with EDEADLK.");\ + } else if (ret != 0) {\ + TRACE_STRERROR("ERR:pthread_mutex_unlock FAIL with %d.", ret);\ + } \ +} + +#define CLIENT_MUTEX_DESTROY(mutex_add) { \ + int ret = 0; \ + ret = pthread_mutex_destroy(mutex_add); \ + if(EINVAL == ret) {\ + TRACE_STRERROR("ERR:pthread_mutex_destroy FAIL with EINVAL."); \ + } else if(ENOMEM == ret) {\ + TRACE_STRERROR("ERR:pthread_mutex_destroy FAIL with ENOMEM."); \ + } else if(EBUSY == ret) {\ + TRACE_STRERROR("ERR:pthread_mutex_destroy FAIL with EBUSY."); \ + if (pthread_mutex_unlock(mutex_add) == 0) \ + pthread_mutex_destroy(mutex_add); \ + } else if (ret != 0) {\ + TRACE_STRERROR("ERR:pthread_mutex_destroy FAIL with %d.", ret); \ + } \ +} + +#define CLIENT_MUTEX_INIT(mutex_add, attr) { \ + int ret = 0; \ + unsigned retry = 3; \ + while (retry > 0) { \ + ret = pthread_mutex_init(mutex_add, attr); \ + if (0 == ret) { \ + break; \ + } else if(EINVAL == ret) { \ + TRACE_STRERROR("ERR:pthread_mutex_init FAIL with EINVAL."); \ + } else if(ENOMEM == ret) { \ + TRACE_STRERROR("ERR:pthread_mutex_init FAIL with ENOMEM."); \ + usleep(1000); \ + } else if(EBUSY == ret) {\ + TRACE_STRERROR("ERR:pthread_mutex_destroy FAIL with EBUSY."); \ + if (pthread_mutex_unlock(mutex_add) == 0) \ + pthread_mutex_destroy(mutex_add); \ + } else if (ret != 0) { \ + TRACE_STRERROR("ERR:pthread_mutex_init FAIL with %d.", ret); \ + } \ + retry--; \ + } \ +} + +#ifdef __cplusplus +} +#endif +#endif diff --git a/provider/include/download-provider-queue.h b/provider/include/download-provider-queue.h new file mode 100755 index 0000000..71bb62b --- /dev/null +++ b/provider/include/download-provider-queue.h @@ -0,0 +1,23 @@ +/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+
+#ifndef DOWNLOAD_PROVIDER2_QUEUE_H
+#define DOWNLOAD_PROVIDER2_QUEUE_H
+
+void dp_thread_queue_manager_wake_up();
+void *dp_thread_queue_manager(void *arg);
+
+#endif
diff --git a/provider/include/download-provider-request.h b/provider/include/download-provider-request.h new file mode 100755 index 0000000..bc26953 --- /dev/null +++ b/provider/include/download-provider-request.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef DOWNLOAD_PROVIDER2_REQUEST_H +#define DOWNLOAD_PROVIDER2_REQUEST_H + +#include "download-provider.h" +#include <bundle.h> + +// for Debugging +char *dp_print_state(dp_state_type state); +char *dp_print_errorcode(dp_error_type errorcode); + +int dp_is_smackfs_mounted(void); +char *dp_strdup(char *src); + +dp_error_type dp_request_create(int id, dp_client_group *group, dp_request** empty_slot); +dp_error_type dp_request_set_url(int id, dp_request *request, char *url); +dp_error_type dp_request_set_destination(int id, dp_request *request, char *dest); +dp_error_type dp_request_set_filename(int id, dp_request *request, char *filename); +dp_error_type dp_request_set_title(int id, dp_request *request, char *filename); +dp_error_type dp_request_set_bundle(int id, dp_request *request, int type, bundle_raw *b, unsigned length); +dp_error_type dp_request_set_description(int id, dp_request *request, char *description); +dp_error_type dp_request_set_noti_type(int id, dp_request *request, unsigned type); +dp_error_type dp_request_set_notification(int id, dp_request *request, unsigned enable); +dp_error_type dp_request_set_auto_download(int id, dp_request *request, unsigned enable); +dp_error_type dp_request_set_state_event(int id, dp_request *request, unsigned enable); +dp_error_type dp_request_set_progress_event(int id, dp_request *request, unsigned enable); +dp_error_type dp_request_set_network_type(int id, dp_request *request, int type); +char *dp_request_get_url(int id, dp_error_type *errorcode); +char *dp_request_get_destination(int id, dp_request *request, dp_error_type *errorcode); +char *dp_request_get_filename(int id, dp_request *request, dp_error_type *errorcode); +char *dp_request_get_title(int id, dp_request *request, dp_error_type *errorcode); +bundle_raw *dp_request_get_bundle(int id, dp_request *request, dp_error_type *errorcode, char* column, int* length); +char *dp_request_get_description(int id, dp_request *request, dp_error_type *errorcode); +int dp_request_get_noti_type(int id, dp_request *request, dp_error_type *errorcode); +char *dp_request_get_contentname(int id, dp_request *request, dp_error_type *errorcode); +char *dp_request_get_etag(int id, dp_request *request, dp_error_type *errorcode); +char *dp_request_get_savedpath(int id, dp_request *request, dp_error_type *errorcode); +char *dp_request_get_tmpsavedpath(int id, dp_request *request, dp_error_type *errorcode); +char *dp_request_get_mimetype(int id, dp_request *request, dp_error_type *errorcode); +char *dp_request_get_pkg_name(int id, dp_request *request, dp_error_type *errorcode); +dp_request *dp_request_load_from_log(int id, dp_error_type *errorcode); +void dp_request_state_response(dp_request *request); +#endif diff --git a/provider/include/download-provider-slots.h b/provider/include/download-provider-slots.h new file mode 100755 index 0000000..53859f8 --- /dev/null +++ b/provider/include/download-provider-slots.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef DOWNLOAD_PROVIDER2_SLOTS_H +#define DOWNLOAD_PROVIDER2_SLOTS_H + +#include "download-provider.h" +#include "download-provider-pthread.h" + +// Backgound Daemon should has the limitation of resource. +#define DP_MAX_GROUP 15 +#define DP_MAX_REQUEST 64 + +typedef struct { + pid_t pid; + uid_t uid; + gid_t gid; +} dp_credential; + +typedef struct { + // send command * get return value. + int cmd_socket; + // send event to client + int event_socket; + unsigned queued_count; // start ++, finish or failed -- ( queue & active ) + // fill by app-manager + char *pkgname; + dp_credential credential; + char *smack_label; +} dp_client_group; + +typedef struct { + int id; // ID created in create request in requests thread. + int agent_id; + int create_time; + int start_time; // setted by START command + int pause_time; // setted by PAUSE command + int stop_time; // time setted by finished_cb + int noti_priv_id; + unsigned state_cb; // set : 1 unset : 0 + unsigned progress_cb; // set : 1 unset : 0 + unsigned startcount; + unsigned auto_notification; + unsigned ip_changed; + dp_state_type state; // downloading state + dp_error_type error; + dp_network_type network_type; + size_t progress_lasttime; + unsigned long long received_size; // progress + unsigned long long file_size; + char *packagename; + dp_client_group *group; // indicate dp_client_group included this request +} dp_request; + +typedef struct { + dp_client_group *group; +} dp_group_slots; + +typedef struct { + pthread_mutex_t mutex; + dp_request *request; +} dp_request_slots; + + +// functions +dp_group_slots *dp_client_group_slots_new(int size); +dp_request_slots *dp_request_slots_new(int size); +int dp_client_group_free(dp_client_group *group); +int dp_client_group_slots_free(dp_group_slots *slots, int size); +dp_request *dp_request_new(); +void dp_request_init(dp_request *request); +int dp_request_free(dp_request *request); +int dp_request_slot_free(dp_request_slots *request_slot); +int dp_request_slots_free(dp_request_slots *slots, int size); +int dp_get_request_count(dp_request_slots *slots); + +#endif diff --git a/provider/include/download-provider-socket.h b/provider/include/download-provider-socket.h new file mode 100755 index 0000000..b5a37cb --- /dev/null +++ b/provider/include/download-provider-socket.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef DOWNLOAD_PROVIDER2_SOCKET_H +#define DOWNLOAD_PROVIDER2_SOCKET_H + +#include <bundle.h> +#include "download-provider.h" +#include "download-provider-slots.h" + +int dp_ipc_send_errorcode(int fd, dp_error_type errorcode); +int dp_ipc_send_event(int fd, int id, dp_state_type state, + dp_error_type errorcode, unsigned long long received_size); +#if 0 +int dp_ipc_send_progressinfo(int fd, int id, + unsigned long long received_size, unsigned long long file_size, + unsigned int chunk_size); +int dp_ipc_send_stateinfo(int fd, int id, dp_state_type state, + dp_error_type errorcode); +#endif +char *dp_ipc_read_string(int fd); +unsigned dp_ipc_read_bundle(int fd, int *type, bundle_raw **b); +int dp_ipc_send_string(int fd, const char *str); +int dp_ipc_send_bundle(int fd, bundle_raw *b, unsigned length); +int dp_ipc_send_custom_type(int fd, void *value, size_t type_size); +int dp_ipc_read_custom_type(int fd, void *value, size_t type_size); +int dp_accept_socket_new(); +int dp_socket_free(int sockfd); + +#endif diff --git a/provider/include/download-provider.h b/provider/include/download-provider.h new file mode 100755 index 0000000..a1f22f3 --- /dev/null +++ b/provider/include/download-provider.h @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef DOWNLOAD_PROVIDER2_H +#define DOWNLOAD_PROVIDER2_H + +#include "download-provider-defs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define DP_IPC "/tmp/download-provider" + +#define DP_MAX_STR_LEN_64 64 +#define DP_MAX_STR_LEN 256 +#define DP_MAX_PATH_LEN DP_MAX_STR_LEN +#define DP_MAX_URL_LEN 2048 +#define DP_DEFAULT_BUFFER_SIZE 1024 + +typedef enum { + DP_CMD_NONE = 0, + DP_CMD_ECHO, + DP_CMD_CREATE, + DP_CMD_START, + DP_CMD_SET_COMMAND_SOCKET, + DP_CMD_SET_EVENT_SOCKET, + DP_CMD_FREE, + + DP_CMD_ACTION_SECT = 100, + DP_CMD_PAUSE, + DP_CMD_CANCEL, + DP_CMD_DESTROY, + + DP_CMD_GET_SECT = 200, + DP_CMD_GET_URL, + DP_CMD_GET_DESTINATION, + DP_CMD_GET_FILENAME, + DP_CMD_GET_NOTIFICATION, + DP_CMD_GET_STATE_CALLBACK, + DP_CMD_GET_PROGRESS_CALLBACK, + DP_CMD_GET_HTTP_HEADERS, + DP_CMD_GET_AUTO_DOWNLOAD, + DP_CMD_GET_NETWORK_TYPE, + DP_CMD_GET_SAVED_PATH, + DP_CMD_GET_TEMP_SAVED_PATH, + DP_CMD_GET_MIME_TYPE, + DP_CMD_GET_HTTP_HEADER, + DP_CMD_GET_HTTP_HEADER_LIST, + DP_CMD_GET_EXTRA_PARAM, + DP_CMD_GET_RECEIVED_SIZE, + DP_CMD_GET_TOTAL_FILE_SIZE, + DP_CMD_GET_CONTENT_NAME, + DP_CMD_GET_HTTP_STATUS, + DP_CMD_GET_ETAG, + DP_CMD_GET_STATE, + DP_CMD_GET_ERROR, + DP_CMD_GET_NOTIFICATION_BUNDLE, + DP_CMD_GET_NOTIFICATION_TITLE, + DP_CMD_GET_NOTIFICATION_DESCRIPTION, + DP_CMD_GET_NOTIFICATION_TYPE, + + DP_CMD_SET_SECT = 300, + DP_CMD_SET_URL, + DP_CMD_SET_DESTINATION, + DP_CMD_SET_FILENAME, + DP_CMD_SET_NOTIFICATION, + DP_CMD_SET_STATE_CALLBACK, + DP_CMD_SET_PROGRESS_CALLBACK, + DP_CMD_SET_AUTO_DOWNLOAD, + DP_CMD_SET_NETWORK_TYPE, + DP_CMD_SET_HTTP_HEADER, + DP_CMD_SET_EXTRA_PARAM, // prevent build error + DP_CMD_DEL_HTTP_HEADER, + DP_CMD_ADD_EXTRA_PARAM, + DP_CMD_REMOVE_EXTRA_PARAM, + DP_CMD_SET_NOTIFICATION_BUNDLE, + DP_CMD_SET_NOTIFICATION_TITLE, + DP_CMD_SET_NOTIFICATION_DESCRIPTION, + DP_CMD_SET_NOTIFICATION_TYPE, + + DP_CMD_LAST_SECT = 400 +} dp_command_type; + +typedef struct { + unsigned int length; + char *str; +} dp_string; + +typedef struct { + int id; + dp_state_type state; + dp_error_type err; + unsigned long long received_size; +} dp_event_info; + +typedef struct { + dp_command_type cmd; + int id; +} dp_command; + + // Usage IPC : send(dp_command);send(dp_string); + +#ifdef __cplusplus +} +#endif +#endif |