void ViewItems::paintEvent( QPaintEvent * event ) { AFINFO("ViewItems::paintEvent:"); if( m_back_filename != afqt::QEnvironment::image_back.str ) loadImage(); if( m_back_pixmap.isNull() || verticalScrollBar()->isVisible()) { QListView::paintEvent( event ); return; } QPainter p( viewport()); QRect r = viewport()->rect(); int x = r.width(); int y = r.height(); int w = m_back_pixmap.width(); int h = m_back_pixmap.height(); x -= w + m_back_offset_x; y -= h + m_back_offset_y; p.drawPixmap( x, y, w, h, m_back_pixmap); QListView::paintEvent( event ); }
ListItems::ListItems( QWidget* parent, const std::string & type): QWidget( parent), m_type( type), m_parentWindow( parent) { AFINFO("ListItems::ListItems.\n"); setAttribute ( Qt::WA_DeleteOnClose, true ); m_hlayout = new QHBoxLayout( this); m_vlayout = new QVBoxLayout(); m_panel_l = new QVBoxLayout(); m_panel_r = new QVBoxLayout(); m_hlayout->addLayout( m_panel_l); m_hlayout->addLayout( m_vlayout); m_hlayout->addLayout( m_panel_r); m_panel_l->setAlignment( Qt::AlignTop); m_panel_l->setContentsMargins( 5, 5, 5, 5); m_panel_l->setSpacing( 5); m_panel_r->setAlignment( Qt::AlignTop); m_panel_r->setContentsMargins( 5, 5, 5, 5); m_panel_r->setSpacing( 5); //m_panel_r->setFiltedWidth(400); //m_panel_r->addWidget(new QLabel("right")); m_hlayout->setSpacing( 0); m_vlayout->setSpacing( 0); m_hlayout->setContentsMargins( 0, 0, 0, 0); m_vlayout->setContentsMargins( 0, 0, 0, 0); m_infoline = new InfoLine( this); // if( m_parentWindow != (QWidget*)(Watch::getDialog())) setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus); }
Dialog::~Dialog() { AFINFO("Dialog::~Dialog:") Watch::destroy(); if( m_connected ) m_qThreadSend.send( new af::Msg( af::Msg::TMonitorDeregister, MonitorHost::id())); }
bool afqt::connectAfanasy( QTcpSocket * qSocket) { if( qSocket->state() != QAbstractSocket::ConnectedState) { #ifdef AFOUTPUT printf("afqt::connectAfanasy: %s : %d\n", afqt::QEnvironment::getAfServerQHostAddress().toString().toUtf8().data(), af::Environment::getServerPort()); #endif qSocket->connectToHost( afqt::QEnvironment::getAfServerQHostAddress(), af::Environment::getServerPort()); if( qSocket->waitForConnected( WAITFORCONNECTED) == false) { AFINFO("qtnet::connectAfanasy: can't connect to server.\n"); return false; } } else { AFINFO("qtcom::connectAfanasy: QTcpSocket seems to be already connected.\n"); } return true; }
ListItems::ListItems( QWidget* parent, int RequestMsgType): QWidget( parent), parentWindow( parent), requestmsgtype( RequestMsgType), subscribed( false), subscribeFirstTime( true) { AFINFO("ListItems::ListItems.\n"); setAttribute ( Qt::WA_DeleteOnClose, true ); layout = new QVBoxLayout( this); layout->setSpacing( 0); #if QT_VERSION >= 0x040300 layout->setContentsMargins( 0, 0, 0, 0); #endif infoline = new InfoLine( this); if( parentWindow != (QWidget*)(Watch::getDialog())) setFocusPolicy(Qt::StrongFocus); }
void MonitorHost::setUid( int i_uid) { AFINFO("MonitorHost::setUid:"); // If it is first time, we store it; if( ms_uid < 0 ) ms_uid = i_uid; // Negative value means restore original: if( i_uid < 0 ) i_uid = m_->m_uid; std::vector<int> ids; ids.push_back( m_->getId()); std::ostringstream str; af::jsonActionOperationStart( str,"monitors","watch","", ids); str << ",\"class\":\"perm\""; str << ",\"uid\":" << i_uid; af::jsonActionOperationFinish( str); Watch::sendMsg( af::jsonMsg( str)); }
ListItems::~ListItems() { AFINFO("ListItems::~ListItems.\n"); Watch::unsubscribe( eventsOnOff); }
ListItems::~ListItems() { AFINFO("ListItems::~ListItems.\n"); }
this, SLOT( renderAdded( ItemNode *, const QModelIndex &))); if( false == af::Environment::VISOR()) connect( m_view->selectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &)), this, SLOT( selectionChanged( const QItemSelection &, const QItemSelection &))); setSpacing(); QTimer * timer = new QTimer(this); timer->start( 1900 * af::Environment::getWatchRefreshGuiSec()); connect( timer, SIGNAL( timeout()), this, SLOT( repaintItems())); } ListRenders::~ListRenders() { AFINFO("ListRenders::~ListRenders.") } void ListRenders::setSpacing() { switch( ms_displaysize ) { case ListRenders::ESMallSize: m_view->setSpacing( 1); break; case ListRenders::ENormalSize: m_view->setSpacing( 2); break; default: m_view->setSpacing( 3); }
//######################################## main ######################################### int main(int argc, char *argv[]) { // Initialize environment: af::Environment ENV( af::Environment::Server, argc, argv); ENV.addUsage("-demo", "Disable tasks changing and new jobs."); // Initialize general library: if( af::init( af::InitFarm) == false) return 1; // Initialize store: afsql::init(); // Environment aready printed usage and we can exit. if( ENV.isHelpMode()) return 0; // create directories if it is not exists if( af::pathMakePath( ENV.getTempDir(), af::VerboseOn ) == false) return 1; if( af::pathMakeDir( ENV.getJobsDir(), af::VerboseOn ) == false) return 1; if( af::pathMakeDir( ENV.getUsersDir(), af::VerboseOn ) == false) return 1; if( af::pathMakeDir( ENV.getRendersDir(), af::VerboseOn ) == false) return 1; // Server for windows can be me more simple and not use signals at all. // Windows is not a server platform, so it designed for individual tests or very small companies with easy load. #ifndef _WIN32 // Interrupt signals catch. // We need to catch interrupt signals to let threads to finish running function themselves. // This needed mostly fot queues to let them to finish to process last item. struct sigaction actint; bzero( &actint, sizeof(actint)); actint.sa_handler = sig_int; sigaction( SIGINT, &actint, NULL); sigaction( SIGTERM, &actint, NULL); // SIGPIPE signal catch. // This is not an error for our application. struct sigaction actpipe; bzero( &actpipe, sizeof(actpipe)); actpipe.sa_handler = sig_pipe; sigaction( SIGPIPE, &actpipe, NULL); // SIGALRM signal catch and block. // Special threads use alarm signal to unblock connect function. // Other threads should ignore this signal. struct sigaction actalrm; bzero( &actalrm, sizeof(actalrm)); actalrm.sa_handler = sig_alrm; sigaction( SIGALRM, &actalrm, NULL); sigset_t sigmask; sigemptyset( &sigmask); sigaddset( &sigmask, SIGALRM); if( sigprocmask( SIG_BLOCK, &sigmask, NULL) != 0) perror("sigprocmask:"); if( pthread_sigmask( SIG_BLOCK, &sigmask, NULL) != 0) perror("pthread_sigmask:"); #endif // containers initialization JobContainer jobs; if( false == jobs.isInitialized()) return 1; UserContainer users; if( false == users.isInitialized()) return 1; RenderContainer renders; if( false == renders.isInitialized()) return 1; MonitorContainer monitors; if( false == monitors.isInitialized()) return 1; // Message Queue initialization, but without thread start. // Run cycle queue will read this messages itself. af::MsgQueue msgQueue("RunMsgQueue"); if( false == msgQueue.isInitialized()) return 1; // Thread aruguments. ThreadArgs threadArgs; threadArgs.jobs = &jobs; threadArgs.renders = &renders; threadArgs.users = &users; threadArgs.monitors = &monitors; threadArgs.msgQueue = &msgQueue; /* Creating the afcommon object will actually create many message queues that will spawn threads. Have a look in the implementation of AfCommon. */ AFCommon afcommon( &threadArgs ); // Update SQL tables: afsql::DBConnection afdb_upTables("AFDB_upTables"); afdb_upTables.DBOpen(); if( afdb_upTables.isOpen()) { afsql::UpdateTables( &afdb_upTables); afdb_upTables.DBClose(); } // // Get Renders from store: // { printf("Getting renders from store...\n"); std::vector<std::string> folders = AFCommon::getStoredFolders( ENV.getRendersDir()); printf("%d renders found.\n", (int)folders.size()); for( int i = 0; i < folders.size(); i++) { RenderAf * render = new RenderAf( folders[i]); if( render->isStoredOk() != true ) { af::removeDir( render->getStoreDir()); delete render; continue; } renders.addRender( render); } printf("%d renders registered.\n", renders.getCount()); } // // Get Users from store: // { printf("Getting users from store...\n"); std::vector<std::string> folders = AFCommon::getStoredFolders( ENV.getUsersDir()); printf("%d users found.\n", (int)folders.size()); for( int i = 0; i < folders.size(); i++) { UserAf * user = new UserAf( folders[i]); if( user->isStoredOk() != true ) { af::removeDir( user->getStoreDir()); delete user; continue; } if( users.addUser( user) == 0 ) delete user; } printf("%d users registered from store.\n", users.getCount()); } // // Get Jobs from store: // bool hasSystemJob = false; { printf("Getting jobs from store...\n"); std::vector<std::string> folders = AFCommon::getStoredFolders( ENV.getJobsDir()); std::string sysjob_folder = AFCommon::getStoreDir( ENV.getJobsDir(), AFJOB::SYSJOB_ID, AFJOB::SYSJOB_NAME); printf("%d jobs found.\n", (int)folders.size()); for( int i = 0; i < folders.size(); i++) { JobAf * job = NULL; if( folders[i] == sysjob_folder) job = new SysJob( folders[i]); else job = new JobAf( folders[i]); if( job->isValidConstructed()) { if( job->getId() == AFJOB::SYSJOB_ID ) { SysJob * sysjob = (SysJob*)job; if( sysjob->initSystem() ) { hasSystemJob = true; } else { printf("System job retrieved from store is obsolete. Deleting it...\n"); delete job; continue; } } jobs.job_register( job, &users, NULL); } else { af::removeDir( job->getStoreDir()); delete job; } } printf("%d jobs registered from store.\n", jobs.getCount()); } // Disable new commands and editing: if( af::Environment::hasArgument("-demo")) { printf("Demo mode, no new commands.\n"); af::Environment::setDemoMode(); } // // Create system maintenance job if it was not in store: if( hasSystemJob == false ) { SysJob* job = new SysJob(); jobs.job_register( job, &users, NULL); } /* Start the thread that is responsible of listening to the port for incoming connections. */ DlThread ServerAccept; ServerAccept.Start( &threadAcceptClient, &threadArgs); // Run cycle thread. // All 'brains' are there. DlThread RunCycleThread; RunCycleThread.Start( &threadRunCycle, &threadArgs); /* Do nothing since everything is done in our threads. */ while( AFRunning ) { DlThread::Self()->Sleep( 1 ); } AFINFO("afanasy::main: Waiting child threads.") //alarm(1); /*FIXME: Why we don`t need to join accent thread? */ //ServerAccept.Cancel(); //ServerAccept.Join(); AFINFO("afanasy::main: Waiting Run.") // No need to chanel run cycle thread as // every new cycle it checks running external valiable RunCycleThread.Join(); af::destroy(); return 0; }
#include "monitorcontainer.h" #define AFOUTPUT #undef AFOUTPUT #include "../include/macrooutput.h" #include "../libafanasy/logger.h" JobContainer::JobContainer(): AfContainer( "Jobs", AFJOB::MAXQUANTITY) { JobAf::setJobContainer( this); } JobContainer::~JobContainer() { AFINFO("JobContainer::~JobContainer:") } void JobContainer::updateTaskState( af::MCTaskUp &taskup, RenderContainer * renders, MonitorContainer * monitoring) { switch( taskup.getStatus()) { case af::TaskExec::UPNULL: case af::TaskExec::UPNoTaskRunning: case af::TaskExec::UPNoJob: case af::TaskExec::UPLAST: AFERRAR("JobContainer::updateTaskState: Bad task update status (jobID=%d).\n", taskup.getNumJob()); return; } JobContainerIt jobsIt( this);
/** This is a main run cycle thread entry point **/ void threadRunCycle( void * i_args) { AFINFO("ThreadRun::run:") ThreadArgs * a = (ThreadArgs*)i_args; while( AFRunning) { #ifdef _DEBUG printf("...................................\n"); #endif /**/ { // // Lock containers: // AFINFO("ThreadRun::run: Locking containers...") AfContainerLock jLock( a->jobs, AfContainerLock::WRITELOCK); AfContainerLock lLock( a->renders, AfContainerLock::WRITELOCK); AfContainerLock mlock( a->monitors, AfContainerLock::WRITELOCK); AfContainerLock tlock( a->talks, AfContainerLock::WRITELOCK); AfContainerLock ulock( a->users, AfContainerLock::WRITELOCK); // // Messages reaction: // AFINFO("ThreadRun::run: React on incoming messages:") /* Process all messages in our message queue. We do it without waiting so that the job solving below can run just after. NOTE: I think this should be a waiting operation in a different thread. The job solving below should be put asleep using a semaphore and woke up when something changes. We need to avoid the Sleep() function below. */ af::Msg *message; while( message = a->msgQueue->popMsg( af::AfQueue::e_no_wait) ) { threadRunCycleCase( a, message ); } // // Refresh data: // AFINFO("ThreadRun::run: Refreshing data:") a->talks ->refresh( NULL, a->monitors); a->monitors ->refresh( NULL, a->monitors); a->jobs ->refresh( a->renders, a->monitors); a->renders ->refresh( a->jobs, a->monitors); a->users ->refresh( NULL, a->monitors); // // Jobs sloving: // { AFINFO("ThreadRun::run: Solving jobs:") RenderContainerIt rendersIt( a->renders); std::list<int> rIds; { // ask every ready render to produce a task for( RenderAf *render = rendersIt.render(); render != NULL; rendersIt.next(), render = rendersIt.render()) { if( render->isReady()) { // store render Id if it produced a task if( a->users->solve( render, a->monitors)) { rIds.push_back( render->getId()); continue; } } // Render not solved, needed to update render status render->notSolved(); } } // cycle on renders, which produced a task static const int renders_cycle_limit = 100000; int renders_cycle = 0; while( rIds.size()) { renders_cycle++; if( renders_cycle > renders_cycle_limit ) { AFERROR("Renders solve cycles limit reached."); break; } AFINFA("ThreadRun::run: Renders on cycle: %d", int(rIds.size())) std::list<int>::iterator rIt = rIds.begin(); while( rIt != rIds.end()) { RenderAf * render = rendersIt.getRender( *rIt); if( render->isReady()) { if( a->users->solve( render, a->monitors)) { rIt++; continue; } } // delete render id from list if it can't produce a task rIt = rIds.erase( rIt); } } } // // Wake-On-Lan: // { AFINFO("ThreadRun::run: Wake-On-Lan:") RenderContainerIt rendersIt( a->renders); { for( RenderAf *render = rendersIt.render(); render != NULL; rendersIt.next(), render = rendersIt.render()) { if( render->isWOLWakeAble()) { if( a->users->solve( render, a->monitors)) { render->wolWake( a->monitors, std::string("Automatic waking by a job.")); continue; } } } } } // // Dispatch events to monitors: // AFINFO("ThreadRun::run: dispatching monitor events:") a->monitors->dispatch(); // // Free Containers: // AFINFO("ThreadRun::run: deleting zombies:") a->talks ->freeZombies(); a->monitors ->freeZombies(); a->renders ->freeZombies(); a->jobs ->freeZombies(); a->users ->freeZombies(); } // // Sleeping // AFINFO("ThreadRun::run: sleeping...") af::sleep_sec( 1); } }