int CondorQ::getFilterAndProcessAds( const char *constraint, StringList &attrs, condor_q_process_func process_func, void * process_func_data, bool useAll ) { ClassAd *ad; if (useAll) { // The fast case with the new protocol char *attrs_str = attrs.print_to_delimed_string(); GetAllJobsByConstraint_Start(constraint, attrs_str); free(attrs_str); while( true ) { ad = new ClassAd; if( GetAllJobsByConstraint_Next( *ad ) != 0 ) { delete ad; break; } if ( ( *process_func )( process_func_data, ad ) ) { delete(ad); } } } else { // slow case, using old protocol if ((ad = GetNextJobByConstraint(constraint, 1)) != NULL) { // Process the data and insert it into the list if ( ( *process_func )( process_func_data, ad ) ) { delete(ad); } while((ad = GetNextJobByConstraint(constraint, 0)) != NULL) { // Process the data and insert it into the list if ( ( *process_func )( process_func_data, ad ) ) { delete(ad); } } } } // here GetNextJobByConstraint returned NULL. check if it was // because of the network or not. if qmgmt had a problem with // the net, then errno is set to ETIMEDOUT, and we should fail. if ( errno == ETIMEDOUT ) { return Q_SCHEDD_COMMUNICATION_ERROR; } return Q_OK; }
int CondorQ::getFilterAndProcessAds( const char *constraint, StringList &attrs, int match_limit, condor_q_process_func process_func, void * process_func_data, bool useAll ) { int match_count = 0; ClassAd *ad = NULL; // job ad result int rval = Q_OK; // return success by default, reset on error if (useAll) { // The fast case with the new protocol char *attrs_str = attrs.print_to_delimed_string("\n"); GetAllJobsByConstraint_Start(constraint, attrs_str); free(attrs_str); while( true ) { ad = new ClassAd(); if (match_limit >= 0 && match_count >= match_limit) break; if( GetAllJobsByConstraint_Next( *ad ) != 0 ) { break; } ++match_count; // Note: According to condor_q.h, process_func() will return false if taking // ownership of ad, so only delete if it returns true, else set to NULL // so we don't delete it here. Either way, next set ad to NULL since either // it has been deleted or will be deleted later by process_func(). if (process_func(process_func_data, ad)) { delete(ad); } ad = NULL; } } else { // slow case, using old protocol ad = GetNextJobByConstraint(constraint, 1); if (ad) { // Process the data and insert it into the list. // Note: According to condor_q.h, process_func() will return false if taking // ownership of ad, so only delete if it returns true, else set to NULL // so we don't delete it here. Either way, next set ad to NULL since either // it has been deleted or will be deleted later by process_func(). if (process_func(process_func_data, ad)) { delete ad; } ad = NULL; ++match_count; while ((ad = GetNextJobByConstraint(constraint, 0)) != NULL) { if (match_limit >= 0 && match_count >= match_limit) break; // Process the data and insert it into the list. // See comment above re the return value of process_func. if (process_func(process_func_data, ad)) { delete ad; } ad = NULL; } } } // Make sure ad is not leaked no matter how we break out of the above loops. delete ad; // here GetNextJobByConstraint returned NULL. check if it was // because of the network or not. if qmgmt had a problem with // the net, then errno is set to ETIMEDOUT, and we should fail. if ( errno == ETIMEDOUT ) { rval = Q_SCHEDD_COMMUNICATION_ERROR; } return rval; }