this repo has no description
at fixPythonPipStalling 69 lines 2.2 kB view raw
1/* 2This file is part of Darling. 3 4Copyright (C) 2020 Lubos Dolezel 5 6Darling is free software: you can redistribute it and/or modify 7it under the terms of the GNU General Public License as published by 8the Free Software Foundation, either version 3 of the License, or 9(at your option) any later version. 10 11Darling is distributed in the hope that it will be useful, 12but WITHOUT ANY WARRANTY; without even the implied warranty of 13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14GNU General Public License for more details. 15 16You should have received a copy of the GNU General Public License 17along with Darling. If not, see <http://www.gnu.org/licenses/>. 18*/ 19 20#ifndef _COMPONENT_DISPATCH_H 21#define _COMPONENT_DISPATCH_H 22#include "AudioComponentManager.h" 23#include <CarbonCore/Components.h> 24 25template <typename First, typename... Rest> 26void assignParams(ComponentParameters* cp, size_t totalArgs, size_t argumentIndex, First arg, Rest... rest) 27{ 28#if __LP64__ 29 cp->params[argumentIndex] = long(arg); 30#else 31 cp->params[totalArgs - argumentIndex - 1] = long(arg); 32#endif 33 34 if constexpr (sizeof...(Rest) > 0) 35 assignParams(cp, totalArgs, argumentIndex+1, rest...); 36} 37 38template <typename ...Args> 39OSStatus dispatchCall(AudioComponentInstance inUnit, SInt16 sel, Args... args) 40{ 41 if (AudioComponentManager::isOurInstance(inUnit)) 42 { 43 AudioComponentPlugInInterface* iface = AudioComponentManager::instance()->instanceInterface(inUnit); 44 AudioComponentMethod method = iface->Lookup(sel); 45 if (method != nullptr) 46 return method(iface, args...); 47 else 48 return badComponentSelector; 49 } 50 else 51 { 52 ComponentParameters* cp = (ComponentParameters*) alloca(sizeof(ComponentParameters) + sizeof...(Args) * sizeof(long)); 53 constexpr size_t totalArgs = sizeof...(Args)+1; 54 55 assignParams(cp, totalArgs, 0, inUnit); 56 57 if constexpr (totalArgs > 1) 58 assignParams(cp, totalArgs, 1, args...); 59 60 cp->paramSize = totalArgs * sizeof(long); 61 cp->what = sel; 62 cp->flags = 0; 63 64 return CallComponentDispatch(cp); 65 } 66} 67 68#endif 69