diff --git a/src/ampswitch.cpp b/src/ampswitch.cpp index f01b899..be48efa 100644 --- a/src/ampswitch.cpp +++ b/src/ampswitch.cpp @@ -51,6 +51,7 @@ CAmpSwitch::CAmpSwitch(int argc, char *argv[]) m_jackshutdown = false; m_switchedon = false; m_samplecounter = 0; + m_usekodi = false; struct option longoptions[] = { @@ -58,11 +59,12 @@ CAmpSwitch::CAmpSwitch(int argc, char *argv[]) {"off-command", required_argument, NULL, 'f'}, {"switch-time", required_argument, NULL, 's'}, {"trigger-level", required_argument, NULL, 't'}, + {"kodi", no_argument, NULL, 'k'}, {"help", no_argument, NULL, 'h'}, {0, 0, 0, 0} }; - const char* shortoptions = "n:f:s:t:h"; + const char* shortoptions = "n:f:s:t:kh"; int c; int optionindex = 0; while ((c = getopt_long(argc, argv, shortoptions, longoptions, &optionindex)) != -1) @@ -102,6 +104,10 @@ CAmpSwitch::CAmpSwitch(int argc, char *argv[]) m_triggerlevel = triggerlevel; } + else if (c == 'k') + { + m_usekodi = true; + } else if (c == '?') { exit(1); @@ -131,6 +137,9 @@ bool CAmpSwitch::Setup() if (m_offcommand) printf("off command: \"%s\"\n", m_offcommand); + if (m_usekodi) + m_kodiclient.Start(); //start a thread that connects to Kodi's JSONRPC + return true; } @@ -212,6 +221,7 @@ void CAmpSwitch::PrintHelpMessage() " -f, --off-command command to execute when switching off\n" " -s, --switch-time minimum number of seconds between switches\n" " -t, --trigger-level absolute value of trigger level\n" + " -k, --kodi use Kodi's JSONRPC to switch on when playback starts\n" " -h, --help print this message\n" "\n" ); diff --git a/src/ampswitch.h b/src/ampswitch.h index fae25ea..60df974 100644 --- a/src/ampswitch.h +++ b/src/ampswitch.h @@ -20,6 +20,7 @@ #define AMPSWITCH_H #include +#include "kodiclient.h" class CAmpSwitch { @@ -64,6 +65,9 @@ class CAmpSwitch bool m_switchedon; int m_samplecounter; + + bool m_usekodi; + CKodiClient m_kodiclient; }; #endif //AMPSWITCH_H diff --git a/src/kodiclient.cpp b/src/kodiclient.cpp new file mode 100644 index 0000000..24b8cdd --- /dev/null +++ b/src/kodiclient.cpp @@ -0,0 +1,35 @@ +/* + * ampswitch + * Copyright (C) Bob 2021 + * + * ampswitch 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 3 of the License, or + * (at your option) any later version. + * + * ampswitch 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, see . + */ + +#include "kodiclient.h" +#include + +void CKodiClient::Start() +{ + m_thread = std::thread(SProcess, this); +} + +void CKodiClient::SProcess(CKodiClient* kodiclient) +{ + kodiclient->Process(); +} + +void CKodiClient::Process() +{ + printf("Kodi client started\n"); +} diff --git a/src/kodiclient.h b/src/kodiclient.h new file mode 100644 index 0000000..3d0d993 --- /dev/null +++ b/src/kodiclient.h @@ -0,0 +1,31 @@ +/* + * ampswitch + * Copyright (C) Bob 2021 + * + * ampswitch 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 3 of the License, or + * (at your option) any later version. + * + * ampswitch 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, see . + */ + +#include + +class CKodiClient +{ + public: + void Start(); + + private: + static void SProcess(CKodiClient* kodiclient); + void Process(); + + std::thread m_thread; +}; diff --git a/wscript b/wscript index 1cf13f8..f7a6eae 100644 --- a/wscript +++ b/wscript @@ -16,15 +16,18 @@ def configure(conf): conf.load('compiler_cxx') conf.check(header_name='jack/jack.h') + conf.check(header_name='boost/asio.hpp') - conf.check(lib='jack', uselib_store='jack', mandatory=False) + conf.check(lib='jack', uselib_store='jack', mandatory=True) + conf.check(lib='pthread', uselib_store='pthread', mandatory=False) conf.write_config_header('config.h') def build(bld): bld.program(source='src/main.cpp\ - src/ampswitch.cpp', - use=['jack'], + src/ampswitch.cpp\ + src/kodiclient.cpp', + use=['jack', 'pthread'], includes='./src', cxxflags='-Wall -g', target='ampswitch')