Home | History | Annotate | Download | only in app
      1 //
      2 // Copyright 2005 The Android Open Source Project
      3 //
      4 // Contents of the "user event" sent from the device thread.
      5 //
      6 #ifndef _SIM_USER_EVENT_MESSAGE_H
      7 #define _SIM_USER_EVENT_MESSAGE_H
      8 
      9 #include "utils.h"
     10 #include "LogMessage.h"
     11 
     12 /*
     13  * This gets stuffed into a UserEvent, which is posted to the main thread
     14  * from a worker thread.
     15  *
     16  * The object does NOT own anything you stuff into it.  It's just a vehicle
     17  * for carting data from one thread to another in a wxWidgets-safe manner,
     18  * usually as pointers to data that can be shared between threads.
     19  */
     20 class UserEventMessage {
     21 public:
     22     /*
     23      * What type of message is this?
     24      */
     25     typedef enum UEMType {
     26         kUnknown = 0,
     27 
     28         kRuntimeStarted,
     29         kRuntimeStopped,
     30         kErrorMessage,      // message in mString
     31         kLogMessage,        // ptr to heap-allocated LogMessage
     32         kExternalRuntime,   // external runtime wants to party
     33     } UEMType;
     34 
     35     UserEventMessage(void)
     36         : mType(kUnknown), mpLogMessage(NULL)
     37         {}
     38     ~UserEventMessage(void) {
     39     }
     40 
     41     /*
     42      * Create one of our various messages.
     43      */
     44     void CreateRuntimeStarted(void) {
     45         mType = kRuntimeStarted;
     46     }
     47     void CreateRuntimeStopped(void) {
     48         mType = kRuntimeStopped;
     49     }
     50     void CreateErrorMessage(wxString& str) {
     51         mType = kErrorMessage;
     52         mString = str;
     53     }
     54     void CreateLogMessage(LogMessage* pLogMessage) {
     55         mType = kLogMessage;
     56         mpLogMessage = pLogMessage;
     57     }
     58     void CreateExternalRuntime(android::Pipe* reader, android::Pipe* writer) {
     59         mType = kExternalRuntime;
     60         mReader = reader;
     61         mWriter = writer;
     62     }
     63 
     64     /*
     65      * Accessors.
     66      */
     67     UEMType GetType(void) const { return mType; }
     68     const wxString& GetString(void) const { return mString; }
     69     LogMessage* GetLogMessage(void) const { return mpLogMessage; }
     70     android::Pipe* GetReader(void) const { return mReader; }
     71     android::Pipe* GetWriter(void) const { return mWriter; }
     72 
     73 private:
     74     UserEventMessage& operator=(const UserEventMessage&);   // not implemented
     75     UserEventMessage(const UserEventMessage&);              // not implemented
     76 
     77     UEMType     mType;
     78     wxString    mString;            // for kErrorMessage
     79     LogMessage* mpLogMessage;       // for kLogMessage
     80     android::Pipe*  mReader;        // for kExternalRuntime
     81     android::Pipe*  mWriter;        // for kExternalRuntime
     82 };
     83 
     84 #endif // _SIM_USER_EVENT_MESSAGE_H
     85