The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 1 | /* Copyright (C) 2007-2008 The Android Open Source Project |
| 2 | ** |
| 3 | ** This software is licensed under the terms of the GNU General Public |
| 4 | ** License version 2, as published by the Free Software Foundation, and |
| 5 | ** may be copied, distributed, and modified under those terms. |
| 6 | ** |
| 7 | ** This program is distributed in the hope that it will be useful, |
| 8 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | ** GNU General Public License for more details. |
| 11 | */ |
| 12 | #ifndef _android_qemud_h |
| 13 | #define _android_qemud_h |
| 14 | |
| 15 | #include "qemu-common.h" |
| 16 | |
David Turner | fff1ae5 | 2009-04-05 14:22:28 -0700 | [diff] [blame] | 17 | /* Support for the qemud-based 'services' in the emulator. |
| 18 | * Please read docs/ANDROID-QEMUD.TXT to understand what this is about. |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | /* initialize the qemud support code in the emulator |
| 22 | */ |
| 23 | |
| 24 | extern void android_qemud_init( void ); |
| 25 | |
| 26 | /* return the character driver state object that needs to be connected to the |
| 27 | * emulated serial port where all multiplexed channels go through. |
| 28 | */ |
| 29 | extern CharDriverState* android_qemud_get_cs( void ); |
| 30 | |
David Turner | fff1ae5 | 2009-04-05 14:22:28 -0700 | [diff] [blame] | 31 | /* returns in '*pcs' a CharDriverState object that will be connected to |
| 32 | * a single client in the emulated system for a given named service. |
| 33 | * |
| 34 | * this is only used to connect GPS and GSM service clients to the |
| 35 | * implementation that requires a CharDriverState object for legacy |
| 36 | * reasons. |
| 37 | * |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 38 | * returns 0 on success, or -1 in case of error |
| 39 | */ |
| 40 | extern int android_qemud_get_channel( const char* name, CharDriverState* *pcs ); |
| 41 | |
David Turner | fff1ae5 | 2009-04-05 14:22:28 -0700 | [diff] [blame] | 42 | /* set an explicit CharDriverState object for a given qemud communication channel. this |
| 43 | * is used to attach the channel to an external char driver device (e.g. one |
| 44 | * created with "-serial <device>") directly. |
| 45 | * |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 46 | * returns 0 on success, -1 on error |
| 47 | */ |
| 48 | extern int android_qemud_set_channel( const char* name, CharDriverState* peer_cs ); |
| 49 | |
| 50 | /* list of known qemud channel names */ |
| 51 | #define ANDROID_QEMUD_GSM "gsm" |
| 52 | #define ANDROID_QEMUD_GPS "gps" |
| 53 | #define ANDROID_QEMUD_CONTROL "control" |
The Android Open Source Project | 9877e2e | 2009-03-18 17:39:44 -0700 | [diff] [blame] | 54 | #define ANDROID_QEMUD_SENSORS "sensors" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 55 | |
The Android Open Source Project | 9877e2e | 2009-03-18 17:39:44 -0700 | [diff] [blame] | 56 | /* A QemudService service is used to connect one or more clients to |
| 57 | * a given emulator facility. Only one client can be connected at any |
| 58 | * given time, but the connection can be closed periodically. |
| 59 | */ |
| 60 | |
| 61 | typedef struct QemudClient QemudClient; |
| 62 | typedef struct QemudService QemudService; |
| 63 | |
| 64 | |
David 'Digit' Turner | 318e4f2 | 2009-05-25 18:01:03 +0200 | [diff] [blame] | 65 | /* A function that will be called when the client running in the emulated |
| 66 | * system has closed its connection to qemud. |
| 67 | */ |
The Android Open Source Project | 9877e2e | 2009-03-18 17:39:44 -0700 | [diff] [blame] | 68 | typedef void (*QemudClientClose)( void* opaque ); |
The Android Open Source Project | 9877e2e | 2009-03-18 17:39:44 -0700 | [diff] [blame] | 69 | |
David 'Digit' Turner | 318e4f2 | 2009-05-25 18:01:03 +0200 | [diff] [blame] | 70 | /* A function that will be called when the client sends a message to the |
| 71 | * service through qemud. |
| 72 | */ |
| 73 | typedef void (*QemudClientRecv) ( void* opaque, uint8_t* msg, int msglen, QemudClient* client ); |
| 74 | |
Ot ten Thije | 871da2a | 2010-09-20 10:29:22 +0100 | [diff] [blame^] | 75 | /* A function that will be called when the state of the client should be |
| 76 | * saved to a snapshot. |
| 77 | */ |
| 78 | typedef void (*QemudClientSave) ( QEMUFile* f, QemudClient* client, void* opaque ); |
| 79 | |
| 80 | /* A function that will be called when the state of the client should be |
| 81 | * restored from a snapshot. |
| 82 | */ |
| 83 | typedef int (*QemudClientLoad) ( QEMUFile* f, QemudClient* client, void* opaque ); |
| 84 | |
David 'Digit' Turner | 318e4f2 | 2009-05-25 18:01:03 +0200 | [diff] [blame] | 85 | /* Register a new client for a given service. |
| 86 | * 'clie_opaque' will be sent as the first argument to 'clie_recv' and 'clie_close' |
| 87 | * 'clie_recv' and 'clie_close' are both optional and may be NULL. |
| 88 | * |
| 89 | * You should typically use this function within a QemudServiceConnect callback |
| 90 | * (see below). |
| 91 | */ |
The Android Open Source Project | 9877e2e | 2009-03-18 17:39:44 -0700 | [diff] [blame] | 92 | extern QemudClient* qemud_client_new( QemudService* service, |
| 93 | int channel_id, |
| 94 | void* clie_opaque, |
| 95 | QemudClientRecv clie_recv, |
Ot ten Thije | 871da2a | 2010-09-20 10:29:22 +0100 | [diff] [blame^] | 96 | QemudClientClose clie_close, |
| 97 | QemudClientSave clie_save, |
| 98 | QemudClientLoad clie_load ); |
The Android Open Source Project | 9877e2e | 2009-03-18 17:39:44 -0700 | [diff] [blame] | 99 | |
David 'Digit' Turner | 318e4f2 | 2009-05-25 18:01:03 +0200 | [diff] [blame] | 100 | /* Enable framing on a given client channel. |
| 101 | */ |
The Android Open Source Project | 9877e2e | 2009-03-18 17:39:44 -0700 | [diff] [blame] | 102 | extern void qemud_client_set_framing( QemudClient* client, int enabled ); |
| 103 | |
David 'Digit' Turner | 318e4f2 | 2009-05-25 18:01:03 +0200 | [diff] [blame] | 104 | /* Send a message to a given qemud client |
| 105 | */ |
The Android Open Source Project | 9877e2e | 2009-03-18 17:39:44 -0700 | [diff] [blame] | 106 | extern void qemud_client_send ( QemudClient* client, const uint8_t* msg, int msglen ); |
David 'Digit' Turner | 318e4f2 | 2009-05-25 18:01:03 +0200 | [diff] [blame] | 107 | |
| 108 | /* Force-close the connection to a given qemud client. |
| 109 | */ |
The Android Open Source Project | 9877e2e | 2009-03-18 17:39:44 -0700 | [diff] [blame] | 110 | extern void qemud_client_close( QemudClient* client ); |
| 111 | |
| 112 | |
David 'Digit' Turner | 318e4f2 | 2009-05-25 18:01:03 +0200 | [diff] [blame] | 113 | /* A function that will be called each time a new client in the emulated |
| 114 | * system tries to connect to a given qemud service. This should typically |
| 115 | * call qemud_client_new() to register a new client. |
| 116 | */ |
The Android Open Source Project | 9877e2e | 2009-03-18 17:39:44 -0700 | [diff] [blame] | 117 | typedef QemudClient* (*QemudServiceConnect)( void* opaque, QemudService* service, int channel ); |
| 118 | |
Ot ten Thije | 871da2a | 2010-09-20 10:29:22 +0100 | [diff] [blame^] | 119 | /* A function that will be called when the state of the service should be |
| 120 | * saved to a snapshot. |
| 121 | */ |
| 122 | typedef void (*QemudServiceSave) ( QEMUFile* f, QemudService* service, void* opaque ); |
| 123 | |
| 124 | /* A function that will be called when the state of the service should be |
| 125 | * restored from a snapshot. |
| 126 | */ |
| 127 | typedef int (*QemudServiceLoad) ( QEMUFile* f, QemudService* service, void* opaque ); |
| 128 | |
David 'Digit' Turner | 318e4f2 | 2009-05-25 18:01:03 +0200 | [diff] [blame] | 129 | /* Register a new qemud service. |
| 130 | * 'serv_opaque' is the first parameter to 'serv_connect' |
| 131 | */ |
The Android Open Source Project | 9877e2e | 2009-03-18 17:39:44 -0700 | [diff] [blame] | 132 | extern QemudService* qemud_service_register( const char* serviceName, |
| 133 | int max_clients, |
| 134 | void* serv_opaque, |
Ot ten Thije | 871da2a | 2010-09-20 10:29:22 +0100 | [diff] [blame^] | 135 | QemudServiceConnect serv_connect, |
| 136 | QemudServiceSave serv_save, |
| 137 | QemudServiceLoad serv_load); |
The Android Open Source Project | 9877e2e | 2009-03-18 17:39:44 -0700 | [diff] [blame] | 138 | |
David 'Digit' Turner | 318e4f2 | 2009-05-25 18:01:03 +0200 | [diff] [blame] | 139 | /* Sends a message to all clients of a given service. |
| 140 | */ |
The Android Open Source Project | 9877e2e | 2009-03-18 17:39:44 -0700 | [diff] [blame] | 141 | extern void qemud_service_broadcast( QemudService* sv, |
| 142 | const uint8_t* msg, |
| 143 | int msglen ); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 144 | |
| 145 | #endif /* _android_qemud_h */ |