void ReleaseLibraries(void) { if(eCompass.isLoaded()) { eCompass.unload(); } if(Altimeter.isLoaded()) { Altimeter.unload(); } if(Nordic.isLoaded()) { Nordic.unload(); } if(GPS.isLoaded()) { GPS.unload(); } }
//General library functions void LoadLibraries(void) { //Load Library eCompass if(!eCompass.isLoaded()) { eCompass.load(); } if(!Altimeter.isLoaded()) { Altimeter.load(); } if(!Nordic.isLoaded()) { Nordic.load(); } if(!GPS.isLoaded()) { GPS.load(); } }
//eComnpass libray funcitons void eCompass_GetVersion(int *pMajorVer, int *pMinorVer) { if(eCompass.isLoaded()) { pFuncGetVersion eCompass_GetVersion = (pFuncGetVersion) eCompass.resolve("eCompass_GetVersion"); if(eCompass_GetVersion) { eCompass_GetVersion(pMajorVer, pMinorVer); } } }
BOOL HRS_Stop(void) { if(Nordic.isLoaded()) { pFuncGetBool HRS_Stop = (pFuncGetBool)Nordic.resolve("HRS_Stop"); if(HRS_Stop) { return HRS_Stop(); } } return FALSE; }
UCHAR HRS_GetHeartRate(void) { if(Nordic.isLoaded()) { pFuncGetUCHAR HRS_GetHeartRate = (pFuncGetUCHAR)Nordic.resolve("HRS_GetHeartRate"); if(HRS_GetHeartRate) { return HRS_GetHeartRate(); } } return NULL; }
BOOL eCompass_Stop() { if(eCompass.isLoaded()) { pFuncGetInt eCompass_Stop = (pFuncGetInt) eCompass.resolve("eCompass_Stop"); if(eCompass_Stop) { return eCompass_Stop(); } } return FALSE; }
UCHAR NOR_GetChStatus(UCHAR ucChannel) { if(Nordic.isLoaded()) { pFuncGetUCHARParamUCHAR NOR_GetChStatus = (pFuncGetUCHARParamUCHAR)Nordic.resolve("NOR_GetChStatus"); if(NOR_GetChStatus) { return NOR_GetChStatus(ucChannel); } } return NULL; }
BOOL NOR_Close(void) { if(Nordic.isLoaded()) { pFuncGetBool NOR_Close = (pFuncGetBool)Nordic.resolve("NOR_Close"); if(NOR_Close) { return NOR_Close(); } } return FALSE; }
USHORT CAD_GetCandence(void) { if(Nordic.isLoaded()) { pFuncGetUShort CAD_GetCandence = (pFuncGetUShort)Nordic.resolve("CAD_GetCandence"); if(CAD_GetCandence) { return CAD_GetCandence(); } } return NULL; }
BOOL NOR_Open(void) { if(Nordic.isLoaded()) { pFuncGetBool NOR_Open = (pFuncGetBool)Nordic.resolve("NOR_Open"); if(NOR_Open) { return NOR_Open(); } } return FALSE; }
BOOL SND_Stop(void) { if(Nordic.isLoaded()) { pFuncGetBool SND_Stop = (pFuncGetBool)Nordic.resolve("SND_Stop"); if(SND_Stop) { return SND_Stop(); } } return FALSE; }
BOOL SND_Start(void) { if(Nordic.isLoaded()) { pFuncGetBool SND_Start = (pFuncGetBool)Nordic.resolve("SND_Start"); if(SND_Start) { return SND_Start(); } } return FALSE; }
BOOL SND_SendTxBuf(UCHAR *ucTxBuf) { if(Nordic.isLoaded()) { pFuncGetBoolParamUCharPt SND_SendTxBuf = (pFuncGetBoolParamUCharPt)Nordic.resolve("SND_SendTxBuf"); if(SND_SendTxBuf) { return SND_SendTxBuf(ucTxBuf); } } return FALSE; }
UCHAR* RTK_GetRxBuf(void) { if(Nordic.isLoaded()) { pFuncGetUCHARPt RTK_GetRxBuf = (pFuncGetUCHARPt)Nordic.resolve("RTK_GetRxBuf"); if(RTK_GetRxBuf) { return RTK_GetRxBuf(); } } return NULL; }
BOOL RTK_Stop(void) { if(Nordic.isLoaded()) { pFuncGetBool RTK_Stop = (pFuncGetBool)Nordic.resolve("RTK_Stop"); if(RTK_Stop) { return RTK_Stop(); } } return FALSE; }
BOOL eCompass_Init() { if(eCompass.isLoaded()) { pFuncGetInt eCompass_Init = (pFuncGetInt) eCompass.resolve("eCompass_Init"); if(eCompass_Init) { return eCompass_Init(); } } return FALSE; }
BOOL CAD_Stop(void) { if(Nordic.isLoaded()) { pFuncGetBool CAD_Stop = (pFuncGetBool)Nordic.resolve("CAD_Stop"); if(CAD_Stop) { return CAD_Stop(); } } return FALSE; }
BOOL NOR_Reset(void) { if(Nordic.isLoaded()) { pFuncGetBool NOR_Reset = (pFuncGetBool)Nordic.resolve("NOR_Reset"); if(NOR_Reset) { return NOR_Reset(); } } return FALSE; }
BOOL NOR_GetChID(UCHAR ucChannel, UCHAR *ucManufact, USHORT *usDeviceNum) { if(Nordic.isLoaded()) { pFuncGetId NOR_GetChID = (pFuncGetId)Nordic.resolve("NOR_GetChID"); if(NOR_GetChID) { return NOR_GetChID(ucChannel,ucManufact,usDeviceNum); } } return FALSE; }
BOOL HRS_Start(USHORT usDeviceNumber, UCHAR ucManufactureID) { if(Nordic.isLoaded()) { pFuncStart HRS_Start = (pFuncStart)Nordic.resolve("HRS_Start"); if(HRS_Start) { return HRS_Start(usDeviceNumber,ucManufactureID); } } return FALSE; }
void emitSignals () { bool openBabelAvailable = openBabelInterface.isLoaded (); bool isInchiAvailable = inChIAvailable && inChIAvailable (); bool isGen2dAvailable = gen2dAvailable && gen2dAvailable (); qDebug() << "OpenBabel available: " << QString::number (openBabelAvailable) << "Library location:" << openBabelInterface.fileName(); qDebug() << "InChI available: " << QString::number (isInchiAvailable) << "gen2d available: " << QString::number (isGen2dAvailable); emit parent->obabelIfaceAvailable (openBabelAvailable); emit parent->inchiAvailable (isInchiAvailable && isGen2dAvailable); emit parent->optimizeAvailable(isGen2dAvailable); emit parent->obabelIfaceFileNameChanged(openBabelInterface.fileName()); }
short eCompass_GetYaw() { ECOMPASS_INFO Info; if(eCompass.isLoaded()) { pFuncCompassInfo eCompass_GetInfo = (pFuncCompassInfo) eCompass.resolve("eCompass_GetInfo"); if(eCompass_GetInfo) { eCompass_GetInfo(&Info); return Info.Yaw; } } return -1; }
//Altimeter library functions long AltimeterGetTemperature() { INFO_GET Info; if(Altimeter.isLoaded()) { pFuncGetAltInfo AltiMeter_GetInfo = (pFuncGetAltInfo) Altimeter.resolve("GetBikeInfo"); if(AltiMeter_GetInfo) { AltiMeter_GetInfo(&Info); return Info.OUT_TEMP; } } return -100; }
long AltimeterGetAltitude() { INFO_GET Info; if(Altimeter.isLoaded()) { pFuncGetAltInfo AltiMeter_GetInfo = (pFuncGetAltInfo) Altimeter.resolve("GetBikeInfo"); if(AltiMeter_GetInfo) { AltiMeter_GetInfo(&Info); return Info.OUT_ALTITUDE; } } return -1; }
BOOL AltimeterCalibrateAltitude(long altitude) { INFO_SET Info; Info.IN_ALTITUDE = altitude; if(Altimeter.isLoaded()) { pFuncCalibrateAlt AltiMeter_SetInfo = (pFuncCalibrateAlt) Altimeter.resolve("SetBikeInfo"); if(AltiMeter_SetInfo) { AltiMeter_SetInfo(&Info); return TRUE; } } return FALSE; }
/* * We do simple ref counting... We will add the QLibrary again * and again to the dictionary and on deref we will pop and pop it * until there are no more library and we will unload and delete the library * luckily dlopen does some ref counting as well so we don't need * to hack QPEApplication */ QLibrary* OPluginLibraryHolder::ref(const QString& str) { QLibrary *lib = m_libs[str]; /* if not in the dict try to load it */ if ( !lib ) { lib = new QLibrary( str, QLibrary::Immediately ); if ( !lib->isLoaded() ) { delete lib; return 0l; } } /* now refcount one up */ m_libs.insert( str, lib ); return lib; }
void tst_QLibrary::errorString() { QFETCH(int, operation); QFETCH(QString, fileName); QFETCH(bool, success); QFETCH(QString, errorString); QLibrary lib; if (!(operation & DontSetFileName)) { lib.setFileName(fileName); } bool ok = false; switch (operation & OperationMask) { case Load: ok = lib.load(); break; case Unload: ok = lib.load(); //### ok = lib.unload(); break; case Resolve: { ok = lib.load(); QCOMPARE(ok, true); if (success) { ok = lib.resolve("mylibversion"); } else { ok = lib.resolve("nosuchsymbol"); } break;} default: QFAIL(qPrintable(QString("Unknown operation: %1").arg(operation))); break; } QRegExp re(errorString); QString libErrorString = lib.errorString(); QVERIFY(!lib.isLoaded() || lib.unload()); QVERIFY2(re.exactMatch(libErrorString), qPrintable(libErrorString)); QCOMPARE(ok, success); }
int main(int argc, char *argv[]) { int ret = -1; LibraryCleanupHandler cleanup; { ::initApp("tokoloshtail", argc, argv); QCoreApplication app(argc, argv); if (!QDBusConnection::sessionBus().isConnected()) { fprintf(stderr, "Cannot connect to the D-Bus session bus.\n" "To start it, run:\n" "\teval `dbus-launch --auto-syntax`\n"); return 1; } { QDBusInterface iface(SERVICE_NAME, "/"); if (iface.isValid()) { iface.call("quit"); } } // const QString pluginDirectory = Config::value<QString>("plugindir", PLUGINDIR); // ### Can't make this work const QString pluginDirectory = Config::value<QString>("plugindir", QDir::cleanPath(QCoreApplication::applicationDirPath() + "/../plugins")); Log::log(10) << "Using plugin directory" << pluginDirectory; const QString backendName = Config::value<QString>("backend", "xine"); Log::log(10) << "Searching for backend" << backendName; QDir dir(pluginDirectory); if (!dir.exists()) { Log::log(0) << pluginDirectory << " doesn't seem to exist"; return 1; } { Tail tail; Backend *backend = 0; QLibrary *library = 0; QHash<QLibrary*, BackendPlugin*> candidates; foreach(const QFileInfo &fi, dir.entryInfoList(QDir::Files, QDir::Size)) { QLibrary *lib = new QLibrary(fi.absoluteFilePath()); CreateBackend createBackend = 0; if (lib->load() && (createBackend = (CreateBackend)lib->resolve("createTokoloshBackendInterface"))) { BackendPlugin *interface = createBackend(); if (interface && interface->keys().contains(backendName, Qt::CaseInsensitive)) { backend = interface->createBackend(&tail); if (backend) { library = lib; break; } else { Log::log(0) << fi.absoluteFilePath() << "doesn't seem to be able to create a backend"; } delete interface; } else if (!interface) { delete lib; } else { candidates[lib] = interface; } } else { if (lib->isLoaded()) { Log::log(1) << "Can't load" << fi.absoluteFilePath() << lib->errorString(); } delete lib; } } Q_ASSERT(!backend == !library); if (!backend) { for (QHash<QLibrary*, BackendPlugin*>::const_iterator it = candidates.begin(); it != candidates.end(); ++it) { const bool hadBackend = backend != 0; if (!backend) backend = it.value()->createBackend(&app); if (hadBackend || !backend) { it.key()->unload(); delete it.key(); } else { library = it.key(); } delete it.value(); } } if (!backend) { Log::log(0) << "Can't find a suitable backend"; return 1; } cleanup.library = library; bool registered = false; for (int i=0; i<5; ++i) { if (QDBusConnection::sessionBus().registerService(SERVICE_NAME)) { registered = true; break; } ::sleep(500); } if (!registered) { Log::log(0) << "Can't seem to register service" << QDBusConnection::sessionBus().lastError().message(); return 1; } if (!tail.setBackend(backend)) { Log::log(0) << backend->errorMessage() << backend->errorCode(); return 1; } QDBusConnection::sessionBus().registerObject("/", &tail, QDBusConnection::ExportScriptableSlots |QDBusConnection::ExportScriptableSignals); Log::log(10) << "Using" << backend->name(); ret = app.exec(); } } return ret; }
void Init( bool b, int rate2, int bits2, int chn2, int /*buff*/ ) { mustReset = false; if ( !b ) { Save.odczytajopcje(); fs.Init(); fs.ApplyB(); } PlErr = false; if ( b ) { if ( !isOpen ) { if ( !pa_lib.isLoaded() ) { QString libName = "libpulse-simple" + libExt; #ifdef Q_WS_X11 libName += ".0"; #endif pa_lib.setFileName( libName ); if ( !pa_lib.load() ) { errStr = pa_lib.errorString(); PlErr = true; return; } qmplay_pa_simple_new = ( _qmplay_pa_simple_new )pa_lib.resolve( "pa_simple_new" ); qmplay_pa_simple_free = ( _qmplay_pa_simple_free )pa_lib.resolve( "pa_simple_free" ); qmplay_pa_simple_write = ( _qmplay_pa_simple_write )pa_lib.resolve( "pa_simple_write" ); qmplay_pa_simple_read = ( _qmplay_pa_simple_read )pa_lib.resolve( "pa_simple_read" ); qmplay_pa_simple_flush = ( _qmplay_pa_simple_flush )pa_lib.resolve( "pa_simple_flush" ); if ( !qmplay_pa_simple_new || !qmplay_pa_simple_free || !qmplay_pa_simple_write || !qmplay_pa_simple_read || !qmplay_pa_simple_flush ) { pa_lib.unload(); errStr = "błąd podczas pobierania funkcji z biblioteki: " + libName; PlErr = true; return; } } switch ( bits2 ) { case 8: ss.format = PA_SAMPLE_U8; break; case 16: ss.format = PA_SAMPLE_S16NE; break; case 24: ss.format = PA_SAMPLE_S24NE; break; case 32: ss.format = PA_SAMPLE_S32NE; break; } ss.channels = chn2; ss.rate = rate2; attr.maxlength = ( uint32_t ) -1; attr.tlength = delay * ( rate2 * ( bits2/8 ) * chn2 ); attr.prebuf = ( uint32_t ) -1; attr.minreq = ( uint32_t ) -1; attr.fragsize = attr.tlength; pa_channel_map *chn_map = NULL; if ( chn2 > 2 && chn2 <= 8 ) { chn_map = new pa_channel_map; chn_map->channels = chn2; chn_map->map[ 0 ] = PA_CHANNEL_POSITION_FRONT_LEFT; chn_map->map[ 1 ] = PA_CHANNEL_POSITION_FRONT_RIGHT; chn_map->map[ 2 ] = PA_CHANNEL_POSITION_FRONT_CENTER; chn_map->map[ 3 ] = PA_CHANNEL_POSITION_LFE; chn_map->map[ 4 ] = PA_CHANNEL_POSITION_REAR_LEFT; chn_map->map[ 5 ] = PA_CHANNEL_POSITION_REAR_RIGHT; chn_map->map[ 6 ] = PA_CHANNEL_POSITION_SIDE_LEFT; chn_map->map[ 7 ] = PA_CHANNEL_POSITION_SIDE_RIGHT; } pulse = qmplay_pa_simple_new( NULL, "QMPlay", PA_STREAM_PLAYBACK, NULL, "Output", &ss, chn_map, &attr, NULL ); delete chn_map; if ( !pulse ) { pa_lib.unload(); errStr = "błąd podczas otwierania wyjścia PulseAudio"; PlErr = true; return; } if ( REC ) { pulseREC = qmplay_pa_simple_new( NULL, "QMPlay", PA_STREAM_RECORD, NULL, "Input", &ss, chn_map, &attr, NULL ); if ( !pulseREC ) { qmplay_pa_simple_free( pulse ); pa_lib.unload(); errStr = "błąd podczas otwierania wejścia PulseAudio"; PlErr = true; return; } } isOpen = true; } } }
void LocalApp::readSuffixFilter(){ QFile *suffixFilterFile = 0; if ( appName == "home") suffixFilterFile = new QFile (home+"/"+QString("home.suffixfilter")); else suffixFilterFile = new QFile (home+"/"+ appName + "/"+ appName + QString(".suffixfilter")); ERR<<"INFO: LocalApp::readSuffixFilter(): "<<suffixFilterFile->fileName()<<endl; #ifndef USE_QT5 if ( ! suffixFilterFile->open(QIODevice::ReadOnly) ){ #else if ( ! suffixFilterFile->open(QFile::ReadOnly) ){ #endif ERR<<"WARN: LocalApp::readSuffixFilter(): Unable to read : "<<suffixFilterFile->fileName()<<endl; suffixFilterFile->close(); }else { suffixFilter += suffixFilterFile->readAll(); suffixFilterFile->close(); } //TODO: convert suffix filter to map of string ERR<<"DBUG: LocalApp::readSuffixFilter(): "<<suffixFilter<<endl; delete suffixFilterFile; } void LocalApp::readLibraryLoadConfig(){ QFile *llConfigFile = 0; if ( appName == "home") llConfigFile = new QFile (home+"/"+QString("home.cfg")); else llConfigFile = new QFile (home+"/"+ appName + "/"+ appName + QString(".cfg")); #ifndef USE_QT5 if ( ! llConfigFile->open(QIODevice::ReadOnly) ){ #else if ( ! llConfigFile->open(QFile::ReadOnly) ){ #endif ERR<<"DBUG: LocalApp::readLibraryLoadConfig(): Unable to open file :"<<llConfigFile->fileName()<<endl; } else { QByteArray libConfig; while ( (libConfig = llConfigFile->readLine() ).length() > 0 ){ /* * Read the config file * <scriptname>:<libraryname> */ QString line(libConfig); if( line.split(":").length() > 1) { QString script = line.split(":")[0]; QString soFile = line.split(":")[1]; #ifndef WINDOWS soFile.replace(QString("\n"), QString("")); soFile += QString(".so"); //soFile.remove(soFile.length()-1,1); #else soFile.replace(QString("\r\n"), QString("")); soFile += QString(".dll"); //soFile.remove(soFile.length()-2,2); #endif if( appName == "home"){ QLibrary *lib = new QLibrary( home + "/" + soFile ); lib->setLoadHints(QLibrary::ResolveAllSymbolsHint); lib->load(); ERR<<"ERRR: LocalApp::readLibraryLoadConfig(): "<< script<<" -> "<<lib->fileName()<<": Loaded ? "<<lib->isLoaded()<<endl; mapScriptToSo[script] = lib; } else { QLibrary *lib = new QLibrary( home + "/" + appName + "/" + soFile, this ); lib->setLoadHints(QLibrary::ResolveAllSymbolsHint); lib->load(); ERR<<"ERRR: LocalApp::readLibraryLoadConfig(): "<<script<<" -> "<<lib->fileName()<<": Loaded ? "<<lib->isLoaded()<<endl; mapScriptToSo[script] = lib; } } } } delete llConfigFile; } QString LocalApp::readAppName( QUrl url ){ QString app(""); #ifndef USE_QT5 ERR<<"INFO: LocalApp::readAppName(): Encoded Path: "<<url.encodedPath()<<endl; //QStringList app = url.encodedPath().split('/')[0]; //app = list[0]; if ( app.contains(".py")){ app = "home"; } ERR<<"INFO: LocalApp::readAppName(): App: "<<app<<endl; #else ERR<<"INFO: LocalApp::readAppName(): Path: "<<url.path()<<endl; app = url.path().split('/')[0]; if ( app.contains(".py") || app.contains(".")){ app = "home"; } ERR<<"INFO: LocalApp::readAppName(): App: "<<app<<endl; ERR<<"INFO: LocalApp::readAppName(): Path: "<<url.path()<<endl; #endif return app; }