Beispiel #1
0
static void timer_timeout(int argc, uint32_t itimer)
{
#ifndef CONFIG_CAN_PASS_STRUCTS
  /* On many small machines, pointers are encoded and cannot be simply cast from
   * uint32_t to struct tcb_s*.  The following union works around this (see wdogparm_t).
   */

  union
  {
    FAR struct posix_timer_s *timer;
    uint32_t                  itimer;
  } u;

  u.itimer = itimer;

  /* Send the specified signal to the specified task.   Increment the reference
   * count on the timer first so that will not be deleted until after the
   * signal handler returns.
   */

  u.timer->pt_crefs++;
  timer_sigqueue(u.timer);

  /* Release the reference.  timer_release will return nonzero if the timer
   * was not deleted.
   */

  if (timer_release(u.timer))
    {
      /* If this is a repetitive timer, the restart the watchdog */

      timer_restart(u.timer, itimer);
    }
#else
  /* (casting to uintptr_t first eliminates complaints on some architectures
   *  where the sizeof uint32_t is different from the size of a pointer).
   */

  FAR struct posix_timer_s *timer = (FAR struct posix_timer_s *)((uintptr_t)itimer);

  /* Send the specified signal to the specified task.   Increment the reference
   * count on the timer first so that will not be deleted until after the
   * signal handler returns.
   */

  timer->pt_crefs++;
  timer_sigqueue(timer);

  /* Release the reference.  timer_release will return nonzero if the timer
   * was not deleted.
   */

  if (timer_release(timer))
    {
      /* If this is a repetitive timer, the restart the watchdog */

      timer_restart(timer, itimer);
    }
#endif
}
Beispiel #2
0
t_status	interface_timer_release(o_syscall*	message)
{
  t_status error;

  error = timer_release(message->u.request.u.timer_release.arg1);

  message->u.reply.error = error;

  return (STATUS_OK);
}
Beispiel #3
0
int timer_delete(timer_t timerid)
{
    int ret = timer_release((FAR struct posix_timer_s *)timerid);
    if (ret < 0)
    {
        *get_errno_ptr() = -ret;
        return ERROR;
    }
    return OK;
}
static void	call_StartTimer(t_HWindow handle)
{
	t_CallWindowData *data = (t_CallWindowData*)wgt_get_tag(handle);
	if(data->timer >= 0)
		timer_release(data->timer);
	data->timer = timer_create(call_TimerCB, handle);
	if(data->timer >= 0)
		timer_start(data->timer, 1000, TIMER_MODE_PERIOD);
	
}
Beispiel #5
0
int main(int argc, char** argv)
{
	struct heaptimer_t* timer;
	struct task_t* t;
	struct task_step_t* t1, *t2, *t3;
	struct timeval timeout;
	struct timeval tv;

    int32_t loop = argc > 1 ? atoi(argv[1]) : 3;

    cp = curl_pool_init();
    assert(cp);

    timer = timer_init();
    assert(timer);

    t = task_init(on_success, on_fail, (void*)&loop);
    assert(t);

    t1 = task_step_init(t1_run);
    assert(t1);
    task_push_back_step(t, t1);
    id = task_step_id(t1);

    t2 = task_step_init(t2_run);
    assert(t2);
    task_push_back_step(t, t2);

    t3 = task_step_init(t3_run);
    assert(t3);
    task_push_back_step(t, t3);

    timeout.tv_sec = 1;
    timeout.tv_usec = 0;
    task_run(t, timer, &timeout);

    while (1) {
        if (curl_pool_running_count(cp) > 0) {
            curl_pool_run(cp);
        }

        util_gettimeofday(&tv, NULL);
        timer_poll(timer, &tv);

        if (task_finished(t) == 0) {
            break;
        }
    }

    task_release(t);
    timer_release(timer);
    curl_pool_release(cp);
    return 0;
}
Beispiel #6
0
//Documentation in header file
uint8_t dhcp_requestIP(uint16_t timeout_ms)
{
	//Get a timer
	int8_t timer = timer_get();
	timer_set(timer,timeout_ms);
	
	//Send dhcp discover packet
	dhcp_sendDiscover();

	do
	{
		//Wait for a packet to arrive
		//If no packets arrive in time, return 0
		while(enc28j60Read(EPKTCNT) == 0)
			if(timer_check(timer) == TIMER_EXPIRED)
			{
				//Release the timer
				timer_release(timer);
				return 0;
			}				
				
		//Receive packet
		ns.plength = enc28j60PacketReceive(ns.pbuf, ns.pbuf_size);
		
		//Check if packet is DHCP!
		if(ns.plength > 0)
			if(getPacketType() == DHCP)
				dhcp_handlePacket();
						
	}
	while(ns.ipAcquired == 0);	
	
	//Release the timer
	timer_release(timer);	
	
	//Return success		
	return ns.ipAcquired;
}
static void	dtmf_callback(int timer, void *userdata)
{
	t_CallWindowData *wdata = userdata;
	gu8 flag = TRUE;
	char *p = &wdata->info->dtmf[1];
	if(*(p-1) == 'w'){
		//3 notify user to determine whether to start dtmf or not.
		if(msgbox_show(NULL, MBB_YES_NO, 0, 0, "%s %s?", brd_get_string(BRD_HANDLE_SELF, RESID_STR_PROMPT_DTMF, ""), p) == MBB_NO)
			flag = FALSE;
	}
	if(flag){
		while(*p){
			call_send_dtmf(wdata->info->cid, *p++);
			call_stop_dtmf(wdata->info->cid);
		}
	}

	timer_release(timer);
}
Beispiel #8
0
int
test_logic_task(const char* param) {
    timerheap_t* timer = timer_create_heap();
    if (!timer) {
        fprintf(stderr, "timer create fail\n");
        return -1;
    }

    _curl_pool = curlp_create();
    if (!_curl_pool) {
        fprintf(stderr, "curl create fail\n");
        timer_release(timer);
        return -1;
    }

    task_t* t = task_create(on_success, on_fail, NULL);
    if (!t) {
        fprintf(stderr, "task create fail\n");
        timer_release(timer);
        curlp_release(_curl_pool);
        return -1;
    }

    struct timeval timeout;
    struct timeval tv;

    t1_param_t p;
    p.loop = (param ? atoi(param) : 3);
    task_step_t* t1 = task_step_create(t1_run, (void*)&p);
    task_step_t* t2 = task_step_create(t2_run, NULL);
    task_step_t* t3 = task_step_create(t3_run, NULL);
    if (!t1 || !t2 || !t3) {
        fprintf(stderr, "task step create fail\n");
        if (t1) task_step_release(t1);
        if (t2) task_step_release(t2);
        if (t3) task_step_release(t3);
        task_release(t);
        timer_release(timer);
        curlp_release(_curl_pool);
        return -1;
    }

    task_push_back_step(t, t1);
    _task_step_id = task_step_id(t1);
    task_push_back_step(t, t2);
    task_push_back_step(t, t3);

    timeout.tv_sec = 3;
    timeout.tv_usec = 0;
    task_run(t, timer, &timeout);

    while (1) {
        if (curlp_running_count(_curl_pool) > 0) {
            curlp_poll(_curl_pool);
        }
        gettimeofday(&tv, NULL);
        timer_poll(timer, &tv);
        if (task_is_finished(t) == 0) {
            break;
        }
    }

    task_release(t);
    timer_release(timer);
    curlp_release(_curl_pool);
    return 0;
}
//2 <sparam>=<call_id>, <lparam>=<t_CSessionID>
error_t	call_WndMsgHandler(t_HWindow handle, t_WidgetEvent evt, t_sparam sparam, t_lparam lparam)
{
	error_t ret = NOT_HANDLED;
	t_CallWindowData *wdata = (t_CallWindowData*)wgt_get_tag(handle);
	switch(evt){
		case WINDOW_OnOpen:
			g_printf("WINDOW_OnOpen\r\n");
			{
				t_HWidget widget;

				wgt_enable_attr(handle, WND_ATTR_HAS_STATUS|WND_ATTR_HAS_TITLE);
				wdata = MALLOC(sizeof(t_CallWindowData));
				memset(wdata, 0, sizeof(t_CallWindowData));
				wdata->cid = sparam;
				wdata->contact = lparam;
				wdata->info = call_get_info(wdata->cid);
				wdata->number = wdata->info->phone;
				if(wdata->contact == CSESSION_NULL){
					wdata->contact = contact_query_by_number(wdata->number, wdata->name, sizeof(wdata->name));
				}
				wdata->cinfo = contact_get_info(wdata->contact);
				if(wdata->cinfo)
					wdata->name = wdata->cinfo->name;
				else
					wdata->name = wdata->number;

				wdata->timer = -1;
				datetime_current(&wdata->dt);
				wdata->tick = tick_current();
				wdata->connected = FALSE;
				wdata->handfree = FALSE;
				wdata->mute = FALSE;
				wdata->held = FALSE;
				wdata->keypad = FALSE;
				wdata->btn_down = -1;
				dev_audio_set_path(wdata->info->aud, AUD_DEV_RECEIVER);
				wgt_set_tag(handle, wdata);
				call_StartTimer(handle);
				//wnd_SetTitle(handle, "Outgoing Call", BRD_HANDLE_SELF, RESID_STR_OUTGOING);
#if 0
				widget = wnd_get_widget(handle, RESID_LABEL_NUMBER);
				if(g_object_valid(widget)){
					label_set_text(widget, wdata->name);
				}
				widget = wnd_get_widget(handle, RESID_LABEL_EVENT);
				if(g_object_valid(widget)){
					if(wdata->info->outgoing)
						wgt_set_caption_by_resid(widget, brd_get(PACK_GUID_SELF), gaCallEvtResid[CALL_EVT_O_ALERT]);
					else
						wgt_set_caption_by_resid(widget, brd_get(PACK_GUID_SELF), gaCallEvtResid[CALL_EVT_INCOMING]);
						
					label_set_text(widget, "");
				}
				widget = wnd_get_widget(handle, RESID_CTRL_IMAGE);
				if(g_object_valid(widget)){
					t_ContactInfo info;
					if(!IS_UNSAVED_CONTACT(wdata->contact) && wdata->contact != UNKNOWN_CONTACT && contact_get_info(wdata->contact, &info)){
						if(info.pic_resid)
							imagectrl_set_by_resid(widget, brd_get("contact"), info.pic_resid);
						else if(info.pic_fname)
							imagectrl_set_by_file(widget, info.pic_fname);
						else
							imagectrl_set_by_resid(widget, brd_get(PACK_GUID_SELF), RESID_IMG_PICTURE);
						contact_free_info(&info);
					}else{
						imagectrl_set_by_resid(widget, brd_get(PACK_GUID_SELF), RESID_IMG_PICTURE);
					}
					wgt_disable_attr(widget, CTRL_ATTR_TABSTOP);
				}
				#endif
				if(wgt_get_resid(handle) == RESID_WIN_CALL){
					widget = wnd_get_widget(handle, RESID_BTN_END);
					wgt_set_text_align(widget, guiRight);
					wgt_set_border(widget, BORDER_TYPE_3DIN, 1, guiFourCorner);
					wgt_set_bg_fill(widget, GDI_FILL_MODE_2COLOR_H, MAKE_RGB(0xe0,0,0), MAKE_RGB(0xb0,0,0));
					
					widget = wnd_get_widget(handle, RESID_BTN_HIDE_KEYPAD);
					wgt_set_text_align(widget, guiRight);
					wgt_set_border(widget, BORDER_TYPE_3DIN, 2, guiFourCorner);
					wgt_set_bg_fill(widget, GDI_FILL_MODE_2COLOR_H, MAKE_RGB(0xe0,0,0), MAKE_RGB(0xb0,0,0));
				}else if(wgt_get_resid(handle) == RESID_WIN_CALL_MT){
					wgt_set_text_align(wnd_get_widget(handle, RESID_BTN_ANSWER), guiRight);
					wgt_set_text_align(wnd_get_widget(handle, RESID_BTN_END_MO), guiRight);
				}

				sk_set_text(wnd_get_skbar(handle), SK_LSK, NULL, RESID_STR_CALL_KEYPAD);
				sk_set_text(wnd_get_skbar(handle), SK_RSK, NULL, RESID_STR_BACK);
				
				ret = SUCCESS;
			}
			break;
		case WINDOW_OnClose:
			g_printf("WINDOW_OnClose\r\n");
			if(wdata){
				if(wdata->cid >= 0)
					call_end(wdata->cid);
				if(wdata->timer >= 0)
					timer_release(wdata->timer);
				contact_free_info(wdata->cinfo);
				FREE(wdata);
			}
			ret = SUCCESS;
			break;
		case WIDGET_OnPreDraw:
			__window_predraw(handle);
			break;
		case WINDOW_OnDraw:
			g_printf("WINDOW_OnDraw\r\n");
			//__show_incall_panel(handle, NULL, TRUE);
			ret = SUCCESS;
			break;
		case WIDGET_OnSelected:
			switch(wgt_get_resid(lparam)){
#if 0 // alvin
				case RESID_BTN_MUTE:
					if(wdata->mute){
						dev_audio_mute(wdata->info->aud, FALSE);
						wdata->mute = FALSE;
						wgt_set_caption_by_resid((t_HWidget)lparam, BRD_HANDLE_SELF, RESID_STR_MUTE);
						wgt_set_icon_by_resid((t_HWidget)lparam, BRD_HANDLE_SELF, RESID_IMG_MUTE);
					}else{
						dev_audio_mute(wdata->info->aud, TRUE);
						wdata->mute = TRUE;
						wgt_set_caption_by_resid((t_HWidget)lparam, BRD_HANDLE_SELF, RESID_STR_UNMUTE);
						wgt_set_icon_by_resid((t_HWidget)lparam, BRD_HANDLE_SELF, RESID_IMG_UNMUTE);
					}
					wgt_redraw((t_HWidget)lparam, FALSE);
					ret = SUCCESS;
					break;
				case RESID_BTN_SPEAKER:
					if(wdata->handfree){
						dev_audio_set_path(wdata->info->aud, AUD_DEV_RECEIVER);
						dev_audio_set_volume(wdata->info->aud, VOLUME_LEVEL_6);
						wdata->handfree = FALSE;
						wgt_set_caption_by_resid((t_HWidget)lparam, BRD_HANDLE_SELF, RESID_STR_SPEAKER_ON);
						wgt_set_icon_by_resid((t_HWidget)lparam, BRD_HANDLE_SELF, RESID_IMG_SPEAKER_ON);
					}else{
						dev_audio_set_path(wdata->info->aud, AUD_DEV_SPEAKER);
						dev_audio_set_volume(wdata->info->aud, VOLUME_LEVEL_6);
						wdata->handfree = TRUE;
						wgt_set_caption_by_resid((t_HWidget)lparam, BRD_HANDLE_SELF, RESID_STR_SPEAKER_OFF);
						wgt_set_icon_by_resid((t_HWidget)lparam, BRD_HANDLE_SELF, RESID_IMG_SPEAKER_OFF);
					}
					wgt_redraw((t_HWidget)lparam, FALSE);
					ret = SUCCESS;
					break;
				#endif
				case RESID_BTN_END:
					call_handle_end(wdata, handle);
					ret = SUCCESS;
					break;
				case RESID_BTN_END_MO:
					call_handle_end(wdata, handle);
					ret = SUCCESS;
					break;
				case RESID_BTN_ANSWER:
					call_answer(wdata->cid);
					ret = SUCCESS;
					break;
				case RESID_BTN_HIDE_KEYPAD:
					__incall_keypad_toggle(handle, wdata);
					break;
			}
			break;
#if !defined(FTR_NO_INPUT_KEY)
		case WIDGET_OnKeyEvent:
			if(sparam != MMI_KEY_PRESS && sparam != MMI_KEY_REPEAT)
				break;
			switch(lparam){
				case MVK_SEND:
					break;
				case MVK_END:
					call_handle_end(wdata, handle);
					ret = SUCCESS;
					break;
				case MVK_RSK:
					GOTO_DESKTOP();
					ret = SUCCESS;
					break;
				case MVK_0:
				case MVK_1:
				case MVK_2:
				case MVK_3:
				case MVK_4:
				case MVK_5:
				case MVK_6:
				case MVK_7:
				case MVK_8:
				case MVK_9:
					if(wdata->info->outgoing && wdata->info->state == CALL_STATE_INCALL){
						call_stop_dtmf(wdata->cid);
						call_send_dtmf(wdata->cid, '0'+lparam-MVK_0);
						label_append_char(wnd_get_widget(handle, RESID_LABEL_NUMBER), '0'+lparam-MVK_0);
						wgt_redraw(wnd_get_widget(handle, RESID_LABEL_NUMBER), FALSE);
					}
					break;
				case MVK_STAR:
					if(wdata->info->outgoing && wdata->info->state == CALL_STATE_INCALL){
						call_stop_dtmf(wdata->cid);
						call_send_dtmf(wdata->cid, '*');
						label_append_char(wnd_get_widget(handle, RESID_LABEL_NUMBER), '*');
						wgt_redraw(wnd_get_widget(handle, RESID_LABEL_NUMBER), FALSE);
					}
					break;
				case MVK_HASH:
					if(wdata->info->outgoing && wdata->info->state == CALL_STATE_INCALL){
						call_stop_dtmf(wdata->cid);
						call_send_dtmf(wdata->cid, '#');
						label_append_char(wnd_get_widget(handle, RESID_LABEL_NUMBER), '#');
						wgt_redraw(wnd_get_widget(handle, RESID_LABEL_NUMBER), FALSE);
					}
					break;
			}
			break;
#endif
		case WIDGET_OnPenEvent:
			{
				coord_t x0,y0;
				PEN_XY(lparam, x0,y0);
				switch(PEN_TYPE(lparam)){
					case MMI_PEN_DOWN:
						if(!wgt_point_in_client(handle, &x0, &y0))
							break;
						__incall_OnPenEvent(handle, wdata, __get_pad_cell(wdata, x0, y0, NULL), MMI_PEN_DOWN);
						break;
					case MMI_PEN_UP:
						if(wdata->btn_down >= 0 && wgt_point_in_client(handle, &x0, &y0)){
							__incall_OnPenEvent(handle, wdata, __get_pad_cell(wdata, x0, y0, NULL), MMI_PEN_UP);
						}
						break;
					case MMI_PEN_MOVE:
						if(wdata->btn_down >= 0){
						}
						break;
				}
				ret = SUCCESS;
			}
			break;
	}
	return ret;
}