-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeScanner.cpp
More file actions
81 lines (61 loc) · 2.34 KB
/
Copy pathNodeScanner.cpp
File metadata and controls
81 lines (61 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <string>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include "NodeScanner.h"
std::map<std::string,std::string> get_active_streams() {
std::map<std::string,std::string> streams;
FILE* pipe = popen("wpctl status" ,"r");
if (!pipe) return streams;
char buffer[1024];
std::string line;
bool in_streams = false;
while(fgets(buffer, sizeof(buffer), pipe) != nullptr) {
line = buffer;
if (line.find("Streams:") != std::string::npos) {
in_streams = true;
}
if (line.find("Video:") != std::string::npos) {
in_streams = false;
}
if(in_streams) {
size_t non_space = line.find_first_not_of(" \t");
if(non_space != std::string::npos) {
std::string trimmed_line = line.substr(non_space);
if(isdigit(trimmed_line[0])) {
size_t dot_pos = trimmed_line.find(". ");
if(dot_pos != std::string::npos) {
std::string id = trimmed_line.substr(0,dot_pos);
std::string name = trimmed_line.substr(dot_pos+2);
size_t last_char = name.find_last_not_of(" \r\n");
if(last_char != std::string::npos) {
name = name.substr(0,last_char+1);
}
if(name.find("input_") == std::string::npos &&
name.find("output_") == std::string::npos &&
name.find("monitor_") == std::string::npos) {
std::transform(name.begin(),name.end(),name.begin(), ::tolower);
streams[name] = id; // ID saved in the map here
}
}
}
}
}
}
pclose(pipe);
return streams;
}
// int main() {
// std::map<std::string,std::string> active_nodes = get_active_streams();
// if(active_nodes.empty()) {
// std::cout << "No active Nodes" << "\n";
// }
// else {
// std::cout << active_nodes.size() << "\n";
// for(const auto& pair : active_nodes) {
// std::cout << "Name " << pair.first << " " << "ID " << pair.second << "\n";
// }
// }
// return 0;
// }