예제 #1
0
TEST(Variant, managedObjectCopy)
{
	Manager mgr(1);
	bool a = false;
	{
		Handle<TestManaged> p{new TestManaged{mgr, a}};
		Variant v1 = Variant::fromObject(p);
		{
			Variant v2 = v1;
			ASSERT_TRUE(v2.isObject());
			ASSERT_EQ(p, v2.asObject());
			ASSERT_TRUE(a);
		}
		ASSERT_TRUE(a);
	}
	ASSERT_FALSE(a);
}
void SensorListener::disableSensor(sensor_type_t type) {
    Sensor const* sensor;
    SensorManager& mgr(SensorManager::getInstance());

    LOG_FUNCTION_NAME;

    Mutex::Autolock lock(&mLock);

    if ((type & SENSOR_ORIENTATION) && (sensorsEnabled & SENSOR_ORIENTATION)) {
        sensor = mgr.getDefaultSensor(Sensor::TYPE_ACCELEROMETER);
        CAMHAL_LOGDB("orientation = %p (%s)", sensor, sensor->getName().string());
        mSensorEventQueue->disableSensor(sensor);
        sensorsEnabled &= ~SENSOR_ORIENTATION;
    }

    LOG_FUNCTION_NAME_EXIT;
}
    void SensorListener::disableSensor(sensor_type_t type) {
        const Sensor *sensor;

        SensorManager& mgr(SensorManager::getInstance());

        AutoMutex lock(mLock);

        if ((type & SENSOR_ORIENTATION) && (sensorsEnabled & SENSOR_ORIENTATION)) {
            sensor = mgr.getDefaultSensor(Sensor::TYPE_ACCELEROMETER);
            ALOGV("%s: name: %s, type: %d, handle: %d",
                  __FUNCTION__,
                  sensor->getName().string(), sensor->getType(), sensor->getHandle());
            mSensorEventQueue->disableSensor(sensor->getHandle());
            sensorsEnabled &= ~SENSOR_ORIENTATION;
            mRegisterHandle = -1;
        }
    }
예제 #4
0
/** Saves the chapter as valid HTML page. */
void CBibleReadWindow::saveChapterHTML() {
    //saves the complete chapter to disk
    Q_ASSERT(dynamic_cast<const CSwordBibleModuleInfo*>(modules().first()) != 0);
    const CSwordBibleModuleInfo *bible = static_cast<const CSwordBibleModuleInfo*>(modules().first());

    CSwordVerseKey dummy(*verseKey());
    dummy.setVerse(1);

    CSwordVerseKey vk(*verseKey());
    vk.setLowerBound(dummy);

    dummy.setVerse(bible->verseCount(dummy.book(), dummy.getChapter()));
    vk.setUpperBound(dummy);

    CExportManager mgr(true, tr("Saving"), filterOptions(), displayOptions());
    mgr.saveKey(&vk, CExportManager::HTML, true);
}
예제 #5
0
void cac::destroyIIU ( tcpiiu & iiu )
{
    {
        callbackManager mgr ( this->notify, this->cbMutex );
        epicsGuard < epicsMutex > guard ( this->mutex );

        if ( iiu.channelCount ( guard ) ) {
            char hostNameTmp[64];
            iiu.getHostName ( guard, hostNameTmp, sizeof ( hostNameTmp ) );
            genLocalExcep ( mgr.cbGuard, guard, *this, ECA_DISCONN, hostNameTmp );
        }
        osiSockAddr addr = iiu.getNetworkAddress ( guard );
        if ( addr.sa.sa_family == AF_INET ) {
            inetAddrID tmp ( addr.ia );
            bhe * pBHE = this->beaconTable.lookup ( tmp );
            if ( pBHE ) {
                pBHE->unregisterIIU ( guard, iiu );
            }
        }
       
        assert ( this->pudpiiu );
        iiu.disconnectAllChannels ( mgr.cbGuard, guard, *this->pudpiiu );

        this->serverTable.remove ( iiu );
        this->circuitList.remove ( iiu );
    }

    // this destroys a timer that takes the primary mutex
    // so we must not hold the primary mutex here
    //
    // this waits for send/recv threads to exit
    // this also uses the cac free lists so cac must wait 
    // for this to finish before it shuts down

    iiu.~tcpiiu ();

    {
        epicsGuard < epicsMutex > guard ( this->mutex );
        this->freeListVirtualCircuit.release ( & iiu );
        this->iiuExistenceCount--;
        // signal iiu uninstall event so that cac can properly shut down
        this->iiuUninstall.signal();
    }
    // do not touch "this" after lock is released above
}
예제 #6
0
void SensorListener::enableSensor(sensor_type_t type) {
    android::Sensor const* sensor;
    android::SensorManager& mgr(android::SensorManager::getInstance());

    LOG_FUNCTION_NAME;

    android::AutoMutex lock(&mLock);

    if ((type & SENSOR_ORIENTATION) && !(sensorsEnabled & SENSOR_ORIENTATION)) {
        sensor = mgr.getDefaultSensor(android::Sensor::TYPE_ACCELEROMETER);
        CAMHAL_LOGDB("orientation = %p (%s)", sensor, sensor->getName().string());
        mSensorEventQueue->enableSensor(sensor);
        mSensorEventQueue->setEventRate(sensor, ms2ns(100));
        sensorsEnabled |= SENSOR_ORIENTATION;
    }

    LOG_FUNCTION_NAME_EXIT;
}
예제 #7
0
int main(int argc, char* argv[])
{
  int argc_fake = 1;
  char* argv_fake = new char[128];
  sprintf(argv_fake, "app-ScorbotConsole");
  QApplication app(argc_fake, &argv_fake);

  ModelManager mgr("Scorbot Console");

  nub::ref<ScorbotConsole> console(new ScorbotConsole(mgr));
  mgr.addSubComponent(console);
  if(mgr.parseCommandLine(argc, argv, "", 0, 0) == false) return -1;
  mgr.start();


  //console->setGeometry(100,100, 600, 600);
  console->show();
  return app.exec();
}
예제 #8
0
void FdoSmPhPostGisOwner::SetOptions()
{
	bool validOption = false;

	// validate LT method
	validOption = (GetLtMode() == NoLtLock || GetLtMode() == FdoMode);

	if (false == validOption)
    {
		SetLtMode(NoLtLock);
    }

	FdoStringP tempValue = FdoStringP::Format(L"%d",
        static_cast<int>(GetLtMode()));

	FdoStringP sqlStmt = FdoStringP::Format(
        L"UPDATE f_options SET value = '%ls'"
        L"WHERE name = 'LT_MODE'",
        static_cast<FdoString*>(tempValue));

	FdoSmPhPostGisMgrP mgr(GetManager()->SmartCast<FdoSmPhPostGisMgr>());
    
    GdbiConnection* gdbiConn = NULL;
    gdbiConn = mgr->GetGdbiConnection();

	gdbiConn->ExecuteNonQuery(static_cast<const char*>(sqlStmt));

	// validate locking method
	validOption = (NoLtLock == GetLckMode() || FdoMode == GetLckMode());
    if (false == validOption)
    {
		SetLckMode(NoLtLock);
    }

	tempValue = FdoStringP::Format(L"%d", static_cast<int>(GetLckMode()));

	sqlStmt = FdoStringP::Format(
        L"UPDATE f_options SET value = '%ls'"
        L"WHERE name ='LOCKING_MODE'",
		static_cast<FdoString*>(tempValue));

	gdbiConn->ExecuteNonQuery(static_cast<const char*>(sqlStmt));
}
예제 #9
0
TEST(Manager, selfReferentialCyclicDependencies)
{
	std::array<bool, 2> a;

	Manager mgr(1);
	{
		TestManaged *n1;
		n1 = new TestManaged(mgr, a[1]);

		{
			Rooted<TestManaged> hr{new TestManaged(mgr, a[0])};
			ASSERT_TRUE(a[0] && a[1]);
			hr->addRef(n1);
			n1->addRef(n1);
		}

		// All nodes must have set their "alive" flag to false
		ASSERT_FALSE(a[0] || a[1]);
	}
}
예제 #10
0
TEST(CampaignTest, testResetProgress) {
	SCOPED_TRACE("gamestate2.sqlite");
	FS.copy("gamestate2.sqlite", "gamestate2.sqlite.temp");
	SQLitePersister persister(System.getDatabaseDirectory() + "gamestate2.sqlite.temp");
	ASSERT_TRUE(persister.init()) << "Failed to initialize the persister";
	LUAMapManager mapMgr;
	mapMgr.loadMaps();
	TextureDefinition t("small");
	SpriteDefinition::get().init(t);
	CampaignManager mgr(&persister, mapMgr);
	mgr.init();
	CampaignPtr c = mgr.getAutoActiveCampaign();
	ASSERT_TRUE(c.get()) << "There is no active campaign";
	ASSERT_EQ("ice", c->getId());
	ASSERT_TRUE(c->isUnlocked()) << "Campaign ice is not unlocked";
	ASSERT_TRUE(mgr.resetAllSavedData()) << "Failed to reset the campaign progress";
	ASSERT_FALSE(c->isUnlocked()) << "Campaign ice is still unlocked";
	CampaignPtr activeCampaign = mgr.getActiveCampaign();
	ASSERT_EQ("tutorial", activeCampaign->getId());
}
void
QvisPostableWindowObserver::loadSubject()
{
    if (!subject)
        return;

    QString filename = QFileDialog::getOpenFileName(this,
                                                    tr("Open Attribute XML"),
                                                    NULL,
                                                    tr("XML Files (*.xml);;"
                                                       "All files (*)"));
    if (filename.isNull())
        return;
    
    AttributeSubject *as = (AttributeSubject *)subject;
    SingleAttributeConfigManager mgr(as);
    mgr.Import(filename.toStdString());
    as->SelectAll();
    as->Notify();
}
예제 #12
0
파일: main_proxy.C 프로젝트: flipk/pfkutils
int
main()
{
    fd_mgr                   mgr( /*debug*/ false, /*threshold*/ 0 );
    fd_interface           * hkup;
    Pipe_Mgr                 pipe_mgr;
    Adm_Gateway_factory      factory ( &pipe_mgr );
    Config_fd                config_fd( &pipe_mgr, CONFIG_UDP_PORT_NO );

    fd_interface * fd1 = new Adm_Hookup_fd( &factory, 2500, "127.1", 2501 );
    fd_interface * fd2 = new Adm_Hookup_fd( &factory, 2502, "127.1", 2503 );

    mgr.register_fd( &config_fd );
    mgr.register_fd( fd1 );
    mgr.register_fd( fd2 );

    mgr.loop();

    return 0;
}
예제 #13
0
TEST(Manager, doubleRooted)
{
	std::array<bool, 4> a;

	Manager mgr(1);
	{
		TestManaged *n1, *n2;
		n1 = new TestManaged(mgr, a[1]);
		n2 = new TestManaged(mgr, a[2]);

		{
			Rooted<TestManaged> hr1{new TestManaged(mgr, a[0])};
			{
				Rooted<TestManaged> hr2{new TestManaged(mgr, a[3])};

				// All nodes must have set their "alive" flag to true
				for (bool v : a) {
					ASSERT_TRUE(v);
				}

				// Reference n1 and n2 in the rooted nodes
				hr1->addRef(n1);
				hr2->addRef(n2);

				// Create cyclical dependency between n2 and n1
				n1->addRef(n2);
				n2->addRef(n1);
			}

			// hr2 is dead, all other nodes are still alive
			ASSERT_FALSE(a[3]);
			ASSERT_TRUE(a[0] && a[1] && a[2]);
		}

		// All nodes are dead
		for (bool v : a) {
			ASSERT_FALSE(v);
		}
	}
}
예제 #14
0
void FindAssociation::findCallback(void* callbackData, T_DIMSE_C_FindRQ* /*rq*/, int responseCount, T_DIMSE_C_FindRSP* rsp, DcmDataset *responseIdentifiers)
{
        FindCallbackInfo* pCallback = (FindCallbackInfo*) callbackData;

        if (pCallback->pCaller->GetMaxResults() > 0 && responseCount > pCallback->pCaller->GetMaxResults()) {
                LOG_DEBUG(pCallback->pCaller->ambitolog, "findCallback(): Ignoring response num " << responseCount << ". The maximum number of responses was " << pCallback->pCaller->GetMaxResults());
                rsp->DimseStatus = STATUS_FIND_Cancel_MatchingTerminatedDueToCancelRequest;
                pCallback->pCaller->Stop();
                ASC_releaseAssociation(pCallback->assoc);
                return;
        }

        wxString mess = wxString::Format(_("%d results has been found"), (int)(responseCount) );
        std::string mensaje(mess.ToUTF8());

        LOG_DEBUG(pCallback->pCaller->ambitolog, "Processing response num " << responseCount);
        if(!pCallback->pCaller->NotificarProgreso(0.0f, mensaje)) {
                rsp->DimseStatus = STATUS_FIND_Cancel_MatchingTerminatedDueToCancelRequest;
                pCallback->pCaller->Stop();
                ASC_releaseAssociation(pCallback->assoc);
                LOG_INFO(pCallback->pCaller->ambitolog, "Operation canceled by user");
                return;
        } else {
                DcmDataset* response = new DcmDataset(*responseIdentifiers);

                if (pCallback->pCaller->bPushResults) {
                        pCallback->pCaller->result.push(response);
                        //push into Ginkgo data...
                        if (pCallback->pCaller->pResultsWrapper != NULL && pCallback->pCaller->pDicomServer.IsValid()) {
                                GIL::DICOM::DICOMManager mgr( response, pCallback->pCaller->pDicomServer->GetDefaultCharset() );
                                GNC::GCS::Ptr<GIL::DICOM::DicomDataset> base = new GIL::DICOM::DicomDataset();
                                mgr.CargarJerarquia((*base), DCM_MaxReadLength);
                                pCallback->pCaller->pResultsWrapper->push_back(base);
                        }
                } else {
                        LOG_DEBUG("C-FIND", "No results found");
                }
                pCallback->pCaller->OnResponseReceived(response);
        }
}
예제 #15
0
TEST(Manager, hiddenRootedGraph)
{
	constexpr int nElem = 16;
	std::array<bool, nElem> a;
	bool b;
	Manager mgr(1);

	{
		Rooted<HidingTestManaged> n{new HidingTestManaged{mgr, b}};
		n->setHiddenRef(createFullyConnectedGraph(mgr, nElem, &a[0]));

		ASSERT_TRUE(b);
		for (bool v : a) {
			ASSERT_TRUE(v);
		}
	}

	ASSERT_FALSE(b);
	for (bool v : a) {
		ASSERT_FALSE(v);
	}
}
예제 #16
0
TEST(Owned, equalsAndAssign)
{
	Manager mgr(1);

	Managed *n1 = new Managed(mgr), *n2 = new Managed(mgr);

	Rooted<Managed> rh1{n1};
	Rooted<Managed> rh2{n2};

	Owned<Managed> h2{n2, n1};

	// Equals operator
	ASSERT_TRUE(rh1 == n1);
	ASSERT_TRUE(n1 == rh1);
	ASSERT_FALSE(rh1 == rh2);
	ASSERT_TRUE(rh2 == h2);
	ASSERT_TRUE(h2 == rh2);

	// Assignment operator
	Rooted<Managed> rh2b;

	ASSERT_FALSE(rh2b == rh2);
	rh2b = rh2;
	ASSERT_TRUE(rh2b == rh2);
	ASSERT_TRUE(rh2b == h2);

	rh2b = h2;
	ASSERT_TRUE(rh2b == h2);

	Owned<Managed> h2b;
	ASSERT_FALSE(rh2 == h2b);
	ASSERT_FALSE(h2 == h2b);
	h2b = h2;
	ASSERT_TRUE(rh2 == h2b);
	ASSERT_TRUE(h2 == h2b);

	Owned<Managed> h2c{h2b, n1};
	ASSERT_TRUE(h2b == h2c);
}
예제 #17
0
status_t SensorListener::initialize() {
    status_t ret = NO_ERROR;
    SensorManager& mgr(SensorManager::getInstance());

    LOG_FUNCTION_NAME;

    sp<Looper> mLooper;

    mSensorEventQueue = mgr.createEventQueue();
    if (mSensorEventQueue == NULL) {
        CAMHAL_LOGEA("createEventQueue returned NULL");
        ret = NO_INIT;
        goto out;
    }

    mLooper = new Looper(false);
    mLooper->addFd(mSensorEventQueue->getFd(), 0, ALOOPER_EVENT_INPUT, sensor_events_listener, this);

    if (mSensorLooperThread.get() == NULL)
            mSensorLooperThread = new SensorLooperThread(mLooper.get());

    if (mSensorLooperThread.get() == NULL) {
        CAMHAL_LOGEA("Couldn't create sensor looper thread");
        ret = NO_MEMORY;
        goto out;
    }

    ret = mSensorLooperThread->run("sensor looper thread", PRIORITY_URGENT_DISPLAY);
    if (ret == INVALID_OPERATION){
        CAMHAL_LOGDA("thread already running ?!?");
    } else if (ret != NO_ERROR) {
        CAMHAL_LOGEA("couldn't run thread");
        goto out;
    }

 out:
    LOG_FUNCTION_NAME_EXIT;
    return ret;
}
예제 #18
0
TEST(TransferTestHelpers, Transfer)
{
    uavcan::PoolAllocator<uavcan::MemPoolBlockSize * 8, uavcan::MemPoolBlockSize> pool;

    uavcan::TransferBufferManager<128, 1> mgr(pool);
    uavcan::TransferBufferAccessor tba(mgr, uavcan::TransferBufferManagerKey(0, uavcan::TransferTypeMessageBroadcast));

    uavcan::RxFrame frame(uavcan::Frame(123, uavcan::TransferTypeMessageBroadcast, 1, 0, 0),
                          uavcan::MonotonicTime(), uavcan::UtcTime(), 0);
    frame.setEndOfTransfer(true);
    uavcan::MultiFrameIncomingTransfer mfit(tsMono(10), tsUtc(1000), frame, tba);

    // Filling the buffer with data
    static const std::string TEST_DATA = "Kaneda! What do you see? Kaneda! What do you see? Kaneda! Kaneda!!!";
    ASSERT_TRUE(tba.create());
    ASSERT_EQ(TEST_DATA.length(), tba.access()->write(0, reinterpret_cast<const uint8_t*>(TEST_DATA.c_str()),
                                                      unsigned(TEST_DATA.length())));

    // Reading back
    const Transfer transfer(mfit, uavcan::DataTypeDescriptor());
    ASSERT_EQ(TEST_DATA, transfer.payload);
}
예제 #19
0
TEST(Manager, storeData)
{
	Manager mgr(1);

	std::array<bool, 5> a;

	{
		Rooted<TestManaged> n{new TestManaged{mgr, a[0]}};

		mgr.storeData(n.get(), "key1", new TestManaged{mgr, a[1]});

		Managed *m2 = new TestManaged{mgr, a[2]};
		mgr.storeData(n.get(), "key2", m2);

		ASSERT_TRUE(a[0] && a[1] && a[2]);

		ASSERT_TRUE(mgr.deleteData(n.get(), "key1"));
		ASSERT_FALSE(a[1]);
		ASSERT_FALSE(mgr.deleteData(n.get(), "key1"));

		mgr.storeData(n.get(), "key1", new TestManaged{mgr, a[3]});
		ASSERT_TRUE(a[3]);

		Managed *m = new TestManaged{mgr, a[4]};
		mgr.storeData(n.get(), "key1", m);
		ASSERT_FALSE(a[3]);
		ASSERT_TRUE(a[4]);

		ASSERT_EQ(m, mgr.readData(n.get(), "key1"));
		ASSERT_EQ(m2, mgr.readData(n.get(), "key2"));

		auto map = mgr.readData(n.get());
		ASSERT_EQ(2U, map.size());
		ASSERT_TRUE(map.find("key1") != map.end());
		ASSERT_TRUE(map.find("key2") != map.end());
	}

	ASSERT_FALSE(a[0] || a[1] || a[2] || a[3] || a[4]);
}
예제 #20
0
TEST(Manager, disconnectSubgraph)
{
	std::array<bool, 4> a;

	Manager mgr(1);
	{
		TestManaged *n1, *n2, *n3;
		n1 = new TestManaged(mgr, a[1]);
		n2 = new TestManaged(mgr, a[2]);
		n3 = new TestManaged(mgr, a[3]);

		{
			Rooted<TestManaged> hr{new TestManaged(mgr, a[0])};

			// Create a linear dependency chain
			hr->addRef(n1);
			n1->addRef(n2);
			n2->addRef(n3);

			// All nodes must have set their "alive" flag to true
			for (bool v : a) {
				ASSERT_TRUE(v);
			}

			// Remove the reference from n1 to n2
			n1->deleteRef(n2);

			// Nodes 2 and 3 must be dead, all others alive
			ASSERT_FALSE(a[2] || a[3]);
			ASSERT_TRUE(a[0] && a[1]);
		}

		// All nodes must have set their "alive" flag to false
		for (bool v : a) {
			ASSERT_FALSE(v);
		}
	}
}
예제 #21
0
파일: empltest.cpp 프로젝트: Mindful/sos
int main()
{
  Employee empl("John Burke", 25.0);
  Manager mgr("Jan Kovacs", 1200.0, true);
  Supervisor sup("Denise Zephyr", 780.0, "Accounting");

  // Assume all employees worked 40 hours this period.

  cout << "For Employee:" << endl;
  cout << "Name: " << empl.getName() << endl;
  cout << "Pay: " << empl.pay(40.0) << endl;

  cout << "Changing the Employee's name..." << endl;
  empl.setName("Doug Conners");
  cout << "New Name: " << empl.getName() << endl;

  cout << endl;
  cout << "For Manager:" << endl;
  cout << "Name: " << mgr.getName() << endl;
  cout << "Salaried: " << mgr.getSalaried() << endl;
  cout << "Pay: " << mgr.pay(40.0) << endl;

  cout << "Changing the Manager's salaried status..." << endl;
  mgr.setSalaried(false);
  cout << "New Pay: " << mgr.pay(40.0) << endl;

  cout << endl;
  cout << "For Supervisor:" << endl;
  cout << "Name: " << sup.getName() << endl;
  cout << "Pay: " << sup.pay(40.0) << endl;
  cout << "Dept: " << sup.getDept() << endl;

  cout << "Changing the Supervisor's pay rate..." << endl;
  sup.setPayRate(900.0);
  cout << "New Pay: " << sup.pay(40.0) << endl;

  return 0;
}
QAbstractLangList::QAbstractLangList(const QString& langCode ,const QString& qmfilter,const QString &qmd,const QString &conf)
//    :cfg(conf),qmDir(qmd),languageCode(langCode),haveSysLangCode(false),qmFilter(qmfilter)
{
    ZDEBUG

#ifdef QAbstractLangList_QT4
    Q_INIT_RESOURCE(resources);
#endif //QAbstractLangList_QT4

    d=new QAbstractLangListPrivate;
    d->ts=new QTranslator(qApp);
    d->thisQmDir=".",d->cfg=conf,d->qmDir=qmd,d->languageCode=langCode,d->haveSysLangCode=false,d->qmFilter=qmfilter;

    qApp->installTranslator(d->ts);

        //频繁的install会产生问题吗

	if(d->languageCode.isEmpty()) {
#ifdef NO_EZX
		QSettings ss(d->cfg,QSettings::NativeFormat);
		int index=ss.value("Languages/LanguageIndex",0).toInt();
		d->languageCode=ss.value(QString("Languages/Language-%1").arg(index),"en").toString();
		//if(d->languageCode=="sys") d->languageCode=QLocale::system().name();  //"sys" is useful when set the default index

#else
		SETUP_SET_Manager mgr(d->cfg, false);
		int index;
		mgr.getSettingInfo("Languages","LanguageIndex",index,0);
		mgr.getSettingInfo("Languages",QString("Language-%1").arg(index),d->languageCode,"en",true);
                //if(d->languageCode=="sys") d->languageCode=ZLanguage::getSystemlanguageCode();
#endif //NO_EZX
	}
#ifdef QAbstractLangList_QT4
	qDebug()<<"langcode is "+d->languageCode;
#else
	qDebug("langcode is "+d->languageCode);
#endif //QAbstractLangList_QT4
}
예제 #23
0
// check that all the specified maps exist and are loadable
TEST(CampaignTest, testMaps) {
	SCOPED_TRACE("idontcare.temp");
	SQLitePersister persister(System.getDatabaseDirectory() + "idontcare.temp");
	ASSERT_TRUE(persister.init()) << "Failed to initialize the persister";
	LUAMapManager mapMgr;
	mapMgr.loadMaps();
	TextureDefinition t("small");
	SpriteDefinition::get().init(t);
	CampaignManager mgr(&persister, mapMgr);
	mgr.init();

	class Visitor: public ICampaignVisitor {
	public:
		bool atLeastOnce;
		Visitor() :
				atLeastOnce(false) {
		}
		void visitCampaign(CampaignPtr& campaign) {
			const Campaign::MapList& m = campaign->getMaps();
			ASSERT_FALSE(m.empty()) << "failed to get the maps for campaign " << campaign->getId();
			for (Campaign::MapListConstIter i = m.begin(); i != m.end(); ++i) {
				atLeastOnce = true;
				const std::string& id = (*i)->getId();
				CaveExpressMapContext ctx(id);
				EXPECT_TRUE(ctx.load(false)) << "failed to load the map " << id;
				IMap::SettingsMap settings = ctx.getSettings();
				const gridCoord x = string::toFloat(ctx.getStartPositions()[0]._x);
				const gridCoord y = string::toFloat(ctx.getStartPositions()[0]._y);
				EXPECT_TRUE(ctx.isLocationValid(x, y)) << "map " << id << " has invalid player start positions: " << x << ":" << y << " (" << settings[msn::WIDTH] << ":" << settings[msn::HEIGHT] << ")";
				EXPECT_TRUE(ctx.isLocationFree(x, y)) << "map " << id << " has blocked player start positions: " << x << ":" << y;
			}
		}
	};

	Visitor visitor;
	mgr.visitCampaigns(&visitor);
	ASSERT_TRUE(visitor.atLeastOnce) << "failed to get any campaign";
}
예제 #24
0
파일: main.cpp 프로젝트: airobert/DEL
int main(int argc, char **argv)
{   

    int vc = 6;
    XBDDManager mgr(vc);

    BDD *x = new BDD[vc+1];
    for(int i=1; i<=vc; i++){
        x[i] = mgr.BddVar(i);
    }

    BDD r = (!x[4] + !x[6]) * (!x[3] + !x[6]) * (!x[2] + !x[5]);
  
    BDD v  = mgr.BddOne();
    if (r == v) cout<<"equal to one"<<endl;
    else cout<<"not equal to one"<<endl;

    mgr.ShowInfo();
    
    delete []x;
    
    return 0;
}
void BtInstallThread::removeModule()
{
	CSwordModuleInfo* m = CPointers::backend()->findModuleByName(m_module);
	if (m) { //module found?
		QString prefixPath = m->config(CSwordModuleInfo::AbsoluteDataPath) + "/";
		QString dataPath = m->config(CSwordModuleInfo::DataPath);
		if (dataPath.left(2) == "./") {
			dataPath = dataPath.mid(2);
		}

		if (prefixPath.contains(dataPath)) {
			prefixPath.remove( prefixPath.indexOf(dataPath), dataPath.length() );
		}
		else {
			prefixPath = QString::fromLatin1(CPointers::backend()->prefixPath);
		}

		sword::SWMgr mgr(prefixPath.toLatin1());
		//BtInstallMgr iMgr;
		//TODO: use SWModule name, see also removepage
		m_iMgr.removeModule(&mgr, m->name().toLatin1());
	}
}
/*!
  change current index.
  if sytem language exists, then will update the translation of item "System" through changeSysText()
*/
bool QAbstractLangList::changeLangIndex(int index)
{
    bool changed=false;
        if(index!=d->langIndexOld) {
                changed=true;
                d->langIndexOld=index;
                d->languageCode=langCode(d->langIndexOld);

                changeSysText();

                //qDebug("index %d",d->langIndexOld);

                //emit langChanged();

                if(d->ts->load(d->qms[index], d->qmDir)) 
#ifdef QAbstractLangList_QT4
                qDebug()<<"load "+d->qms[index]+" succesful";
#else
			    qDebug("load "+d->qms[index]+" succesful");
#endif			             

//if this is in a dialog and we canceled, don't change the settings
#ifdef NO_EZX
                QSettings settings(d->cfg,QSettings::NativeFormat);
                settings.setValue("Languages/LanguageIndex",index);
#else
                SETUP_SET_Manager mgr(d->cfg, false);
                mgr.setSettingInfo("Languages", "LanguageIndex",index);

#endif //NO_EZX

#ifndef QAbstractLangList_QT4
                //qDebug("TopLevelWidget: %s",topLevelWidget()->name());
#endif //QAbstractLangList_QT4
        }
        return changed;
}
static jint
nativeGetNextSensor(JNIEnv *env, jclass clazz, jobject sensor, jint next)
{
    SensorManager& mgr(SensorManager::getInstance());

    Sensor const* const* sensorList;
    size_t count = mgr.getSensorList(&sensorList);
    if (size_t(next) >= count)
        return -1;

    Sensor const* const list = sensorList[next];
    const SensorOffsets& sensorOffsets(gSensorOffsets);
    jstring name = env->NewStringUTF(list->getName().string());
    jstring vendor = env->NewStringUTF(list->getVendor().string());
    jstring stringType = env->NewStringUTF(list->getStringType().string());
    jstring requiredPermission = env->NewStringUTF(list->getRequiredPermission().string());
    env->SetObjectField(sensor, sensorOffsets.name,      name);
    env->SetObjectField(sensor, sensorOffsets.vendor,    vendor);
    env->SetIntField(sensor, sensorOffsets.version,      list->getVersion());
    env->SetIntField(sensor, sensorOffsets.handle,       list->getHandle());
    env->SetIntField(sensor, sensorOffsets.type,         list->getType());
    env->SetFloatField(sensor, sensorOffsets.range,      list->getMaxValue());
    env->SetFloatField(sensor, sensorOffsets.resolution, list->getResolution());
    env->SetFloatField(sensor, sensorOffsets.power,      list->getPowerUsage());
    env->SetIntField(sensor, sensorOffsets.minDelay,     list->getMinDelay());
    env->SetIntField(sensor, sensorOffsets.fifoReservedEventCount,
                     list->getFifoReservedEventCount());
    env->SetIntField(sensor, sensorOffsets.fifoMaxEventCount,
                     list->getFifoMaxEventCount());
    env->SetObjectField(sensor, sensorOffsets.stringType, stringType);
    env->SetObjectField(sensor, sensorOffsets.requiredPermission,
                        requiredPermission);
    env->SetIntField(sensor, sensorOffsets.maxDelay, list->getMaxDelay());
    env->SetIntField(sensor, sensorOffsets.flags, list->getFlags());
    next++;
    return size_t(next) < count ? next : 0;
}
int run(int argc, char **argv)
{
    if (argc < 4)
    {
        PRINTMSG("Usage: " << argv[0] << " <outputDir> <robotFile> <objectFile>");
        return 0;
    }

    std::string outputDirectory(argv[1]);
    std::string robotFilename(argv[2]);
    std::string objectFilename(argv[3]);

    PRINTMSG("Creating database");
    std::string name = "Database1";
    SHARED_PTR<GraspIt::GraspItSceneManager> graspitMgr(new GraspIt::GraspItSceneManagerHeadless());

    SHARED_PTR<GraspIt::GraspItSimpleDBManager> mgr(new GraspIt::GraspItSimpleDBManager(name, graspitMgr));

    std::string robotName("Robot1");
    std::string objectName("Object1");

    PRINTMSG("Now loading robot");

    int robotID = -1;
    int objectID = -1;

    // here we'd have to put the robot joint names, we'll leave this empty for this test fle
    std::vector<std::string> jointNames;
    if ((robotID = mgr->loadRobotToDatabase(robotFilename, robotName, jointNames)) < 0)
    {
        PRINTERROR("Could not load robot");
        return 0;
    }

    PRINTMSG("Now loading object");

    if ((objectID = mgr->loadObjectToDatabase(objectFilename, objectName, true)) < 0)
    {
        PRINTERROR("Could not load object");
        return 0;
    }

    // Now objects should be in the database only, but not in the world.
    // Re-add them to test if the world still workds afterwards:
    PRINTMSG("Now loading robot to world");
    if (mgr->loadToWorld(robotID, GraspIt::EigenTransform::Identity()) != 0)
    {
        PRINTERROR("Could not add the robot to the graspit world");
        return 0;
    }

    PRINTMSG("Now loading object to world");
    if (mgr->loadToWorld(objectID, GraspIt::EigenTransform::Identity()) != 0)
    {
        PRINTERROR("Could not add the object to the graspit world");
        return 0;
    }

    PRINTMSG("Saving world files");

    // test to see if it worked: save as world
    bool createDir = true;  // if true, the directory will be created, if it doesn't exist.
    graspitMgr->saveGraspItWorld(outputDirectory + "/dbtest/world.xml", createDir);
    graspitMgr->saveInventorWorld(outputDirectory + "/dbtest/world.iv", createDir);

    PRINTMSG("Quitting program.");
    return 0;
}
예제 #29
0
/**
 * Allocate a single object by using the TCP/IP protocol with a local allocation mechanism
 * @param objectname  Name of the object to be allocated
 * @param od          Object description used for allocation
 * @return A string representation of the access-point
 */
std::string socket_allocator_local::allocate(const std::string& objectname, const pop_od& od) {
    std::string codefile;

    char tmpstr[10240];
    std::vector<std::string> argv;
    char* tmp;
    const char* rport = nullptr;
    bool isManual = od.getIsManual();

    std::string hostname = od.getURL();
    const std::string& ruser = od.getUser();
    const std::string& rcore = od.getCore();
    std::string rarch = od.getArch().c_str();
    const std::string& batch = od.getBatch();
    const std::string& cwd = od.getCwd();

    if (hostname.empty()) {
        hostname = pop_system::GetHost().c_str();
    }

    if (!hostname.empty() && (tmp = (char*)strchr(hostname.c_str(), ':')) != nullptr) {
        *tmp = 0;
        rport = tmp + 1;
    }

    // Get the executable path name
    codefile = od.getExecutable();
    // If od.executable is not defined, throw an exception as the parallel object couldn't be allocated
    if (codefile.empty()) {
        assert(!pop_system::appservice.IsEmpty());
        CodeMgr mgr(pop_system::appservice);
        if (rarch.empty()) {
            rarch = pop_system::platform;
        }
        if (!mgr.QueryCode(objectname, rarch, codefile)) {
            pop_exception::pop_throw(OBJECT_NO_RESOURCE, objectname.c_str(), "QueryCode failed");
        }
    }

    std::string myhost = pop_system::GetHost();
    bool isLocal = (isManual || hostname.empty() || pop_utils::SameContact(myhost.c_str(), hostname.c_str()) ||
                    (hostname == "localhost") || (hostname == "127.0.0.1"));
    if (batch.empty()) {
        if (!isLocal) {
            char* tmp = getenv("POPC_RSH");
            argv.push_back(tmp ? tmp : "/usr/bin/ssh");
            if (!ruser.empty()) {
                char tmpstr[100];
                sprintf(tmpstr, "%s@%s", ruser.c_str(), hostname.c_str());
                argv.push_back(tmpstr);
            } else {
                argv.push_back(hostname);
            }
        }
    } else {
        char tmpstr[100];
        tmp = getenv("POPC_LOCATION");
        if (tmp != nullptr) {
            sprintf(tmpstr, "%s/services/popcobjrun.%s", tmp, batch.c_str());
        } else {
            sprintf(tmpstr, "popcobjrun.%s", batch.c_str());
        }
        argv.push_back(tmpstr);
    }
    tmp = getenv("POPC_LOCATION");
    if (tmp != nullptr) {
        sprintf(tmpstr, "%s/services/popcobjrun", tmp);
    } else {
        strcpy(tmpstr, "popcobjrun");
    }
    argv.push_back(tmpstr);

    popc_tokenize_r(argv, codefile, " \t\n");

    /**
     * Create a combox to allocate the new parallel object.
     */

    auto& combox_factory = pop_combox_factory::get_instance();

    pop_combox* tmpsock = combox_factory.Create("socket");
    if (tmpsock == nullptr) {
        pop_exception::pop_throw(POP_NO_PROTOCOL, objectname.c_str(), "Creation of combox failed");
    }

    if (!tmpsock->Create(0, true)) {
        pop_exception::pop_throw("Creation of socket failed");
    }

    pop_connection* connection = tmpsock->get_connection();
    auto cburl = tmpsock->GetUrl();
    sprintf(tmpstr, "-callback=%s", cburl.c_str());
    argv.push_back(tmpstr);

    sprintf(tmpstr, "-object=%s", objectname.c_str());
    argv.push_back(tmpstr);

    if (!pop_system::appservice.IsEmpty()) {
        sprintf(tmpstr, "-appservice=%s", pop_system::appservice.GetAccessString().c_str());
        argv.push_back(tmpstr);
    }

    if (!pop_system::jobservice.IsEmpty()) {
        sprintf(tmpstr, "-jobservice=%s", pop_system::jobservice.GetAccessString().c_str());
        argv.push_back(tmpstr);
    }

    // Select core
    if (!rcore.empty()) {
        sprintf(tmpstr, "-core=%s", rcore.c_str());
        argv.push_back(tmpstr);
    }

    // Select core
    if (rport != nullptr && rport != 0) {
        sprintf(tmpstr, "-socket_port=%s", rport);
        argv.push_back(tmpstr);
    }

#ifdef OD_DISCONNECT
    if (checkConnection) {
        sprintf(tmpstr, "-checkConnection");
        argv.push_back(tmpstr);
    }
#endif

    if (pop_od::defaultLocalJob) {
        argv.push_back("-runlocal");
    }

    // Add the working directory as argument
    if (!cwd.empty()) {
        sprintf(tmpstr, "-cwd=%s", cwd.c_str());
        argv.push_back(tmpstr);
    }

    int ret = 0, err = 0;

    if (isManual) {
        printf("\nTo launch this object, run this command on the target machine :\n");
        for (auto str : argv) {
            printf("%s ", str.c_str());
        }
        printf("\n");
    } else {
#ifndef NDEBUG
        std::stringstream ss;
        ss << "--->";
        for (auto str : argv) {
            ss << str << " ";
        }
        LOG_DEBUG("Launching a new object with command : %s", ss.str().c_str());
#endif
        char** argvc = popc_createArgsFromVect(argv);
        ret = RunCmd(argv.size(), argvc, nullptr);
        popc_freeArgs(argvc);
        err = errno;
    }

    if (ret == -1) {
        LOG_WARNING("Can not start the object: code %d", ret);
        pop_exception::pop_throw(err, objectname.c_str(), "Can not start the object");
    }

    // Now get the return pop_accesspoint....
    tmpsock->SetTimeout(ALLOC_TIMEOUT * 1000);

    pop_buffer* tmpbuffer = tmpsock->GetBufferFactory()->CreateBuffer();

    if (!tmpbuffer->Recv((*tmpsock), connection)) {
        LOG_WARNING("cannot receive anything");
        pop_exception::pop_throw("cannot receive anything");
    }

    pop_buffer::CheckAndThrow(*tmpbuffer);

    int n = 0;
    tmpbuffer->Push("status", "int", 1);
    tmpbuffer->UnPack(&n, 1);
    tmpbuffer->Pop();

    if (n != 0) {
        pop_exception::pop_throw(n, objectname.c_str(), "n is null");
    }

    std::string objectaddress;
    tmpbuffer->Push("objectaddress", "pop_accesspoint", 1);
    tmpbuffer->UnPack(&objectaddress, 1);
    tmpbuffer->Pop();
    delete tmpbuffer;

    tmpsock->Close();

    return objectaddress;
}
예제 #30
0
        void testGTIDManager() {
            GTID lastGTID(1,1);
            GTIDManager mgr(lastGTID, 0, 0, 0, 0);
            
            // make sure initialization is what we expect
            ASSERT(GTID::cmp(mgr._lastLiveGTID, lastGTID) == 0);
            ASSERT(GTID::cmp(mgr._minLiveGTID, lastGTID) > 0);
            lastGTID.inc();
            ASSERT(GTID::cmp(mgr._minLiveGTID, lastGTID) == 0);
            mgr.catchUnappliedToLive();
            ASSERT(GTID::cmp(mgr._lastLiveGTID, mgr._lastUnappliedGTID) == 0);
            ASSERT(GTID::cmp(mgr._minLiveGTID, mgr._minUnappliedGTID) == 0);
            GTID resetGTID(2,2);
            mgr.resetAfterInitialSync(resetGTID, 1, 1);
            mgr.verifyReadyToBecomePrimary();
            ASSERT(GTID::cmp(mgr._lastLiveGTID, resetGTID) == 0);
            ASSERT(GTID::cmp(mgr._lastLiveGTID, mgr._lastUnappliedGTID) == 0);
            ASSERT(GTID::cmp(mgr._minLiveGTID, mgr._minUnappliedGTID) == 0);
            resetGTID.inc();
            ASSERT(GTID::cmp(mgr._minLiveGTID, resetGTID) == 0);

            // now test that it works as primary
            GTID currLast = mgr.getLiveState();
            GTID currMin = mgr._minLiveGTID;
            ASSERT(GTID::cmp(currLast, mgr._lastLiveGTID) == 0);

            uint64_t ts;
            uint64_t hash;
            GTID gtid;
            mgr.getGTIDForPrimary(&gtid, &ts, &hash);
            cerr << gtid.toString() << endl;
            cerr << currMin.toString() <<endl;
            ASSERT(GTID::cmp(gtid, currMin) == 0);
            ASSERT(GTID::cmp(gtid, mgr._minLiveGTID) == 0);
            ASSERT(GTID::cmp(gtid, mgr._lastLiveGTID) == 0);
            mgr.noteLiveGTIDDone(gtid);
            ASSERT(GTID::cmp(gtid, mgr._lastLiveGTID) == 0);
            ASSERT(GTID::cmp(gtid, mgr._minLiveGTID) < 0);

            // simple test of resetManager
            currLast = mgr._lastLiveGTID;
            currMin = mgr._minLiveGTID;
            uint64_t currHkp = mgr.getHighestKnownPrimary();
            // just a sanity check, that hkp is 2
            ASSERT(currHkp == 2);
            ASSERT(mgr._newPrimaryValue == 0);
            ASSERT(!mgr.resetManager(1));
            ASSERT(!mgr.resetManager(2));
            ASSERT(mgr.resetManager(4));
            mgr.verifyReadyToBecomePrimary();
            // make sure that lastLive and minLive not changed yet
            ASSERT(GTID::cmp(currMin, mgr._minLiveGTID) == 0);
            ASSERT(GTID::cmp(currLast, mgr._lastLiveGTID) == 0);
            // now make sure that primary has increased
            ASSERT(mgr._newPrimaryValue == 4);
            mgr.getGTIDForPrimary(&gtid, &ts, &hash);
            ASSERT(mgr._newPrimaryValue == 0);

            ASSERT(gtid._primarySeqNo > currLast._primarySeqNo);
            ASSERT(gtid._primarySeqNo == 4);
            ASSERT(gtid._GTSeqNo == 0);

            mgr.noteLiveGTIDDone(gtid);
            mgr.verifyReadyToBecomePrimary();

            // now test that min is properly maintained
            currLast = mgr._lastLiveGTID;
            currMin = mgr._minLiveGTID;
            GTID gtid1, gtid2, gtid3, gtid4, gtid5;
            mgr.getGTIDForPrimary(&gtid1, &ts, &hash);
            mgr.getGTIDForPrimary(&gtid2, &ts, &hash);
            mgr.getGTIDForPrimary(&gtid3, &ts, &hash);
            mgr.getGTIDForPrimary(&gtid4, &ts, &hash);
            ASSERT(GTID::cmp(gtid1, gtid2) < 0);
            ASSERT(GTID::cmp(gtid2, gtid3) < 0);
            ASSERT(GTID::cmp(gtid3, gtid4) < 0);
            ASSERT(GTID::cmp(mgr._lastLiveGTID, gtid4) == 0);
            ASSERT(GTID::cmp(mgr._minLiveGTID, gtid1) == 0);
            // finish 2, nothing should change
            mgr.noteLiveGTIDDone(gtid2);
            ASSERT(GTID::cmp(mgr._lastLiveGTID, gtid4) == 0);
            ASSERT(GTID::cmp(mgr._minLiveGTID, gtid1) == 0);
            // finish 1, min should jump to 3
            mgr.noteLiveGTIDDone(gtid1);
            ASSERT(GTID::cmp(mgr._lastLiveGTID, gtid4) == 0);
            ASSERT(GTID::cmp(mgr._minLiveGTID, gtid3) == 0);
            // get 5, _lastLive should change
            mgr.getGTIDForPrimary(&gtid5, &ts, &hash);
            ASSERT(GTID::cmp(gtid4, gtid5) < 0);
            ASSERT(GTID::cmp(mgr._lastLiveGTID, gtid5) == 0);
            ASSERT(GTID::cmp(mgr._minLiveGTID, gtid3) == 0);
            
            // finish 3 and 4, should both jump to 5
            mgr.noteLiveGTIDDone(gtid3);
            mgr.noteLiveGTIDDone(gtid4);
            ASSERT(GTID::cmp(mgr._lastLiveGTID, gtid5) == 0);
            ASSERT(GTID::cmp(mgr._minLiveGTID, gtid5) == 0);
            // finish 5, min should jump up
            mgr.noteLiveGTIDDone(gtid5);
            ASSERT(GTID::cmp(mgr._lastLiveGTID, gtid5) == 0);
            ASSERT(GTID::cmp(mgr._minLiveGTID, gtid5) > 0);
            mgr.verifyReadyToBecomePrimary();

            GTID currLastUnapplied = mgr._lastUnappliedGTID;
            GTID currMinUnapplied = mgr._minUnappliedGTID;
            
            gtid5.inc();
            gtid5.inc();
            gtid5.inc();
            GTID gtidOther = gtid5;
            gtidOther.inc();

            GTID gtidUnapplied1 = gtid5;
            // now let's do a test for secondaries
            mgr.noteGTIDAdded(gtidUnapplied1, ts, hash);
            ASSERT(GTID::cmp(mgr._lastLiveGTID, gtidUnapplied1) == 0);
            ASSERT(GTID::cmp(mgr._minLiveGTID, gtidOther) == 0);
            gtid5.inc();
            gtidOther.inc();
            GTID gtidUnapplied2 = gtid5;
            mgr.noteGTIDAdded(gtidUnapplied2, ts, hash);
            ASSERT(GTID::cmp(mgr._lastLiveGTID, gtidUnapplied2) == 0);
            ASSERT(GTID::cmp(mgr._minLiveGTID, gtidOther) == 0);
            // verify unapplied values not changed
            ASSERT(GTID::cmp(mgr._lastUnappliedGTID, currLastUnapplied) == 0);
            ASSERT(GTID::cmp(mgr._minUnappliedGTID, currMinUnapplied) == 0);
            gtid5.inc();
            GTID gtidUnapplied3 = gtid5;
            mgr.noteGTIDAdded(gtidUnapplied3, ts, hash);
            gtid5.inc();
            GTID gtidUnapplied4 = gtid5;
            mgr.noteGTIDAdded(gtidUnapplied4, ts, hash);
            // at this point, we have 4 GTIDs that have been added, but
            // yet to be applied
            mgr.noteApplyingGTID(gtidUnapplied1);
            mgr.noteApplyingGTID(gtidUnapplied2);
            ASSERT(GTID::cmp(mgr._lastUnappliedGTID, gtidUnapplied2) == 0);
            ASSERT(GTID::cmp(mgr._minUnappliedGTID, gtidUnapplied1) == 0);
            mgr.noteGTIDApplied(gtidUnapplied2);
            ASSERT(GTID::cmp(mgr._minUnappliedGTID, gtidUnapplied1) == 0);
            mgr.noteApplyingGTID(gtidUnapplied3);
            mgr.noteApplyingGTID(gtidUnapplied4);
            ASSERT(GTID::cmp(mgr._lastUnappliedGTID, gtidUnapplied4) == 0);
            ASSERT(GTID::cmp(mgr._minUnappliedGTID, gtidUnapplied1) == 0);
            mgr.noteGTIDApplied(gtidUnapplied3);
            mgr.noteGTIDApplied(gtidUnapplied1);
            ASSERT(GTID::cmp(mgr._minUnappliedGTID, gtidUnapplied4) == 0);
            mgr.noteGTIDApplied(gtidUnapplied4);
            ASSERT(GTID::cmp(mgr._lastUnappliedGTID, gtidUnapplied4) == 0);
            ASSERT(GTID::cmp(mgr._minUnappliedGTID, gtidUnapplied4) > 0);
        }