void TGameTimer::OnLoop() { if (enabled) { if (SDL_GetTicks() < old_time + timer_rate) return; #ifdef DEBUG std::cout << "Tick!" << std::endl; std::cout << "loop mode = " << loop_mode << std::endl; #endif old_time = SDL_GetTicks(); if (callback_func) callback_func(); switch(loop_mode) { case ONCE: enabled = false; break; case REPEATCOUNT: repeat_count += 1; if (repeat_count > max_repeat_count) enabled = false; break; case FOREVER: default: break; } } }
/*** * rt_udp_rcv */ int rt_udp_rcv (struct rtskb *skb) { struct rtsocket *sock = skb->sk; void (*callback_func)(struct rtdm_dev_context *, void *); void *callback_arg; unsigned long flags; rtskb_queue_tail(&sock->incoming, skb); rtos_event_sem_signal(&sock->wakeup_event); rtos_spin_lock_irqsave(&sock->param_lock, flags); #ifdef CONFIG_RTNET_RTDM_SELECT if (sock->wakeup_select != NULL) { wq_wakeup(sock->wakeup_select); } #endif /* CONFIG_RTNET_RTDM_SELECT */ callback_func = sock->callback_func; callback_arg = sock->callback_arg; rtos_spin_unlock_irqrestore(&sock->param_lock, flags); if (callback_func) callback_func(rt_socket_context(sock), callback_arg); return 0; }
/*** * rt_packet_rcv */ int rt_packet_rcv(struct rtskb *skb, struct rtpacket_type *pt) { struct rtsocket *sock = (struct rtsocket *)(((u8 *)pt) - ((u8 *)&((struct rtsocket *)0)->prot.packet)); int ifindex = sock->prot.packet.ifindex; void (*callback_func)(struct rtdm_dev_context *, void *); void *callback_arg; unsigned long flags; if (((ifindex != 0) && (ifindex != skb->rtdev->ifindex)) || (rtskb_acquire(skb, &sock->skb_pool) != 0)) kfree_rtskb(skb); else { rtdev_reference(skb->rtdev); rtskb_queue_tail(&sock->incoming, skb); rtos_event_sem_signal(&sock->wakeup_event); rtos_spin_lock_irqsave(&sock->param_lock, flags); callback_func = sock->callback_func; callback_arg = sock->callback_arg; rtos_spin_unlock_irqrestore(&sock->param_lock, flags); if (callback_func) callback_func(rt_socket_context(sock), callback_arg); } return 0; }
/*! * \brief The function is used to unblock previously blocked callbacks. * * If there is a callback pending, it gets immediately executed. * This function must not be called from a callback routine (it does not make sense to do so anyway as callback function never gets executed while callbacks are blocked). * * \param hwtimer[in] Pointer to hwtimer structure. * * \return MQX_INVALID_PARAMETER When input parameter hwtimer is NULL pointer. * \return MQX_OK When callback unblock succeed. * * \warning This function must not be called from a callback routine. * * \see hwtimer_callback_reg * \see hwtimer_callback_block * \see hwtimer_callback_cancel */ _mqx_int hwtimer_callback_unblock(HWTIMER_PTR hwtimer) { HWTIMER_CALLBACK_FPTR callback_func; #if MQX_CHECK_ERRORS if (NULL == hwtimer) { return MQX_INVALID_PARAMETER; } #endif /* Unblock callbacks in ISR. No more pending request could arrive after this. */ hwtimer->callback_blocked = 0; /* Check for any previously set pending requests during blocked state */ if (hwtimer->callback_pending) { callback_func = hwtimer->callback_func; if (NULL != callback_func) { /* Prevent invocation of callback from ISR (callback may not be reentrant) */ hwtimer->callback_func = NULL; callback_func(hwtimer->callback_data); /* Allow invocation of callback from ISR */ hwtimer->callback_func = callback_func; } /* Clear pending flag, callback just serviced */ hwtimer->callback_pending = 0; } return MQX_OK; }
void ForEachString(void (*callback_func)(string_node *snod,int string_id)) { int i; for (i=0;i<num_strings;i++) callback_func(&strings[i],i); }
/*** * rt_packet_rcv */ int rt_packet_rcv(struct rtskb *skb, struct rtpacket_type *pt) { struct rtsocket *sock = (struct rtsocket *)(((u8 *)pt) - ((u8 *)&((struct rtsocket *)0)->prot.packet)); int ifindex = sock->prot.packet.ifindex; void (*callback_func)(struct rtdm_dev_context *, void *); void *callback_arg; rtdm_lockctx_t context; if (((ifindex != 0) && (ifindex != skb->rtdev->ifindex)) || (rtskb_acquire(skb, &sock->skb_pool) != 0)) kfree_rtskb(skb); else { rtdev_reference(skb->rtdev); rtskb_queue_tail(&sock->incoming, skb); rtdm_sem_up(&sock->pending_sem); rtdm_lock_get_irqsave(&sock->param_lock, context); callback_func = sock->callback_func; callback_arg = sock->callback_arg; rtdm_lock_put_irqrestore(&sock->param_lock, context); if (callback_func) callback_func(rt_socket_context(sock), callback_arg); } return 0; }
bool WebPage::process (WebRequest *req) { int err; FILE *fp; struct stat file_stat; if (callback_func) { return callback_func (req); } else { err = stat (filename, &file_stat); if (err < 0) { log (LOG_ERROR, "stat %s (%d : %s)", filename, errno, strerror (errno)); } if (file_stat.st_mtime != last_modified) { last_modified = file_stat.st_mtime; free (html_file); html_file = 0; fp = fopen (filename, "r"); if (fp) { fseeko (fp, 0, SEEK_END); html_len = ftello (fp); fseeko (fp, 0, SEEK_SET); html_file = (char *) malloc (html_len + 1); fread (html_file, html_len, 1, fp); html_file[html_len] = 0; fclose (fp); req->set_response_code (200); req->add_template_response (html_file, html_len); return true; } else { return false; } } else { req->set_response_code (200); req->add_template_response (html_file, html_len); return true; } } }
void ForEachObject(void (*callback_func)(object_node *o)) { int i; for (i=0;i<num_objects;i++) if (!objects[i].deleted) callback_func(&objects[i]); }
void ForEachTimer(void (*callback_func)(timer_node *t)) { if (numActiveTimers == 0) return; for (int i = 0; i < numActiveTimers; ++i) callback_func(timer_heap[i]); }
int test_level_four(int one, int two, int three, int four, void (*callback_func)(void*), void* data) { if (callback_func != NULL) { callback_func(data); } else { while (1) ; } return one + two + three + four; }
int test_recursive_call(int level, void (*callback_func)(void*), void* data) { if (level > 0) { return test_recursive_call(level - 1, callback_func, data) + level; } else if (callback_func != NULL) { callback_func(data); } else { while (1) { } } return 0; }
void ForEachUser(void (*callback_func)(user_node *u)) { user_node *u; u = users; while (u != NULL) { callback_func(u); u = u->next; } }
void ForEachTimer(void (*callback_func)(timer_node *t)) { timer_node *t; t = timers; while (t != NULL) { callback_func(t); t = t->next; } }
void ForEachTimerMatchingMsgID(void (*callback_func)(timer_node *t), int m_id) { if (numActiveTimers == 0) return; for (int i = 0; i < numActiveTimers; ++i) { if (timer_heap[i]->message_id == m_id) callback_func(timer_heap[i]); } }
void ForEachConfigNode(void (*callback_func)(config_node *c,const char *config_name,const char *default_str)) { int i,config_id; for (i=0;i<LEN_CONFIG_TABLE;i++) { config_id = config_table[i].config_id; callback_func(&configs[config_id],config_table[i].config_name, config_table[i].default_str); } }
void ForEachTimerMatchingObjID(void (*callback_func)(timer_node *t), int o_id) { if (numActiveTimers == 0) return; for (int i = 0; i < numActiveTimers; ++i) { if (timer_heap[i]->object_id == o_id) callback_func(timer_heap[i]); } }
void ForEachAccount(void (*callback_func)(account_node *a)) { account_node *a; a = accounts; while (a != NULL) { callback_func(a); a = a->next; } }
void ForEachSession(void (*callback_func)(session_node *s)) { int i; /* the callback function shouldn't delete the session, in case it becomes a linked list */ for (i=0;i<num_sessions;i++) if (sessions[i].connected) callback_func(&sessions[i]); }
void ForEachDLlist(void (*callback_func)(dllist_node *dl)) { dllist_node *dl; dl = dllist; while (dl != NULL) { callback_func(dl); dl = dl->next; } }
void ForEachUserByAccountID(void (*callback_func)(user_node *u),int account_id) { user_node *u; u = users; while (u != NULL) { if (u->account_id == account_id) callback_func(u); u = u->next; } }
// SPI probe static int bp_spi_probe(struct spi_device *spi) { int err; struct bp_spi_dev *bp_spi; // finish_flag = 0; DEBUGONDISPLAY(MODE_PHY_DEBUG,printk("[SPI] probe\n")); // initializing SPI bp_spi = kzalloc(sizeof(*bp_spi), GFP_KERNEL); if (!bp_spi) { return -ENOMEM; } spi->bits_per_word = 8; spi->max_speed_hz = 5000000; err = spi_setup(spi); if (err < 0) { printk(KERN_ERR"spi_setup error %d\n", err); goto error_spi_setup; } mutex_init(&bp_spi->lock); bp_spi->spi = spi; strcpy(bp_spi->name, spi->modalias); bp_spi->irq = (u16)spi->irq; m_bp_spi = bp_spi; printk(KERN_INFO "bp_spi_probe name[%s]]\n", bp_spi->name); spi_set_drvdata(spi, bp_spi); DEBUGONDISPLAY(MODE_PHY_DEBUG,printk("[SPI] set drvdata\n")); // callback PHY err = callback_func(); if(err != 0) { printk(KERN_INFO "[SPI] MAC callback func error\n"); goto error_mac_callback; } DEBUGONDISPLAY(MODE_PHY_DEBUG,printk("[SPI] probe done\n")); return 0; error_mac_callback: spi_set_drvdata(bp_spi->spi, NULL); error_spi_setup: kfree(bp_spi); return err; }
void ForEachRoom(void(*callback_func)(room_node *r)) { room_node *node; for (int i = 0; i < INIT_ROOMTABLE_SIZE; i++) { node = rooms[i]; while (node) { callback_func(node); node = node->next; } } }
void ForEachNewDLFile(session_node *s,void (*callback_func)(char *str,int time,int type,int size)) { dllist_node *temp; temp = dllist; while (temp != NULL && temp->last_mod_time <= s->last_download_time) temp = temp->next; while (temp != NULL) { callback_func(temp->fname,temp->last_mod_time,temp->file_type,temp->file_size); temp = temp->next; } }
HRESULT STDMETHODCALLTYPE Progress::ProgressCallback () { //std::cout << " progress = " << progress << "\n"; //progress++; HRESULT result = AAFRESULT_SUCCESS; if (callback_func != NULL) { result = callback_func(); } //exit(-1); return result; }
bool Motion::Node::update(float time_now) { if (!active) return active; if (time_now < start_time) return active; else if (time_now >= end_time) { *val = end_val; active = false; if (callback_func) callback_func(callback_data); } else { float local_normal = (time_now - start_time) / (end_time - start_time); *val = (end_val - start_val) * interpolator_func(local_normal) + start_val; } return active; }
/*** * rt_udp_rcv */ int rt_udp_rcv (struct rtskb *skb) { struct rtsocket *sock = skb->sk; void (*callback_func)(struct rtdm_dev_context *, void *); void *callback_arg; unsigned long flags; rtskb_queue_tail(&sock->incoming, skb); rtos_event_sem_signal(&sock->wakeup_event); rtos_spin_lock_irqsave(&sock->param_lock, flags); callback_func = sock->callback_func; callback_arg = sock->callback_arg; rtos_spin_unlock_irqrestore(&sock->param_lock, flags); if (callback_func) callback_func(rt_socket_context(sock), callback_arg); return 0; }
/*** * rt_packet_rcv */ static int rt_packet_rcv(struct rtskb *skb, struct rtpacket_type *pt) { struct rtsocket *sock = container_of(pt, struct rtsocket, prot.packet.packet_type); int ifindex = sock->prot.packet.ifindex; void (*callback_func)(struct rtdm_fd *, void *); void *callback_arg; rtdm_lockctx_t context; if (unlikely((ifindex != 0) && (ifindex != skb->rtdev->ifindex))) return -EUNATCH; #ifdef CONFIG_XENO_DRIVERS_NET_ETH_P_ALL if (pt->type == htons(ETH_P_ALL)) { struct rtskb *clone_skb = rtskb_clone(skb, &sock->skb_pool); if (clone_skb == NULL) goto out; skb = clone_skb; } else #endif /* CONFIG_XENO_DRIVERS_NET_ETH_P_ALL */ if (unlikely(rtskb_acquire(skb, &sock->skb_pool) < 0)) { kfree_rtskb(skb); goto out; } rtskb_queue_tail(&sock->incoming, skb); rtdm_sem_up(&sock->pending_sem); rtdm_lock_get_irqsave(&sock->param_lock, context); callback_func = sock->callback_func; callback_arg = sock->callback_arg; rtdm_lock_put_irqrestore(&sock->param_lock, context); if (callback_func) callback_func(rt_socket_fd(sock), callback_arg); out: return 0; }
void ListenSocket::on_readable (void) { int new_sockfd; socklen_t new_addrlen; struct sockaddr_in new_addr; Socket *new_socket; char buffer[100]; log (LOG_LISTENSOCKET, "ListenSocket::on_readable"); new_addrlen = sizeof (new_addr); new_sockfd = accept (sockfd, (struct sockaddr *) &new_addr, &new_addrlen); if (new_sockfd == -1) { log (LOG_ERROR, "accept (%d : %s)", errno, strerror (errno)); return; } callback_func (new_sockfd, ntohl (new_addr.sin_addr.s_addr), ntohs (new_addr.sin_port)); }
void * log_imp::dispatch_callbacks(void) { while (true) { sem_wait(&log_waiting); if((write_index - read_index) > 0) { callback_func(user_obj, log_buf[read_index % LOG_BUF_COUNT].level, log_buf[read_index % LOG_BUF_COUNT].msg, log_buf[read_index % LOG_BUF_COUNT].time_stamp_ms ); read_index++; } else { break; } } return 0; }
static int write_type(scconf_context * config, scconf_block * block, scconf_entry * entry, int depth) { void *parm = entry->parm; void *arg = entry->arg; int (*callback_func) (scconf_context * config, scconf_block * block, scconf_entry * entry, int depth) = (int (*)(scconf_context *, scconf_block *, scconf_entry *, int)) parm; int r = 0; if (config->debug) { fprintf(stderr, "encoding '%s'\n", entry->name); } switch (entry->type) { case SCCONF_CALLBACK: if (parm) { r = callback_func(config, block, entry, depth); } break; case SCCONF_BLOCK: if (parm) { scconf_block *subblock; const scconf_list *name = (const scconf_list *) arg; subblock = scconf_block_add(config, block, entry->name, name); r = write_entries(config, subblock, (scconf_entry *) parm, depth + 1); } break; case SCCONF_LIST: if (parm) { const scconf_list *val = (const scconf_list *) parm; scconf_item_add(config, block, NULL, SCCONF_ITEM_TYPE_VALUE, entry->name, val); if (entry->flags & SCCONF_VERBOSE) { char *buf = scconf_list_strdup(val, ", "); printf("%s = %s\n", entry->name, buf); free(buf); } } break; case SCCONF_BOOLEAN: if (parm) { const int val = * (int* ) parm; scconf_put_bool(block, entry->name, val); if (entry->flags & SCCONF_VERBOSE) { printf("%s = %s\n", entry->name, val == 0 ? "false" : "true"); } } break; case SCCONF_INTEGER: if (parm) { const int val = * (int*) parm; scconf_put_int(block, entry->name, val); if (entry->flags & SCCONF_VERBOSE) { printf("%s = %i\n", entry->name, val); } } break; case SCCONF_STRING: if (parm) { const char *val = (const char *) parm; scconf_put_str(block, entry->name, val); if (entry->flags & SCCONF_VERBOSE) { printf("%s = %s\n", entry->name, val); } } break; default: fprintf(stderr, "invalid configuration type: %d\n", entry->type); } if (r) { fprintf(stderr, "encoding of configuration entry '%s' failed.\n", entry->name); return r; } entry->flags |= SCCONF_PRESENT; return 0; }