diff options
Diffstat (limited to 'toxav/msi.c')
-rw-r--r-- | toxav/msi.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/toxav/msi.c b/toxav/msi.c index e21ec948..29e053ec 100644 --- a/toxav/msi.c +++ b/toxav/msi.c | |||
@@ -99,9 +99,9 @@ void handle_msi_packet ( Messenger *m, int friend_id, const uint8_t *data, uint1 | |||
99 | */ | 99 | */ |
100 | void msi_register_callback ( MSISession *session, MSICallbackType callback, MSICallbackID id) | 100 | void msi_register_callback ( MSISession *session, MSICallbackType callback, MSICallbackID id) |
101 | { | 101 | { |
102 | pthread_mutex_lock(session->mutex); | 102 | LOGGED_LOCK(session->mutex); |
103 | session->callbacks[id] = callback; | 103 | session->callbacks[id] = callback; |
104 | pthread_mutex_unlock(session->mutex); | 104 | LOGGED_UNLOCK(session->mutex); |
105 | } | 105 | } |
106 | MSISession *msi_new ( Messenger *messenger ) | 106 | MSISession *msi_new ( Messenger *messenger ) |
107 | { | 107 | { |
@@ -141,7 +141,7 @@ int msi_kill ( MSISession *session ) | |||
141 | } | 141 | } |
142 | 142 | ||
143 | m_callback_msi_packet((struct Messenger *) session->messenger, NULL, NULL); | 143 | m_callback_msi_packet((struct Messenger *) session->messenger, NULL, NULL); |
144 | pthread_mutex_lock(session->mutex); | 144 | LOGGED_LOCK(session->mutex); |
145 | 145 | ||
146 | if (session->calls) { | 146 | if (session->calls) { |
147 | MSIMessage msg; | 147 | MSIMessage msg; |
@@ -154,7 +154,7 @@ int msi_kill ( MSISession *session ) | |||
154 | } | 154 | } |
155 | } | 155 | } |
156 | 156 | ||
157 | pthread_mutex_unlock(session->mutex); | 157 | LOGGED_UNLOCK(session->mutex); |
158 | pthread_mutex_destroy(session->mutex); | 158 | pthread_mutex_destroy(session->mutex); |
159 | 159 | ||
160 | LOGGER_DEBUG("Terminated session: %p", session); | 160 | LOGGER_DEBUG("Terminated session: %p", session); |
@@ -165,17 +165,17 @@ int msi_invite ( MSISession *session, MSICall **call, uint32_t friend_id, uint8_ | |||
165 | { | 165 | { |
166 | LOGGER_DEBUG("Session: %p Inviting friend: %u", session, friend_id); | 166 | LOGGER_DEBUG("Session: %p Inviting friend: %u", session, friend_id); |
167 | 167 | ||
168 | pthread_mutex_lock(session->mutex); | 168 | LOGGED_LOCK(session->mutex); |
169 | if (get_call(session, friend_id) != NULL) { | 169 | if (get_call(session, friend_id) != NULL) { |
170 | LOGGER_ERROR("Already in a call"); | 170 | LOGGER_ERROR("Already in a call"); |
171 | pthread_mutex_unlock(session->mutex); | 171 | LOGGED_UNLOCK(session->mutex); |
172 | return -1; | 172 | return -1; |
173 | } | 173 | } |
174 | 174 | ||
175 | (*call) = new_call ( session, friend_id ); | 175 | (*call) = new_call ( session, friend_id ); |
176 | 176 | ||
177 | if ( *call == NULL ) { | 177 | if ( *call == NULL ) { |
178 | pthread_mutex_unlock(session->mutex); | 178 | LOGGED_UNLOCK(session->mutex); |
179 | return -1; | 179 | return -1; |
180 | } | 180 | } |
181 | 181 | ||
@@ -195,7 +195,7 @@ int msi_invite ( MSISession *session, MSICall **call, uint32_t friend_id, uint8_ | |||
195 | (*call)->state = msi_CallRequesting; | 195 | (*call)->state = msi_CallRequesting; |
196 | 196 | ||
197 | LOGGER_DEBUG("Invite sent"); | 197 | LOGGER_DEBUG("Invite sent"); |
198 | pthread_mutex_unlock(session->mutex); | 198 | LOGGED_UNLOCK(session->mutex); |
199 | return 0; | 199 | return 0; |
200 | } | 200 | } |
201 | int msi_hangup ( MSICall* call ) | 201 | int msi_hangup ( MSICall* call ) |
@@ -203,7 +203,7 @@ int msi_hangup ( MSICall* call ) | |||
203 | LOGGER_DEBUG("Session: %p Hanging up call with friend: %u", call->session, call->friend_id); | 203 | LOGGER_DEBUG("Session: %p Hanging up call with friend: %u", call->session, call->friend_id); |
204 | 204 | ||
205 | MSISession* session = call->session; | 205 | MSISession* session = call->session; |
206 | pthread_mutex_lock(session->mutex); | 206 | LOGGED_LOCK(session->mutex); |
207 | 207 | ||
208 | MSIMessage msg; | 208 | MSIMessage msg; |
209 | msg_init(&msg, requ_pop); | 209 | msg_init(&msg, requ_pop); |
@@ -211,7 +211,7 @@ int msi_hangup ( MSICall* call ) | |||
211 | send_message ( session->messenger, call->friend_id, &msg ); | 211 | send_message ( session->messenger, call->friend_id, &msg ); |
212 | 212 | ||
213 | kill_call(call); | 213 | kill_call(call); |
214 | pthread_mutex_unlock(session->mutex); | 214 | LOGGED_UNLOCK(session->mutex); |
215 | return 0; | 215 | return 0; |
216 | } | 216 | } |
217 | int msi_answer ( MSICall* call, uint8_t capabilities ) | 217 | int msi_answer ( MSICall* call, uint8_t capabilities ) |
@@ -219,13 +219,13 @@ int msi_answer ( MSICall* call, uint8_t capabilities ) | |||
219 | LOGGER_DEBUG("Session: %p Answering call from: %u", call->session, call->friend_id); | 219 | LOGGER_DEBUG("Session: %p Answering call from: %u", call->session, call->friend_id); |
220 | 220 | ||
221 | MSISession* session = call->session; | 221 | MSISession* session = call->session; |
222 | pthread_mutex_lock(session->mutex); | 222 | LOGGED_LOCK(session->mutex); |
223 | 223 | ||
224 | if ( call->state != msi_CallRequested ) { | 224 | if ( call->state != msi_CallRequested ) { |
225 | /* Though sending in invalid state will not cause anything wierd | 225 | /* Though sending in invalid state will not cause anything wierd |
226 | * Its better to not do it like a maniac */ | 226 | * Its better to not do it like a maniac */ |
227 | LOGGER_ERROR("Call is in invalid state!"); | 227 | LOGGER_ERROR("Call is in invalid state!"); |
228 | pthread_mutex_unlock(session->mutex); | 228 | LOGGED_UNLOCK(session->mutex); |
229 | return -1; | 229 | return -1; |
230 | } | 230 | } |
231 | 231 | ||
@@ -243,7 +243,7 @@ int msi_answer ( MSICall* call, uint8_t capabilities ) | |||
243 | send_message ( session->messenger, call->friend_id, &msg ); | 243 | send_message ( session->messenger, call->friend_id, &msg ); |
244 | 244 | ||
245 | call->state = msi_CallActive; | 245 | call->state = msi_CallActive; |
246 | pthread_mutex_unlock(session->mutex); | 246 | LOGGED_UNLOCK(session->mutex); |
247 | 247 | ||
248 | return 0; | 248 | return 0; |
249 | } | 249 | } |
@@ -252,7 +252,7 @@ int msi_change_capabilities( MSICall* call, uint8_t capabilities ) | |||
252 | LOGGER_DEBUG("Session: %p Trying to change capabilities to friend %u", call->session, call->friend_id); | 252 | LOGGER_DEBUG("Session: %p Trying to change capabilities to friend %u", call->session, call->friend_id); |
253 | 253 | ||
254 | MSISession* session = call->session; | 254 | MSISession* session = call->session; |
255 | pthread_mutex_lock(session->mutex); | 255 | LOGGED_LOCK(session->mutex); |
256 | 256 | ||
257 | if ( call->state != msi_CallActive ) { | 257 | if ( call->state != msi_CallActive ) { |
258 | /* Sending capabilities change can cause error on other side if | 258 | /* Sending capabilities change can cause error on other side if |
@@ -263,7 +263,7 @@ int msi_change_capabilities( MSICall* call, uint8_t capabilities ) | |||
263 | * like new. TODO: explain this better | 263 | * like new. TODO: explain this better |
264 | */ | 264 | */ |
265 | LOGGER_ERROR("Call is in invalid state!"); | 265 | LOGGER_ERROR("Call is in invalid state!"); |
266 | pthread_mutex_unlock(session->mutex); | 266 | LOGGED_UNLOCK(session->mutex); |
267 | return -1; | 267 | return -1; |
268 | } | 268 | } |
269 | 269 | ||
@@ -277,7 +277,7 @@ int msi_change_capabilities( MSICall* call, uint8_t capabilities ) | |||
277 | 277 | ||
278 | send_message ( call->session->messenger, call->friend_id, &msg ); | 278 | send_message ( call->session->messenger, call->friend_id, &msg ); |
279 | 279 | ||
280 | pthread_mutex_unlock(session->mutex); | 280 | LOGGED_UNLOCK(session->mutex); |
281 | return 0; | 281 | return 0; |
282 | } | 282 | } |
283 | 283 | ||
@@ -581,17 +581,17 @@ void on_peer_status(Messenger *m, int friend_id, uint8_t status, void *data) | |||
581 | case 0: { /* Friend is now offline */ | 581 | case 0: { /* Friend is now offline */ |
582 | LOGGER_DEBUG("Friend %d is now offline", friend_id); | 582 | LOGGER_DEBUG("Friend %d is now offline", friend_id); |
583 | 583 | ||
584 | pthread_mutex_lock(session->mutex); | 584 | LOGGED_LOCK(session->mutex); |
585 | MSICall* call = get_call(session, friend_id); | 585 | MSICall* call = get_call(session, friend_id); |
586 | 586 | ||
587 | if (call == NULL) { | 587 | if (call == NULL) { |
588 | pthread_mutex_unlock(session->mutex); | 588 | LOGGED_UNLOCK(session->mutex); |
589 | return; | 589 | return; |
590 | } | 590 | } |
591 | 591 | ||
592 | invoke_callback(call, msi_OnPeerTimeout); /* Failure is ignored */ | 592 | invoke_callback(call, msi_OnPeerTimeout); /* Failure is ignored */ |
593 | kill_call(call); | 593 | kill_call(call); |
594 | pthread_mutex_unlock(session->mutex); | 594 | LOGGED_UNLOCK(session->mutex); |
595 | } | 595 | } |
596 | break; | 596 | break; |
597 | 597 | ||
@@ -759,20 +759,20 @@ void handle_msi_packet ( Messenger *m, int friend_id, const uint8_t *data, uint1 | |||
759 | LOGGER_DEBUG("Successfully parsed message"); | 759 | LOGGER_DEBUG("Successfully parsed message"); |
760 | } | 760 | } |
761 | 761 | ||
762 | pthread_mutex_lock(session->mutex); | 762 | LOGGED_LOCK(session->mutex); |
763 | MSICall *call = get_call(session, friend_id); | 763 | MSICall *call = get_call(session, friend_id); |
764 | 764 | ||
765 | if (call == NULL) { | 765 | if (call == NULL) { |
766 | if (msg.request.value != requ_push) { | 766 | if (msg.request.value != requ_push) { |
767 | send_error(m, friend_id, msi_EStrayMessage); | 767 | send_error(m, friend_id, msi_EStrayMessage); |
768 | pthread_mutex_unlock(session->mutex); | 768 | LOGGED_UNLOCK(session->mutex); |
769 | return; | 769 | return; |
770 | } | 770 | } |
771 | 771 | ||
772 | call = new_call(session, friend_id); | 772 | call = new_call(session, friend_id); |
773 | if (call == NULL) { | 773 | if (call == NULL) { |
774 | send_error(m, friend_id, msi_ESystem); | 774 | send_error(m, friend_id, msi_ESystem); |
775 | pthread_mutex_unlock(session->mutex); | 775 | LOGGED_UNLOCK(session->mutex); |
776 | return; | 776 | return; |
777 | } | 777 | } |
778 | } | 778 | } |
@@ -782,5 +782,5 @@ void handle_msi_packet ( Messenger *m, int friend_id, const uint8_t *data, uint1 | |||
782 | else | 782 | else |
783 | handle_pop(call, &msg); /* always kills the call */ | 783 | handle_pop(call, &msg); /* always kills the call */ |
784 | 784 | ||
785 | pthread_mutex_unlock(session->mutex); | 785 | LOGGED_UNLOCK(session->mutex); |
786 | } | 786 | } |