Beispiel #1
0
unsigned long
_st_remove(smat_table_t *table, smat_entry_t *entry, unsigned int remflag)
{
  unsigned long retval;

  if (remflag & ST_REM_HASH) { /* remove from hash table */
    if ((retval = ht_remove(&table->st_table, &entry->se_hash)))
      return retval;
  }

  if (remflag & ST_REM_FIRST) { /* remove from first linked list */
    if ((retval = ll_remove(entry->se_link[SMAT_LOC_FIRST].le_head,
			    &entry->se_link[SMAT_LOC_FIRST])))
      return retval;
  }

  if (remflag & ST_REM_SECOND) { /* remove from second linked list */
    if ((retval = ll_remove(entry->se_link[SMAT_LOC_SECOND].le_head,
			    &entry->se_link[SMAT_LOC_SECOND])))
      return retval;
  }

  if (remflag & ST_REM_FREE) /* free entry */
    _smat_free(entry);

  return 0;
}
Beispiel #2
0
void rtobject_dealloca(rtobject_t* rtobj){
  int i;
  if (rtobj->name) free(rtobj->name);
  if (rtobj->description) free(rtobj->description);
  if (rtobj->imp_arg_list){
    for (i=0;i<rtobj->imp_arg_list_size;++i){
      if (rtobj->imp_arg_list[i]) free(rtobj->imp_arg_list[i]);
    }
    free(rtobj->imp_arg_list);
  }
  if (rtobj->imp_struct) free(rtobj->imp_struct);

  destroy_namespace(rtobj->control_ns);
  while (rtobj->control_list){
    control_dealloc((control_t*)rtobj->control_list->data);
    ll_remove(rtobj->control_list,&rtobj->control_list);
  }

  destroy_namespace(rtobj->data_port_ns);
  while (rtobj->data_port_list){
    data_port_dealloc((data_port_t*)rtobj->data_port_list->data);
    ll_remove(rtobj->data_port_list,&rtobj->data_port_list);
  }

  if (rtobj->instance_list) free(rtobj->instance_list);

  rtobject_flush_map_list(rtobj);
  if (rtobj->event_map_list)
    generic_array_destroy(rtobj->event_map_list);

  free(rtobj);
}
Beispiel #3
0
int rtobject_cleanup(rtobject_t* rtobj){
  node_t* temp_node;
  rtobject_instance_t* curr_ins;

  if (rtobject_get_major_type(rtobj) == RTOBJECT_MAJOR_TYPE_SIGNAL_PATH){

    /*free local buffer references from outdated instances*/
    for (temp_node=rtobj->outdated_instance_list;\
	   temp_node;\
	   temp_node=temp_node->next){

      curr_ins = (rtobject_instance_t*)temp_node->data;
      
      while (curr_ins->imp_data.signal_path_element.local_buffer_list){
	ll_remove(curr_ins->imp_data.signal_path_element.local_buffer_list,\
		  &curr_ins->imp_data.signal_path_element.local_buffer_list);
      }
      
    }

    /*call signal path's cleanup function to handle unused channels*/
    if ((signal_path_cleanup((signal_path_t*)rtobj->imp_struct)) <0) return -1;

  }
   
  /*free outdated instances*/
  while (rtobj->outdated_instance_list){
    free((rtobject_instance_t*)rtobj->outdated_instance_list->data);
    ll_remove(rtobj->outdated_instance_list, &rtobj->outdated_instance_list);
  }


  return 0;
}
Beispiel #4
0
/**
 * Remove timer
 * @param timer Timer that should be removed
 */
void timers_remove(Timer timer) {
	// Remove timer from linked list
	ll_remove(timer->timers, timer);

	// Free timer structure
	free(timer);
} // timers_remove
Beispiel #5
0
llist * ll_split(llist * list, ll_filter_f * f){
    llist * iter 	= list;
    llist * aux 	= NULL;
    llist * newlist = NULL;
    llist * tail 	= NULL;
	
	assert(f != NULL);
	
	if (list == NULL || f == NULL)
		return NULL;

	while (iter){
		if ((*f)(iter->val, iter->size)){
			aux = iter;
			iter = ll_next(iter);
			list = ll_remove(aux);
			tail = tail != NULL? ll_appendl(tail, aux) : aux;
		} else {
			iter = ll_next(iter);
		}
	}
	newlist = ll_head(tail);
	
    return newlist;
}
Beispiel #6
0
void
smcp_invalidate_timer(
	smcp_t	self,
	smcp_timer_t	timer
) {
	SMCP_EMBEDDED_SELF_HOOK;
#if SMCP_DEBUG_TIMERS
	size_t previousTimerCount = ll_count(self->timers);
	assert(previousTimerCount>=1);
#endif

	DEBUG_PRINTF("Timer:%p: Invalidating...",timer);
	DEBUG_PRINTF("Timer:%p: (CTX=%p)",timer,timer->context);

	ll_remove((void**)&self->timers, (void*)timer);

#if SMCP_DEBUG_TIMERS
	assert((ll_count(self->timers)) == previousTimerCount-1);
#endif
	timer->ll.next = NULL;
	timer->ll.prev = NULL;
	if(timer->cancel)
		(*timer->cancel)(self,timer->context);
	DEBUG_PRINTF("Timer:%p: Invalidated.",timer);
	DEBUG_PRINTF("%p: Timers in play = %d",self,(int)ll_count(self->timers));
}
Beispiel #7
0
void
smcp_node_delete(smcp_node_t node) {
	void** owner = NULL;

	DEBUG_PRINTF("%s: %p",__func__,node);

	if (node->parent) {
		owner = (void**)&((smcp_node_t)node->parent)->children;
	}

	// Delete all child objects.
	while (((smcp_node_t)node)->children) {
		smcp_node_delete(((smcp_node_t)node)->children);
	}

	if (owner) {
#if SMCP_NODE_ROUTER_USE_BTREE
		bt_remove(owner,
			node,
			(bt_compare_func_t)smcp_node_compare,
			(void*)node->finalize,
			NULL
		);
#else
		ll_remove(owner,(void*)node);
		if(node->finalize)
			node->finalize(node);
#endif
	}

bail:
	return;
}
Beispiel #8
0
void
smcp_invalidate_timer(
	smcp_t	self,
	smcp_timer_t	timer
) {
	SMCP_EMBEDDED_SELF_HOOK;
#if SMCP_DEBUG_TIMERS
	size_t previousTimerCount = ll_count(self->timers);
	// Sanity check. If we don't have at least one timer
	// then we know something is off.
	check(previousTimerCount>=1);
#endif

	DEBUG_PRINTF("Timer:%p: Invalidating...",timer);
	DEBUG_PRINTF("Timer:%p: (CTX=%p)",timer,timer->context);

	ll_remove((void**)&self->timers, (void*)timer);

#if SMCP_DEBUG_TIMERS
	check((ll_count(self->timers)) == previousTimerCount-1);
#endif
	timer->ll.next = NULL;
	timer->ll.prev = NULL;
	if(timer->cancel)
		(*timer->cancel)(self,timer->context);
	DEBUG_PRINTF("Timer:%p: Invalidated.",timer);
	DEBUG_PRINTF("%p: Timers in play = %d",self,(int)ll_count(self->timers));
}
Beispiel #9
0
//-----------------------------------------------------------------------------
// External function that is used to reply to a http request.
void rq_http_reply(rq_http_req_t *req, const int code, char *ctype, expbuf_t *data)
{
	rq_http_t *http;
	
	assert(req && code > 0);
	
	assert(req->reply);
	assert(BUF_LENGTH(req->reply) == 0);
	
	addCmd(req->reply, HTTP_CMD_CLEAR);
	if (ctype) { addCmdShortStr(req->reply, HTTP_CMD_CONTENT_TYPE, strlen(ctype), ctype); }
	if (data && BUF_LENGTH(data)) { addCmdLargeStr(req->reply, HTTP_CMD_FILE, BUF_LENGTH(data), BUF_DATA(data)); }
	addCmdInt(req->reply, HTTP_CMD_CODE, code);
	addCmd(req->reply, HTTP_CMD_REPLY);

	// If we already have a reply, then we send it and then close off the request object.
	assert(req->msg);
	rq_reply(req->msg, BUF_LENGTH(req->reply), BUF_DATA(req->reply));
	expbuf_clear(req->reply);
	req->msg = NULL;

	if (req->inprocess > 0) {

		// need to remove the request from the list.
		assert(req->http);
		http = req->http;
		
		assert(http->req_list);
		ll_remove(http->req_list, req);

		req_free(req);
		req = NULL;
	}
}
Beispiel #10
0
static void procResult(cache_waiting_t *ptr, rq_blacklist_status_t status)
{
	struct timeval tv;
	cache_entry_t *entry;
 	
	// will need to remove the 'waiting' object from the list... which means
	// that the waiting object will need a pointer to the control structure.
 	assert(ptr);
	assert(ptr->blacklist);
	assert(ptr->blacklist->waiting);
	ll_remove(ptr->blacklist->waiting, ptr);

	assert(ptr->ip != 0);

	// we need to make an entry in the cache for this entry...
	entry = (cache_entry_t *) malloc(sizeof(cache_entry_t));
	entry->ip = ptr->ip;
	entry->status = status;
	
	// determine the expiry.
	assert(ptr->blacklist->expires > 0);
	gettimeofday(&tv, NULL);
	entry->expires = tv.tv_sec + ptr->blacklist->expires;

	// place it at the top.
	assert(ptr->blacklist->cache);
	ll_push_head(ptr->blacklist->cache, entry);

	// call the handler that was saved.
	assert(ptr->handler);
	ptr->handler(status, ptr->arg);
}
Beispiel #11
0
int32_t tick (TCPsocket sock, uint32_t add) {
	
	p_linkedlist item, next;
	p_cronjob job;
	
	// increment timestamp
	searchjob.timestamp += add;
	uint32_t timestamp = searchjob.timestamp;
	

	log_message(DEBUG,"Tick : %d, cronlist: %d", timestamp, cronlist);
	/*
	 * handle cron call
	 */ 
	 
	item = cronlist;
	while(item) {
		next = item->next;

		job = (p_cronjob)item->data;
		if (! job) {
			return -1;
		}
		
		if (job->timestamp == timestamp) {
			log_message(DEBUG, "Found a job!");
					
			/*
			 * set message data
			 */
			strncpy(cronmessage.id, job->message, ROCS_IDSIZE);
			strcpy(cronmessage.tail, job->data);  
			rocsmq_send(sock, &cronmessage, 0);
			
			log_message(DEBUG, "message '%s' sent!", cronmessage.id);

			// put new timestamp 
			job->timestamp += job->period;

			// repeat until all repititions done
			if (job->repetitions > 0) {
				job->repetitions --;
		
			// after the last repitition, remove job
			} 
			
			if (job->repetitions == 0){
				log_message(DEBUG, "removing item");
				cronlist = ll_remove(cronlist,item);
				ll_destroy(item);
			}
		
		}
		/*
		 * check next item
		 */ 
		item = next; 
	}
}
Beispiel #12
0
void delete_vcpu(vcpu_t *vcpu) {
  ll_node_t *a;

  a = (ll_node_t*)((unsigned int)vcpu - sizeof(ll_node_t));

  ll_remove(a);  
  free(a);
}
/**
 * Clear the linked list of all nodes, and free the nodes.  DON'T FREE THE LIST
 * 
 * @param list the list to clear
 * @return -1 if remove returns an error, otherwise return 0
 */
int ll_clear(LINKED_LIST *list){
  while(list->size > 0){
    if(ll_remove(list, 0, NULL) != 0){
      errno = 0;
      return -1;
    }
  }
  return 0;
}
Beispiel #14
0
void delete_vm(vm_t *dom) {
  ll_node_t *nd;

  //free((void*)dom->base_addr);
  nd = (ll_node_t*)((unsigned int)dom - sizeof(ll_node_t));
  ll_remove(nd);
  free(nd);
 
 // flush_tlb();
  
}
Beispiel #15
0
block_t *cache_get(cache_t *cache, uint64_t blkno){
    block_t *block = NULL;
    
    pthread_mutex_lock(&cache->ca_lock);
    
    if (!ht_find(cache->ca_ht, &blkno, (void *)block)) // block is in the cache
        goto got_block;
    
    // it's not in the cache, so we need to read it in from disk
    if ((cache->ca_currsz + sizeof(block_t) + cache->ca_blksz) < cache->ca_maxsz) {
        // we're not at max size yet, so allocate some more memory
        block = malloc(sizeof(block_t));
        if (block == NULL) {
            printf("malloc() error\n");
            goto fail;
        }
        
        memset(block, 0, sizeof(block_t));
        pthread_rwlock_init(&block->bl_lock, NULL);
        block->bl_blkno = blkno;
        block->bl_refcnt = 0;
        block->bl_data = malloc(cache->ca_blksz);
        if (block->bl_data == NULL) {
            printf("malloc() error\n");
            goto fail;
        }

	// XXX shouldn't hold ca_lock over the pread.. set a flag on block and use condition variable to synchronize 
        if (pread(cache->ca_fd, block->bl_data, cache->ca_blksz, blkno * cache->ca_blksz) != cache->ca_blksz) {
            printf("pread() error\n");
            goto fail;
        }
    } else { // we're at max size, so we need to evict someone
        printf("cache eviction not yet supported\n");
        goto fail;
    }

got_block:
    if (block->bl_refcnt == 0) // remove it from the free list
        ll_remove(cache->ca_free_list, (void *)&blkno, LL_NO_FREE); // XXX don't do this if you just alloc'd it..
    
    block->bl_refcnt++;
    
    pthread_mutex_unlock(&cache->ca_lock);
    
    return block;

fail:
    printf("something failed and your code doesn't deal with failure yet..\n");
    
    pthread_mutex_unlock(&cache->ca_lock);
    
    return block;
}
Beispiel #16
0
/**
 * remove all jobs matching the name..
 */ 
int del_cronjob(p_cronjob job){
	p_linkedlist item = ll_create(job, sizeof(t_cronjob));
	p_linkedlist remove	= ll_find(cronlist, item, jobequal);
	while(remove != 0) {
		cronlist = ll_remove(cronlist,remove);
		ll_destroy(remove);
		remove	= ll_find(cronlist, item, jobequal);
	} 

	ll_destroy(item);
}
Beispiel #17
0
int remove_scale(int pos){
  node_t* temp_node;

  if (!(temp_node = ll_get_node(&scale_list, pos))){
    printf("remove scale error: scale %d not found\n", pos);
    return 0;
  }

  ll_remove(temp_node, &scale_list);

  return 0;
}
/* The malloc() function allocates size bytes and returns a pointer to
 * the allocated memory. The memory is not initialized. If size is 0,
 * then malloc() returns either NULL, or a unique pointer value that can
 * later be successfully passed to free().
 * ----
 * Implementation notes:
 * So, somebody wants a block of memory... fine!  Here's the game
 * plan for getting them said memory:
 * 
 * 1) Scan each block in our free list to see if any of them are
 *    big enough.  If we find one that is big enough, we will
 *    either use that memory as-is or chunk it into a couple smaller
 *    pieces (part of which is used, the other which is a new
 *    entry in the free linked list.
 * 2) If we do not find an item in the free list, we will add the
 *    new block onto the end of our heap.  We will attempt to expand
 *    the heap if needed.
 */
void * po_malloc(size_t size)
{
    block_header_t *current_header, *new_free_header, *block_header;
    void *memory_to_use = NULL;
    const size_t size_plus_header = size + sizeof(block_header_t);
    new_free_header = block_header = NULL;
    current_header = free_ll_head;
    while (current_header) {
        if (current_header->block_length >= size) {
            memory_to_use = FREE_BLOCK_MEMORY(current_header);
            if (current_header->block_length > size_plus_header) {
                new_free_header = (block_header_t *)((unsigned long)memory_to_use + size);
                new_free_header->block_length = current_header->block_length - size;
                ll_replace(current_header, new_free_header);
             } else {
            	 ll_remove(current_header);
             }
            return memory_to_use;
        } else {
            current_header = current_header->next_free_chunk;
        }
    }

    // if we are here, we didn't get what we needed from scanning the
    // freed list, tack on to the end of memory
    size_t expand_size;
    if (current_header) {
    	expand_size = (size_plus_header - current_header->block_length);
    } else {
    	expand_size = size_plus_header;
    }
    block_header = (block_header_t *)sbrk(expand_size);
    memory_to_use = FREE_BLOCK_MEMORY(block_header);
    if (!block_header) {
    	/* failed to allocate more memory, return NULL */
    	return NULL;
    }

    /* current_header points to end of current LL unless first */
	block_header->next_free_chunk = NULL;
	block_header->prev_free_chunk = NULL;
	block_header->block_length = size;
    return memory_to_use;
}
Beispiel #19
0
void top_unsubscribe(char *name, unsigned long id) {
    Topic *st;

    if (tshm_get(topicTable, name, (void **)&st)) {
        long n;
        unsigned long entId;

        /* remove entry that matches au->id */
        pthread_mutex_lock(&(st->lock));
        for(n = 0; n < ll_size(st->regAUs); n++) {
            (void)ll_get(st->regAUs, n, (void **)&entId);
            if (entId == id) {
                (void)ll_remove(st->regAUs, n, (void **)&entId);
                break;
            }
        }
        pthread_mutex_unlock(&(st->lock));
    }
}
Beispiel #20
0
/* WARNING: This does not sync!!! */
void remove_element(cache_t *c, struct ce_t *o, int locked)
{
	if(!o) return;
	if(o->dirty)
		panic(PANIC_NOSYNC, "tried to remove non-sync'd element");
	
	if(!locked) rwlock_acquire(c->rwl, RWL_WRITER);
	if(o->dirty)
		set_dirty(c, o, 0);
	assert(c->count);
	sub_atomic(&c->count, 1);
	ll_remove(&c->primary_ll, o->list_node);
	if(c->hash) chash_delete(c->hash, o->id, o->key);
	if(o->data)
		kfree(o->data);
	rwlock_destroy(o->rwl);
	kfree(o);
	if(!locked) rwlock_release(c->rwl, RWL_WRITER);
}
Beispiel #21
0
/** \ingroup dbprim_hash
 * \brief Move an entry in the hash table.
 *
 * This function moves an existing entry in the hash table to
 * correspond to the new key.
 *
 * \param table	A pointer to a #hash_table_t.
 * \param entry	A pointer to a #hash_entry_t to be moved.  It must
 *		already be in the hash table.
 * \param key	A pointer to a #db_key_t describing the new key for
 *		the entry.
 *
 * \retval DB_ERR_BADARGS	An invalid argument was given.
 * \retval DB_ERR_UNUSED	Entry is not in a hash table.
 * \retval DB_ERR_WRONGTABLE	Entry is not in this hash table.
 * \retval DB_ERR_FROZEN	Hash table is frozen.
 * \retval DB_ERR_DUPLICATE	New key is a duplicate of an existing
 *				key.
 * \retval DB_ERR_READDFAILED	Unable to re-add entry to table.
 */
unsigned long
ht_move(hash_table_t *table, hash_entry_t *entry, db_key_t *key)
{
  unsigned long retval;

  initialize_dbpr_error_table(); /* initialize error table */

  if (!ht_verify(table) || !he_verify(entry) || !key) /* verify arguments */
    return DB_ERR_BADARGS;

  if (!entry->he_table) /* it's not in a table */
    return DB_ERR_UNUSED;
  if (entry->he_table != table) /* it's in the wrong table */
    return DB_ERR_WRONGTABLE;

  if (table->ht_flags & HASH_FLAG_FREEZE) /* don't mess with frozen tables */
    return DB_ERR_FROZEN;

  if (!ht_find(table, 0, key)) /* don't permit duplicates */
    return DB_ERR_DUPLICATE;

  /* remove the entry from the table */
  if ((retval = ll_remove(&table->ht_table[entry->he_hash], &entry->he_elem)))
    return retval;

  /* rekey the entry */
  entry->he_key = *key; /* thank goodness for structure copy! */

  /* get the new hash value for the entry */
  entry->he_hash =
    (*table->ht_func)(table, &entry->he_key) % table->ht_modulus;

  /* Now re-add it to the table */
  if ((retval = ll_add(&table->ht_table[entry->he_hash], &entry->he_elem,
		       LINK_LOC_HEAD, 0))) {
    table->ht_count--; /* decrement the count--don't worry about shrinking */
    entry->he_table = 0; /* zero the table pointer */
    return DB_ERR_READDFAILED;
  }

  return 0;
}
Beispiel #22
0
int remove_scale_by_name(const char *name){
  scale_t* curr_scale;
  node_t* temp_node;

  for (temp_node=scale_list;temp_node;temp_node=temp_node->next){
    curr_scale = (scale_t*)temp_node->data;

    if (!(strcmp(name, scale_get_name(curr_scale))))
      break;
  }

  if (!temp_node){
    printf("get scale error: scale %s not found\n", name);
    return -1;
  }

  ll_remove(temp_node, &scale_list);

  return 0;
}
Beispiel #23
0
/** \ingroup dbprim_link
 * \brief Flush a linked list.
 *
 * This function flushes a linked list--that is, it removes each
 * element from the list.  If a \p flush_func is specified, it will be
 * called on the entry after it has been removed from the list, and
 * may safely call <CODE>free()</CODE>.
 *
 * \param list	A pointer to a #link_head_t.
 * \param flush_func
 *		A pointer to a callback function used to perform
 *		user-specified actions on an element after removing it
 *		from the list.  May be \c NULL.  See the documentation
 *		for #link_iter_t for more information.
 * \param extra	A \c void pointer that will be passed to \p
 *		flush_func.
 *
 * \retval DB_ERR_BADARGS	An argument was invalid.
 */
unsigned long
ll_flush(link_head_t *list, link_iter_t flush_func, void *extra)
{
  link_elem_t *elem;
  unsigned long retval;

  initialize_dbpr_error_table(); /* initialize error table */

  if (!ll_verify(list)) /* Verify arguments */
    return DB_ERR_BADARGS;

  while ((elem = list->lh_first)) { /* Walk through the list... */
    ll_remove(list, elem); /* remove the element */
    /* call flush function, erroring out if it fails */
    if (flush_func && (retval = (*flush_func)(list, elem, extra)))
      return retval;
  }

  list->lh_count = 0; /* clear the list head */
  list->lh_first = 0;
  list->lh_last = 0;

  return 0;
}
Beispiel #24
0
int rtobject_update_instance_situation(rtobject_t* rtobj){
  int j;
  rtobject_instance_t* new_ins;
  node_t* temp_node;

  if (debug_readout) printf("updating instance situation for rtobject %d\n",\
			    rtobject_get_address(rtobj));

  /*
    If nothing is in the object's outdated instance list, we move all
    the current instances there, then duplicate all the current
    instances to form a new list of instances and modify the copies.
    Otherwise, this has been done already, but changes haven't been
    enacted and can be overwritten.  In either case we take the "new"
    instances and update their data, while leaving the "old" instances
    to be deallocated after the proclist is swapped out.
  */

  if (!rtobj->outdated_instance_list){

    /*swap instance list with outdated instance list*/
    rtobj->outdated_instance_list = rtobj->instance_list;
    rtobj->instance_list = 0;

    /*duplicate all current instances*/
    for (temp_node=rtobj->outdated_instance_list;\
	   temp_node;\
	   temp_node=temp_node->next){

      /*use copy allocator to duplicate each instance*/
      if (!(new_ins = rtobject_instance_alloca_copy((rtobject_instance_t*)temp_node->data))){
	printf("memory allocation error\n");
	return -1;
      }
          
      /*add duplicated instance to instance list*/
      if (!(ll_append(&rtobj->instance_list, (void*)new_ins))){
	printf("memory allocation error\n");
	return -1;
      }

    }

  }

  /*update new instances' data port lists*/
  for (temp_node=rtobj->instance_list;temp_node;temp_node=temp_node->next){
    new_ins = (rtobject_instance_t*)temp_node->data;
    
    for (j=0;j<rtobj->data_port_list_size;++j)
      new_ins->data_port_list[j] = data_port_get_buffer_struct(rtobject_get_data_port(rtobj,j));
    
  }

  /*handle implementation type specific instance updating*/
  /*TODO: make this done via uniformly named xxx_instance_attach fxn*/

  if (RTOBJECT_MAJOR_TYPE_SIGNAL_PATH == rtobject_get_major_type(rtobj)){

    for (temp_node=rtobj->instance_list;temp_node;temp_node=temp_node->next){
      new_ins = (rtobject_instance_t*)temp_node->data;
      
      /*erase old changes, will recreate*/
      while (new_ins->imp_data.signal_path_element.local_buffer_list){
	ll_remove(new_ins->imp_data.signal_path_element.local_buffer_list,\
		  &new_ins->imp_data.signal_path_element.local_buffer_list);
      }
     
      /*now we have a path instance w/ a blank context buffer list to
	be filled, fill it*/
      if ((init_instance_signal_path(rtobj,new_ins)) < 0){
	printf("failed attempt to initialize signal path instance\n");
	return -1;
      }

    }

  }

  if (RTOBJECT_IMP_TYPE_LADSPA_PLUGIN == rtobject_get_implementation_type(rtobj)){

    for (temp_node=rtobj->instance_list;temp_node;temp_node=temp_node->next){
      new_ins = (rtobject_instance_t*)temp_node->data;

      /*must call ladspa's connect port function to update plugin instance*/
      if ((attach_instance_ladspa_plugin(rtobj, new_ins)) < 0){
	printf("failed attempt to initialize LADSPA plugin instance\n");
	return -1;
      }

    }

  }

  return 0;
}
Beispiel #25
0
//-----------------------------------------------------------------------------
// make a blacklist query and call the handler function when we have an answer.
// 
// NOTE: that it is possible for the callback funcction to be called before
//       this function exits (if the result is already cached), so dont put
//       any important initialization of the passed in object after this call
//       is made.
rq_blacklist_id_t rq_blacklist_check(
	rq_blacklist_t *blacklist,
	struct sockaddr *address,
	int socklen,
	void (*handler)(rq_blacklist_status_t status, void *arg), void *arg)
{
	struct sockaddr_in *sin;
	ev_uint32_t ip;
	cache_entry_t *entry;
	struct timeval tv;
	time_t curtime;
	rq_message_t *msg;
	cache_waiting_t *waiting;
	rq_blacklist_id_t id;

	assert(blacklist);
	assert(address);
	assert(socklen > 0);
	assert(handler);
	assert(arg);

	// convert 'address' into a 32bit uint.
	sin = (struct sockaddr_in *) address;
	ip = sin->sin_addr.s_addr;

	// get the current time in seconds.
	gettimeofday(&tv, NULL);
	curtime=tv.tv_sec;

	// check the cache for the address.
	assert(blacklist->cache);
	ll_start(blacklist->cache);
	entry = ll_next(blacklist->cache);
	while (entry) {
		if (entry->ip == ip) {
			// check to see if entry has expired.
			assert(entry->expires > 0);
			if (entry->expires <= curtime) {
				// cached entry has expired, so we need to remove it from the list.
				ll_remove(blacklist->cache, entry);
				free(entry);
			}
			else {
				// entry is in the list, so we call the handler, and then we return 0.
				handler(entry->status, arg);
				ll_finish(blacklist->cache);
				return(0);
			}
			entry = NULL;
		}
		else {
			entry = ll_next(blacklist->cache);
		}
	}
	ll_finish(blacklist->cache);
	
	// if we got this far, then the entry was not found in the cache, so we need
	// to send a request to the queue.

	// get the next id.
	id = next_id(blacklist);

	// create the structure that will hold the information we are waiting on, and add it to the tail of the list.
	waiting = (cache_waiting_t *)  malloc(sizeof(cache_waiting_t));
	assert(waiting);
	waiting->id = id;
	waiting->ip = ip;
	waiting->arg = arg;
	waiting->blacklist = blacklist;
	waiting->msg = NULL;
	waiting->handler = handler;
	ll_push_tail(blacklist->waiting, waiting);

	// now create a message object so we can send the message
	assert(blacklist->queue);
	assert(blacklist->rq);
	msg = rq_msg_new(blacklist->rq, NULL);
	assert(msg);
	assert(msg->data);

	// apply the queue that we are sending a request for.
	rq_msg_setqueue(msg, blacklist->queue);

	// build the command payload.
	rq_msg_addcmd(msg, BL_CMD_CLEAR);
// 	rq_msg_addcmd(msg, BL_CMD_NOP);
	rq_msg_addcmd_largeint(msg, BL_CMD_IP, ip);
	rq_msg_addcmd(msg, BL_CMD_CHECK);

	// message has been prepared, so send it.
	// TODO: add fail handler.
	rq_send(msg, blacklist_handler, NULL, waiting);
	msg = NULL;

	return(id);
}
Beispiel #26
0
int
main(int argc, char **argv)
{
    int c = 0;
    llist_t* list = 0;
    node_t* aux = 0;


    list = ll_create();
    ll_initialize(list, free, compare_int_data);

    /* 0...9 */
    for(; c < 10; c++)
        ll_add_last(list, create_node( create_int_data(c) ) );

    /* 10 0...9 */
    ll_add_first(list, create_node( create_int_data(c) ) );

    /* 11 10 0...9 */
    ll_add_first(list, create_node( create_int_data(++c) ) );

    /* 11 10 12 0...9 */
    ll_add_before(list, list->first->next->next, create_node( create_int_data(++c) ) );

    /* 11 10 12 0...8 13 9 */
    ll_add_after(list, list->last->prev, create_node( create_int_data(++c) ));

    /* 11 10 12 0...8 13 14 9 */
    ll_add_after(list, list->last->prev, create_node( create_int_data(++c) ));

    /* 11 12 0...8 13 14 9	*/
    ll_remove(list, list->first->next, DESTROYNODE );

    /* 11 12 0...8 13 14 */
    ll_remove(list, list->last, DESTROYNODE);

    /* 12 0...8 13 14 */
    ll_remove(list, list->first, DESTROYNODE);

    /* to test "NOTDESTROY" option*/
    aux = list->last->prev;

    /* 12 0...8 14 */
    ll_remove(list, list->last->prev, NOTDESTROY);

    printf("\n");

    /* Forward: 12 0...8 14	*/
    ll_traverse(list, print_int_data, FORWARDTRAVERSE);
    printf("\n");

    /* Backward: 14 8...0 12 */
    ll_traverse(list, print_int_data, BACKWARDTRAVERSE);
    printf("\n\n");

    /* Destroy node	"13"*/
    free_node(aux, list->free_data);
    printf("\n");

    /* Deleted node, is not found*/
    int a = 10;
    aux = ll_search_node(list, &a);

    if(aux != NULL)
        printf("NODE: %p DATA: %d\n", aux ,*(int*)DATA(aux));

    a = 4;
    aux = ll_search_node(list, &a);

    if(aux != NULL)
        printf("NODE: %p DATA: %d\n", aux ,*(int*)DATA(aux));


    ll_free(list);
    list = 0;
    return EXIT_SUCCESS;
}
Beispiel #27
0
char* rtobject_get_absolute_pathname(rtobject_t* rtobj){
  /*bloatware fxn that allocates a new string containing absolute
    pathname of rtobject*/
  rtobject_t* local_rtobj;
  ll_head pwd_list;
  node_t* temp_node;
  int path_len,i;
  char *path;

  pwd_list = 0;

  /*first find rtobject's path rtobject*/
  local_rtobj = rtobject_get_parent(rtobj);
   
  /*work up tree towards root, adding each name to a linked list*/
  while (!(signal_path_is_master_path((signal_path_t*)local_rtobj->imp_struct))){

    ll_append(&pwd_list,(void*)local_rtobj);
    local_rtobj = rtobject_get_parent(local_rtobj);

  }
   
  /*walk list to find length of pathname, remember pathname includes name*/
  /*precede each object name with '/' */
  path_len = 1 + strlen(rtobject_get_name(rtobj));
  for (temp_node=pwd_list;temp_node;temp_node=temp_node->next){
    path_len += (1 + strlen(rtobject_get_name((rtobject_t*)temp_node->data)));
  }

  /*remember ending null*/
  path_len++;

  /*allocate string to hold pathname*/
  if (!(path = (char*)malloc(path_len * sizeof(char)))){
    printf("error rtobject get absolute pathname memory error\n");
    return 0;
  }
    
  /*walk list backwards to fill path*/
  i=0;
  if (pwd_list){
    temp_node = pwd_list;
    while(temp_node->next) temp_node=temp_node->next;
    for (;temp_node;temp_node=temp_node->previous){
      path[i++] = '/';
      strncpy(&path[i],\
	      rtobject_get_name((rtobject_t*)temp_node->data),\
	      strlen(rtobject_get_name((rtobject_t*)temp_node->data)));
      i += strlen(rtobject_get_name((rtobject_t*)temp_node->data));
    }
  }

  /*rtobject name*/
  path[i++] = '/';
  strncpy(&path[i], rtobject_get_name(rtobj), strlen(rtobject_get_name(rtobj)));
  path[path_len - 1] = '\0'; /*strncpy seems to be f-ing this up*/

  /*free the list*/
  while (pwd_list) ll_remove(pwd_list,&pwd_list);

  return path;
}
Beispiel #28
0
int main(int argc, char** argv) {
    llist *l = malloc(sizeof(llist));
    
    const int reference[11] = {20, 19, 18, 14, 12, 10, 8, 6, 4, 2, -1};
    const int size = sizeof(reference) / sizeof(int);
    
    int error = 1;
    
    // Add numbers 20, 18, 16, 14, ... 2, 0 to the list.
    {
        int i;
        for (i = 20; i >= 0; i -= 2) {
            ll_push(l, i);
        }
    }
    if (ll_size(l) != 11) {
        return error;
    }
    ll_print(l);
    error++;
    
    ll_pop(l);
    ll_push(l, -1);
    ll_insert(l, 1, 19);
    ll_remove(l, 3);
    printf("Phase 2 complete (pop, push, insert, remove).\n");
    
    // Check first and last index.
    if (l -> first -> value != reference[0]) {
        return error;
    }
    printf("Phase 3A complete (check first value).\n");
    error++;
    
    if (l -> last -> value != reference[size - 1]) {
        return error;
    }
    printf("Phase 3B complete (check last value).\n");
    error++;
    
    // Check by traversing.
    {
        node *n = l -> first;
        int index = 0;
        while (n != NULL) {
            if (n -> value == reference[index++]) {
                n = n -> next;
            } else {
                return error;
            }
        }
    }
    printf("Phase 4A complete (traverse forward).\n");
    error++;
    
    // Check by backward traversing.
    {
        node *n = l -> last;
        int index = size - 1;
        while (n != NULL) {
            if (n -> value == reference[index--]) {
                n = n -> prev;
            } else {
                return error;
            }
        }
    }
    printf("Phase 4B complete (traverse backward).\n");
    error++;
    
    // Check by indexing.
    {
        int i;
        for (i = 0; i < ll_size(l); i++) {
            if (reference[i] != ll_get(l, i)) {
                return error;
            }
        }
    }
    printf("Phase 5 complete (iterate).\n");
    error++;
    
    printf("Completed without error.\n");
    return 0;
}
Beispiel #29
0
void rtobject_free_search_results(ll_head* results){
  while (*results){
    free((int*)(*results)->data);
    ll_remove(*results,results);
  }
}
void abLayer::removeSprite(abSprite *sprite) {
    ll_remove(sprites, sprite);
    toErase[toEraseCount++] = sprite;
}