This commit is contained in:
Robin Davies
2022-04-30 09:06:40 -04:00
parent 179ff9c276
commit f0f075ae4e
16 changed files with 209 additions and 77 deletions
+4 -6
View File
@@ -29,6 +29,8 @@
using namespace pipedal;
using namespace std;
const bool ENABLE_KEEP_ALIVE = false;
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
const size_t MAX_READ_SIZE = 1 * 1024 * 204;
@@ -164,8 +166,7 @@ namespace pipedal
virtual const std::string &get(const std::string &key) const { return m_request.get_header(key); }
virtual bool keepAlive() const
{
m_request.get_version() != "1.0" || m_request.get_header("Connection") == "keep-alive";
return true;
return ENABLE_KEEP_ALIVE && (m_request.get_version() != "1.0" || m_request.get_header("Connection") == "keep-alive");
}
};
class HttpResponseImpl : public HttpResponse
@@ -187,7 +188,7 @@ namespace pipedal
virtual void setBody(const std::string &body) { request.set_body(body); }
virtual void keepAlive(bool value)
{
if (!value)
if ((!value) || (!ENABLE_KEEP_ALIVE))
{
set("Connection", "close");
}
@@ -418,9 +419,6 @@ namespace pipedal
if (requestHandler->wants(req.method(), requestUri))
{
try
{
+30
View File
@@ -735,6 +735,36 @@ WifiDirectConfigSettings PiPedalModel::GetWifiDirectConfigSettings()
return this->storage.GetWifiDirectConfigSettings();
}
void PiPedalModel::SetShowStatusMonitor(bool show)
{
IPiPedalModelSubscriber **t;
size_t n;
{
std::lock_guard<std::recursive_mutex> guard(mutex); // copy atomically.
t = new IPiPedalModelSubscriber *[this->subscribers.size()];
n = this->subscribers.size();
storage.SetShowStatusMonitor(show);
// Notify clients.
IPiPedalModelSubscriber **t = new IPiPedalModelSubscriber *[this->subscribers.size()];
for (size_t i = 0; i < subscribers.size(); ++i)
{
t[i] = this->subscribers[i];
}
for (size_t i = 0; i < n; ++i)
{
t[i]->OnShowStatusMonitorChanged(show);
}
delete[] t;
}
}
bool PiPedalModel::GetShowStatusMonitor()
{
std::lock_guard<std::recursive_mutex> guard(mutex); // copy atomically.
return storage.GetShowStatusMonitor();
}
JackConfiguration PiPedalModel::GetJackConfiguration()
{
std::lock_guard<std::recursive_mutex> guard(mutex); // copy atomically.
+4
View File
@@ -67,6 +67,7 @@ public:
virtual void OnWifiDirectConfigSettingsChanged(const WifiDirectConfigSettings&wifiDirectConfigSettings) = 0;
virtual void OnGovernorSettingsChanged(const std::string &governor) = 0;
virtual void OnFavoritesChanged(const std::map<std::string,bool> &favorites) = 0;
virtual void OnShowStatusMonitorChanged(bool show) = 0;
virtual void Close() = 0;
};
@@ -214,6 +215,9 @@ public:
void SetJackChannelSelection(int64_t clientId,const JackChannelSelection &channelSelection);
JackChannelSelection GetJackChannelSelection();
void SetShowStatusMonitor(bool show);
bool GetShowStatusMonitor();
void SetWifiConfigSettings(const WifiConfigSettings&wifiConfigSettings);
WifiConfigSettings GetWifiConfigSettings();
+15
View File
@@ -924,6 +924,16 @@ public:
pReader->read(&jackSettings);
this->model.SetJackChannelSelection(this->clientId, jackSettings);
}
else if (message == "setShowStatusMonitor")
{
bool showStatusMonitor;
pReader->read(&showStatusMonitor);
this->model.SetShowStatusMonitor(showStatusMonitor);
}
else if (message == "getShowStatusMonitor")
{
Reply(replyTo,"getShowStatusMonitor",this->model.GetShowStatusMonitor());
}
else if (message == "version")
{
PiPedalVersion version(this->model);
@@ -1255,6 +1265,11 @@ public:
{
Send("onFavoritesChanged",favorites);
}
virtual void OnShowStatusMonitorChanged(bool show) {
Send("onShowStatusMonitorChanged",show);
}
virtual void OnChannelSelectionChanged(int64_t clientId, const JackChannelSelection &channelSelection)
{
ChannelSelectionChangedBody body;
+32 -13
View File
@@ -33,7 +33,9 @@ const char *BANK_EXTENSION = ".bank";
const char *BANKS_FILENAME = "index.banks";
#define WIFI_CONFIG_SETTINGS_FILENAME "wifiConfigSettings.json";
#define GOVERNOR_SETTINGS_FILENAME "governorSettings.json";
#define USER_SETTINGS_FILENAME "userSettings.json";
Storage::Storage()
{
@@ -228,7 +230,7 @@ void Storage::Initialize()
}
LoadWifiConfigSettings();
LoadWifiDirectConfigSettings();
LoadGovernorSettings();
LoadUserSettings();
}
@@ -854,9 +856,14 @@ int64_t Storage::UploadBank(BankFile&bankFile,int64_t uploadAfter)
return lastBank;
}
void Storage::SetGovernorSettings(const std::string & governor)
{
std::filesystem::path path = this->dataRoot / GOVERNOR_SETTINGS_FILENAME;
userSettings.governor_ = governor;
SaveUserSettings();
}
void Storage::SaveUserSettings() {
std::filesystem::path path = this->dataRoot / USER_SETTINGS_FILENAME;
{
std::ofstream f(path);
if (!f.is_open())
@@ -864,13 +871,22 @@ void Storage::SetGovernorSettings(const std::string & governor)
throw PiPedalException("Unable to write to " + ((std::string)path));
}
json_writer writer(f);
writer.write(governor);
this->governorSettings = governor;
writer.write(userSettings);
}
}
void Storage::SetShowStatusMonitor(bool show)
{
this->userSettings.showStatusMonitor_ = show;
SaveUserSettings();
}
bool Storage::GetShowStatusMonitor() const
{
return this->userSettings.showStatusMonitor_;
}
std::string Storage::GetGovernorSettings() const
{
return this->governorSettings;
return this->userSettings.governor_;
}
@@ -925,9 +941,9 @@ void Storage::SetWifiDirectConfigSettings(const WifiDirectConfigSettings & wifiD
this->wifiDirectConfigSettings = copyToStore;
}
void Storage::LoadGovernorSettings()
void Storage::LoadUserSettings()
{
std::filesystem::path path = this->dataRoot / GOVERNOR_SETTINGS_FILENAME;
std::filesystem::path path = this->dataRoot / USER_SETTINGS_FILENAME;
try {
if (std::filesystem::is_regular_file(path))
@@ -935,16 +951,13 @@ void Storage::LoadGovernorSettings()
std::ifstream f(path);
if (!f.is_open())
{
throw PiPedalException("Unable to write to " + ((std::string)path));
throw PiPedalException("Unable to read from " + ((std::string)path));
}
json_reader reader(f);
std::string governorSettings;
reader.read(&governorSettings);
this->governorSettings = governorSettings;
reader.read(&userSettings);
}
} catch (const std::exception&)
{
this->governorSettings = "performance";
}
this->wifiConfigSettings.valid_ = true;
@@ -1293,6 +1306,12 @@ void Storage::SetFavorites(const std::map<std::string,bool>&favorites) {
}
JSON_MAP_BEGIN(UserSettings)
JSON_MAP_REFERENCE(UserSettings,governor)
JSON_MAP_REFERENCE(UserSettings,showStatusMonitor)
JSON_MAP_END()
JSON_MAP_BEGIN(CurrentPreset)
JSON_MAP_REFERENCE(CurrentPreset,modified)
JSON_MAP_REFERENCE(CurrentPreset,preset)
+16 -2
View File
@@ -41,6 +41,15 @@ public:
DECLARE_JSON_MAP(CurrentPreset);
};
class UserSettings {
public:
std::string governor_ = "performance";
bool showStatusMonitor_ = true;
DECLARE_JSON_MAP(UserSettings);
};
// controls user-defined storage. Implmentation hidden to allow to later migration to a database (perhaps)
class Storage {
@@ -77,7 +86,8 @@ private:
JackChannelSelection jackChannelSelection;
WifiConfigSettings wifiConfigSettings;
WifiDirectConfigSettings wifiDirectConfigSettings;
std::string governorSettings = "performance";
UserSettings userSettings;
public:
Storage();
void Initialize();
@@ -93,7 +103,8 @@ public:
void LoadWifiConfigSettings();
void LoadWifiDirectConfigSettings();
void LoadGovernorSettings();
void LoadUserSettings();
void SaveUserSettings();
void LoadBank(int64_t instanceId);
const PedalBoard& GetCurrentPreset();
void SaveCurrentPreset(const PedalBoard&pedalBoard);
@@ -154,6 +165,9 @@ public:
std::map<std::string,bool> GetFavorites() const;
void SetFavorites(const std::map<std::string,bool>&favorites);
void SetShowStatusMonitor(bool show);
bool GetShowStatusMonitor() const;
};