Add zalsa configure flag, enabled by default if possible
[jack2.git] / android / Shm.h
blob6c8ecb43c0dee137d843a847f9be0e0fc57ed3df
1 /*
2 Copyright (C) 2001-2003 Paul Davis
3 Copyright (C) 2005-2012 Grame
4 Copyright (C) 2013 Samsung Electronics
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifndef __jack_shm_android_h__
23 #define __jack_shm_android_h__
25 #include <limits.h>
26 #include <sys/types.h>
27 #include "types.h"
28 #include "JackCompilerDeps.h"
29 #include <binder/MemoryHeapBase.h>
30 #include <utils/RefBase.h>
32 #ifdef __cplusplus
33 extern "C"
35 #endif
37 #define JACK_SHM_REGISTRY_FD -1
38 #define JACK_SHM_HEAP_ENOUGH_COUNT 300
40 void jack_instantiate();
42 #ifdef __cplusplus
44 #endif
46 namespace android {
48 class IAndroidShm;
50 class Shm {
51 public:
52 static Shm* Instantiate();
53 virtual ~Shm();
54 private:
55 Shm();
56 Shm( const Shm&);
57 Shm& operator=(const Shm);
59 private:
60 void set_server_prefix (const char *server_name);
61 int server_initialize_shm (int new_registry);
62 int shm_lock_registry (void);
63 void shm_unlock_registry (void);
64 int access_registry (jack_shm_info_t *ri);
65 void remove_shm (jack_shm_id_t *id);
66 int create_registry (jack_shm_info_t *ri);
67 int shm_validate_registry ();
68 int GetUID();
69 int GetPID();
70 void shm_init_registry ();
71 void release_shm_entry (jack_shm_registry_index_t index);
72 jack_shm_registry_t * get_free_shm_info ();
74 public:
75 static void jack_shm_copy_from_registry (jack_shm_info_t*, jack_shm_registry_index_t);
76 static void jack_shm_copy_to_registry (jack_shm_info_t*, jack_shm_registry_index_t*);
77 static int jack_release_shm_info (jack_shm_registry_index_t);
78 static char* jack_shm_addr (jack_shm_info_t* si);
79 static int jack_register_server (const char *server_name, int new_registry);
80 static int jack_unregister_server (const char *server_name);
81 static int jack_initialize_shm (const char *server_name);
82 static int jack_initialize_shm_server (void);
83 static int jack_initialize_shm_client (void);
84 static int jack_cleanup_shm (void);
85 static int jack_shmalloc (const char *shm_name, jack_shmsize_t size, jack_shm_info_t* result);
86 static void jack_release_shm (jack_shm_info_t*);
87 static void jack_release_lib_shm (jack_shm_info_t*);
88 static void jack_destroy_shm (jack_shm_info_t*);
89 static int jack_attach_shm (jack_shm_info_t*);
90 static int jack_attach_lib_shm (jack_shm_info_t*);
91 static int jack_attach_shm_read (jack_shm_info_t*);
92 static int jack_attach_lib_shm_read (jack_shm_info_t*);
93 static int jack_resize_shm (jack_shm_info_t*, jack_shmsize_t size);
95 public:
96 void shm_copy_from_registry (jack_shm_info_t*, jack_shm_registry_index_t);
97 void shm_copy_to_registry (jack_shm_info_t*, jack_shm_registry_index_t*);
98 int release_shm_info (jack_shm_registry_index_t);
99 char* shm_addr (unsigned int fd);
101 // here begin the API
102 int register_server (const char *server_name, int new_registry);
103 int unregister_server (const char *server_name);
105 int initialize_shm (const char *server_name);
106 int initialize_shm_server (void);
107 int initialize_shm_client (void);
108 int cleanup_shm (void);
110 int shmalloc (const char *shm_name, jack_shmsize_t size, jack_shm_info_t* result);
111 void release_shm (jack_shm_info_t*);
112 void release_lib_shm (jack_shm_info_t*);
113 void destroy_shm (jack_shm_info_t*);
114 int attach_shm (jack_shm_info_t*);
115 int attach_lib_shm (jack_shm_info_t*);
116 int attach_shm_read (jack_shm_info_t*);
117 int attach_lib_shm_read (jack_shm_info_t*);
118 int resize_shm (jack_shm_info_t*, jack_shmsize_t size);
120 private:
121 static jack_shmtype_t jack_shmtype;
122 static jack_shm_id_t registry_id;
123 static jack_shm_fd_t registry_fd;
124 static jack_shm_info_t registry_info;
125 static jack_shm_header_t *jack_shm_header;
126 static jack_shm_registry_t *jack_shm_registry;
127 static char jack_shm_server_prefix[JACK_SERVER_NAME_SIZE+1];
128 static int semid;
129 static pthread_mutex_t mutex;
130 static Shm* ref;
132 void jack_release_shm_entry (jack_shm_registry_index_t index);
133 int jack_shm_lock_registry (void);
134 void jack_shm_unlock_registry (void);
136 //static sp<IAndroidShm> mShmService;
137 static sp<IMemoryHeap> mShmMemBase[JACK_SHM_HEAP_ENOUGH_COUNT];
139 public:
140 static sp<IAndroidShm> getShmService();
144 #endif /* __jack_shm_android_h__ */