root/trunk/libffado/src/libutil/PosixSharedMemory.h

Revision 1172, 2.2 kB (checked in by ppalmers, 15 years ago)

lay down the foundations for easy ALSA/Pulse support

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #ifndef __UTIL_POSIX_SHARED_MEMORY__
25 #define __UTIL_POSIX_SHARED_MEMORY__
26
27 #include "debugmodule/debugmodule.h"
28
29 #include <string>
30
31 namespace Util {
32
33 /**
34  * @brief A POSIX Shared Memory Wrapper.
35  */
36
37 class PosixSharedMemory
38 {
39 public:
40     enum eDirection {
41         eD_None,
42         eD_ReadOnly,
43         eD_WriteOnly,
44         eD_ReadWrite
45     };
46
47     enum eResult {
48         eR_OK,
49         eR_Again,
50         eR_Error,
51     };
52
53 public:
54     PosixSharedMemory(std::string name, unsigned int len);
55     virtual ~PosixSharedMemory();
56    
57     // mlock interface
58     /**
59      * Tries to (un)lock the segment to stay in memory
60      * @param lock
61      * @return
62      */
63     bool LockInMemory(bool lock);
64
65     virtual bool Create(enum eDirection d=eD_ReadWrite);
66     virtual bool Open(enum eDirection d=eD_ReadWrite);
67     virtual bool Close();
68
69     virtual enum eResult Write(unsigned int offset, void * buff, unsigned int len);
70     virtual enum eResult Read(unsigned int offset, void * buff, unsigned int len);
71
72     virtual void* requestBlock(unsigned int offset, unsigned int len);
73     virtual void commitBlock(unsigned int offset, unsigned int len);
74
75     virtual void show();
76     virtual void setVerboseLevel(int l) {setDebugLevel(l);};
77
78 protected:
79     DECLARE_DEBUG_MODULE;
80
81 private:
82     std::string     m_name;
83     unsigned int    m_size;
84     bool            m_owner;
85     char *          m_access;
86 };
87
88 } // namespace Util
89
90 #endif // __UTIL__POSIX_SHARED_MEMORY__
Note: See TracBrowser for help on using the browser.