1/*
2// Copyright (c) 2014 Intel Corporation 
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#ifndef UEVENT_OBSERVER_H
17#define UEVENT_OBSERVER_H
18
19#include <utils/KeyedVector.h>
20#include <utils/String8.h>
21#include <common/base/SimpleThread.h>
22
23namespace android {
24namespace intel {
25
26typedef void (*UeventListenerFunc)(void *data);
27
28class UeventObserver
29{
30public:
31    UeventObserver();
32    virtual ~UeventObserver();
33
34public:
35    bool initialize();
36    void deinitialize();
37    void start();
38    void registerListener(const char *event, UeventListenerFunc func, void *data);
39
40private:
41    DECLARE_THREAD(UeventObserverThread, UeventObserver);
42    void onUevent();
43
44private:
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