Пример #1
0
uint32_t hwt_delegate_rq_send(struct reconos_hwt *hwt) {
	int i;
	uint32_t handle, arg0, msg_size, *msg;

	handle = reconos_osif_read(hwt->osif);
	arg0 = reconos_osif_read(hwt->osif);

	resource_check_type(hwt, handle, RECONOS_RESOURCE_TYPE_RQ);

	msg_size = arg0;
	msg = malloc(msg_size);
	if (!msg)
		panic("rq_receive malloc failed\n");

	// read data from HWT
	for (i = 0; i < msg_size / sizeof(uint32_t); i++)
		msg[i] = reconos_osif_read(hwt->osif);

	// write data into rq
	rq_send(hwt->cfg->resource[handle].ptr, msg, msg_size);

	free(msg);

	return 0;
}
Пример #2
0
//-----------------------------------------------------------------------------
// Internal function used to send a formatted string to the logger.  It will
// generate all the appropriate commands, and then send it.  If the send was
// not able to complete, then it will add it to the outgoing buffer to be sent
// the next time.
static void rq_log_send(rq_log_t *log, unsigned short level, char *data, int length)
{
	rq_message_t *msg;
	rq_conn_t *conn;
	
	assert(log && data);
	assert(length > 0 && length < 0xffff);
	assert(level > 0);
	
	assert(log->queue);
	assert(log->rq);

	msg = rq_msg_new(log->rq, NULL);
	assert(msg);
	rq_msg_setqueue(msg, log->queue);
	
	rq_msg_addcmd(msg,          LOG_CMD_CLEAR);
	rq_msg_addcmd_shortint(msg, LOG_CMD_LEVEL, level);
	rq_msg_addcmd_str(msg,      LOG_CMD_TEXT, length, data);
	rq_msg_addcmd(msg,          LOG_CMD_EXECUTE);

	// message has been prepared, so send it.
	rq_send(msg, NULL, NULL, NULL);

	// msg is now controlled by the RQ system, so we set it to null so we dont
	// modify something we no longer control.
	msg = NULL;
}
Пример #3
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);
}