Wwise Version
Wwise SDK 2019.2.14
AkSyncCaller.h
Go to the documentation of this file.
1 /*******************************************************************************
2 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
3 released in source code form as part of the SDK installer package.
4 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24  Version: <VERSION> Build: <BUILDNUMBER>
25  Copyright (c) <COPYRIGHTYEAR> Audiokinetic Inc.
26 *******************************************************************************/
27 
28 // AkSyncLoader.h
29 
30 /// \file
31 /// Class for synchronous calls of asynchronous models
32 
33 #ifndef _AK_SYNC_CALLER_H_
34 #define _AK_SYNC_CALLER_H_
35 
37 
38 namespace AK
39 {
40  namespace SoundEngine
41  {
42  /// AkSyncLoader: Init to create a sync event, call the asynchronous method, passing
43  /// it the address of this object as the cookie, then call Wait.
44  class AkSyncCaller
45  {
46  public:
47  /// Initialize.
49  {
50  if ( AKPLATFORM::AkCreateEvent( m_hEvent ) != AK_Success )
51  {
52  AKASSERT( !"Could not create synchronization event" );
53  return AK_Fail;
54  }
55  return AK_Success;
56  }
57 
58  /// Wait until the async function calls its callback.
59  AKRESULT Wait( AKRESULT in_eResult )
60  {
61  if ( in_eResult != AK_Success )
62  {
63  AKPLATFORM::AkDestroyEvent( m_hEvent );
64  return in_eResult;
65  }
66 
67  // Task queueing successful. Block until completion.
68  AKPLATFORM::AkWaitForEvent( m_hEvent );
69  AKPLATFORM::AkDestroyEvent( m_hEvent );
70 
71  return m_eResult;
72  }
73 
74  /// Call this from callback to release blocked thread.
75  inline void Done() { AKPLATFORM::AkSignalEvent( m_hEvent ); }
76 
77  AKRESULT m_eResult; ///< Operation result
78 
79  private:
80  AkEvent m_hEvent; ///< Sync event
81  };
82  }
83 }
84 
85 #endif // _AK_SYNC_CALLER_H_
AKRESULT Init()
Initialize.
Definition: AkSyncCaller.h:48
Audiokinetic namespace.
@ AK_Fail
The operation failed.
Definition: AkTypes.h:125
void Done()
Call this from callback to release blocked thread.
Definition: AkSyncCaller.h:75
semaphore_t AkEvent
Definition: AkTypes.h:77
void AkWaitForEvent(AkEvent &in_event)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:101
AKRESULT
Standard function call result.
Definition: AkTypes.h:122
@ AK_Success
The operation was successful.
Definition: AkTypes.h:124
void AkDestroyEvent(AkEvent &io_event)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:81
#define AKASSERT(Condition)
Definition: AkAssert.h:76
AKRESULT AkCreateEvent(AkEvent &out_event)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:58
AKRESULT m_eResult
Operation result.
Definition: AkSyncCaller.h:77
void AkSignalEvent(const AkEvent &in_event)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:112
AKRESULT Wait(AKRESULT in_eResult)
Wait until the async function calls its callback.
Definition: AkSyncCaller.h:59