mirror of
https://github.com/commaai/msgq.git
synced 2026-06-11 23:44:58 +08:00
visionipc: new helper function get_ipc_path (#564)
new helper function ipc_get_path
This commit is contained in:
@@ -3,24 +3,19 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include <unistd.h>
|
||||
#include "cereal/visionipc/ipc.h"
|
||||
#include "cereal/visionipc/visionipc_client.h"
|
||||
#include "cereal/visionipc/visionipc_server.h"
|
||||
#include "cereal/logger/logger.h"
|
||||
|
||||
static int connect_to_vipc_server(const std::string &name, bool blocking) {
|
||||
char* prefix = std::getenv("OPENPILOT_PREFIX");
|
||||
std::string path = "/tmp/";
|
||||
if (prefix) {
|
||||
path = path + std::string(prefix) + "_";
|
||||
}
|
||||
path = path + "visionipc_" + name;
|
||||
|
||||
int socket_fd = ipc_connect(path.c_str());
|
||||
const std::string ipc_path = get_ipc_path(name);
|
||||
int socket_fd = ipc_connect(ipc_path.c_str());
|
||||
while (socket_fd < 0 && blocking) {
|
||||
std::cout << "VisionIpcClient connecting" << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
socket_fd = ipc_connect(path.c_str());
|
||||
socket_fd = ipc_connect(ipc_path.c_str());
|
||||
}
|
||||
return socket_fd;
|
||||
}
|
||||
|
||||
@@ -2,11 +2,8 @@
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "cereal/messaging/messaging.h"
|
||||
#include "cereal/visionipc/visionipc.h"
|
||||
#include "cereal/visionipc/visionbuf.h"
|
||||
|
||||
class VisionIpcClient {
|
||||
|
||||
@@ -22,6 +22,14 @@ std::string get_endpoint_name(std::string name, VisionStreamType type){
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_ipc_path(const std::string& name) {
|
||||
std::string path = "/tmp/";
|
||||
if (char* prefix = std::getenv("OPENPILOT_PREFIX")) {
|
||||
path += std::string(prefix) + "_";
|
||||
}
|
||||
return path + "visionipc_" + name;
|
||||
}
|
||||
|
||||
VisionIpcServer::VisionIpcServer(std::string name, cl_device_id device_id, cl_context ctx) : name(name), device_id(device_id), ctx(ctx) {
|
||||
msg_ctx = Context::create();
|
||||
|
||||
@@ -83,14 +91,8 @@ void VisionIpcServer::start_listener(){
|
||||
void VisionIpcServer::listener(){
|
||||
std::cout << "Starting listener for: " << name << std::endl;
|
||||
|
||||
char* prefix = std::getenv("OPENPILOT_PREFIX");
|
||||
std::string path = "/tmp/";
|
||||
if (prefix) {
|
||||
path = path + std::string(prefix) + "_";
|
||||
}
|
||||
path = path + "visionipc_" + name;
|
||||
|
||||
int sock = ipc_bind(path.c_str());
|
||||
const std::string ipc_path = get_ipc_path(name);
|
||||
int sock = ipc_bind(ipc_path.c_str());
|
||||
assert(sock >= 0);
|
||||
|
||||
while (!should_exit){
|
||||
@@ -160,7 +162,7 @@ void VisionIpcServer::listener(){
|
||||
|
||||
std::cout << "Stopping listener for: " << name << std::endl;
|
||||
close(sock);
|
||||
unlink(path.c_str());
|
||||
unlink(ipc_path.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
#include <map>
|
||||
|
||||
#include "cereal/messaging/messaging.h"
|
||||
#include "cereal/visionipc/visionipc.h"
|
||||
#include "cereal/visionipc/visionbuf.h"
|
||||
|
||||
std::string get_endpoint_name(std::string name, VisionStreamType type);
|
||||
std::string get_ipc_path(const std::string &name);
|
||||
|
||||
class VisionIpcServer {
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user