CustusX  22.04-rc5
An IGT application
cxSharedMemory.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #ifndef CXSHAREDMEMORY_H_
13 #define CXSHAREDMEMORY_H_
14 
15 #include "cxResourceExport.h"
16 
17 #include <QSharedMemory>
18 #include <QDateTime>
19 
20 namespace cx
21 {
22 
28 
40 class cxResource_EXPORT SharedMemoryServer
41 {
42 private:
43  QSharedMemory mBuffer;
44  int mSize;
45  int mBuffers;
46  int mCurrentBuffer;
47  QDateTime mLastTimestamp;
48 
49 public:
59  SharedMemoryServer(QString key, int buffers, int sizeEach, QObject *parent = 0);
61  int size() { return mSize; }
62  int buffers() { return mBuffers; }
63  QString key() { return mBuffer.key(); }
64  void *buffer();
65  void release();
66 
69  QDateTime lastTimestamp() { return mLastTimestamp; }
73  bool hasBuffer() { return mCurrentBuffer != -1; }
74 private:
75  void internalRelease(bool lock);
76 };
77 
84 class cxResource_EXPORT SharedMemoryClient
85 {
86 private:
87  QSharedMemory mBuffer;
88  int mSize;
89  int mBuffers;
90  int mCurrentBuffer;
91  QDateTime mTimestamp;
92 
93 public:
94  SharedMemoryClient(QObject *parent = 0);
96  bool attach(const QString &key);
97  bool detach();
98  int size() { return mSize; }
99  int buffers() { return mBuffers; }
100  QString key() { return mBuffer.key(); }
101  const void *buffer(bool onlyNew=false);
102  void release();
103  const void *isNew();
104  QDateTime timestamp() { return mTimestamp; }
105 };
106 
107 }
108 
109 #endif
Shared Memory Server.
Shared Memory Client.
Namespace for all CustusX production code.