Exemplo n.º 1
0
void *init_oscam_ser(struct s_client *UNUSED(cl), uchar *UNUSED(mbuf), int32_t module_idx)
{
	char sdevice[512];
	int32_t ret;
	struct s_thread_param param;
	pthread_attr_t attr;
	pthread_attr_init(&attr);
	pthread_attr_setstacksize(&attr, PTHREAD_STACK_SIZE);
	oscam_init_serialdata(&param.serialdata);
	if(cfg.ser_device)
		{ cs_strncpy(sdevice, cfg.ser_device, sizeof(sdevice)); }
	else
		{ memset(sdevice, 0, sizeof(sdevice)); }
	param.module_idx = module_idx;
	char *p;
	pthread_t temp;
	char cltype = 'c'; //now auto should work
	if(bcopy_end == -1)  //mutex should be initialized only once
	{
		pthread_mutex_init(&mutex, NULL);
		pthread_cond_init(&cond, NULL);
		bcopy_end = 0;
	}
	while((p = strrchr(sdevice, ';')))
	{
		*p = 0;
		if(!(p + 1) || (!(p + 1)[0])) { return NULL; }
		if(!oscam_ser_parse_url(p + 1, &param.serialdata, &cltype)) { return NULL; }
		ret = pthread_create(&temp, &attr, oscam_ser_fork, (void *) &param);
		if(ret)
		{
			cs_log("ERROR: can't create serial reader thread (errno=%d %s)", ret, strerror(ret));
			pthread_attr_destroy(&attr);
			return NULL;
		}
		else
		{
			oscam_wait_ser_fork();
			pthread_detach(temp);
		}
	}

	if(!sdevice[0]) { return NULL; }
	if(!oscam_ser_parse_url(sdevice, &param.serialdata, &cltype)) { return NULL; }
	ret = pthread_create(&temp, &attr, oscam_ser_fork, (void *) &param);
	if(ret)
	{
		cs_log("ERROR: can't create serial reader thread (errno=%d %s)", ret, strerror(ret));
		pthread_attr_destroy(&attr);
		return NULL;
	}
	else
	{
		oscam_wait_ser_fork();
		pthread_detach(temp);
	}
	pthread_attr_destroy(&attr);
	return NULL;
}
Exemplo n.º 2
0
static int32_t oscam_ser_client_init(struct s_client *client)
{
  if (!client->serialdata && !cs_malloc(&client->serialdata, sizeof(struct s_serial_client)))
    return 1;

  oscam_init_serialdata(client->serialdata);

  if ((!client->reader->device[0])) cs_disconnect_client(client);
  if (!oscam_ser_parse_url(client->reader->device, client->serialdata, NULL)) cs_disconnect_client(client);
  client->pfd=init_oscam_ser_device(client);
  return((client->pfd>0) ? 0 : 1);
}
Exemplo n.º 3
0
static void * oscam_ser_fork(void *pthreadparam)
{
  struct s_thread_param *pparam = (struct s_thread_param *) pthreadparam;
  struct s_client *cl=create_client(get_null_ip());
  pthread_setspecific(getclient, cl);
  cl->thread=pthread_self();
  cl->typ='c';
  cl->module_idx = pparam->module_idx;
  cl->account=first_client->account;

  if (!cl->serialdata && !cs_malloc(&cl->serialdata, sizeof(struct s_serial_client)))
    return NULL;

  set_thread_name(__func__);
  oscam_init_serialdata(cl->serialdata);
  oscam_copy_serialdata(cl->serialdata, &pparam->serialdata);
  if (cl->serialdata->oscam_ser_port > 0)
  {
    // reader struct for serial network connection
    struct s_reader *newrdr;
    if (!cs_malloc(&newrdr, sizeof(struct s_reader)))
      return NULL;
    memset(newrdr, 0, sizeof(struct s_reader));
    newrdr->client = cl;
    newrdr->ph = *serial_ph;
    cl->reader = newrdr;
    cs_strncpy(cl->reader->label, "network-socket", sizeof(cl->reader->label));
  }
  cs_log("serial: initialized (%s@%s)", cl->serialdata->oscam_ser_proto>P_MAX ?
         "auto" : proto_txt[cl->serialdata->oscam_ser_proto], cl->serialdata->oscam_ser_device);

  pthread_mutex_lock(&mutex);
  bcopy_end = 1;
  pthread_mutex_unlock(&mutex);
  pthread_cond_signal(&cond);

  while(1)
  {
    cl->login=time((time_t *)0);
    cl->pfd=init_oscam_ser_device(cl);
    if (cl->pfd)
      oscam_ser_server();
    else
      cs_sleepms(60000);	// retry in 1 min. (USB-Device ?)
    if (cl->pfd) close(cl->pfd);
  }
  NULLFREE(cl->serialdata);
  NULLFREE(cl->reader);
  return NULL;
}