1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
1 |
/* Copyright (c) 2010 PrimeBase Technologies GmbH, Germany
|
2 |
*
|
|
3 |
* PrimeBase Media Stream for MySQL
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
8 |
* (at your option) any later version.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
1841.1.6
by Barry.Leslie at PrimeBase
Updating PBMS code to match pbms revision 244 |
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
18 |
*
|
19 |
* Author: Barry Leslie
|
|
20 |
*
|
|
21 |
* 2010-02-05
|
|
22 |
*
|
|
23 |
* CORE SYSTEM:
|
|
24 |
* Basic system specific file I/O classes.
|
|
25 |
* The classes in this header are defined in CSSys_unix.cc and CSSys_win.cc
|
|
26 |
*
|
|
27 |
*/
|
|
28 |
||
29 |
#ifndef __CSSYSFILE_H__
|
|
30 |
#define __CSSYSFILE_H__
|
|
31 |
||
32 |
#ifdef OS_WINDOWS
|
|
33 |
#define INVALID_DIR_HANDLE (INVALID_HANDLE_VALUE)
|
|
34 |
#define INVALID_FILE_HANDLE (INVALID_HANDLE_VALUE)
|
|
35 |
#else
|
|
36 |
#include <dirent.h> |
|
37 |
#define INVALID_DIR_HANDLE (NULL)
|
|
38 |
#define INVALID_FILE_HANDLE (-1)
|
|
39 |
#endif
|
|
40 |
||
41 |
#include "CSString.h" |
|
42 |
#include "CSException.h" |
|
43 |
#include "CSTime.h" |
|
44 |
||
45 |
class CSSysDir { |
|
46 |
public: |
|
47 |
CSSysDir(): |
|
48 |
sd_path(NULL), |
|
49 |
sd_filter(NULL), |
|
50 |
sd_dir(INVALID_DIR_HANDLE){} |
|
51 |
||
52 |
~CSSysDir(); |
|
53 |
||
54 |
void open(); |
|
55 |
void close(); |
|
56 |
bool next(); |
|
57 |
||
58 |
bool entryIsFile(); |
|
59 |
const char *entryName(); |
|
60 |
void getEntryPath(char *path, size_t size); |
|
61 |
||
62 |
CSString *sd_path; |
|
63 |
||
64 |
private: |
|
65 |
CSStringBuffer *sd_filter; |
|
66 |
#ifdef OS_WINDOWS
|
|
67 |
WIN32_FIND_DATAA sd_entry; |
|
68 |
HANDLE sd_dir; |
|
69 |
#else
|
|
70 |
struct dirent sd_entry; |
|
71 |
DIR *sd_dir; |
|
72 |
#endif
|
|
73 |
};
|
|
74 |
||
75 |
||
76 |
class CSSysFile { |
|
77 |
public: |
|
78 |
||
79 |
static bool isDirNotFound(CSException *e); |
|
80 |
static bool isFileNotFound(CSException *e); |
|
81 |
static bool isDirExists(CSException *e); |
|
82 |
||
83 |
CSSysFile(): sf_path(NULL), sf_fh(INVALID_FILE_HANDLE){} |
|
84 |
||
85 |
~CSSysFile(){ sf_close();} |
|
86 |
||
87 |
bool fs_isOpen() { return ( sf_fh != INVALID_FILE_HANDLE);} |
|
88 |
||
89 |
void sf_open(const char *path, bool readonly, bool create); |
|
90 |
void sf_close(); |
|
91 |
||
92 |
size_t sf_pread(void *data, size_t size, off64_t offset); |
|
93 |
void sf_pwrite(const void *data, size_t size, off64_t offset); |
|
94 |
||
95 |
off64_t sf_getEOF(); |
|
96 |
void sf_setEOF(off64_t offset); |
|
97 |
||
98 |
void sf_sync(); |
|
99 |
||
100 |
void sf_lock(bool shared); |
|
101 |
void sf_unlock(); |
|
102 |
||
103 |
private: |
|
104 |
CSString *sf_path; |
|
105 |
#ifdef OS_WINDOWS
|
|
106 |
HANDLE sf_fh; |
|
107 |
#else
|
|
108 |
int sf_fh; |
|
109 |
#endif
|
|
110 |
||
111 |
};
|
|
112 |
||
113 |
class CSSys { |
|
114 |
public: |
|
115 |
static bool sys_exists(const char *path); |
|
116 |
static void sys_makeDir(const char *path); |
|
117 |
static void sys_removeDir(const char *path); |
|
118 |
static void sys_removeFile(const char *path); |
|
119 |
static void sys_rename(const char *old_path, const char *new_path); |
|
120 |
static void sys_stat(const char *path, bool *is_dir, off64_t *size, CSTime *mod_time); |
|
121 |
static bool sys_isLink(const char *path); |
|
122 |
static void sys_getcwd(char *path, size_t size); |
|
123 |
static void sys_setcwd(const char *path); |
|
124 |
static uint32_t sys_getpid(); |
|
125 |
static bool sys_isAlive(uint32_t pid); |
|
126 |
};
|
|
127 |
||
128 |
#endif
|