static VALUE rb_source_timer(VALUE klass, VALUE sel, VALUE delay, VALUE interval, VALUE leeway, VALUE queue) { Check_Queue(queue); dispatch_time_t start_time; VALUE argv[4] = {INT2FIX(SOURCE_TYPE_TIMER), INT2FIX(0), INT2FIX(0), queue}; VALUE self = rb_class_new_instance(4, argv, cSource); rb_source_t *src = RSource(self); if (NIL_P(leeway)) { leeway = INT2FIX(0); } if (NIL_P(delay)) { start_time = DISPATCH_TIME_NOW; } else { start_time = rb_num2timeout(delay); } rb_dispatch_suspend(self, 0); dispatch_source_set_timer(src->source, start_time, rb_num2nsec(interval), rb_num2nsec(leeway)); rb_dispatch_resume(self, 0); return self; }
static VALUE rb_source_init(VALUE self, SEL sel, VALUE type, VALUE handle, VALUE mask, VALUE queue) { Check_Queue(queue); rb_source_t *src = RSource(self); src->source_enum = (source_enum_t) NUM2LONG(type); dispatch_source_type_t c_type = rb_source_enum2type(src->source_enum); assert(c_type != NULL); uintptr_t c_handle = NUM2UINT(rb_Integer(handle)); unsigned long c_mask = NUM2LONG(mask); dispatch_queue_t c_queue = RQueue(queue)->queue; src->source = dispatch_source_create(c_type, c_handle, c_mask, c_queue); assert(src->source != NULL); rb_vm_block_t *block = get_prepared_block(); GC_WB(&src->event_handler, block); GC_RETAIN(self); // apparently needed to ensure consistent counting dispatch_set_context(src->source, (void *)self); dispatch_source_set_event_handler_f(src->source, rb_source_event_handler); GC_WB(&src->handle, handle); if (rb_source_is_file(src) && rb_obj_is_kind_of(handle, rb_cIO)) { dispatch_source_set_cancel_handler_f(src->source, rb_source_close_handler); } rb_dispatch_resume(self, 0); return self; }
static VALUE rb_group_notify(VALUE self, SEL sel, VALUE target) { rb_vm_block_t *block = get_prepared_block(); Check_Queue(target); dispatch_group_notify_f(RGroup(self)->group, RQueue(target)->queue, (void *)block, rb_block_dispatcher); return Qnil; }
dispatch_queue_t rb_get_dispatch_queue_object(VALUE queue) { Check_Queue(queue); return (dispatch_queue_t)dispatch_object_imp((void *)queue, 0); }
/* This is the main handler for messages received from the server */ void Server_Response( BYTE *data, DWORD len, WORD cmd, WORD ver, WORD seq, DWORD uin ) { SIMPLE_MESSAGE_PTR s_mesg; int i; CONNECT_INFO random; CONTACT_INFO *contact; USER_INFO user; DWORD xuin; switch ( cmd ) { case SRV_ACK: Check_Queue( seq ); break; case SRV_MULTI_PACKET: Multi_Packet( data ); break; case SRV_NEW_UIN: icq_callback(IM_NEWUIN,uin,0,0,0); break; case SRV_UPDATE_FAIL: infoupdate(FAIL,IR_INFO); break; case SRV_UPDATE_SUCCESS: infoupdate(SUCCESS,IR_INFO); break; case SRV_AUTHORIZE_SUCCESS: infoupdate(SUCCESS,IR_AUTH); break; case SRV_AUTHORIZE_FAIL: infoupdate(FAIL,IR_AUTH); break; case SRV_UPDATE_EXT_SUCCESS: infoupdate(SUCCESS,IR_EXT); break; case SRV_UPDATE_EXT_FAIL: infoupdate(FAIL,IR_EXT); break; case SRV_LOGIN_REPLY: snd_contact_list(); snd_invis_list(); snd_vis_list(); icq_callback(IM_LOGIN,0,0,0,0); break; case SRV_X1: /* unknown message sent after login*/ icq_callback(IM_LOGIN2,0,0,0,0); break; case SRV_X2: /* unknown message sent after login*/ icq_snd_got_messages(); break; case SRV_GO_AWAY: icq_callback(IM_FORCEDDISCONNECT,0,0,0,0); break; case SRV_END_OF_SEARCH: icq_callback(IM_SEARCHDONE,0,0,0,0); break; case SRV_BAD_PASS: icq_callback(IM_BADPASS,0,0,0,0); break; case SRV_TRY_AGAIN: icq_callback(IM_ACCOUNTBUSY,0,0,0,0); for ( i = 0; i< 1024; i++ ) { serv_mess[ i ]=FALSE; } break; case SRV_USER_OFFLINE: contact = FindContact(Chars_2_DW(&data[0])); if (!contact) return; icq_callback(IM_USEROFFLINE,0,contact,0,0); contact->ci.status = STATUS_OFFLINE; contact->last_time = time( NULL ); break; case SRV_USER_ONLINE: contact = FindContact(Chars_2_DW( &data[0] )); if (!contact) return; FillConnectInfo(&contact->ci,data); icq_callback(IM_USERONLINE,0,contact,0,0); break; case SRV_STATUS_UPDATE: contact = FindContact(Chars_2_DW(&data[0])); if (!contact) return; contact->ci.status = GetStatusVal(Chars_2_DW(&data[4])); icq_callback(IM_STATUSUPDATE,0,contact,0,0); break; case SRV_RAND_USER: if (len == 37) { FillConnectInfo(&random,data); icq_callback(IM_RANDRESPONSE,0,&random,0,0); } else icq_callback(IM_RANDRESPONSE,0,0,0,0); break; case SRV_USER_FOUND: FillUserInfo(&user,data); icq_callback(IM_USERFOUND,0,0,&user,0); break; case SRV_INFO_REPLY: HandleInfoReply(SUCCESS, UI_BASIC, data); break; case SRV_INFO_NONE: HandleInfoReply(FAIL, UI_BASIC, data); break; case SRV_EXT_INFO_REPLY: HandleInfoReply(SUCCESS, UI_EXTENDED, data); break; case SRV_EXT_INFO_NONE: HandleInfoReply(FAIL, UI_EXTENDED, data); break; case SRV_RECV_MESSAGE: Recv_Message( data ); break; case SRV_SYS_DELIVERED_MESS: s_mesg = ( SIMPLE_MESSAGE_PTR ) data; xuin = Chars_2_DW( s_mesg->uin ); Do_Msg( Chars_2_Word( s_mesg->type ), Chars_2_Word( s_mesg->len ), s_mesg->len + 2,xuin, 0, 0); break; default: /* commands we dont handle yet */ icq_callback(IM_UNHANDLED,cmd,data,(void *)len,0); break; } }