1 /*
2  * Copyright (C) 2022 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 #pragma once
18 
19 #include <map>
20 #include <memory>
21 #include <mutex>
22 #include <aidl/android/hardware/media/bufferpool2/BnObserver.h>
23 #include <bufferpool2/BufferPoolTypes.h>
24 
25 namespace aidl::android::hardware::media::bufferpool2::implementation {
26 
27 class BufferPoolClient;
28 
29 struct Observer : public BnObserver {
30     ::ndk::ScopedAStatus onMessage(int64_t in_connectionId, int32_t in_msgId) override;
31 
32     ~Observer();
33 
34     void addClient(ConnectionId connectionId,
35                    const std::weak_ptr<BufferPoolClient> &wclient);
36 
37     void delClient(ConnectionId connectionId);
38 
39 private:
40     Observer();
41 
42     friend class ::ndk::SharedRefBase;
43 
44     std::mutex mLock;
45     std::map<ConnectionId, const std::weak_ptr<BufferPoolClient>> mClients;
46 };
47 
48 }  // namespace aidl::android::hardware::media::bufferpool2::implementation
49 
50