}
static void* recvThread(void* data)
{
+ const size_t data_len = 16 * 1024 * 1024;
struct target *target = data;
int pass = 0;
uint64_t event;
- struct msg_target_t log;
+ struct _msg_target_t *msg;
int err;
+ msg = malloc(sizeof(*msg) + data_len);
+ if (!msg) {
+ LOGE("Out of memory\n");
+ return NULL;
+ }
+
// initialize target variable
target->allocmem = 0;
for (;;) {
- err = target_recv_msg(target, &log);
- if ((err != 0) || (log.length >= TARGER_MSG_MAX_LEN)) {
+ err = target_recv_msg(target, (struct msg_target_t *)msg,
+ data_len);
+ if (err) {
/* disconnect */
event = EVENT_STOP;
write(target->event_fd, &event, sizeof(event));
break;
}
- if (IS_PROBE_MSG(log.type)) {
- struct msg_data_t *msg_data = (struct msg_data_t *)&log;
+ if (IS_PROBE_MSG(msg->type)) {
+ struct msg_data_t *msg_data = (struct msg_data_t *)msg;
if (msg_data->len > MAX_RAW_MESSAGE_SIZE) {
LOGE("Raw message is too big = %d\n",
continue;
}
- if (log.type == APP_MSG_STOP) {
+ if (msg->type == APP_MSG_STOP) {
LOGI("APP_MSG_STOP arrived\n");
pthread_cond_broadcast(&target->target_cv);
continue;
}
- log.data[log.length] = '\0';
- if (log.type == APP_MSG_ALLOC) {
- target->allocmem = str_to_int64(log.data);
+ msg->data[msg->length] = '\0';
+ if (msg->type == APP_MSG_ALLOC) {
+ target->allocmem = str_to_int64(msg->data);
continue; // don't send to host
- } else if (log.type == APP_MSG_PID) {
- LOGI("APP_MSG_PID arrived (pid ppid): %s\n", log.data);
+ } else if (msg->type == APP_MSG_PID) {
+ LOGI("APP_MSG_PID arrived (pid ppid): %s\n", msg->data);
/* only when first APP_MSG_PID is arrived */
if (target_get_pid(target) == UNKNOWN_PID) {
int n;
pid_t pid, ppid;
- n = sscanf(log.data, "%d %d", &pid, &ppid);
+ n = sscanf(msg->data, "%d %d", &pid, &ppid);
if (n != 2)
{
/**
write(target->event_fd, &event, sizeof(uint64_t));
}
continue; // don't send to host
- } else if (log.type == APP_MSG_TERMINATE) {
+ } else if (msg->type == APP_MSG_TERMINATE) {
LOGI("APP_MSG_TERMINATE arrived: pid[%d]\n",
target_get_pid(target));
sizeof(uint64_t));
break;
- } else if (log.type == APP_MSG_MSG) {
+ } else if (msg->type == APP_MSG_MSG) {
// don't send to host
- LOGI("EXTRA '%s'\n", log.data);
+ LOGI("EXTRA '%s'\n", msg->data);
continue;
} else if (log.type == APP_MSG_ERROR) {
// don't send to host
- LOGE("EXTRA '%s'\n", log.data);
+ LOGE("EXTRA '%s'\n", msg->data);
continue;
} else if (log.type == APP_MSG_WARNING) {
// don't send to host
- LOGW("EXTRA '%s'\n", log.data);
+ LOGW("EXTRA '%s'\n", msg->data);
continue;
} else if (log.type == APP_MSG_IMAGE) {
/* need chsmak */
- void *p = log.data;
+ void *p = msg->data;
char *file_name = p;
if (access(file_name, F_OK) != -1) {
struct msg_data_t *msg_data = (struct msg_data_t *)(p);
/* check packed size */
- if (log.length != strnlen(file_name, PATH_MAX) + 1 +
+ if (msg->length != strnlen(file_name, PATH_MAX) + 1 +
sizeof(*msg_data) + msg_data->len) {
LOGE("Bad packed message\n");
continue;
continue;
- } else if (log.type == APP_MSG_GET_UI_HIERARCHY) {
+ } else if (msg->type == APP_MSG_GET_UI_HIERARCHY) {
enum ErrorCode err_code = ERR_UNKNOWN;
- if (log.length == sizeof(uint32_t)) {
- err_code = *(uint32_t*)log.data;
+ if (msg->length == sizeof(uint32_t)) {
+ err_code = *(uint32_t*)msg->data;
}
sendACKToHost(NMSG_GET_UI_HIERARCHY, err_code, 0, 0);
continue;
- } else if (log.type == APP_MSG_GET_UI_HIERARCHY_DATA) {
- char *file_name = log.data;
+ } else if (msg->type == APP_MSG_GET_UI_HIERARCHY_DATA) {
+ char *file_name = msg->data;
struct msg_data_t *msg_data;
- const int len = log.length;
+ const int len = msg->length;
if (len == sizeof(uint32_t)) {
- enum ErrorCode err_code = *(uint32_t*)log.data;
+ enum ErrorCode err_code = *(uint32_t*)msg->data;
LOGE("APP_MSG_GET_UI_HIERARCHY_DATA error <%d>\n", err_code);
// TODO: system error
msg_data = malloc(MSG_DATA_HDR_LEN + len);
if (!msg_data) {
LOGE("Cannot alloc message: %d bytes\n", MSG_DATA_HDR_LEN + len);
- return NULL;
+ goto free_msg;
}
fill_data_msg_head(msg_data, NMSG_UI_HIERARCHY, 0, len);
- memcpy(msg_data->payload, log.data, log.length);
+ memcpy(msg_data->payload, msg->data, msg->length);
if (access(file_name, F_OK) != -1) {
LOGI("APP_MSG_GET_UI_HIERARCHY_DATA> File: <%s>\n",
LOGE("write to buf fail\n");
continue;
- } else if (log.type == APP_MSG_GET_UI_SCREENSHOT) {
+ } else if (msg->type == APP_MSG_GET_UI_SCREENSHOT) {
enum ErrorCode err_code = ERR_UNKNOWN;
- char *payload = log.data;
- int payload_size = log.length;
+ char *payload = msg->data;
+ int payload_size = msg->length;
- LOGI("APP_MSG_GET_UI_SCREENSHOT> log length = %d\n", log.length);
+ LOGI("APP_MSG_GET_UI_SCREENSHOT> log length = %d\n", msg->length);
if (payload_size >= sizeof(uint32_t)) {
char *file_name;
}
#ifdef PRINT_TARGET_LOG
else if (log.type == APP_MSG_LOG) {
- switch(log.data[0])
+ switch(msg->data[0])
{
case '2': // UI control creation log
case '3': // UI event log
}
} else {
/* not APP_MSG_LOG and not APP_MSG_IMAGE */
- LOGI("Extra MSG TYPE (%d|%d|%s)\n", log.type, log.length, log.data);
+ LOGI("Extra MSG TYPE (%d|%d|%s)\n", msg->type, msg->length, msg->data);
}
#endif
pass = 1;
}
+free_msg:
+ free(msg);
LOGI("thread finished %u:%u\n", target->pid, target->ppid);
return NULL;
}