<commit_before>#include "spotify-fs.h"
#include "spfs_spotify.h"
#include "spfs_audio.h"
#include "spfs_appkey.h"
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <stdbool.h>
time_t g_logged_in_at = (time_t) -1;

/* thread globals */
static bool g_main_thread_do_notify = false;
static bool g_running = false;
static bool g_playback_done = false;
static spfs_audio_playback *g_playback;
static GMutex g_spotify_notify_mutex;
static GMutex g_spotify_api_mutex;
static GCond g_spotify_notify_cond;
static GCond g_spotify_data_available;
static GThread *spotify_thread;

/*foward declarations*/
void * spotify_thread_start(void *arg);

#define STRINGIFY(x) #x
#define SPFS_WAIT_ON_FUNC(_Type) \
	static bool wait_on_ ## _Type (sp_ ## _Type *_Type) { \
		if (!_Type) return false; \
		gint64 end_time = g_get_monotonic_time() + SPFS_CB_TIMEOUT_S * G_TIME_SPAN_SECOND; \
		while (! sp_ ## _Type ## _is_loaded ( _Type )) { \
			g_debug("waiting for " STRINGIFY(_Type ) " to load"); \
			if (!g_cond_wait_until(&g_spotify_data_available, &g_spotify_api_mutex, end_time)) \
			{ \
				g_warning(STRINGIFY(_Type ) " still not loaded...giving up"); \
				return false; \
			} \
		} \
		sp_error err = sp_ ## _Type ## _error(_Type); \
		if (err != SP_ERROR_OK) { \
			g_warning(STRINGIFY(_Type ) " error: %s", sp_error_message(err)); \
			return false; \
		} \
		return true; \
	}

#define SPFS_SPOTIFY_SESSION_API_FUNC(_Ret, _Type, _Field) \
	_Ret spotify_ ## _Type ## _ ## _Field (sp_session *session, sp_ ## _Type * _Type) { \
	_Ret _Field; \
	g_mutex_lock(&g_spotify_api_mutex); \
	if (!wait_on_ ## _Type( _Type )) { \
		g_warning(STRINGIFY(_Type) " never loaded, unreliable " STRINGIFY(_Field) " information"); \
	} \
	_Field = sp_ ## _Type ## _ ## _Field (session, _Type); \
	g_mutex_unlock(&g_spotify_api_mutex); \
	return _Field; \
	}

#define SPFS_SPOTIFY_API_FUNC2(_Ret, _Type, _Field, _Type2, _Field2) \
	_Ret spotify_ ## _Type ## _ ## _Field (sp_ ## _Type * _Type, _Type2 _Field2) { \
	_Ret _Field; \
	g_mutex_lock(&g_spotify_api_mutex); \
	if (!wait_on_ ## _Type( _Type )) { \
		g_warning(STRINGIFY(_Type) " never loaded, unreliable " STRINGIFY(_Field) " information"); \
	} \
	_Field = sp_ ## _Type ## _ ## _Field (_Type, _Field2); \
	g_mutex_unlock(&g_spotify_api_mutex); \
	return _Field; \
}

#define SPFS_SPOTIFY_API_FUNC(_Ret, _Type, _Field) \
	_Ret spotify_ ## _Type ## _ ## _Field (sp_ ## _Type * _Type) { \
	_Ret _Field; \
	g_mutex_lock(&g_spotify_api_mutex); \
	if (!wait_on_ ## _Type( _Type )) { \
		g_warning(STRINGIFY(_Type) " never loaded, unreliable " STRINGIFY(_Field) " information"); \
	} \
	_Field = sp_ ## _Type ## _ ## _Field (_Type); \
	g_mutex_unlock(&g_spotify_api_mutex); \
	return _Field; \
}


sp_error sp_playlistcontainer_error(sp_playlistcontainer *unused) {
	return SP_ERROR_OK;
}
sp_error sp_artist_error(sp_artist *unused) {
	return SP_ERROR_OK;
}
sp_error sp_user_error(sp_user *unused) {
	return SP_ERROR_OK;
}
sp_error sp_playlist_error(sp_playlist *unused) {
	return SP_ERROR_OK;
}
sp_error sp_album_error(sp_album *unused) {
	return SP_ERROR_OK;
}
SPFS_WAIT_ON_FUNC(image)
SPFS_WAIT_ON_FUNC(artist)
SPFS_WAIT_ON_FUNC(album)
SPFS_WAIT_ON_FUNC(track)
SPFS_WAIT_ON_FUNC(playlist)
SPFS_WAIT_ON_FUNC(user)
SPFS_WAIT_ON_FUNC(playlistcontainer)
SPFS_WAIT_ON_FUNC(artistbrowse)
#define wait_on_session(S) (true)
int spotify_login(sp_session * session, const char *username, const char *password, const char *blob) {
	if (username == NULL) {
		char reloginname[256];

		if (sp_session_relogin(session) == SP_ERROR_NO_CREDENTIALS) {
			g_message("no stored credentials");<commit_msg>spotify: Remove unused wait_on-function<commit_after>#include "spotify-fs.h"
#include "spfs_spotify.h"
#include "spfs_audio.h"
#include "spfs_appkey.h"
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <stdbool.h>
time_t g_logged_in_at = (time_t) -1;

/* thread globals */
static bool g_main_thread_do_notify = false;
static bool g_running = false;
static bool g_playback_done = false;
static spfs_audio_playback *g_playback;
static GMutex g_spotify_notify_mutex;
static GMutex g_spotify_api_mutex;
static GCond g_spotify_notify_cond;
static GCond g_spotify_data_available;
static GThread *spotify_thread;

/*foward declarations*/
void * spotify_thread_start(void *arg);

#define STRINGIFY(x) #x
#define SPFS_WAIT_ON_FUNC(_Type) \
	static bool wait_on_ ## _Type (sp_ ## _Type *_Type) { \
		if (!_Type) return false; \
		gint64 end_time = g_get_monotonic_time() + SPFS_CB_TIMEOUT_S * G_TIME_SPAN_SECOND; \
		while (! sp_ ## _Type ## _is_loaded ( _Type )) { \
			g_debug("waiting for " STRINGIFY(_Type ) " to load"); \
			if (!g_cond_wait_until(&g_spotify_data_available, &g_spotify_api_mutex, end_time)) \
			{ \
				g_warning(STRINGIFY(_Type ) " still not loaded...giving up"); \
				return false; \
			} \
		} \
		sp_error err = sp_ ## _Type ## _error(_Type); \
		if (err != SP_ERROR_OK) { \
			g_warning(STRINGIFY(_Type ) " error: %s", sp_error_message(err)); \
			return false; \
		} \
		return true; \
	}

#define SPFS_SPOTIFY_SESSION_API_FUNC(_Ret, _Type, _Field) \
	_Ret spotify_ ## _Type ## _ ## _Field (sp_session *session, sp_ ## _Type * _Type) { \
	_Ret _Field; \
	g_mutex_lock(&g_spotify_api_mutex); \
	if (!wait_on_ ## _Type( _Type )) { \
		g_warning(STRINGIFY(_Type) " never loaded, unreliable " STRINGIFY(_Field) " information"); \
	} \
	_Field = sp_ ## _Type ## _ ## _Field (session, _Type); \
	g_mutex_unlock(&g_spotify_api_mutex); \
	return _Field; \
	}

#define SPFS_SPOTIFY_API_FUNC2(_Ret, _Type, _Field, _Type2, _Field2) \
	_Ret spotify_ ## _Type ## _ ## _Field (sp_ ## _Type * _Type, _Type2 _Field2) { \
	_Ret _Field; \
	g_mutex_lock(&g_spotify_api_mutex); \
	if (!wait_on_ ## _Type( _Type )) { \
		g_warning(STRINGIFY(_Type) " never loaded, unreliable " STRINGIFY(_Field) " information"); \
	} \
	_Field = sp_ ## _Type ## _ ## _Field (_Type, _Field2); \
	g_mutex_unlock(&g_spotify_api_mutex); \
	return _Field; \
}

#define SPFS_SPOTIFY_API_FUNC(_Ret, _Type, _Field) \
	_Ret spotify_ ## _Type ## _ ## _Field (sp_ ## _Type * _Type) { \
	_Ret _Field; \
	g_mutex_lock(&g_spotify_api_mutex); \
	if (!wait_on_ ## _Type( _Type )) { \
		g_warning(STRINGIFY(_Type) " never loaded, unreliable " STRINGIFY(_Field) " information"); \
	} \
	_Field = sp_ ## _Type ## _ ## _Field (_Type); \
	g_mutex_unlock(&g_spotify_api_mutex); \
	return _Field; \
}


sp_error sp_playlistcontainer_error(sp_playlistcontainer *unused) {
	return SP_ERROR_OK;
}
sp_error sp_artist_error(sp_artist *unused) {
	return SP_ERROR_OK;
}
sp_error sp_user_error(sp_user *unused) {
	return SP_ERROR_OK;
}
sp_error sp_playlist_error(sp_playlist *unused) {
	return SP_ERROR_OK;
}
sp_error sp_album_error(sp_album *unused) {
	return SP_ERROR_OK;
}
SPFS_WAIT_ON_FUNC(image)
SPFS_WAIT_ON_FUNC(artist)
SPFS_WAIT_ON_FUNC(album)
SPFS_WAIT_ON_FUNC(track)
SPFS_WAIT_ON_FUNC(playlist)
SPFS_WAIT_ON_FUNC(playlistcontainer)
SPFS_WAIT_ON_FUNC(artistbrowse)
#define wait_on_session(S) (true)
int spotify_login(sp_session * session, const char *username, const char *password, const char *blob) {
	if (username == NULL) {
		char reloginname[256];

		if (sp_session_relogin(session) == SP_ERROR_NO_CREDENTIALS) {
			g_message("no stored credentials");
{'fraction_non_alphanumeric': 0.13215258855585832, 'fraction_numerical': 0.0032697547683923707, 'mean_word_length': 5.046952224052719, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '307043', 'n_tokens_mistral': 3008, 'n_tokens_neox': 2929, 'n_words': 565}