#include "da_protocol.h"
#include "daemon.h"
#include "sys_stat.h"
+ #include "transfer_thread.h"
#include "elf.h"
+#include "ioctl_commands.h"
+#include "debug.h"
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
#define SYSTEM_INFO_DEBUG
#define parse_deb_on
return p;
}
+
+//This function concat 2 user space lists
+// this function clean "from" pointer
+static void concat_add_user_space_inst(struct user_space_inst_t *from,
+ struct user_space_inst_t *to)
+{
+ struct app_inst_t *new_app_inst_list = NULL;
+ uint32_t size;
+ char *p;
+
+ if (from->app_num == 0)
+ return;
+
+ new_app_inst_list = malloc((from->app_num + to->app_num) * sizeof(*new_app_inst_list));
+ p = new_app_inst_list;
+
+ size = from->app_num * sizeof(*new_app_inst_list);
+ memcpy(p, from->app_inst_list, size);
+ p +=size;
+
+ size = to->app_num * sizeof(*new_app_inst_list);
+ memcpy(p, to->app_inst_list, size);
+ p +=size;
+
+ free(to->app_inst_list);
+ to->app_inst_list = new_app_inst_list;
+
+ to->app_num += from->app_num;
+ return;
+}
+
void reset_msg(struct msg_t *msg)
{
- free(msg->payload);
+ if (msg->len)
+ free(msg->payload);
}
static void reset_app_info(struct app_info_t *app_info)
int host_message_handler(struct msg_t *msg)
{
- char *answer = 0;
- uint32_t answer_len = 0;
struct app_info_t app_info;
+ struct target_info_t target_info;
struct msg_t *msg_reply;
+ struct user_space_inst_t user_space_inst;
+ struct conf_t conf;
LOGI("MY HANDLE %s (%X)\n", msg_ID_str(msg->id), msg->id);
sendACKToHost(msg->id, ERR_NO, 0, 0);
break;
case NMSG_START:
- if (!parse_prof_session(msg->payload, &prof_session)) {
+ if (parse_prof_session(msg->payload, &prof_session) != 0) {
LOGE("prof session parsing error\n");
sendACKToHost(msg->id, ERR_WRONG_MESSAGE_FORMAT, 0, 0);
- return 1;
+ return -1;
}
+ // TODO: launch translator thread
if (start_transfer() != 0) {
LOGE("Cannot start transfer\n");
return -1;
}
- // TODO: kill app
- /* #ifdef RUN_APP_LOADER */
- /* kill_app(manager.appPath); */
- /* #else */
- /* kill_app(execPath); */
- /* #endif */
-
+
// TODO: apply_prof_session()
if (0) {
sendACKCodeToHost(MSG_NOTOK, ERR_CANNOT_START_PROFILING);
return -1;
}
- // TODO: exec app
-
// TODO: start app launch timer
+ //write to device
+ //ioctl_send_msg(msg);
+
// success
sendACKToHost(msg->id, ERR_NO, 0, 0);
break;
case NMSG_STOP:
terminate_all();
+ stop_profiling();
reset_prof_session(&prof_session);
stop_transfer();
+ //write to device
+ ioctl_send_msg(msg);
+ //send ack to host
sendACKToHost(msg->id, ERR_NO, 0, 0);
break;
case NMSG_CONFIG:
- if (!parse_msg_config(msg->payload, &prof_session.conf)) {
+ if (!parse_msg_config(msg->payload, &conf)) {
LOGE("config parsing error\n");
sendACKToHost(msg->id, ERR_WRONG_MESSAGE_FORMAT, 0, 0);
- return 1;
+ return -1;
+ }
+ if (!reconfigure(conf)) {
+ LOGE("Cannot change configuration\n");
+ return -1;
}
+ //write to device
+ ioctl_send_msg(msg);
+ //send ack to host
sendACKToHost(msg->id,ERR_NO,0,0);
break;
case NMSG_BINARY_INFO:
break;
case NMSG_SWAP_INST_ADD:
if (!parse_user_space_inst(msg->payload,
- &prof_session.user_space_inst)) {
+ &user_space_inst)) {
LOGE("user space inst parsing error\n");
sendACKToHost(msg->id, ERR_WRONG_MESSAGE_FORMAT, 0, 0);
- return 1;
+ return -1;
}
// TODO: apply_prof_session()
+ // warning concat_add_user_space_inst free user_space_inst
+ // so, data will not be availible
+ concat_add_user_space_inst(&user_space_inst, &prof_session.user_space_inst);
+ //write to device
+ ioctl_send_msg(msg);
+ //send ack to host
sendACKToHost(msg->id, ERR_NO, 0, 0);
+ // TODO release user_space_inst
break;
case NMSG_SWAP_INST_REMOVE:
if (!parse_user_space_inst(msg->payload,
return 0;
}
- // use sequence:
- /* receive_msg_header */
- /* receive_msg_payload */
- /* handle_msg */
- /* dispose_payload */
-
// testing
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
+
static void print_app_info( struct app_info_t *app_info)
{
LOGI("application info=\n");