clang optimizations
This commit is contained in:
@@ -49,10 +49,13 @@ private:
|
|||||||
std::string handleGetEHDRStatus();
|
std::string handleGetEHDRStatus();
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
VX_IMAGE_FORMAT stringToFormat(const std::string& format);
|
static VX_IMAGE_FORMAT stringToFormat(const std::string& format);
|
||||||
std::string formatToString(VX_IMAGE_FORMAT format);
|
|
||||||
std::string createErrorResponse(const std::string& error);
|
static std::string formatToString(VX_IMAGE_FORMAT format);
|
||||||
std::string createSuccessResponse(const std::string& message = "");
|
|
||||||
|
static std::string createErrorResponse(const std::string& error);
|
||||||
|
|
||||||
|
static std::string createSuccessResponse(const std::string& message = "");
|
||||||
|
|
||||||
std::shared_ptr<VxCamera> camera_;
|
std::shared_ptr<VxCamera> camera_;
|
||||||
std::shared_ptr<StreamingEngine> streamingEngine_;
|
std::shared_ptr<StreamingEngine> streamingEngine_;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void serverLoop();
|
void serverLoop();
|
||||||
void handleClient(int clientFd);
|
void handleClient(int clientFd) const;
|
||||||
|
|
||||||
std::string socketPath_;
|
std::string socketPath_;
|
||||||
int serverFd_;
|
int serverFd_;
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ std::string CameraController::processCommand(const std::string& jsonCommand) {
|
|||||||
return createErrorResponse("Missing command field");
|
return createErrorResponse("Missing command field");
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t colonPos = jsonCommand.find(":", cmdPos);
|
const size_t colonPos = jsonCommand.find(':', cmdPos);
|
||||||
const size_t quoteStart = jsonCommand.find("\"", colonPos);
|
const size_t quoteStart = jsonCommand.find('\"', colonPos);
|
||||||
const size_t quoteEnd = jsonCommand.find("\"", quoteStart + 1);
|
const size_t quoteEnd = jsonCommand.find('\"', quoteStart + 1);
|
||||||
|
|
||||||
if (quoteStart == std::string::npos || quoteEnd == std::string::npos) {
|
if (quoteStart == std::string::npos || quoteEnd == std::string::npos) {
|
||||||
return createErrorResponse("Invalid command format");
|
return createErrorResponse("Invalid command format");
|
||||||
@@ -41,10 +41,10 @@ std::string CameraController::processCommand(const std::string& jsonCommand) {
|
|||||||
const size_t pos = jsonCommand.find("\"" + paramName + "\"");
|
const size_t pos = jsonCommand.find("\"" + paramName + "\"");
|
||||||
if (pos == std::string::npos) return "";
|
if (pos == std::string::npos) return "";
|
||||||
|
|
||||||
const size_t colonPos = jsonCommand.find(":", pos);
|
const size_t colonPos = jsonCommand.find(':', pos);
|
||||||
|
|
||||||
if (size_t valueStart = jsonCommand.find_first_not_of(" \t\n\r", colonPos + 1); jsonCommand[valueStart] == '\"') {
|
if (size_t valueStart = jsonCommand.find_first_not_of(" \t\n\r", colonPos + 1); jsonCommand[valueStart] == '\"') {
|
||||||
size_t valueEnd = jsonCommand.find("\"", valueStart + 1);
|
size_t valueEnd = jsonCommand.find('\"', valueStart + 1);
|
||||||
return jsonCommand.substr(valueStart + 1, valueEnd - valueStart - 1);
|
return jsonCommand.substr(valueStart + 1, valueEnd - valueStart - 1);
|
||||||
} else {
|
} else {
|
||||||
size_t valueEnd = jsonCommand.find_first_of(",}", valueStart);
|
size_t valueEnd = jsonCommand.find_first_of(",}", valueStart);
|
||||||
@@ -106,7 +106,7 @@ std::string CameraController::handleSetFormat(const std::string& width, const st
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
VxFormat fmt;
|
VxFormat fmt{};
|
||||||
fmt.width = std::stoi(width);
|
fmt.width = std::stoi(width);
|
||||||
fmt.height = std::stoi(height);
|
fmt.height = std::stoi(height);
|
||||||
fmt.framerate = std::stoi(framerate);
|
fmt.framerate = std::stoi(framerate);
|
||||||
@@ -131,13 +131,13 @@ std::string CameraController::handleGetFormats() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "{\"status\":\"success\",\"formats\":[";
|
oss << R"({"status":"success","formats":[)";
|
||||||
for (size_t i = 0; i < fmtList.size(); i++) {
|
for (size_t i = 0; i < fmtList.size(); i++) {
|
||||||
if (i > 0) oss << ",";
|
if (i > 0) oss << ",";
|
||||||
oss << "{\"width\":" << fmtList[i].width
|
oss << "{\"width\":" << fmtList[i].width
|
||||||
<< ",\"height\":" << fmtList[i].height
|
<< ",\"height\":" << fmtList[i].height
|
||||||
<< ",\"framerate\":" << fmtList[i].framerate
|
<< ",\"framerate\":" << fmtList[i].framerate
|
||||||
<< ",\"format\":\"" << formatToString(fmtList[i].format) << "\"}";
|
<< R"(,"format":")" << formatToString(fmtList[i].format) << "\"}";
|
||||||
}
|
}
|
||||||
oss << "]}";
|
oss << "]}";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
@@ -328,7 +328,7 @@ std::string CameraController::handleGetEHDRStatus() {
|
|||||||
VxGetISPImageProcessing(camera_, VX_ISP_IMAGE_PROPERTIES::ISP_EHDR_RATIO_MAX, ratioMax, flag);
|
VxGetISPImageProcessing(camera_, VX_ISP_IMAGE_PROPERTIES::ISP_EHDR_RATIO_MAX, ratioMax, flag);
|
||||||
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "{\"status\":\"success\",\"ehdr_mode\":" << mode
|
oss << R"({"status":"success","ehdr_mode":)" << mode
|
||||||
<< ",\"exposure_min\":" << expMin
|
<< ",\"exposure_min\":" << expMin
|
||||||
<< ",\"exposure_max\":" << expMax
|
<< ",\"exposure_max\":" << expMax
|
||||||
<< ",\"ratio_min\":" << ratioMin
|
<< ",\"ratio_min\":" << ratioMin
|
||||||
@@ -338,8 +338,8 @@ std::string CameraController::handleGetEHDRStatus() {
|
|||||||
|
|
||||||
std::string CameraController::handleGetStatus() {
|
std::string CameraController::handleGetStatus() {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "{\"status\":\"success\",\"streaming\":" << (streamingEngine_->isRunning() ? "true" : "false")
|
oss << R"({"status":"success","streaming":)" << (streamingEngine_->isRunning() ? "true" : "false")
|
||||||
<< ",\"pipeline\":\"" << gstPipeline_ << "\"}";
|
<< R"(,"pipeline":")" << gstPipeline_ << "\"}";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,7 +388,7 @@ VX_IMAGE_FORMAT CameraController::stringToFormat(const std::string& format) {
|
|||||||
return VX_IMAGE_FORMAT::NONE;
|
return VX_IMAGE_FORMAT::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CameraController::formatToString(VX_IMAGE_FORMAT format) {
|
std::string CameraController::formatToString(const VX_IMAGE_FORMAT format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case VX_IMAGE_FORMAT::YUY2: return "YUY2";
|
case VX_IMAGE_FORMAT::YUY2: return "YUY2";
|
||||||
case VX_IMAGE_FORMAT::UYVY: return "UYVY";
|
case VX_IMAGE_FORMAT::UYVY: return "UYVY";
|
||||||
@@ -401,12 +401,12 @@ std::string CameraController::formatToString(VX_IMAGE_FORMAT format) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string CameraController::createErrorResponse(const std::string& error) {
|
std::string CameraController::createErrorResponse(const std::string& error) {
|
||||||
return "{\"status\":\"error\",\"message\":\"" + error + "\"}";
|
return R"({"status":"error","message":")" + error + "\"}";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CameraController::createSuccessResponse(const std::string& message) {
|
std::string CameraController::createSuccessResponse(const std::string& message) {
|
||||||
if (message.empty()) {
|
if (message.empty()) {
|
||||||
return "{\"status\":\"success\"}";
|
return R"({"status":"success"})";
|
||||||
}
|
}
|
||||||
return "{\"status\":\"success\",\"message\":\"" + message + "\"}";
|
return R"({"status":"success","message":")" + message + "\"}";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,10 +27,8 @@ bool SocketServer::start(CommandCallback callback) {
|
|||||||
|
|
||||||
commandCallback_ = std::move(callback);
|
commandCallback_ = std::move(callback);
|
||||||
|
|
||||||
// Remove existing socket file if it exists
|
|
||||||
unlink(socketPath_.c_str());
|
unlink(socketPath_.c_str());
|
||||||
|
|
||||||
// Create Unix domain socket
|
|
||||||
serverFd_ = socket(AF_UNIX, SOCK_STREAM, 0);
|
serverFd_ = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (serverFd_ < 0) {
|
if (serverFd_ < 0) {
|
||||||
std::cerr << "Failed to create socket" << std::endl;
|
std::cerr << "Failed to create socket" << std::endl;
|
||||||
@@ -70,14 +68,12 @@ void SocketServer::stop() {
|
|||||||
|
|
||||||
running_ = false;
|
running_ = false;
|
||||||
|
|
||||||
// Close server socket to unblock accept()
|
|
||||||
if (serverFd_ >= 0) {
|
if (serverFd_ >= 0) {
|
||||||
shutdown(serverFd_, SHUT_RDWR);
|
shutdown(serverFd_, SHUT_RDWR);
|
||||||
close(serverFd_);
|
close(serverFd_);
|
||||||
serverFd_ = -1;
|
serverFd_ = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for server thread to finish
|
|
||||||
if (serverThread_ && serverThread_->joinable()) {
|
if (serverThread_ && serverThread_->joinable()) {
|
||||||
serverThread_->join();
|
serverThread_->join();
|
||||||
}
|
}
|
||||||
@@ -101,7 +97,7 @@ void SocketServer::serverLoop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketServer::handleClient(const int clientFd) {
|
void SocketServer::handleClient(const int clientFd) const {
|
||||||
char buffer[4096];
|
char buffer[4096];
|
||||||
const ssize_t bytesRead = recv(clientFd, buffer, sizeof(buffer) - 1, 0);
|
const ssize_t bytesRead = recv(clientFd, buffer, sizeof(buffer) - 1, 0);
|
||||||
|
|
||||||
@@ -109,10 +105,8 @@ void SocketServer::handleClient(const int clientFd) {
|
|||||||
buffer[bytesRead] = '\0';
|
buffer[bytesRead] = '\0';
|
||||||
const std::string command(buffer);
|
const std::string command(buffer);
|
||||||
|
|
||||||
// Call the command callback
|
|
||||||
const std::string response = commandCallback_(command);
|
const std::string response = commandCallback_(command);
|
||||||
|
|
||||||
// Send response back to client
|
|
||||||
send(clientFd, response.c_str(), response.length(), 0);
|
send(clientFd, response.c_str(), response.length(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user