The Android Open Source Project | 52d4c30 | 2009-03-03 19:29:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Fake device support. |
| 5 | */ |
| 6 | #ifndef _WRAPSIM_FAKEDEV_H |
| 7 | #define _WRAPSIM_FAKEDEV_H |
| 8 | |
| 9 | #include <sys/types.h> |
| 10 | #include <sys/uio.h> |
| 11 | #include <errno.h> |
| 12 | |
| 13 | typedef struct FakeDev FakeDev; |
| 14 | |
| 15 | typedef int (*Fake_close)(FakeDev* dev, int); |
| 16 | typedef ssize_t (*Fake_read)(FakeDev* dev, int, void*, size_t); |
| 17 | typedef ssize_t (*Fake_readv)(FakeDev* dev, int, const struct iovec*, int); |
| 18 | typedef ssize_t (*Fake_write)(FakeDev* dev, int, const void*, size_t); |
| 19 | typedef ssize_t (*Fake_writev)(FakeDev* dev, int, const struct iovec*, int); |
| 20 | typedef void* (*Fake_mmap)(FakeDev* dev, void*, size_t, int, int, int, __off_t); |
| 21 | typedef int (*Fake_ioctl)(FakeDev* dev, int, int, void*); |
| 22 | |
| 23 | /* |
| 24 | * An open fake device entry. |
| 25 | */ |
| 26 | struct FakeDev { |
| 27 | /* string, for debugging; usually orig. device name */ |
| 28 | char* debugName; |
| 29 | |
| 30 | /* state bucket */ |
| 31 | void* state; |
| 32 | |
| 33 | /* the file descriptor we're associated with */ |
| 34 | int fd; |
| 35 | |
| 36 | /* in some cases we use a pair; this is the other one */ |
| 37 | int otherFd; |
| 38 | |
| 39 | /* |
| 40 | * Device functions we provide. |
| 41 | * |
| 42 | * All other file descriptor operations should fail, usually with EBADF. |
| 43 | */ |
| 44 | Fake_close close; |
| 45 | Fake_read read; |
| 46 | Fake_readv readv; |
| 47 | Fake_write write; |
| 48 | Fake_writev writev; |
| 49 | Fake_mmap mmap; // handles both mmap() and mmap64() |
| 50 | Fake_ioctl ioctl; |
| 51 | }; |
| 52 | |
| 53 | /* |
| 54 | * If a handler isn't defined for a syscall, we return EMLINK so that it's |
| 55 | * obvious when the error is generated by us. |
| 56 | */ |
| 57 | #define kNoHandlerError EMLINK |
| 58 | |
| 59 | /* |
| 60 | * Fake file descriptors begin here. This should be chosen such that no |
| 61 | * real descriptor is ever at or above this value. |
| 62 | */ |
| 63 | #define kFakeFdBase 512 |
| 64 | #define kMaxFakeFdCount 256 |
| 65 | |
| 66 | /* |
| 67 | * Create a new, completely fake device entry. |
| 68 | */ |
| 69 | FakeDev* wsCreateFakeDev(const char* debugName); |
| 70 | |
| 71 | /* |
| 72 | * Create a new, mostly fake device entry. |
| 73 | */ |
| 74 | FakeDev* wsCreateRealFakeDev(const char* debugName); |
| 75 | |
| 76 | /* |
| 77 | * Free a fake device entry. |
| 78 | */ |
| 79 | void wsFreeFakeDev(FakeDev* dev); |
| 80 | |
| 81 | /* |
| 82 | * Given a file descriptor, find the corresponding fake device. Returns |
| 83 | * NULL if the fd doesn't correspond to one of our entries. |
| 84 | */ |
| 85 | FakeDev* wsFakeDevFromFd(int fd); |
| 86 | |
| 87 | /* |
| 88 | * Check to see if this open() call is on a device we want to spoof. |
| 89 | * |
| 90 | * Returns a "fake" file descriptor on success, <0 on error. |
| 91 | */ |
| 92 | int wsInterceptDeviceOpen(const char* pathName, int flags); |
| 93 | |
| 94 | /* |
| 95 | * Check to see if this access() call is on a device we want to spoof. |
| 96 | * |
| 97 | * Returns 0 if the device can be fake-accessed, -1 if it can't, -2 |
| 98 | * if it can't and we don't want to allow fallback to the host-device. |
| 99 | */ |
| 100 | int wsInterceptDeviceAccess(const char* pathName, int flags); |
| 101 | |
| 102 | /* |
| 103 | * Devices. |
| 104 | */ |
| 105 | FakeDev* wsOpenDevAudio(const char* pathName, int flags); |
| 106 | FakeDev* wsOpenDevConsoleTty(const char* pathName, int flags); |
| 107 | FakeDev* wsOpenDevEvent(const char* pathName, int flags); |
| 108 | FakeDev* wsOpenDevFb(const char* pathName, int flags); |
| 109 | FakeDev* wsOpenDevLog(const char* pathName, int flags); |
| 110 | FakeDev* wsOpenDevPower(const char* pathName, int flags); |
Marco Nelissen | 1b2bd1d | 2009-04-30 14:11:03 -0700 | [diff] [blame] | 111 | FakeDev* wsOpenSysPower(const char* pathName, int flags); |
The Android Open Source Project | 52d4c30 | 2009-03-03 19:29:09 -0800 | [diff] [blame] | 112 | FakeDev* wsOpenDevVibrator(const char* pathName, int flags); |
| 113 | |
| 114 | /* |
| 115 | * Performs key remapping and sends the event to the global input event device. |
| 116 | */ |
| 117 | void wsSendSimKeyEvent(int key, int isDown); |
| 118 | |
| 119 | /* |
| 120 | * Send a touch event to the global input event device. |
| 121 | */ |
| 122 | void wsSendSimTouchEvent(int action, int x, int y); |
| 123 | |
| 124 | #endif /*_WRAPSIM_FAKEDEV_H*/ |