%if 0%{?sec_product_feature_profile_wearable}
BuildRequires: pkgconfig(capi-base-common)
BuildRequires: pkgconfig(capi-appfw-service-application)
+BuildRequires: pkgconfig(capi-message-port)
BuildRequires: pkgconfig(sap-client-stub-api)
BuildRequires: hash-signer
src/main.cpp
src/ft.cpp
src/sticker_info.cpp
+ src/message.cpp
)
INCLUDE(FindPkgConfig)
capi-base-common
dlog
capi-appfw-service-application
+ capi-message-port
sap-client-stub-api
json-glib-1.0
)
--- /dev/null
+/*
+ * Copyright (c) 2020 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.
+ */
+#include <glib.h>
+#include <message_port.h>
+
+#ifndef __MESSAGE_H__
+#define __MESSAGE_H__
+
+bool message_sink_init(message_port_message_cb callback, void *user_data);
+void message_sink_shutdown(void);
+bool send_message(const char *cmd, const char *data);
+
+#endif /* __MESSAGE_H__ */
#include "ft.h"
#include "log.h"
#include "sticker_info.h"
+#include "message.h"
#define ACCESSORY_SERVICE_PROFILE_ID "/sample/filetransfersender"
#define ACCESSORY_SERVICE_CHANNEL_ID 107
static string incoming_file_name;
static int t_id = 0;
static int rec_file_cnt = 0;
+static int total_file_count = 0;
static gboolean _send_json_data(JsonObject *obj)
{
return result ? FALSE : TRUE;
}
+static void notify_sync_progress(unsigned int file_progress)
+{
+ if (total_file_count == 0)
+ return;
+
+ double total_progress = (((double)rec_file_cnt / (double)total_file_count) + (1.0/(double)total_file_count*file_progress/100))*100;
+
+ LOGI("recv : %d, total : %d, file_progress : %d, %u%%", rec_file_cnt, total_file_count, file_progress, (unsigned int)total_progress);
+ char progress_str[32];
+ snprintf(progress_str, sizeof(progress_str), "%u", (unsigned int)total_progress);
+ send_message("sync_progress", progress_str);
+}
+
static void _on_send_completed(sap_file_transaction_h file_transaction,
sap_ft_transfer_e result,
const char *file_path,
void *user_data)
{
LOGI("# progress %d", percentage_progress);
+ notify_sync_progress(percentage_progress);
}
static void __set_file_transfer_cb(sap_file_transaction_h file_socket)
LOGD("result : %s, resultCode : %d", result.c_str(), result_code);
} else if (msg_id == STICKER_SEND_START_REQ) {
LOGD("msg : %s", msg_id.c_str());
+ total_file_count = 0;
rec_file_cnt = 0;
t_id = json_object_get_int_member(root_obj, "tID");
JsonArray *file_list = json_object_get_array_member(root_obj, "list");
if (file_len > 0) {
LOGD("fileName : %s, len : %d", file_name.c_str(), file_len);
+ total_file_count++;
} else {
// Delete sticker
LOGD("fileName : %s, len : %d", file_name.c_str(), file_len);
--- /dev/null
+/*
+ * Copyright (c) 2020 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.
+ */
+
+#include <stdlib.h>
+
+#include "message.h"
+#include "log.h"
+
+#define REMOTE_APP_ID "com.samsung.w-input-selector"
+#define MESSAGE_PORT_REMOTE_NAME REMOTE_APP_ID"_msg_port_rcv"
+
+static int port_id = -1;
+
+bool message_sink_init(message_port_message_cb callback, void *user_data)
+{
+ port_id = message_port_register_local_port(MESSAGE_PORT_REMOTE_NAME, callback, user_data);
+ if (port_id < 0)
+ {
+ LOGW("Function message_port_register_local_port() failed.");
+ return false;
+ }
+
+ return true;
+}
+
+void message_sink_shutdown(void)
+{
+ int ret;
+ bool exists = false;
+
+ port_id = -1;
+
+ ret = message_port_check_remote_port(REMOTE_APP_ID, MESSAGE_PORT_REMOTE_NAME, &exists);
+ if (exists)
+ {
+ ret = message_port_unregister_local_port(port_id);
+ if (ret != MESSAGE_PORT_ERROR_NONE)
+ LOGE("Function message_port_unregister_local_port() failed.");
+ }
+ else if (ret != MESSAGE_PORT_ERROR_NONE)
+ {
+ LOGE("Function message_port_check_remote_port() failed.");
+ }
+}
+
+bool send_message(const char *cmd, const char *data)
+{
+ bool result = false;
+ int ret;
+ bool found = false;
+
+ message_port_check_remote_port(REMOTE_APP_ID, MESSAGE_PORT_REMOTE_NAME, &found);
+ if (!found) {
+ LOGW("Can't find remote port");
+ return false;
+ }
+
+ bundle *b = bundle_create();
+ bundle_add_str(b, "command", cmd);
+ bundle_add_str(b, "data", data);
+ ret = message_port_send_message(REMOTE_APP_ID, MESSAGE_PORT_REMOTE_NAME, b);
+ if (ret != MESSAGE_PORT_ERROR_NONE) {
+ LOGW("message port send message error. err : %d", ret);
+ result = false;
+ }
+ else
+ {
+ LOGI("send message done");
+ result = true;
+ }
+
+ bundle_free(b);
+
+ return result;
+}
\ No newline at end of file