~ubuntu-branches/ubuntu/quantal/jackd2/quantal

« back to all changes in this revision

Viewing changes to .pc/0000_sync_upstream_VCS.patch/common/JackShmMem.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler, Adrian Knoth, Reinhard Tartler, Jonas Smedegaard
  • Date: 2010-06-19 18:54:29 UTC
  • Revision ID: james.westby@ubuntu.com-20100619185429-zhbhh0mqvukgzx0l
Tags: 1.9.5~dfsg-15
[ Adrian Knoth ]
* Also provide the shlibs file for libjack-jackd2-0
* Fix FTBFS on sparc64 (Closes: #586257)

[ Reinhard Tartler ]
* jackd must not be a virtual package, use 'jack-daemon' for that
* add breaks/replaces on old libjack0
* change shlibsfile to prefer jackd2's libjack
* use conflicts instead of breaks. libjack-jackd2-0 has file conflicts
  with libjack0 and will keep it

[ Jonas Smedegaard ]
* Update control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2001 Paul Davis
 
3
Copyright (C) 2004-2009 Grame
 
4
 
 
5
This program is free software; you can redistribute it and/or modify
 
6
it under the terms of the GNU General Public License as published by
 
7
the Free Software Foundation; either version 2 of the License, or
 
8
(at your option) any later version.
 
9
 
 
10
This program is distributed in the hope that it will be useful,
 
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
GNU General Public License for more details.
 
14
 
 
15
You should have received a copy of the GNU General Public License
 
16
along with this program; if not, write to the Free Software
 
17
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 
 
19
*/
 
20
 
 
21
#ifndef __JackShmMem__
 
22
#define __JackShmMem__
 
23
 
 
24
#include "shm.h"
 
25
#include "JackError.h"
 
26
#include "JackCompilerDeps.h"
 
27
 
 
28
#include <new>  // GCC 4.0
 
29
#include <errno.h>
 
30
#include <stdlib.h>
 
31
 
 
32
#include "JackShmMem_os.h"
 
33
 
 
34
namespace Jack
 
35
{
 
36
 
 
37
SERVER_EXPORT void LockMemoryImp(void* ptr, size_t size);
 
38
SERVER_EXPORT void InitLockMemoryImp(void* ptr, size_t size);
 
39
SERVER_EXPORT void UnlockMemoryImp(void* ptr, size_t size);
 
40
SERVER_EXPORT void LockAllMemory();
 
41
SERVER_EXPORT void UnlockAllMemory();
 
42
 
 
43
class JackMem
 
44
{
 
45
    private:
 
46
 
 
47
        size_t fSize;
 
48
        static size_t gSize;
 
49
 
 
50
    protected:
 
51
    
 
52
        JackMem(): fSize(gSize)
 
53
        {}
 
54
        ~JackMem()
 
55
        {}
 
56
        
 
57
    public:
 
58
 
 
59
        void* operator new(size_t size)
 
60
        {
 
61
            gSize = size;
 
62
            return calloc(1, size);
 
63
        }
 
64
 
 
65
        void operator delete(void* ptr, size_t size)
 
66
        {
 
67
            free(ptr);
 
68
        }
 
69
        
 
70
        void LockMemory()
 
71
        {
 
72
            LockMemoryImp(this, fSize);
 
73
        }
 
74
 
 
75
        void UnlockMemory()
 
76
        {
 
77
            UnlockMemoryImp(this, fSize);
 
78
        }
 
79
 
 
80
};
 
81
 
 
82
/*!
 
83
\brief
 
84
 
 
85
A class which objects possibly want to be allocated in shared memory derives from this class.
 
86
*/
 
87
 
 
88
class JackShmMemAble
 
89
{
 
90
    protected:
 
91
        
 
92
        jack_shm_info_t fInfo;
 
93
        
 
94
    public:
 
95
             
 
96
        void Init();
 
97
 
 
98
        int GetShmIndex()
 
99
        {
 
100
            return fInfo.index;
 
101
        }
 
102
 
 
103
        char* GetShmAddress()
 
104
        {
 
105
            return (char*)fInfo.ptr.attached_at;
 
106
        }
 
107
 
 
108
        void LockMemory()
 
109
        {
 
110
            LockMemoryImp(this, fInfo.size);
 
111
        }
 
112
 
 
113
        void UnlockMemory()
 
114
        {
 
115
            UnlockMemoryImp(this, fInfo.size);
 
116
        }
 
117
 
 
118
};
 
119
 
 
120
/*!
 
121
\brief The base class for shared memory management.
 
122
 
 
123
A class which objects need to be allocated in shared memory derives from this class.
 
124
*/
 
125
 
 
126
class SERVER_EXPORT JackShmMem : public JackShmMemAble
 
127
{
 
128
 
 
129
     protected:
 
130
    
 
131
        JackShmMem();
 
132
        ~JackShmMem();
 
133
  
 
134
    public:
 
135
    
 
136
        void* operator new(size_t size);
 
137
        void* operator new(size_t size, void* memory);
 
138
        
 
139
        void operator delete(void* p, size_t size);
 
140
                void operator delete(void* p);
 
141
   
 
142
};
 
143
 
 
144
/*!
 
145
\brief Pointer on shared memory segment in the client side.
 
146
*/
 
147
 
 
148
template <class T>
 
149
class JackShmReadWritePtr
 
150
{
 
151
 
 
152
    private:
 
153
 
 
154
        jack_shm_info_t fInfo;
 
155
 
 
156
        void Init(int index, const char* server_name = "default")
 
157
        {
 
158
            if (fInfo.index < 0 && index >= 0) {
 
159
                jack_log("JackShmReadWritePtr::Init %ld %ld", index, fInfo.index);
 
160
                if (jack_initialize_shm(server_name) < 0)
 
161
                    throw - 1;
 
162
                fInfo.index = index;
 
163
                if (jack_attach_shm(&fInfo)) {
 
164
                    throw - 2;
 
165
                }
 
166
                GetShmAddress()->LockMemory();
 
167
            }
 
168
        }
 
169
 
 
170
    public:
 
171
 
 
172
        JackShmReadWritePtr()
 
173
        {
 
174
            fInfo.index = -1;
 
175
            fInfo.ptr.attached_at = (char*)NULL;
 
176
        }
 
177
 
 
178
        JackShmReadWritePtr(int index, const char* server_name)
 
179
        {
 
180
            Init(index, server_name);
 
181
        }
 
182
 
 
183
        ~JackShmReadWritePtr()
 
184
        {
 
185
            if (fInfo.index >= 0) {
 
186
                jack_log("JackShmReadWritePtr::~JackShmReadWritePtr %ld", fInfo.index);
 
187
                GetShmAddress()->UnlockMemory();
 
188
                jack_release_shm(&fInfo);
 
189
                fInfo.index = -1;
 
190
             }
 
191
        }
 
192
 
 
193
        T* operator->() const
 
194
        {
 
195
            return (T*)fInfo.ptr.attached_at;
 
196
        }
 
197
 
 
198
        operator T*() const
 
199
        {
 
200
            return (T*)fInfo.ptr.attached_at;
 
201
        }
 
202
 
 
203
        JackShmReadWritePtr& operator=(int index)
 
204
        {
 
205
            Init(index);
 
206
            return *this;
 
207
        }
 
208
 
 
209
        void SetShmIndex(int index, const char* server_name)
 
210
        {
 
211
            Init(index, server_name);
 
212
        }
 
213
 
 
214
        int GetShmIndex()
 
215
        {
 
216
            return fInfo.index;
 
217
        }
 
218
 
 
219
        T* GetShmAddress()
 
220
        {
 
221
            return (T*)fInfo.ptr.attached_at;
 
222
        }
 
223
};
 
224
 
 
225
/*!
 
226
\brief Pointer on shared memory segment in the client side: destroy the segment (used client control)
 
227
*/
 
228
 
 
229
template <class T>
 
230
class JackShmReadWritePtr1
 
231
{
 
232
 
 
233
    private:
 
234
 
 
235
        jack_shm_info_t fInfo;
 
236
 
 
237
        void Init(int index, const char* server_name = "default")
 
238
        {
 
239
            if (fInfo.index < 0 && index >= 0) {
 
240
                jack_log("JackShmReadWritePtr1::Init %ld %ld", index, fInfo.index);
 
241
                if (jack_initialize_shm(server_name) < 0)
 
242
                    throw - 1;
 
243
                fInfo.index = index;
 
244
                if (jack_attach_shm(&fInfo)) {
 
245
                    throw - 2;
 
246
                }
 
247
                /*
 
248
                nobody else needs to access this shared memory any more, so
 
249
                destroy it. because we have our own attachment to it, it won't
 
250
                vanish till we exit (and release it).
 
251
                */
 
252
                jack_destroy_shm(&fInfo);
 
253
                GetShmAddress()->LockMemory();
 
254
            }
 
255
        }
 
256
 
 
257
    public:
 
258
 
 
259
        JackShmReadWritePtr1()
 
260
        {
 
261
            fInfo.index = -1;
 
262
            fInfo.ptr.attached_at = NULL;
 
263
        }
 
264
 
 
265
        JackShmReadWritePtr1(int index, const char* server_name)
 
266
        {
 
267
            Init(index, server_name);
 
268
        }
 
269
 
 
270
        ~JackShmReadWritePtr1()
 
271
        {
 
272
            if (fInfo.index >= 0) {
 
273
                jack_log("JackShmReadWritePtr1::~JackShmReadWritePtr1 %ld", fInfo.index);
 
274
                GetShmAddress()->UnlockMemory();
 
275
                jack_release_shm(&fInfo);
 
276
                fInfo.index = -1;
 
277
            }
 
278
        }
 
279
 
 
280
        T* operator->() const
 
281
        {
 
282
            return (T*)fInfo.ptr.attached_at;
 
283
        }
 
284
 
 
285
        operator T*() const
 
286
        {
 
287
            return (T*)fInfo.ptr.attached_at;
 
288
        }
 
289
 
 
290
        JackShmReadWritePtr1& operator=(int index)
 
291
        {
 
292
            Init(index);
 
293
            return *this;
 
294
        }
 
295
 
 
296
        void SetShmIndex(int index, const char* server_name)
 
297
        {
 
298
            Init(index, server_name);
 
299
        }
 
300
 
 
301
        int GetShmIndex()
 
302
        {
 
303
            return fInfo.index;
 
304
        }
 
305
 
 
306
        T* GetShmAddress()
 
307
        {
 
308
            return (T*)fInfo.ptr.attached_at;
 
309
        }
 
310
};
 
311
 
 
312
/*!
 
313
\brief Pointer on shared memory segment in the client side.
 
314
*/
 
315
 
 
316
template <class T>
 
317
class JackShmReadPtr
 
318
{
 
319
 
 
320
    private:
 
321
 
 
322
        jack_shm_info_t fInfo;
 
323
 
 
324
        void Init(int index, const char* server_name = "default")
 
325
        {
 
326
            if (fInfo.index < 0 && index >= 0) {
 
327
                jack_log("JackShmPtrRead::Init %ld %ld", index, fInfo.index);
 
328
                if (jack_initialize_shm(server_name) < 0)
 
329
                    throw - 1;
 
330
                fInfo.index = index;
 
331
                if (jack_attach_shm_read(&fInfo)) {
 
332
                    throw - 2;
 
333
                }
 
334
                GetShmAddress()->LockMemory();
 
335
            }
 
336
        }
 
337
 
 
338
    public:
 
339
 
 
340
        JackShmReadPtr()
 
341
        {
 
342
            fInfo.index = -1;
 
343
            fInfo.ptr.attached_at = NULL;
 
344
        }
 
345
 
 
346
        JackShmReadPtr(int index, const char* server_name)
 
347
        {
 
348
            Init(index, server_name);
 
349
        }
 
350
 
 
351
        ~JackShmReadPtr()
 
352
        {
 
353
            if (fInfo.index >= 0) {
 
354
                jack_log("JackShmPtrRead::~JackShmPtrRead %ld", fInfo.index);
 
355
                GetShmAddress()->UnlockMemory();
 
356
                jack_release_shm(&fInfo);
 
357
                fInfo.index = -1;
 
358
            }
 
359
        }
 
360
 
 
361
        T* operator->() const
 
362
        {
 
363
            return (T*)fInfo.ptr.attached_at;
 
364
        }
 
365
 
 
366
        operator T*() const
 
367
        {
 
368
            return (T*)fInfo.ptr.attached_at;
 
369
        }
 
370
 
 
371
        JackShmReadPtr& operator=(int index)
 
372
        {
 
373
            Init(index);
 
374
            return *this;
 
375
        }
 
376
 
 
377
        void SetShmIndex(int index, const char* server_name)
 
378
        {
 
379
            Init(index, server_name);
 
380
        }
 
381
 
 
382
        int GetShmIndex()
 
383
        {
 
384
            return fInfo.index;
 
385
        }
 
386
 
 
387
        T* GetShmAddress()
 
388
        {
 
389
            return (T*)fInfo.ptr.attached_at;
 
390
        }
 
391
 
 
392
};
 
393
 
 
394
} // end of namespace
 
395
 
 
396
#endif