Home | History | Annotate | Download | only in include
      1 /*
      2 // Copyright(c)2014 IntelCorporation
      3 //
      4 // LicensedundertheApacheLicense,Version2.0(the"License");
      5 // youmaynotusethisfileexceptincompliancewiththeLicense.
      6 // YoumayobtainacopyoftheLicenseat
      7 //
      8 // http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unlessrequiredbyapplicablelaworagreedtoinwriting,software
     11 // distributedundertheLicenseisdistributedonan"ASIS"BASIS,
     12 // WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.
     13 // SeetheLicenseforthespecificlanguagegoverningpermissionsand
     14 // limitationsundertheLicense.
     15 */
     16 #ifndef UEVENT_OBSERVER_H
     17 #define UEVENT_OBSERVER_H
     18 
     19 #include <utils/KeyedVector.h>
     20 #include <utils/String8.h>
     21 #include <SimpleThread.h>
     22 
     23 namespace android {
     24 namespace intel {
     25 
     26 typedef void (*UeventListenerFunc)(void *data);
     27 
     28 class UeventObserver
     29 {
     30 public:
     31     UeventObserver();
     32     virtual ~UeventObserver();
     33 
     34 public:
     35     bool initialize();
     36     void deinitialize();
     37     void start();
     38     void registerListener(const char *event, UeventListenerFunc func, void *data);
     39 
     40 private:
     41     DECLARE_THREAD(UeventObserverThread, UeventObserver);
     42     void onUevent();
     43 
     44 private:
     45     enum {
     46         UEVENT_MSG_LEN = 4096,
     47     };
     48 
     49     char mUeventMessage[UEVENT_MSG_LEN];
     50     int mUeventFd;
     51     int mExitRDFd;
     52     int mExitWDFd;
     53     struct UeventListener {
     54         UeventListenerFunc func;
     55         void *data;
     56     };
     57     KeyedVector<String8, UeventListener*> mListeners;
     58 };
     59 
     60 } // namespace intel
     61 } // namespace android
     62 
     63 #endif
     64 
     65