using namespace std;
-struct priv {
+struct sap_info_s {
sap_agent_h agent;
sap_socket_h socket;
+ sap_peer_agent_h peer_agent;
sap_file_transaction_h file_socket;
};
+struct sync_request {
+ string mode;
+ string category;
+ string type;
+};
+
static void _reset_sticker_data();
struct sticker_info {
}
};
-static struct priv priv_data = { 0 };
+static struct sap_info_s priv_data = { 0 };
static struct sticker_info sticker_data;
+static struct sync_request pending_sync_request;
gboolean file_on_progress = 0;
static string incoming_file_name;
json_object_set_string_member(j_object, "category", category);
json_object_set_string_member(j_object, "type", type);
- if (_send_json_data(j_object) == FALSE)
- LOGE("Failed to request sticker data");
+ if (_send_json_data(j_object) == FALSE) {
+ pending_sync_request.mode = string(mode ? mode : "manual");
+ pending_sync_request.category = string(category? category : "arsticker");
+ pending_sync_request.type = string(type ? type : "input");
+
+ LOGI("Push sync request");
+ }
json_object_unref(j_object);
}
sap_service_connection_terminated_reason_e result,
void *user_data)
{
+ sap_info_s *priv = NULL;
+ priv = (sap_info_s *)user_data;
+
switch (result)
{
case SAP_CONNECTION_TERMINATED_REASON_PEER_DISCONNECTED:
break;
}
+ sap_socket_destroy(priv->socket);
+ priv->socket = NULL;
+
service_app_exit();
}
JsonObject *file_obj = json_array_get_object_element(file_list, i);
int file_len = json_object_get_int_member(file_obj, "size");
const char *json_filename = json_object_get_string_member(file_obj, "fileName");
+ if (!json_filename) {
+ json_filename = json_object_get_string_member(file_obj, "filename");
+ }
string file_name = string(json_filename ? json_filename : "");
if (file_len > 0) {
LOGI("Connection success");
priv_data.socket = socket;
sap_peer_agent_accept_service_connection(peer_agent);
- sap_peer_agent_set_service_connection_terminated_cb(peer_agent, conn_terminated, NULL);
+ sap_peer_agent_set_service_connection_terminated_cb(peer_agent, conn_terminated, &priv_data);
sap_socket_set_data_received_cb(socket, on_data_received, peer_agent);
break;
case SAP_CONNECTION_ALREADY_EXIST:
}
}
+static void
+_on_service_connection_created(sap_peer_agent_h peer_agent,
+ sap_socket_h socket,
+ sap_service_connection_result_e result,
+ void *user_data)
+{
+ sap_info_s *priv = (sap_info_s *)user_data;
+
+ switch (result)
+ {
+ case SAP_CONNECTION_SUCCESS:
+ sap_peer_agent_set_service_connection_terminated_cb(priv->peer_agent,
+ conn_terminated,
+ priv);
+
+ sap_socket_set_data_received_cb(socket, on_data_received, peer_agent);
+ priv->socket = socket;
+ LOGI("Connection Established");
+
+ if (!pending_sync_request.mode.empty()) {
+ LOGD("[Request to sync sticker] mode: %s, category: %s, type : %s", pending_sync_request.mode.c_str(),
+ pending_sync_request.category.c_str(),
+ pending_sync_request.type.c_str());
+
+ request_sticker_data(pending_sync_request.mode.c_str(), pending_sync_request.category.c_str(), pending_sync_request.type.c_str());
+ pending_sync_request.mode.clear();
+ pending_sync_request.category.clear();
+ pending_sync_request.type.clear();
+ }
+
+ break;
+
+ case SAP_CONNECTION_ALREADY_EXIST:
+ priv->socket = socket;
+ LOGI("Connection Already Exist");
+ break;
+
+ case SAP_CONNECTION_FAILURE_DEVICE_UNREACHABLE:
+ LOGW("Connection Failure device unreachable");
+ break;
+
+ case SAP_CONNECTION_FAILURE_INVALID_PEERAGENT:
+ LOGW("Connection Failure invalid peer agent");
+ break;
+
+ case SAP_CONNECTION_FAILURE_NETWORK:
+ LOGW("Connection Failure network");
+ break;
+
+ case SAP_CONNECTION_FAILURE_PEERAGENT_NO_RESPONSE:
+ LOGW("Connection Failure peer agent no response");
+ break;
+
+ case SAP_CONNECTION_FAILURE_PEERAGENT_REJECTED:
+ LOGW("Connection Failure peer agent rejected");
+ break;
+
+ case SAP_CONNECTION_FAILURE_UNKNOWN:
+ LOGW("Connection Failure peer agent unknown");
+ break;
+
+ case SAP_CONNECTION_IN_PROGRESS:
+ LOGW("Connection in progress");
+ break;
+
+ case SAP_CONNECTION_PEER_AGENT_NOT_SUPPORTED:
+ LOGW("Connection peer agent not supported");
+ break;
+ }
+}
+
+static gboolean
+_create_service_connection(gpointer user_data)
+{
+ sap_info_s *priv = (sap_info_s *)user_data;
+ int result = sap_agent_request_service_connection(priv->agent,
+ priv->peer_agent,
+ _on_service_connection_created,
+ priv);
+
+ LOGD("request connection result : %d", result);
+
+ return FALSE;
+}
+
+static void
+_on_peer_agent_updated(sap_peer_agent_h peer_agent,
+ sap_peer_agent_status_e peer_status,
+ sap_peer_agent_found_result_e result,
+ void *user_data)
+{
+ sap_info_s *priv = (sap_info_s *)user_data;
+
+ switch (result)
+ {
+ case SAP_PEER_AGENT_FOUND_RESULT_DEVICE_NOT_CONNECTED:
+ LOGW("SAP_PEER_AGENT_FOUND_RESULT_DEVICE_NOT_CONNECTED");
+ break;
+
+ case SAP_PEER_AGENT_FOUND_RESULT_FOUND:
+ if (peer_status == SAP_PEER_AGENT_STATUS_AVAILABLE)
+ {
+ LOGD("SAP_PEER_AGENT_FOUND_RESULT_FOUND");
+ priv->peer_agent = peer_agent;
+ g_idle_add(_create_service_connection, priv);
+ }
+ else
+ {
+ sap_peer_agent_destroy(peer_agent);
+ }
+ break;
+
+ case SAP_PEER_AGENT_FOUND_RESULT_SERVICE_NOT_FOUND:
+ LOGW("SAP_PEER_AGENT_FOUND_RESULT_SERVICE_NOT_FOUND");
+ break;
+
+ case SAP_PEER_AGENT_FOUND_RESULT_TIMEDOUT:
+ LOGW("SAP_PEER_AGENT_FOUND_RESULT_TIMEDOUT");
+ break;
+
+ case SAP_PEER_AGENT_FOUND_RESULT_INTERNAL_ERROR:
+ LOGW("SAP_PEER_AGENT_FOUND_RESULT_INTERNAL_ERROR");
+ break;
+
+ default:
+ break;
+ }
+}
+
+static gboolean
+_find_peer_agent(gpointer user_data)
+{
+ sap_info_s *priv = (sap_info_s *)user_data;
+ sap_agent_find_peer_agent(priv->agent, _on_peer_agent_updated, priv);
+
+ return FALSE;
+}
+
static void on_agent_initialized(sap_agent_h agent,
sap_agent_initialized_result_e result,
void *user_data)
break;
case SAP_DEVICE_STATUS_ATTACHED:
LOGD("Attached calling find peer now");
+ g_idle_add(_find_peer_agent, &priv_data);
break;
default:
LOGE("unknown status (%d)", status);
+#include <app_common.h>
+#include <service_app.h>
+#include <stdlib.h>
+
#include "main.h"
#include "ft.h"
#include "log.h"
-#include <app_common.h>
-#include <service_app.h>
static bool app_create(void *data)
{
static void app_control(app_control_h app_control, void *data)
{
/* Handle the launch request. */
+ char* request = NULL;
+ char* mode = NULL;
+ char* category = NULL;
+ char* type = NULL;
+
+ int res;
+
+ // sync request
+ res = app_control_get_extra_data(app_control, "request", &request);
+ if (APP_CONTROL_ERROR_NONE == res && NULL != request)
+ {
+ if (strcmp(request, "sync") == 0)
+ {
+ if (app_control_get_extra_data(app_control, "mode", &mode) != APP_CONTROL_ERROR_NONE)
+ {
+ LOGE("No given mode");
+ goto cleanup;
+ }
+
+ if (app_control_get_extra_data(app_control, "category", &category) != APP_CONTROL_ERROR_NONE)
+ {
+ LOGE("No given category");
+ goto cleanup;
+ }
+
+ if (app_control_get_extra_data(app_control, "type", &type) != APP_CONTROL_ERROR_NONE)
+ {
+ LOGE("No given type");
+ goto cleanup;
+ }
+
+ LOGI("[sync request] mode : %s, category : %s, type : %s", mode, category, type);
+
+ if (mode && category && type)
+ request_sticker_data(mode, category, type);
+ }
+ }
+cleanup:
+ if (NULL != request)
+ free(request);
+
+ if (NULL != mode)
+ free(mode);
+
+ if (NULL != category)
+ free(category);
+
+ if (NULL != type)
+ free(type);
}
static void app_terminate(void *data)