RenderAf::RenderAf( const std::string & i_store_dir): af::Render(), AfNodeSrv( this, i_store_dir) { //printf("RenderAf::RenderAf:\n"); //printf("this = %p\n", this); // setNode( this); AFINFA("RenderAf::RenderAf(%d)", m_id); initDefaultValues(); int size; char * data = af::fileRead( getStoreFile(), &size); if( data == NULL ) return; rapidjson::Document document; char * res = af::jsonParseData( document, data, size); if( res == NULL ) { delete [] data; return; } if( jsonRead( document)) setStoredOk(); delete [] res; delete [] data; // This render came from store on server start, it can't be online or busy setOffline(); setBusy( false); }
void ViewItems::loadImage() { #ifdef DRAWBACK AFINFA("ViewItems::loadImage: '%s'", afqt::QEnvironment::image_back.str.toUtf8().data()); if( afqt::QEnvironment::image_back.str.isEmpty() && ( false == m_back_filename.isEmpty())) { m_back_filename.clear(); m_back_pixmap = QPixmap(); } else { m_back_filename = afqt::QEnvironment::image_back.str; if( false == m_back_pixmap.load( m_back_filename) ) { if( false == m_back_pixmap.load( afqt::stoq(af::Environment::getAfRoot()) + "/icons/watch/" + afqt::QEnvironment::theme.str + "/" + m_back_filename)) m_back_pixmap = QPixmap(); } if( false == m_back_pixmap.isNull() ) { m_back_angle = int( 20.0f * rand() / RAND_MAX ); m_back_offset_x = int( 20.0f * rand() / RAND_MAX ); m_back_offset_y = int( 20.0f * rand() / RAND_MAX ); m_back_pixmap = m_back_pixmap.transformed( QTransform().rotate( m_back_angle ), Qt::SmoothTransformation); } } #endif }
int afqt::readdata( QTcpSocket * qSocket, char* data, int len_min, int len_max) { AFINFA("qtcom::readdata: trying to recieve %d bytes.\n", len_min); int bytes = 0; while( bytes < len_min) { qSocket->waitForReadyRead( WAITFORREADYREAD); int r = qSocket->read( data+bytes, len_max); if( r < 0) { AFERRPE("qtcom::readdata::read"); return 0; } if( r == 0) { AFERROR("qtcom::readdata:: read 0 bytes.\n"); return 0; } bytes += r; AFINFA("qtcom::readdata::read %d bytes.\n", r); } return bytes; }
JobAf::JobAf( const std::string & i_store_dir, bool i_system): af::Job(), AfNodeSrv( this, i_store_dir) { AFINFA("JobAf::JobAf: store dir = %s", i_store_dir.c_str()) initializeValues(); // We do not read store for system job // as some virtual functions from system job // will not work in a base class constructor if( i_system ) return; readStore(); }
void MonitorHost::setJobId( int i_jid, bool i_add) { AFINFA("MonitorHost::setJobId: jid=%d, add=%d", i_jid, i_add); std::vector<int> ids; ids.push_back( m_->getId()); std::ostringstream str; af::jsonActionOperationStart( str,"monitors","watch","", ids); str << ",\"class\":\"tasks\""; str << ",\"status\":\"" << ( i_add ? "subscribe" : "unsubscribe" ) << "\""; str << ",\"ids\":[" << i_jid << "]"; af::jsonActionOperationFinish( str); Watch::sendMsg( af::jsonMsg( str)); }
void Dialog::idReceived( int i_id, int i_uid) { if( MonitorHost::id() > 0 ) { if( i_id != MonitorHost::id()) { connectionLost(); } } else { if( i_id == 0) { connectionLost(); } else { AFINFA("Dialog::idReceived: ID=%d UID=%d\n", i_id, i_uid) MonitorHost::connectionEstablished( i_id, i_uid); connectionEstablished(); Watch::connectionEstablished(); if( i_uid == -1 ) { if( m_monitorType == Watch::WJobs ) { ButtonMonitor::unset(); closeList(); } displayWarning("You are not exist."); } else { displayInfo("You have registered."); if( m_monitorType == Watch::WNONE ) { ButtonMonitor::pushButton( Watch::WJobs); } } af::Msg * msg = new af::Msg( af::Msg::TMonitorUpdateId, i_id); m_qThreadClientUpdate.setUpMsg( msg); } } }
/** 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); } }