コード例 #1
0
ファイル: satipc.c プロジェクト: Newman101/minisatip
int satipc_close(sockets * s)
{
	LOG("satip_close called for adapter %d, socket_id %d, handle %d timeout %d",
			s->sid, s->id, s->sock, s->close_sec);
	close_adapter(s->sid);
	return 0;
}
コード例 #2
0
ファイル: adapter.c プロジェクト: crowm/minisatip
int close_adapter_for_socket(sockets * s)
{
	int aid = s->sid;

	LOG("closing DVR socket %d pos %d aid %d", s->sock, s->id, aid);
	if (aid >= 0)
		close_adapter(aid);
	return 0;
}
コード例 #3
0
ファイル: adapter.c プロジェクト: crowm/minisatip
int init_hw(int i)
{
	char name[100];
	adapter *ad;
	if (i < 0 || i >= MAX_ADAPTERS)
		return 1;

	if (a[i] && a[i]->enabled)
		return 1;

	if (!a[i])
		return 1;

	ad = a[i];
	mutex_init(&ad->mutex);
	mutex_lock(&ad->mutex);
	if (ad->force_disable)
		goto NOK;
	if (ad->enabled)
		goto NOK;

	ad->sock = -1;
	ad->id = i;
	ad->fe_sock = -1;
	ad->sock = -1;

	if (ad->enabled)
	{
		goto NOK;
	}

	if (ad->open(ad))
	{
		init_complete = 0;
		goto NOK;
	}
	ad->enabled = 1;

	if (!ad->buf)
		ad->buf = malloc1(opts.adapter_buffer + 10);
	if (!ad->buf)
	{
		LOG(
				"memory allocation failed for %d bytes failed, adapter %d, trying %d bytes",
				opts.adapter_buffer, i, ADAPTER_BUFFER);
		opts.adapter_buffer = ADAPTER_BUFFER;
		ad->buf = malloc1(opts.adapter_buffer + 10);
		if (!ad->buf)
		{
			LOG("memory allocation failed for %d bytes failed, adapter %d",
					opts.adapter_buffer, i);
			close_adapter(i);
		}
		goto NOK;
	}
	memset(ad->buf, 0, opts.adapter_buffer + 1);
	init_dvb_parameters(&ad->tp);
	mark_pids_deleted(i, -1, NULL);
	update_pids(i);
	ad->delsys(i, ad->fe, ad->sys);
	ad->master_sid = -1;
	ad->sid_cnt = 0;
	ad->pid_err = ad->dec_err = 0;
	ad->new_gs = 0;
	ad->force_close = 0;
	ad->ca_mask = 0;
	ad->rtime = getTick();
	ad->sock = sockets_add(ad->dvr, NULL, i, TYPE_DVR, (socket_action) read_dmx,
			(socket_action) close_adapter_for_socket,
			(socket_action) adapter_timeout);
	memset(ad->buf, 0, opts.adapter_buffer + 1);
	set_socket_buffer(ad->sock, (unsigned char*) ad->buf, opts.adapter_buffer);
	sockets_timeout(ad->sock, ADAPTER_TIMEOUT);
	snprintf(ad->name, sizeof(ad->name), "AD%d", i);
	set_socket_thread(ad->sock, start_new_thread(ad->name));
	tables_init_device(ad);
	if (ad->post_init)
		ad->post_init(ad);

//	set_sock_lock(ad->sock, &ad->mutex); // locks automatically the adapter on reading from the DVR 

	LOG("done opening adapter %i fe_sys %d %d %d %d", i, ad->sys[0], ad->sys[1],
			ad->sys[2], ad->sys[3]);

	OK:
	mutex_unlock(&ad->mutex);
	return 0;

	NOK:
	mutex_unlock(&ad->mutex);
	return 1;
}