virtual void get_rate_limit(xmlrpc_c::paramList const& paramList, xmlrpc_c::value* retvalP) {
		ACE_TRACE("modEmulateRate_Interface::get_rate");
		int rate = 0;

		if (paramList.size() > 2 ) {
			rate = find_handler(paramList)->getRateLimitAtTime(paramList.getDouble(2));
		}
		else {
			rate = find_handler(paramList)->getRateLimit();
		}

		*retvalP = xmlrpc_c::value_double(rate);
	}
Exemplo n.º 2
0
GList *
gnc_find_gui_components (const char *component_class,
                         GNCComponentFindHandler find_handler,
                         gpointer find_data)
{
    GList *list = NULL;
    GList *node;

    if (!component_class)
        return NULL;

    for (node = components; node; node = node->next)
    {
        ComponentInfo *ci = node->data;

        if (g_strcmp0 (component_class, ci->component_class) != 0)
            continue;

        if (find_handler && !find_handler (find_data, ci->user_data))
            continue;

        list = g_list_prepend (list, ci->user_data);
    }

    return list;
}
Exemplo n.º 3
0
int KSGDevice::create_handler(KSGDeviceNode*node,ACE_HANDLE* handler)
{
	ACE_HANDLE oldhandler;
	int ret;
	ret = make_handler(node,handler);
	if(ret == 0)
	{
		ret = find_handler(node,&oldhandler);
		if(ret == 0)
		{
			close_handler(node,oldhandler);
		}
		save_handler(node,*handler);
		return 0;
	}
	else if(ret > 0)
	{
		if(node->GetParent() && node->GetParent()->GetDevice())
			ret = node->GetParent()->GetDevice()->create_handler(node->GetParent(),handler);
		return ret;
	}
	else
	{
		return -1;
	}
}
Exemplo n.º 4
0
Arquivo: use.c Projeto: DevL/ponyc
// Handle a uri command
static bool uri_command(ast_t* ast, ast_t* uri, ast_t* alias, ast_t* guard,
  pass_opt_t* options)
{
  assert(uri != NULL);
  assert(alias != NULL);
  assert(guard != NULL);

  const char* locator;
  int index = find_handler(uri, &locator);

  if(index < 0) // Scheme not found
    return false;

  if(ast_id(alias) != TK_NONE && !handlers[index].allow_name)
  {
    ast_error(alias, "Use scheme %s may not have an alias",
      handlers[index].scheme);
    return false;
  }

  if(ast_id(guard) != TK_NONE && !handlers[index].allow_guard)
  {
    ast_error(alias, "Use scheme %s may not have a guard",
      handlers[index].scheme);
    return false;
  }

  if(!ifdef_cond_eval(guard, options))
    return true;

  assert(handlers[index].handler != NULL);
  return handlers[index].handler(ast, locator, alias, options);
}
	virtual void clear_timeline(xmlrpc_c::paramList const& paramList, xmlrpc_c::value* retvalP) {
		ACE_TRACE("modEmulateRate_Interface::clear_timeline");

		find_handler(paramList)->clearTimeLine();

		*retvalP = xmlrpc_c::value_nil();
	}
Exemplo n.º 6
0
unsigned int avctp_register_pdu_handler(struct avctp *session, uint8_t opcode,
						avctp_control_pdu_cb cb,
						void *user_data)
{
	struct avctp_channel *control = session->control;
	struct avctp_pdu_handler *handler;
	static unsigned int id = 0;

	if (control == NULL)
		return 0;

	handler = find_handler(control->handlers, opcode);
	if (handler)
		return 0;

	handler = g_new(struct avctp_pdu_handler, 1);
	handler->opcode = opcode;
	handler->cb = cb;
	handler->user_data = user_data;
	handler->id = ++id;

	control->handlers = g_slist_append(control->handlers, handler);

	return handler->id;
}
Exemplo n.º 7
0
/* Function: al_open_video
 */
ALLEGRO_VIDEO *al_open_video(char const *filename)
{
   ALLEGRO_VIDEO *video;
   const char *extension = filename + strlen(filename) - 1;

   while ((extension >= filename) && (*extension != '.'))
      extension--;
   video = al_calloc(1, sizeof *video);
   
   video->vtable = find_handler(extension);

   if (video->vtable == NULL) {
      ALLEGRO_ERROR("No handler for video extension %s - "
         "therefore not trying to load %s.\n", extension, filename);
      al_free(video);
      return NULL;
   }
   
   video->filename = al_create_path(filename);
   video->playing = true;

   if (!video->vtable->open_video(video)) {
      ALLEGRO_ERROR("Could not open %s.\n", filename);
      al_destroy_path(video->filename);
      al_free(video);
      return NULL;
   }
   
   al_init_user_event_source(&video->es);
   video->es_inited = true;
   
   return video;
}
	void rebuild_encoder(xmlrpc_c::paramList const& paramList, xmlrpc_c::value* retvalP) {
		ACE_TRACE("modRSEncode_Interface::rebuild_encoder");
			
		find_handler(paramList)->rebuildEncoder();
		
		*retvalP = xmlrpc_c::value_nil();
	}
Exemplo n.º 9
0
/***********************************************************************
 *           process_events
 */
static int process_events( Display *display, ULONG_PTR mask )
{
    XEvent event;
    HWND hwnd;
    int count = 0;
    x11drv_event_handler handler;

    wine_tsx11_lock();
    while (XCheckIfEvent( display, &event, filter_event, (char *)mask ))
    {
        count++;
        if (XFilterEvent( &event, None )) continue;  /* filtered, ignore it */

        if (!(handler = find_handler( event.type )))
        {
            TRACE( "%s, ignoring\n", dbgstr_event( event.type ));
            continue;  /* no handler, ignore it */
        }

        if (XFindContext( display, event.xany.window, winContext, (char **)&hwnd ) != 0)
            hwnd = 0;  /* not for a registered window */
        if (!hwnd && event.xany.window == root_window) hwnd = GetDesktopWindow();

        wine_tsx11_unlock();
        TRACE( "%s for hwnd/window %p/%lx\n",
               dbgstr_event( event.type ), hwnd, event.xany.window );
        handler( hwnd, &event );
        wine_tsx11_lock();
    }
    XFlush( gdi_display );
    wine_tsx11_unlock();
    if (count) TRACE( "processed %d events\n", count );
    return count;
}
Exemplo n.º 10
0
int KSGDevice::ExecuteTask(DeviceNodeType* node,Task* task)
{
	// 检查是否支持指令
	DI * devintr = FindDevInterface(task->GetTaskCode());
	if(!devintr)
	{
		throw TaskNotSupportedException();
	}
	//
	int ret;
	ACE_HANDLE handler;
	ret = find_handler(node,&handler);
	if(ret)
	{
		ACE_DEBUG((LM_ERROR,"连接指定设备失败!"));
		return TASK_ERR_CONNECT;
	}
	// 执行指令
	try
	{
		task->_handle = handler;
		ret = devintr->ExecuteTask(node,task);
	}
	catch(...)
	{
		// ignore
	}
	// 如果指令执行超时,关闭连接
	if(release_handler(node,&handler,ret != TASK_SUCCESS))
	{
		ACE_DEBUG((LM_ERROR,"释放连接失败"));
	}
	return ret;
}
Exemplo n.º 11
0
static int
UdpAliasOut(struct libalias *la, struct ip *pip, int create)
{
    struct udphdr *ud;
    struct alias_link *lnk;
    int error;

    LIBALIAS_LOCK_ASSERT(la);
/* Return if proxy-only mode is enabled */
    if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY)
        return (PKT_ALIAS_OK);

    ud = (struct udphdr *)ip_next(pip);

    lnk = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst,
        ud->uh_sport, ud->uh_dport,
        IPPROTO_UDP, create);
    if (lnk != NULL) {
        u_short alias_port;
        struct in_addr alias_address;
        struct alias_data ad;
        ad.lnk = lnk;
        ad.oaddr = NULL;
        ad.aaddr = &alias_address;
        ad.aport = &alias_port;
        ad.sport = &ud->uh_sport;
        ad.dport = &ud->uh_dport;
        ad.maxpktsize = 0;

        alias_address = GetAliasAddress(lnk);
        alias_port = GetAliasPort(lnk);

        /* Walk out chain. */
        error = find_handler(OUT, UDP, la, pip, &ad);

/* If UDP checksum is not zero, adjust since source port is */
/* being aliased and source address is being altered        */
        if (ud->uh_sum != 0) {
            int accumulate;

            accumulate = ud->uh_sport;
            accumulate -= alias_port;
            accumulate += twowords(&pip->ip_src);
            accumulate -= twowords(&alias_address);
            ADJUST_CHECKSUM(accumulate, ud->uh_sum);
        }
/* Put alias port in UDP header */
        ud->uh_sport = alias_port;

/* Change source address */
        DifferentialChecksum(&pip->ip_sum,
            &alias_address, &pip->ip_src, 2);
        pip->ip_src = alias_address;

        return (PKT_ALIAS_OK);
    }
    return (PKT_ALIAS_IGNORED);
}
Exemplo n.º 12
0
PUBLIC
bool
Jdb_kobject::handle_obj(Kobject *o, int lvl)
{
  if (Jdb_kobject_handler *h = find_handler(o))
    return h->show_kobject(o, lvl);

  return true;
}
Exemplo n.º 13
0
int
parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout )
{
	int r;
	struct handler * h;
	vector cmdvec = NULL;
	struct timespec tmo;

	r = get_cmdvec(cmd, &cmdvec);

	if (r) {
		*reply = genhelp_handler(cmd, r);
		*len = strlen(*reply) + 1;
		return 0;
	}

	h = find_handler(fingerprint(cmdvec));

	if (!h || !h->fn) {
		*reply = genhelp_handler(cmd, EINVAL);
		*len = strlen(*reply) + 1;
		free_keys(cmdvec);
		return 0;
	}

	/*
	 * execute handler
	 */
	if (clock_gettime(CLOCK_MONOTONIC, &tmo) == 0) {
		tmo.tv_sec += timeout;
	} else {
		tmo.tv_sec = 0;
	}
	if (h->locked) {
		int locked = 0;
		struct vectors * vecs = (struct vectors *)data;

		pthread_cleanup_push(cleanup_lock, &vecs->lock);
		if (tmo.tv_sec) {
			r = timedlock(&vecs->lock, &tmo);
		} else {
			lock(&vecs->lock);
			r = 0;
		}
		if (r == 0) {
			locked = 1;
			pthread_testcancel();
			r = h->fn(cmdvec, reply, len, data);
		}
		pthread_cleanup_pop(locked);
	} else
		r = h->fn(cmdvec, reply, len, data);
	free_keys(cmdvec);

	return r;
}
Exemplo n.º 14
0
int
set_handler_callback (unsigned long fp, int (*fn)(void *, char **, int *, void *))
{
	struct handler * h = find_handler(fp);

	if (!h)
		return 1;
	h->fn = fn;
	return 0;
}
Exemplo n.º 15
0
//---------------------------------------------------------------------------------------
void Observer::remove_old_handler(int eventType)
{
    std::list<EventCallback*>::iterator it = find_handler(eventType);
    if (it != m_handlers.end())
    {
        EventCallback* pCB = *it;
        m_handlers.erase(it);
        delete pCB;
    }
}
Exemplo n.º 16
0
int
set_handler_callback (uint64_t fp, int (*fn)(void *, char **, int *, void *))
{
	struct handler * h = find_handler(fp);

	if (!h)
		return 1;
	h->fn = fn;
	h->locked = 1;
	return 0;
}
Exemplo n.º 17
0
int vsavefile(char *newfilename ){
	imageHandler *ih;
	int handleno = 0;
	handleno = find_handler(newfilename);
	if( handleno == -1){
		printf(" We cannot handle this kind of files\n");
		return FALSE;
	}
	ih=imagehandlers[handleno];
	ih->savefile(newfilename);
}	
Exemplo n.º 18
0
int vdrawImage(char *filename){
	imageHandler *ih;
	int handleno = 0;
	handleno = find_handler(filename);
	printf(" handle no = %d\n", handleno);
	if( handleno == -1){
		printf(" We cannot handle this kind of files\n");
		return FALSE;
	}
	ih=imagehandlers[handleno];
	ih->drawImage(filename);	
	return FALSE;		
}
Exemplo n.º 19
0
Arquivo: rtnl.c Projeto: ebichu/dd-wrt
static int call_handler(struct rtnl_handle *rtnl_handle,
			u_int16_t type,
			struct nlmsghdr *hdr)
{
	struct rtnl_handler *h = find_handler(rtnl_handle, type);

	if (!h) {
		rtnl_log(LOG_DEBUG, "no registered handler for type %u", type);
		return 0;
	}

	return (h->handlefn)(hdr, h->arg);
}
	void set_fill_pattern(xmlrpc_c::paramList const& paramList, xmlrpc_c::value* retvalP) {
		ACE_TRACE("modTM_VC_Gen_Packet_Interface::set_fill_pattern");
		const std::vector<xmlrpc_c::value> xml_rpc_pattern = paramList.getArray(2);

		std::vector<uint8_t> fillPattern;

		for (unsigned i = 0; i < xml_rpc_pattern.size(); i++ ) {
			fillPattern[i] = xmlrpc_c::value_int(xml_rpc_pattern[i]);
		}

		find_handler(paramList)->setFillPattern(fillPattern);

		*retvalP = xmlrpc_c::value_nil();
	}
	void get_fill_pattern(xmlrpc_c::paramList const& paramList, xmlrpc_c::value* retvalP) {
		ACE_TRACE("modTM_VC_Gen_Packet_Interface::get_fill_pattern");

		std::vector<uint8_t> fillPattern;
		find_handler(paramList)->getFillPattern(fillPattern);

		std::vector<xmlrpc_c::value> xml_rpc_pattern;

		for (unsigned i = 0; i < fillPattern.size(); i++ ) {
			xml_rpc_pattern[i] = xmlrpc_c::value_int(fillPattern[i]);
		}

		*retvalP = xmlrpc_c::value_array(xml_rpc_pattern);
	}
Exemplo n.º 22
0
void
maybe_start_try (int start_pc, int end_pc)
{
  struct eh_range *range;
  if (! doing_eh ())
    return;

  range = find_handler (start_pc);
  while (range != NULL_EH_RANGE && range->start_pc == start_pc
	 && range->end_pc < end_pc)
    range = range->outer;
	 
  current_range = range;
  check_start_handlers (range, start_pc);
}
Exemplo n.º 23
0
//////////////////////////////////////////////////////////////////////////
// KSGDevice
int KSGDevice::ExecuteTask(DeviceNodeType* node,Task* task)
{
	// 检查是否支持指令
	DI * devintr = FindDevInterface(task->GetTaskCode());
	if(!devintr)
	{
		throw TaskNotSupportedException();
	}
	//
	int ret;
	ACE_HANDLE handler;
	// 先检查 handler 是否可用
	if(node->GetState() == KSGDeviceNode::dsOffline)
	{
		ret = create_handler(node,&handler);
	}
	else if((ret = find_handler(node,&handler)))
	{
		// 尝试连接
		ret = create_handler(node,&handler);
		if(ret)
		{
			// 连接失败
			node->SetState(KSGDeviceNode::dsOffline);
		}
	}
	if(ret)
	{
		return TASK_ERR_CONNECT;
	}
	
	// 执行指令
	ret = devintr->ExecuteTask(node,task);
	if(ret)
	{
		// 如果指令执行超时
		if(ret == TASK_ERR_TIMEOUT)
		{
			// 尝试重新连接
			if(create_handler(node,&handler))
			{
				// 重连失败
				node->SetState(KSGDeviceNode::dsError);
			}
		}
	}
	return ret;
}
Exemplo n.º 24
0
int KSGDevice::ExecuteTask(DeviceNodeType* node,Task* task)
{
	// 检查是否支持指令
	bool free_conn = false;
	DI devintr = FindDevInterface(task->GetTaskCode());
	if(!devintr)
	{
		throw TaskNotSupportedException();
	}
	//
	int ret;
	ACE_HANDLE handler;
	ret = find_handler(node,&handler);
	if(ret)
	{
		ACE_DEBUG((LM_ERROR,"连接指定设备失败!"));
		return TASK_ERR_CONNECT;
	}
	// 执行指令
	try
	{
		task->_handle = handler;
		ret = devintr->ExecuteTask(node,task);
	}
	catch(...)
	{
		// ignore
	}
	// 如果指令执行超时,关闭连接
	if(node->connect_module() == KSGDeviceNode::cm_short_conn
		|| ret != TASK_SUCCESS)
	{
		free_conn = true;
	}
	try
	{
		if(release_handler(node,&handler,free_conn))
		{
			ACE_DEBUG((LM_ERROR,"释放连接失败"));
		}
	}
	catch (...)
	{
		ACE_DEBUG((LM_ERROR,"关闭连接异常!"));
	}
	return ret;
}
	virtual void set_rate_limit(xmlrpc_c::paramList const& paramList, xmlrpc_c::value* retvalP) {
		ACE_TRACE("modEmulateRate_Interface::set_rate");
		int rate = 0, startTime = -1.0;

		if ( paramList[2].type() != xmlrpc_c::value::TYPE_ARRAY ) {
			rate = paramList.getInt(2);
		}
		else {
			const std::vector<xmlrpc_c::value> arrayData = paramList.getArray(2);
			startTime = xmlrpc_c::value_double(arrayData[0]);
			rate = xmlrpc_c::value_double(arrayData[1]);
		}

		find_handler(paramList)->setRateLimit(rate, startTime);

		*retvalP = xmlrpc_c::value_nil();
	}
Exemplo n.º 26
0
static void parse_listener(struct config *c, struct config_line *l,
                           struct lwan *lwan)
{
    free(lwan->config.listener);
    lwan->config.listener = strdup(l->value);

    while (config_read_line(c, l)) {
        switch (l->type) {
        case CONFIG_LINE_TYPE_LINE:
            config_error(c, "Expecting prefix section");
            return;
        case CONFIG_LINE_TYPE_SECTION:
            if (streq(l->key, "prefix")) {
                parse_listener_prefix(c, l, lwan, NULL, NULL);
                continue;
            }

            if (l->key[0] == '&') {
                l->key++;

                void *handler = find_handler(l->key);
                if (handler) {
                    parse_listener_prefix(c, l, lwan, NULL, handler);
                    continue;
                }

                config_error(c, "Could not find handler name: %s", l->key);
                return;
            }

            const struct lwan_module *module = find_module(l->key);
            if (module) {
                parse_listener_prefix(c, l, lwan, module, NULL);
                continue;
            }

            config_error(c, "Invalid section or module not found: %s", l->key);
            return;
        case CONFIG_LINE_TYPE_SECTION_END:
            return;
        }
    }

    config_error(c, "Expecting section end while parsing listener");
}
Exemplo n.º 27
0
unsigned int avctp_register_pdu_handler(uint8_t opcode, avctp_pdu_cb cb,
							void *user_data)
{
	struct avctp_pdu_handler *handler;
	static unsigned int id = 0;

	handler = find_handler(handlers, opcode);
	if (handler)
		return 0;

	handler = g_new(struct avctp_pdu_handler, 1);
	handler->opcode = opcode;
	handler->cb = cb;
	handler->user_data = user_data;
	handler->id = ++id;

	handlers = g_slist_append(handlers, handler);

	return handler->id;
}
Exemplo n.º 28
0
static void handle_input_line(shell_t *shell, char* line) {
    char* saveptr;
    char* linedup = strdup(line);
    char* command = strtok_r(linedup, " ", &saveptr);

    void (*handler)(char*) = NULL;
    
    if (command) {
        handler = find_handler(shell->command_list, command);
        if (handler != NULL) {
            handler(line);
        } else {
            if ( strcmp("help", command) == 0) {
                print_help(shell->command_list);
            } else {
                puts("shell: command not found.");
            }
        }
    }

    free(linedup);
}
Exemplo n.º 29
0
int KSGDevice::ExecuteTask(DeviceNodeType* node,Task* task)
{
	// 检查是否支持指令
	bool free_conn = false;
	DI devintr = FindDevInterface(task->GetTaskCode());
	if(!devintr)
	{
		ACE_DEBUG((LM_ERROR,"设备不支持该指令..."));
		throw TaskNotSupportedException();
	}
	//
	int ret;
	ACE_HANDLE handler;
	ret = find_handler(node,&handler);
	if(ret)
	{
		ACE_DEBUG((LM_ERROR,"连接指定设备失败!"));
		return TASK_ERR_CONNECT;
	}
	// 执行指令
	try
	{
		task->_handle = handler;
		ret = devintr->ExecuteTask(node,task);
	}
	catch(...)
	{
		// ignore
	}

	if(node->connect_module() == KSGDeviceNode::cm_short_conn)
	{
		free_conn = true;
	}
	// 如果指令执行不成功
	else
	{
		//
		if(ret != TASK_SUCCESS)
		{
			if(ret == TASK_ERR_TIMEOUT)
				free_conn = true;
			else
			{
				ACE_Time_Value tv(1);
				int res = ACE::handle_exception_ready(task->_handle,&tv);
				if(res >0)
				{
					// 如果发生异常,则重连
					free_conn = true;
				}
				else if(res == 0) // 超时
				{
					free_conn = true;
				}
				else // 返回错误
				{

				}
			}
		}
	}
	
	try
	{
		if(release_handler(node,&handler,free_conn))
		{
			ACE_DEBUG((LM_ERROR,"释放连接失败"));
		}
	}
	catch (...)
	{
		ACE_DEBUG((LM_ERROR,"关闭连接异常!"));
	}
	return ret;
}
Exemplo n.º 30
0
static gboolean session_cb(GIOChannel *chan, GIOCondition cond,
				gpointer data)
{
	struct avctp *session = data;
	struct avctp_channel *control = session->control;
	uint8_t *buf = control->buffer;
	uint8_t *operands, code, subunit;
	struct avctp_header *avctp;
	struct avc_header *avc;
	int ret, packet_size, operand_count, sock;
	struct avctp_pdu_handler *handler;

	if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
		goto failed;

	sock = g_io_channel_unix_get_fd(chan);

	ret = read(sock, buf, control->imtu);
	if (ret <= 0)
		goto failed;

	if ((unsigned int) ret < sizeof(struct avctp_header)) {
		error("Too small AVCTP packet");
		goto failed;
	}

	avctp = (struct avctp_header *) buf;

	ret -= sizeof(struct avctp_header);
	if ((unsigned int) ret < sizeof(struct avc_header)) {
		error("Too small AVCTP packet");
		goto failed;
	}

	avc = (struct avc_header *) (buf + sizeof(struct avctp_header));

	ret -= sizeof(struct avc_header);

	operands = buf + sizeof(struct avctp_header) + sizeof(struct avc_header);
	operand_count = ret;

	if (avctp->cr == AVCTP_RESPONSE) {
		control_response(control, avctp, avc, operands, operand_count);
		return TRUE;
	}

	packet_size = AVCTP_HEADER_LENGTH + AVC_HEADER_LENGTH;
	avctp->cr = AVCTP_RESPONSE;

	if (avctp->packet_type != AVCTP_PACKET_SINGLE) {
		avc->code = AVC_CTYPE_NOT_IMPLEMENTED;
		goto done;
	}

	if (avctp->pid != htons(AV_REMOTE_SVCLASS_ID)) {
		avctp->ipid = 1;
		packet_size = AVCTP_HEADER_LENGTH;
		goto done;
	}

	handler = find_handler(control->handlers, avc->opcode);
	if (!handler) {
		DBG("handler not found for 0x%02x", avc->opcode);
		packet_size += avrcp_handle_vendor_reject(&code, operands);
		avc->code = code;
		goto done;
	}

	code = avc->code;
	subunit = avc->subunit_type;

	packet_size += handler->cb(session, avctp->transaction, &code,
					&subunit, operands, operand_count,
					handler->user_data);

	avc->code = code;
	avc->subunit_type = subunit;

done:
	ret = write(sock, buf, packet_size);
	if (ret != packet_size)
		goto failed;

	return TRUE;

failed:
	DBG("AVCTP session %p got disconnected", session);
	avctp_set_state(session, AVCTP_STATE_DISCONNECTED);
	return FALSE;
}