コード例 #1
0
ファイル: kplex.c プロジェクト: bakerkj/kplex
/*
 * Free all the data associated with an interface except the iface_t itself
 * Args: Pointer to iface_t to be freed
 * Returns: Nothing
 * Side Effects: Cleanup routines invoked, de-coupled from any pair, all data
 * other than the main interface structure is freed
 * Because of dealing with the pair, the io_mutex should be locked before
 * involing this routine
 */
void free_if_data(iface_t *ifa)
{
    if ((ifa->direction == OUT) && ifa->q) {
        /* output interfaces have queues which need freeing */
        free(ifa->q->base);
        free(ifa->q);
    }

    free_filter(ifa->ifilter);
    free_filter(ifa->ofilter);

    if (ifa->info) {
        if (ifa->cleanup)
            ifa->cleanup(ifa);
        free(ifa->info);
    }

    if (ifa->pair) {
        ifa->pair->pair=NULL;
        if (ifa->pair->direction == OUT) {
            pthread_mutex_lock(&ifa->pair->q->q_mutex);
            ifa->pair->q->active=0;
            pthread_cond_broadcast(&ifa->pair->q->freshmeat);
            pthread_mutex_unlock(&ifa->pair->q->q_mutex);
        } else {
            if (ifa->pair->tid)
                pthread_kill(ifa->pair->tid,SIGUSR1);
            else
                ifa->pair->direction = NONE;
        }
    } else
        if (ifa->name && !(ifa->id & IDMINORMASK)) {
            free(ifa->name);
       }
}
コード例 #2
0
static void process_departed_sec(service_t *p_svc, dvb_section_t *p_sec)
{
  dvb_svc_data_t *p_svc_data = (dvb_svc_data_t *)p_svc->get_data_buffer(p_svc);
  dvb_priv_t *p_priv = p_svc_data->p_this->p_data;
  request_mode_t req_mode = 
    p_priv->table_map[p_sec->table_map_index].request_mode;
  
  if(DATA_SINGLE == req_mode)
  {
    free_filter(p_priv, p_sec);
    push_simple_queue(p_priv->q_handle, p_priv->free_queue, p_sec->id);
  }
  else if(DATA_PERIODIC == req_mode)
  {
    free_filter(p_priv, p_sec);
    push_simple_queue(p_priv->q_handle, p_svc_data->block_queue, p_sec->id);
  }
  else if(DATA_MULTI == req_mode)
  {
    MT_ASSERT(p_sec->dmx_handle != 0xffff);
    if(p_sec->ts_in != p_priv->current_ts_in)
     {
        free_filter(p_priv, p_sec);
        p_sec->ts_in = p_priv->current_ts_in;
        push_simple_queue(p_priv->q_handle, p_svc_data->wait_queue, p_sec->id); 
     }
    else
        push_simple_queue(p_priv->q_handle, p_svc_data->using_queue, p_sec->id); 
  }
}
コード例 #3
0
static void dvb_update_ts(service_t *p_svc)
{
  dvb_svc_data_t *p_svc_data = (dvb_svc_data_t *)p_svc->get_data_buffer(p_svc);
  dvb_priv_t *p_priv = p_svc_data->p_this->p_data;
  class_handle_t q_handle = p_priv->q_handle;
  dvb_section_t *p_sec = NULL;
  u16 i = 0;
  u16 sec_id = 0;
  u16 sec_num = 0;

  sec_num = get_simple_queue_len(q_handle, p_svc_data->wait_queue);
  for(i = 0; i < sec_num; i ++)
  {
    pop_simple_queue(q_handle, p_svc_data->wait_queue, &sec_id);
    p_sec = p_priv->p_sec + sec_id;
    p_sec->ts_in = p_priv->current_ts_in;
    if(p_sec->dmx_handle != 0xffff)
        free_filter(p_priv, p_sec);    
    push_simple_queue_on_head(q_handle, p_svc_data->wait_queue, sec_id);
  }     

  sec_num = get_simple_queue_len(q_handle, p_svc_data->using_queue);
  for(i = 0; i < sec_num; i ++)
  {
    pop_simple_queue(q_handle, p_svc_data->using_queue, &sec_id);
    p_sec = p_priv->p_sec + sec_id;
    if(p_sec->ts_in != p_priv->current_ts_in)
    {
        p_sec->ts_in = p_priv->current_ts_in;
        if(p_sec->dmx_handle != 0xffff)
            free_filter(p_priv, p_sec);        
        push_simple_queue_on_head(q_handle, p_svc_data->wait_queue, sec_id);        
    }
    else
        push_simple_queue_on_head(q_handle, p_svc_data->using_queue, sec_id);
  }  

  sec_num = get_simple_queue_len(q_handle, p_svc_data->block_queue);
  for(i = 0; i < sec_num; i ++)
  {
    pop_simple_queue(q_handle, p_svc_data->block_queue, &sec_id);
    p_sec = p_priv->p_sec + sec_id;
    p_sec->ts_in = p_priv->current_ts_in;
    if(p_sec->dmx_handle != 0xffff)
        free_filter(p_priv, p_sec);
    push_simple_queue_on_head(q_handle, p_svc_data->block_queue, sec_id);
  }  
}
コード例 #4
0
ファイル: filter.c プロジェクト: royalwang/linux-commands
void free_filter_tree() {
  int i;
  for(i = 0; i < filter_list_len; i++) {
    free_filter(filter_list[i]);
  } 
  free(filter_list);
}
コード例 #5
0
ファイル: kalman_test.c プロジェクト: ruipgil/ikalman
/* Test the example of a train moving along a 1-d track */
void test_train() {
  KalmanFilter f = alloc_filter(2, 1);

  /* The train state is a 2d vector containing position and velocity.
     Velocity is measured in position units per timestep units. */
  set_matrix(f.state_transition,
	     1.0, 1.0,
	     0.0, 1.0);

  /* We only observe position */
  set_matrix(f.observation_model, 1.0, 0.0);

  /* The covariance matrices are blind guesses */
  set_identity_matrix(f.process_noise_covariance);
  set_identity_matrix(f.observation_noise_covariance);

  /* Our knowledge of the start position is incorrect and unconfident */
  double deviation = 1000.0;
  set_matrix(f.state_estimate, 10 * deviation);
  set_identity_matrix(f.estimate_covariance);
  scale_matrix(f.estimate_covariance, deviation * deviation);

  /* Test with time steps of the position gradually increasing */
  for (int i = 0; i < 10; ++i) {
    set_matrix(f.observation, (double) i);
    update(f);
  }

  /* Our prediction should be close to (10, 1) */
  printf("estimated position: %f\n", f.state_estimate.data[0][0]);
  printf("estimated velocity: %f\n", f.state_estimate.data[1][0]);

  free_filter(f);
}
コード例 #6
0
ファイル: gps_test.c プロジェクト: ruipgil/ikalman
void test_bearing_west() {
  KalmanFilter f = alloc_filter_velocity2d(1.0);
  for (int i = 0; i < 100; ++i) {
    update_velocity2d(f, 0.0, i * -0.0001, 1.0);
  }

  double bearing = get_bearing(f);
  assert(abs(bearing - 270.0) < 0.01);

  free_filter(f);
}
コード例 #7
0
ファイル: multicast.c プロジェクト: JokeLook/dbstar
int softdvb_uninit()
{
	int ret = 0;
	
	softdvb_running = 0;
	pthread_join(pth_softdvb_id, NULL);
	
	// prog/file
	unsigned short root_pid = root_channel_get();
	ret = free_filter(root_pid);
	DEBUG("free pid %d return with %d\n", root_pid, ret);
	
#ifdef PUSH_LOCAL_TEST
	// prog/video
	unsigned short video_pid = 123;
	ret = free_filter(video_pid);
	DEBUG("free pid %d return with %d\n", video_pid, ret);
	
	// prog/file
	unsigned short file_pid = 654;
	ret = free_filter(file_pid);
	DEBUG("free pid %d return with %d\n", file_pid, ret);
	
	// prog/audio
	unsigned short audio_pid = 8123;
	ret = free_filter(audio_pid);
	DEBUG("free pid %d return with %d\n", audio_pid, ret);
#else
	if(-1==pid_init(0)){
		DEBUG("allpid init faild\n");
		return -1;
	}	
#endif

	return ret;
}
コード例 #8
0
ファイル: dvb_svc.c プロジェクト: github188/1521
static void process_departed_sec(service_t *p_svc, dvb_section_t *p_sec)
{
  dvb_svc_data_t *p_svc_data = (dvb_svc_data_t *)p_svc->get_data_buffer(p_svc);
  dvb_priv_t *p_priv = p_svc_data->p_this->p_data;
  request_mode_t req_mode = 
    p_priv->table_map[p_sec->table_map_index].request_mode;
  
  if(DATA_SINGLE == req_mode)
  {
    free_filter(p_priv, p_sec);
    push_simple_queue(p_priv->q_handle, p_priv->free_queue, p_sec->id);
  }
  else if(DATA_PERIODIC == req_mode)
  {
    free_filter(p_priv, p_sec);
    push_simple_queue(p_priv->q_handle, p_svc_data->block_queue, p_sec->id);
  }
  else if(DATA_MULTI == req_mode)
  {
    MT_ASSERT(p_sec->pti_handle != NULL);
    //push it back to using queue
    push_simple_queue(p_priv->q_handle, p_svc_data->using_queue, p_sec->id);
  }
}
コード例 #9
0
ファイル: gps_test.c プロジェクト: ruipgil/ikalman
void test_variable_timestep() {
  KalmanFilter f = alloc_filter_velocity2d(1.0);

  /* Move at a constant speed but taking slower and slower readings */
  int east_distance = 0;
  for (int i = 0; i < 20; ++i) {
    east_distance += i;
    update_velocity2d(f, 0.0, east_distance * 0.0001, i);
  }

  double dlat, dlon;
  get_velocity(f, &dlat, &dlon);
  assert(abs(dlat) < 0.000001);
  assert(abs(dlon - 0.0001) < 0.000001);

  free_filter(f);
}
コード例 #10
0
ファイル: gps_test.c プロジェクト: ruipgil/ikalman
void test_bearing_north() {
  KalmanFilter f = alloc_filter_velocity2d(1.0);
  for (int i = 0; i < 100; ++i) {
    update_velocity2d(f, i * 0.0001, 0.0, 1.0);
  }

  double bearing = get_bearing(f);
  assert(abs(bearing - 0.0) < 0.01);

  /* Velocity should be 0.0001 x units per timestep */
  double dlat, dlon;
  get_velocity(f, &dlat, &dlon);
  assert(abs(dlat - 0.0001) < 0.00001);
  assert(abs(dlon) < 0.00001);

  free_filter(f);
}
コード例 #11
0
ファイル: gps_test.c プロジェクト: ruipgil/ikalman
void test_bearing_east() {
  KalmanFilter f = alloc_filter_velocity2d(1.0);
  for (int i = 0; i < 100; ++i) {
    update_velocity2d(f, 0.0, i * 0.0001, 1.0);
  }

  double bearing = get_bearing(f);
  assert(abs(bearing - 90.0) < 0.01);

  /* At this rate, it takes 10,000 timesteps to travel one longitude
     unit, and thus 3,600,000 timesteps to travel the circumference of
     the earth. Let's say one timestep is a second, so it takes
     3,600,000 seconds, which is 60,000 minutes, which is 1,000
     hours. Since the earth is about 25000 miles around, this means we
     are traveling at about 25 miles per hour. */
  double mph = get_mph(f);
  assert(abs(mph - 25.0) < 2.0);

  free_filter(f);
}
コード例 #12
0
ファイル: multicast.c プロジェクト: JokeLook/dbstar
static int allpid_sqlite_cb(char **result, int row, int column, void *filter_act, unsigned int receiver_size)
{
	DEBUG("sqlite callback, row=%d, column=%d, filter_act addr: %p, receiver_size=%u\n", row, column, filter_act,receiver_size);
	if(row<1 || NULL==filter_act){
		DEBUG("no record in table, return\n");
		return 0;
	}
	
	int i = 0;
	
	for(i=1;i<row+1;i++)
	{
		unsigned short pid = (unsigned short)(strtol(result[i*column],NULL,0));
		if(0==*((int *)filter_act) || 0==atoi(result[i*column+2])){
			int ret = free_filter(pid);
			DEBUG("free pid %d[%s] return with %d\n", pid, result[i*column], ret);
		}
	}
	
	for(i=1;i<row+1;i++)
	{
		DEBUG("PID --- %s:%s:%s --- \n", result[i*column],result[i*column+1],result[i*column+2]);
		unsigned short pid = (unsigned short)(strtol(result[i*column],NULL,0));
		if(1==*((int *)filter_act) && 1==atoi(result[i*column+2])){
			int filter = -1;
			if(0==strcmp(result[i*column+1],"file"))
				filter = alloc_filter(pid, 1);
			else
				filter = alloc_filter(pid, 0);
			DEBUG("set filter, pid=%d[%s], fid=%d\n", pid, result[i*column], filter);
		}
//		else{
//			int ret = free_filter(pid);
//			DEBUG("free pid %d return with %d\n", pid, ret);
//		}
	}
	
	return 0;
}
コード例 #13
0
static void do_free_cmd(service_t *p_svc, dvb_request_t *p_para)
{
  dvb_svc_data_t *p_svc_data = (dvb_svc_data_t *)p_svc->get_data_buffer(p_svc);
  dvb_priv_t *p_priv = p_svc_data->p_this->p_data;
  u16 i = 0;
  u16 sec_id = 0;
  dvb_section_t *p_sec = NULL;
  u16 sec_num = 0;
  class_handle_t q_handle = p_priv->q_handle;

  //A.sreach section in filter array(it's used)-------->
  sec_num = get_simple_queue_len(q_handle, p_svc_data->using_queue);
  for(i = 0; i < sec_num; i ++)
  {
    pop_simple_queue(q_handle, p_svc_data->using_queue, &sec_id);
    p_sec = p_priv->p_sec + sec_id;
    MT_ASSERT(sec_id == p_sec->id);

    if(match_free_sec(p_priv, p_sec, p_para))
    {
      free_filter(p_priv, p_sec);
      push_simple_queue(q_handle, p_priv->free_queue, sec_id);
      if(p_priv->table_map[p_sec->table_map_index].free != NULL)
      {
        p_priv->table_map[p_sec->table_map_index].free();
      }
    }
    else
    {
      //push to using queue back
      push_simple_queue(q_handle, p_svc_data->using_queue, sec_id);
    }
  }
  
  //B.sreach section in block queue------------>
  sec_num = get_simple_queue_len(q_handle, p_svc_data->block_queue);

  for(i = 0; i < sec_num; i ++)
  {
    pop_simple_queue(q_handle, p_svc_data->block_queue, &sec_id);
    p_sec = p_priv->p_sec + sec_id;
    MT_ASSERT(sec_id == p_sec->id);
    if(match_free_sec(p_priv, p_sec, p_para))
    {
      //push to free queue
      push_simple_queue(q_handle, p_priv->free_queue, sec_id);
      if(p_priv->table_map[p_sec->table_map_index].free != NULL)
      {
        p_priv->table_map[p_sec->table_map_index].free();
      }
    }
    else
    {
      MT_ASSERT(p_sec->dmx_handle == 0xffff);
      //push to block queue back
      push_simple_queue(q_handle, p_svc_data->block_queue, sec_id);
    }
  }

  
  //C.sreach section in wait queue--------------->
  sec_num = get_simple_queue_len(q_handle, p_svc_data->wait_queue);

  for(i = 0; i < sec_num; i ++)
  {
    pop_simple_queue(q_handle, p_svc_data->wait_queue, &sec_id);
    p_sec = p_priv->p_sec + sec_id;
    MT_ASSERT(sec_id == p_sec->id);
    if(match_free_sec(p_priv, p_sec, p_para))
    {
      //push to free queue
      push_simple_queue(q_handle, p_priv->free_queue, sec_id);
      if(p_priv->table_map[p_sec->table_map_index].free != NULL)
      {
        p_priv->table_map[p_sec->table_map_index].free();
      }
    }
    else
    {
      //MT_ASSERT(p_sec->dmx_handle == 0xffff);
      //push to wait queue back
      push_simple_queue(q_handle, p_svc_data->wait_queue, sec_id);
    }
  }
}
コード例 #14
0
ファイル: options.c プロジェクト: IrishMarineInstitute/kplex
int add_common_opt(char *var, char *val,iface_t *ifp)
{
    char *ptr;

    if (!strcasecmp(var,"direction")) {
        if (!strcasecmp(val,"in"))
            ifp->direction = IN;
        else if (!strcasecmp(val,"out"))
            ifp->direction = OUT;
        else if (!strcasecmp(val,"both"))
            ifp->direction = BOTH;
        else return(-2);
    } else if (!strcmp(var,"ifilter")) {
        if (ifp->ifilter)
            free_filter(ifp->ifilter);
        if ((ifp->ifilter=getfilter(val)) == NULL)
        return(-2);
    } else if (!strcmp(var,"ofilter")) {
        if (ifp->ofilter)
            free_filter(ifp->ofilter);
        if ((ifp->ofilter=getfilter(val)) == NULL)
        return(-2);
    } else if (!strcmp(var,"strict")) {
        if (!strcasecmp(val,"yes")) {
            ifp->strict=1;
        } else if (!strcasecmp(val,"no")) {
            ifp->strict=0;
        } else
            return(-2);
    } else if (!strcmp(var,"checksum")) {
        if (!strcasecmp(val,"yes")) {
            ifp->checksum=1;
        } else if (!strcasecmp(val,"no")) {
            ifp->checksum=0;
        } else
            return(-2);
    } else if (!strcmp(var,"timestamp")) {
        if (!strcasecmp(val,"s")) {
            ifp->tagflags |= TAG_TS;
            ifp->tagflags &= ~TAG_MS;
        } else if (!strcasecmp(val,"ms")) {
            ifp->tagflags |= (TAG_TS|TAG_MS);
        } else
            return(-2);
    } else if (!strcmp(var,"srctag")) {
        if (!strcasecmp(val,"yes")) {
            ifp->tagflags |= TAG_SRC;
        } else if (!strcasecmp(val,"no")) {
            ifp->tagflags &= ~TAG_SRC;
        } else if (!strcasecmp(val,"input")) {
            ifp->tagflags |= TAG_SRC;
            ifp->tagflags |= TAG_ISRC;
        } else
            return(-2);
    } else if (!strcmp(var,"persist")) {
        if (!strcasecmp(val,"yes")) {
            flag_set(ifp,F_PERSIST);
            flag_clear(ifp,F_IPERSIST);
        } else if (!strcasecmp(val,"fromstart")) {
            flag_set(ifp,F_PERSIST);
            flag_set(ifp,F_IPERSIST);
        } else if (!strcasecmp(val,"no")) {
            flag_clear(ifp,F_PERSIST);
            flag_clear(ifp,F_IPERSIST);
        } else
            return(-2);
    } else if (!strcmp(var,"loopback")) {
        if (!strcasecmp(val,"yes")) {
            flag_set(ifp,F_LOOPBACK);
        } else if (!strcasecmp(val,"no")) {
            flag_clear(ifp,F_LOOPBACK);
        } else
            return(-2);
    } else if (!strcmp(var,"optional")) {
        if (!strcasecmp(val,"yes")) {
            flag_set(ifp,F_OPTIONAL);
        } else if (!strcasecmp(val,"no")) {
            flag_clear(ifp,F_OPTIONAL);
        } else
            return(-2);
    } else if (!strcmp(var,"eol")) {
        if (!strcasecmp(val,"n")) {
            flag_set(ifp,F_NOCR);
        } else if (!strcasecmp(val,"rn")) {
            flag_clear(ifp,F_NOCR);
        } else
            return(-2);
    } else if (!strcasecmp(var,"name")) {
        if ((ifp->name=(char *)malloc(strlen(val)+1)) == NULL)
            return(-1);
        for (ptr=ifp->name;*val;)
                *ptr++= *val++;
    } else
        return(1);

    return(0);
}
コード例 #15
0
ファイル: GPSFilter.cpp プロジェクト: ProbablePrime/ikalman
GPSFilter::~GPSFilter(){
  free_filter(f);
}