git-svn-id: svn://db.shs.com.ru/pip@480 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -92,6 +92,7 @@ namespace PIScreenTypes {
|
||||
typedef PIFlags<CharFlag> CharFlags;
|
||||
typedef PIFlags<FocusFlag> FocusFlags;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
union CellFormat {
|
||||
CellFormat(uint f = 0) {raw_format = f;}
|
||||
CellFormat(Color col_char, Color col_back = Default, CharFlags flags_ = 0) {
|
||||
@@ -124,6 +125,7 @@ namespace PIScreenTypes {
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
struct TileEvent {
|
||||
TileEvent(int t = -1, const PIVariant & d = PIVariant()): type(t), data(d) {}
|
||||
|
||||
@@ -83,30 +83,24 @@ PISharedMemory::PISharedMemory(const PIString & shm_name, int size, PIIODevice::
|
||||
}
|
||||
|
||||
|
||||
PISharedMemory::PISharedMemory(const PISharedMemory & other) {
|
||||
initPrivate();
|
||||
dsize = other.dsize;
|
||||
setPath(other.path());
|
||||
mode_ = other.mode_;
|
||||
}
|
||||
|
||||
|
||||
bool PISharedMemory::openDevice() {
|
||||
close();
|
||||
piCoutObj << "try open" << path() << dsize;
|
||||
#ifdef WINDOWS
|
||||
DWORD m = PAGE_READWRITE;
|
||||
if (!isWriteable()) m = PAGE_READONLY;
|
||||
PRIVATE->name = ("PIP_SHM_" + path()).toByteArray();
|
||||
PRIVATE->name.push_back(0);
|
||||
PRIVATE->map = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, m, 0, (DWORD)dsize, (const char *)PRIVATE->name.data());
|
||||
const char * nm = (const char *)PRIVATE->name.data();
|
||||
PRIVATE->map = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, nm);
|
||||
//piCoutObj << "open map =" << ullong(PRIVATE->map);
|
||||
if (!PRIVATE->map) {
|
||||
PRIVATE->map = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (DWORD)dsize, nm);
|
||||
//piCoutObj << "create map =" << ullong(PRIVATE->map);
|
||||
if (!PRIVATE->map) {
|
||||
piCoutObj << path() << dsize << "CreateFileMapping error," << errorString();
|
||||
return false;
|
||||
}
|
||||
if (!isWriteable()) m = FILE_MAP_READ;
|
||||
else m = FILE_MAP_ALL_ACCESS;
|
||||
PRIVATE->data = MapViewOfFile(PRIVATE->map, m, 0, 0, dsize);
|
||||
}
|
||||
PRIVATE->data = MapViewOfFile(PRIVATE->map, FILE_MAP_ALL_ACCESS, 0, 0, dsize);
|
||||
if (!PRIVATE->data) {
|
||||
piCoutObj << path() << dsize << "MapViewOfFile error," << errorString();
|
||||
CloseHandle(PRIVATE->map);
|
||||
@@ -209,20 +203,6 @@ PIByteArray PISharedMemory::readAll() {
|
||||
#endif
|
||||
PIByteArray a(dsize);
|
||||
read(a.data(), a.size_s());
|
||||
/*llong cp = pos();
|
||||
if (forceRead) {
|
||||
seekToBegin();
|
||||
while (!isEnd())
|
||||
a.push_back(readChar());
|
||||
seek(cp);
|
||||
return a;
|
||||
}
|
||||
llong s = size();
|
||||
if (s < 0) return a;
|
||||
a.resize(s);
|
||||
s = readAll(a.data());
|
||||
seek(cp);
|
||||
if (s >= 0) a.resize(s);*/
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -233,6 +213,14 @@ llong PISharedMemory::size() const {
|
||||
}
|
||||
|
||||
|
||||
void PISharedMemory::setSize(llong s) {
|
||||
bool o = isOpened();
|
||||
if (o) close();
|
||||
dsize = s;
|
||||
if (o) open();
|
||||
}
|
||||
|
||||
|
||||
int PISharedMemory::read(void * read_to, int max_size) {
|
||||
return read(read_to, max_size, 0);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ public:
|
||||
//! Constructs a shared memory object with name "shm_name", size "size" and open mode "mode"
|
||||
explicit PISharedMemory(const PIString & shm_name, int size, DeviceMode mode = ReadWrite);
|
||||
|
||||
PISharedMemory(const PISharedMemory & other);
|
||||
|
||||
virtual ~PISharedMemory() {close();}
|
||||
|
||||
@@ -46,6 +45,9 @@ public:
|
||||
//! Returns shared memory object size
|
||||
llong size() const;
|
||||
|
||||
//! Set shared memory object size
|
||||
void setSize(llong s);
|
||||
|
||||
//! Returns if shared memory object is empty
|
||||
bool isEmpty() const {return (size() <= 0);}
|
||||
|
||||
|
||||
@@ -249,6 +249,7 @@ __THREAD_FUNC__ PIThread::thread_function(void * t) {
|
||||
if (ct.lockRun) ct.mutex_.unlock();
|
||||
ct.started();
|
||||
while (!ct.terminating) {
|
||||
ct.maybeCallQueuedEvents();
|
||||
if (ct.lockRun) ct.mutex_.lock();
|
||||
//piCout << "thread" << ct.name() << "...";
|
||||
ct.run();
|
||||
|
||||
@@ -516,6 +516,7 @@ void PITimer::tickImp() {
|
||||
if (ret_func != 0) ret_func(data_t, 1);
|
||||
tick(data_t, 1);
|
||||
tickEvent(data_t, 1);
|
||||
maybeCallQueuedEvents();
|
||||
piForeach (Delimiter & i, delims) {
|
||||
if (i.delim > ++(i.tick)) continue;
|
||||
i.tick = 0;
|
||||
|
||||
Reference in New Issue
Block a user