source: flair-src/trunk/lib/FlairCore/src/SharedMem.h@ 173

Last change on this file since 173 was 149, checked in by Bayard Gildas, 8 years ago

SharedMem in producerConsumer mode

File size: 1.6 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5/*!
6 * \file SharedMem.h
7 * \brief Class defining a shared memory
8 * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
9 * \date 2014/02/10
10 * \version 4.0
11 */
12
13#ifndef SHAREDMEM_H
14#define SHAREDMEM_H
15
16#include <Object.h>
17#include <semaphore.h>
18
19class SharedMem_impl;
20
21namespace flair {
22namespace core {
23
24/*! \class SharedMem
25*
26* \brief Class defining a shared memory
27*
28* Shared memory is identified by its name so it can be accessed
29* by another processus using its name.
30*/
31
32class SharedMem : public Object {
33public:
34 enum class Type { mutex, producerConsumer };
35 /*!
36 * \brief Constructor
37 *
38 * Construct a shared memory object
39 *
40 * \param parent parent
41 * \param name name
42 * \param size size of the shared memory
43 * \param blockOnRead if true reading will block if nothing written
44 */
45 SharedMem(const Object *parent, std::string name, size_t size, Type type=Type::mutex);
46
47 /*!
48 * \brief Destructor
49 *
50 */
51 ~SharedMem();
52
53 /*!
54 * \brief Write
55 *
56 * \param buf input buffer to write to memory
57 * \param size buffer size
58 */
59 void Write(const char *buf, size_t size);
60
61 /*!
62 * \brief Read
63 *
64 * \param buf output buffer to write from memory
65 * \param size buffer size
66 */
67 void Read(char *buf, size_t size) const;
68
69
70 /*!
71 * \brief This function should be called when reader starts (in case of a SharedMem of type producerConsumer)
72 */
73 void ReaderReady();
74private:
75 SharedMem_impl *pimpl_;
76 Type type;
77};
78
79} // end namespace core
80} // end namespace flair
81
82#endif // SHAREDMEM_H
Note: See TracBrowser for help on using the repository browser.