Exemplo n.º 1
0
/* create a new subscriber */
static struct subscriber *
newSubscriber(const char * eventurl, const char * callback, int callbacklen)
{
	struct subscriber * tmp;
	if(!eventurl || !callback || !callbacklen)
		return NULL;
	tmp = calloc(1, sizeof(struct subscriber)+callbacklen+1);
	if(strcmp(eventurl, CONTENTDIRECTORY_EVENTURL)==0)
		tmp->service = EContentDirectory;
	else if(strcmp(eventurl, CONNECTIONMGR_EVENTURL)==0)
		tmp->service = EConnectionManager;
	else if(strcmp(eventurl, X_MS_MEDIARECEIVERREGISTRAR_EVENTURL)==0)
		tmp->service = EMSMediaReceiverRegistrar;
	else if (strcmp(eventurl, RENDERTRNSPORT_EVENTLURL) == 0)
		tmp->service = ERenderTransport;
	else if (strcmp(eventurl, RENDERCONTROL_PATH) == 0)
		tmp->service = ERenderControl;
	else {
		free(tmp);
		return NULL;
	}
	memcpy(tmp->callback, callback, callbacklen);
	tmp->callback[callbacklen] = '\0';
	/* make a dummy uuid */
	strncpyt(tmp->uuid, uuidvalue, sizeof(tmp->uuid));
	if( get_uuid_string(tmp->uuid+5) != 0 )
	{
		tmp->uuid[sizeof(tmp->uuid)-1] = '\0';
		snprintf(tmp->uuid+37, 5, "%04lx", random() & 0xffff);
	}

	return tmp;
}
Exemplo n.º 2
0
/**
 * To process the request issued from the controller.
 *
 * The daemon reads the request from the controller, and executes the issued
 * request type from the controller. The daemons have separate data structure
 * for each request type.
 */
static void process_requests()
{
	int rc;
	DEBUG_MSG(LOG_DEBUG, "process_requests trying to lock mutex");
	pthread_mutex_lock(&mutex);
	DEBUG_MSG(LOG_DEBUG, "process_requests locked mutex");

	char tmp[100];
	for (;;) {
		int rc = read(daemon_pipe[0], tmp, 100);
		if (rc != 100)
			break;
	}

	while (requests) {
		struct request* request = requests;
		requests = requests->next;
		rc = 0;

		switch (request->type) {
		case REQUEST_ADD_DESTINATION:
			add_flow_destination((struct
						request_add_flow_destination
						*)request);
			break;
		case REQUEST_ADD_SOURCE:
			rc = add_flow_source((struct
						request_add_flow_source
						*)request);
			break;
		case REQUEST_START_FLOWS:
			start_flows((struct request_start_flows *)request);
			break;
		case REQUEST_STOP_FLOW:
			stop_flow((struct request_stop_flow *)request);
			break;
		case REQUEST_GET_STATUS:
			{
				struct request_get_status *r =
					(struct request_get_status *)request;
				r->started = started;
				r->num_flows = fg_list_size(&flows);
			}
			break;
		case REQUEST_GET_UUID:
			{
				struct request_get_uuid *r =
					(struct request_get_uuid *)request;
				get_uuid_string(r->server_uuid);
			}
			break;
		default:
			request_error(request, "Unknown request type");
			break;
		}
		if (rc != 1)
			pthread_cond_signal(request->condition);
	}

	pthread_mutex_unlock(&mutex);
	DEBUG_MSG(LOG_DEBUG, "process_requests unlocked mutex");
}