int cmd_stats(mpd_unused int argc, mpd_unused char **argv, mpd_Connection *conn) { mpd_Stats *stats; time_t t; mpd_sendStatsCommand(conn); stats = mpd_getStats(conn); printErrorAndExit(conn); if (stats != NULL) { t = stats->dbUpdateTime; printf("Artists: %6d\n", stats->numberOfArtists); printf("Albums: %6d\n", stats->numberOfAlbums); printf("Songs: %6d\n", stats->numberOfSongs); printf("\n"); printf("Play Time: %s\n", DHMS(stats->playTime)); printf("Uptime: %s\n", DHMS(stats->uptime)); printf("DB Updated: %s", ctime(&t)); /* no \n needed */ printf("DB Play Time: %s\n", DHMS(stats->dbPlayTime)); mpd_freeStats(stats); } else { printf("Error getting mpd stats\n"); } return 0; }
int mpd_stats_update_real(MpdObj *mi, ChangedStatusType* what_changed) { ChangedStatusType what_changed_here = 0; if ( what_changed == NULL ) { /* we need to save the current state, because we're called standalone */ memcpy(&(mi->OldState), &(mi->CurrentState), sizeof(MpdServerState)); } if(!mpd_check_connected(mi)) { debug_printf(DEBUG_INFO,"not connected\n"); return MPD_NOT_CONNECTED; } if(mpd_lock_conn(mi)) { debug_printf(DEBUG_ERROR,"lock failed\n"); return MPD_LOCK_FAILED; } if(mi->stats != NULL) { mpd_freeStats(mi->stats); } mpd_sendStatsCommand(mi->connection); mi->stats = mpd_getStats(mi->connection); if(mi->stats == NULL) { debug_printf(DEBUG_ERROR,"Failed to grab stats from mpd\n"); } else if(mi->stats->dbUpdateTime != mi->OldState.dbUpdateTime) { debug_printf(DEBUG_INFO, "database updated\n"); what_changed_here |= MPD_CST_DATABASE; mi->CurrentState.dbUpdateTime = mi->stats->dbUpdateTime; } if (what_changed) { (*what_changed) |= what_changed_here; } else { if((mi->the_status_changed_callback != NULL) & what_changed_here) { mi->the_status_changed_callback(mi, what_changed_here, mi->the_status_changed_signal_userdata); } } if(mpd_unlock_conn(mi)) { debug_printf(DEBUG_ERROR, "unlock failed"); return MPD_LOCK_FAILED; } return MPD_OK; }
MPDStats MPDConnection::stats() { if (!isConnected()) return MPDStats(); Q_ASSERT(d->connection); mpd_call(MPDConnection::stats, Stats); mpd_Stats *stats = mpd_getStats(d->connection); if (!finishCommand() || !stats) return MPDStats(); MPDStats ret(stats); mpd_freeStats(stats); return ret; }