Added musikcubed daemon.

This commit is contained in:
casey langen 2018-01-27 23:18:56 -08:00
parent 5807fafe1b
commit 369f9054ba
3 changed files with 89 additions and 1 deletions

View File

@ -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 .)

View 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
View 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();
}
}