first commit

This commit is contained in:
2019-08-19 19:19:58 +08:00
parent 7bb6b54204
commit 2b71bf8135
145 changed files with 23208 additions and 0 deletions

29
inc/hgl/proc/Fifo.h Normal file
View File

@@ -0,0 +1,29 @@
#ifndef HGL_MULTI_PROC_FIFO_INCLUDE
#define HGL_MULTI_PROC_FIFO_INCLUDE
#include<hgl/platform/Platform.h>
namespace hgl
{
/**
* 命名管道通信
*/
class Fifo ///命名管道通信
{
public:
char filename[HGL_MAX_PATH];
int fd;
public:
Fifo()
{
*filename=0;
fd=-1;
}
bool Create(const char *); ///<创建一个管道通信文件(注:只需要文件名,不需要完整路径)
};//namespace hgl
}//namespace hgl
#endif//HGL_MULTI_PROC_FIFO_INCLUDE

View File

@@ -0,0 +1,35 @@
#ifndef HGL_MULTI_PROC_FIFO_INPUT_STREAM_INCLUDE
#define HGL_MULTI_PROC_FIFO_INPUT_STREAM_INCLUDE
#include<hgl/Fifo.h>
#include<hgl/io/InputStream.h>
namespace hgl
{
namespace io
{
/**
* 命名管道输入流
*/
class FifoInputStream:public InputStream
{
Fifo *f;
public:
FifoInputStream(Fifo *_f)
{
f=_f;
}
virtual ~FifoInputStream()
{
if(f)
delete f;
}
};//class FifoInputStream
}//namespace io
}//namespace hgl
#endif//HGL_MULTI_PROC_FIFO_INPUT_STREAM_INCLUDE

24
inc/hgl/proc/Pipe.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef HGL_MULTI_PROC_PIPE_INCLUDE
#define HGL_MULTI_PROC_PIPE_INCLUDE
#include<hgl/platform/Platform.h>
#if HGL_OS==HGL_OS_Windows
#include<windows.h>
#endif//
namespace hgl
{
#if HGL_OS==HGL_OS_Windows
using pipe_ptr=HANDLE;
constexpr pipe_ptr PIPE_NULL=nullptr;
#else
using pipe_ptr=int;
constexpr pipe_ptr PIPE_NULL=-1;
#endif//
using pipe_pair=pipe_ptr[2];
bool CreatePipe(pipe_pair &); ///<创建一对通信管道
}//namespace hgl
#endif//HGL_MULTI_PROC_PIPE_INCLUDE

41
inc/hgl/proc/Proc.h Normal file
View File

@@ -0,0 +1,41 @@
#ifndef HGL_PROCESS_INCLUDE
#define HGL_PROCESS_INCLUDE
#include<hgl/type/StringList.h>
namespace hgl
{
/**
* 进程管理类
*/
class Process ///进程管理类
{
OSString work_path;
OSString filename;
StringList<OSString> args;
int pid;
public:
Process()
{
pid=-1;
}
virtual ~Process()
{
}
bool SetWorkPath(const OSString &wp); ///<设置工作目录
bool SetExecFile(const OSString &ef); ///<设置执行文件
void AddArgv(const OSString &argv){if(!argv.IsEmpty())args.Add(argv);} ///<增加一个参数
void ClearArgs(){args.Clear();} ///<清除所有参数
bool Execute(); ///<执行程序
bool Wait(); ///<等待子进程暂停或是终止
bool Kill(); ///<杀掉子进程
bool RequestTerminate(); ///<请求子进程终止
};//class Process
}//namespace hgl
#endif//HGL_PROCESS_INCLUDE

37
inc/hgl/proc/ProcMutex.h Normal file
View File

@@ -0,0 +1,37 @@
#ifndef HGL_PROCESS_MUTEX_INCLUDE
#define HGL_PROCESS_MUTEX_INCLUDE
#include<hgl/type/DataType.h>
#if HGL_OS!=HGL_OS_Windows
#include<semaphore.h>
#endif//HGL_OS!=HGL_OS_Windows
namespace hgl
{
/**
* 进程排斥
*/
class ProcMutex ///进程排斥
{
#if HGL_OS==HGL_OS_Windows
void *lock;
#else
sem_t *lock;
#endif//HGL_OS==HGL_OS_Windows
public:
ProcMutex();
~ProcMutex(){Clear();}
bool Create(const os_char *); ///<创建进程排斥
void Clear(); ///<清除进程排斥
bool Lock(); ///<锁定
bool TryLock(); ///<尝试锁定
bool Unlock(); ///<解锁
};//class ProcMutex
}//namespace hgl
#endif//HGL_PROCESS_MUTEX_INCLUDE