0.1.8-beta-4

This commit is contained in:
Robin Davies
2022-04-26 02:07:05 -04:00
parent 3db29505bb
commit c31bea9ecd
33 changed files with 886 additions and 572 deletions
+49 -14
View File
@@ -42,13 +42,15 @@ void AvahiService::Announce(
int portNumber,
const std::string &name,
const std::string &instanceId,
const std::string &mdnsName)
const std::string &mdnsName,
bool addTestGroup)
{
Unannounce();
this->portNumber = portNumber;
this->instanceId = instanceId;
this->mdnsName = mdnsName;
this->addTestGroup = addTestGroup;
this->name = avahi_strdup(name.c_str());
@@ -63,6 +65,9 @@ void AvahiService::Unannounce()
avahi_free(name);
this->name = nullptr;
}
this->group = nullptr;
this->client = nullptr;
this->threadedPoll = nullptr;
}
void AvahiService::entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userData)
@@ -87,7 +92,7 @@ void AvahiService::EntryGroupCallback(AvahiEntryGroup *g, AvahiEntryGroupState s
n = avahi_alternative_service_name(name);
avahi_free(name);
name = n;
Lv2Log::debug(SS("Service name collision, renaming service to '" << name << "'\n"));
Lv2Log::error(SS("Service name collision, renaming service to '" << name << "'\n"));
/* And recreate the services */
create_group(avahi_entry_group_get_client(g));
break;
@@ -102,31 +107,32 @@ void AvahiService::EntryGroupCallback(AvahiEntryGroup *g, AvahiEntryGroupState s
}
}
static int toRawDns(char*rawResult,size_t size, const std::string &name)
static int toRawDns(char *rawResult, size_t size, const std::string &name)
{
// from standard name format to <nn>xyz<nn>foo<nn>com<00> format
size_t len = name.length();
rawResult[0] = 0;
if (len+1 >= size-1) return 0;
if (len + 1 >= size - 1)
return 0;
rawResult[len+1] = 0;
rawResult[len + 1] = 0;
int count = 0;
for (int i = len-1; i >= 0; --i)
for (int i = len - 1; i >= 0; --i)
{
if (name[i] == '.')
{
rawResult[i+1] = (char)count;
rawResult[i + 1] = (char)count;
count = 0;
} else {
rawResult[i+1] = name[i];
}
else
{
rawResult[i + 1] = name[i];
++count;
}
}
rawResult[0] = count;
return len+1;
return len + 1;
}
void AvahiService::create_group(AvahiClient *c)
{
@@ -149,14 +155,14 @@ void AvahiService::create_group(AvahiClient *c)
{
Lv2Log::debug(SS("Adding service '" << name));
std::string instanceTxtRecord = SS("pipedal_id=" << this->instanceId);
std::string instanceTxtRecord = SS("id=" << this->instanceId);
#define PIPEDAL_SERVICE_TYPE "_pipedal._tcp"
if ((ret = avahi_entry_group_add_service(
group,
AVAHI_IF_UNSPEC,
AVAHI_PROTO_INET, // IPv4 for now, until we figure out why dnsqmasq borks IPv6 routing.)
AVAHI_PROTO_UNSPEC, // IPv4 for now, until we figure out why dnsqmasq borks IPv6 routing.)
(AvahiPublishFlags)0,
name,
PIPEDAL_SERVICE_TYPE,
@@ -174,12 +180,41 @@ void AvahiService::create_group(AvahiClient *c)
goto fail;
}
if (this->addTestGroup)
{
Lv2Log::info("Added tests DNS/SD service.");
std::string instanceTxtRecord = SS("id=" << "0a6045b0-1753-4104-b3e4-b9713b9cc360");
if ((ret = avahi_entry_group_add_service(
group,
AVAHI_IF_UNSPEC,
AVAHI_PROTO_INET, // IPv4 for now, until we figure out why dnsqmasq borks IPv6 routing.)
(AvahiPublishFlags)0,
"Ed's PiPedal",
PIPEDAL_SERVICE_TYPE,
NULL,
NULL,
portNumber,
// txt records.
instanceTxtRecord.c_str(),
NULL)) < 0)
{
if (ret == AVAHI_ERR_COLLISION)
goto collision;
Lv2Log::error(SS("Failed to add _pipedal._tcp service: " << avahi_strerror(ret)));
goto fail;
}
}
/* Tell the server to register the service */
if ((ret = avahi_entry_group_commit(group)) < 0)
{
Lv2Log::error(SS("Failed to commit entry group: " << avahi_strerror(ret)));
goto fail;
}
Lv2Log::info(SS("DNS/SD service announced."));
}
return;
collision:
+3 -1
View File
@@ -39,7 +39,8 @@ namespace pipedal {
class AvahiService {
public:
~AvahiService() { Unannounce(); }
void Announce(int portNumber, const std::string &name, const std::string &instanceId, const std::string&mdnsName);
void Announce(
int portNumber, const std::string &name, const std::string &instanceId, const std::string&mdnsName,bool addTestGroup = false);
void Unannounce();
@@ -62,6 +63,7 @@ namespace pipedal {
int portNumber = -1;
std::string instanceId;
std::string mdnsName;
bool addTestGroup = false;
AvahiClient *client = NULL;
AvahiEntryGroup *group = NULL;
+1
View File
@@ -948,6 +948,7 @@ int main(int argc, char **argv)
settings.valid_ = true;
settings.enable_ = false;
SetWifiDirectConfig(settings);
RestartService(true);
}
else if (enable_ap)
{
+20
View File
@@ -18,6 +18,7 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "pch.h"
#include "DeviceIdFile.hpp"
#include <sched.h>
#include "PiPedalModel.hpp"
#include "JackHost.hpp"
@@ -151,8 +152,10 @@ void PiPedalModel::LoadLv2PluginInfo(const PiPedalConfiguration&configuration)
void PiPedalModel::Load(const PiPedalConfiguration &configuration)
{
this->webRoot = configuration.GetWebRoot();
this->webPort = (uint16_t)configuration.GetSocketServerPort();
this->jackServerSettings.ReadJackConfiguration();
adminClient.MonitorGovernor(storage.GetGovernorSettings());
// lv2Host.Load(configuration.GetLv2Path().c_str());
@@ -678,6 +681,16 @@ void PiPedalModel::SetWifiConfigSettings(const WifiConfigSettings &wifiConfigSet
delete[] t;
}
}
void PiPedalModel::UpdateDnsSd()
{
avahiService.Unannounce();
DeviceIdFile deviceIdFile;
deviceIdFile.Load();
avahiService.Announce(webPort,deviceIdFile.deviceName,deviceIdFile.uuid,"pipedal");
}
void PiPedalModel::SetWifiDirectConfigSettings(const WifiDirectConfigSettings &wifiDirectConfigSettings)
{
std::lock_guard<std::recursive_mutex> guard(mutex);
@@ -701,7 +714,14 @@ void PiPedalModel::SetWifiDirectConfigSettings(const WifiDirectConfigSettings &w
t[i]->OnWifiDirectConfigSettingsChanged(tWifiDirectConfigSettings);
}
delete[] t;
// update NSD-SD announement.
UpdateDnsSd();
}
}
WifiConfigSettings PiPedalModel::GetWifiConfigSettings()
+8
View File
@@ -35,6 +35,7 @@
#include "WifiConfigSettings.hpp"
#include "WifiDirectConfigSettings.hpp"
#include "AdminClient.hpp"
#include "AvahiService.hpp"
@@ -71,6 +72,10 @@ public:
class PiPedalModel: private IJackHostCallbacks {
private:
AvahiService avahiService;
uint16_t webPort;
PiPedalAlsaDevices alsaDevices;
std::recursive_mutex mutex;
@@ -149,8 +154,11 @@ public:
PiPedalModel();
virtual ~PiPedalModel();
void Close();
void UpdateDnsSd();
AdminClient&GetAdminClient() { return adminClient; }
+7
View File
@@ -83,6 +83,11 @@ static std::pair<std::string,PluginType> urisToNames[] {
URI_TO_TYPE_MAP_ENTRY(UtilityPlugin),
URI_TO_TYPE_MAP_ENTRY(WaveshaperPlugin),
URI_TO_TYPE_MAP_ENTRY(MIDIPlugin),
// Artificial node in filters plugin that serves as parent of AmplifierPlugin and SimulatorPlugin
{std::string("http://two_play.com/ns/pluginClass#ampsNode"),PluginType::PiPedalAmpsNode }
};
PluginType pipedal::uri_to_plugin_type(const std::string&uri)
@@ -155,6 +160,8 @@ static std::pair<std::string,PluginType> strings_to_type_map[] {
STRING_TO_TYPE_MAP_ENTRY(UtilityPlugin),
STRING_TO_TYPE_MAP_ENTRY(WaveshaperPlugin),
STRING_TO_TYPE_MAP_ENTRY(MIDIPlugin),
STRING_TO_TYPE_MAP_ENTRY(MIDIPlugin),
STRING_TO_TYPE_MAP_ENTRY(PiPedalAmpsNode),
};
PluginType pipedal::string_to_plugin_type(const std::string&uri)
+2
View File
@@ -71,6 +71,8 @@ enum class PluginType {
UtilityPlugin,
WaveshaperPlugin,
MIDIPlugin,
PiPedalAmpsNode, // Pseudo-plugin type used for Amps folder in filter view.
};
const std::string &plugin_type_to_uri(PluginType type);
+12 -11
View File
@@ -499,23 +499,24 @@ void pipedal::SetWifiDirectConfig(const WifiDirectConfigSettings &settings)
sysExec("rfkill unblock wlan");
sysExec(SYSTEMCTL_BIN " daemon-reload");
sysExec(SYSTEMCTL_BIN " restart dnsmasq");
sysExec(SYSTEMCTL_BIN " enable dnsmasq");
sysExec(SYSTEMCTL_BIN " stop pipedal_p2pd");
sysExec(SYSTEMCTL_BIN " stop dnsmasq");
sysExec(SYSTEMCTL_BIN " stop wpa_supplicant");
sysExec(SYSTEMCTL_BIN " restart dhcpcd");
sysExec(SYSTEMCTL_BIN " enable dhcpcd");
sysExec(SYSTEMCTL_BIN " unmask pipedal_p2pd");
if (sysExec(SYSTEMCTL_BIN " restart pipedal_p2pd") != 0)
sysExec(SYSTEMCTL_BIN " unmask wpa_supplicant");
sysExec(SYSTEMCTL_BIN " start wpa_supplicant");
sysExec(SYSTEMCTL_BIN " enable wpa_supplicant");
sysExec(SYSTEMCTL_BIN " start dnsmasq");
sysExec(SYSTEMCTL_BIN " enable dnsmasq");
sysExec(SYSTEMCTL_BIN " start pipedal_p2pd");
if (sysExec(SYSTEMCTL_BIN " start pipedal_p2pd") != 0)
{
throw PiPedalException("Unable to start the Wi-Fi Direct access point.");
}
sysExec(SYSTEMCTL_BIN " enable pipedal_p2pd");
sysExec(SYSTEMCTL_BIN " restart pipedald");
}
}
+8
View File
@@ -143,6 +143,14 @@ void WifiDirectConfigSettings::Save() const
}
void WifiDirectConfigSettings::Load()
{
this->enable_ = false;
std::string strEnable;
if (ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","enabled",&strEnable))
{
this->enable_ = (strEnable == "true" || strEnable == "1");
}
if (!ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","p2p_device_name",&this->hotspotName_))
{
this->hotspotName_ = "PiPedal";
+4 -9
View File
@@ -504,6 +504,7 @@ int main(int argc, char *argv[])
bool help = false;
bool error = false;
bool systemd = false;
bool testExtraDevice = false;
std::string portOption;
CommandLineParser parser;
@@ -511,6 +512,7 @@ int main(int argc, char *argv[])
parser.AddOption("--help", &help);
parser.AddOption("-systemd", &systemd);
parser.AddOption("-port", &portOption);
parser.AddOption("-test-extra-device", &testExtraDevice); // advertise two different devices (for testing multi-device connect)
try
{
@@ -700,17 +702,10 @@ int main(int argc, char *argv[])
server->AddRequestHandler(downloadIntercept);
{
// Publish DNS Service.
DeviceIdFile deviceIdFile;
deviceIdFile.Load();
AvahiService service;
service.Announce(
configuration.GetSocketServerPort(),deviceIdFile.deviceName,deviceIdFile.uuid,"pipedal");
server->RunInBackground(SIGUSR1);
model.UpdateDnsSd(); // now that the server is running, publish a DNS-SD announcement.
sem_wait(&signalSemaphore);
if (systemd)
+4 -1
View File
@@ -1,13 +1,16 @@
[Unit]
Description=PiPedal P2P Session Manager
After=network.target
After=wpa_supplicant.service
After=dhcpcd.service
[Service]
ExecStart=${COMMAND} --systemd --log-level debug
Type=notify
WorkingDirectory=/var/pipedal
TimeoutStopSec=5
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
+2
View File
@@ -17,6 +17,8 @@ Group=pipedal_d
Restart=always
TimeoutStartSec=60
RestartSec=25
TimeoutStopSec=15
WorkingDirectory=/var/pipedal
Environment=JACK_PROMISCUOUS_SERVER=audio
Environment=JACK_NO_AUDIO_RESERVATION=1