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; }
void mpd_free(MpdObj *mi) { debug_printf(DEBUG_INFO, "destroying MpdObj object\n"); if(mi->connected) { /* disconnect */ debug_printf(DEBUG_WARNING, "Connection still running, disconnecting\n"); mpd_disconnect(mi); } if(mi->hostname) { free(mi->hostname); } if(mi->password) { free(mi->password); } if(mi->error_msg) { free(mi->error_msg); } if(mi->connection) { /* obsolete */ mpd_closeConnection(mi->connection); } if(mi->status) { mpd_freeStatus(mi->status); } if(mi->stats) { mpd_freeStats(mi->stats); } if(mi->CurrentSong) { mpd_freeSong(mi->CurrentSong); } mpd_free_queue_ob(mi); mpd_server_free_commands(mi); free(mi); }
int mpd_disconnect(MpdObj *mi) { /* lock */ mpd_lock_conn(mi); debug_printf(DEBUG_INFO, "disconnecting\n"); if(mi->connection) { mpd_closeConnection(mi->connection); mi->connection = NULL; } if(mi->status) { mpd_freeStatus(mi->status); mi->status = NULL; } if(mi->stats) { mpd_freeStats(mi->stats); mi->stats = NULL; } if(mi->CurrentSong) { mpd_freeSong(mi->CurrentSong); mi->CurrentSong = NULL; } mi->CurrentState.playlistid = -1; mi->CurrentState.queueid = -2; mi->CurrentState.storedplaylistid = -1; mi->CurrentState.state = -1; mi->CurrentState.songid = -1; mi->CurrentState.songpos = -1; mi->CurrentState.dbUpdateTime = 0; mi->CurrentState.updatingDb = 0; mi->CurrentState.repeat = -1; mi->CurrentState.random = -1; mi->CurrentState.volume = -2; mi->CurrentState.xfade = -1; mi->CurrentState.totaltime = 0; mi->CurrentState.elapsedtime = 0; mi->CurrentState.bitrate = 0; mi->CurrentState.samplerate = 0; mi->CurrentState.channels = 0; mi->CurrentState.bits = 0; mi->CurrentState.playlistLength = 0; mi->CurrentState.error[0] = '\0'; /* search stuff */ mi->search_type = MPD_SEARCH_TYPE_NONE; /* no need to initialize, but set it to anything anyway*/ mi->search_field = MPD_TAG_ITEM_ARTIST; memcpy(&(mi->OldState), &(mi->CurrentState) , sizeof(MpdServerState)); mpd_free_queue_ob(mi); mpd_server_free_commands(mi); /*don't reset errors */ /* Remove this signal, we don't actually disconnect */ if(mi->connected) { /* set disconnect flag */ mi->connected = FALSE; if(mi->the_connection_changed_callback != NULL) { mi->the_connection_changed_callback( mi, FALSE, mi->the_connection_changed_signal_userdata ); } } debug_printf(DEBUG_INFO, "Disconnect completed\n"); return MPD_OK; }