no message

master
zcy 2021-10-07 00:51:42 +08:00
parent dee7d8a2b2
commit f43424e8c6
10 changed files with 154 additions and 93 deletions

View File

@ -1,7 +1,14 @@
{
"files.associations": {
"*.go": "go",
"*.rh": "cpp",
"iostream": "cpp"
"iostream": "cpp",
"list": "cpp",
"mutex": "cpp",
"map": "cpp",
"thread": "cpp",
"vector": "cpp",
"xmemory": "cpp"
},
"cmake.buildDirectory": "${workspaceFolder}/build",
"cmake.mingwSearchDirs": [

View File

@ -55,6 +55,13 @@ file(GLOB NET ${PROJECT_SOURCE_DIR}/general/src/net/*.h)
file(COPY ${NET} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/net/
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ)
message( "copy threadsafe library \n")
file(GLOB THREADSAFECODE ${PROJECT_SOURCE_DIR}/general/src/threadsafe/*.hpp)
message("threadsafe " ${THREADSAFECODE})
file(COPY ${THREADSAFECODE} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/threadsafe/
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ)
file(GLOB ALGORITHM ${PROJECT_SOURCE_DIR}/general/src/algorithm/*)
file(COPY ${ALGORITHM} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/algorithm/
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ)

BIN
general/src/function/daemon Normal file

Binary file not shown.

View File

@ -4,7 +4,7 @@
* @Date: 2021-07-23 23:39:57
* @LastEditTime: 2021-08-17 00:39:53
* @LastEditTime: 2021-10-06 23:42:13
* @LastEditors: Please set LastEditors
@ -106,13 +106,14 @@ vector<string> StripList(const char *in, const char *d)
return ret;
}
#ifdef linux
inline bool existed(const std::string &name)
{
return (access(name.c_str(), F_OK) != -1);
}
#ifdef linux
void _process_start(string path)
{
@ -328,51 +329,51 @@ static BOOL SetProcessPrivilege(char *lpName, BOOL opt)
}
}
static int RangeProcess()
{
DWORD Proc_pid[1024], Retn_bytes, Proc_count, Retn_bytes2;
// static int RangeProcess()
// {
// DWORD Proc_pid[1024], Retn_bytes, Proc_count, Retn_bytes2;
unsigned int i;
// unsigned int i;
HMODULE hMod[1024];
// HMODULE hMod[1024];
HANDLE hProcess;
// HANDLE hProcess;
char szModName[MAX_PATH];
// char szModName[MAX_PATH];
if (EnumProcesses(Proc_pid, sizeof(Proc_pid), &Retn_bytes))
// if (EnumProcesses(Proc_pid, sizeof(Proc_pid), &Retn_bytes))
{
// {
Proc_count = Retn_bytes / sizeof(DWORD);
// Proc_count = Retn_bytes / sizeof(DWORD);
SetProcessPrivilege("SeDebugPrivilege", 1);
// SetProcessPrivilege("SeDebugPrivilege", 1);
for (i = 0; i < Proc_count; i++)
// for (i = 0; i < Proc_count; i++)
{
// {
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, Proc_pid[i]);
// hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, Proc_pid[i]);
if (hProcess != NULL)
// if (hProcess != NULL)
{
// {
EnumProcessModules(hProcess, hMod, sizeof(hMod), &Retn_bytes2);
// EnumProcessModules(hProcess, hMod, sizeof(hMod), &Retn_bytes2);
GetModuleFileNameEx(hProcess, hMod[0], szModName, sizeof(szModName));
// GetModuleFileNameEx(hProcess, hMod[0], szModName, sizeof(szModName));
// printf("PID=%d Path=%s\n", Proc_pid[i], szModName);
}
// // printf("PID=%d Path=%s\n", Proc_pid[i], szModName);
// }
CloseHandle(hProcess);
}
// CloseHandle(hProcess);
// }
SetProcessPrivilege("SeDebugPrivilege", 0);
}
// SetProcessPrivilege("SeDebugPrivilege", 0);
// }
return 0;
}
// return 0;
// }
static int test_fork()
@ -449,7 +450,7 @@ DaemonizeMonitor::DaemonizeMonitor(string path)
auto strip = StripList(path.c_str(), "/");
if(strip.size() > 0){
std::cout<< strip[strip.size() - 1]<<std::endl;
if(m_pids[strip[strip.size() - 1]] > 0){
if(m_running_pid[strip[strip.size() - 1]] > 0){
}else{
this->AddNewProcess(path);
}
@ -695,14 +696,7 @@ int DaemonizeMonitor::StopProcess(string path)
return -1;
}
if (!existed(path))
{
return -1;
}
#ifdef _WIN32
if (m_running_pid.find(path) != m_running_pid.end())
{

View File

@ -4,7 +4,7 @@
* @Date: 2021-07-23 23:40:36
* @LastEditTime: 2021-08-13 00:28:16
* @LastEditTime: 2021-10-06 23:48:41
* @LastEditors: Please set LastEditors
@ -13,87 +13,43 @@
* @FilePath: \generallib\general\src\function\daemon.h
*/
#if __cplusplus >= 201103L
#pragma message("编译器支持c++11")
#endif
#ifdef linux
#include <unistd.h>
#endif
#include <list>
#include<iostream>
#include <algorithm>
using namespace std;
#ifdef WIN32
#include <windows.h>
#include <Tlhelp32.h>
#include <psapi.h>
#endif
#include <string>
#include <vector>
#include <map>
#include <stdint.h>
#include <thread>
#include <stdio.h>
#include <errno.h>
#include <memory.h>
class DaemonizeMonitor{
public:
DaemonizeMonitor(string path);
int AddNewProcess(string);
int StopMonitor(string);
int StopProcess(string);
int StartMonitor();
private:
std::vector<string> m_path_process;
std::map<string,uint32_t> m_running_pid;
};

View File

@ -1,3 +1,11 @@
/*
* @Author: your name
* @Date: 2020-05-20 19:53:22
* @LastEditTime: 2021-10-07 00:44:29
* @LastEditors: your name
* @Description: In User Settings Edit
* @FilePath: \generallib\general\src\pattern\adapter.hpp
*/
//
// Created by 29019 on 2019/12/30.
//
@ -49,7 +57,7 @@ public:
};
int SetMediater(Mediator<T>* p){
mMediater = p;
return 0;
}
virtual int Send(std::string colleage,T data)=0;
virtual int Recv(std::string colleage,T data)=0;

View File

@ -1,3 +1,11 @@
/*
* @Author: your name
* @Date: 2020-05-18 19:57:58
* @LastEditTime: 2021-10-07 00:45:03
* @LastEditors: your name
* @Description: In User Settings Edit
* @FilePath: \generallib\general\src\pattern\factory.hpp
*/
//
// Created by 29019 on 2020/5/18.
//
@ -17,7 +25,7 @@ template<typename T>
class CloneAble{
public:
virtual T* Clone(){
return nullptr;
}
};

View File

@ -1,7 +1,7 @@
/*
* @Author: caiyuzheng
* @Date: 2021-10-06 23:05:26
* @LastEditTime: 2021-10-06 23:24:08
* @LastEditTime: 2021-10-07 00:50:17
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \generallib\general\src\threadsafe\thread_safe_list.h
@ -15,9 +15,78 @@ using namespace std;
template <class T>
class SafeList{
public:
SafeList(T *);
SafeList(){
}
int PushBack(T v){
m_mux.lock();
m_data.push_back(v);
m_mux.unlock();
return 0;
}
int PushFront(T v){
m_mux.lock();
m_data.push_front(v);
m_mux.unlock();
return 0;
}
int Emplace(int pos,T v){
m_mux.lock();
auto itr =m_data.begin();
for(int i = 0;itr != m_data.end(),itr++){
i++;
if(i == pos)
break;
}
m_data.emplace(itr,v);
m_mux.unlock();
return 0;
}
int EmplaceEnd(T v){
m_mux.lock();
auto itr =m_data.begin();
for(int i = 0;itr != m_data.end(),itr++){
i++;
if(i == pos)
break;
}
m_data.emplace(itr,v);
m_mux.unlock();
return 0;
}
T PopFront(int pos,T v){
if(m_data.empty()){
m_mux.lock();
ret = m_data.front();
m_data.erase(ret);
m_mux.unlock();
return ret;
}
}
T PopEnd(){
T ret;
if(m_data.empty()){
m_mux.lock();
ret = m_data.end();
m_data.erase(ret);
m_mux.unlock();
return ret;
}
}
uint32_t Length(){
m_mux.lock();
return m_data.size();
m_mux.unlock();
}
private:
std::mutex m_mux;
std::list<T> m_data;
}
};

View File

@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 3.15)
project(pattern_test)
message("current dir" ../..)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../general/obj/inc/third/include)
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../../general/obj/inc/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../obj/inc/third/include)
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../../obj/inc/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../general/obj/inc/third/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../obj/inc/third/include)
message("shit" ${CMAKE_CURRENT_SOURCE_DIR}/../../../general/obj/inc/)
message("shit" ${CMAKE_CURRENT_SOURCE_DIR}/../../../general/obj/inc/third/include)

View File

@ -1,9 +1,11 @@
//
// Created by 29019 on 2020/5/18.
//
#include "factory.hpp"
#include "pattern/factory.hpp"
#include <iostream>
#include "adapter.hpp"
#include "pattern/adapter.hpp"
#include "threadsafe/thread_safe_list.hpp"
class Player{
public:
@ -80,9 +82,12 @@ public:
}
int Send(std::string colleage,HandleData data){
this->mMediater->Relay(colleage,data);
return 0;
}
int Recv(std::string colleage,HandleData data){
std::cout<<colleage<<this->mName<<" receive data "<<data.data<<endl;
return 0;
}
};
class SoundCard :public MediatorColleague<HandleData>{
@ -91,9 +96,11 @@ public:
}
int Send(std::string colleage,HandleData data){
this->mMediater->Relay(colleage,data);
return 0;
}
int Recv(std::string colleage,HandleData data){
std::cout<<colleage<<this->mName<<" receive data "<<data.data<<endl;
return 0;
}
};
/*
@ -124,4 +131,9 @@ int main(){
// 即使delete掉了原型也能接着使用
auto tbl3 = x.GetProduct();
tbl3->Show();
// test threadsafe
SafeList<std::string> m1;
m1.PushBack("111");
}