From: Kitae Kim Date: Mon, 11 Aug 2014 10:55:57 +0000 (+0900) Subject: tethering: add functions to get connected ip address and port X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~262^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2f7fb3e1582c1a7f4314126083184893850b51bf;p=sdk%2Femulator%2Fqemu.git tethering: add functions to get connected ip address and port Those functions are required to give connection infomation to ECP-UI and ECP-CLI. Change-Id: Ibc65454fe1621fe98283aff4dbb5eb93c8294736 Signed-off-by: Kitae Kim --- diff --git a/tizen/src/ecs/ecs_tethering.c b/tizen/src/ecs/ecs_tethering.c index b4d488361a..5180e40eb8 100644 --- a/tizen/src/ecs/ecs_tethering.c +++ b/tizen/src/ecs/ecs_tethering.c @@ -35,6 +35,7 @@ #include "../tethering/sensor.h" #include "../tethering/touch.h" #include "../hw/maru_virtio_touchscreen.h" +#include "../hw/maru_virtio_hwkey.h" #include "../debug_ch.h" MULTI_DEBUG_CHANNEL(tizen, ecs_tethering); @@ -42,7 +43,9 @@ MULTI_DEBUG_CHANNEL(tizen, ecs_tethering); #define MSG_BUF_SIZE 255 #define MSG_LEN_SIZE 4 -// static bool send_tethering_ntf(const char *data, const int len); +#define PRESSED 1 +#define RELEASED 2 + static bool send_tethering_ntf(const char *data); static void send_tethering_status_ntf(type_group group, type_action action); @@ -68,6 +71,7 @@ void send_tethering_connection_status_ecp(void) ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS); } +#if 0 static void send_tethering_port_ecp(void) { type_length length; @@ -82,7 +86,6 @@ static void send_tethering_port_ecp(void) } TRACE(">> send port_num: %d\n", tethering_port); - g_snprintf(data, sizeof(data) - 1, "%d", tethering_port); length = strlen(data); @@ -95,13 +98,61 @@ static void send_tethering_port_ecp(void) TRACE(">> send tethering_ntf to ecp. action=%d, group=%d, data=%s\n", action, group, data); -// send_tethering_ntf((const char *)msg, MSG_BUF_SIZE); send_tethering_ntf((const char *)msg); if (msg) { g_free(msg); } } +#endif + +static void send_tethering_connection_info(void) +{ + type_length length; + type_group group = ECS_TETHERING_MSG_GROUP_ECP; + type_action action = ECS_TETHERING_MSG_ACTION_CONNECT; + uint8_t *msg = NULL; + gchar data[64]; + + msg = g_malloc(MSG_BUF_SIZE); + if (!msg) { + ERR("failed to allocate memory\n"); + return; + } + + INFO(">> send port_num: %d\n", tethering_port); + { + const char *ip = get_tethering_connected_ipaddr(); + int port = get_tethering_connected_port(); + + if (!ip) { + ERR("invalid connected ip\n"); + return; + } + + if (!port) { + ERR("invalid connected port\n"); + return; + } + g_snprintf(data, sizeof(data) - 1, "%s:%d", ip, port); + length = strlen(data); + data[length] = '\0'; + } + + memcpy(msg, ECS_TETHERING_MSG_CATEGORY, 10); + memcpy(msg + 10, &length, sizeof(unsigned short)); + memcpy(msg + 12, &group, sizeof(unsigned char)); + memcpy(msg + 13, &action, sizeof(unsigned char)); + memcpy(msg + 14, data, length); + + INFO(">> send connection msg to ecp. " + "action=%d, group=%d, data=%s length=%d\n", + action, group, data, length); + + send_tethering_ntf((const char *)msg); + + g_free(msg); +} static void send_tethering_status_ntf(type_group group, type_action action) { @@ -111,20 +162,20 @@ static void send_tethering_status_ntf(type_group group, type_action action) gchar data[2]; switch (action) { - case ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS: - status = get_tethering_connection_status(); - if (status == CONNECTED) { - send_tethering_port_ecp(); - } - break; - case ECS_TETHERING_MSG_ACTION_SENSOR_STATUS: - status = get_tethering_sensor_status(); - break; - case ECS_TETHERING_MSG_ACTION_TOUCH_STATUS: - status = get_tethering_touch_status(); - break; - default: - break; + case ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS: + status = get_tethering_connection_status(); + if (status == CONNECTED) { + send_tethering_connection_info(); + } + break; + case ECS_TETHERING_MSG_ACTION_SENSOR_STATUS: + status = get_tethering_sensor_status(); + break; + case ECS_TETHERING_MSG_ACTION_TOUCH_STATUS: + status = get_tethering_touch_status(); + break; + default: + break; } msg = g_malloc(MSG_BUF_SIZE); @@ -143,7 +194,6 @@ static void send_tethering_status_ntf(type_group group, type_action action) TRACE(">> send tethering_ntf to ecp. action=%d, group=%d, data=%s\n", action, group, data); -// send_tethering_ntf((const char *)msg, MSG_BUF_SIZE); send_tethering_ntf((const char *)msg); if (msg) { @@ -151,7 +201,6 @@ static void send_tethering_status_ntf(type_group group, type_action action) } } -// static bool send_tethering_ntf(const char *data, const int len) static bool send_tethering_ntf(const char *data) { type_length length = 0; @@ -169,7 +218,7 @@ static bool send_tethering_ntf(const char *data) const char* ijdata = (data + catsize + 2 + 1 + 1); - TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group); + TRACE(">> header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group); ECS__Master master = ECS__MASTER__INIT; ECS__TetheringNtf ntf = ECS__TETHERING_NTF__INIT; @@ -217,25 +266,32 @@ void send_tethering_touch_data(int x, int y, int index, int status) virtio_touchscreen_event(x, y, index, status); } +void send_tethering_hwkey_data(int keycode) +{ + maru_hwkey_event(PRESSED, keycode); + maru_hwkey_event(RELEASED, keycode); +} + // handle tethering_req message bool msgproc_tethering_req(ECS_Client* ccli, ECS__TetheringReq* msg) { gchar cmd[10] = {0}; gchar **server_addr = NULL; + TRACE("enter %s\n", __func__); + g_strlcpy(cmd, msg->category, sizeof(cmd)); type_length length = (type_length) msg->length; type_group group = (type_group) (msg->group & 0xff); type_action action = (type_action) (msg->action & 0xff); - TRACE(">> header = cmd = %s, length = %d, action=%d, group=%d\n", + TRACE("<< header = cmd = %s, length = %d, action=%d, group=%d\n", cmd, length, action, group); - if (group == ECS_TETHERING_MSG_GROUP_ECP) { - switch(action) { + switch(action) { case ECS_TETHERING_MSG_ACTION_CONNECT: - { - // get ip address and port + INFO("MSG_ACTION_CONNECT\n"); + if (msg->data.data && msg->data.len > 0) { const gchar *data = (const gchar *)msg->data.data; gchar *ip_address = NULL; @@ -258,8 +314,6 @@ bool msgproc_tethering_req(ECS_Client* ccli, ECS__TetheringReq* msg) } else { ERR("failed to parse port number\n"); } - - TRACE("MSG_ACTION_CONNECT"); TRACE("len = %zd, data\" %s\"", strlen(data), data); connect_tethering_app(ip_address, port); @@ -267,10 +321,10 @@ bool msgproc_tethering_req(ECS_Client* ccli, ECS__TetheringReq* msg) TRACE(">> port_num: %d, %d\n", port, tethering_port); g_free(ip_address); - g_strfreev(server_addr); + } else { + INFO("ip address and port value are null\n"); } - } break; case ECS_TETHERING_MSG_ACTION_DISCONNECT: INFO(">> MSG_ACTION_DISCONNECT\n"); @@ -285,8 +339,9 @@ bool msgproc_tethering_req(ECS_Client* ccli, ECS__TetheringReq* msg) break; default: break; - } } + TRACE("leave %s\n", __func__); + return true; } diff --git a/tizen/src/ecs/ecs_tethering.h b/tizen/src/ecs/ecs_tethering.h index 1acf0787ef..dcaa09fd73 100644 --- a/tizen/src/ecs/ecs_tethering.h +++ b/tizen/src/ecs/ecs_tethering.h @@ -32,18 +32,7 @@ * define tethering messages between ecs and ecp */ #define ECS_TETHERING_MSG_CATEGORY "tethering" - #define ECS_TETHERING_MSG_GROUP_ECP 1 -// #define TETHERING_MSG_GROUP_USB -// #define TETHERING_MSG_GROUP_WIFI - -#if 0 -#define ECS_TETHERING_MSG_ACTION_CONNECT 1 -#define ECS_TETHERING_MSG_ACTION_DISCONNECT 2 -#define ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS 3 -#define ECS_TETHERING_MSG_ACTION_SENSOR_STATUS 4 -#define ECS_TETHERING_MSG_ACTION_TOUCH_STATUS 5 -#endif enum ECS_TETHERING_MSG_ACTION { ECS_TETHERING_MSG_ACTION_CONNECT = 1, @@ -62,3 +51,6 @@ void send_tethering_connection_status_ecp(void); void send_tethering_sensor_data(const char *data, int len); void send_tethering_touch_data(int x, int y, int index, int status); + +void send_tethering_hwkey_data(int keycode); + diff --git a/tizen/src/tethering/common.c b/tizen/src/tethering/common.c index 9796a079c8..55fed810ce 100644 --- a/tizen/src/tethering/common.c +++ b/tizen/src/tethering/common.c @@ -27,6 +27,7 @@ * - S-Core Co., Ltd * */ + #ifndef __WIN32 #include #else @@ -43,7 +44,6 @@ #include "common.h" #include "sensor.h" #include "touch.h" -// #include "display.h" #include "emul_state.h" #include "ecs/ecs_tethering.h" #include "genmsg/tethering.pb-c.h" @@ -63,21 +63,18 @@ MULTI_DEBUG_CHANNEL(tizen, app_tethering); #define SEND_BUF_MAX_SIZE 4096 static const char *loopback = "127.0.0.1"; +enum connection_type { + NONE = 0, + USB, + WIFI, +}; + typedef struct tethering_recv_buf { uint32_t len; uint32_t stack_size; char data[MSG_BUF_SIZE]; } tethering_recv_buf; -#if 0 -typedef struct input_device_list { - int type; - void *opaque; - - QTAILQ_ENTRY(input_device_list) node; -} input_device_list; -#endif - typedef struct _TetheringState { int fd; @@ -87,6 +84,7 @@ typedef struct _TetheringState { // connection state int status; + int type; // receiver handling thread QemuThread thread; @@ -100,9 +98,8 @@ typedef struct _TetheringState { } TetheringState; -static TetheringState *tethering_client; +static TetheringState *tethering_client = NULL; static tethering_recv_buf recv_buf; -// static bool app_state = false; static void end_tethering_socket(int sockfd); static void set_tethering_connection_status(int status); @@ -111,32 +108,6 @@ static void set_tethering_app_state(bool state); static bool get_tethering_app_state(void); #endif -#if 0 -int add_input_device(void *opaque) -{ - input_device_list *elem = (input_device_list *)opaque; - - if (!tethering_client) { - return -1; - } - - QTAILQ_INSERT_TAIL(&tethering_client->device, elem, node); - - return (tethering_client->device_node_cnt++); -} - -int remove_input_device(void *opaque) -{ - if (!tethering_client) { - return -1; - } - - QTAILQ_REMOVE(&tethering_client->device, opaque, node); - - tethering_client->device_node_cnt--; -} -#endif - // create master message static void *build_tethering_msg(Tethering__TetheringMsg* msg, int *payloadsize) { @@ -338,8 +309,7 @@ static bool send_set_event_status_msg(Tethering__EventType event_type, // message handlers static void msgproc_tethering_handshake_ans(Tethering__HandShakeAns *msg) { - // FIXME: handle handshake answer - // ans = msg->result; + // handle handshake answer } static void msgproc_app_state_msg(Tethering__AppState *msg) @@ -354,8 +324,6 @@ static void msgproc_app_state_msg(Tethering__AppState *msg) set_tethering_touch_status(status); disconnect_tethering_app(); - } else { - // does nothing } } @@ -373,15 +341,12 @@ static bool msgproc_tethering_event_msg(Tethering__EventMsg *msg) TETHERING__STATE__ENABLED); // TODO: check sensor device whether it exists or not - // set_tethering_sensor_status(ENABLED); set_tethering_sensor_status(TETHERING__STATE__ENABLED); if (is_emul_input_touch_enable()) { touch_status = TETHERING__STATE__ENABLED; - // set_tethering_touch_status(ENABLED); } else { touch_status = TETHERING__STATE__DISABLED; - // set_tethering_touch_status(DISABLED); } set_tethering_touch_status(touch_status); @@ -481,28 +446,12 @@ static bool handle_tethering_msg_from_controller(char *data, int len) } break; -#if 0 - case TETHERING__TETHERING_MSG__TYPE__DISPLAY_MSG: - { - Tethering__DisplayMsg *msg = tethering->displaymsg; - - TRACE("receive display_msg\n"); - if (!msg) { - ret = false; - } else { - msgproc_tethering_display_msg(msg); - } - } - break; -#endif - default: TRACE("invalid type message\n"); ret = false; break; } -// g_free(data); tethering__tethering_msg__free_unpacked(tethering, NULL); return ret; } @@ -607,16 +556,13 @@ static void tethering_io_handler(void *opaque) static int start_tethering_socket(const char *ipaddress, int port) { struct sockaddr_in addr; - - int sock = -1; - int ret = 0; + int sock = -1, ret = 0; addr.sin_family = AF_INET; addr.sin_port = htons(port); // i.e. 1234 INFO("server ip address: %s, port: %d\n", ipaddress, port); ret = inet_aton(ipaddress, &addr.sin_addr); - if (ret == 0) { ERR("inet_aton failure\n"); return -1; @@ -738,16 +684,42 @@ int get_tethering_connection_status(void) int status = 0; if (!tethering_client) { - return -1; + INFO("tethering_client is null\n"); + INFO("tetherging connection status: %d\n", status); + return DISCONNECTED; } qemu_mutex_lock(&tethering_client->mutex); status = tethering_client->status; qemu_mutex_unlock(&tethering_client->mutex); + INFO("tetherging connection status: %d\n", status); + return status; } +int get_tethering_connected_port(void) +{ + if (!tethering_client) { + ERR("tethering_client is null\n"); + return 0; + } + + ERR("connected port: %d\n", tethering_client->port); + return tethering_client->port; +} + +const char *get_tethering_connected_ipaddr(void) +{ + if (!tethering_client) { + ERR("tethering client is null\n"); + return NULL; + } + + TRACE("connected ip address: %s\n", tethering_client->ipaddress); + return tethering_client->ipaddress; +} + static void set_tethering_connection_status(int status) { if (!tethering_client) { @@ -762,7 +734,6 @@ static void set_tethering_connection_status(int status) } static void *initialize_tethering_socket(void *opaque); -// static void release_tethering_thread(void *opaque); int connect_tethering_app(const char *ipaddress, int port) { @@ -778,22 +749,27 @@ int connect_tethering_app(const char *ipaddress, int port) if (ipaddress) { ipaddr_len = strlen(ipaddress); + client->type = WIFI; } else { ipaddr_len = strlen(loopback); ipaddress = loopback; + client->type = USB; } client->ipaddress = g_malloc0(ipaddr_len + 1); if (!client->ipaddress) { + ERR("failed to allocate ipaddress buffer\n"); g_free(client); return -1; } + g_strlcpy(client->ipaddress, ipaddress, ipaddr_len + 1); + INFO("connection info. ip %s, port %d type %d\n", + client->ipaddress, client->port, client->type); tethering_client = client; qemu_mutex_init(&tethering_client->mutex); - qemu_thread_create(&tethering_client->thread, "tethering-io-thread", initialize_tethering_socket, client, QEMU_THREAD_DETACHED); @@ -813,7 +789,7 @@ int disconnect_tethering_app(void) sock = tethering_client->fd; if (sock < 0) { - ERR("tethering socket is terminated or not ready\n"); + ERR("tethering socket is already terminated or not ready\n"); return -1; } else { send_emul_state_msg(); @@ -881,12 +857,3 @@ static void *initialize_tethering_socket(void *opaque) return client; } - -#if 0 -static void release_tethering_thread(void *opaque) -{ - TetheringState *client = (TetheringState *)opaque; - - qemu_thread_join(&client->thread); -} -#endif diff --git a/tizen/src/tethering/common.h b/tizen/src/tethering/common.h index c9c2892f6a..605e62ffd9 100644 --- a/tizen/src/tethering/common.h +++ b/tizen/src/tethering/common.h @@ -28,17 +28,9 @@ * */ -typedef struct input_device_list { - int type; - void *opaque; - - QTAILQ_ENTRY(input_device_list) node; -} input_device_list; - -// common enum connection_status { - CONNECTED = 1, - DISCONNECTED, + DISCONNECTED = 0, + CONNECTED, CONNECTING, CONNREFUSED, }; @@ -56,4 +48,6 @@ int disconnect_tethering_app(void); int get_tethering_connection_status(void); -int add_input_device(void *opaque); +int get_tethering_connected_port(void); + +const char *get_tethering_connected_ipaddr(void); \ No newline at end of file diff --git a/tizen/src/tethering/genmsg/tethering.pb-c.c b/tizen/src/tethering/genmsg/tethering.pb-c.c index 0620a77854..1b4a7e0c36 100644 --- a/tizen/src/tethering/genmsg/tethering.pb-c.c +++ b/tizen/src/tethering/genmsg/tethering.pb-c.c @@ -694,6 +694,49 @@ void tethering__touch_data__free_unpacked PROTOBUF_C_ASSERT (message->base.descriptor == &tethering__touch_data__descriptor); protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); } +void tethering__hwkey_msg__init + (Tethering__HWKeyMsg *message) +{ + static Tethering__HWKeyMsg init_value = TETHERING__HWKEY_MSG__INIT; + *message = init_value; +} +size_t tethering__hwkey_msg__get_packed_size + (const Tethering__HWKeyMsg *message) +{ + PROTOBUF_C_ASSERT (message->base.descriptor == &tethering__hwkey_msg__descriptor); + return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); +} +size_t tethering__hwkey_msg__pack + (const Tethering__HWKeyMsg *message, + uint8_t *out) +{ + PROTOBUF_C_ASSERT (message->base.descriptor == &tethering__hwkey_msg__descriptor); + return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); +} +size_t tethering__hwkey_msg__pack_to_buffer + (const Tethering__HWKeyMsg *message, + ProtobufCBuffer *buffer) +{ + PROTOBUF_C_ASSERT (message->base.descriptor == &tethering__hwkey_msg__descriptor); + return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); +} +Tethering__HWKeyMsg * + tethering__hwkey_msg__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data) +{ + return (Tethering__HWKeyMsg *) + protobuf_c_message_unpack (&tethering__hwkey_msg__descriptor, + allocator, len, data); +} +void tethering__hwkey_msg__free_unpacked + (Tethering__HWKeyMsg *message, + ProtobufCAllocator *allocator) +{ + PROTOBUF_C_ASSERT (message->base.descriptor == &tethering__hwkey_msg__descriptor); + protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); +} void tethering__touch_msg__init (Tethering__TouchMsg *message) { @@ -1668,7 +1711,45 @@ const ProtobufCMessageDescriptor tethering__touch_data__descriptor = (ProtobufCMessageInit) tethering__touch_data__init, NULL,NULL,NULL /* reserved[123] */ }; -const ProtobufCEnumValue tethering__touch_msg__type__enum_values_by_number[7] = +static const ProtobufCFieldDescriptor tethering__hwkey_msg__field_descriptors[1] = +{ + { + "type", + 1, + PROTOBUF_C_LABEL_REQUIRED, + PROTOBUF_C_TYPE_ENUM, + 0, /* quantifier_offset */ + PROTOBUF_C_OFFSETOF(Tethering__HWKeyMsg, type), + &tethering__hwkey_type__descriptor, + NULL, + 0, /* packed */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned tethering__hwkey_msg__field_indices_by_name[] = { + 0, /* field[0] = type */ +}; +static const ProtobufCIntRange tethering__hwkey_msg__number_ranges[1 + 1] = +{ + { 1, 0 }, + { 0, 1 } +}; +const ProtobufCMessageDescriptor tethering__hwkey_msg__descriptor = +{ + PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC, + "tethering.HWKeyMsg", + "HWKeyMsg", + "Tethering__HWKeyMsg", + "tethering", + sizeof(Tethering__HWKeyMsg), + 1, + tethering__hwkey_msg__field_descriptors, + tethering__hwkey_msg__field_indices_by_name, + 1, tethering__hwkey_msg__number_ranges, + (ProtobufCMessageInit) tethering__hwkey_msg__init, + NULL,NULL,NULL /* reserved[123] */ +}; +const ProtobufCEnumValue tethering__touch_msg__type__enum_values_by_number[8] = { { "START_REQ", "TETHERING__TOUCH_MSG__TYPE__START_REQ", 2 }, { "START_ANS", "TETHERING__TOUCH_MSG__TYPE__START_ANS", 3 }, @@ -1677,13 +1758,15 @@ const ProtobufCEnumValue tethering__touch_msg__type__enum_values_by_number[7] = { "TOUCH_DATA", "TETHERING__TOUCH_MSG__TYPE__TOUCH_DATA", 6 }, { "RESOLUTION", "TETHERING__TOUCH_MSG__TYPE__RESOLUTION", 7 }, { "DISPLAY_MSG", "TETHERING__TOUCH_MSG__TYPE__DISPLAY_MSG", 8 }, + { "HWKEY_MSG", "TETHERING__TOUCH_MSG__TYPE__HWKEY_MSG", 9 }, }; static const ProtobufCIntRange tethering__touch_msg__type__value_ranges[] = { -{2, 0},{0, 7} +{2, 0},{0, 8} }; -const ProtobufCEnumValueIndex tethering__touch_msg__type__enum_values_by_name[7] = +const ProtobufCEnumValueIndex tethering__touch_msg__type__enum_values_by_name[8] = { { "DISPLAY_MSG", 6 }, + { "HWKEY_MSG", 7 }, { "MAX_COUNT", 3 }, { "RESOLUTION", 5 }, { "START_ANS", 1 }, @@ -1698,15 +1781,15 @@ const ProtobufCEnumDescriptor tethering__touch_msg__type__descriptor = "Type", "Tethering__TouchMsg__Type", "tethering", - 7, + 8, tethering__touch_msg__type__enum_values_by_number, - 7, + 8, tethering__touch_msg__type__enum_values_by_name, 1, tethering__touch_msg__type__value_ranges, NULL,NULL,NULL,NULL /* reserved[1234] */ }; -static const ProtobufCFieldDescriptor tethering__touch_msg__field_descriptors[8] = +static const ProtobufCFieldDescriptor tethering__touch_msg__field_descriptors[9] = { { "type", @@ -1804,9 +1887,22 @@ static const ProtobufCFieldDescriptor tethering__touch_msg__field_descriptors[8] 0, /* packed */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, + { + "hwkey", + 9, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_MESSAGE, + 0, /* quantifier_offset */ + PROTOBUF_C_OFFSETOF(Tethering__TouchMsg, hwkey), + &tethering__hwkey_msg__descriptor, + NULL, + 0, /* packed */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, }; static const unsigned tethering__touch_msg__field_indices_by_name[] = { 7, /* field[7] = display */ + 8, /* field[8] = hwkey */ 4, /* field[4] = maxCount */ 6, /* field[6] = resolution */ 2, /* field[2] = startAns */ @@ -1818,7 +1914,7 @@ static const unsigned tethering__touch_msg__field_indices_by_name[] = { static const ProtobufCIntRange tethering__touch_msg__number_ranges[1 + 1] = { { 1, 0 }, - { 0, 8 } + { 0, 9 } }; const ProtobufCMessageDescriptor tethering__touch_msg__descriptor = { @@ -1828,7 +1924,7 @@ const ProtobufCMessageDescriptor tethering__touch_msg__descriptor = "Tethering__TouchMsg", "tethering", sizeof(Tethering__TouchMsg), - 8, + 9, tethering__touch_msg__field_descriptors, tethering__touch_msg__field_indices_by_name, 1, tethering__touch_msg__number_ranges, @@ -2180,3 +2276,39 @@ const ProtobufCEnumDescriptor tethering__touch_state__descriptor = tethering__touch_state__value_ranges, NULL,NULL,NULL,NULL /* reserved[1234] */ }; +const ProtobufCEnumValue tethering__hwkey_type__enum_values_by_number[6] = +{ + { "MENU", "TETHERING__HWKEY_TYPE__MENU", 1 }, + { "HOME", "TETHERING__HWKEY_TYPE__HOME", 2 }, + { "BACK", "TETHERING__HWKEY_TYPE__BACK", 3 }, + { "POWER", "TETHERING__HWKEY_TYPE__POWER", 4 }, + { "VOLUME_UP", "TETHERING__HWKEY_TYPE__VOLUME_UP", 5 }, + { "VOLUME_DOWN", "TETHERING__HWKEY_TYPE__VOLUME_DOWN", 6 }, +}; +static const ProtobufCIntRange tethering__hwkey_type__value_ranges[] = { +{1, 0},{0, 6} +}; +const ProtobufCEnumValueIndex tethering__hwkey_type__enum_values_by_name[6] = +{ + { "BACK", 2 }, + { "HOME", 1 }, + { "MENU", 0 }, + { "POWER", 3 }, + { "VOLUME_DOWN", 5 }, + { "VOLUME_UP", 4 }, +}; +const ProtobufCEnumDescriptor tethering__hwkey_type__descriptor = +{ + PROTOBUF_C_ENUM_DESCRIPTOR_MAGIC, + "tethering.HWKeyType", + "HWKeyType", + "Tethering__HWKeyType", + "tethering", + 6, + tethering__hwkey_type__enum_values_by_number, + 6, + tethering__hwkey_type__enum_values_by_name, + 1, + tethering__hwkey_type__value_ranges, + NULL,NULL,NULL,NULL /* reserved[1234] */ +}; diff --git a/tizen/src/tethering/genmsg/tethering.pb-c.h b/tizen/src/tethering/genmsg/tethering.pb-c.h index a2fc95751d..c2049b36bf 100644 --- a/tizen/src/tethering/genmsg/tethering.pb-c.h +++ b/tizen/src/tethering/genmsg/tethering.pb-c.h @@ -24,6 +24,7 @@ typedef struct _Tethering__Resolution Tethering__Resolution; typedef struct _Tethering__DisplayMsg Tethering__DisplayMsg; typedef struct _Tethering__TouchMaxCount Tethering__TouchMaxCount; typedef struct _Tethering__TouchData Tethering__TouchData; +typedef struct _Tethering__HWKeyMsg Tethering__HWKeyMsg; typedef struct _Tethering__TouchMsg Tethering__TouchMsg; typedef struct _Tethering__TetheringMsg Tethering__TetheringMsg; @@ -50,7 +51,8 @@ typedef enum _Tethering__TouchMsg__Type { TETHERING__TOUCH_MSG__TYPE__MAX_COUNT = 5, TETHERING__TOUCH_MSG__TYPE__TOUCH_DATA = 6, TETHERING__TOUCH_MSG__TYPE__RESOLUTION = 7, - TETHERING__TOUCH_MSG__TYPE__DISPLAY_MSG = 8 + TETHERING__TOUCH_MSG__TYPE__DISPLAY_MSG = 8, + TETHERING__TOUCH_MSG__TYPE__HWKEY_MSG = 9 } Tethering__TouchMsg__Type; typedef enum _Tethering__TetheringMsg__Type { TETHERING__TETHERING_MSG__TYPE__HANDSHAKE_REQ = 2, @@ -90,6 +92,14 @@ typedef enum _Tethering__TouchState { TETHERING__TOUCH_STATE__PRESSED = 1, TETHERING__TOUCH_STATE__RELEASED = 2 } Tethering__TouchState; +typedef enum _Tethering__HWKeyType { + TETHERING__HWKEY_TYPE__MENU = 1, + TETHERING__HWKEY_TYPE__HOME = 2, + TETHERING__HWKEY_TYPE__BACK = 3, + TETHERING__HWKEY_TYPE__POWER = 4, + TETHERING__HWKEY_TYPE__VOLUME_UP = 5, + TETHERING__HWKEY_TYPE__VOLUME_DOWN = 6 +} Tethering__HWKeyType; /* --- messages --- */ @@ -280,6 +290,16 @@ struct _Tethering__TouchData , 0,0, 0,0, 0,0, 0,0 } +struct _Tethering__HWKeyMsg +{ + ProtobufCMessage base; + Tethering__HWKeyType type; +}; +#define TETHERING__HWKEY_MSG__INIT \ + { PROTOBUF_C_MESSAGE_INIT (&tethering__hwkey_msg__descriptor) \ + , 0 } + + struct _Tethering__TouchMsg { ProtobufCMessage base; @@ -291,10 +311,11 @@ struct _Tethering__TouchMsg Tethering__TouchData *touchdata; Tethering__Resolution *resolution; Tethering__DisplayMsg *display; + Tethering__HWKeyMsg *hwkey; }; #define TETHERING__TOUCH_MSG__INIT \ { PROTOBUF_C_MESSAGE_INIT (&tethering__touch_msg__descriptor) \ - , 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL } + , 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } struct _Tethering__TetheringMsg @@ -618,6 +639,25 @@ Tethering__TouchData * void tethering__touch_data__free_unpacked (Tethering__TouchData *message, ProtobufCAllocator *allocator); +/* Tethering__HWKeyMsg methods */ +void tethering__hwkey_msg__init + (Tethering__HWKeyMsg *message); +size_t tethering__hwkey_msg__get_packed_size + (const Tethering__HWKeyMsg *message); +size_t tethering__hwkey_msg__pack + (const Tethering__HWKeyMsg *message, + uint8_t *out); +size_t tethering__hwkey_msg__pack_to_buffer + (const Tethering__HWKeyMsg *message, + ProtobufCBuffer *buffer); +Tethering__HWKeyMsg * + tethering__hwkey_msg__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data); +void tethering__hwkey_msg__free_unpacked + (Tethering__HWKeyMsg *message, + ProtobufCAllocator *allocator); /* Tethering__TouchMsg methods */ void tethering__touch_msg__init (Tethering__TouchMsg *message); @@ -706,6 +746,9 @@ typedef void (*Tethering__TouchMaxCount_Closure) typedef void (*Tethering__TouchData_Closure) (const Tethering__TouchData *message, void *closure_data); +typedef void (*Tethering__HWKeyMsg_Closure) + (const Tethering__HWKeyMsg *message, + void *closure_data); typedef void (*Tethering__TouchMsg_Closure) (const Tethering__TouchMsg *message, void *closure_data); @@ -724,6 +767,7 @@ extern const ProtobufCEnumDescriptor tethering__event_type__descriptor; extern const ProtobufCEnumDescriptor tethering__state__descriptor; extern const ProtobufCEnumDescriptor tethering__sensor_type__descriptor; extern const ProtobufCEnumDescriptor tethering__touch_state__descriptor; +extern const ProtobufCEnumDescriptor tethering__hwkey_type__descriptor; extern const ProtobufCMessageDescriptor tethering__hand_shake_req__descriptor; extern const ProtobufCMessageDescriptor tethering__hand_shake_ans__descriptor; extern const ProtobufCMessageDescriptor tethering__emulator_state__descriptor; @@ -742,6 +786,7 @@ extern const ProtobufCMessageDescriptor tethering__resolution__descriptor; extern const ProtobufCMessageDescriptor tethering__display_msg__descriptor; extern const ProtobufCMessageDescriptor tethering__touch_max_count__descriptor; extern const ProtobufCMessageDescriptor tethering__touch_data__descriptor; +extern const ProtobufCMessageDescriptor tethering__hwkey_msg__descriptor; extern const ProtobufCMessageDescriptor tethering__touch_msg__descriptor; extern const ProtobufCEnumDescriptor tethering__touch_msg__type__descriptor; extern const ProtobufCMessageDescriptor tethering__tethering_msg__descriptor; diff --git a/tizen/src/tethering/msg/tethering.proto b/tizen/src/tethering/msg/tethering.proto index cf1c01cbce..01988bc394 100644 --- a/tizen/src/tethering/msg/tethering.proto +++ b/tizen/src/tethering/msg/tethering.proto @@ -158,6 +158,19 @@ message TouchData { optional TouchState state = 4; } +enum HWKeyType { + MENU = 1; + HOME = 2; + BACK = 3; + POWER = 4; + VOLUME_UP = 5; + VOLUME_DOWN = 6; +} + +message HWKeyMsg { + required HWKeyType type = 1; +} + message TouchMsg { enum Type { START_REQ = 2; @@ -167,6 +180,7 @@ message TouchMsg { TOUCH_DATA = 6; RESOLUTION = 7; DISPLAY_MSG = 8; + HWKEY_MSG = 9; } required Type type = 1; optional StartReq startReq = 2; @@ -176,6 +190,7 @@ message TouchMsg { optional TouchData touchData = 6; optional Resolution resolution = 7; optional DisplayMsg display = 8; + optional HWKeyMsg hwkey = 9; } message TetheringMsg { diff --git a/tizen/src/tethering/sensor.c b/tizen/src/tethering/sensor.c index 43f7a0ac59..e082f8c9e9 100644 --- a/tizen/src/tethering/sensor.c +++ b/tizen/src/tethering/sensor.c @@ -35,7 +35,6 @@ #define EISCONN WSAEISCONN #endif -#include "qemu-common.h" #include "qemu/main-loop.h" #include "qemu/sockets.h" #include "ui/console.h" @@ -68,36 +67,10 @@ enum sensor_level { level_magnetic = 13 }; -static int sensor_device_status; - -#if 0 -static void init_sensor_state(void) -{ - input_device_list *device = NULL; - sensor_state *sensor = NULL; - int ret = 0; - - device = g_malloc0(sizeof(device)); - if (!device) { - return; - } - - sensor = g_malloc0(sizeof(sensor_state)); - if (!sensor) { - g_free(device); - return; - } +#define ACCEL_ADJUST 100000 +#define GYRO_ADJUST 17.50 - device->type = TETHERING__TETHERING_MSG__TYPE__SENSOR_MSG; - device->opaque = sensor; - - ret = add_input_device(device); - if (ret < 0) { - g_free(sensor); - g_free(device); - } -} -#endif +static int sensor_device_status; // create a sensor message. static bool build_sensor_msg(Tethering__SensorMsg *sensor) @@ -177,8 +150,9 @@ static void set_sensor_data(Tethering__SensorData *data) { char tmp[255] = {0}; - sprintf(tmp, "%d\n%d\n%s\n%s\n%s\n", - level_accel, 3, data->x, data->y, data->z); + sprintf(tmp, "%d\n%d\n%lf\n%lf\n%lf\n", + level_accel, 3, (atof(data->x) * ACCEL_ADJUST), + (atof(data->y) * ACCEL_ADJUST), (atof(data->z) * ACCEL_ADJUST)); send_tethering_sensor_data(tmp, strlen(tmp)); TRACE("sensor_accel x: %s, y: %s, z: %s\n", @@ -201,8 +175,9 @@ static void set_sensor_data(Tethering__SensorData *data) { char tmp[255] = {0}; - sprintf(tmp, "%d\n%d\n%s\n%s\n%s\n", - level_gyro, 3, data->x, data->y, data->z); + sprintf(tmp, "%d\n%d\n%lf\n%lf\n%lf\n", + level_gyro, 3, (atof(data->x) / GYRO_ADJUST), + (atof(data->y) / GYRO_ADJUST), (atof(data->z) / GYRO_ADJUST)); send_tethering_sensor_data(tmp, strlen(tmp)); TRACE("sensor_gyro x: %s, y: %s, z: %s\n", @@ -245,9 +220,6 @@ bool msgproc_tethering_sensor_msg(void *message) case TETHERING__SENSOR_MSG__TYPE__START_REQ: TRACE("SENSOR_MSG_TYPE_START_REQ\n"); - // TODO - // init_sensor_state(); - // set sensor type. send_set_sensor_status_msg(TETHERING__SENSOR_TYPE__ACCEL, TETHERING__STATE__ENABLED); diff --git a/tizen/src/tethering/touch.c b/tizen/src/tethering/touch.c index 0af096a8d9..c39f45f9f2 100644 --- a/tizen/src/tethering/touch.c +++ b/tizen/src/tethering/touch.c @@ -38,50 +38,11 @@ MULTI_DEBUG_CHANNEL(tizen, app_tethering); -typedef struct touch_state { - bool is_touch_event; - bool is_touch_supported; - - // int touch_max_point; - // display_state *display; -} touch_event; - -// static bool is_touch_event; static int touch_device_status; - -// static void set_touch_event_status(bool status); static bool send_display_image_data(void); -#if 0 -touch_state *init_touch_state(void) -{ - input_device_list *device = NULL; - touch_state *touch = NULL; - int ret = 0; - - device = g_malloc0(sizeof(device)); - if (!device) { - return NULL; - } - - touch = g_malloc0(sizeof(touch_state)); - if (!touch) { - g_free(device); - return NULL; - } - - device->type = TETHERING__TETHERING_MSG__TYPE__TOUCH_MSG; - device->opaque = touch; - - ret = add_input_device(device); - if (ret < 0) { - g_free(touch); - g_free(device); - } - - return touch; -} -#endif +#define HARD_KEY_MENU 169 +#define HARD_KEY_BACK 158 static bool build_touch_msg(Tethering__TouchMsg *touch) { @@ -198,21 +159,13 @@ static bool send_set_touch_resolution(void) return ret; } -#if 0 -static void set_touch_event_status(bool status) -{ - is_touch_event = status; - - INFO("set touch_event status: %d\n", status); -} - static void set_hwkey_data(Tethering__HWKeyMsg *msg) { int32_t keycode = 0; switch (msg->type) { case TETHERING__HWKEY_TYPE__MENU: - // keycode = HARD_KEY_ ; + keycode = HARD_KEY_MENU; break; case TETHERING__HWKEY_TYPE__HOME: @@ -220,18 +173,18 @@ static void set_hwkey_data(Tethering__HWKeyMsg *msg) break; case TETHERING__HWKEY_TYPE__BACK: - // keycode = ; + keycode = HARD_KEY_BACK; break; case TETHERING__HWKEY_TYPE__POWER: keycode = HARD_KEY_POWER; break; - case TETHERING__HWKEY_TYPE__VOLUMEUP: + case TETHERING__HWKEY_TYPE__VOLUME_UP: keycode = HARD_KEY_VOL_UP; break; - case TETHERING__HWKEY_TYPE__VOLUMEDOWN: + case TETHERING__HWKEY_TYPE__VOLUME_DOWN: keycode = HARD_KEY_VOL_DOWN; break; @@ -242,7 +195,6 @@ static void set_hwkey_data(Tethering__HWKeyMsg *msg) INFO("convert hwkey msg to keycode: %d\n", keycode); send_tethering_hwkey_data(keycode); } -#endif static bool is_display_dirty = false; @@ -252,50 +204,42 @@ void set_display_dirty(bool dirty) is_display_dirty = dirty; } -// bool msgproc_tethering_touch_msg(Tethering__TouchMsg *msg) bool msgproc_tethering_touch_msg(void *message) { bool ret = true; Tethering__TouchMsg *msg = (Tethering__TouchMsg *)message; - // touch_state *state = NULL; - switch(msg->type) { case TETHERING__TOUCH_MSG__TYPE__START_REQ: TRACE("TOUCH_MSG_TYPE_START\n"); - // state = init_touch_state(); - - // it means that app starts to send touch values. - // set_touch_event_status(true); - send_set_touch_max_count(); send_set_touch_resolution(); - ret = send_touch_start_ans_msg(TETHERING__MESSAGE_RESULT__SUCCESS); break; case TETHERING__TOUCH_MSG__TYPE__TERMINATE: TRACE("TOUCH_MSG_TYPE_TERMINATE\n"); - - // it means that app stops to send touch values. - // set_touch_event_status(false); break; case TETHERING__TOUCH_MSG__TYPE__TOUCH_DATA: + TRACE("TOUCH_MSG_TYPE_TOUCH_DATA\n"); set_touch_data(msg->touchdata); break; case TETHERING__TOUCH_MSG__TYPE__DISPLAY_MSG: + TRACE("TOUCH_MSG_TYPE_DISPLAY_MSG\n"); + if (is_display_dirty) { + TRACE("display dirty status!! send the image\n"); send_display_image_data(); is_display_dirty = false; } break; -#if 0 case TETHERING__TOUCH_MSG__TYPE__HWKEY_MSG: + TRACE("TOUCH_MSG_TYPE_HWKEY_MSG\n"); set_hwkey_data(msg->hwkey); break; -#endif + default: TRACE("invalid touch_msg\n"); ret = false;