コード例 #1
0
/**
 * Load a module and create the driver object.
 */
static EGLBoolean
_eglLoadModule(_EGLModule *mod)
{
   _EGLMain_t mainFunc;
   lib_handle lib;
   _EGLDriver *drv;

   if (mod->Driver)
      return EGL_TRUE;

   if (mod->BuiltIn) {
      lib = (lib_handle) NULL;
      mainFunc = mod->BuiltIn;
   }
   else {
      mainFunc = _eglOpenLibrary(mod->Path, &lib);
      if (!mainFunc)
         return EGL_FALSE;
   }

   drv = mainFunc(NULL);
   if (!drv) {
      return EGL_FALSE;
   }

   if (!drv->Name) {
      _eglLog(_EGL_WARNING, "Driver loaded from %s has no name", mod->Path);
      drv->Name = "UNNAMED";
   }

   mod->Handle = (void *) lib;
   mod->Driver = drv;

   return EGL_TRUE;
}
コード例 #2
0
ファイル: egldriver.c プロジェクト: MttDs/new-rexeno-tindpe
/**
 * Load the named driver.  The path and args passed will be
 * owned by the driver and freed.
 */
static _EGLDriver *
_eglLoadDriver(char *path, char *args)
{
   _EGLMain_t mainFunc;
   lib_handle lib;
   _EGLDriver *drv = NULL;

   mainFunc = _eglOpenLibrary(path, &lib);
   if (!mainFunc)
      return NULL;

   drv = mainFunc(args);
   if (!drv) {
      if (lib)
         close_library(lib);
      return NULL;
   }

   if (!drv->Name) {
      _eglLog(_EGL_WARNING, "Driver loaded from %s has no name", path);
      drv->Name = "UNNAMED";
   }

   drv->Path = path;
   drv->Args = args;
   drv->LibHandle = lib;

   return drv;
}
コード例 #3
0
/**
* @brief Performs the removal of functions.
*
* Updates @c removedFuncs. For more information, see the description of
* removeFuncs().
*/
void UnreachableFuncsRemover::performRemoval() {
	// If there is no main function, we should do nothing.
	ShPtr<Function> mainFunc(module->getFuncByName(mainFuncName));
	if (!mainFunc) {
		return;
	}

	// Use the call graph of the module to compute functions that are reachable
	// from main, either directly or in other function calls (the 'true'
	// argument below).
	ShPtr<CG> cg(CGBuilder::getCG(module));
	FuncSet reachableFuncs(cg->getCalledFuncs(mainFunc, true)->callees);
	// The main function has to be also considered as reachable from main.
	reachableFuncs.insert(mainFunc);

	// Include all functions that may be called by pointers into reachableFuncs
	// to prevent "use of undeclared variable" or "call of an undeclared
	// function" errors. These errors mean that we have removed a function
	// which is called indirectly by a pointer.
	// TODO When a function pointer appears in a function that is not directly
	//      reachable from main(), we still consider it as a possibly reachable
	//      function. Can we improve the implementation so when a function is
	//      left in the code, it is definitely reachable?
	FuncSet indirectlyCalledFuncs(getFuncsThatMayBeCalledIndirectly(module));
	addToSet(indirectlyCalledFuncs, reachableFuncs);

	// Remove defined functions that are not reachable from the module.
	// We have to iterate over a copy of the functions in the module because we
	// remove functions during the iteration.
	FuncVector allFuncs(module->func_begin(), module->func_end());
	for (const auto &func : allFuncs) {
		if (!hasItem(reachableFuncs, func) && func->isDefinition()) {
			module->removeFunc(func);
			removedFuncs.push_back(func);
		}
	}
}
コード例 #4
0
std::string runAndCapture(int (* mainFunc)(),
                          const std::string& cinInput,
                          const std::string& outputFileName) {
    // run the 'main' function, possibly feeding it cin, input, and capture its cout output
    if (!cinInput.empty()) {
        ioutils::redirectStdinBegin(cinInput);
    }
    
    ioutils::setConsoleOutputLimit(MAX_STUDENT_OUTPUT);   // prevent infinite output by student
    ioutils::captureStdoutBegin();
    
    mainFunc();
    
    std::string output = ioutils::captureStdoutEnd();
    if (!cinInput.empty()) {
        ioutils::redirectStdinEnd();
    }

    // return the output as a string (and also possibly write it to a file)
    if (!outputFileName.empty()) {
        writeEntireFile(outputFileName, output);
    }
    return output;
}
コード例 #5
0
void CPlugInManager::Init()
{
	CAutoLock Lock(gpApplication->GetMeterMutex());
	
#ifdef _Mac
	// Get the path to the plug-in folder
	tchar pszPlugInPath[1024];
	IFile::GetSystemDirectory(IFile::SystemDirApplicationSupport, pszPlugInPath);
	std::string sPlugInPath(pszPlugInPath);
	sPlugInPath += std::string("Koblo:KSPI:Plug-Ins:");
	
	// Scan the system for plug-ins
	CAutoDelete<IFileSearch> pFileSearch(IFileSearch::Create());
	// Lasse, modified 2008-04-15 - don't crash if folder missing
	//pFileSearch->Init(sPlugInPath.c_str());
	pFileSearch->Init2(sPlugInPath.c_str());
	// .. Lasse
	
	tchar pszName[256];
	tbool bDirectory;
	while (pFileSearch->GetNext(pszName, bDirectory)) {
		std::string sName(pszName);
		std::string sPathName = sPlugInPath + sName;
		
		// Load the plug-in to get info
		{
			CFBundleRef BundleRef;
			kspi::IModule* pModule;
			kspi::IPlugIn* pPlugIn;
			
			// Make a CFURLRef from the CFString representation of the bundle's path.
			tchar pszPathName[1024];
			strcpy(pszPathName, sPathName.c_str());
			ToUnix(pszPathName);
			CFURLRef bundleURL = CFURLCreateWithFileSystemPath( 
															   kCFAllocatorDefault, 
															   __CFStringMakeConstantString(pszPathName),
															   kCFURLPOSIXPathStyle,
															   true );
			if ( !bundleURL ) continue;
			
			// Make a bundle instance using the URLRef.
			BundleRef = CFBundleCreate( kCFAllocatorDefault, bundleURL );
			
			// We don't need the URL anymore
			CFRelease( bundleURL );	
			
			if ( !BundleRef ) {
				continue;
			}
			
			if ( !CFBundleLoadExecutable( BundleRef ) )
			{
				CFRelease( BundleRef );
				BundleRef = NULL;
				continue;
			}
			
			kspi::kspiMainFunc mainFunc = (kspi::kspiMainFunc)(void*)CFBundleGetFunctionPointerForName( 
																									   BundleRef, CFSTR("kspiMain") );
			if (mainFunc == NULL) {
				continue;
			}
			
			tuint32 uiKSPIVersionNumber;
			void* pDispatcher = NULL;
			void* hModule = mainFunc(&kspi::kspiCCallbackDispatcher, dynamic_cast<kspi::IHost*>(this), &uiKSPIVersionNumber, &pDispatcher);
			if (hModule == NULL) {
				continue;
			}
			
			kspi::kspiCDispatcherFunc CFunc = (kspi::kspiCDispatcherFunc)pDispatcher;
			if (CFunc == NULL) {
				continue;
			}
			pModule = kspi::kspiModule::Create(CFunc, hModule, &uiKSPIVersionNumber, false);
			
			// Get the number of plug-ins in the module
			tint32 iPlugIns = pModule->GetNrOfPlugIns();
			
			tint32 iPlugIn;
			for (iPlugIn = 0; iPlugIn < iPlugIns; iPlugIn++) {
				SPlugInInfo* pInfo = new SPlugInInfo();
				
				pInfo->PlugInType = SPlugInInfo::PlugInTypeEffect;
				
				pInfo->sPathName = sPathName;
				pInfo->iPlugInIndex = iPlugIn;
				
				pInfo->puiInputs = new tuint32[1024];
				pInfo->puiOutputs = new tuint32[1024];
				pInfo->puiSideChains = new tuint32[1024];
				
				pPlugIn = pModule->CreateProcess(iPlugIn);
				if (pPlugIn == NULL) {
					// No plugin with given index
					continue;
				}
				
				// Get the channel configurations
				pPlugIn->GetChannelConfigurations(&(pInfo->uiChannelConfigurations), pInfo->puiInputs, pInfo->puiOutputs, pInfo->puiSideChains);
				
				// Get the ids and names
				tchar pszTmp[256];
				pInfo->uiCompanyID = pModule->GetCompanyID();
				pModule->GetCompanyName(pszTmp);
				pInfo->sCompanyName = std::string(pszTmp);
				
				pInfo->uiProductID = pPlugIn->GetProductID();
				pPlugIn->GetProductName(pszTmp);
				pInfo->sProductName = std::string(pszTmp);
				
				mPlugIns.push_back(pInfo);
				
				pPlugIn->Destroy();
			}
			
			pModule->Destroy();
		}
	}
#endif	// _Mac
	
#ifdef WIN32
	// Get the path to the plug-in folder
	tchar pszPlugInPath[1024];
	::CoInitialize(NULL);
	// This only works with NT-based Windows versions
	::SHGetSpecialFolderPath(NULL, (LPSTR)pszPlugInPath, CSIDL_PROGRAM_FILES_COMMON, FALSE);
	::CoUninitialize();
	std::string sPlugInPath(pszPlugInPath);
	sPlugInPath += std::string("\\Koblo\\KSPI\\Plug-Ins\\");
	
	// Scan the system for plug-ins
	CAutoDelete<IFileSearch> pFileSearch(IFileSearch::Create());
	// Lasse, modified 2008-04-15 - don't crash if folder missing
	//pFileSearch->Init(sPlugInPath.c_str());
	pFileSearch->Init2(sPlugInPath.c_str());
	// .. Lasse
	
	tchar pszName[256];
	tbool bDirectory;
	while (pFileSearch->GetNext(pszName, bDirectory)) {
		std::string sName(pszName);
		std::string sPathName = sPlugInPath + sName;
		
		// Load the plug-in to get info
		{
			HMODULE hDLL;
			kspi::IModule* pModule;
			kspi::IPlugIn* pPlugIn;
			
			hDLL = LoadLibrary(sPathName.c_str());
			if (hDLL == NULL) {
				continue;
			}
			
			kspi::kspiMainFunc mainFunc = (kspi::kspiMainFunc)(void*)GetProcAddress(hDLL, "kspiMain");
			if (mainFunc == NULL) {
				continue;
			}
			
			tuint32 uiKSPIVersionNumber;
			void* pDispatcher = NULL;
			void* hModule = mainFunc(&kspi::kspiCCallbackDispatcher, dynamic_cast<kspi::IHost*>(this), &uiKSPIVersionNumber, &pDispatcher);
			if (hModule == NULL) {
				continue;
			}
			
			kspi::kspiCDispatcherFunc CFunc = (kspi::kspiCDispatcherFunc)pDispatcher;
			if (CFunc == NULL) {
				continue;
			}
			pModule = kspi::kspiModule::Create(CFunc, hModule, &uiKSPIVersionNumber, false);
			
			// Get the number of plug-ins in the module
			tint32 iPlugIns = pModule->GetNrOfPlugIns();
			
			tint32 iPlugIn;
			for (iPlugIn = 0; iPlugIn < iPlugIns; iPlugIn++) {
				SPlugInInfo* pInfo = new SPlugInInfo();
				
				pInfo->PlugInType = SPlugInInfo::PlugInTypeEffect;
				
				pInfo->sPathName = sPathName;
				pInfo->iPlugInIndex = iPlugIn;
				
				pInfo->puiInputs = new tuint32[1024];
				pInfo->puiOutputs = new tuint32[1024];
				pInfo->puiSideChains = new tuint32[1024];
				
				pPlugIn = pModule->CreateProcess(iPlugIn);
				if (pPlugIn == NULL) {
					// No plugin with given index
					continue;
				}
				
				// Get the channel configurations
				pPlugIn->GetChannelConfigurations(&(pInfo->uiChannelConfigurations), pInfo->puiInputs, pInfo->puiOutputs, pInfo->puiSideChains);
				
				// Get the ids and names
				tchar pszTmp[256];
				pInfo->uiCompanyID = pModule->GetCompanyID();
				pModule->GetCompanyName(pszTmp);
				pInfo->sCompanyName = std::string(pszTmp);
				
				pInfo->uiProductID = pPlugIn->GetProductID();
				pPlugIn->GetProductName(pszTmp);
				pInfo->sProductName = std::string(pszTmp);
				
				mPlugIns.push_back(pInfo);
				
				pPlugIn->Destroy();
			}
			
			pModule->Destroy();
		}
	}
#endif	// WIN32
}
コード例 #6
0
CPlugInManager::PlugInHandle CPlugInManager::LoadPlugIn(tint32 iIndex, tint32 iChannel, tint32 iInsertIndex)
{
	CAutoLock Lock(gpApplication->GetMeterMutex());
	
	if (iIndex >= (tint32)mPlugIns.size()) {
		throw IException::Create(IException::TypeCode, IException::ReasonCodeInvalidArgument, EXCEPTION_INFO, "Invalid Index / Unknown plug-in");
	}
	
	// Locate the plug-in
	std::list<SPlugInInfo*>::const_iterator it = mPlugIns.begin();
	for (; iIndex; it++, iIndex--) {
	}
	SPlugInInfo* pInfo = *it;
	
#ifdef _Mac
	CFBundleRef BundleRef;
	kspi::IModule* pModule;
	kspi::IPlugIn* pPlugIn;
	
	// Make a CFURLRef from the CFString representation of the bundle's path.
	tchar pszPathName[1024];
	strcpy(pszPathName, pInfo->sPathName.c_str());
	ToUnix(pszPathName);
	CFURLRef bundleURL = CFURLCreateWithFileSystemPath( 
													   kCFAllocatorDefault, 
													   __CFStringMakeConstantString(pszPathName),
													   kCFURLPOSIXPathStyle,
													   true );
	if ( !bundleURL ) {
	}
	
	// Make a bundle instance using the URLRef.
	BundleRef = CFBundleCreate( kCFAllocatorDefault, bundleURL );
	
	// We don't need the URL anymore
	CFRelease( bundleURL );	
	
	if (!BundleRef) {
	}
	
	if (!CFBundleLoadExecutable(BundleRef)) {
		CFRelease( BundleRef );
		BundleRef = NULL;
	}
	
	kspi::kspiMainFunc mainFunc = (kspi::kspiMainFunc)(void*)CFBundleGetFunctionPointerForName( BundleRef, CFSTR("kspiMain") );
	if (mainFunc == NULL) {
	}
	
	tuint32 uiKSPIVersionNumber;
	void* pDispatcher = NULL;
	void* hModule = mainFunc(&kspi::kspiCCallbackDispatcher, dynamic_cast<kspi::IHost*>(this), &uiKSPIVersionNumber, &pDispatcher);
	if (hModule == NULL) {
	}
	
	kspi::kspiCDispatcherFunc CFunc = (kspi::kspiCDispatcherFunc)pDispatcher;
	if (CFunc == NULL) {
	}
	pModule = kspi::kspiModule::Create(CFunc, hModule, &uiKSPIVersionNumber, false);
	
	pPlugIn = pModule->CreateProcess(pInfo->iPlugInIndex);
	if (pPlugIn == NULL) {
		// No plugin with given index
	}
	
	tint32 iLoadedPlugs = mLoadedPlugIns.size();
	
	mLoadedPlugIns.push_back(pPlugIn);
	
	pPlugIn->PreInitialize();
	pPlugIn->SetSampleRate(44100);
	pPlugIn->SetMaxBufferSize(32);
	pPlugIn->Initialize();
	pPlugIn->Start();

	CBaseGUI* pBaseGUI = gpMainApplication->CreateExtraWindow(giPlug_In_Window, (void*)CFSTR("PlugInWnd"));
	CKSPlugInGUI* pPlugInGUI = dynamic_cast<CKSPlugInGUI*>(pBaseGUI);
	
	kspi::IGUI* pGUI = pPlugIn->CreateGUI(0);
	
	pPlugInGUI->SetInfo(iChannel, iInsertIndex);
	
	pPlugInGUI->SetGUI(pGUI);
	
	SLoadedPlugInInfo LoadedInfo;
	LoadedInfo.pPlugIn = pPlugIn;
	LoadedInfo.bGUILoaded = true;
	LoadedInfo.pBaseGUI = pBaseGUI;
	LoadedInfo.pPlugInGUI = pPlugInGUI;
	LoadedInfo.pGUI = pGUI;
	
	mPlugInMap.insert(std::pair<tint32, SLoadedPlugInInfo>(iChannel << 16 | iInsertIndex, LoadedInfo));
	
	//	return (PlugInHandle)iLoadedPlugs;
	return (PlugInHandle)pPlugIn;
#endif	// _Mac
	
#ifdef WIN32
	HMODULE hDLL;
	kspi::IModule* pModule;
	kspi::IPlugIn* pPlugIn;
	
	hDLL = LoadLibrary(pInfo->sPathName.c_str());
	if (hDLL == NULL) {
	}
	
	kspi::kspiMainFunc mainFunc = (kspi::kspiMainFunc)(void*)GetProcAddress(hDLL, "kspiMain"); 
	if (mainFunc == NULL) {
	}
	
	tuint32 uiKSPIVersionNumber;
	void* pDispatcher = NULL;
	void* hModule = mainFunc(&kspi::kspiCCallbackDispatcher, dynamic_cast<kspi::IHost*>(this), &uiKSPIVersionNumber, &pDispatcher);
	if (hModule == NULL) {
	}
	
	kspi::kspiCDispatcherFunc CFunc = (kspi::kspiCDispatcherFunc)pDispatcher;
	if (CFunc == NULL) {
	}
	pModule = kspi::kspiModule::Create(CFunc, hModule, &uiKSPIVersionNumber, false);
	
	pPlugIn = pModule->CreateProcess(pInfo->iPlugInIndex);
	if (pPlugIn == NULL) {
		// No plugin with given index
	}
	
	tint32 iLoadedPlugs = mLoadedPlugIns.size();
	
	mLoadedPlugIns.push_back(pPlugIn);
	
	pPlugIn->PreInitialize();
	pPlugIn->SetSampleRate(44100);
	pPlugIn->SetMaxBufferSize(32);
	pPlugIn->Initialize();
	pPlugIn->Start();

	CBaseGUI* pBaseGUI = gpMainApplication->CreateExtraWindow(giPlug_In_Window, (void*)"PlugInWnd", true);
	CKSPlugInGUI* pPlugInGUI = dynamic_cast<CKSPlugInGUI*>(pBaseGUI);
	
	kspi::IGUI* pGUI = pPlugIn->CreateGUI(0);
	
	pPlugInGUI->SetInfo(iChannel, iInsertIndex);
	
	pPlugInGUI->SetGUI(pGUI);
	
	SLoadedPlugInInfo LoadedInfo;
	LoadedInfo.pPlugIn = pPlugIn;
	LoadedInfo.bGUILoaded = true;
	LoadedInfo.pBaseGUI = pBaseGUI;
	LoadedInfo.pPlugInGUI = pPlugInGUI;
	LoadedInfo.pGUI = pGUI;
	
	mPlugInMap.insert(std::pair<tint32, SLoadedPlugInInfo>(iChannel << 16 | iInsertIndex, LoadedInfo));
	
	//	return (PlugInHandle)iLoadedPlugs;
	return (PlugInHandle)pPlugIn;
#endif	// WIN32
}
コード例 #7
0
ファイル: mexMain.cpp プロジェクト: stevendaniluk/HAA
/* The gateway function */
void mexFunction(int nlhs, mxArray *plhs[],
	int nrhs, const mxArray *prhs[])
{
//	double *inMatrix;               /* 1xN input matrix */
//	size_t ncols;                   /* size of matrix */
//	double *outMatrix;              /* output matrix */
	//inMatrix = mxGetPr(prhs[1]);

	char *hostConfig, *missionFile;//, *output_buf;
	_TCHAR *hostConfig_t, *missionFile_t;
//	_TCHAR *output_buf_t;
	size_t bufLenHost, bufLenMission;

	/* check for proper number of arguments */
	if (nrhs < 1)
		mexErrMsgIdAndTxt("MATLAB:invalidNumInputs",
			"At least one input required.");
	else if (nlhs > 1)
		mexErrMsgIdAndTxt("MATLAB:maxlhs",
			"Too many output arguments.");

	/* input must be a string */
	if (mxIsChar(prhs[0]) != 1)
		mexErrMsgIdAndTxt("MATLAB:hostConfigNotString",
			"Input must be a string.");

	/* input must be a row vector */
	if (mxGetM(prhs[0]) != 1)
		mexErrMsgIdAndTxt("MATLAB:inputNotVector",
			"Input must be a row vector.");

	/* get the length of the input string */
	bufLenHost = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;

	/* copy the string data from prhs[0] into a C string input_ buf.    */
	hostConfig = mxArrayToString(prhs[0]);

	if (hostConfig == NULL)
		mexErrMsgIdAndTxt("MATLAB:conversionFailed",
			"Could not convert input to string.");

	mexPrintf("\n Contents of hostConfig %s \n", hostConfig);

	if (nrhs == 2) {

		/* input must be a string */
		if (mxIsChar(prhs[1]) != 1)
			mexErrMsgIdAndTxt("MATLAB:missionFileNotString",
				"Input must be a string.");

		/* input must be a row vector */
		if (mxGetM(prhs[1]) != 1)
			mexErrMsgIdAndTxt("MATLAB:inputNotVector",
				"Input must be a row vector.");

		/* get the length of the input string */
		bufLenMission = (mxGetM(prhs[1]) * mxGetN(prhs[1])) + 1;

		/* copy the string data from prhs[0] into a C string input_ buf.    */
		missionFile = mxArrayToString(prhs[1]);

		if (missionFile == NULL)
			mexErrMsgIdAndTxt("MATLAB:conversionFailed",
				"Could not convert input to string.");


		mexPrintf("\n Contents of missionFile %s \n", missionFile);
	}



	// newsize describes the length of the 
	// wchar_t string called wcstring in terms of the number 
	// of wide characters, not the number of bytes.
	size_t newsize = strlen(hostConfig) + 1;

	// The following creates a buffer large enough to contain 
	// the exact number of characters in the original string
	// in the new format. If you want to add more characters
	// to the end of the string, increase the value of newsize
	// to increase the size of the buffer.
	hostConfig_t = (_TCHAR *)mxMalloc(sizeof(_TCHAR)*newsize);// new wchar_t[newsize];

	// Convert char* string to a wchar_t* string.
	size_t convertedChars = 0;
	mbstowcs_s(&convertedChars, hostConfig_t, newsize, hostConfig, _TRUNCATE);
	// Display the result and indicate the type of string that it is.
	wcout << hostConfig_t << _T(" (wchar_t *)") << endl;
//	std::wstring testString(wcstring);
//	mexPrintf("\n testString?: %s \n", testString);
	mexPrintf("\n Contents of hostConfig_t %s \n", hostConfig_t);


	if (nrhs == 2) {
		newsize = strlen(missionFile) + 1;

		// The following creates a buffer large enough to contain 
		// the exact number of characters in the original string
		// in the new format. If you want to add more characters
		// to the end of the string, increase the value of newsize
		// to increase the size of the buffer.
		missionFile_t = (_TCHAR *)mxMalloc(sizeof(_TCHAR)*newsize);// new wchar_t[newsize];

		// Convert char* string to a wchar_t* string.
		convertedChars = 0;
		mbstowcs_s(&convertedChars, missionFile_t, newsize, missionFile, _TRUNCATE);
		// Display the result and indicate the type of string that it is.
		wcout << missionFile_t << _T(" (wchar_t *)") << endl;
		//	std::wstring testString(wcstring);
		//	mexPrintf("\n testString?: %s \n", testString);
		mexPrintf("\n Contents of missionFile_t %s \n", missionFile_t);
	}

	if (nrhs == 1) {
		_TCHAR* input_list[] = { TEXT("MatlabBridge"), hostConfig_t };
		mainFunc(2, input_list);
	}
	else if (nrhs == 2) {
		_TCHAR* input_list[] = { TEXT("MatlabBridge"), hostConfig_t, missionFile_t };
		mainFunc(3, input_list);
		mxFree(missionFile_t);
	}


//	mxFree(hostConfig);
//	mxFree(missionFile);
//	delete missionFile_t;
//	delete hostConfig_t;

	mxFree(hostConfig_t);


	return;
}