Beispiel #1
0
void active_protocol_c::worker_check()
#endif
{
    ts::str_c ipcname(CONSTASTR("isotoxin_ap_"));
    uint64 utg = ts::uuid();
    ipcname.append_as_hex(&utg, sizeof(utg)).append_char('_');

    auto ww = syncdata.lock_write();
    ww().flags.set(F_WORKER);
    ww().flags.clear(F_WORKER_STOPED);
    ipcname.append( ww().data.tag );
    ww.unlock();

    // ipc allocated at stack
    isotoxin_ipc_s ipcs(ipcname, DELEGATE(this,cmdhandler));
    if (ipcs.ipc_ok)
    {
        ipcp = &ipcs;
        push_debug_settings();
        ipcp->send(ipcw(AQ_SET_PROTO) << syncdata.lock_read()().data.tag);
        ipcp->wait_loop(DELEGATE(this, tick));
        auto w = syncdata.lock_write();
        ipcp = nullptr;
        w().flags.clear(F_WORKER);
        w().flags.set(F_WORKER_STOPED);
        w.unlock();

        spinlock::auto_simple_lock l(lbsync);
        for(data_header_s *dh : locked_bufs)
            ipcs.junct.unlock_buffer(dh);

    } else
        syncdata.lock_write()().flags.clear(F_WORKER);

}
Beispiel #2
0
active_protocol_c::~active_protocol_c()
{
    save_config(true);
    stop_and_die(true);
    if (gui)
    {
        gui->delete_event(DELEGATE(this,check_die));
        gui->delete_event(DELEGATE(this,check_save));
    }
}
Beispiel #3
0
void active_protocol_c::save_config(bool wait)
{
    if (!ipcp) return;
    ts::Time t = ts::Time::current();

    auto w = syncdata.lock_write();
    if (w().flags.is(F_CONFIG_OK))
        if ((t - lastconfig) < 1000) return;

    w().flags.clear(F_CONFIG_OK|F_CONFIG_FAIL|F_SAVE_REQUEST|F_CONFIG_UPDATED);
    w().data.config.clear();
    w.unlock();

    if (!ipcp) return;
    ipcp->send( ipcw(AQ_SAVE_CONFIG) );
    DMSG("save request" << id);

    if (wait)
    {
        Sleep(10);
        while( !syncdata.lock_read()().flags.is(F_CONFIG_OK|F_CONFIG_FAIL) )
        {
            Sleep(10);
            sys_idle();
            if (!syncdata.lock_read()().flags.is(F_WORKER))
                return;
        }
        check_save(RID(),nullptr);

    } else
    {
        syncdata.lock_write()().flags.set(F_CFGSAVE_CHECKER);
        DEFERRED_UNIQUE_CALL( 0, DELEGATE(this,check_save), nullptr );
    }
}
Beispiel #4
0
void gui_filterbar_c::show_options(bool show)
{
    if (show && option1 != nullptr)
        return;
    if (!show && option1 == nullptr)
        return;

    if (show)
    {
        int tag = gui->get_free_tag();
        gui_button_c &o1 = MAKE_VISIBLE_CHILD<gui_button_c>(getrid());
        o1.set_check(tag);
        o1.set_handler(DELEGATE(this, option_handler), as_param(1));
        o1.set_face_getter(BUTTON_FACE(check));
        o1.set_text(TTT("Search in messages",337));
        if (search_in_messages)
            o1.mark();

        option1 = &o1;
    } else
    {
        TSDEL( option1 );
    }

    HOLD( getparent() ).as<gui_contactlist_c>().update_filter_pos();
}
Beispiel #5
0
/*virtual*/ void gui_filterbar_c::created()
{
    set_theme_rect(CONSTASTR("filter"), false);

    filtereditheight = gui->theme().conf().get_int(CONSTASTR("filtereditheight"), 25);

    if (prf().get_options().is(UIOPT_SHOW_SEARCH_BAR))
    {
        gui_textfield_c &e = (MAKE_CHILD<gui_textfield_c>(getrid(), L"", MAX_PATH, 0, false) << (gui_textedit_c::TEXTCHECKFUNC)DELEGATE(this, update_filter));
        edit = &e;
        e.set_placeholder(TOOLTIP(TTT("Search", 277)), get_default_text_color(COL_PLACEHOLDER));
        e.register_kbd_callback(DELEGATE(this, cancel_filter), SSK_ESC, false);
    }
    if (prf().get_options().is(UIOPT_TAGFILETR_BAR))
    {
        fill_tags();
    }

    search_in_messages = prf().is_loaded() && prf().get_options().is(MSGOP_FULL_SEARCH);

    if (!is_all())
        refresh_list();

    __super::created();
}
Beispiel #6
0
  void BaseGameLogic::unregisterDelegates()
  {
    LOGI << "Unregistering all delegates for the base game logic." << endl;

    auto load_game_delegate = DELEGATE(&BaseGameLogic::loadGameDelegate, this);
    event_mgr_->removeListener(LoadGameEvent::TYPE, load_game_delegate);
  }
Beispiel #7
0
void active_protocol_c::stop_and_die(bool wait_worker_end)
{
    auto w = syncdata.lock_write();
    if (w().flags.is(F_DIP) || !w().flags.is(F_WORKER))
    {
        w().flags.set(F_DIP);
        return;
    }
    w().flags.set(F_DIP);
    if (ipcp) ipcp->something_happens();
    w.unlock();

    if (wait_worker_end)
    {
        auto lr = syncdata.lock_read();
        while( lr().flags.is(F_WORKER) )
        {
            if (ipcp) ipcp->something_happens();
            lr.unlock();
            Sleep(0);
            lr = syncdata.lock_read();
        }
    } else
        DEFERRED_UNIQUE_CALL( 0, DELEGATE(this,check_die), nullptr );
}
Beispiel #8
0
gui_filterbar_c::~gui_filterbar_c()
{
    if (g_app)
    {
        g_app->found_items = nullptr;
        g_app->delete_event( DELEGATE(this, do_contact_check) );
    }
}
Beispiel #9
0
void Entity::registerComponent(MessageType messageType, ReceiverFunction receiver)
{
	//Component* component = (Component*)receiver.object_ptr;
	//if(hasComponent(component))
	//{
		this->messageHandler.registerReceiver(messageType, receiver);
		this->gameState.getMessageHandler().registerReceiver(messageType,DELEGATE(Entity, Entity::receiveMessage, this));
	//}
}
Beispiel #10
0
void gui_filterbar_c::do_tag_rclick(int lnk)
{
    menu_c mnu;
    mnu.add(TTT("Rename tag",224), 0, DELEGATE(this, ctx_rename_tag), ts::amake(lnk));
    popupmenu = &gui_popup_menu_c::show(menu_anchor_s(true), mnu);
    popupmenu->leech(this);
    textrect.make_dirty();
    getengine().redraw();

}
void RemoteDesktop::Network_Server::_Run(){

	std::vector<WSAEVENT> EventArray;
	auto sharedrockarray = std::make_shared<std::vector<std::shared_ptr<SocketHandler>>>();
	_Sockets = sharedrockarray;
	EventArray.reserve(WSA_MAXIMUM_WAIT_EVENTS);
	sharedrockarray->reserve(WSA_MAXIMUM_WAIT_EVENTS);

	SOCKET listensocket = RemoteDesktop::Listen(_Port, _Host);
	if (listensocket == INVALID_SOCKET) return;

	auto newevent = WSACreateEvent();
	WSAEventSelect(listensocket, newevent, FD_ACCEPT | FD_CLOSE);

	EventArray.push_back(newevent);
	sharedrockarray->push_back(std::make_shared<SocketHandler>(listensocket, false));

	NetworkProcessor processor(DELEGATE(&RemoteDesktop::Network_Server::_HandleReceive), DELEGATE(&RemoteDesktop::Network_Server::_HandleConnect));
	WSANETWORKEVENTS NetworkEvents;
	auto timer = std::chrono::high_resolution_clock::now();
	while (_Running && !EventArray.empty()) {

		auto Index = WSAWaitForMultipleEvents(EventArray.size(), EventArray.data(), FALSE, 1000, FALSE);

		if ((Index != WSA_WAIT_FAILED) && (Index != WSA_WAIT_TIMEOUT) && _Running) {

			WSAEnumNetworkEvents(sharedrockarray->at(Index)->get_Socket(), EventArray[Index], &NetworkEvents);
			if (((NetworkEvents.lNetworkEvents & FD_ACCEPT) == FD_ACCEPT) && NetworkEvents.iErrorCode[FD_ACCEPT_BIT] == ERROR_SUCCESS){
				if (EventArray.size() >= WSA_MAXIMUM_WAIT_EVENTS - 1) continue;// ignore this event too many connections
				_HandleNewConnect(listensocket, EventArray, *sharedrockarray);
			}
			else if (((NetworkEvents.lNetworkEvents & FD_READ) == FD_READ) && NetworkEvents.iErrorCode[FD_READ_BIT] == ERROR_SUCCESS){
				processor.Receive(sharedrockarray->at(Index));
			}
			else if (((NetworkEvents.lNetworkEvents & FD_CLOSE) == FD_CLOSE) && NetworkEvents.iErrorCode[FD_CLOSE_BIT] == ERROR_SUCCESS){
				if (Index == 0) {//stop all processing, set running to false and next loop will fail and cleanup
					_Running = false;
					continue;
				}
			}
		}
		//once every second send a keep alive. this will trigger disconnects 
		if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - timer).count() > 1000){
			_CheckForDisconnects(EventArray, *sharedrockarray);
			timer = std::chrono::high_resolution_clock::now();
		}
	}
	for (size_t beg = 1; beg < sharedrockarray->size(); beg++){
		OnDisconnect(sharedrockarray->at(beg));//let all callers know about the disconnect, skip slot 0 which is the listen socket
	}
	//cleanup code here
	for (auto x : EventArray) WSACloseEvent(x);
	DEBUG_MSG("_Listen Exiting");
}
Beispiel #12
0
/*virtual*/ int gui_filterbar_c::full_search_s::iterate(int pass)
{
    // mtype 0 == MTA_MESSAGE
    // mtype 107 == MTA_UNDELIVERED_MESSAGE

    ts::str_c where(CONSTASTR("(mtype == 0 or mtype == 107) and msg like \"%"));
    where.encode_pointer(&flt).append(CONSTASTR("\" order by mtime") );

    db->read_table(CONSTASTR("history"), DELEGATE(this, reader), where);

    return R_DONE;
}
Beispiel #13
0
void Entity::deregisterComponent(MessageType messageType, ReceiverFunction receiver)
{
	// May have to check if the component has been add to some component list
	
	// Deregister the component from receiving this message
	this->messageHandler.deregisterReceiver(messageType, receiver);
	
	// Now, if no components are asking for this message, remove the entity from the global message map
	if(!this->messageHandler.hasMessageType(messageType))
	{
		this->gameState.getMessageHandler().deregisterReceiver(messageType, DELEGATE(Entity, Entity::receiveMessage, this)); 
	}
}
Beispiel #14
0
/*virtual*/ bool mainrect_c::sq_evt(system_query_e qp, RID rid, evt_data_s &data)
{
    if (qp == SQ_RECT_CHANGED)
    {
        cfg().onclosereg( DELEGATE(this, onclosesave) );
        if (data.changed.manual)
        {
            rrect = getprops().screenrect();
            mrect = ts::wnd_get_max_size(rrect);
            DEFERRED_UNIQUE_CALL( 1.0, DELEGATE(this,saverectpos), nullptr );
        }
    }

    if (__super::sq_evt(qp, rid, data)) return true;

	switch( qp )
	{
	case SQ_DRAW:
        if (const theme_rect_s *tr = themerect())
		if (icons[0].info().sz.x > 0 && icons[1].info().sz.x)
        {
            ts::irect cr = tr->captionrect( getprops().currentszrect(), getprops().is_maximized() );

            ts::bitmap_c &icon = icons[ g_app->F_OFFLINE_ICON ? 1 : 0 ];
            //cr.lt.y += (cr.height() - icon.info().sz.y)/2;
            cr.lt.y += tr->captextadd.y;

            getengine().begin_draw();
            getengine().draw( cr.lt, icon.extbody(), ts::irect(0, icon.info().sz), true );
            getengine().end_draw();
        }
		break;
	}

    return false;
}
Beispiel #15
0
stepperSim::stepperSim(arduinoIOSim* arduinoIO, int enablePinNr, int stepPinNr, int dirPinNr, bool invertDir)
{
    this->minStepValue = -1;
    this->maxStepValue = -1;
    this->stepValue = 0;
    this->minEndstopPin = -1;
    this->maxEndstopPin = -1;
    
    this->invertDir = invertDir;
    this->enablePin = enablePinNr;
    this->stepPin = stepPinNr;
    this->dirPin = dirPinNr;
    
    arduinoIO->registerPortCallback(stepPinNr, DELEGATE(ioDelegate, stepperSim, *this, stepPinUpdate));
}
Beispiel #16
0
bool active_protocol_c::check_die(RID, GUIPARAM)
{
    auto r = syncdata.lock_read();
    if (r().flags.is(F_WORKER))
    {
        // worker still works. waiting again
        if (ipcp) ipcp->something_happens();
        r.unlock();
        DEFERRED_UNIQUE_CALL(0.01, DELEGATE(this, check_die), nullptr);
    } else
    {
        r.unlock();
        TSDEL( this ); // actual death
    }
    return true;
}
Beispiel #17
0
bool active_protocol_c::check_save(RID, GUIPARAM)
{
    auto ttt = syncdata.lock_write();
    ttt().flags.clear(F_CFGSAVE_CHECKER);
    if (!ttt().flags.is(F_CONFIG_OK))
    {
        // config still not received. waiting again
        ttt().flags.set(F_CFGSAVE_CHECKER);
        DEFERRED_UNIQUE_CALL(0.01, DELEGATE(this, check_save), nullptr);
    }
    else
    {
        ttt().flags.clear(F_CONFIG_UPDATED);
        save_config( ttt().data.config );
    }
    return true;
}
Beispiel #18
0
void active_protocol_c::send_audio(int cid, const s3::Format &ifmt, const void *data, int size)
{
    if (!ipcp) return;

    struct s
    {
        int cid;
        isotoxin_ipc_s *ipcp;
        void send_audio(const s3::Format& ofmt, const void *data, int size)
        {
            ipcp->send(ipcw(AQ_SEND_AUDIO) << cid << data_block_s(data,size));
        }
    } ss = { cid, ipcp };

    cvt.ofmt = audio_fmt;
    cvt.acceptor = DELEGATE( &ss, send_audio );
    cvt.cvt(ifmt, data, size );

}
Beispiel #19
0
void gui_filterbar_c::ctx_rename_tag(const ts::str_c &tis)
{
    int ti = tis.as_int();

    ts::wstr_c hint = TTT("Rename tag $", 218) / ts::wstr_c(CONSTWSTR("<b>")).append(tagname(ti)).append(CONSTWSTR("</b>"));
    if (ti < BIT_count)
        hint.append(CONSTWSTR("<br>")).append( TTT("Empty - set default",249) );


    SUMMON_DIALOG<dialog_entertext_c>(UD_RENTAG, dialog_entertext_c::params(
        UD_RENTAG,
        gui_isodialog_c::title(title_rentag),
        hint,
        tagname(ti),
        tis,
        DELEGATE(this, renamed),
        nullptr,
        ti < BIT_count ? check_always_ok : check_always_ok_except_empty,
        getrid()));

}
Beispiel #20
0
bool gui_filterbar_c::do_contact_check(RID, GUIPARAM p)
{
    for (int n = ts::tmax(1, contacts().count() / 10 ); contact_index < contacts().count() && n > 0; --n)
    {
        contact_c &c = contacts().get(contact_index++);
        if (c.is_rootcontact())
        {
            contact_root_c *cr = ts::ptr_cast<contact_root_c *>(&c);

            if (cr->is_full_search_result())
            {
                cr->full_search_result(false);
                if (cr->gui_item) cr->gui_item->update_text();
            }

            if (cr->gui_item)
            {
                MODIFY(*cr->gui_item).visible(check_one(cr));
            }
        }
    }

    if (contact_index < contacts().count())
    {
        if (active)
        {
            gui_contactlist_c &cl = HOLD(getparent()).as<gui_contactlist_c>();
            cl.scroll_to_child(active, false);
        }
        DEFERRED_UNIQUE_CALL(0, DELEGATE(this, do_contact_check), 0);
    }
    else
    {
        apply_full_text_search_result();
    }

    return true;
}
void RemoteDesktop::Network_Client::_Run(std::shared_ptr<SocketHandler>& socket){
	_Socket = socket;
	auto newevent(RAIIWSAEVENT(WSACreateEvent()));

	WSAEventSelect(socket->get_Socket(), newevent.get(), FD_CLOSE | FD_READ);
	int counter = 0;
	NetworkProcessor processor(DELEGATE(&RemoteDesktop::Network_Client::_HandleReceive), DELEGATE(&RemoteDesktop::Network_Client::_HandleConnect));
	WSANETWORKEVENTS NetworkEvents;
	DEBUG_MSG("Starting Loop");
	auto timer = std::chrono::high_resolution_clock::now();
	while (_Running && !_ShouldDisconnect) {

		auto Index = WaitForSingleObject(newevent.get(), 1000);

		if ((Index != WSA_WAIT_FAILED) && (Index != WSA_WAIT_TIMEOUT)) {

			WSAEnumNetworkEvents(socket->get_Socket(), newevent.get(), &NetworkEvents);
			if (((NetworkEvents.lNetworkEvents & FD_READ) == FD_READ)
				&& NetworkEvents.iErrorCode[FD_READ_BIT] == ERROR_SUCCESS){
				processor.Receive(socket);
			}
			else if (((NetworkEvents.lNetworkEvents & FD_CLOSE) == FD_CLOSE) && NetworkEvents.iErrorCode[FD_CLOSE_BIT] == ERROR_SUCCESS){
				break;// get out of loop and try reconnecting
			}
		}
		if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - timer).count() > 1000){
			if (RemoteDesktop::SocketHandler::CheckState(socket) == RemoteDesktop::Network_Return::FAILED) {
				break;// get out of the loop and try reconnecting
			}
			timer = std::chrono::high_resolution_clock::now();
		}

	}
	socket->Disconnect();
	DEBUG_MSG("Ending Loop");
}
displaySDD1309Sim::displaySDD1309Sim(i2cSim* i2c, int id)
{
    i2c->registerDevice(id, DELEGATE(i2cMessageDelegate, displaySDD1309Sim, *this, processMessage));
    lcd_data_pos = 0;
}
Beispiel #23
0
gui_c::tempbuf_c::tempbuf_c( double ttl )
{
    if ( ttl >= 0 )
        DEFERRED_CALL( ttl, DELEGATE(this, selfdie), nullptr );
}
Beispiel #24
0
adcSim::adcSim()
{
    ADCSRA.setCallback(DELEGATE(registerDelegate, adcSim, *this, ADC_ADCSRA_callback));
    for(unsigned int n=0;n<16;n++)
        adcValue[n] = 0;
}
 static void scan(DeadCodeElimination* self, Expression** currp) {
   if (!self->reachable) {
     // convert to an unreachable. do this without UB, even though we have no destructors on AST nodes
     #define DELEGATE(CLASS_TO_VISIT) \
       { ExpressionManipulator::convert<CLASS_TO_VISIT, Unreachable>(static_cast<CLASS_TO_VISIT*>(*currp)); break; }
     switch ((*currp)->_id) {
       case Expression::Id::BlockId: DELEGATE(Block);
       case Expression::Id::IfId: DELEGATE(If);
       case Expression::Id::LoopId: DELEGATE(Loop);
       case Expression::Id::BreakId: DELEGATE(Break);
       case Expression::Id::SwitchId: DELEGATE(Switch);
       case Expression::Id::CallId: DELEGATE(Call);
       case Expression::Id::CallImportId: DELEGATE(CallImport);
       case Expression::Id::CallIndirectId: DELEGATE(CallIndirect);
       case Expression::Id::GetLocalId: DELEGATE(GetLocal);
       case Expression::Id::SetLocalId: DELEGATE(SetLocal);
       case Expression::Id::LoadId: DELEGATE(Load);
       case Expression::Id::StoreId: DELEGATE(Store);
       case Expression::Id::ConstId: DELEGATE(Const);
       case Expression::Id::UnaryId: DELEGATE(Unary);
       case Expression::Id::BinaryId: DELEGATE(Binary);
       case Expression::Id::SelectId: DELEGATE(Select);
       case Expression::Id::ReturnId: DELEGATE(Return);
       case Expression::Id::HostId: DELEGATE(Host);
       case Expression::Id::NopId: DELEGATE(Nop);
       case Expression::Id::UnreachableId: DELEGATE(Unreachable);
       case Expression::Id::InvalidId:
       default: WASM_UNREACHABLE();
     }
     #undef DELEGATE
     return;
   }
   auto* curr =* currp;
   if (curr->is<If>()) {
     self->pushTask(DeadCodeElimination::doVisitIf, currp);
     if (curr->cast<If>()->ifFalse) {
       self->pushTask(DeadCodeElimination::scan, &curr->cast<If>()->ifFalse);
       self->pushTask(DeadCodeElimination::doAfterIfElseTrue, currp);
     }
     self->pushTask(DeadCodeElimination::scan, &curr->cast<If>()->ifTrue);
     self->pushTask(DeadCodeElimination::doAfterIfCondition, currp);
     self->pushTask(DeadCodeElimination::scan, &curr->cast<If>()->condition);
   } else if (curr->is<Block>()) {
     self->pushTask(DeadCodeElimination::doVisitBlock, currp);
     auto& list = curr->cast<Block>()->list;
     for (int i = int(list.size()) - 1; i >= 0; i--) {
       self->pushTask(DeadCodeElimination::doAfterBlockElement, currp);
       self->pushTask(DeadCodeElimination::scan, &list[i]);
     }
     self->pushTask(DeadCodeElimination::doPreBlock, currp);
   } else {
     WalkerPass<PostWalker<DeadCodeElimination, Visitor<DeadCodeElimination>>>::scan(self, currp);
   }
 }
Beispiel #26
0
mainrect_c::~mainrect_c() 
{
    if (gui) gui->delete_event( DELEGATE(this,saverectpos) );
    cfg().onclosedie( DELEGATE(this, onclosesave) );
}
Beispiel #27
0
i2cSim::i2cSim()
{
    TWCR.setCallback(DELEGATE(registerDelegate, i2cSim, *this, I2C_TWCR_callback));
}