mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 13:21:13 +00:00
Added musikcubed
daemon.
This commit is contained in:
parent
5807fafe1b
commit
369f9054ba
@ -84,6 +84,7 @@ endif()
|
||||
|
||||
add_subdirectory(src/core)
|
||||
add_subdirectory(src/musikcube)
|
||||
add_subdirectory(src/musikcubed)
|
||||
add_subdirectory(src/plugins/taglib_plugin)
|
||||
add_subdirectory(src/plugins/nullout)
|
||||
add_subdirectory(src/plugins/server)
|
||||
@ -104,6 +105,7 @@ endif()
|
||||
add_dependencies(taglibreader taglib)
|
||||
|
||||
add_dependencies(musikcube musikcore taglibreader nullout server httpdatastream stockencoders)
|
||||
add_dependencies(musikcubed musikcube)
|
||||
|
||||
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
add_subdirectory(src/plugins/alsaout)
|
||||
@ -203,5 +205,5 @@ endif()
|
||||
# run `cmake .` again to pick up build plugin build artifacts that we need
|
||||
# to file glob in. these won't be picked up on the initial build because
|
||||
# they don't yet exist!
|
||||
add_custom_target(postbuild ALL DEPENDS musikcube)
|
||||
add_custom_target(postbuild ALL DEPENDS musikcube musikcubed)
|
||||
add_custom_command(TARGET postbuild POST_BUILD COMMAND cmake .)
|
||||
|
6
src/musikcubed/CMakeLists.txt
Normal file
6
src/musikcubed/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
set (DAEMON_SRCS
|
||||
./main.cpp
|
||||
)
|
||||
|
||||
add_executable(musikcubed ${DAEMON_SRCS})
|
||||
target_link_libraries(musikcubed ${musikcube_LINK_LIBS} musikcore)
|
80
src/musikcubed/main.cpp
Normal file
80
src/musikcubed/main.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <core/audio/PlaybackService.h>
|
||||
#include <core/audio/MasterTransport.h>
|
||||
#include <core/debug.h>
|
||||
#include <core/library/LibraryFactory.h>
|
||||
#include <core/plugin/Plugins.h>
|
||||
#include <core/runtime/MessageQueue.h>
|
||||
#include <core/support/PreferenceKeys.h>
|
||||
#include <core/support/Common.h>
|
||||
|
||||
#include <boost/locale.hpp>
|
||||
#include <boost/filesystem/detail/utf8_codecvt_facet.hpp>
|
||||
|
||||
using namespace musik;
|
||||
using namespace musik::core;
|
||||
using namespace musik::core::audio;
|
||||
using namespace musik::core::runtime;
|
||||
|
||||
void startDaemon() {
|
||||
pid_t pid = fork();
|
||||
|
||||
if (pid < 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (pid > 0) {
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
umask(0);
|
||||
|
||||
pid_t sid = setsid();
|
||||
if (sid < 0) {
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
if (chdir("/") < 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
close(STDIN_FILENO);
|
||||
close(STDOUT_FILENO);
|
||||
close(STDERR_FILENO);
|
||||
}
|
||||
|
||||
int main() {
|
||||
startDaemon();
|
||||
|
||||
freopen("/tmp/musikcube.log", "w", stderr);
|
||||
srand((unsigned int) time(0));
|
||||
|
||||
std::locale locale = std::locale();
|
||||
std::locale utf8Locale(locale, new boost::filesystem::detail::utf8_codecvt_facet);
|
||||
boost::filesystem::path::imbue(utf8Locale);
|
||||
|
||||
debug::init();
|
||||
|
||||
MessageQueue messageQueue;
|
||||
MasterTransport transport;
|
||||
auto library = LibraryFactory::Libraries().at(0);
|
||||
auto prefs = Preferences::ForComponent(prefs::components::Settings);
|
||||
|
||||
library->SetMessageQueue(messageQueue);
|
||||
PlaybackService playback(messageQueue, library, transport);
|
||||
|
||||
plugin::InstallDependencies(&messageQueue, &playback, library);
|
||||
|
||||
if (prefs->GetBool(prefs::keys::SyncOnStartup, true)) {
|
||||
library->Indexer()->Schedule(IIndexer::SyncType::All);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
messageQueue.WaitAndDispatch();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user