Beispiel #1
0
void Gobby::GSelector::add_socket(const net6::socket& sock,
                                  net6::io_condition cond)
{
	SelectedSocket& sel = m_map[&sock];

	sel.sock = &sock;
	sel.cond = cond;

	// Timeout is set in set_timeout
	if( (cond & IO_FLAGS) != net6::IO_NONE)
	{
		net6::socket::socket_type fd = sock.cobj();

		sel.io_chan =
#ifdef _WIN32
			Glib::IOChannel::create_from_win32_socket(fd);
#else
			Glib::IOChannel::create_from_fd(fd);
#endif

		sel.io_conn = Glib::signal_io().connect(
			sigc::bind(
				sigc::mem_fun(*this, &GSelector::on_io),
				&sock
			),
			sel.io_chan,
			gcond(cond)
		);
	}
}
Beispiel #2
0
void Gobby::GSelector::modify_socket(map_type::iterator iter,
                                     net6::io_condition cond)
{
	// IO_FLAGS did change
	if( (iter->second.cond & IO_FLAGS) != (cond & IO_FLAGS) )
	{
		if(iter->second.io_conn.connected() )
			iter->second.io_conn.disconnect();

		if( (cond & IO_FLAGS) != net6::IO_NONE)
		{
			iter->second.io_conn = Glib::signal_io().connect(
				sigc::bind(
					sigc::mem_fun(*this, &GSelector::on_io),
					iter->first
				),
				iter->second.io_chan,
				gcond(cond)
			);
		}
	}

	// IO_TIMEOUT changed
	if( (iter->second.cond & net6::IO_TIMEOUT) != (cond & net6::IO_TIMEOUT))
	{
		if(iter->second.time_conn.connected() )
			iter->second.time_conn.disconnect();

		// Timeout is set in set_timeout
	}

	iter->second.cond = cond;
}
Beispiel #3
0
bool Gobby::GSelector::on_io(Glib::IOCondition cond,
                             const net6::socket* sock)
{
	{
		Glib::RecMutex::Lock lock(*m_mutex);
		map_type::const_iterator iter = m_map.find(sock);

		// Has been removed by previous handler
		if(iter == m_map.end() ) return false;

		// Occured condition has been removed by previous handler
		if( (gcond(iter->second.cond) & cond) == gcond(net6::IO_NONE))
			return true;
	}

	// Event handler may destroy the selector, so do not reference
	// m_mutex anymore.
	sock->io_event().emit(ncond(cond) );
	return true;
}
// ============================================================================
// pxpByteCode
// ============================================================================
pxpByteCode::pxpByteCode( pkgDecompiler* decompiler )
:   Decompiler(decompiler)
,   CToken(NULL)
,   CTokenTree(NULL)
,   CTokenGroup(NULL)
,   CTokenGroupTree(NULL)
,   CTokenItem(NULL)
,   CTokenItemTree(NULL)
,   CTokenGroupCnd(NULL)
,   CTokenGroupCndTree(NULL)
,   unXmlParser()
{
    // temp tree nodes
    unXmlParseTree bytecode   ( wxT("bytecode") );
    unXmlParseTree bgroup     ( wxT("group") );
    unXmlParseTree gname      ( wxT("name") );
    unXmlParseTree gmemo      ( wxT("memo") );

    unXmlParseTree gtoken     ( wxT("token") );
    unXmlParseTree tcode      ( wxT("code") );
    unXmlParseTree tname      ( wxT("name") );
    unXmlParseTree tdesc      ( wxT("desc") );
    unXmlParseTree tdata      ( wxT("data") );

    unXmlParseTree titem      ( wxT("item") );
    unXmlParseTree itype      ( wxT("type") );
    unXmlParseTree iname      ( wxT("name") );

    unXmlParseTree ttext      ( wxT("text") );

    unXmlParseTree gcond      ( wxT("gcond") );
    unXmlParseTree cif        ( wxT("if") );
    unXmlParseTree ceq        ( wxT("eq") );
    unXmlParseTree cthen      ( wxT("then") );
    unXmlParseTree cleft      ( wxT("left") );
    unXmlParseTree cright     ( wxT("right") );

    unXmlParseTree ctstream   ( wxT("tstream") );
    unXmlParseTree cnum       ( wxT("num") );

    unXmlParseTree nfunc      ( wxT("nativefunctions") );
    unXmlParseTree ffirst     ( wxT("first") );
    unXmlParseTree fextended  ( wxT("extended") );

    // token group - pre
    bgroup.AddCommand( new_xpObjCreate<pkgTokenGroup>(txpParseTree) );
    bgroup.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroup, txpTokenGroupObject ) );
    bgroup.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupTree, txpParseTree ) );
        gname.AddCommand( new_xpFunc1( txpTokenGroup, &pkgTokenGroup::SetName, txpNodeName(txpParseTree) ) );
        gname.AddPostCommand( new_xpFunc1( Decompiler, &pkgDecompiler::AddTokenGroup, txpTokenGroup ) );

    // token group - post
    bgroup.AddPostCommand( new_xpObjClear(txpParseTree) );
    bgroup.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroup ) );
    bgroup.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupTree ) );

    // gcond = pre
    gcond.AddCommand( new_xpObjCreate<pkgTokenCondition>(txpParseTree) );
    gcond.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupCnd, txpTokenGroupCndObject ) );
    gcond.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupCndTree, txpParseTree ) );

    // gcond = post
    gcond.AddPostCommand( new_xpObjClear(txpParseTree) );
    gcond.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupCnd ) );
    gcond.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupCndTree ) );

    // token - pre
    gtoken.AddCommand( new_xpObjCreate<dtToken>(txpParseTree) );
    gtoken.AddCommand( new_xpFunc1( this, &pxpByteCode::SetToken, txpTokenObject ) );
    gtoken.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenTree, txpParseTree ) );
        tcode.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetTokenData, txpNodeData(txpParseTree) ) );
        tname.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetTokenName, txpNodeName(txpParseTree) ) );
        tdesc.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetDesc, txpNodeName(txpParseTree) ) );
        tdesc.AddCommand( new_xpFunc1( txpTokenGroup, &pkgTokenGroup::AddToken, txpToken ) );
        tdesc.AddCommand( new_xpFunc2( Decompiler, &pkgDecompiler::AddToken, txpToken, txpTokenGroupCnd ) );

    // token - post
    gtoken.AddPostCommand( new_xpFunc0( txpToken, &dtToken::DumpInfo ) );
    gtoken.AddPostCommand( new_xpObjClear(txpParseTree) );
    gtoken.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearToken ) );
    gtoken.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenTree ) );

    // titem - pre
    titem.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenItemTree, txpParseTree ) );
        itype.AddCommand( new_xpObjFactory( txpTokenItemTree, &GDataTypeFactory, &pkgDataTypeFactory::Create, txpNodeName(txpParseTree) ) );
        itype.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenItem, txpTokenItemTreeObject ) );
        iname.AddCommand( new_xpFunc1( txpTokenItem, &pkgDataType::SetDesc, txpNodeName(txpParseTree) ) );

    // titem - post
    titem.AddPostCommand( new_xpFunc1( txpToken, &dtToken::AddItem, txpTokenItem ) );
    titem.AddPostCommand( new_xpObjClear(txpParseTree) );
    titem.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenItem ) );
    titem.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenItemTree ) );
    
    ffirst.AddCommand( new_xpFunc1( Decompiler, &pkgDecompiler::SetFunctionIdFirst, txpNodeData(txpParseTree) ) );
    fextended.AddCommand( new_xpFunc1( Decompiler, &pkgDecompiler::SetFunctionIdExtended, txpNodeData(txpParseTree) ) );


    // construct tree starting from leaves
    // ie: node on right side *cannot* appear anywhere below on left side

    // token
    gtoken.AddChild( tcode, pl::one );
    gtoken.AddChild( tname, pl::one );
    gtoken.AddChild( tdesc, pl::one );
            titem.AddChild( itype, pl::one );
            titem.AddChild( iname, pl::one );
        tdata.AddChild( titem, pl::minone );
        tdata.AddChild( ttext, pl::maxone );
    gtoken.AddChild( tdata, pl::maxone );

    // if
            cleft.AddChild( ctstream, pl::maxone );
            cleft.AddChild( cnum, pl::maxone );
            cright.AddChild( ctstream, pl::maxone );
            cright.AddChild( cnum, pl::maxone );
        ceq.AddChild( cleft, pl::one );
        ceq.AddChild( cright, pl::one );
    cif.AddChild( ceq, pl::one );

    // then
    cthen.AddChild( gtoken, pl::any );

    // group
    bgroup.AddChild( gname, pl::one );
    bgroup.AddChild( gmemo, pl::any );
        gcond.AddChild( cif, pl::one );
        gcond.AddChild( cthen, pl::one );
    bgroup.AddChild( gcond, pl::maxone );
    bgroup.AddChild( gtoken, pl::any );

    // native functions
    nfunc.AddChild( fextended, pl::one );
    nfunc.AddChild( ffirst, pl::one );

    // bytecode
    bytecode.AddChild( bgroup, pl::minone );
    bytecode.AddChild( nfunc, pl::maxone );

    ParseTree = new unXmlParseTree( bytecode );
}