void rApplicationBase::InitModule(){ m_module = CreateModule(); m_module->Init(m_engine); m_module->InitUI(*m_overlayManager, m_engine); m_module->LoadScene("Default", m_engine); }
JNIEXPORT jint JNICALL Java_app_zxtune_ZXTune_Module_1Create (JNIEnv* env, jclass /*self*/, jobject buffer, jstring subpath) { const jlong capacity = env->GetDirectBufferCapacity(buffer); const void* addr = env->GetDirectBufferAddress(buffer); if (capacity && addr) { const Binary::Container::Ptr data = Binary::CreateNonCopyContainer(addr, capacity); return CreateModule(data, Jni::MakeString(env, subpath)); } else { return 0; } }
void SubscribeGyro::GyroStart () { try { /** Create a proxy to ALMemory. */ gettimeofday(&startTime); fMemoryProxy = AL::ALMemoryProxy(getParentBroker()); bool test = CreateModule("/home/nao/lib/libmovementtools.so", "MovementTools", getParentBroker(), true, false); //fState = fMemoryProxy.getData("RightSubscribeGyroPressed"); /** Subscribe to event LeftSubscribeGyroPressed * Arguments: * - name of the event * - name of the module to be called for the callback * - name of the bound method to be called on event */ //fMemoryProxy.subscribeToEvent("RightSubscribeGyroPressed", "SubscribeGyro", "onRightSubscribeGyroPressed"); AL::ALProxy genericProxy ("MovementTools", "127.0.0.1" , 9559); genericProxy.callVoid("setSpeed", 0.8f); timer(); gettimeofday(¤tTime); gettimeofday(&lastTime); /* while (time < 180000){ qiLogInfo("subscribegyro.gyroswing") << "Time: " << time << std::endl; genericProxy.callVoid("swingForwards"); qi::os::msleep(1250); genericProxy.callVoid("swingBackwards"); qi::os::msleep(1250); gettimeofday(¤tTime); timer(); } */ fMemoryProxy.subscribeToEvent("GyroMoveForward", "SubscribeGyro", "onMoveForward"); fMemoryProxy.subscribeToEvent("GyroMoveBackward", "SubscribeGyro", "onMoveBackward"); } catch (const AL::ALError& e) { qiLogError("module.example") << e.what() << std::endl; } }
qString RunLLVMBuilding(qValue * prog) { InitializeNativeTarget(); llvm::Module * m = CreateModule(); globalllvmmodule=m; prog->LLVM_prebuild(m); prog->LLVM_build(m); std::string ErrorInfo; std::string Q; llvm::raw_string_ostream * ff1 = new llvm::raw_string_ostream(Q); llvm::AssemblyAnnotationWriter * Annotator = 0; m->print(*ff1, Annotator); if (ShouldWriteOutput()) setFile("compile_llvm.txt",Q); for (int i =0;i<llvmglobalvars.size();i++) { GlobalVariable * gv= (GlobalVariable*)llvmglobalvars[i]->llvmvar; llvmglobalvars[i]->dataptr = TheExecutionEngine->getOrEmitGlobalVariable(gv); if (llvmglobalvars[i]->pretty_name== "EMPTY_WND_PROC") { int * pttt = (int*) llvmglobalvars[i]->dataptr; *pttt= (int)xxxWndProc; } } qneu_Function * ff = 0;//FIXME functions["main"][0]; fun mainfun = (fun)TheExecutionEngine->getPointerToFunction(ff->llvmd); qdtprintf2("Running...\n\n"); int wynik=runcode(mainfun); qdtprintf2("\n\n *** Return value: %d\n", wynik); return Q; }
XnStatus XnDeviceBase::CreateDeviceModule(XnDeviceModuleHolder** ppModuleHolder) { XnStatus nRetVal = XN_STATUS_OK; // create module nRetVal = CreateModule(XN_MODULE_NAME_DEVICE, ppModuleHolder); XN_IS_STATUS_OK(nRetVal); XnDeviceModule* pModule = (*ppModuleHolder)->GetModule(); // add device properties XnProperty* pProps[] = { &m_DeviceMirror }; nRetVal = pModule->AddProperties(pProps, sizeof(pProps)/sizeof(XnProperty*)); if (nRetVal != XN_STATUS_OK) { DestroyModule(*ppModuleHolder); *ppModuleHolder = NULL; return (nRetVal); } return XN_STATUS_OK; }
XnStatus XnDeviceBase::CreateDeviceModule(XnDeviceModuleHolder** ppModuleHolder) { XnStatus nRetVal = XN_STATUS_OK; // create module nRetVal = CreateModule(XN_MODULE_NAME_DEVICE, ppModuleHolder); XN_IS_STATUS_OK(nRetVal); XnDeviceModule* pModule = (*ppModuleHolder)->GetModule(); // add device properties XnProperty* pProps[] = { &m_ReadWriteMode, &m_SharingMode, &m_PrimaryStream, &m_DeviceMirror, &m_SDKVersionProp, &m_HighResTimestamps, &m_DeviceName }; nRetVal = pModule->AddProperties(pProps, sizeof(pProps)/sizeof(XnProperty*)); if (nRetVal != XN_STATUS_OK) { DestroyModule(*ppModuleHolder); *ppModuleHolder = NULL; return (nRetVal); } return XN_STATUS_OK; }
int main(int argc, char *argv[]) { llvm::cl::SetVersionPrinter(PrintVersion); llvm::cl::ParseCommandLineOptions(argc, argv, "CFG to LLVM"); if (InputFilename.empty() || OutputFilename.empty()) { std::cerr << "Must specify an input and output file"; return EXIT_FAILURE; } auto context = new llvm::LLVMContext; if (!InitArch(context, OS, Arch)) { std::cerr << "Cannot initialize for arch " << Arch << " and OS " << OS << std::endl; return EXIT_FAILURE; } auto M = CreateModule(context); if (!M) { return EXIT_FAILURE; } auto triple = M->getTargetTriple(); //reproduce NativeModule from CFG input argument try { auto mod = ReadProtoBuf(InputFilename); if (!mod) { std::cerr << "Unable to read module from CFG" << std::endl; return EXIT_FAILURE; } //now, convert it to an LLVM module ArchInitAttachDetach(M); if (!LiftCodeIntoModule(mod, M)) { std::cerr << "Failure to convert to LLVM module!" << std::endl; return EXIT_FAILURE; } std::set<VA> entry_point_pcs; for (const auto &entry_point_name : EntryPoints) { auto entry_pc = FindSymbolInModule(mod, entry_point_name); if (entry_pc != static_cast<VA>( -1)) { std::cerr << "Adding entry point: " << entry_point_name << std::endl << entry_point_name << " is implemented by sub_" << std::hex << entry_pc << std::endl; if ( !ArchAddEntryPointDriver(M, entry_point_name, entry_pc)) { return EXIT_FAILURE; } entry_point_pcs.insert(entry_pc); } else { std::cerr << "Could not find entry point: " << entry_point_name << "; aborting" << std::endl; return EXIT_FAILURE; } } RenameLiftedFunctions(mod, M, entry_point_pcs); // will abort if verification fails if (llvm::verifyModule( *M, &llvm::errs())) { std::cerr << "Could not verify module!" << std::endl; return EXIT_FAILURE; } std::error_code ec; llvm::tool_output_file Out(OutputFilename.c_str(), ec, llvm::sys::fs::F_None); llvm::WriteBitcodeToFile(M, Out.os()); Out.keep(); } catch (std::exception &e) { std::cerr << "error: " << std::endl << e.what() << std::endl; return EXIT_FAILURE; } return EXIT_SUCCESS; }
int main(int argc, char* argv[]) { // Whether to print verbose output - default off bool verb = false; // Whether to manually load Libraries - default off bool init = false; // Name of desired library std::string libName = "bodyinfo"; // Name of desired module in library std::string moduleName = "BodyInfo"; // Explicit library path std::string libPath = ""; // Set broker name, ip and port, finding first available port from 54000 const std::string brokerName = "MotionDerivativeBroker"; int brokerPort = qi::os::findAvailablePort(54000); const std::string brokerIp = "0.0.0.0"; // Default parent port and ip int pport = 9559; std::string pip = "127.0.0.1"; // Default time to run in seconds int timeToRun = 10; // Get any arguments while (true) { static int index = 0; // Struct of options // Columns are: // {Option name, Option required?, flag(not needed here), return value/character} static const struct option longopts[] = { {"pip", 1, 0, 'i'}, {"pport", 1, 0, 'p'}, {"path", 1, 0, 'x'}, {"time", 0, 0, 't'}, {"verb", 0, 0, 'v'}, {"help", 0, 0, 'h'}, {0, 0, 0, 0 } }; // Get next option, and check return value switch(index = getopt_long(argc, argv, "i:p:t:vh", longopts, &index)) { // Print usage and quit case 'h': argErr(); break; // Set parent IP case 'i': if (optarg) pip = std::string(optarg); else argErr(); break; // Set parent port case 'p': if (optarg) pport = atoi(optarg); else argErr(); break; case 'x': if (optarg) libPath = std::string(optarg); else argErr(); break; case 't': if (optarg) timeToRun = atoi(optarg); else argErr(); break; case 'v': verb = true; break; } if (index == -1) break; } // Need this for SOAP serialisation of floats to work setlocale(LC_NUMERIC, "C"); // Create a broker if(verb) std::cout << bold_on << "Creating broker..." << bold_off << std::endl; boost::shared_ptr<AL::ALBroker> broker; try { broker = AL::ALBroker::createBroker( brokerName, brokerIp, brokerPort, pip, pport, 0); } // Throw error and quit if a broker could not be created catch(...) { std::cerr << "Failed to connect broker to: " << pip << ":" << pport << std::endl; AL::ALBrokerManager::getInstance()->killAllBroker(); AL::ALBrokerManager::kill(); return 1; } // Add the broker to NAOqi AL::ALBrokerManager::setInstance(broker->fBrokerManager.lock()); AL::ALBrokerManager::getInstance()->addBroker(broker); // Create an instance of the desired module if (libPath == "") CreateModule(libName, moduleName, broker, verb, true); else CreateModule(libPath, moduleName, broker, verb, false); // Create a proxy to the module if(verb) std::cout << bold_on << "Creating proxy to module..." << bold_off << std::endl; AL::ALProxy bodyProxy(moduleName, pip, pport); // Get COM angles as vector of [upper body, lower body] std::vector<float> COMAngles = bodyProxy.genericCall("getSittingCOMAngles", 0); // Get start time of simulation and store it qi::os::timeval startTime; qi::os::timeval currentTime; qi::os::gettimeofday(&startTime); qi::os::gettimeofday(¤tTime); // Run for time "timeToRun" while (currentTime.tv_sec - startTime.tv_sec < timeToRun) { std::cout << std::setw(15) << std::left << "Upper Body:" << COMAngles[0] << std::endl; std::cout << std::setw(15) << std::left << "Lower Body:" << COMAngles[1] << std::endl; qi::os::sleep(1); qi::os::gettimeofday(¤tTime); COMAngles = bodyProxy.genericCall("getSittingCOMAngles", 0); } // Get a handle to the module and close it { boost::shared_ptr<AL::ALModuleCore> module = broker->getModuleByName(moduleName); if(verb) std::cout << bold_on << "Closing module " << moduleName << "..." << bold_off << std::endl; module->exit(); } // Check module has closed if(verb) { std::cout << bold_on << "Module " << moduleName << " is "; if (!(broker->isModulePresent(moduleName))) { std::cout << "not "; } std::cout << "present" << bold_off << std::endl; } // Close the broker if(verb) std::cout << bold_on << "Closing broker..." << bold_off << std::endl; broker->shutdown(); // Exit program if(verb) std::cout << bold_on << "Exiting..." << bold_off << std::endl; return 0; }
void rApplicationBase::InitModule(){ m_module = CreateModule(&m_engine); m_module->Init(args); }
XnStatus XnStreamReaderDevice::SetInitialState(const XnDeviceConfig* pDeviceConfig, XnPropertySet* pSet) { XnStatus nRetVal = XN_STATUS_OK; // Fix state (remove some properties that we don't wish to reflect in reader device) XnActualPropertiesHash* pDeviceModule = NULL; if (XN_STATUS_OK == pSet->pData->Get(XN_MODULE_NAME_DEVICE, pDeviceModule)) { pDeviceModule->Remove(XN_MODULE_PROPERTY_READ_WRITE_MODE); pDeviceModule->Remove(XN_MODULE_PROPERTY_PRIMARY_STREAM); } // now init base using this state (this will also create module DEVICE) XnDeviceConfig initConfig; initConfig.cpConnectionString = pDeviceConfig->cpConnectionString; initConfig.DeviceMode = pDeviceConfig->DeviceMode; initConfig.pInitialValues = pSet; initConfig.SharingMode = pDeviceConfig->SharingMode; nRetVal = XnStreamDevice::InitImpl(&initConfig); XN_IS_STATUS_OK(nRetVal); // now create the rest of the modules and streams (DEVICE was already created) XnPropertySetData* pPropSetData = pSet->pData; for (XnPropertySetData::ConstIterator it = pPropSetData->begin(); it != pPropSetData->end(); ++it) { // ignore module DEVICE if (strcmp(XN_MODULE_NAME_DEVICE, it.Key()) == 0) { continue; } // check if this is a stream XnActualPropertiesHash::ConstIterator itProp = it.Value()->end(); if (XN_STATUS_OK == it.Value()->Find(XN_STREAM_PROPERTY_TYPE, itProp)) { XnActualStringProperty* pTypeProp = (XnActualStringProperty*)itProp.Value(); nRetVal = HandleNewStream(pTypeProp->GetValue(), it.Key(), it.Value()); XN_IS_STATUS_OK(nRetVal); } else { // this is module. create it XnDeviceModuleHolder* pHolder = NULL; nRetVal = CreateModule(it.Key(), &pHolder); XN_IS_STATUS_OK(nRetVal); // set its props nRetVal = pHolder->Init(it.Value()); if (nRetVal != XN_STATUS_OK) { DestroyModule(pHolder); return (nRetVal); } // and add it nRetVal = AddModule(pHolder); if (nRetVal != XN_STATUS_OK) { DestroyModule(pHolder); return (nRetVal); } } } // modules loop return (XN_STATUS_OK); }
HIPOCProgram::HIPOCProgram(const std::string& program_name, std::string params, bool is_kernel_str) { this->module = CreateModule(program_name, params, is_kernel_str); this->name = program_name; }
int main(int argc, char *argv[]) { llvm::cl::SetVersionPrinter(PrintVersion); llvm::cl::ParseCommandLineOptions(argc, argv, "CFG to LLVM"); auto context = llvm::make_unique<llvm::LLVMContext>(); if (OS.empty()) { if (ListSupported || ListUnsupported) { OS = "linux"; // just need something } else { std::cerr << "-os must be specified" << std::endl; return EXIT_FAILURE; } } if (!(ListSupported || ListUnsupported || ListCFGFunctions) && EntryPoints.empty()) { std::cerr << "-entrypoint must be specified" << std::endl; return EXIT_FAILURE; } if (!InitArch(context.get(), OS, Arch)) { std::cerr << "Cannot initialize for arch " << Arch << " and OS " << OS << std::endl; return EXIT_FAILURE; } auto M = CreateModule(context.get()); if (!M) { return EXIT_FAILURE; } auto triple = M->getTargetTriple(); if (ListSupported || ListUnsupported) { ListArchSupportedInstructions(triple, llvm::outs(), ListSupported, ListUnsupported); return EXIT_SUCCESS; } if (InputFilename.empty()) { std::cerr << "Must specify an input file." << std::endl; return EXIT_FAILURE; } //reproduce NativeModule from CFG input argument try { std::unique_ptr<NativeModule> mod(ReadProtoBuf(InputFilename)); if (!mod) { std::cerr << "Unable to read module from CFG" << std::endl; return EXIT_FAILURE; } if (ListCFGFunctions) { PrintCFGFunctionList(mod.get(), Arch); return EXIT_SUCCESS; } //make sure the entry point list is correct before we start lifting the code const std::vector<NativeEntrySymbol> &module_entry_points = mod->getEntryPoints(); for (const auto &entry_point : EntryPoints) { auto it = std::find_if( module_entry_points.begin(), module_entry_points.end(), [&entry_point](const NativeEntrySymbol &symbol) -> bool { return (symbol.getName() == entry_point); } ); if (it == module_entry_points.end()) { std::cerr << "The following entry point could not be found: \"" << entry_point << "\". Aborting..." << std::endl; return EXIT_FAILURE; } } //now, convert it to an LLVM module ArchInitAttachDetach(M); if (!LiftCodeIntoModule(mod.get(), M)) { std::cerr << "Failure to convert to LLVM module!" << std::endl; return EXIT_FAILURE; } std::set<VA> entry_point_pcs; for (const auto &entry_point_name : EntryPoints) { auto entry_pc = FindSymbolInModule(mod.get(), entry_point_name); assert(entry_pc != static_cast<VA>( -1)); std::cerr << "Adding entry point: " << entry_point_name << std::endl << entry_point_name << " is implemented by sub_" << std::hex << entry_pc << std::endl; if ( !ArchAddEntryPointDriver(M, entry_point_name, entry_pc)) { return EXIT_FAILURE; } entry_point_pcs.insert(entry_pc); } RenameLiftedFunctions(mod.get(), M, entry_point_pcs); // will abort if verification fails if (llvm::verifyModule( *M, &llvm::errs())) { std::cerr << "Could not verify module!" << std::endl; return EXIT_FAILURE; } std::error_code ec; llvm::tool_output_file Out(OutputFilename.c_str(), ec, llvm::sys::fs::F_None); llvm::WriteBitcodeToFile(M, Out.os()); Out.keep(); } catch (std::exception &e) { std::cerr << "error: " << std::endl << e.what() << std::endl; return EXIT_FAILURE; } return EXIT_SUCCESS; }