#include <dirent.h>
#include <dlfcn.h>
#include <Ecore.h>
+#include <message_port.h>
#include "multi_assistant_main.h"
#include "multi_assistant_dbus_server.h"
static Ecore_Fd_Handler* g_dbus_fd_handler = NULL;
+static int g_streaming_data_serial = 0;
+
int mas_dbus_reconnect()
{
if (!g_conn_sender || !g_conn_listener) {
return 0;
}
-int masc_dbus_send_streaming_audio_data(int pid, int event, unsigned char* data, unsigned int data_size)
-{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- DBusMessage* msg;
- DBusError err;
- dbus_error_init(&err);
+const char *message_port = "ma_streaming_port";
- char service_name[64];
- memset(service_name, '\0', 64);
- snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
+#define STREAMING_BUFFER_SIZE 4096
- msg = dbus_message_new_method_call(
- service_name,
- MA_CLIENT_SERVICE_OBJECT_PATH,
- MA_CLIENT_SERVICE_INTERFACE,
- MAS_METHOD_STREAMING_AUDIO_DATA);
+typedef enum {
+ streaming_data_type_audio_data,
+ streaming_data_type_streaming_section
+} streaming_data_type_e;
- static int count = 0;
- if (NULL == msg) {
- MAS_LOGE(">>>> Request mas send utterance stream : Fail to make message");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD(">>>> Request mas send utterance stream : %s event(%d) %d", service_name, event, count++);
- }
+typedef struct {
+ unsigned int streaming_data_size;
+ int streaming_data_type;
+ int streaming_data_serial;
+} streaming_data_header;
- if (true != dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &event,
- DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
- &data, data_size,
- DBUS_TYPE_INVALID)) {
- dbus_message_unref(msg);
- MAS_LOGE("[ERROR] Fail to append args");
- return -1;
- }
+typedef struct {
+ int event;
+ unsigned int data_size;
+} streaming_data_audio_data_header;
- dbus_message_set_no_reply(msg, TRUE);
+typedef struct {
+ int section;
+} streaming_data_streaming_section_header;
- if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] Fail to Send");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- static int last_event = -1;
- if (event != last_event) {
- MAS_LOGI("[Dbus DEBUG] Success to Send utterance stream : %d event (%d)", pid, event);
- }
- last_event = event;
- dbus_connection_flush(g_conn_sender);
- }
+void masc_message_port_error(int error)
+{
+ MAS_LOGE("message_port error found : %s",
+ (MESSAGE_PORT_ERROR_NONE == error) ? "MESSAGE_PORT_ERROR_NONE" :
+ (MESSAGE_PORT_ERROR_IO_ERROR == error) ? "MESSAGE_PORT_ERROR_IO_ERROR" :
+ (MESSAGE_PORT_ERROR_OUT_OF_MEMORY == error) ? "MESSAGE_PORT_ERROR_OUT_OF_MEMORY" :
+ (MESSAGE_PORT_ERROR_INVALID_PARAMETER == error) ? "MESSAGE_PORT_ERROR_INVALID_PARAMETER" :
+ (MESSAGE_PORT_ERROR_PORT_NOT_FOUND == error) ? "MESSAGE_PORT_ERROR_PORT_NOT_FOUND" :
+ (MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH == error) ? "MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH" :
+ (MESSAGE_PORT_ERROR_MAX_EXCEEDED == error) ? "MESSAGE_PORT_ERROR_MAX_EXCEEDED" :
+ (MESSAGE_PORT_ERROR_RESOURCE_UNAVAILABLE == error) ? "MESSAGE_PORT_ERROR_RESOURCE_UNAVAILABLE" :
+ "MESSAGE_PORT_ERROR_UNKNOWN");
+}
- dbus_message_unref(msg);
+int masc_dbus_send_streaming_audio_data(int pid, int event, unsigned char* data, unsigned int data_size)
+{
+ bundle *b = bundle_create();
+
+ streaming_data_header header;
+ header.streaming_data_type = 0;
+ header.streaming_data_size = sizeof(streaming_data_header) + sizeof(streaming_data_audio_data_header) + data_size;
+ header.streaming_data_serial = g_streaming_data_serial++;
+
+ streaming_data_audio_data_header audio_data_header;
+ audio_data_header.event = event;
+ audio_data_header.data_size = data_size;
+
+ unsigned char buffer[STREAMING_BUFFER_SIZE];
+ size_t total_size = 0;
+ memcpy(buffer, &header, sizeof(header));
+ total_size += sizeof(header);
+ memcpy(buffer + total_size, &audio_data_header, sizeof(audio_data_header));
+ total_size += sizeof(audio_data_header);
+ memcpy(buffer + total_size, data, data_size);
+ total_size += data_size;
+
+ bundle_add_byte(b, "content", buffer, total_size);
+ int ret = message_port_send_message(mas_get_client_appid_by_pid(pid), message_port, b);
+ if (MESSAGE_PORT_ERROR_NONE != ret)
+ masc_message_port_error(ret);
+
+ bundle_free(b);
return 0;
}
int masc_dbus_send_streaming_section_changed(int pid, int section)
{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
+ static int serial = 0;
+ bundle *b = bundle_create();
- DBusMessage* msg;
+ streaming_data_header header;
+ header.streaming_data_type = 1;
+ header.streaming_data_size = sizeof(streaming_data_header) + sizeof(streaming_data_streaming_section_header);
+ header.streaming_data_serial = g_streaming_data_serial++;
- DBusError err;
- dbus_error_init(&err);
+ streaming_data_streaming_section_header streaming_section_header;
+ streaming_section_header.section = section;
- char service_name[64];
- memset(service_name, '\0', 64);
- snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
+ unsigned char buffer[STREAMING_BUFFER_SIZE];
+ size_t total_size = 0;
+ memcpy(buffer, &header, sizeof(header));
+ total_size += sizeof(header);
+ memcpy(buffer + total_size, &streaming_section_header, sizeof(streaming_section_header));
+ total_size += sizeof(streaming_section_header);
- msg = dbus_message_new_method_call(
- service_name,
- MA_CLIENT_SERVICE_OBJECT_PATH,
- MA_CLIENT_SERVICE_INTERFACE,
- MAS_METHOD_AUDIO_STREAMING_DATA_SECTION);
+ bundle_add_byte(b, "content", buffer, total_size);
+ int ret = message_port_send_message(mas_get_client_appid_by_pid(pid), message_port, b);
+ if (MESSAGE_PORT_ERROR_NONE != ret)
+ masc_message_port_error(ret);
- static int count = 0;
- if (NULL == msg) {
- MAS_LOGE(">>>> Request mas send streaming section changed information : Fail to make message");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD(">>>> Request mas send streaming section changed information : %s", service_name);
- }
-
- if (true != dbus_message_append_args(msg,
- DBUS_TYPE_INT32, §ion,
- DBUS_TYPE_INVALID)) {
- dbus_message_unref(msg);
- MAS_LOGE("[ERROR] Fail to append args");
- return -1;
- }
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] Fail to Send");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[Dbus DEBUG] Success to Send streaming section changed information : %d %d", pid, section);
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
+ bundle_free(b);
return 0;
}
MAS_LOGD("Get fd from dbus : %d", fd);
}
-
g_dbus_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn_listener, NULL, NULL);
if (NULL == g_dbus_fd_handler) {