aboutsummaryrefslogtreecommitdiff
path: root/monitor-android.c
blob: 5c2eb108fbd406a28ab51dbbe7edde2982006b52 (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
#include "monitor/monitor.h"

#include <stdarg.h>
#include "hw/hw.h"

struct Monitor {
    CharDriverState *chr;
    int mux_out;
    // int reset_seen;
    int flags;
    // int suspend_cnt;
    uint8_t outbuf[1024];
    int outbuf_index;
    // ReadLineState *rs;
    // CPUOldState *mon_cpu;
    // BlockDriverCompletionFunc *password_completion_cb;
    // void *password_opaque;
    QLIST_ENTRY(Monitor) entry;
    //int has_quit;
#ifdef CONFIG_ANDROID
    void*            fake_opaque;
    MonitorFakeFunc  fake_func;
    int64_t          fake_count;

#endif
};

// Minimalistic / fake implementation of the QEMU Monitor.

Monitor* cur_mon;

/* Return non-zero iff we have a current monitor, and it is in QMP mode.  */
int monitor_cur_is_qmp(void)
{
    return 0;
}

Monitor*
monitor_fake_new(void* opaque, MonitorFakeFunc cb)
{
    Monitor* mon;

    assert(cb != NULL);
    mon = g_malloc0(sizeof(*mon));
    mon->fake_opaque = opaque;
    mon->fake_func   = cb;
    mon->fake_count  = 0;

    return mon;
}

int
monitor_fake_get_bytes(Monitor* mon)
{
    assert(mon->fake_func != NULL);
    return mon->fake_count;
}

void
monitor_fake_free(Monitor* mon)
{
    assert(mon->fake_func != NULL);
    free(mon);
}

/* This replaces the definition in monitor.c which is in a
 * #ifndef CONFIG_ANDROID .. #endif block.
 */
void monitor_flush(Monitor *mon)
{
    if (!mon)
        return;

    if (mon->fake_func != NULL) {
        mon->fake_func(mon->fake_opaque, (void*)mon->outbuf, mon->outbuf_index);
        mon->outbuf_index = 0;
        mon->fake_count += mon->outbuf_index;
    } else if (!mon->mux_out) {
        qemu_chr_write(mon->chr, mon->outbuf, mon->outbuf_index);
        mon->outbuf_index = 0;
    }
}

/* flush at every end of line or if the buffer is full */
static void monitor_puts(Monitor *mon, const char *str)
{
    char c;

    if (!mon)
        return;

    for(;;) {
        c = *str++;
        if (c == '\0')
            break;
        if (c == '\n')
            mon->outbuf[mon->outbuf_index++] = '\r';
        mon->outbuf[mon->outbuf_index++] = c;
        if (mon->outbuf_index >= (sizeof(mon->outbuf) - 1)
            || c == '\n')
            monitor_flush(mon);
    }
}

void monitor_vprintf(Monitor* mon, const char* fmt, va_list args) {
    char buf[4096];
    vsnprintf(buf, sizeof(buf), fmt, args);
    monitor_puts(mon, buf);
}

void monitor_printf(Monitor *mon, const char *fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    monitor_vprintf(mon, fmt, ap);
    va_end(ap);
}

void monitor_print_filename(Monitor *mon, const char *filename)
{
    int i;

    for (i = 0; filename[i]; i++) {
        switch (filename[i]) {
        case ' ':
        case '"':
        case '\\':
            monitor_printf(mon, "\\%c", filename[i]);
            break;
        case '\t':
            monitor_printf(mon, "\\t");
            break;
        case '\r':
            monitor_printf(mon, "\\r");
            break;
        case '\n':
            monitor_printf(mon, "\\n");
            break;
        default:
            monitor_printf(mon, "%c", filename[i]);
            break;
        }
    }
}

void monitor_protocol_event(MonitorEvent event, QObject *data)
{
    /* XXX: TODO */
}

void monitor_set_error(Monitor *mon, QError *qerror)
{
    QDECREF(qerror);
}

void monitor_init(CharDriverState* cs, int flags) {
    // Nothing.
}

/* boot_set handler */
static QEMUBootSetHandler *qemu_boot_set_handler = NULL;
static void *boot_opaque;

void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
{
    qemu_boot_set_handler = func;
    boot_opaque = opaque;
}