blob: 991258001063d87bc52d238da3c13b69892100ff [file] [log] [blame]
Andy Hunge8986cc2023-05-15 18:20:49 -07001/*
2 * Copyright (C) 2023 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
19namespace android {
20
21class SyncEvent;
22
23typedef void (*sync_event_callback_t)(const wp<SyncEvent>& event) ;
24
25class SyncEvent : public RefBase {
26public:
27 SyncEvent(AudioSystem::sync_event_t type,
28 audio_session_t triggerSession,
29 audio_session_t listenerSession,
30 sync_event_callback_t callBack,
31 const wp<RefBase>& cookie)
32 : mType(type), mTriggerSession(triggerSession), mListenerSession(listenerSession),
33 mCallback(callBack), mCookie(cookie)
34 {}
35
36 virtual ~SyncEvent() {}
37
38 void trigger() {
39 Mutex::Autolock _l(mLock);
40 if (mCallback) mCallback(wp<SyncEvent>(this));
41 }
42 bool isCancelled() const { Mutex::Autolock _l(mLock); return (mCallback == NULL); }
43 void cancel() { Mutex::Autolock _l(mLock); mCallback = NULL; }
44 AudioSystem::sync_event_t type() const { return mType; }
45 audio_session_t triggerSession() const { return mTriggerSession; }
46 audio_session_t listenerSession() const { return mListenerSession; }
47 wp<RefBase> cookie() const { return mCookie; }
48
49private:
50 const AudioSystem::sync_event_t mType;
51 const audio_session_t mTriggerSession;
52 const audio_session_t mListenerSession;
53 sync_event_callback_t mCallback;
54 const wp<RefBase> mCookie;
55 mutable Mutex mLock;
56};
57
58} // namespace android