17 changed files with 573 additions and 496 deletions
-
12core/components/config_template/config_template.hpp
-
34core/components/fileutils.cpp
-
4core/components/fileutils.hpp
-
2core/components/jobs/thread_pool_task_scheduler.hpp
-
21core/components/process/process.hpp
-
18core/components/stringutils.cpp
-
6core/components/stringutils.hpp
-
10core/components/timeutils.hpp
-
8core/components/uart/uart.cpp
-
42core/linuxcoreutils/linuxcoreutils.cpp
-
55core/linuxcoreutils/linuxcoreutils.hpp
-
7module.cmake
@ -0,0 +1,42 @@ |
|||
#include "linuxcoreutils.hpp"
|
|||
|
|||
#include "iflytopcpp/core/components/process/process.hpp"
|
|||
using namespace iflytop; |
|||
using namespace core; |
|||
|
|||
static void docmd(string cmd, string &stdout_str, string &stderr_str) { |
|||
Process process( |
|||
cmd, "", //
|
|||
[&](const char *bytes, size_t n) { stdout_str += string(bytes, n); }, |
|||
[&](const char *bytes, size_t n) { stderr_str += string(bytes, n); }); |
|||
process.get_exit_status(); |
|||
return; |
|||
} |
|||
|
|||
int LinuxCoreUtils::ls(string order, vector<string> &files) { |
|||
/**
|
|||
* @brief 检查ls指令是否包含-1参数 |
|||
*/ |
|||
if (order.find("-1") == string::npos) { |
|||
logger->error("ls must contain -1 parameter"); |
|||
return -1; |
|||
} |
|||
|
|||
string stdoutstr; |
|||
string stderrstr; |
|||
docmd(order, stdoutstr, stderrstr); |
|||
if (stderrstr.size() > 0) { |
|||
return -1; |
|||
} |
|||
//
|
|||
string file; |
|||
int filestrbegin = 0; |
|||
for (size_t i = 0; i < stdoutstr.size(); i++) { |
|||
if (stdoutstr[i] == '\n') { |
|||
file = string(stdoutstr.begin() + filestrbegin, stdoutstr.begin() + i); |
|||
files.push_back(file); |
|||
filestrbegin = i + 1; |
|||
} |
|||
} |
|||
return 0; |
|||
} |
@ -0,0 +1,55 @@ |
|||
//
|
|||
// Created by zwsd
|
|||
//
|
|||
|
|||
#pragma once
|
|||
#include <fstream>
|
|||
#include <iostream>
|
|||
#include <list>
|
|||
#include <map>
|
|||
#include <memory>
|
|||
#include <set>
|
|||
#include <sstream>
|
|||
#include <string>
|
|||
#include <vector>
|
|||
|
|||
#include "iflytopcpp/core/components/process/process.hpp"
|
|||
#include "iflytopcpp/core/spdlogfactory/logger.hpp"
|
|||
#include "iflytopcpp/core/thread/thread.hpp"
|
|||
|
|||
/**
|
|||
* @brief |
|||
* |
|||
* service: LinuxCoreUtils |
|||
* |
|||
* 监听事件: |
|||
* 依赖状态: |
|||
* 依赖服务: |
|||
* 作用: |
|||
* |
|||
*/ |
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
using namespace core; |
|||
using namespace process; |
|||
class LinuxCoreUtils { |
|||
ENABLE_LOGGER(LinuxCoreUtils); |
|||
|
|||
public: |
|||
LinuxCoreUtils(){}; |
|||
|
|||
|
|||
/**
|
|||
* @brief 调用ls指令并返回结果 |
|||
* |
|||
* @param order |
|||
* ls -1 |
|||
* ls -1 *.txt |
|||
* |
|||
* @param files |
|||
* @return int |
|||
*/ |
|||
int ls(string order, vector<string>& files); |
|||
}; |
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue