summaryrefslogtreecommitdiffhomepage
path: root/midiplay.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2025-01-17 20:19:51 +0100
committerRoland Reichwein <mail@reichwein.it>2025-01-17 20:19:51 +0100
commitd9ace12fee24965baf6cf065691ed99c0d229ab1 (patch)
tree368705985079f432a17a4275867db03de7a601b5 /midiplay.cpp
parent641df30129ed241cda2440280b5282410d5ee5b3 (diff)
Detect MIDI port
Diffstat (limited to 'midiplay.cpp')
-rw-r--r--midiplay.cpp81
1 files changed, 43 insertions, 38 deletions
diff --git a/midiplay.cpp b/midiplay.cpp
index 34879ee..bc1ad08 100644
--- a/midiplay.cpp
+++ b/midiplay.cpp
@@ -2,6 +2,7 @@
#include <stdexcept>
#include <string>
+#include <iostream>
#include <fcgiapp.h>
@@ -79,53 +80,57 @@ std::string to_xml(const std::vector<std::string>& filelist, const std::string&
} // namespace
int main(int argc, char* argv[]) {
- MIDIPlayer player;
+ try {
+ MIDIPlayer player;
- std::string ok_data{"<data><status>ok</status><message>OK</message></data>"};
- std::string error_data{"<data><status>error</status><message>General Error</message></data>"};
+ std::string ok_data{"<data><status>ok</status><message>OK</message></data>"};
+ std::string error_data{"<data><status>error</status><message>General Error</message></data>"};
- int result = FCGX_Init();
- if (result != 0) {
- return 1; // error on init
- }
-
- FCGX_Request request;
-
- if (FCGX_InitRequest(&request, 0, 0) != 0) {
- return 1; // error on init
- }
+ int result = FCGX_Init();
+ if (result != 0) {
+ return 1; // error on init
+ }
- while (FCGX_Accept_r(&request) == 0) {
- std::string method = FCGX_GetParam("REQUEST_METHOD", request.envp);
+ FCGX_Request request;
- try {
- if (method == "POST") {
- FCGX_PutS("Content-Type: text/xml\r\n\r\n", request.out);
+ if (FCGX_InitRequest(&request, 0, 0) != 0) {
+ return 1; // error on init
+ }
- PostData data{request};
- std::string command {getCommand(request)};
- if (command == "start") {
- player.start();
- FCGX_PutS(ok_data.c_str(), request.out);
- } else if (command == "stop") {
- player.stop();
- FCGX_PutS(ok_data.c_str(), request.out);
- } else if (command == "getlist") {
- FCGX_PutS(to_xml(player.get_filelist(), player.get_file()).c_str(), request.out);
- } else if (command == "setfile") {
- std::string filename = data.getXMLElement("data.value");
- player.set_file(filename);
- FCGX_PutS(ok_data.c_str(), request.out);
+ while (FCGX_Accept_r(&request) == 0) {
+ std::string method = FCGX_GetParam("REQUEST_METHOD", request.envp);
+
+ try {
+ if (method == "POST") {
+ FCGX_PutS("Content-Type: text/xml\r\n\r\n", request.out);
+
+ PostData data{request};
+ std::string command {getCommand(request)};
+ if (command == "start") {
+ player.start();
+ FCGX_PutS(ok_data.c_str(), request.out);
+ } else if (command == "stop") {
+ player.stop();
+ FCGX_PutS(ok_data.c_str(), request.out);
+ } else if (command == "getlist") {
+ FCGX_PutS(to_xml(player.get_filelist(), player.get_file()).c_str(), request.out);
+ } else if (command == "setfile") {
+ std::string filename = data.getXMLElement("data.value");
+ player.set_file(filename);
+ FCGX_PutS(ok_data.c_str(), request.out);
+ } else {
+ FCGX_PutS(error_data.c_str(), request.out);
+ }
} else {
- FCGX_PutS(error_data.c_str(), request.out);
+ throw std::runtime_error(fmt::format("Bad request method: POST expected, got {}", method).c_str());
}
- } else {
- throw std::runtime_error(fmt::format("Bad request method: POST expected, got {}", method).c_str());
+ } catch (const std::exception& ex) {
+ FCGX_PutS("Content-Type: text/xml\r\n\r\n", request.out);
+ FCGX_PutS(("<data><status>error</status><message>"s + ex.what() + "</message></data>").c_str(), request.out);
}
- } catch (const std::exception& ex) {
- FCGX_PutS("Content-Type: text/xml\r\n\r\n", request.out);
- FCGX_PutS(("<data><status>error</status><message>"s + ex.what() + "</message></data>").c_str(), request.out);
}
+ } catch (const std::exception& ex) {
+ std::cerr << "Error: " << ex.what() << std::endl;
}
return 0;