• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2005 The Android Open Source Project
3 //
4 // Miscellaneous definitions and declarations used for interaction
5 // between the device and the simulator.
6 //
7 // This header is included on both sides, so try not to include
8 // any other headers from here.
9 //
10 #ifndef _RUNTIME_SIMULATOR_H
11 #define _RUNTIME_SIMULATOR_H
12 
13 #include "MessageStream.h"
14 #include "Shmem.h"
15 //#include "utils/RefBase.h"
16 #include "utils/Log.h"
17 
18 namespace android {
19 
20 #define ANDROID_PIPE_NAME "runtime"
21 
22 /*
23  * Hold simulator state.
24  */
25 class Simulator {
26 public:
27     Simulator(void);
28     ~Simulator(void);
29 
30     /*
31      * Commands exchanged between simulator and runtime.
32      */
33     typedef enum Command {
34         kCommandUnknown = 0,
35 
36         /* sent from sim to runtime */
37         kCommandGoAway,             // sim says: go away, I'm busy
38         kCommandConfigDone,         // sim says: done sending config
39         kCommandQuit,               // quit nicely
40         kCommandNewPGroup,          // process group management
41         kCommandKeyDown,            // key has been pressed
42         kCommandKeyUp,              // key has been released
43         kCommandTouch,              // finger touched/lifted/dragged
44 
45         /* sent from runtime to sim */
46         kCommandNewPGroupCreated,    // send process group as argument
47         kCommandRuntimeReady,       // we're initialized and about to start
48         kCommandUpdateDisplay,      // display has been updated
49         kCommandVibrate,            // vibrate on or off
50     } Command;
51 
52     typedef enum TouchMode {
53         kTouchDown = 0,
54         kTouchUp = 1,
55         kTouchDrag = 2
56     } TouchMode;
57 
58     /*
59      * Some parameters for config exchange.
60      */
61     enum {
62         kDisplayConfigMagic = 0x44495350,
63         kValuesPerDisplay = 5,
64     };
65 
66     /*
67      * Set up communication with parent process.
68      */
69     //bool create(ParentProcess* pParent);
70 
71     /*
72      * Set up communication with detached simulator.
73      */
74     bool create(Pipe* reader, Pipe* writer);
75 
76     /*
77      * Tell simulator that we're ready to go.
78      */
79     void sendRuntimeReady(void);
80 
81     /*
82      * Tell the simulator that a display has been refreshed.
83      */
84     void sendDisplayUpdate(int displayIndex);
85 
86     /*
87      * Tell the simulator to turn the vibrator on or off
88      */
89     void sendVibrate(int vibrateOn);
90 
91     /*
92      * Get a pointer to the shared memory for the Nth display.
93      */
94     Shmem* getGraphicsBuffer(int displayIndex);
95 
96     /*
97      * Return a copy of our input pipe so the event system can monitor
98      * it for pending activity.
99      */
getReadPipe(void)100     Pipe* getReadPipe(void) { return mStream.getReadPipe(); }
101 
102     /*
103      * Retrieve the next command from the parent.  Returns NO_ERROR
104      * if all is okay, WOULD_BLOCK if blocking is false and there
105      * are no pending commands, or INVALID_OPERATION if the simulator
106      * has disappeared.
107      */
108     int getNextKey(int32_t* outKey, bool* outDown);
109 
110     /*
111      * Log system callback function.
112      */
113     static void writeLogMsg(const android_LogBundle* pBundle);
114 
115 private:
116     bool finishCreate(void);
117     bool handleDisplayConfig(const long* pData, int length);
118 
119     MessageStream   mStream;
120 };
121 
122 }; // namespace android
123 
124 #endif // _RUNTIME_SIMULATOR_H
125