2016-12-31 01:28:18 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Christian Meffert <christian.meffert@googlemail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SRC_LIBRARY_H_
|
|
|
|
#define SRC_LIBRARY_H_
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2017-01-04 14:27:55 -05:00
|
|
|
#include "commands.h"
|
2016-12-31 01:28:18 -05:00
|
|
|
#include "db.h"
|
|
|
|
|
2017-03-13 15:03:25 -04:00
|
|
|
#define LIBRARY_OK 0
|
|
|
|
#define LIBRARY_ERROR -1
|
|
|
|
#define LIBRARY_PATH_INVALID -2
|
2017-02-18 00:55:51 -05:00
|
|
|
|
2020-03-21 17:16:57 -04:00
|
|
|
typedef void (*library_cb)(void *arg);
|
2020-03-08 16:06:21 -04:00
|
|
|
|
2020-03-23 18:17:26 -04:00
|
|
|
/*
|
|
|
|
* Argument to library_callback_schedule()
|
|
|
|
*/
|
|
|
|
enum library_cb_action
|
|
|
|
{
|
|
|
|
// Add as new callback
|
|
|
|
LIBRARY_CB_ADD,
|
|
|
|
// Replace callback if it already exists
|
|
|
|
LIBRARY_CB_REPLACE,
|
|
|
|
// Replace callback if it already exists, otherwise add as new
|
|
|
|
LIBRARY_CB_ADD_OR_REPLACE,
|
|
|
|
// Delete a callback
|
|
|
|
LIBRARY_CB_DELETE,
|
|
|
|
};
|
|
|
|
|
2016-12-31 01:28:18 -05:00
|
|
|
/*
|
|
|
|
* Definition of a library source
|
|
|
|
*
|
|
|
|
* A library source is responsible for scanning items into the library db.
|
|
|
|
*/
|
|
|
|
struct library_source
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
int disabled;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize library source (called from the main thread)
|
|
|
|
*/
|
|
|
|
int (*init)(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shutdown library source (called from the main thread after
|
|
|
|
* terminating the library thread)
|
|
|
|
*/
|
|
|
|
void (*deinit)(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run initial scan after startup (called from the library thread)
|
|
|
|
*/
|
|
|
|
int (*initscan)(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run rescan (called from the library thread)
|
|
|
|
*/
|
|
|
|
int (*rescan)(void);
|
|
|
|
|
2019-06-08 10:10:55 -04:00
|
|
|
/*
|
|
|
|
* Run a metadata rescan of library even if files not changed (called from the library thread)
|
|
|
|
*/
|
|
|
|
int (*metarescan)(void);
|
|
|
|
|
2016-12-31 01:28:18 -05:00
|
|
|
/*
|
|
|
|
* Run a full rescan (purge library entries and rescan) (called from the library thread)
|
|
|
|
*/
|
|
|
|
int (*fullrescan)(void);
|
|
|
|
|
2020-03-08 16:06:21 -04:00
|
|
|
/*
|
2020-03-21 17:16:57 -04:00
|
|
|
* Add an item to the library
|
2020-03-08 16:06:21 -04:00
|
|
|
*/
|
2020-03-21 17:16:57 -04:00
|
|
|
int (*item_add)(const char *path);
|
2020-03-08 16:06:21 -04:00
|
|
|
|
2017-08-09 12:19:20 -04:00
|
|
|
/*
|
2020-01-20 17:13:47 -05:00
|
|
|
* Add item to playlist
|
2017-08-09 12:19:20 -04:00
|
|
|
*/
|
2020-01-20 17:13:47 -05:00
|
|
|
int (*playlist_item_add)(const char *vp_playlist, const char *vp_item);
|
2017-08-09 12:19:20 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Removes the playlist under the given virtual path
|
|
|
|
*/
|
|
|
|
int (*playlist_remove)(const char *virtual_path);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save queue as a new playlist under the given virtual path
|
|
|
|
*/
|
|
|
|
int (*queue_save)(const char *virtual_path);
|
2016-12-31 01:28:18 -05:00
|
|
|
|
2018-03-09 13:03:43 -05:00
|
|
|
/*
|
|
|
|
* Add item for the given path to the current queue
|
|
|
|
*/
|
2020-01-20 17:13:47 -05:00
|
|
|
int (*queue_item_add)(const char *path, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id);
|
2018-03-09 13:03:43 -05:00
|
|
|
};
|
2016-12-31 01:28:18 -05:00
|
|
|
|
2020-01-20 17:13:47 -05:00
|
|
|
/* --------------------- Interface towards source backends ----------------- */
|
|
|
|
|
2020-03-21 17:16:57 -04:00
|
|
|
/*
|
|
|
|
* Adds a mfi if mfi->id == 0, otherwise updates.
|
|
|
|
*
|
|
|
|
* @param mfi Media to save
|
|
|
|
* @return 0 if operation succeeded, -1 on failure.
|
|
|
|
*/
|
2020-01-31 17:38:05 -05:00
|
|
|
int
|
2020-01-20 17:13:47 -05:00
|
|
|
library_media_save(struct media_file_info *mfi);
|
2016-12-31 01:28:18 -05:00
|
|
|
|
2020-02-04 17:15:56 -05:00
|
|
|
/*
|
|
|
|
* Adds a playlist if pli->id == 0, otherwise updates.
|
|
|
|
*
|
|
|
|
* @param pli Playlist to save
|
2020-03-21 17:16:57 -04:00
|
|
|
* @return Playlist id if operation succeeded, -1 on failure.
|
2020-02-04 17:15:56 -05:00
|
|
|
*/
|
2016-12-31 01:28:18 -05:00
|
|
|
int
|
2020-01-20 17:13:47 -05:00
|
|
|
library_playlist_save(struct playlist_info *pli);
|
2016-12-31 01:28:18 -05:00
|
|
|
|
2020-03-21 17:16:57 -04:00
|
|
|
/*
|
|
|
|
* @param cb Callback to call
|
|
|
|
* @param arg Argument to call back with
|
|
|
|
* @param timeval How long to wait before calling back
|
2020-03-23 18:17:26 -04:00
|
|
|
* @param action (see enum)
|
2020-03-21 17:16:57 -04:00
|
|
|
* @return id of the scheduled event, -1 on failure
|
|
|
|
*/
|
|
|
|
int
|
2020-03-23 18:17:26 -04:00
|
|
|
library_callback_schedule(library_cb cb, void *arg, struct timeval *wait, enum library_cb_action action);
|
2020-03-21 17:16:57 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @return true if a running scan should be aborted due to imminent shutdown
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
library_is_exiting();
|
|
|
|
|
|
|
|
|
2020-01-20 17:13:47 -05:00
|
|
|
/* ------------------------ Library external interface --------------------- */
|
2017-02-18 00:55:51 -05:00
|
|
|
|
2016-12-31 01:28:18 -05:00
|
|
|
void
|
|
|
|
library_rescan();
|
|
|
|
|
2019-06-08 10:10:55 -04:00
|
|
|
void
|
|
|
|
library_metarescan();
|
|
|
|
|
2016-12-31 01:28:18 -05:00
|
|
|
void
|
|
|
|
library_fullrescan();
|
|
|
|
|
2020-01-20 17:13:47 -05:00
|
|
|
/*
|
|
|
|
* @return true if scan is running, otherwise false
|
|
|
|
*/
|
2016-12-31 01:28:18 -05:00
|
|
|
bool
|
|
|
|
library_is_scanning();
|
|
|
|
|
2020-01-20 17:13:47 -05:00
|
|
|
/*
|
|
|
|
* @param is_scanning true if scan is running, otherwise false
|
|
|
|
*/
|
2016-12-31 01:28:18 -05:00
|
|
|
void
|
|
|
|
library_set_scanning(bool is_scanning);
|
|
|
|
|
2020-01-20 17:13:47 -05:00
|
|
|
/*
|
|
|
|
* Trigger for sending the DATABASE event
|
|
|
|
*
|
|
|
|
* Needs to be called, if an update to the database (library tables) occurred. The DATABASE event
|
|
|
|
* is emitted with the delay 'library_update_wait'. It is safe to call this function from any thread.
|
|
|
|
*/
|
2017-01-27 17:23:25 -05:00
|
|
|
void
|
2017-12-09 11:12:13 -05:00
|
|
|
library_update_trigger(short update_events);
|
2017-01-27 17:23:25 -05:00
|
|
|
|
2017-08-09 12:19:20 -04:00
|
|
|
int
|
2020-01-20 17:13:47 -05:00
|
|
|
library_playlist_item_add(const char *vp_playlist, const char *vp_item);
|
2017-08-09 12:19:20 -04:00
|
|
|
|
|
|
|
int
|
|
|
|
library_playlist_remove(char *virtual_path);
|
|
|
|
|
|
|
|
int
|
|
|
|
library_queue_save(char *path);
|
|
|
|
|
2020-01-20 17:13:47 -05:00
|
|
|
int
|
|
|
|
library_queue_item_add(const char *path, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id);
|
|
|
|
|
2020-03-08 16:06:21 -04:00
|
|
|
int
|
2020-03-21 17:16:57 -04:00
|
|
|
library_item_add(const char *path);
|
2020-03-08 16:06:21 -04:00
|
|
|
|
|
|
|
|
2020-01-20 17:13:47 -05:00
|
|
|
/*
|
|
|
|
* Execute the function 'func' with the given argument 'arg' in the library thread.
|
|
|
|
*
|
|
|
|
* The pointer passed as argument is freed in the library thread after func returned.
|
|
|
|
*
|
|
|
|
* @param func The function to be executed
|
|
|
|
* @param arg Argument passed to func
|
|
|
|
* @return 0 if triggering the function execution succeeded, -1 on failure.
|
|
|
|
*/
|
2017-01-04 14:27:55 -05:00
|
|
|
int
|
|
|
|
library_exec_async(command_function func, void *arg);
|
|
|
|
|
2016-12-31 01:28:18 -05:00
|
|
|
int
|
|
|
|
library_init();
|
|
|
|
|
|
|
|
void
|
|
|
|
library_deinit();
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* SRC_LIBRARY_H_ */
|