Example #1
0
void walletmanager::walletIsOpen( bool walletOpened )
{
	if( walletOpened ){
		Task * t ;
		switch( m_action ){
		case walletmanager::showAccountInfo :

			this->buildGUI() ;
			this->disableAll() ;
			this->show() ;

			t = new Task( m_wallet,&m_accounts ) ;
			connect( t,SIGNAL( taskFinished( int ) ),this,SLOT( taskComplete( int ) ) ) ;
			t->start( Task::showAccountInfo ) ;

			break ;
		case walletmanager::getAccountInfo :

			t = new Task( m_wallet,&m_accounts ) ;
			connect( t,SIGNAL( taskFinished( int ) ),this,SLOT( taskComplete( int ) ) ) ;
			t->start( Task::getAccountInfo ) ;

			break ;
		default:
			/*
			 * we dont get here
			 */
			this->deleteLater() ;
		}
	}else{
		this->deleteLater() ;
Example #2
0
void keyDialog::slotMountComplete( int st,QString m )
{
	m_working = false ;
	if( st == 0 ){
		if( utility::mapperPathExists( m_path ) ) {
			/*
			 * The volume is reported as opened and it actually is
			 */
			if( m_autoOpenFolderOnMount ){
				Task * t = new Task() ;
				t->setMountPoint( utility::mountPath( m_point ) ) ;
				t->setMountPointOpener( m_folderOpener ) ;
				connect( t,SIGNAL( errorStatus( int,int,int ) ),this,SLOT( fileManagerOpenStatus( int,int,int ) ) ) ;
				t->start( Task::openMountPoint ) ;
			}
		}else{
			/*
			 * The volume is reported as opened but it isnt,possible reason is a backe end crash
			 */

			DialogMsg m( this ) ;

			m.ShowUIOK( tr( "ERROR" ),tr( "An error has occured and the volume could not be opened" ) ) ;
			emit cancel() ;
		}
		this->HideUI() ;
	}else{
Example #3
0
void tst_QThreadPool::stressTest()
{
    class Task : public QRunnable
    {
        QSemaphore semaphore;
    public:
        Task() { setAutoDelete(false); }

        void start()
        {
            QThreadPool::globalInstance()->start(this);
        }

        void wait()
        {
            semaphore.acquire();
        }

        void run()
        {
            semaphore.release();
        }
    };

    QTime total;
    total.start();
    while (total.elapsed() < 30000) {
        Task t;
        t.start();
        t.wait();
    }
}
Example #4
0
void MainWindow::slotOpenSharedFolder()
{
	Task * t = new Task() ;
	t->setMountPoint( m_sharedFolderPath ) ;
	t->setMountPointOpener( m_folderOpener ) ;
	connect( t,SIGNAL( errorStatus( int,int,int ) ),this,SLOT( fileManagerOpenStatus( int,int,int ) ) ) ;
	t->start( Task::openMountPoint ) ;
}
Example #5
0
void MainWindow::openVolumeFromArgumentList()
{
	if( !m_device.isEmpty() ){
		Task * t = new Task() ;
		connect( t,SIGNAL( getVolumeInfo( QStringList ) ),this,SLOT( showMoungDialog( QStringList ) ) ) ;
		t->setDevice( m_device ) ;
		t->start( Task::VolumeType ) ;
	}
}
Example #6
0
void MainWindow::volumeProperties()
{
	this->disableAll() ;

	Task * t = new Task() ;
	t->setDevice( m_ui->tableWidget->item( m_ui->tableWidget->currentRow(),0 )->text() ) ;
	connect( t,SIGNAL( signalProperties( QString ) ),this,SLOT( volumeProperties( QString ) ) ) ;

	t->start( Task::VolumeProperties ) ;
}
Example #7
0
void MainWindow::slotOpenFolder()
{
	QTableWidgetItem * item = m_ui->tableWidget->currentItem() ;
	QString path = m_ui->tableWidget->item( item->row(),1 )->text() ;

	Task * t = new Task() ;
	t->setMountPoint( path ) ;
	t->setMountPointOpener( m_folderOpener ) ;
	connect( t,SIGNAL( errorStatus( int,int,int ) ),this,SLOT( fileManagerOpenStatus( int,int,int ) ) ) ;
	t->start( Task::openMountPoint ) ;
}
Example #8
0
void MainWindow::deviceRemoved( QString dev )
{
	int row = tablewidget::columnHasEntry( m_ui->tableWidget,0,dev ) ;
	if( row != -1 ){
		tablewidget::deleteRowFromTable( m_ui->tableWidget,row ) ;
		/*
		* see if a user just removed the device without properly closing it/unmounting it
		* and try to do so for them
		*/
		Task * t = new Task() ;
		t->setDevice( dev ) ;
		t->start( Task::checkUnMount ) ;
	}
}
Example #9
0
void MainWindow::pbUpdate()
{
	this->disableAll() ;

	while( m_ui->tableWidget->rowCount() ){
		m_ui->tableWidget->removeRow( 0 ) ;
	}

	m_ui->tableWidget->setEnabled( false ) ;

	Task * t = new Task() ;
	connect( t,SIGNAL( signalMountedList( QStringList,QStringList ) ),this,SLOT( slotMountedList( QStringList,QStringList ) ) ) ;
	t->start( Task::Update ) ;
}
Example #10
0
void MainWindow::pbMount()
{
	this->disableAll() ;

	QString path = QFileDialog::getOpenFileName( this,tr( "select an image file to mount" ),QDir::homePath() ) ;
	if( path.isEmpty() ){
		this->enableAll() ;
	}else{
		m_device = path ;
		Task * t = new Task() ;
		connect( t,SIGNAL( getVolumeInfo( QStringList ) ),this,SLOT( showMoungDialog( QStringList ) ) ) ;
		t->setDevice( m_device ) ;
		t->start( Task::VolumeType ) ;
	}
}
Example #11
0
void MainWindow::dropEvent( QDropEvent * e )
{
	const QMimeData * m = e->mimeData() ;
	QList<QUrl> l = m->urls() ;
	int j = l.size() ;

	for( int i = 0 ; i < j ; i++ ){
		m_device = l.at( i ).path() ;
		if( utility::pathPointsToAFile( m_device ) ){
			Task * t = new Task() ;
			connect( t,SIGNAL( getVolumeInfo( QStringList ) ),
				 this,SLOT( showMoungDialog( QStringList ) ) ) ;
			t->setDevice( m_device ) ;
			t->start( Task::VolumeType ) ;
		}
	}
}
Example #12
0
void MainWindow::pbUmount()
{
	this->disableAll() ;

	int row = m_ui->tableWidget->currentRow() ;

	QString path = m_ui->tableWidget->item( row,0 )->text() ;
	QString type = m_ui->tableWidget->item( row,2 )->text() ;

	Task * t = new Task() ;

	t->setDevice( path ) ;
	t->setType( type ) ;

	connect( t,SIGNAL( signalUnmountComplete( int,QString) ),this,SLOT( slotUnmountComplete( int,QString ) ) ) ;

	t->start( Task::Unmount ) ;
}
Example #13
0
bool Scheduler::is_started(const uint_fast8_t i) {
  Task *pCurTask = m_functionList[i];
  uint_fast32_t time = m_pHAL->scheduler->millis() - pCurTask->get_timer();

  // Time yet to start the current emitter?
  if(time <= m_tickrateList[i] + pCurTask->get_delay() ) {
    return false;
  } else {
    // Release the block for the transmitter
    pCurTask->reset();
  }

  if(pCurTask->start() ) {
    // Set timer to the current time
    pCurTask->set_timer(m_pHAL->scheduler->millis() );
  } else {
    return false;
  }

  return true;
}
Example #14
0
void monitor_mountinfo::run()
{
	m_mtoto = this ;

	connect( m_mtoto,SIGNAL( terminated() ),m_main,SLOT( threadStopped() ) ) ;
	connect( m_mtoto,SIGNAL( terminated() ),m_mtoto,SLOT( deleteLater() ) ) ;

	Task::FileHandle manage_fd ;

	int fd = manage_fd( open( "/proc/self/mountinfo",O_RDONLY ) ) ;

	if( fd == -1 ){
		return ;
	}else{
		m_running = true ;
	}

	struct pollfd monitor ;

	monitor.fd     = fd ;
	monitor.events = POLLPRI ;

	auto _loop = [&](){
		poll( &monitor,1,-1 ) ;
		return 1 ;
	} ;

	auto _unmountProperty = [&]( const QString& volume ){
		Task * t = new Task() ;
		t->setDevice( volume ) ;
		connect( t,SIGNAL( volumeMiniProperties( volumeEntryProperties * ) ),
			 m_babu,SLOT( volumeMiniProperties( volumeEntryProperties * ) ) ) ;
		connect( t,SIGNAL( volumeRemoved( QString ) ),
			 m_babu,SLOT( volumeRemoved( QString ) ) ) ;
		t->start( Task::VolumeMiniProperties ) ;
	} ;

	auto _mountProperty = [&]( const QString& volume ){
		Task * t = new Task() ;
		t->setDevice( volume ) ;
		connect( t,SIGNAL( volumeMiniProperties( volumeEntryProperties * ) ),
			 m_babu,SLOT( volumeMiniProperties( volumeEntryProperties * ) ) ) ;
		t->start( Task::VolumeMiniProperties ) ;
	} ;

	QStringList oldMountList = Task::updateVolumeList() ;
	QStringList newMountList ;

	auto _volumeWasUnMounted = [&](){
		return oldMountList.size() > newMountList.size() ;
	} ;

	auto _volumeWasMounted = [&](){
		return oldMountList.size() < newMountList.size() ;
	} ;

	auto _unmountedVolume = [&]( const QString& e ){
		return !newMountList.contains( e ) ;
	} ;

	auto _mountedVolume = [&]( const QString& e ){
		return !oldMountList.contains( e ) ;
	} ;

	while( _loop() ){

		newMountList = Task::updateVolumeList() ;

		if( _volumeWasUnMounted() ){

			for( const auto& it : oldMountList ){
				if( _unmountedVolume( it ) ){
					_unmountProperty( it ) ;
				}
			}
		}else if( _volumeWasMounted() ){

			for( const auto& it : newMountList ){
				if( _mountedVolume( it ) ){
					_mountProperty( it ) ;
				}
			}
		}else{
			/*
			 * mount/unmount just happened but volume count remain the same,
			 * possible reason is because of a bind mount
			 */
		}

		oldMountList = newMountList ;
	}
}
Example #15
0
void Task::task( QObject * object,function_t f,const char * slotName )
{
	Task * t = new Task( object,slotName ) ;
	t->start( Task::runTask,f ) ;
}
Example #16
0
/*!
 * Main body - creates two threads - one for window and and one
 * for images acquisition/processing.
 */
int main(int argc, char* argv[])
{
	// DisCODe config filename.
	std::string config_name;

	// Task config filename.
	std::string task_name;

	// Task settings overrides
	std::vector <std::string> task_overrides;

	// Log level
	int log_lvl = 2;

	void (*prev_fn)(int);

	prev_fn = signal (SIGINT, terminate);
	if (prev_fn==SIG_IGN) signal (SIGINT,SIG_IGN);

	// =========================================================================
	// === Program command-line options
	// =========================================================================

	// Declare the supported options.
	po::options_description desc("Allowed options");
	desc.add_options()
		("help", "produce help message")
		("config,C", po::value<std::string>(&config_name)->default_value("config.xml"), "choose config file")
		("create-config,D", "create default configuration file")
		("task,T", po::value<std::string>(&task_name), "choose task file")
		("create-task", "create default task file")
		("log-level,L", po::value<int>(&log_lvl)->default_value(3), "set log severity level")
		("unstoppable","MWAHAHAHA!")
		("set,S",po::value< vector<string> >(&task_overrides),"override task settings")
		("interactive,I", "interactive mode")
	;

	po::variables_map vm;

	try {
		po::store(po::parse_command_line(argc, argv, desc), vm);
		po::notify(vm);
	}
	catch (const po::error & u) {
		std::cout << u.what() << "\n";
		return 0;
	}

	if (vm.count("help")) {
		std::cout << desc << "\n";
		return 0;
	}

	// set logger severity level
	LOGGER.setLevel((Utils::Logger::Severity)log_lvl);
	LOGGER.addOutput(new Utils::Logger::ConsoleOutput, (Utils::Logger::Severity)log_lvl);

	if (vm.count("create-task")) {
		cout << "Creating task file " << task_name << "\n";

		std::ofstream cfg(task_name.c_str());

		cfg << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
				"<Task>\n"
				"\t<!-- List of components -->\n"
				"\t<Components>\n"
				"\t</Components>\n"
				"\n"
				"\t<!-- Threads of execution -->\n"
				"\t<Executors>\n"
				"\t\t<Thread1 type=\"passive\">\n"
				"\t\t</Thread1>\n"
				"\t</Executors>\n"
				"\n"
				"\t<!-- Event connections -->\n"
				"\t<Events>\n"
				"\t</Events>\n"
				"\n"
				"\t<!-- Data stream assignments -->\n"
				"\t<DataStreams>\n"
				"\t</DataStreams>\n"
				"</Task>\n";

		cfg.close();

		return 0;
	}

	if (vm.count("create-config")) {
		cout << "Creating configuration file " << config_name << "\n";

		std::ofstream cfg(config_name.c_str());

		cfg << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
				"<DisCODe>\n"
				"\t<task>blob.xml</task>"
				"</DisCODe>\n";

		cfg.close();

		return 0;
	}

	if (vm.count("unstoppable")) {
		unstoppable = true;
	}

	// =========================================================================
	// === DisCODe configuration
	// =========================================================================

	config_name = vm["config"].as<std::string>();

	pt::ptree conf;
	try {
		read_xml(config_name, conf);
	}
	catch(xml_parser_error&) {
		LOG(LWARNING) << "Configuration file " << config_name + " not found.";
		LOG(LNOTICE) << "Quick fixes:";
		LOG(LNOTICE) << "   specify config file name with -C switch";
		LOG(LNOTICE) << "   create default configuration using -D switch";
	}

	if (!vm.count("task")) {
		if (!conf.get_optional<std::string>("DisCODe.task")) {
			LOG(LERROR) << "No task specified!";
			LOG(LNOTICE) << "Quick fixes:";
			LOG(LNOTICE) << "   specify task name using -T switch";
			LOG(LNOTICE) << "   set default task name in config file";
			LOG(LNOTICE) << "   run DisCODe in interactive mode (-I)";
			exit(EXIT_FAILURE);
		} else {
			task_name = conf.get<std::string>("DisCODe.task");
			LOG(LINFO) << "Task: " << task_name << " from configuration file\n";
		}
	} else {
		LOG(LINFO) << "Task: " << task_name << " from command line\n";
	}

	std::vector<std::pair<std::string, std::string> > overrides;
	for (size_t i = 0; i < task_overrides.size(); ++i) {
		std::vector<std::string> strs;
		boost::split(strs, task_overrides[i], boost::is_any_of("="));
		if (strs.size() == 1) {
			LOG(LWARNING) << strs[0] << "have no assigned value";
		} else {
			overrides.push_back(std::make_pair(strs[0], strs[1]));
		}
	}

	// =========================================================================
	// === Main program part
	// =========================================================================

	Configurator configurator;
	ComponentManager km;
	ExecutorManager em;
	ConnectionManager cm;

	Task task;

	configurator.setExecutorManager(&em);
	configurator.setComponentManager(&km);
	configurator.setConnectionManager(&cm);

	TaskInformer task_informer(task);
	ComponentInformer component_informer(km);
	SystemInformer system_informer(running);
	ExecutorInformer executor_informer(em);

	try {
		CommandServer server;

		server.addInformer(&task_informer);
		server.addInformer(&component_informer);
		server.addInformer(&system_informer);
		server.addInformer(&executor_informer);
		server.printCommands();

		server.start();

		km.initializeComponentsList();

		task = configurator.loadConfiguration(task_name, overrides);
		if (!task.start()) {
			LOG(LFATAL) << "Task::start() returned false\n";
			running = false;
		}


		while(running) {
			Common::Thread::msleep(50);
		}

		Common::Thread::msleep(500);

		task.finish();

		km.release();
		cm.release();
		em.release();

		km.deactivateComponentList();

		server.stop();
	}//: try

	// =========================================================================
	// === Exception handling
	// =========================================================================

	catch (Common::DisCODeException& ex) {
		LOG(LFATAL) << ex.what() << "\n";
		ex.printStackTrace();
		exit(EXIT_FAILURE);
	}
	catch (exception& ex) {
		LOG(LFATAL) << ex.what() << "\n";
		exit(EXIT_FAILURE);
	}
	catch (const char * ex) {
		LOG(LFATAL) << ex << "\n";
		exit(EXIT_FAILURE);
	}
	catch (...) {
		LOG(LFATAL) << "Unknown exception.\n";
		exit(EXIT_FAILURE);
	}//: catch
}
Example #17
0
void MainWindow::setUpApp()
{
	this->setLocalizationLanguage() ;
	m_ui = new Ui::MainWindow ;
	m_ui->setupUi( this ) ;

	this->setFixedSize( this->size() ) ;

	m_ui->tableWidget->setColumnWidth( 0,225 ) ;
	m_ui->tableWidget->setColumnWidth( 1,320 ) ;
	m_ui->tableWidget->setColumnWidth( 2,105 ) ;
	m_ui->tableWidget->hideColumn( 3 ) ;
	m_ui->tableWidget->setColumnWidth( 4,87 ) ;
	m_ui->tableWidget->setColumnWidth( 5,87 ) ;

#if QT_VERSION < QT_VERSION_CHECK( 5,0,0 )
	m_ui->tableWidget->verticalHeader()->setResizeMode( QHeaderView::ResizeToContents ) ;
#else
	m_ui->tableWidget->verticalHeader()->setSectionResizeMode( QHeaderView::ResizeToContents ) ;
#endif
	m_ui->tableWidget->verticalHeader()->setMinimumSectionSize( 30 ) ;

	this->setAcceptDrops( true ) ;
	this->setWindowIcon( QIcon( QString( ":/zuluMount.png" ) ) ) ;

	m_ui->tableWidget->setMouseTracking( true ) ;

	connect( m_ui->tableWidget,SIGNAL( itemEntered( QTableWidgetItem * ) ),this,SLOT( itemEntered( QTableWidgetItem * ) ) ) ;
	connect( m_ui->tableWidget,SIGNAL( currentItemChanged( QTableWidgetItem *,QTableWidgetItem * ) ),
		 this,SLOT( slotCurrentItemChanged( QTableWidgetItem *,QTableWidgetItem * ) ) ) ;
	connect( m_ui->pbmount,SIGNAL( clicked() ),this,SLOT( pbMount() ) ) ;
	connect( m_ui->pbupdate,SIGNAL( clicked()),this,SLOT(pbUpdate() ) ) ;
	connect( m_ui->pbclose,SIGNAL( clicked() ),this,SLOT( pbClose() ) ) ;
	connect( m_ui->tableWidget,SIGNAL( itemClicked( QTableWidgetItem * ) ),this,SLOT( itemClicked( QTableWidgetItem * ) ) ) ;

	this->setUpShortCuts() ;

	this->setUpFont() ;

	m_trayIcon = new QSystemTrayIcon( this ) ;
	m_trayIcon->setIcon( QIcon( QString( ":/zuluMount.png" ) ) ) ;

	QMenu * trayMenu = new QMenu( this ) ;

	m_autoMountAction = new QAction( this ) ;
	m_autoMount = this->autoMount() ;
	m_autoMountAction->setCheckable( true ) ;
	m_autoMountAction->setChecked( m_autoMount ) ;

	m_autoMountAction->setText( tr( "automount volumes" ) ) ;

	connect( m_autoMountAction,SIGNAL( toggled( bool ) ),this,SLOT( autoMountToggled( bool ) ) ) ;

	trayMenu->addAction( m_autoMountAction ) ;

	QAction * autoOpenFolderOnMount = new QAction( this ) ;
	autoOpenFolderOnMount->setCheckable( true ) ;
	m_autoOpenFolderOnMount = this->autoOpenFolderOnMount() ;
	autoOpenFolderOnMount->setChecked( m_autoOpenFolderOnMount ) ;
	autoOpenFolderOnMount->setText( tr( "auto open mount point" ) ) ;
	connect( autoOpenFolderOnMount,SIGNAL( toggled( bool ) ),this,SLOT( autoOpenFolderOnMount( bool ) ) ) ;

	trayMenu->addAction( autoOpenFolderOnMount ) ;

	trayMenu->addAction( tr( "quit" ),this,SLOT( pbClose() ) ) ;
	m_trayIcon->setContextMenu( trayMenu ) ;

	connect( m_trayIcon,SIGNAL( activated( QSystemTrayIcon::ActivationReason ) ),
		 this,SLOT( slotTrayClicked( QSystemTrayIcon::ActivationReason ) ) ) ;

	m_trayIcon->show() ;

	QString dirPath = QDir::homePath() + QString( "/.zuluCrypt/" ) ;
	QDir dir( dirPath ) ;

	if( !dir.exists() ){
		dir.mkdir( dirPath ) ;
	}

	Task * t = new Task() ;

	this->disableAll() ;

	connect( t,SIGNAL( signalMountedList( QStringList,QStringList ) ),
		 this,SLOT( slotMountedList( QStringList,QStringList ) ) ) ;
	connect( t,SIGNAL( done() ),this,SLOT( openVolumeFromArgumentList() ) ) ;
	connect( t,SIGNAL( done() ),this,SLOT( started() ) ) ;

	t->start( Task::Update ) ;

	this->startAutoMonitor() ;
}