source: trunk/tools/qvfb/qvfbshmem.cpp@ 1039

Last change on this file since 1039 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 8.4 KB
RevLine 
[2]1/****************************************************************************
2**
[846]3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
[561]4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
[2]6**
7** This file is part of the tools applications of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
[561]24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
[2]27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
[561]36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
[2]38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qlock_p.h"
43
44#include "qvfbshmem.h"
45#include "qvfbhdr.h"
46
47#include <QFile>
48#include <QTimer>
49
50#include <stdlib.h>
51#include <unistd.h>
52#include <sys/ipc.h>
53#include <sys/types.h>
54#include <sys/shm.h>
55#include <sys/stat.h>
56#include <sys/sem.h>
57#include <sys/mman.h>
58#include <fcntl.h>
59#include <errno.h>
60#include <math.h>
61
62QT_BEGIN_NAMESPACE
63
64#ifdef Q_WS_QWS
65#error qvfb must be compiled with the Qt for X11 package
66#endif
67
68// Get the name of the directory where Qt for Embedded Linux temporary data should
69// live.
70static QString qws_dataDir(int qws_display_id)
71{
[561]72 QByteArray dataDir = QT_VFB_DATADIR(qws_display_id).toLocal8Bit();
[2]73 if (mkdir(dataDir, 0700)) {
74 if (errno != EEXIST) {
75 qFatal("Cannot create Qt for Embedded Linux data directory: %s", dataDir.constData());
76 }
77 }
78
79 struct stat buf;
80 if (lstat(dataDir, &buf))
81 qFatal("stat failed for Qt for Embedded Linux data directory: %s", dataDir.constData());
82
83 if (!S_ISDIR(buf.st_mode))
84 qFatal("%s is not a directory", dataDir.constData());
85 if (buf.st_uid != getuid())
86 qFatal("Qt for Embedded Linux data directory is not owned by user %uh", getuid());
87
88 if ((buf.st_mode & 0677) != 0600)
89 qFatal("Qt for Embedded Linux data directory has incorrect permissions: %s", dataDir.constData());
90 dataDir += "/";
91
92 return QString(dataDir);
93}
94
95
96static QString displayPipe;
97static QString displayPiped;
98class DisplayLock
99{
100public:
101 DisplayLock() : qlock(0) {
102 if (QFile::exists(displayPiped)) {
103 qlock = new QLock(displayPipe, 'd', false);
104 qlock->lock(QLock::Read);
105 }
106 }
107 ~DisplayLock() {
108 if (qlock) {
109 qlock->unlock();
110 delete qlock;
111 qlock = 0;
112 }
113 }
114private:
115 QLock *qlock;
116};
117
118QShMemViewProtocol::QShMemViewProtocol(int displayid, const QSize &s,
119 int d, QObject *parent)
120 : QVFbViewProtocol(displayid, parent), hdr(0), dataCache(0), lockId(-1),
121 windowId(0)
122{
123 int w = s.width();