| AAX SDK 2.8.0 Avid Audio Extensions Development Kit

- Welcome
- Manual
- Classes
- Files
- Lists
- Support

- File List
- File Members

Loading...
Searching...
No Matches
AAX_CPacketDispatcher.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 *
4 * Copyright 2013-2017, 2023-2024 Avid Technology, Inc.
5 * All rights reserved.
6 *
7 * This file is part of the Avid AAX SDK.
8 *
9 * The AAX SDK is subject to commercial or open-source licensing.
10 *
11 * By using the AAX SDK, you agree to the terms of both the Avid AAX SDK License
12 * Agreement and Avid Privacy Policy.
13 *
14 * AAX SDK License: https://developer.avid.com/aax
15 * Privacy Policy: https://www.avid.com/legal/privacy-policy-statement
16 *
17 * Or: You may also use this code under the terms of the GPL v3 (see
18 * www.gnu.org/licenses).
19 *
20 * THE AAX SDK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 * EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 * DISCLAIMED.
23 *
24 */
25
32/*================================================================================================*/
33
34
35#ifndef AAX_CPACKETDISPATCHER_H
36#define AAX_CPACKETDISPATCHER_H
37
38#include "AAX.h"
39#include "AAX_IController.h"
40#include "AAX_CMutex.h"
41
42#include <string>
43#include <map>
44
45
54 class AAX_CPacket
55{
56 public:
57 AAX_CPacket(AAX_CFieldIndex inFieldIndex) : mID(inFieldIndex), mDirty(true), mDataSize(0) {}
58 ~AAX_CPacket() {}
59
60 template<typename DataType>
61 DataType* GetPtr()
62 {
63 mDataSize = sizeof(DataType);
64 void * data = mPacketData.Get(mDataSize);
65 return reinterpret_cast<DataType*> (data);
66 }
67
68 void SetDirty(bool iDirty) { mDirty = iDirty; };
69 bool IsDirty() const { return mDirty; };
70
71 AAX_CFieldIndex GetID() const { return mID; };
72 uint32_t GetSize() const { return mDataSize; }
73
74 private:
75 AAX_CFieldIndex mID;
76 bool mDirty;
77 uint32_t mDataSize;
78
79 private:
80 struct SPacketData
81 {
82 public:
83 SPacketData();
84 ~SPacketData();
85 const void* Get() const;
86 void* Get(size_t newSize) const;
87 private:
88 mutable void* mData;
89 } mPacketData;
90};
91
92// GetPtr() specialization for void*
93 template <>
94 inline const void*
95AAX_CPacket::GetPtr<const void>()
96{
97 return mPacketData.Get();
98}
99
100
103 struct AAX_IPacketHandler
104{
105 virtual ~AAX_IPacketHandler() {};
106 virtual AAX_IPacketHandler* Clone() const = 0;
107 virtual AAX_Result Call( AAX_CParamID inParamID, AAX_CPacket& ioPacket ) const = 0;
108};
109
112 template<class TWorker>
113 class AAX_CPacketHandler : public AAX_IPacketHandler
114{
115 typedef AAX_Result(TWorker::*fPt2Fn)(AAX_CPacket&);
116 typedef AAX_Result(TWorker::*fPt2FnEx)(AAX_CParamID, AAX_CPacket&);
117
118 public:
119 AAX_CPacketHandler( TWorker* iPt2Object, fPt2Fn infPt )
120 : pt2Object(iPt2Object), fpt(infPt), fptEx(NULL) {}
121
122 AAX_CPacketHandler( TWorker* iPt2Object, fPt2FnEx infPt )
123 : pt2Object(iPt2Object), fpt(NULL), fptEx(infPt) {}
124
125 AAX_IPacketHandler* Clone() const
126 {
127 return new AAX_CPacketHandler(*this);
128 }
129
130 AAX_Result Call( AAX_CParamID inParamID, AAX_CPacket& ioPacket ) const
131 {
132 if (fptEx)
133 return (*pt2Object.*fptEx)( inParamID, ioPacket);
134 else if (fpt)
135 return (*pt2Object.*fpt)( ioPacket);
136 else
137 return AAX_ERROR_NULL_OBJECT;
138 }
139
140 protected:
141 TWorker * pt2Object; // pointer to object
142 fPt2Fn fpt ; // pointer to member function
143 fPt2FnEx fptEx ; // pointer to member function
144};
145
146
147 class AAX_IEffectParameters;
148
162 class AAX_CPacketDispatcher
163{
164 typedef std::map<AAX_CFieldIndex, AAX_CPacket*> PacketsHolder;
165 typedef std::multimap<std::string, std::pair<AAX_CPacket*, AAX_IPacketHandler*> > PacketsHandlersMap;
166
167 public:
168 AAX_CPacketDispatcher();
169 ~AAX_CPacketDispatcher();
170
171 void Initialize( AAX_IController* iPlugIn, AAX_IEffectParameters* iEffectParameters);
172
173 AAX_Result RegisterPacket( AAX_CParamID paramID, AAX_CFieldIndex portID, const AAX_IPacketHandler* iHandler);
174
175 template <class TWorker, typename Func>
176 AAX_Result RegisterPacket( AAX_CParamID paramID, AAX_CFieldIndex portID,
177 TWorker* iPt2Object, Func infPt)
178 {
179 AAX_CPacketHandler<TWorker> handler(iPt2Object, infPt);
180 return RegisterPacket(paramID, portID, &handler);
181 }
182
183 AAX_Result RegisterPacket( AAX_CParamID paramID, AAX_CFieldIndex portID)
184 {
185 AAX_CPacketHandler<AAX_CPacketDispatcher> handler(this, &AAX_CPacketDispatcher::GenerateSingleValuePacket);
186 return RegisterPacket(paramID, portID, &handler);
187 }
188
189 AAX_Result SetDirty(AAX_CParamID paramID, bool iDirty = true);
190
191 AAX_Result Dispatch();
192
193 AAX_Result GenerateSingleValuePacket( AAX_CParamID iParam, AAX_CPacket& ioPacket);
194
195 private:
196 PacketsHolder mPacketsHolder;
197 PacketsHandlersMap mPacketsHandlers;
198 AAX_IController* mController;
199 AAX_IEffectParameters* mEffectParameters;
200
201 AAX_CMutex mLockGuard;
202};
203
204
205#endif // AAX_CPACKETDISPATCHER_H
AAX_CMutex.h
Mutex.
AAX_ERROR_NULL_OBJECT
@ AAX_ERROR_NULL_OBJECT
Definition: AAX_Errors.h:54
AAX.h
Various utility definitions for AAX.
AAX_CParamID
const char * AAX_CParamID
Parameter identifier.
Definition: AAX.h:362
AAX_Result
int32_t AAX_Result
Definition: AAX.h:347
AAX_CFieldIndex
AAX_CIndex AAX_CFieldIndex
Not used by AAX plug-ins (except in AAX_FIELD_INDEX macro)
Definition: AAX.h:359
AAX_IController.h
Interface for the AAX host's view of a single instance of an effect.
AAX_CMutex
Mutex with try lock functionality.
Definition: AAX_CMutex.h:40
AAX_CPacket
Container for packet-related data.
Definition: AAX_CPacketDispatcher.h:55
AAX_CPacket::IsDirty
bool IsDirty() const
Definition: AAX_CPacketDispatcher.h:69
AAX_CPacket::SetDirty
void SetDirty(bool iDirty)
Definition: AAX_CPacketDispatcher.h:68
AAX_CPacket::GetPtr
DataType * GetPtr()
Definition: AAX_CPacketDispatcher.h:61
AAX_CPacket::GetSize
uint32_t GetSize() const
Definition: AAX_CPacketDispatcher.h:72
AAX_CPacket::~AAX_CPacket
~AAX_CPacket()
Definition: AAX_CPacketDispatcher.h:58
AAX_CPacket::GetID
AAX_CFieldIndex GetID() const
Definition: AAX_CPacketDispatcher.h:71
AAX_CPacket::AAX_CPacket
AAX_CPacket(AAX_CFieldIndex inFieldIndex)
Definition: AAX_CPacketDispatcher.h:57
AAX_IPacketHandler
Callback container used by AAX_CPacketDispatcher.
Definition: AAX_CPacketDispatcher.h:104
AAX_IPacketHandler::Clone
virtual AAX_IPacketHandler * Clone() const =0
AAX_IPacketHandler::Call
virtual AAX_Result Call(AAX_CParamID inParamID, AAX_CPacket &ioPacket) const =0
AAX_IPacketHandler::~AAX_IPacketHandler
virtual ~AAX_IPacketHandler()
Definition: AAX_CPacketDispatcher.h:105
AAX_CPacketHandler
Callback container used by AAX_CPacketDispatcher.
Definition: AAX_CPacketDispatcher.h:114
AAX_CPacketHandler::Call
AAX_Result Call(AAX_CParamID inParamID, AAX_CPacket &ioPacket) const
Definition: AAX_CPacketDispatcher.h:130
AAX_CPacketHandler::Clone
AAX_IPacketHandler * Clone() const
Definition: AAX_CPacketDispatcher.h:125
AAX_CPacketHandler::AAX_CPacketHandler
AAX_CPacketHandler(TWorker *iPt2Object, fPt2Fn infPt)
Definition: AAX_CPacketDispatcher.h:119
AAX_CPacketHandler::fpt
fPt2Fn fpt
Definition: AAX_CPacketDispatcher.h:142
AAX_CPacketHandler::pt2Object
TWorker * pt2Object
Definition: AAX_CPacketDispatcher.h:141
AAX_CPacketHandler::fptEx
fPt2FnEx fptEx
Definition: AAX_CPacketDispatcher.h:143
AAX_CPacketHandler::AAX_CPacketHandler
AAX_CPacketHandler(TWorker *iPt2Object, fPt2FnEx infPt)
Definition: AAX_CPacketDispatcher.h:122
AAX_CPacketDispatcher
Helper class for managing AAX packet posting.
Definition: AAX_CPacketDispatcher.h:163
AAX_CPacketDispatcher::RegisterPacket
AAX_Result RegisterPacket(AAX_CParamID paramID, AAX_CFieldIndex portID, const AAX_IPacketHandler *iHandler)
AAX_CPacketDispatcher::AAX_CPacketDispatcher
AAX_CPacketDispatcher()
AAX_CPacketDispatcher::~AAX_CPacketDispatcher
~AAX_CPacketDispatcher()
AAX_CPacketDispatcher::SetDirty
AAX_Result SetDirty(AAX_CParamID paramID, bool iDirty=true)
AAX_CPacketDispatcher::RegisterPacket
AAX_Result RegisterPacket(AAX_CParamID paramID, AAX_CFieldIndex portID)
Definition: AAX_CPacketDispatcher.h:183
AAX_CPacketDispatcher::Initialize
void Initialize(AAX_IController *iPlugIn, AAX_IEffectParameters *iEffectParameters)
AAX_CPacketDispatcher::Dispatch
AAX_Result Dispatch()
AAX_CPacketDispatcher::RegisterPacket
AAX_Result RegisterPacket(AAX_CParamID paramID, AAX_CFieldIndex portID, TWorker *iPt2Object, Func infPt)
Definition: AAX_CPacketDispatcher.h:176
AAX_CPacketDispatcher::GenerateSingleValuePacket
AAX_Result GenerateSingleValuePacket(AAX_CParamID iParam, AAX_CPacket &ioPacket)
AAX_IController
Interface for the AAX host's view of a single instance of an effect. Used by both clients of the AAX ...
Definition: AAX_IController.h:55
AAX_IEffectParameters
The interface for an AAX Plug-in's data model.
Definition: AAX_IEffectParameters.h:93