summaryrefslogtreecommitdiff
path: root/tizen/src/emulator.c
blob: 95852a3cc133a04a86f45cadf482404e9005fa22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* 
 * Emulator
 *
 * Copyright (C) 2011, 2012 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: 
 * SeokYeon Hwang <syeon.hwang@samsung.com>
 * HyunJun Son <hj79.son@samsung.com>
 * MunKyu Im <munkyu.im@samsung.com>
 * GiWoong Kim <giwoong.kim@samsung.com>
 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * Contributors:
 * - S-Core Co., Ltd
 *
 */


#include <stdlib.h>
#include <SDL.h>
#include "maru_common.h"
#include "emulator.h"
#include "sdb.h"
#include "string.h"
#include "skin/maruskin_server.h"
#include "skin/maruskin_client.h"
#include "guest_server.h"
#include "debug_ch.h"
#include "process.h"

MULTI_DEBUG_CHANNEL(qemu, main);

#define IMAGE_PATH_PREFIX "file="
#define IMAGE_PATH_SUFFIX ",if=virtio"
#define MAXPATH  512

int tizen_base_port = 0;

int _emulator_condition = 0; //TODO:
extern char tizen_vms_path[256];

int get_emulator_condition(void)
{
    return _emulator_condition;
}

void set_emulator_condition(int state)
{
    _emulator_condition = state;
}

void exit_emulator(void)
{
    shutdown_skin_server();
    shutdown_guest_server();
    SDL_Quit();
    remove_portfile();
}

static void construct_main_window(int skin_argc, char* skin_argv[])
{
    INFO("construct main window\n");
    start_skin_server(11111, 0, 0);
#if 1
    if ( 0 > start_skin_client(skin_argc, skin_argv) ) {
        exit( -1 );
    }
#endif

}

static void parse_options(int argc, char* argv[], int* skin_argc, char*** skin_argv, int* qemu_argc, char*** qemu_argv)
{
    int i;
    int j;

// FIXME !!!
// TODO:
    for(i = 1; i < argc; ++i)
    {
        if(strncmp(argv[i], "--skin-args", 11) == 0)
        {
            *skin_argv = &(argv[i + 1]);
            break;
        }
    }
    for(j = i; j < argc; ++j)
    {
        if(strncmp(argv[j], "--qemu-args", 11) == 0)
        {
            *skin_argc = j - i - 1;

            *qemu_argc = argc - j - i + 1;
            *qemu_argv = &(argv[j]);

            argv[j] = argv[0];

            break;
        }
    }
}

void get_image_path(int qemu_argc, char* qemu_argv)
{
    int i;
    int j = 0;
    int name_len = 0;
    int prefix_len = 0;
    int suffix_len = 0;
    int max = 0;
    char *path = malloc(MAXPATH);
    name_len = strlen(qemu_argv);
    prefix_len = strlen(IMAGE_PATH_PREFIX);
    suffix_len = strlen(IMAGE_PATH_SUFFIX);
    max = name_len - suffix_len;
    for(i = prefix_len , j = 0; i < max; i++)
    {
        path[j++] = qemu_argv[i];
    }
    path[j] = '\0';

    write_portfile(path);
}

int qemu_main(int argc, char** argv, char** envp);

int main(int argc, char* argv[])
{
    tizen_base_port = get_sdb_base_port();

    int skin_argc = 0;
    char** skin_argv = NULL;

    int qemu_argc = 0;
    char** qemu_argv = NULL;

    parse_options(argc, argv, &skin_argc, &skin_argv, &qemu_argc, &qemu_argv);

    int i;

/*
    printf("%d\n", skin_argc);
    for(i = 0; i < skin_argc; ++i)
    {
        printf("%s\n", skin_argv[i]);
    }
*/

//  printf("%d\n", qemu_argc);
    INFO("Start emulator : =====================================\n");
    for(i = 0; i < qemu_argc; ++i)
    {
        INFO("%s ", qemu_argv[i]);
        if(strstr(qemu_argv[i], IMAGE_PATH_PREFIX) != NULL) {
            get_image_path(qemu_argc, qemu_argv[i]);
        }
    }
    INFO("\n");
    INFO("======================================================\n");

    sdb_setup();

    construct_main_window(skin_argc, skin_argv);

    //TODO get port number by args from emulator manager
    int guest_server_port = get_sdb_base_port() + SDB_UDP_SENSOR_INDEX;
    start_guest_server( guest_server_port );

    INFO("qemu main start!\n");
    qemu_main(qemu_argc, qemu_argv, NULL);

    exit_emulator();

    return 0;
}