Skip to content

Commit

Permalink
Clean up native dbus interface files and associated changes to existi…
Browse files Browse the repository at this point in the history
…ng files.
  • Loading branch information
mikebrady committed Mar 20, 2018
1 parent c0b1dc5 commit d692fab
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 131 deletions.
21 changes: 10 additions & 11 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,24 +984,23 @@ void memory_barrier() {
pthread_mutex_unlock(&barrier_mutex);
}

int ss_pthread_mutex_timedlock(pthread_mutex_t *mutex, useconds_t dally_time, const char * debugmessage, int debuglevel) {
int ss_pthread_mutex_timedlock(pthread_mutex_t *mutex, useconds_t dally_time,
const char *debugmessage, int debuglevel) {

int time_to_wait = dally_time;
int r = pthread_mutex_trylock(mutex);
while ((r) && (time_to_wait>0)) {
while ((r) && (time_to_wait > 0)) {
int st = time_to_wait;
if (st>20000)
st=20000;
if (st > 20000)
st = 20000;
usleep(st);
time_to_wait -= st;
time_to_wait -= st;
r = pthread_mutex_trylock(mutex);
}
if (r!=0) {
if (r != 0) {
char errstr[1000];
debug(debuglevel,"error %d: \"%s\" waiting for a mutex: \"%s\".",r,strerror_r(r,errstr,sizeof(errstr)),debugmessage);
}
debug(debuglevel, "error %d: \"%s\" waiting for a mutex: \"%s\".", r,
strerror_r(r, errstr, sizeof(errstr)), debugmessage);
}
return r;
}



6 changes: 3 additions & 3 deletions common.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef _COMMON_H
#define _COMMON_H

#include <unistd.h>
#include <libconfig.h>
#include <signal.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <unistd.h>

#include "audio.h"
#include "config.h"
Expand Down Expand Up @@ -181,7 +181,6 @@ typedef struct {
uint32_t nctohl(const uint8_t *p); // read 4 characters from the p and do ntohl on them
void memory_barrier();


// true if Shairport Sync is supposed to be sending output to the output device, false otherwise

int get_requested_connection_state_to_output();
Expand Down Expand Up @@ -252,6 +251,7 @@ void shairport_shutdown();
extern sigset_t pselect_sigset;

// wait for the specified time in microseconds -- it checks every 20 milliseconds
int ss_pthread_mutex_timedlock(pthread_mutex_t *mutex, useconds_t dally_time, const char * debugmessage, int debuglevel);
int ss_pthread_mutex_timedlock(pthread_mutex_t *mutex, useconds_t dally_time,
const char *debugmessage, int debuglevel);

#endif // _COMMON_H
37 changes: 23 additions & 14 deletions dacp.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@
#include "tinyhttp/http.h"

typedef struct {
int players_connection_thread_index; // the connection thread index when a player thread is associated with this, zero otherwise
int scan_enable; // set to 1 if if sacanning should be considered
uint16_t port; // zero if no port discovered
short connection_family; // AF_INET6 or AF_INET
uint32_t scope_id; // if it's an ipv6 connection, this will be its scope id
char ip_string[INET6_ADDRSTRLEN]; // the ip string pointing to the client
uint32_t active_remote_id; // send this when you want to send remote control commands
int players_connection_thread_index; // the connection thread index when a player thread is
// associated with this, zero otherwise
int scan_enable; // set to 1 if if sacanning should be considered
uint16_t port; // zero if no port discovered
short connection_family; // AF_INET6 or AF_INET
uint32_t scope_id; // if it's an ipv6 connection, this will be its scope id
char ip_string[INET6_ADDRSTRLEN]; // the ip string pointing to the client
uint32_t active_remote_id; // send this when you want to send remote control commands
} dacp_server_record;

pthread_t dacp_monitor_thread;
Expand Down Expand Up @@ -158,7 +159,7 @@ int dacp_send_command(const char *command, char **body, ssize_t *bodysize) {

// only do this one at a time -- not sure it is necessary, but better safe than sorry

int mutex_reply = ss_pthread_mutex_timedlock(&dacp_conversation_lock,1000000,command,1);
int mutex_reply = ss_pthread_mutex_timedlock(&dacp_conversation_lock, 1000000, command, 1);
if (mutex_reply == 0) {
// debug(1,"dacp_conversation_lock acquired for command \"%s\".",command);

Expand Down Expand Up @@ -263,9 +264,13 @@ int send_simple_dacp_command(const char *command) {
}

void relinquish_dacp_server_information(rtsp_conn_info *conn) {
// this will set the dacp_server.players_connection_thread_index to zero iff it has the same value as the conn's connection number
// this is to signify that the player has stopped, but only if another thread (with a different index) hasn't already taken over the dacp service
ss_pthread_mutex_timedlock(&dacp_server_information_lock,500000,"set_dacp_server_information couldn't get DACP server information lock in 0.5 second!.",1);
// this will set the dacp_server.players_connection_thread_index to zero iff it has the same value
// as the conn's connection number
// this is to signify that the player has stopped, but only if another thread (with a different
// index) hasn't already taken over the dacp service
ss_pthread_mutex_timedlock(
&dacp_server_information_lock, 500000,
"set_dacp_server_information couldn't get DACP server information lock in 0.5 second!.", 1);
if (dacp_server.players_connection_thread_index == conn->connection_number)
dacp_server.players_connection_thread_index = 0;
pthread_mutex_unlock(&dacp_server_information_lock);
Expand All @@ -274,7 +279,9 @@ void relinquish_dacp_server_information(rtsp_conn_info *conn) {
// this will be running on the thread of its caller, not of the conversation thread...
void set_dacp_server_information(rtsp_conn_info *conn) { // tell the DACP conversation thread that
// the port has been set or changed
ss_pthread_mutex_timedlock(&dacp_server_information_lock,500000,"set_dacp_server_information couldn't get DACP server information lock in 0.5 second!.",1);
ss_pthread_mutex_timedlock(
&dacp_server_information_lock, 500000,
"set_dacp_server_information couldn't get DACP server information lock in 0.5 second!.", 1);
dacp_server.players_connection_thread_index = conn->connection_number;
dacp_server.port = conn->dacp_port;
dacp_server.connection_family = conn->connection_ip_family;
Expand Down Expand Up @@ -302,7 +309,9 @@ void *dacp_monitor_thread_code(__attribute__((unused)) void *na) {
int32_t revision_number = 1;
while (1) {
int result;
ss_pthread_mutex_timedlock(&dacp_server_information_lock,500000,"dacp_monitor_thread_code couldn't get DACP server information lock in 0.5 second!.",1);
ss_pthread_mutex_timedlock(
&dacp_server_information_lock, 500000,
"dacp_monitor_thread_code couldn't get DACP server information lock in 0.5 second!.", 1);
while (dacp_server.scan_enable == 0) {
// debug(1, "Wait for a valid DACP port");
pthread_cond_wait(&dacp_server_information_cv, &dacp_server_information_lock);
Expand All @@ -313,7 +322,7 @@ void *dacp_monitor_thread_code(__attribute__((unused)) void *na) {
// debug(1,"Stopping scan because the response to \"dacp_get_volume(NULL)\" is %d.",result);
dacp_server.scan_enable = 0;
metadata_hub_modify_prolog();
int ch = metadata_store.dacp_server_active !=0;
int ch = metadata_store.dacp_server_active != 0;
metadata_store.dacp_server_active = 0;
metadata_hub_modify_epilog(ch);
}
Expand Down
Loading

0 comments on commit d692fab

Please sign in to comment.