blob: 447665b82b3c85cdf21e6e08a41d54a1288b41b7 [file] [log] [blame]
Phil Burk11e8d332017-05-24 09:59:02 -07001/*
2 * Copyright (C) 2017 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 ANDROID_AAUDIO_AAUDIO_CLIENT_TRACKER_H
18#define ANDROID_AAUDIO_AAUDIO_CLIENT_TRACKER_H
19
20#include <map>
21#include <mutex>
22#include <set>
23
24#include <utils/Singleton.h>
25
26#include <aaudio/AAudio.h>
27#include "binding/IAAudioClient.h"
28#include "AAudioService.h"
29
30namespace aaudio {
31
32class AAudioClientTracker : public android::Singleton<AAudioClientTracker>{
33public:
34 AAudioClientTracker();
35 ~AAudioClientTracker() = default;
36
37 aaudio_result_t registerClient(pid_t pid, const android::sp<android::IAAudioClient>& client);
38
39 void unregisterClient(pid_t pid);
40
41 aaudio_result_t registerClientStream(pid_t pid,
42 android::sp<AAudioServiceStreamBase> serviceStream);
43
44 aaudio_result_t unregisterClientStream(pid_t pid,
45 android::sp<AAudioServiceStreamBase> serviceStream);
46
47 android::AAudioService *getAAudioService() const {
48 return mAAudioService;
49 }
50
51 void setAAudioService(android::AAudioService *aaudioService) {
52 mAAudioService = aaudioService;
53 }
54
55private:
56 class NotificationClient : public IBinder::DeathRecipient {
57 public:
58 NotificationClient(pid_t pid);
59 virtual ~NotificationClient();
60
61 aaudio_result_t registerClientStream(android::sp<AAudioServiceStreamBase> serviceStream);
62
63 aaudio_result_t unregisterClientStream(android::sp<AAudioServiceStreamBase> serviceStream);
64
65 // IBinder::DeathRecipient
66 virtual void binderDied(const android::wp<IBinder>& who);
67
68 protected:
69 std::mutex mLock;
70 const pid_t mProcessId;
71 std::set<android::sp<AAudioServiceStreamBase>> mStreams;
72 };
73
74 std::mutex mLock;
75 std::map<pid_t, android::sp<NotificationClient>> mNotificationClients;
76 android::AAudioService *mAAudioService = nullptr;
77};
78
79} /* namespace aaudio */
80
81#endif //ANDROID_AAUDIO_AAUDIO_CLIENT_TRACKER_H