void VIHWClass::initializeHWLibraries() { //ApplicationInterfacePlugin QPluginLoader loader1("libPTApplicationcardInterface.so"); IAppCard = qobject_cast<IApplicationCardInterface*>(loader1.instance()); IAppCard->setDeviceName(SLOT0); IAppCard->enumerateAPPCard(); qDebug() << "APPCard Code ID:" <<IAppCard->readAppCardCodeId(); m_nInterruptValue = IAppCard->readScratchPad(); qDebug()<<"Scratch:"<<m_nInterruptValue; //BackPanel Interface Plugin QPluginLoader loader2("libBackPlaneInterface.so"); IBackPlane = qobject_cast<IntefaceBackPlane*> (loader2.instance()); IBackPlane->InitializeBpObject(); qDebug() << "BACKPlane Code ID:" <<IBackPlane->readBackPlaneCodeID(); IBackPlane->writeBackPlaneRegister(0x01, 0x48); //PSOC Interface Plugin QPluginLoader loader3("libPTPsocInterface2.so"); IPsoc = qobject_cast<IPSOCCOMMUNICATION*>(loader3.instance()); IPsoc->openSerial(); QPluginLoader loaderSPIMemory("libSPIMemoryInterface.so"); ISPIMemory = qobject_cast<ISPIMemoryInterface*> (loaderSPIMemory.instance()); ISPIMemory->setHardwarwObject(IAppCard); ISPIMemory->accessSPIMemory(BACKPLANE); m_objAD5318Component = new AD5318Components(IAppCard); m_objAD5293Component = new AD5293(IAppCard); resetDAC(); //IPsoc->closeSerial(); //IPsoc->changeBaudRate(1); //IPsoc->writeSerial(0x50); //IPsoc->writeSerial(0x01); peformDriveConfiguration(); }
TEST(ClassLoaderTest, correctLazyLoadUnload) { try { ASSERT_FALSE(class_loader::class_loader_private::isLibraryLoadedByAnybody(LIBRARY_1)); class_loader::ClassLoader loader1(LIBRARY_1, true); ASSERT_FALSE(class_loader::class_loader_private::isLibraryLoadedByAnybody(LIBRARY_1)); ASSERT_FALSE(loader1.isLibraryLoaded()); { boost::shared_ptr<Base> obj = loader1.createInstance<Base>("Cat"); ASSERT_TRUE(class_loader::class_loader_private::isLibraryLoadedByAnybody(LIBRARY_1)); ASSERT_TRUE(loader1.isLibraryLoaded()); } //The library will unload automatically when the only plugin object left is destroyed ASSERT_FALSE(class_loader::class_loader_private::isLibraryLoadedByAnybody(LIBRARY_1)); return; } catch(class_loader::ClassLoaderException& e) { FAIL() << "ClassLoaderException: " << e.what() << "\n"; } catch(...) { FAIL() << "Unhandled exception"; } }
TEST(ClassLoaderTest, threadSafety) { class_loader::ClassLoader loader1(LIBRARY_1); ASSERT_TRUE(loader1.isLibraryLoaded()); //Note: Hard to test thread safety to make sure memory isn't corrupted. The hope is this test is hard enough that once in a while it'll segfault or something if there's some implementation error. try { std::vector<boost::thread*> client_threads; for(unsigned int c = 0; c < 1000; c++) client_threads.push_back(new boost::thread(boost::bind(&run, &loader1))); for(unsigned int c = 0; c < client_threads.size(); c++) client_threads.at(c)->join(); for(unsigned int c = 0; c < client_threads.size(); c++) delete(client_threads.at(c)); loader1.unloadLibrary(); ASSERT_FALSE(loader1.isLibraryLoaded()); } catch(const class_loader::ClassLoaderException& ex) { FAIL() << "Unexpected ClassLoaderException."; } catch(...) { FAIL() << "Unknown exception."; } }
TEST(ClassLoaderTest, invalidBase) { try { class_loader::ClassLoader loader1(LIBRARY_1, false); if(loader1.isClassAvailable<InvalidBase>("Cat")) { FAIL() << "Cat should not be available for InvalidBase"; } else if(loader1.isClassAvailable<Base>("Cat")) { SUCCEED(); return; } else FAIL() << "Class not available for correct base class."; } catch(const class_loader::LibraryLoadException& e) { FAIL() << "Unexpected exception"; } catch(...) { FAIL() << "Unexpected and unknown exception caught.\n"; } }
GPIOEvent::GPIOEvent(QWidget *parent,int *pKeyCode):QWidget(parent){ //qDebug()<<"----------------------------GPIO LIBRARY STARTS----------------------------"; m_TW = parent; m_nKey = pKeyCode; //Backpanel Interface Plugin QPluginLoader loader2("libBackPlaneInterface.so",this); IBackPlane = qobject_cast<IntefaceBackPlane*>(loader2.instance()); IBackPlane->InitializeBpObject(); QPluginLoader loader1("libPTApplicationcardInterface.so"); IAppCard = qobject_cast<IApplicationCardInterface*>(loader1.instance()); IAppCard->setDeviceName(SLOT0); IAppCard->enumerateAPPCard(); m_nInterruptValue = IAppCard->readScratchPad(); QPluginLoader loaderSPIMemory("libSPIMemoryInterface.so"); ISPIMemory = qobject_cast<ISPIMemoryInterface*> (loaderSPIMemory.instance()); IAppCard->setSPIAppendBit(0xC000); QPluginLoader loader3("libPTPsocInterface2.so"); IPsoc = qobject_cast<IPSOCCOMMUNICATION*>(loader3.instance()); IPsoc->openSerial(); m_nReceiveData = new unsigned short int[300]; m_stopFlag = false; m_strReceiveName =".\ActualData.bin"; //m_objEvent = new QEvent(APPCARDDRIVEEVENT); }
TEST(ClassLoaderTest, basicLoad) { try { class_loader::ClassLoader loader1(LIBRARY_1, false); loader1.createInstance<Base>("Cat")->saySomething(); //See if lazy load works } catch(class_loader::ClassLoaderException& e) { FAIL() << "ClassLoaderException: " << e.what() << "\n"; } SUCCEED(); }
void simple_loading_example(int argc, char **argv) { std::string LIBRARY_1="libplugin_animals.so"; std::string LIBRARY_2="libplugin_fantasy.so"; try { envire::core::Environment envire1; class_loader::ClassLoader loader1(LIBRARY_1, false); std::vector<std::string> classes = loader1.getAvailableClasses<Base>(); for(unsigned int c = 0; c < classes.size(); ++c) { envire::core::Item<Base> item; item->value = loader1.createInstance<Base>(classes[c]); item->value->saySomething(); envire1.insert(boost::uuids::random_generator(), new envire::core::Environment()); } } catch(class_loader::ClassLoaderException& e) { std::cout << "ClassLoaderException: " << e.what() << "\n"; } catch (class_loader::CreateClassException& e) { std::cout <<"CreateClassException: "<< e.what() << "\n"; } try { class_loader::ClassLoader loader2(LIBRARY_2, false); std::vector<std::string> classes = loader2.getAvailableClasses<Base>(); for(unsigned int c = 0; c < classes.size(); ++c) { boost::shared_ptr<Base> plugin = loader2.createInstance<Base>(classes[c]); plugin->saySomething(); } } catch(class_loader::ClassLoaderException& e) { std::cout << "ClassLoaderException: " << e.what() << "\n"; } catch (class_loader::CreateClassException& e) { std::cout <<"CreateClassException: "<< e.what() << "\n"; } }
TEST(ClassLoaderTest, loadRefCountingLazy) { try { class_loader::ClassLoader loader1(LIBRARY_1, true); ASSERT_FALSE(loader1.isLibraryLoaded()); { boost::shared_ptr<Base> obj = loader1.createInstance<Base>("Dog"); ASSERT_TRUE(loader1.isLibraryLoaded()); } ASSERT_FALSE(loader1.isLibraryLoaded()); loader1.loadLibrary(); ASSERT_TRUE(loader1.isLibraryLoaded()); loader1.loadLibrary(); ASSERT_TRUE(loader1.isLibraryLoaded()); loader1.unloadLibrary(); ASSERT_TRUE(loader1.isLibraryLoaded()); loader1.unloadLibrary(); ASSERT_FALSE(loader1.isLibraryLoaded()); loader1.unloadLibrary(); ASSERT_FALSE(loader1.isLibraryLoaded()); loader1.loadLibrary(); ASSERT_TRUE(loader1.isLibraryLoaded()); return; } catch(const class_loader::ClassLoaderException& e) { FAIL() << "Unexpected exception.\n"; } catch(...) { FAIL() << "Unknown exception caught.\n"; } FAIL() << "Did not throw exception as expected.\n"; }
TEST(ClassLoaderTest, nonExistentLibrary) { try { class_loader::ClassLoader loader1("libDoesNotExist.so", false); } catch(const class_loader::LibraryLoadException& e) { SUCCEED(); return; } catch(...) { FAIL() << "Unknown exception caught.\n"; } FAIL() << "Did not throw exception as expected.\n"; }
TEST(ClassLoaderTest, correctNonLazyLoadUnload) { try { ASSERT_FALSE(class_loader::class_loader_private::isLibraryLoadedByAnybody(LIBRARY_1)); class_loader::ClassLoader loader1(LIBRARY_1, false); ASSERT_TRUE(class_loader::class_loader_private::isLibraryLoadedByAnybody(LIBRARY_1)); ASSERT_TRUE(loader1.isLibraryLoaded()); loader1.unloadLibrary(); ASSERT_FALSE(class_loader::class_loader_private::isLibraryLoadedByAnybody(LIBRARY_1)); ASSERT_FALSE(loader1.isLibraryLoaded()); return; } catch(class_loader::ClassLoaderException& e) { FAIL() << "ClassLoaderException: " << e.what() << "\n"; } catch(...) { FAIL() << "Unhandled exception"; } }
TEST(ClassLoaderTest, loadRefCountingNonLazy) { try { class_loader::ClassLoader loader1(LIBRARY_1, false); ASSERT_TRUE(loader1.isLibraryLoaded()); loader1.loadLibrary(); loader1.loadLibrary(); ASSERT_TRUE(loader1.isLibraryLoaded()); loader1.unloadLibrary(); ASSERT_TRUE(loader1.isLibraryLoaded()); loader1.unloadLibrary(); ASSERT_TRUE(loader1.isLibraryLoaded()); loader1.unloadLibrary(); ASSERT_FALSE(loader1.isLibraryLoaded()); loader1.unloadLibrary(); ASSERT_FALSE(loader1.isLibraryLoaded()); loader1.loadLibrary(); ASSERT_TRUE(loader1.isLibraryLoaded()); return; } catch(const class_loader::ClassLoaderException& e) { FAIL() << "Unexpected exception.\n"; } catch(...) { FAIL() << "Unknown exception caught.\n"; } FAIL() << "Did not throw exception as expected.\n"; }
TEST(ClassLoaderTest, nonExistentPlugin) { class_loader::ClassLoader loader1(LIBRARY_1, false); try { boost::shared_ptr<Base> obj = loader1.createInstance<Base>("Bear"); if(obj == NULL) FAIL() << "Null object being returned instead of exception thrown."; obj->saySomething(); } catch(const class_loader::CreateClassException& e) { SUCCEED(); return; } catch(...) { FAIL() << "Unknown exception caught.\n"; } FAIL() << "Did not throw exception as expected.\n"; }