115 } |
116 } |
116 } |
117 } |
117 |
118 |
118 static unsigned long __debug_tick; |
119 static unsigned long __debug_tick; |
119 |
120 |
120 #define _LogAndReturnNull(text) \ |
121 #define _Log(text, err) \ |
121 {\ |
122 {\ |
122 char mstr[256] = text " for ";\ |
123 char mstr[256];\ |
123 strncat(mstr, name, 255);\ |
124 snprintf(mstr, 255, text " for %s (%d)", name, err);\ |
124 LogMessage(LOG_CRITICAL, mstr, strlen(mstr));\ |
125 LogMessage(LOG_CRITICAL, mstr, strlen(mstr));\ |
125 return NULL;\ |
|
126 } |
126 } |
127 |
127 |
128 void *create_RT_to_nRT_signal(char* name){ |
128 void *create_RT_to_nRT_signal(char* name){ |
129 int new_index = -1; |
129 int new_index = -1; |
|
130 int ret; |
130 RT_to_nRT_signal_t *sig; |
131 RT_to_nRT_signal_t *sig; |
131 char pipe_dev[64]; |
132 char pipe_dev[64]; |
132 |
133 |
133 /* find a free slot */ |
134 /* find a free slot */ |
134 for(int i=0; i < max_RT_to_nRT_signals; i++){ |
135 for(int i=0; i < max_RT_to_nRT_signals; i++){ |
139 } |
140 } |
140 } |
141 } |
141 |
142 |
142 /* fail if none found */ |
143 /* fail if none found */ |
143 if(new_index == -1) { |
144 if(new_index == -1) { |
144 _LogAndReturnNull("Maximum count of RT-PIPE reached while creating pipe"); |
145 _Log("Maximum count of RT-PIPE reached while creating pipe", max_RT_to_nRT_signals); |
|
146 return NULL; |
145 } |
147 } |
146 |
148 |
147 /* create rt pipe */ |
149 /* create rt pipe */ |
148 if(rt_pipe_create(&sig->pipe, name, new_index, PIPE_SIZE) < 0){ |
150 if(ret = rt_pipe_create(&sig->pipe, name, new_index, PIPE_SIZE) < 0){ |
149 _LogAndReturnNull("Failed opening real-time end of RT-PIPE"); |
151 _Log("Failed opening real-time end of RT-PIPE", ret); |
|
152 return NULL; |
150 } |
153 } |
151 |
154 |
152 /* open pipe's userland */ |
155 /* open pipe's userland */ |
153 snprintf(pipe_dev, 64, "/dev/rtp%d", new_index); |
156 snprintf(pipe_dev, 63, "/dev/rtp%d", new_index); |
154 if((sig->pipe_fd = open(pipe_dev, O_RDWR)) == -1){ |
157 if((sig->pipe_fd = open(pipe_dev, O_RDWR)) == -1){ |
155 rt_pipe_delete(&sig->pipe); |
158 rt_pipe_delete(&sig->pipe); |
156 _LogAndReturnNull("Failed opening non-real-time end of RT-PIPE"); |
159 _Log("Failed opening non-real-time end of RT-PIPE", errno); |
|
160 return NULL; |
157 } |
161 } |
158 |
162 |
159 sig->used = 1; |
163 sig->used = 1; |
160 sig->name = name; |
164 sig->name = name; |
161 |
165 |
162 return sig; |
166 return sig; |
163 } |
167 } |
164 |
168 |
165 void delete_RT_to_nRT_signal(void* handle){ |
169 void delete_RT_to_nRT_signal(void* handle){ |
|
170 int ret; |
166 RT_to_nRT_signal_t *sig = (RT_to_nRT_signal_t*)handle; |
171 RT_to_nRT_signal_t *sig = (RT_to_nRT_signal_t*)handle; |
|
172 char *name = sig->name; |
167 |
173 |
168 if(!sig->used) return; |
174 if(!sig->used) return; |
169 |
175 |
170 rt_pipe_delete(&sig->pipe); |
176 if(ret = rt_pipe_delete(&sig->pipe) != 0){ |
171 |
177 _Log("Failed closing real-time end of RT-PIPE", ret); |
172 close(sig->pipe_fd); |
178 } |
|
179 |
|
180 if(close(sig->pipe_fd) != 0){ |
|
181 _Log("Failed closing non-real-time end of RT-PIPE", errno); |
|
182 } |
173 |
183 |
174 sig->used = 0; |
184 sig->used = 0; |
175 } |
185 } |
176 |
186 |
177 int wait_RT_to_nRT_signal(void* handle){ |
187 int wait_RT_to_nRT_signal(void* handle){ |