示例#1
0
/** Filtering thread
 *
 * Loops until the stream is not active anymore, or an error occurs
 *
 * \param handle pointer to OmlMStream to use the filters on (cast as void*)
 *
 * \return NULL, inconditionally; shouldn't return in normal operation
 */
static void*
thread_start(void* handle)
{
    OmlMStream* ms = (OmlMStream*)handle;
    OmlMP* mp = ms->mp;
    useconds_t usec = (useconds_t)(1000000 * ms->sample_interval);
    int status = 0;

    while (1) {
        usleep(usec);
        if (!mp_lock(mp)) {
            if (!mp->active) {
                mp_unlock(mp);
                return NULL;  // we are done
            }

            status = filter_process(ms);
            mp_unlock(mp);
        }

        if (status == -1) {
            return NULL; // Fatal error --> exit thread
        }

    }
}
示例#2
0
static modulenode_t *_run(moduletree_t *modtree, modulenode_t *modnode)
{
	int next = 1;
	modulenode_t **child;
	int i;
	switch (modnode->type) {
	case MNTYPE_HEAD:
	case MNTYPE_MODULE:
		module_process(modnode);
		break;

	case MNTYPE_FILTER:
		filter_process(modnode);
		break;

	case MNTYPE_MERGER:
		if (!allset(modnode)) {
			next = 0;
			break;
		}
		merge_process(modnode);
		break;
	}
	if (next == 1) {
		for (i = 0; i < modnode->childsize; ++i) {
			_run(modtree, modnode->child[i]);
		}
	}
}
示例#3
0
BOOL filter_image(IMAGE* image, int filter_id) {
	FILTER filter = create_filter(filter_data[filter_id][0], filter_data[filter_id][1], filter_values[filter_id], filter_data[filter_id][2], filter_data[filter_id][3]);
	//add_extra_filter(&filter, filter_values[extra_filter_id], filter_data[extra_filter_id][0]*filter_data[extra_filter_id][1]);
	filter_process(&filter, image);

	return TRUE;
}
示例#4
0
文件: outgoing.c 项目: n8ohu/aprsc
static void process_outgoing_single(struct worker_t *self, struct pbuf_t *pb)
{
	struct client_t *c, *cnext;
	struct client_t *origin = pb->origin; /* reduce pointer deferencing in tight loops */
	
	/*
	// debug dump
	if (self->id == 0) {
		hlog(LOG_DEBUG, "o: %*s", pb->packet_len-2, pb->data);
		hlog(LOG_DEBUG, "b:%s%s",
			(pb->flags & F_FROM_UPSTR) ? " from_upstr" : "",
			(pb->flags & F_FROM_DOWNSTR) ? " from_downstr" : ""
			);
	}
	*/
	
	/* specific tight loops */
	
	if (pb->flags & F_DUPE) {
		/* Duplicate packet. Don't send, unless client especially wants! */
		for (c = self->clients_dupe; (c); c = cnext) {
			cnext = c->class_next; // client_write() MAY destroy the client object!
			if (c->state == CSTATE_CONNECTED)
				send_single(self, c, pb);
		}
		
		/* Check if I have the client which sent this dupe, and
		 * increment it's dupe counter
		 */
		/* OPTIMIZE: we walk through all clients for each dupe - how to find it quickly? */
		for (c = self->clients; (c); c = c->next) {
			if (c == origin) {
				clientaccount_add(c, -1, 0, 0, 0, 0, 0, 1);
				break;
			}
		}
		
		return;
	}

	if (pb->flags & F_FROM_DOWNSTR) {
		/* client is from downstream, send to upstreams and peers */
		for (c = self->clients_ups; (c); c = cnext) {
			cnext = c->class_next; // client_write() MAY destroy the client object!
			if ((c->state == CSTATE_CONNECTED || c->state == CSTATE_COREPEER) && c != origin)
				send_single(self, c, pb);
		}
	}
	
	/* packet came from anywhere and is not a dupe - let's go through the
	 * clients who connected us
	 */
	for (c = self->clients_other; (c); c = cnext) {
		cnext = c->class_next; // client_write() MAY destroy the client object!
		
		/* Do not send to clients that are not logged in. */
		if (c->state != CSTATE_CONNECTED) {
			//hlog(LOG_DEBUG, "%d/%s: not sending to client: not connected", c->fd, c->username);
			continue;
		}
		
		/* If not full feed, process filters to see if the packet should be sent. */
		if (( (c->flags & CLFLAGS_FULLFEED) != CLFLAGS_FULLFEED) && filter_process(self, c, pb) < 1) {
			//hlog(LOG_DEBUG, "fd %d: Not fullfeed or not matching filter, not sending.", c->fd);
			continue;
		}
		
		/* Do not send packet back to the source client.
		   This may reject a packet that came from a socket that got
		   closed a few milliseconds ago and its client_t got
		   recycled on a newly connected client, but if the new client
		   is a long living one, all further packets will be accepted
		   just fine.
		   For packet history dumps this test shall be ignored!
		   Very unlikely check, so check for this last.
		 */
		if (c == origin) {
			//hlog(LOG_DEBUG, "%d: not sending to client: originated from this socketsocket", c->fd);
			continue;
		}
		
		send_single(self, c, pb);
	}
}