blob: 5b2316046353ac6758a54ab1ecdccfa26e25b0d4 [file] [log] [blame]
Sungtak Leec7f9e2c2018-09-14 16:23:40 -07001/*
2 * Copyright (C) 2018 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#include "Observer.h"
18
19namespace android {
20namespace hardware {
21namespace media {
22namespace bufferpool {
23namespace V2_0 {
24namespace implementation {
25
26Observer::Observer() {
27}
28
29Observer::~Observer() {
30}
31
32// Methods from ::android::hardware::media::bufferpool::V2_0::IObserver follow.
33Return<void> Observer::onMessage(int64_t connectionId, uint32_t msgId) {
34 std::unique_lock<std::mutex> lock(mLock);
35 auto it = mClients.find(connectionId);
36 if (it != mClients.end()) {
37 const std::shared_ptr<BufferPoolClient> client = it->second.lock();
38 if (!client) {
39 mClients.erase(it);
40 } else {
41 lock.unlock();
42 client->receiveInvalidation(msgId);
43 }
44 }
45 return Void();
46}
47
48void Observer::addClient(ConnectionId connectionId,
49 const std::weak_ptr<BufferPoolClient> &wclient) {
50 std::lock_guard<std::mutex> lock(mLock);
51 for (auto it = mClients.begin(); it != mClients.end();) {
52 if (!it->second.lock() || it->first == connectionId) {
53 it = mClients.erase(it);
54 } else {
55 ++it;
56 }
57 }
58 mClients.insert(std::make_pair(connectionId, wclient));
59
60}
61
62void Observer::delClient(ConnectionId connectionId) {
63 std::lock_guard<std::mutex> lock(mLock);
64 mClients.erase(connectionId);
65}
66
67
68} // namespace implementation
69} // namespace V2_0
70} // namespace bufferpool
71} // namespace media
72} // namespace hardware
73} // namespace android