source: pacpusframework/trunk/include/Pacpus/PacpusTools/SharedMemory.h@ 372

Last change on this file since 372 was 312, checked in by Marek Kurdej, 10 years ago

ComponentBase: added addParameter.

File size: 2.9 KB
Line 
1// %pacpus:license{
2// This file is part of the PACPUS framework distributed under the
3// CECILL-C License, Version 1.0.
4// %pacpus:license}
5/// @file
6/// @author Gerald Dherbomez <firstname.surname@utc.fr>
7/// @date January, 2007
8/// @version $Id: ShMem.h 76 2013-01-10 17:05:10Z kurdejma $
9/// @copyright Copyright (c) UTC/CNRS Heudiasyc 2006 - 2013. All rights reserved.
10/// @brief Brief description.
11///
12/// Detailed description.
13
14#ifndef PACPUS_SHARED_MEMORY_H
15#define PACPUS_SHARED_MEMORY_H
16
17#include "PacpusToolsConfig.h"
18#include "ShMemBase.h"
19
20#include <Pacpus/kernel/deprecated.h>
21#include <Pacpus/predef/compiler.h>
22#include <Pacpus/predef/os.h>
23
24#if PACPUS_OS_WINDOWS
25/// Windows handle (opaque pointer) type definition
26typedef void * HANDLE;
27#elif PACPUS_OS_UNIX
28# include <QSharedMemory>
29# include <QSystemSemaphore>
30#endif
31
32#if PACPUS_COMP_MSVC
33# pragma warning(push)
34# pragma warning(disable: 4275)
35#endif // PACPUS_COMP_MSVC
36
37namespace pacpus
38{
39
40/// Shared memory class.
41class /*PACPUSTOOLS_API*/ SharedMemory
42 : public ShMemBase
43{
44public:
45 /// Ctor of shared memory class.
46 ///
47 /// Creates a shared memory of size @b size and named @b name.
48 /// If a shared memory with the name @b name already exists, than
49 /// it will return object pointing to the same memory.
50 /// If this existing memory space has a size smaller than @b size,
51 /// a warning will be issued.
52 ///
53 /// @param name Name of the created shared memory space.
54 /// @param size Size of the created shared memory space in [bytes].
55 SharedMemory(const char* name, int size);
56
57 /// Dtor of shared memory class.
58 virtual ~SharedMemory();
59
60 /// Returns pointer to shared memory
61 virtual void* read();
62 /// Copies a chunk of shared memory to dst buffer
63 virtual void read(void* dst, int size);
64
65 /// Use this method to write data in shared memory. Offset is given in bytes
66 virtual void write(void* data, int size, unsigned long offset = 0);
67
68 /// Use this method to wait the incoming of new data
69 /// you can specify a timeout in ms to avoid infinite blocking or 0 (infinite)
70 /// @returns @b true if new data available before the timeout, @b false otherwise
71 virtual bool wait(unsigned long timeout = 0);
72
73 /// Function that locks access to the shared memory
74 virtual void lockMemory();
75 /// Function that unlocks access to the shared memory
76 virtual void unlockMemory();
77
78 /// Returns event handle on Windows and NULL on Unix.
79 virtual void* getEventIdentifier();
80
81private:
82#if PACPUS_OS_WINDOWS
83 HANDLE semaphore_;
84 HANDLE shMemHandle_;
85 HANDLE event_;
86#elif PACPUS_OS_UNIX
87 QSystemSemaphore* event_;
88 QSharedMemory* memory_;
89#endif
90};
91
92// FIXME: rename references and remove
93PACPUS_DEPRECATED(typedef SharedMemory ShMem);
94
95} // namespace pacpus
96
97#if PACPUS_COMP_MSVC
98# pragma warning(pop)
99#endif // PACPUS_COMP_MSVC
100
101#endif // PACPUS_SHARED_MEMORY_H
Note: See TracBrowser for help on using the repository browser.