• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2019, The Android Open Source Project
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 
17 #ifndef NETD_SERVER_OEM_NETD_LISTENER_H
18 #define NETD_SERVER_OEM_NETD_LISTENER_H
19 
20 #include <map>
21 #include <mutex>
22 
23 #include <android-base/thread_annotations.h>
24 #include "com/android/internal/net/BnOemNetd.h"
25 #include "com/android/internal/net/IOemNetdUnsolicitedEventListener.h"
26 
27 namespace com {
28 namespace android {
29 namespace internal {
30 namespace net {
31 
32 class OemNetdListener : public BnOemNetd {
33   public:
34     using OemUnsolListenerMap = std::map<const ::android::sp<IOemNetdUnsolicitedEventListener>,
35                                          const ::android::sp<::android::IBinder::DeathRecipient>>;
36 
37     OemNetdListener() = default;
38     ~OemNetdListener() = default;
39     static ::android::sp<::android::IBinder> getListener();
40 
41     ::android::binder::Status isAlive(bool* alive) override;
42     ::android::binder::Status registerOemUnsolicitedEventListener(
43             const ::android::sp<IOemNetdUnsolicitedEventListener>& listener) override;
44 
45   private:
46     std::mutex mMutex;
47     std::mutex mOemUnsolicitedMutex;
48 
49     ::android::sp<::android::IBinder> mIBinder GUARDED_BY(mMutex);
50     OemUnsolListenerMap mOemUnsolListenerMap GUARDED_BY(mOemUnsolicitedMutex);
51 
52     ::android::sp<::android::IBinder> getIBinder() EXCLUDES(mMutex);
53 
54     void registerOemUnsolicitedEventListenerInternal(
55             const ::android::sp<IOemNetdUnsolicitedEventListener>& listener)
56             EXCLUDES(mOemUnsolicitedMutex);
57     void unregisterOemUnsolicitedEventListenerInternal(
58             const ::android::sp<IOemNetdUnsolicitedEventListener>& listener)
59             EXCLUDES(mOemUnsolicitedMutex);
60 };
61 
62 }  // namespace net
63 }  // namespace internal
64 }  // namespace android
65 }  // namespace com
66 
67 #endif  // NETD_SERVER_OEM_NETD_LISTENER_H